mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
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.
This commit is contained in:
parent
fcbed26393
commit
4dc5d4ac7e
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user