summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2020-10-15 14:05:45 -0500
committerDavid Teigland <teigland@redhat.com>2020-10-21 16:24:16 -0500
commit677f829e540ef0f2fa2781f4facc7571dee1fb83 (patch)
tree33a1fd4035d6911fdc2ab5685e3a5af02f4e98c0
parentc7311d472203614b229cf17606d14fb53df85945 (diff)
downloadlvm2-677f829e540ef0f2fa2781f4facc7571dee1fb83.tar.gz
add label_read_pvid
To read the lvm headers and set dev->pvid if the device is a PV. Difference from label_scan_ functions is this does not read any vg metadata or add any info to lvmcache.
-rw-r--r--lib/label/label.c48
-rw-r--r--lib/label/label.h1
2 files changed, 49 insertions, 0 deletions
diff --git a/lib/label/label.c b/lib/label/label.c
index a47cd1731..bc8e60fc9 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -1255,6 +1255,54 @@ 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)
+{
+ char buf[4096] __attribute__((aligned(8)));
+ struct label_header *lh;
+ struct pv_header *pvh;
+
+ memset(buf, 0, sizeof(buf));
+
+ if (!label_scan_open(dev))
+ return_0;
+
+ /*
+ * We could do:
+ * dev_read_bytes(dev, 512, LABEL_SIZE, buf);
+ * which works, but there's a bcache issue that
+ * prevents proper invalidation after that.
+ */
+ if (!dev_read_bytes(dev, 0, 4096, buf)) {
+ label_scan_invalidate(dev);
+ return 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;
+ }
+
+ /*
+ * wipefs -a just clears the type field, leaving the
+ * rest of the label_header intact.
+ */
+ if (memcmp(lh->type, LVM2_LABEL, sizeof(lh->type))) {
+ /* Not an lvm deice */
+ label_scan_invalidate(dev);
+ return 0;
+ }
+
+ pvh = (struct pv_header *)(buf + 512 + 32);
+ memcpy(dev->pvid, pvh->pv_uuid, ID_LEN);
+ return 1;
+}
+
+/*
* Scan and cache lvm data from the listed devices. If a device is already
* scanned and cached, this replaces the previously cached lvm data for the
* device. This is called when vg_read() wants to guarantee that it is using
diff --git a/lib/label/label.h b/lib/label/label.h
index 8778c17a8..ddfb34af5 100644
--- a/lib/label/label.h
+++ b/lib/label/label.h
@@ -117,6 +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_scan_for_pvid(struct cmd_context *cmd, char *pvid, struct device **dev_out);