summaryrefslogtreecommitdiff
path: root/lib/label
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2021-04-23 17:32:37 -0500
committerDavid Teigland <teigland@redhat.com>2021-04-23 17:37:08 -0500
commit4dc5d4ac7e7a9457ccc46ff04796b347e58bf4da (patch)
tree1351a95314ea922a11e2f40677fc614fc206a457 /lib/label
parentfcbed26393f57d49daa7da73922b1a922f9523a2 (diff)
downloadlvm2-4dc5d4ac7e7a9457ccc46ff04796b347e58bf4da.tar.gz
label_read_pvid: separate error and no-pvid
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.
Diffstat (limited to 'lib/label')
-rw-r--r--lib/label/label.c14
-rw-r--r--lib/label/label.h2
2 files changed, 11 insertions, 5 deletions
diff --git a/lib/label/label.c b/lib/label/label.c
index 9ebbb4ec9..cfb9ebc80 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -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;
diff --git a/lib/label/label.h b/lib/label/label.h
index fae0f1bcc..fcdc309ac 100644
--- a/lib/label/label.h
+++ b/lib/label/label.h
@@ -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);