]> sourceware.org Git - lvm2.git/commitdiff
label_read_pvid: separate error and no-pvid
authorDavid Teigland <teigland@redhat.com>
Fri, 23 Apr 2021 22:32:37 +0000 (17:32 -0500)
committerDavid Teigland <teigland@redhat.com>
Fri, 23 Apr 2021 22:37:08 +0000 (17:37 -0500)
error reading dev and no pvid on dev were both
returning 0.  make it easier for callers to
know which, if they care.

return 1 if the device could be read, regardless
of whether a pvid was found or not.
set has_pvid=1 if a pvid is found and 0 if no
pvid is found.

lib/device/device_id.c
lib/label/label.c
lib/label/label.h
tools/lvmdevices.c
tools/pvscan.c

index 6fa3b0360a80626207b28089fce968aaf2337be6..67f72e51b1baaffeed5253d4aef6f8a1dd7cd5a3 100644 (file)
@@ -1912,6 +1912,7 @@ void device_ids_find_renamed_devs(struct cmd_context *cmd, struct dm_list *dev_l
         */
        dm_list_iterate_items(devl, &search_devs) {
                dev = devl->dev;
+               int has_pvid;
 
                /*
                 * We only need to check devs that would use ID_TYPE_DEVNAME
@@ -1935,11 +1936,17 @@ void device_ids_find_renamed_devs(struct cmd_context *cmd, struct dm_list *dev_l
 
                /*
                 * Reads 4K from the start of the disk.
+                * Returns 0 if the dev cannot be read.
                 * Looks for LVM header, and sets dev->pvid if the device is a PV.
-                * Returns 0 if the dev has no lvm label or no PVID.
+                * Sets has_pvid=1 if the dev has an lvm PVID.
                 * This loop may look at and skip many non-LVM devices.
                 */
-               if (!label_read_pvid(dev)) {
+               if (!label_read_pvid(dev, &has_pvid)) {
+                       no_pvid++;
+                       continue;
+               }
+
+               if (!has_pvid) {
                        no_pvid++;
                        continue;
                }
index 9ebbb4ec90ec9017a71b3b58ed25310779a383dc..cfb9ebc80b352a232f4475d81c47bbea245424a8 100644 (file)
@@ -1277,7 +1277,7 @@ int label_scan(struct cmd_context *cmd)
  * Read the header of the disk and if it's a PV
  * save the pvid in dev->pvid.
  */
-int label_read_pvid(struct device *dev)
+int label_read_pvid(struct device *dev, int *has_pvid)
 {
        char buf[4096] __attribute__((aligned(8)));
        struct label_header *lh;
@@ -1296,14 +1296,17 @@ int label_read_pvid(struct device *dev)
         */
        if (!dev_read_bytes(dev, 0, 4096, buf)) {
                label_scan_invalidate(dev);
-               return 0;
+               return_0;
        }
 
+       if (has_pvid)
+               *has_pvid = 0;
+
        lh = (struct label_header *)(buf + 512);
        if (memcmp(lh->id, LABEL_ID, sizeof(lh->id))) {
                /* Not an lvm deice */
                label_scan_invalidate(dev);
-               return 0;
+               return 1;
        }
 
        /*
@@ -1313,9 +1316,12 @@ int label_read_pvid(struct device *dev)
        if (memcmp(lh->type, LVM2_LABEL, sizeof(lh->type))) {
                /* Not an lvm deice */
                label_scan_invalidate(dev);
-               return 0;
+               return 1;
        }
 
+       if (has_pvid)
+               *has_pvid = 1;
+
        pvh = (struct pv_header *)(buf + 512 + 32);
        memcpy(dev->pvid, pvh->pv_uuid, ID_LEN);
        return 1;
index fae0f1bcc12d0771e14fa0b4fd37a04087dbbc24..fcdc309ac4f0d5f24a19f74faa03ff690f971764 100644 (file)
@@ -117,7 +117,7 @@ int label_scan_open(struct device *dev);
 int label_scan_open_excl(struct device *dev);
 int label_scan_open_rw(struct device *dev);
 int label_scan_reopen_rw(struct device *dev);
-int label_read_pvid(struct device *dev);
+int label_read_pvid(struct device *dev, int *has_pvid);
 
 int label_scan_for_pvid(struct cmd_context *cmd, char *pvid, struct device **dev_out);
 
index b67db7464e37eb1dc114fc8c6b7eaba8054f6f70..6b3e05683991988a7aa3fa514068ff18576dd541 100644 (file)
@@ -62,8 +62,12 @@ static void _search_devs_for_pvids(struct cmd_context *cmd, struct dm_list *sear
         * searching for.
         */
        dm_list_iterate_items_safe(devl, devl2, &devs) {
+               int has_pvid;
+
                /* sets dev->pvid if an lvm label with pvid is found */
-               if (!label_read_pvid(devl->dev))
+               if (!label_read_pvid(devl->dev, &has_pvid))
+                       continue;
+               if (!has_pvid)
                        continue;
 
                found = 0;
@@ -181,7 +185,8 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
                                continue;
                        dev = du->dev;
 
-                       label_read_pvid(dev);
+                       if (!label_read_pvid(dev, NULL))
+                               continue;
 
                        /*
                         * label_read_pvid has read the first 4K of the device
@@ -283,7 +288,10 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
                 * (it's ok if the device is not a PV and has no PVID)
                 */
                label_scan_setup_bcache();
-               label_read_pvid(dev);
+               if (!label_read_pvid(dev, NULL)) {
+                       log_error("Failed to read %s.", devname);
+                       goto bad;
+               }
 
                /*
                 * Allow filtered devices to be added to devices_file, but
index df38e17584f23a3e7330ca8760ce8457c1472c4b..f8d27372b4ae38dbacb5f21e09cec64ba9a13596 100644 (file)
@@ -1546,7 +1546,15 @@ static int _pvscan_cache_args(struct cmd_context *cmd, int argc, char **argv,
        label_scan_setup_bcache();
 
        dm_list_iterate_items_safe(devl, devl2, &pvscan_devs) {
-               if (!label_read_pvid(devl->dev)) {
+               int has_pvid;
+
+               if (!label_read_pvid(devl->dev, &has_pvid)) {
+                       log_print("pvscan[%d] %s cannot read.", getpid(), dev_name(devl->dev));
+                       dm_list_del(&devl->list);
+                       continue;
+               }
+
+               if (!has_pvid) {
                        /* Not an lvm device */
                        log_print("pvscan[%d] %s not an lvm device.", getpid(), dev_name(devl->dev));
                        dm_list_del(&devl->list);
This page took 0.052557 seconds and 5 git commands to generate.