]> sourceware.org Git - lvm2.git/commitdiff
fix dev_unset_last_byte after write error
authorHeming Zhao <heming.zhao@suse.com>
Wed, 13 Nov 2019 15:15:07 +0000 (09:15 -0600)
committerDavid Teigland <teigland@redhat.com>
Wed, 13 Nov 2019 15:36:58 +0000 (09:36 -0600)
dev_unset_last_byte() must be called while the fd is still valid.
After a write error, dev_unset_last_byte() must be called before
closing the dev and resetting the fd.

In the write error path, dev_unset_last_byte() was being called
after label_scan_invalidate() which meant that it would not unset
the last_byte values.

After a write error, dev_unset_last_byte() is now called in
dev_write_bytes() before label_scan_invalidate(), instead of by
the caller of dev_write_bytes().

In the common case of a successful write, the sequence is still:
dev_set_last_byte(); dev_write_bytes(); dev_unset_last_byte();

Signed-off-by: Zhao Heming <heming.zhao@suse.com>
lib/format_text/format-text.c
lib/label/label.c
lib/metadata/mirror.c

index 6ec47bfcef997f33c297da6f4441183fcbbb606b..894a71007d8c39192f653867116255f92bdc2867 100644 (file)
@@ -277,7 +277,6 @@ static int _raw_write_mda_header(const struct format_type *fmt,
        dev_set_last_byte(dev, start_byte + MDA_HEADER_SIZE);
 
        if (!dev_write_bytes(dev, start_byte, MDA_HEADER_SIZE, mdah)) {
-               dev_unset_last_byte(dev);
                log_error("Failed to write mda header to %s fd %d", dev_name(dev), dev->bcache_fd);
                return 0;
        }
@@ -989,7 +988,6 @@ static int _vg_write_raw(struct format_instance *fid, struct volume_group *vg,
 
        if (!dev_write_bytes(mdac->area.dev, write1_start, (size_t)write1_size, write_buf)) {
                log_error("Failed to write metadata to %s fd %d", devname, mdac->area.dev->bcache_fd);
-               dev_unset_last_byte(mdac->area.dev);
                goto out;
        }
 
@@ -1002,7 +1000,6 @@ static int _vg_write_raw(struct format_instance *fid, struct volume_group *vg,
                if (!dev_write_bytes(mdac->area.dev, write2_start, write2_size,
                                     write_buf + new_size - new_wrap)) {
                        log_error("Failed to write metadata wrap to %s fd %d", devname, mdac->area.dev->bcache_fd);
-                       dev_unset_last_byte(mdac->area.dev);
                        goto out;
                }
        }
index 7dcaf8afd55475fad20082c15589b671410e8f38..05986cbe7086adfb9241e9e93cd28a367d4e2441 100644 (file)
@@ -218,7 +218,7 @@ int label_write(struct device *dev, struct label *label)
 
        if (!dev_write_bytes(dev, offset, LABEL_SIZE, buf)) {
                log_debug_devs("Failed to write label to %s", dev_name(dev));
-               r = 0;
+               return 0;
        }
 
        dev_unset_last_byte(dev);
@@ -655,7 +655,6 @@ static int _scan_list(struct cmd_context *cmd, struct dev_filter *f,
        int submit_count;
        int scan_failed;
        int is_lvm_device;
-       int error;
        int ret;
 
        dm_list_init(&wait_devs);
@@ -702,12 +701,11 @@ static int _scan_list(struct cmd_context *cmd, struct dev_filter *f,
 
        dm_list_iterate_items_safe(devl, devl2, &wait_devs) {
                bb = NULL;
-               error = 0;
                scan_failed = 0;
                is_lvm_device = 0;
 
                if (!bcache_get(scan_bcache, devl->dev->bcache_fd, 0, 0, &bb)) {
-                       log_debug_devs("Scan failed to read %s error %d.", dev_name(devl->dev), error);
+                       log_debug_devs("Scan failed to read %s.", dev_name(devl->dev));
                        scan_failed = 1;
                        scan_read_errors++;
                        scan_failed_count++;
@@ -1451,6 +1449,7 @@ bool dev_write_bytes(struct device *dev, uint64_t start, size_t len, void *data)
        if (!bcache_write_bytes(scan_bcache, dev->bcache_fd, start, len, data)) {
                log_error("Error writing device %s at %llu length %u.",
                          dev_name(dev), (unsigned long long)start, (uint32_t)len);
+               dev_unset_last_byte(dev);
                label_scan_invalidate(dev);
                return false;
        }
@@ -1458,6 +1457,7 @@ bool dev_write_bytes(struct device *dev, uint64_t start, size_t len, void *data)
        if (!bcache_flush(scan_bcache)) {
                log_error("Error writing device %s at %llu length %u.",
                          dev_name(dev), (unsigned long long)start, (uint32_t)len);
+               dev_unset_last_byte(dev);
                label_scan_invalidate(dev);
                return false;
        }
index 01f0246b90862e0f418c7ffe68c75bb6ab3e2ff3..d8803b3e3f30000bb3faa952d65f30c3bbf01a94 100644 (file)
@@ -266,7 +266,6 @@ static int _write_log_header(struct cmd_context *cmd, struct logical_volume *lv)
        dev_set_last_byte(dev, sizeof(log_header));
 
        if (!dev_write_bytes(dev, UINT64_C(0), sizeof(log_header), &log_header)) {
-               dev_unset_last_byte(dev);
                log_error("Failed to write log header to %s.", name);
                return 0;
        }
This page took 0.041934 seconds and 5 git commands to generate.