mirror of
https://github.com/ceph/ceph
synced 2024-12-18 17:37:38 +00:00
ceph-disk: add '[un]suppress-activate <dev>' command
It is often useful to prepare but not activate a device, for example when preparing a bunch of spare disks. This marks a device as 'do not activate' so that it can be prepared without activating. Fixes: #3255 Signed-off-by: Sage Weil <sage@inktank.com>
This commit is contained in:
parent
9ec77ebbd2
commit
225fefe5e7
@ -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
|
||||
@ -1800,6 +1804,72 @@ def main_list(args):
|
||||
list_dev('/dev/' + base, uuid_map, journal_map)
|
||||
|
||||
|
||||
###########################
|
||||
#
|
||||
# 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)
|
||||
if not disk.startswith('/dev/') or not stat.S_ISBLK(os.lstat(path)):
|
||||
return False
|
||||
try:
|
||||
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)):
|
||||
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)):
|
||||
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 e:
|
||||
raise Error('failed to unsuppress', e)
|
||||
|
||||
|
||||
def main_suppress(args):
|
||||
set_suppress(args.path)
|
||||
|
||||
def main_unsuppress(args):
|
||||
unset_suppress(args.path)
|
||||
|
||||
|
||||
###########################
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user