btrfs-progs: unify getopt table terminators
[platform/upstream/btrfs-progs.git] / btrfs-convert.c
index 6e2ab0f..bbd19bb 100644 (file)
@@ -31,6 +31,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <uuid/uuid.h>
+#include <linux/limits.h>
 
 #include "ctree.h"
 #include "disk-io.h"
@@ -2418,8 +2419,17 @@ static int may_rollback(struct btrfs_root *root)
        while (1) {
                ret = btrfs_map_block(&info->mapping_tree, WRITE, bytenr,
                                      &length, &multi, 0, NULL);
-               if (ret)
+               if (ret) {
+                       if (ret == -ENOENT) {
+                               /* removed block group at the tail */
+                               if (length == (u64)-1)
+                                       break;
+
+                               /* removed block group in the middle */
+                               goto next;
+                       }
                        goto fail;
+               }
 
                num_stripes = multi->num_stripes;
                physical = multi->stripes[0].physical;
@@ -2427,7 +2437,7 @@ static int may_rollback(struct btrfs_root *root)
 
                if (num_stripes != 1 || physical != bytenr)
                        goto fail;
-
+next:
                bytenr += length;
                if (bytenr >= total_bytes)
                        break;
@@ -2665,6 +2675,12 @@ next_extent:
                if (bytenr >= total_bytes)
                        break;
                ret = pwrite(fd, buf, sectorsize, bytenr);
+               if (ret != sectorsize) {
+                       fprintf(stderr,
+                               "error during zeroing supreblock %d: %d\n",
+                               i, ret);
+                       goto fail;
+               }
        }
 
        sb_bytenr = (u64)-1;