*/
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
/*
* 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;
}
* 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;
*/
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;
}
/*
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;
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);
* 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;
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
* (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
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);