From 77ff7c3dc6dd6861b094e5a53d329de0802f3032 Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Mon, 17 Aug 2015 23:51:24 +0200 Subject: [PATCH] ceph-disk: multipath support for split_dev_base_partnum split_dev_base_partnum returns the path of the whole disk in /dev/mapper. The base variable name to designate the device for the whole disk is a misnomer since it cannot be used as a basename to rebuild the parition device name in the case of multipath. The logic of split_dev_base_partnum for devices is reworked to use /sys/dev/block/M:m/partition instead of device name parsing. http://tracker.ceph.com/issues/11881 Refs: #11881 Signed-off-by: Loic Dachary --- src/ceph-disk | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/ceph-disk b/src/ceph-disk index 38755ac5ac21..26c19f2e11b0 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -574,6 +574,18 @@ def is_partition_mpath(dev): uuid = get_dm_uuid(dev) return bool(re.match('part\d+-mpath-', uuid)) +def partnum_mpath(dev): + uuid = get_dm_uuid(dev) + return re.findall('part(\d+)-mpath-', uuid)[0] + +def get_partition_base_mpath(dev): + slave_path = os.path.join(block_path(dev), 'slaves') + slaves = os.listdir(slave_path) + assert slaves + name_path = os.path.join(slave_path, slaves[0], 'dm', 'name') + name = open(name_path, 'r').read().strip() + return os.path.join('/dev/mapper', name) + def is_partition(dev): """ Check whether a given device path is a partition or a full disk. @@ -2565,11 +2577,14 @@ def get_dev_fs(dev): def split_dev_base_partnum(dev): - if 'loop' in dev or 'cciss' in dev or 'nvme' in dev: - return re.match('(.*\d+)p(\d+)', dev).group(1, 2) + if is_mpath(dev): + partnum = partnum_mpath(dev) + base = get_partition_base_mpath(dev) else: - return re.match('(\D+)(\d+)', dev).group(1, 2) - + b = block_path(dev) + partnum = open(os.path.join(b, 'partition')).read().strip() + base = get_partition_base(dev) + return (base, partnum) def get_partition_type(part): """ -- 2.47.3