]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: reuse list of LVs
authorRishabh Dave <ridave@redhat.com>
Wed, 14 Aug 2019 15:57:38 +0000 (21:27 +0530)
committerJan Fajerski <jfajerski@suse.com>
Tue, 3 Sep 2019 08:59:34 +0000 (10:59 +0200)
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 <ridave@redhat.com>
(cherry picked from commit ab3a58e78124a984d162b2f63992d01c5e59e2a7)

src/ceph-volume/ceph_volume/api/lvm.py
src/ceph-volume/ceph_volume/devices/lvm/listing.py

index cce8a302cba1ca30743769ba6008993629444513..92ac2c2283db0b87ce405a9ee5243e04594f13f0 100644 (file)
@@ -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
index 96875936377e4e9bd018d861ac3b663310f3f3ee..f3416472a0b9cc14c56839e9d1ada5bfb5ae26f5 100644 (file)
@@ -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: