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;
}
-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;
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;
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) {
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;
+}
+
* 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
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;
}
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\"",
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;
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;
}
}