btrfs-progs: report I/O errors when closing the filesystem
[platform/upstream/btrfs-progs.git] / volumes.c
index d87fd70..b350e25 100644 (file)
--- a/volumes.c
+++ b/volumes.c
@@ -160,6 +160,7 @@ int btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
 {
        struct btrfs_fs_devices *seed_devices;
        struct btrfs_device *device;
+       int ret = 0;
 
 again:
        if (!fs_devices)
@@ -168,7 +169,11 @@ again:
                device = list_entry(fs_devices->devices.next,
                                    struct btrfs_device, dev_list);
                if (device->fd != -1) {
-                       fsync(device->fd);
+                       if (fsync(device->fd) == -1) {
+                               warning("fsync on device %llu failed: %s",
+                                       device->devid, strerror(errno));
+                               ret = -errno;
+                       }
                        if (posix_fadvise(device->fd, 0, 0, POSIX_FADV_DONTNEED))
                                fprintf(stderr, "Warning, could not drop caches\n");
                        close(device->fd);
@@ -197,7 +202,7 @@ again:
                free(fs_devices);
        }
 
-       return 0;
+       return ret;
 }
 
 void btrfs_close_all_devices(void)
@@ -684,8 +689,7 @@ out:
        return ret;
 }
 
-int btrfs_add_system_chunk(struct btrfs_trans_handle *trans,
-                          struct btrfs_root *root,
+int btrfs_add_system_chunk(struct btrfs_root *root,
                           struct btrfs_key *key,
                           struct btrfs_chunk *chunk, int item_size)
 {
@@ -1078,7 +1082,7 @@ again:
        BUG_ON(ret);
 
        if (type & BTRFS_BLOCK_GROUP_SYSTEM) {
-               ret = btrfs_add_system_chunk(trans, chunk_root, &key,
+               ret = btrfs_add_system_chunk(chunk_root, &key,
                                    chunk, btrfs_chunk_item_size(num_stripes));
                BUG_ON(ret);
        }