btrfs-progs: alias btrfs device delete to btrfs device remove
[platform/upstream/btrfs-progs.git] / btrfstune.c
index dd5626e..6f07f31 100644 (file)
@@ -24,6 +24,7 @@
 #include <unistd.h>
 #include <dirent.h>
 #include <uuid/uuid.h>
+#include <getopt.h>
 
 #include "kerncompat.h"
 #include "ctree.h"
@@ -321,6 +322,7 @@ static int change_uuid(struct btrfs_fs_info *fs_info, const char *new_fsid_str)
 {
        uuid_t new_fsid;
        uuid_t new_chunk_id;
+       uuid_t old_fsid;
        char uuid_buf[BTRFS_UUID_UNPARSED_SIZE];
        int ret = 0;
 
@@ -347,14 +349,20 @@ static int change_uuid(struct btrfs_fs_info *fs_info, const char *new_fsid_str)
        fs_info->new_fsid = new_fsid;
        fs_info->new_chunk_tree_uuid = new_chunk_id;
 
-       uuid_unparse_upper(new_fsid, uuid_buf);
-       printf("Changing fsid to %s\n", uuid_buf);
+       memcpy(old_fsid, (const char*)fs_info->fsid, BTRFS_UUID_SIZE);
+       uuid_unparse(old_fsid, uuid_buf);
+       printf("Current fsid: %s\n", uuid_buf);
+
+       uuid_unparse(new_fsid, uuid_buf);
+       printf("New fsid: %s\n", uuid_buf);
        /* Now we can begin fsid change */
+       printf("Set superblock flag CHANGING_FSID\n");
        ret = change_fsid_prepare(fs_info);
        if (ret < 0)
                goto out;
 
        /* Change extents first */
+       printf("Change fsid in extents\n");
        ret = change_extents_uuid(fs_info);
        if (ret < 0) {
                fprintf(stderr, "Failed to change UUID of metadata\n");
@@ -362,6 +370,7 @@ static int change_uuid(struct btrfs_fs_info *fs_info, const char *new_fsid_str)
        }
 
        /* Then devices */
+       printf("Change fsid on devices\n");
        ret = change_devices_uuid(fs_info);
        if (ret < 0) {
                fprintf(stderr, "Failed to change UUID of devices\n");
@@ -378,10 +387,11 @@ static int change_uuid(struct btrfs_fs_info *fs_info, const char *new_fsid_str)
                goto out;
 
        /* Now fsid change is done */
+       printf("Clear superblock flag CHANGING_FSID\n");
        ret = change_fsid_done(fs_info);
        fs_info->new_fsid = NULL;
        fs_info->new_chunk_tree_uuid = NULL;
-       printf("Fsid changed to %s\n", uuid_buf);
+       printf("Fsid change finished\n");
 out:
        return ret;
 }
@@ -413,7 +423,12 @@ int main(int argc, char *argv[])
 
        optind = 1;
        while(1) {
-               int c = getopt(argc, argv, "S:rxfuU:n");
+               static const struct option long_options[] = {
+                       { "help", no_argument, NULL, GETOPT_VAL_HELP},
+                       { NULL, 0, NULL, 0 }
+               };
+               int c = getopt_long(argc, argv, "S:rxfuU:n", long_options, NULL);
+
                if (c < 0)
                        break;
                switch(c) {
@@ -441,9 +456,10 @@ int main(int argc, char *argv[])
                        ctree_flags |= OPEN_CTREE_IGNORE_FSID_MISMATCH;
                        random_fsid = 1;
                        break;
+               case GETOPT_VAL_HELP:
                default:
                        print_usage();
-                       return 1;
+                       return c != GETOPT_VAL_HELP;
                }
        }