]> sourceware.org Git - lvm2.git/commitdiff
io: replace dev_set with bcache equivalents
authorDavid Teigland <teigland@redhat.com>
Wed, 9 May 2018 15:34:28 +0000 (10:34 -0500)
committerDavid Teigland <teigland@redhat.com>
Wed, 9 May 2018 16:29:52 +0000 (11:29 -0500)
lib/label/label.c
lib/label/label.h
lib/locking/lvmlockd.c
lib/metadata/lv_manip.c
lib/metadata/metadata-liblvm.c

index d6a5727e84af13bb1092b95a471bf3a63bdeb723..8b60780cc2b40853b787d6df8da38c4391eeb073 100644 (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;
+}
+
index 55e92e8d4f961cb393fabdc1a501036c319dafdc..bccf777db072e6d2f16a363031dac1f015f2cdf3 100644 (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
index 0521ede1739bc49193053820258517f545fca05e..d78b35c88cb04e7819558bdd641719bace51cfea 100644 (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;
 }
 
index 8bf93795eb1b33b39af9ef561b22ac73230a4b40..84953bbdf87b169eefad96538161dfb9c29218ae 100644 (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;
index 2dc375781273bcf339b8227d4f145d019efc8ad6..f7a07a504533f5872fc86bfc56bcce0cd2b4e82f 100644 (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;
                }
        }
 
This page took 0.05317 seconds and 5 git commands to generate.