From 80af5fb887f30792c342ac16da9ed95d7e89e491 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 14 Mar 2013 21:05:07 -0700 Subject: [PATCH] ceph-disk-activate: identify cluster .conf by fsid Determine what cluster the disk belongs to by checking the fsid defined in /etc/ceph/*.conf. Previously we hard-coded 'ceph'. Note that this has the nice side-effect that if we have a disk with a bad/different fsid, we now fail to activate it. Previously, we would mount and start ceph-osd, but the daemon would fail to authenticate because it was part of the wrong cluster. Fixes: #3253 Signed-off-by: Sage Weil --- src/ceph-disk-activate | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/ceph-disk-activate b/src/ceph-disk-activate index f5a33dd926b8e..9b5370f5d2205 100755 --- a/src/ceph-disk-activate +++ b/src/ceph-disk-activate @@ -560,6 +560,29 @@ def activate_dir( return (cluster, osd_id) +def find_cluster_by_uuid(uuid): + """ + Find a cluster name by searching /etc/ceph/*.conf for a conf file + with the right uuid. + """ + no_fsid = [] + if not os.path.exists('/etc/ceph'): + return None + for file in os.listdir('/etc/ceph'): + if not file.endswith('.conf'): + continue + cluster = file[:-5] + u = get_conf(cluster, 'fsid') + if u is None: + no_fsid.append(cluster) + elif u == uuid: + return cluster + # be tolerant of /etc/ceph/ceph.conf without an fsid defined. + if len(no_fsid) == 1 and no_fsid[0] == 'ceph': + log.warning('No fsid defined in /etc/ceph/ceph.conf; using anyway') + return 'ceph' + return None + def activate( path, activate_key_template, @@ -574,8 +597,9 @@ def activate( raise ActivateError('No cluster uuid assigned.') log.debug('Cluster uuid is %s', ceph_fsid) - # TODO use ceph_fsid to find the right cluster - cluster = 'ceph' + cluster = find_cluster_by_uuid(ceph_fsid) + if cluster is None: + raise ActivateError('No cluster conf found in /etc/ceph with fsid %s' % ceph_fsid) log.debug('Cluster name is %s', cluster) fsid = read_one_line(path, 'fsid') -- 2.39.5