btrfs-progs: image: pass rb_root to find_collisions
[platform/upstream/btrfs-progs.git] / qgroup.c
index cd9f5a7..fffdbb1 100644 (file)
--- a/qgroup.c
+++ b/qgroup.c
@@ -480,7 +480,7 @@ int btrfs_qgroup_setup_comparer(struct btrfs_qgroup_comparer_set  **comp_set,
                *comp_set = set;
        }
 
-       ASSERT(set->comps[set->ncomps].comp_func != NULL);
+       ASSERT(set->comps[set->ncomps].comp_func == NULL);
 
        set->comps[set->ncomps].comp_func = all_comp_funcs[comparer];
        set->comps[set->ncomps].is_descending = is_descending;
@@ -847,7 +847,7 @@ int btrfs_qgroup_setup_filter(struct btrfs_qgroup_filter_set **filter_set,
                *filter_set = set;
        }
 
-       ASSERT(set->filters[set->nfilters].filter_func != NULL);
+       ASSERT(set->filters[set->nfilters].filter_func == NULL);
        set->filters[set->nfilters].filter_func = all_filter_funcs[filter];
        set->filters[set->nfilters].data = data;
        set->nfilters++;
@@ -1064,11 +1064,9 @@ static int __qgroups_search(int fd, struct qgroup_lookup *qgroup_lookup)
 
        while (1) {
                ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
-               if (ret < 0) {
-                       error("cannot perform the search: %s",
-                                       strerror(errno));
-                       return ret;
-               }
+               if (ret < 0)
+                       return -errno;
+
                /* the ioctl returns the number of item it found in nr_items */
                if (sk->nr_items == 0)
                        break;
@@ -1209,23 +1207,7 @@ int btrfs_show_qgroups(int fd,
        return ret;
 }
 
-u64 btrfs_get_path_rootid(int fd)
-{
-       int  ret;
-       struct btrfs_ioctl_ino_lookup_args args;
-
-       memset(&args, 0, sizeof(args));
-       args.objectid = BTRFS_FIRST_FREE_OBJECTID;
-
-       ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args);
-       if (ret < 0) {
-               error("cannot perform the search: %s", strerror(errno));
-               return ret;
-       }
-       return args.treeid;
-}
-
-int btrfs_qgroup_parse_sort_string(char *opt_arg,
+int btrfs_qgroup_parse_sort_string(const char *opt_arg,
                                   struct btrfs_qgroup_comparer_set **comps)
 {
        int order;
@@ -1233,8 +1215,14 @@ int btrfs_qgroup_parse_sort_string(char *opt_arg,
        char *p;
        char **ptr_argv;
        int what_to_sort;
+       char *opt_tmp;
+       int ret = 0;
 
-       while ((p = strtok(opt_arg, ",")) != NULL) {
+       opt_tmp = strdup(opt_arg);
+       if (!opt_tmp)
+               return -ENOMEM;
+
+       while ((p = strtok(opt_tmp, ",")) != NULL) {
                flag = 0;
                ptr_argv = all_sort_items;
 
@@ -1254,10 +1242,10 @@ int btrfs_qgroup_parse_sort_string(char *opt_arg,
                        ptr_argv++;
                }
 
-               if (flag == 0)
-                       return -1;
-
-               else {
+               if (flag == 0) {
+                       ret = -1;
+                       goto out;
+               else {
                        if (*p == '+') {
                                order = 0;
                                p++;
@@ -1268,14 +1256,19 @@ int btrfs_qgroup_parse_sort_string(char *opt_arg,
                                order = 0;
 
                        what_to_sort = btrfs_qgroup_get_sort_item(p);
-                       if (what_to_sort < 0)
-                               return -1;
+                       if (what_to_sort < 0) {
+                               ret = -1;
+                               goto out;
+                       }
                        btrfs_qgroup_setup_comparer(comps, what_to_sort, order);
                }
-               opt_arg = NULL;
+               free(opt_tmp);
+               opt_tmp = NULL;
        }
 
-       return 0;
+out:
+       free(opt_tmp);
+       return ret;
 }
 
 int qgroup_inherit_size(struct btrfs_qgroup_inherit *p)