sizeof(struct btrfs_qgroup_comparer);
set = calloc(1, size);
if (!set) {
- fprintf(stderr, "memory allocation failed\n");
+ error("memory allocation failed");
exit(1);
}
return set;
}
-void btrfs_qgroup_free_comparer_set(struct btrfs_qgroup_comparer_set *comp_set)
-{
- free(comp_set);
-}
-
int btrfs_qgroup_setup_comparer(struct btrfs_qgroup_comparer_set **comp_set,
enum btrfs_qgroup_comp_enum comparer,
int is_descending)
tmp = set;
set = realloc(set, size);
if (!set) {
- fprintf(stderr, "memory allocation failed\n");
+ error("memory allocation failed");
free(tmp);
exit(1);
}
*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;
if (pa && child) {
list = malloc(sizeof(*list));
if (!list) {
- fprintf(stderr, "memory allocation failed\n");
+ error("memory allocation failed");
exit(1);
}
list->qgroup = pa;
bq = calloc(1, sizeof(*bq));
if (!bq) {
- printf("memory allocation failed\n");
+ error("memory allocation failed");
exit(1);
}
if (qgroupid) {
if (parent && child) {
list = malloc(sizeof(*list));
if (!list) {
- fprintf(stderr, "memory allocation failed\n");
+ error("memory allocation failed");
exit(1);
}
list->qgroup = parent;
}
ret = qgroup_tree_insert(qgroup_lookup, bq);
if (ret) {
- printf("failed to insert tree %llu\n",
- bq->qgroupid);
+ error("failed to insert %llu into tree: %s",
+ (unsigned long long)bq->qgroupid, strerror(-ret));
exit(1);
}
return ret;
sizeof(struct btrfs_qgroup_filter);
set = calloc(1, size);
if (!set) {
- fprintf(stderr, "memory allocation failed\n");
+ error("memory allocation failed");
exit(1);
}
set->total = BTRFS_QGROUP_NFILTERS_INCREASE;
return set;
}
-void btrfs_qgroup_free_filter_set(struct btrfs_qgroup_filter_set *filter_set)
-{
- free(filter_set);
-}
-
int btrfs_qgroup_setup_filter(struct btrfs_qgroup_filter_set **filter_set,
enum btrfs_qgroup_filter_enum filter, u64 data)
{
tmp = set;
set = realloc(set, size);
if (!set) {
- fprintf(stderr, "memory allocation failed\n");
+ error("memory allocation failed");
free(tmp);
exit(1);
}
*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++;
static inline void print_status_flag_warning(u64 flags)
{
if (!(flags & BTRFS_QGROUP_STATUS_FLAG_ON))
- fprintf(stderr,
- "WARNING: Quota disabled, qgroup data may be out of date\n");
+ warning("quota disabled, qgroup data may be out of date");
else if (flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN)
- fprintf(stderr,
- "WARNING: Rescan is running, qgroup data may be incorrect\n");
+ warning("rescan is running, qgroup data may be incorrect");
else if (flags & BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT)
- fprintf(stderr,
- "WARNING: Qgroup data inconsistent, rescan recommended\n");
+ warning("qgroup data inconsistent, rescan recommended");
}
static int __qgroups_search(int fd, struct qgroup_lookup *qgroup_lookup)
while (1) {
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
- if (ret < 0) {
- fprintf(stderr,
- "ERROR: can't perform the search - %s\n",
- 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;
print_all_qgroups(&sort_tree);
__free_all_qgroups(&qgroup_lookup);
- btrfs_qgroup_free_filter_set(filter_set);
- btrfs_qgroup_free_comparer_set(comp_set);
+ free(filter_set);
+ free(comp_set);
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) {
- fprintf(stderr,
- "ERROR: can't perform the search - %s\n",
- 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;
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;
ptr_argv++;
}
- if (flag == 0)
- return -1;
-
- else {
+ if (flag == 0) {
+ ret = -1;
+ goto out;
+ } else {
if (*p == '+') {
order = 0;
p++;
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)
out = calloc(sizeof(*out) + sizeof(out->qgroups[0]) * (nitems + n), 1);
if (out == NULL) {
- fprintf(stderr, "ERROR: Not enough memory\n");
+ error("not enough memory");
return -ENOMEM;
}
int pos = 0;
if (qgroupid == 0) {
- fprintf(stderr, "ERROR: bad qgroup specification\n");
+ error("invalid qgroup specification, qgroupid must not 0");
return -EINVAL;
}
p = strchr(arg, ':');
if (!p) {
bad:
- fprintf(stderr, "ERROR: bad copy specification\n");
+ error("invalid copy specification, missing separator :");
return -EINVAL;
}
*p = 0;