summaryrefslogtreecommitdiff
path: root/src/ceph-disk
diff options
context:
space:
mode:
Diffstat (limited to 'src/ceph-disk')
-rwxr-xr-xsrc/ceph-disk78
1 files changed, 57 insertions, 21 deletions
diff --git a/src/ceph-disk b/src/ceph-disk
index 68a171938c5..c9515997ded 100755
--- a/src/ceph-disk
+++ b/src/ceph-disk
@@ -12,6 +12,7 @@ import stat
import sys
import tempfile
import uuid
+import lockfile
CEPH_OSD_ONDISK_MAGIC = 'ceph osd volume v026'
@@ -62,6 +63,7 @@ if LOG_NAME == '__main__':
LOG_NAME = os.path.basename(sys.argv[0])
LOG = logging.getLogger(LOG_NAME)
+lock = lockfile.FileLock('/var/lib/ceph/tmp/ceph-disk.lock')
###### exceptions ########
@@ -683,6 +685,16 @@ def zap(dev):
raise Error(e)
+def get_udev_version():
+ version = _check_output(
+ args=[
+ 'udevadm',
+ '--version',
+ ],
+ )
+ return int(version)
+
+
def prepare_journal_dev(
data,
journal,
@@ -761,9 +773,24 @@ def prepare_journal_dev(
],
)
- journal_symlink = '/dev/disk/by-partuuid/{journal_uuid}'.format(
- journal_uuid=journal_uuid,
- )
+ if get_udev_version() >= 172:
+ journal_symlink = '/dev/disk/by-partuuid/{journal_uuid}'.format(
+ journal_uuid=journal_uuid,
+ )
+ else:
+ # udev prior to version 172 doesn't create by-partuuid directory
+ # use by-path symlink instead. This is the third symlink returned
+ # by udevadm when queried.
+ LOG.debug('Using alternate persistant name for journal symlink')
+ symlinks = _check_output(
+ args=[
+ 'udevadm',
+ 'info',
+ '--query=symlink',
+ '--name={name}'.format(name=os.path.basename(journal)),
+ ],
+ )
+ journal_symlink='/dev/{symlink}-part{num}'.format(symlink=symlinks.split()[2], num=num)
journal_dmcrypt = None
if journal_dm_keypath:
@@ -1035,6 +1062,7 @@ def main_prepare(args):
osd_dm_keypath = None
try:
+ lock.acquire()
if not os.path.exists(args.data):
raise Error('data path does not exist', args.data)
@@ -1163,12 +1191,14 @@ def main_prepare(args):
)
else:
raise Error('not a dir or block device', args.data)
+ lock.release()
except Error as e:
if journal_dm_keypath:
os.unlink(journal_dm_keypath)
if osd_dm_keypath:
os.unlink(osd_dm_keypath)
+ lock.release()
raise e
@@ -1559,26 +1589,32 @@ def main_activate(args):
if not os.path.exists(args.path):
raise Error('%s does not exist', args.path)
- mode = os.stat(args.path).st_mode
- if stat.S_ISBLK(mode):
- (cluster, osd_id) = mount_activate(
- dev=args.path,
- activate_key_template=args.activate_key_template,
- init=args.mark_init,
- )
- elif stat.S_ISDIR(mode):
- (cluster, osd_id) = activate_dir(
- path=args.path,
- activate_key_template=args.activate_key_template,
- init=args.mark_init,
+ lock.acquire()
+ try:
+ mode = os.stat(args.path).st_mode
+ if stat.S_ISBLK(mode):
+ (cluster, osd_id) = mount_activate(
+ dev=args.path,
+ activate_key_template=args.activate_key_template,
+ init=args.mark_init,
+ )
+ elif stat.S_ISDIR(mode):
+ (cluster, osd_id) = activate_dir(
+ path=args.path,
+ activate_key_template=args.activate_key_template,
+ init=args.mark_init,
+ )
+ else:
+ raise Error('%s is not a directory or block device', args.path)
+
+ start_daemon(
+ cluster=cluster,
+ osd_id=osd_id,
)
- else:
- raise Error('%s is not a directory or block device', args.path)
+ lock.release()
- start_daemon(
- cluster=cluster,
- osd_id=osd_id,
- )
+ except:
+ lock.release()