btrfs-progs: chunk-recover: improve error handling in insert_stripe
authorDavid Sterba <dsterba@suse.com>
Tue, 6 Sep 2016 11:39:41 +0000 (13:39 +0200)
committerDavid Sterba <dsterba@suse.com>
Wed, 21 Sep 2016 12:12:38 +0000 (14:12 +0200)
Switch to negative errnos, the callchain handles errors.

Signed-off-by: David Sterba <dsterba@suse.com>
chunk-recover.c

index 4a081db..f1f9849 100644 (file)
@@ -1947,9 +1947,12 @@ static int insert_stripe(struct list_head *devexts,
        dev = btrfs_find_device_by_devid(rc->fs_devices, devext->objectid,
                                        0);
        if (!dev)
-               return 1;
-       BUG_ON(btrfs_find_device_by_devid(rc->fs_devices, devext->objectid,
-                                       1));
+               return -ENOENT;
+       if (btrfs_find_device_by_devid(rc->fs_devices, devext->objectid, 1)) {
+               error("unexpected: found another device with id %llu",
+                               (unsigned long long)devext->objectid);
+               return -EINVAL;
+       }
 
        chunk->stripes[index].devid = devext->objectid;
        chunk->stripes[index].offset = devext->offset;