1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-11-09 07:21:10 +03:00

io: replace dev_set with bcache equivalents

This commit is contained in:
David Teigland 2018-05-09 10:34:28 -05:00
parent 3600caa71d
commit 9a5bd01b0c
5 changed files with 62 additions and 41 deletions

View File

@ -884,7 +884,7 @@ int label_scan_open(struct device *dev)
return 1;
}
bool dev_read_bytes(struct device *dev, off_t start, size_t len, void *data)
bool dev_read_bytes(struct device *dev, uint64_t start, size_t len, void *data)
{
int ret;
@ -918,7 +918,7 @@ bool dev_read_bytes(struct device *dev, off_t start, size_t len, void *data)
}
bool dev_write_bytes(struct device *dev, off_t start, size_t len, void *data)
bool dev_write_bytes(struct device *dev, uint64_t start, size_t len, void *data)
{
int ret;
@ -961,7 +961,7 @@ bool dev_write_bytes(struct device *dev, off_t start, size_t len, void *data)
return true;
}
bool dev_write_zeros(struct device *dev, off_t start, size_t len)
bool dev_write_zeros(struct device *dev, uint64_t start, size_t len)
{
int ret;
@ -969,15 +969,8 @@ bool dev_write_zeros(struct device *dev, off_t start, size_t len)
return true;
if (!scan_bcache) {
if (!dev_open(dev))
return false;
ret = dev_set(dev, start, len, 0, 0);
if (!dev_close(dev))
stack;
return ret ? true : false;
log_error("dev_write_zeros %s bcache not set up", dev_name(dev));
return false;
}
if (dev->bcache_fd <= 0) {
@ -1004,3 +997,39 @@ bool dev_write_zeros(struct device *dev, off_t start, size_t len)
return true;
}
bool dev_set_bytes(struct device *dev, uint64_t start, size_t len, uint8_t val)
{
int ret;
if (test_mode())
return true;
if (!scan_bcache) {
log_error("dev_set_bytes %s bcache not set up", dev_name(dev));
return false;
}
if (dev->bcache_fd <= 0) {
/* This is not often needed, perhaps only with lvmetad. */
if (!label_scan_open(dev)) {
log_error("dev_set_bytes %s cannot open dev", dev_name(dev));
return false;
}
}
if (!bcache_set_bytes(scan_bcache, dev->bcache_fd, start, len, val)) {
log_error("dev_set_bytes %s at %u bcache write failed invalidate fd %d",
dev_name(dev), (uint32_t)start, dev->bcache_fd);
label_scan_invalidate(dev);
return false;
}
if (!bcache_flush(scan_bcache)) {
log_error("dev_set_bytes %s at %u bcache flush failed invalidate fd %d",
dev_name(dev), (uint32_t)start, dev->bcache_fd);
label_scan_invalidate(dev);
return false;
}
return true;
}

View File

@ -119,8 +119,9 @@ int label_scan_open(struct device *dev);
* Wrappers around bcache equivalents.
* (these make it easier to disable bcache and revert to direct rw if needed)
*/
bool dev_read_bytes(struct device *dev, off_t start, size_t len, void *data);
bool dev_write_bytes(struct device *dev, off_t start, size_t len, void *data);
bool dev_write_zeros(struct device *dev, off_t start, size_t len);
bool dev_read_bytes(struct device *dev, uint64_t start, size_t len, void *data);
bool dev_write_bytes(struct device *dev, uint64_t start, size_t len, void *data);
bool dev_write_zeros(struct device *dev, uint64_t start, size_t len);
bool dev_set_bytes(struct device *dev, uint64_t start, size_t len, uint8_t val);
#endif

View File

@ -403,22 +403,17 @@ static int _extend_sanlock_lv(struct cmd_context *cmd, struct volume_group *vg,
return 0;
}
if (!dev_open_quiet(dev)) {
if (!label_scan_open(dev)) {
log_error("Extend sanlock LV %s cannot open device.", display_lvname(lv));
return 0;
}
if (!dev_set(dev, old_size_bytes, new_size_bytes - old_size_bytes, DEV_IO_LV, 0)) {
if (!dev_write_zeros(dev, old_size_bytes, new_size_bytes - old_size_bytes)) {
log_error("Extend sanlock LV %s cannot zero device.", display_lvname(lv));
dev_close_immediate(dev);
return 0;
}
dev_flush(dev);
if (!dev_close_immediate(dev))
stack;
label_scan_invalidate(dev);
return 1;
}

View File

@ -7155,8 +7155,10 @@ int wipe_lv(struct logical_volume *lv, struct wipe_params wp)
return 0;
}
if (!dev_open_quiet(dev))
return_0;
if (!label_scan_open(dev)) {
log_error("Failed to open %s/%s for wiping and zeroing.", lv->vg->name, lv->name);
goto out;
}
if (wp.do_wipe_signatures) {
log_verbose("Wiping known signatures on logical volume \"%s/%s\"",
@ -7177,15 +7179,17 @@ int wipe_lv(struct logical_volume *lv, struct wipe_params wp)
display_size(lv->vg->cmd, zero_sectors),
lv->vg->name, lv->name, wp.zero_value);
if (!dev_set(dev, UINT64_C(0), (size_t) zero_sectors << SECTOR_SHIFT, DEV_IO_LV, wp.zero_value))
stack;
if (!wp.zero_value) {
if (!dev_write_zeros(dev, UINT64_C(0), (size_t) zero_sectors << SECTOR_SHIFT))
stack;
} else {
if (!dev_set_bytes(dev, UINT64_C(0), (size_t) zero_sectors << SECTOR_SHIFT, (uint8_t)wp.zero_value))
stack;
}
}
dev_flush(dev);
if (!dev_close_immediate(dev))
stack;
label_scan_invalidate(dev);
out:
lv->status &= ~LV_NOSCAN;
return 1;

View File

@ -66,19 +66,11 @@ static int _pvcreate_write(struct cmd_context *cmd, struct pv_to_write *pvw)
if (pvw->pp->zero) {
log_verbose("Zeroing start of device %s", pv_name);
if (!dev_open_quiet(dev)) {
log_error("%s not opened: device not zeroed", pv_name);
return 0;
}
if (!dev_set(dev, UINT64_C(0), (size_t) 2048, DEV_IO_LABEL, 0)) {
if (!dev_write_zeros(dev, UINT64_C(0), (size_t) 2048)) {
log_error("%s not wiped: aborting", pv_name);
if (!dev_close(dev))
stack;
return 0;
}
if (!dev_close(dev))
stack;
}
}