From a88d096c0f464ac86cf60e74d79094c3bcb7fa69 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 18 Dec 2019 11:05:32 -0600 Subject: [PATCH] cephadm: add some coarse-grained locking Take per-cluster 'deploy' lock for bootstrap deploy adopt rm-daemon rm-cluster No locking for version pull run (this is never actually used anyway) shell enter ceph-volume unit (this is a clean pass-through to systemctl) logs ls check-host The only one I'm not sure about is ceph-volume. I don't want the c-v list/inventory commands to block, but perhaps the deploy ones should... but perhaps not, since there's no reason we can't deploy multiple OSDs on different devices at the same time. Signed-off-by: Sage Weil --- src/cephadm/cephadm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index b8961e543bcf1..c8fbfd2a5d24b 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -1381,6 +1381,9 @@ def command_bootstrap(): mgr_id = args.mgr_id or generate_service_id() logging.info('Cluster fsid: %s' % fsid) + l = FileLock(fsid) + l.acquire() + # config cp = read_config(args.config) if args.mon_ip: @@ -1692,6 +1695,9 @@ def command_deploy(): # type: () -> None (daemon_type, daemon_id) = args.name.split('.', 1) + l = FileLock(args.fsid) + l.acquire() + supported_daemons = list(Ceph.daemons) supported_daemons.extend(Monitoring.components) @@ -2008,6 +2014,7 @@ def list_daemons(detail=True, legacy_dir=None): def command_adopt(): # type: () -> None + (daemon_type, daemon_id) = args.name.split('.', 1) (uid, gid) = extract_uid_gid() if args.style == 'legacy': @@ -2018,6 +2025,9 @@ def command_adopt(): if not fsid: raise Error('could not detect legacy fsid; set fsid in ceph.conf') + l = FileLock(fsid) + l.acquire() + data_dir_src = ('/var/lib/ceph/%s/%s-%s' % (daemon_type, args.cluster, daemon_id)) data_dir_src = os.path.abspath(args.legacy_dir + data_dir_src) @@ -2087,6 +2097,10 @@ def command_adopt(): def command_rm_daemon(): # type: () -> None + + l = FileLock(args.fsid) + l.acquire() + (daemon_type, daemon_id) = args.name.split('.', 1) if daemon_type in ['mon', 'osd'] and not args.force: raise Error('must pass --force to proceed: ' @@ -2109,6 +2123,9 @@ def command_rm_cluster(): raise Error('must pass --force to proceed: ' 'this command may destroy precious data!') + l = FileLock(args.fsid) + l.acquire() + # stop + disable individual daemon units for d in list_daemons(detail=False): if d['fsid'] != args.fsid: -- 2.39.5