diff options
Diffstat (limited to 'src/ceph-disk')
-rwxr-xr-x | src/ceph-disk | 94 |
1 files changed, 93 insertions, 1 deletions
diff --git a/src/ceph-disk b/src/ceph-disk index c5f16a401e1..6c1b3703847 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -789,7 +789,7 @@ def prepare_journal_dev( '--name={name}'.format(name=os.path.basename(journal)), ], ) - journal_symlink='/dev/{symlink}-part{num}'.format(symlink=symlinks.split()[2], num=num) + journal_symlink = '/dev/{symlink}-part{num}'.format(symlink=str(symlinks).split()[2], num=num) journal_dmcrypt = None if journal_dm_keypath: @@ -1592,6 +1592,10 @@ def main_activate(args): if not os.path.exists(args.path): raise Error('%s does not exist', args.path) + if is_suppressed(args.path): + LOG.info('suppressed activate request on %s', args.path) + return + activate_lock.acquire() try: mode = os.stat(args.path).st_mode @@ -1801,6 +1805,72 @@ def main_list(args): ########################### +# +# Mark devices that we want to suppress activates on with a +# file like +# +# /var/lib/ceph/tmp/suppress-activate.sdb +# +# where the last bit is the sanitized device name (/dev/X without the +# /dev/ prefix) and the is_suppress() check matches a prefix. That +# means suppressing sdb will stop activate on sdb1, sdb2, etc. +# + +SUPPRESS_PREFIX = '/var/lib/ceph/tmp/suppress-activate.' + +def is_suppressed(path): + disk = os.path.realpath(path) + try: + if not disk.startswith('/dev/') or not stat.S_ISBLK(os.lstat(path).st_mode): + return False + base = disk[5:] + while len(base): + if os.path.exists(SUPPRESS_PREFIX + base): + return True + base = base[:-1] + except: + return False + +def set_suppress(path): + disk = os.path.realpath(path) + if not os.path.exists(disk): + raise Error('does not exist', path) + if not stat.S_ISBLK(os.lstat(path).st_mode): + raise Error('not a block device', path) + base = disk[5:] + + with file(SUPPRESS_PREFIX + base, 'w') as f: + pass + LOG.info('set suppress flag on %s', base) + +def unset_suppress(path): + disk = os.path.realpath(path) + if not os.path.exists(disk): + raise Error('does not exist', path) + if not stat.S_ISBLK(os.lstat(path).st_mode): + raise Error('not a block device', path) + assert disk.startswith('/dev/') + base = disk[5:] + + fn = SUPPRESS_PREFIX + base + if not os.path.exists(fn): + raise Error('not marked as suppressed', path) + + try: + os.unlink(fn) + LOG.info('unset suppress flag on %s', base) + except OSError as e: + raise Error('failed to unsuppress', e) + + +def main_suppress(args): + set_suppress(args.path) + +def main_unsuppress(args): + unset_suppress(args.path) + + +########################### def parse_args(): @@ -1936,6 +2006,28 @@ def parse_args(): func=main_list, ) + suppress_parser = subparsers.add_parser('suppress-activate', help='Suppress activate on a device (prefix)') + suppress_parser.add_argument( + 'path', + metavar='PATH', + nargs='?', + help='path to block device or directory', + ) + suppress_parser.set_defaults( + func=main_suppress, + ) + + unsuppress_parser = subparsers.add_parser('unsuppress-activate', help='Stop suppressing activate on a device (prefix)') + unsuppress_parser.add_argument( + 'path', + metavar='PATH', + nargs='?', + help='path to block device or directory', + ) + unsuppress_parser.set_defaults( + func=main_unsuppress, + ) + args = parser.parse_args() return args |