1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

scan: fix missing close in lib

lib was using dev_test_excl which wasn't closing the device.
Switch code to new io layer with excl open.
Also use exclusive open in some other places.
This commit is contained in:
David Teigland 2018-05-16 13:24:00 -05:00
parent 64dd656ef7
commit 28d35e5c59
5 changed files with 11 additions and 15 deletions

View File

@ -114,7 +114,7 @@ int label_remove(struct device *dev)
log_very_verbose("Scanning for labels to wipe from %s", dev_name(dev));
if (!label_scan_open(dev)) {
if (!label_scan_open_excl(dev)) {
log_error("Failed to open device %s", dev_name(dev));
return 0;
}
@ -977,6 +977,12 @@ int label_scan_open(struct device *dev)
return 1;
}
int label_scan_open_excl(struct device *dev)
{
dev->flags |= DEV_BCACHE_EXCL;
return label_scan_open(dev);
}
bool dev_read_bytes(struct device *dev, uint64_t start, size_t len, void *data)
{
if (!scan_bcache) {

View File

@ -114,6 +114,7 @@ int label_read_sector(struct device *dev, uint64_t scan_sector);
void label_scan_confirm(struct device *dev);
int label_scan_setup_bcache(void);
int label_scan_open(struct device *dev);
int label_scan_open_excl(struct device *dev);
/*
* Wrappers around bcache equivalents.

View File

@ -227,13 +227,12 @@ static int _pvcreate_check(struct cmd_context *cmd, const char *name,
/*
* This test will fail if the device belongs to an MD array.
*/
if (!dev_test_excl(dev)) {
if (!label_scan_open_excl(dev)) {
/* FIXME Detect whether device-mapper itself is still using it */
log_error("Can't open %s exclusively. Mounted filesystem?",
name);
goto out;
}
dev_close(dev);
if (!wipe_known_signatures(cmd, dev, name,
TYPE_LVM1_MEMBER | TYPE_LVM2_MEMBER,
@ -578,16 +577,6 @@ static int _pvremove_single(struct cmd_context *cmd, const char *pv_name,
goto out;
}
// FIXME: why is this called if info is not used?
//info = lvmcache_info_from_pvid(dev->pvid, dev, 0);
if (!dev_test_excl(dev)) {
/* FIXME Detect whether device-mapper is still using the device */
log_error("Can't open %s exclusively - not removing. "
"Mounted filesystem?", dev_name(dev));
goto out;
}
/* Wipe existing label(s) */
if (!label_remove(dev)) {
log_error("Failed to wipe existing label(s) on %s", pv_name);

View File

@ -1413,7 +1413,7 @@ static int _pvcreate_write(struct cmd_context *cmd, struct pv_to_write *pvw)
struct device *dev = pv->dev;
const char *pv_name = dev_name(dev);
if (!label_scan_open(dev)) {
if (!label_scan_open_excl(dev)) {
log_error("%s not opened: device not written", pv_name);
return 0;
}

View File

@ -5785,7 +5785,7 @@ do_command:
pv_name = pd->name;
label_scan_open(pd->dev);
label_scan_open_excl(pd->dev);
log_debug("Creating a new PV on %s.", pv_name);