From: Rishabh Dave Date: Wed, 14 Aug 2019 15:57:38 +0000 (+0530) Subject: ceph-volume: reuse list of LVs X-Git-Tag: v14.2.5~268^2^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=75b3c035fca35cd7936384ca5d8a5080c1c452fc;p=ceph.git ceph-volume: reuse list of LVs Avoid creating of list of LVs in different methods of the same module and resue them. Fixes: https://tracker.ceph.com/issues/37490 Signed-off-by: Rishabh Dave (cherry picked from commit ab3a58e78124a984d162b2f63992d01c5e59e2a7) --- diff --git a/src/ceph-volume/ceph_volume/api/lvm.py b/src/ceph-volume/ceph_volume/api/lvm.py index cce8a302cba1c..92ac2c2283db0 100644 --- a/src/ceph-volume/ceph_volume/api/lvm.py +++ b/src/ceph-volume/ceph_volume/api/lvm.py @@ -364,7 +364,7 @@ def get_lv_from_argument(argument): return get_lv(lv_name=lv_name, vg_name=vg_name) -def get_lv(lv_name=None, vg_name=None, lv_path=None, lv_uuid=None, lv_tags=None): +def get_lv(lv_name=None, vg_name=None, lv_path=None, lv_uuid=None, lv_tags=None, lvs=None): """ Return a matching lv for the current system, requiring ``lv_name``, ``vg_name``, ``lv_path`` or ``tags``. Raises an error if more than one lv @@ -376,7 +376,8 @@ def get_lv(lv_name=None, vg_name=None, lv_path=None, lv_uuid=None, lv_tags=None) """ if not any([lv_name, vg_name, lv_path, lv_uuid, lv_tags]): return None - lvs = Volumes() + if lvs is None: + lvs = Volumes() return lvs.get( lv_name=lv_name, vg_name=vg_name, lv_path=lv_path, lv_uuid=lv_uuid, lv_tags=lv_tags diff --git a/src/ceph-volume/ceph_volume/devices/lvm/listing.py b/src/ceph-volume/ceph_volume/devices/lvm/listing.py index 96875936377e4..f3416472a0b9c 100644 --- a/src/ceph-volume/ceph_volume/devices/lvm/listing.py +++ b/src/ceph-volume/ceph_volume/devices/lvm/listing.py @@ -112,8 +112,8 @@ class List(object): def list(self, args): # ensure everything is up to date before calling out # to list lv's - self.update() - report = self.generate(args) + lvs = self.update() + report = self.generate(args, lvs) if args.format == 'json': # If the report is empty, we don't return a non-zero exit status # because it is assumed this is going to be consumed by automated @@ -153,25 +153,27 @@ class List(object): # this means that the device has changed, so it must be updated # on the API to reflect this lv.set_tags({device_name: disk_device}) + return lvs - def generate(self, args): + def generate(self, args, lvs=None): """ Generate reports for an individual device or for all Ceph-related devices, logical or physical, as long as they have been prepared by this tool before and contain enough metadata. """ if args.device: - return self.single_report(args.device) + return self.single_report(args.device, lvs) else: - return self.full_report() + return self.full_report(lvs) - def single_report(self, device): + def single_report(self, device, lvs=None): """ Generate a report for a single device. This can be either a logical volume in the form of vg/lv or a device with an absolute path like /dev/sda1 or /dev/sda """ - lvs = api.Volumes() + if lvs is None: + lvs = api.Volumes() report = {} lv = api.get_lv_from_argument(device) @@ -227,6 +229,7 @@ class List(object): if lvs is None: lvs = api.Volumes() report = {} + for lv in lvs: try: _id = lv.tags['ceph.osd_id'] @@ -246,7 +249,7 @@ class List(object): # bluestore will not have a journal, filestore will not have # a block/wal/db, so we must skip if not present continue - if not api.get_lv(lv_uuid=device_uuid): + if not api.get_lv(lv_uuid=device_uuid, lvs=lvs): # means we have a regular device, so query blkid disk_device = disk.get_device_from_partuuid(device_uuid) if disk_device: