int len = 0;
list_for_each_entry(list, &qgroup->qgroups, next_qgroup) {
- len += printf("%llu/%llu", (list->qgroup)->qgroupid >> 48,
- ((1ll << 48) - 1) & (list->qgroup)->qgroupid);
+ len += printf("%llu/%llu",
+ btrfs_qgroup_level(list->qgroup->qgroupid),
+ btrfs_qgroup_subvid(list->qgroup->qgroupid));
if (!list_is_last(&list->next_qgroup, &qgroup->qgroups))
len += printf(",");
}
int len = 0;
list_for_each_entry(list, &qgroup->members, next_member) {
- len += printf("%llu/%llu", (list->member)->qgroupid >> 48,
- ((1ll << 48) - 1) & (list->member)->qgroupid);
+ len += printf("%llu/%llu",
+ btrfs_qgroup_level(list->member->qgroupid),
+ btrfs_qgroup_subvid(list->member->qgroupid));
if (!list_is_last(&list->next_member, &qgroup->members))
len += printf(",");
}
switch (column) {
case BTRFS_QGROUP_QGROUPID:
- len = printf("%llu/%llu", qgroup->qgroupid >> 48,
- ((1ll << 48) - 1) & qgroup->qgroupid);
+ len = printf("%llu/%llu",
+ btrfs_qgroup_level(qgroup->qgroupid),
+ btrfs_qgroup_subvid(qgroup->qgroupid));
print_qgroup_column_add_blank(BTRFS_QGROUP_QGROUPID, len);
break;
case BTRFS_QGROUP_RFER:
print_qgroup_column_add_blank(BTRFS_QGROUP_PARENT, len);
break;
case BTRFS_QGROUP_MAX_RFER:
- len = printf("%*s", max_len, pretty_size_mode(qgroup->max_rfer, unit_mode));
+ if (qgroup->flags & BTRFS_QGROUP_LIMIT_MAX_RFER)
+ len = printf("%*s", max_len, pretty_size_mode(qgroup->max_rfer, unit_mode));
+ else
+ len = printf("%*s", max_len, "none");
break;
case BTRFS_QGROUP_MAX_EXCL:
- len = printf("%*s", max_len, pretty_size_mode(qgroup->max_excl, unit_mode));
+ if (qgroup->flags & BTRFS_QGROUP_LIMIT_MAX_EXCL)
+ len = printf("%*s", max_len, pretty_size_mode(qgroup->max_excl, unit_mode));
+ else
+ len = printf("%*s", max_len, "none");
break;
case BTRFS_QGROUP_CHILD:
len = print_child_column(qgroup);
printf("\n");
}
-static void print_table_head()
+static void print_table_head(void)
{
int i;
int len;
size = sizeof(struct btrfs_qgroup_comparer_set) +
BTRFS_QGROUP_NCOMPS_INCREASE *
sizeof(struct btrfs_qgroup_comparer);
- set = malloc(size);
+ set = calloc(1, size);
if (!set) {
fprintf(stderr, "memory allocation failed\n");
exit(1);
}
- memset(set, 0, size);
set->total = BTRFS_QGROUP_NCOMPS_INCREASE;
return set;
BUG_ON(set->ncomps > set->total);
if (set->ncomps == set->total) {
+ void *tmp;
+
size = set->total + BTRFS_QGROUP_NCOMPS_INCREASE;
size = sizeof(*set) +
size * sizeof(struct btrfs_qgroup_comparer);
+ tmp = set;
set = realloc(set, size);
if (!set) {
fprintf(stderr, "memory allocation failed\n");
+ free(tmp);
exit(1);
}
if (!ret)
return 0;
- bq = malloc(sizeof(*bq));
+ bq = calloc(1, sizeof(*bq));
if (!bq) {
printf("memory allocation failed\n");
exit(1);
}
- memset(bq, 0, sizeof(*bq));
if (qgroupid) {
bq->qgroupid = qgroupid;
INIT_LIST_HEAD(&bq->qgroups);
size = sizeof(struct btrfs_qgroup_filter_set) +
BTRFS_QGROUP_NFILTERS_INCREASE *
sizeof(struct btrfs_qgroup_filter);
- set = malloc(size);
+ set = calloc(1, size);
if (!set) {
fprintf(stderr, "memory allocation failed\n");
exit(1);
}
- memset(set, 0, size);
set->total = BTRFS_QGROUP_NFILTERS_INCREASE;
return set;
BUG_ON(set->nfilters > set->total);
if (set->nfilters == set->total) {
+ void *tmp;
+
size = set->total + BTRFS_QGROUP_NFILTERS_INCREASE;
size = sizeof(*set) + size * sizeof(struct btrfs_qgroup_filter);
+ tmp = set;
set = realloc(set, size);
if (!set) {
fprintf(stderr, "memory allocation failed\n");
+ free(tmp);
exit(1);
}
memset(&set->filters[set->total], 0,
switch (column) {
case BTRFS_QGROUP_QGROUPID:
- sprintf(tmp, "%llu/%llu", (bq->qgroupid >> 48),
- bq->qgroupid & ((1ll << 48) - 1));
+ sprintf(tmp, "%llu/%llu",
+ btrfs_qgroup_level(bq->qgroupid),
+ btrfs_qgroup_subvid(bq->qgroupid));
len = strlen(tmp);
if (btrfs_qgroup_columns[column].max_len < len)
btrfs_qgroup_columns[column].max_len = len;
len = 0;
list_for_each_entry(list, &bq->qgroups, next_qgroup) {
len += sprintf(tmp, "%llu/%llu",
- (list->qgroup)->qgroupid >> 48,
- ((1ll << 48) - 1) & (list->qgroup)->qgroupid);
+ btrfs_qgroup_level(list->qgroup->qgroupid),
+ btrfs_qgroup_subvid(list->qgroup->qgroupid));
if (!list_is_last(&list->next_qgroup, &bq->qgroups))
len += 1;
}
len = 0;
list_for_each_entry(list, &bq->members, next_member) {
len += sprintf(tmp, "%llu/%llu",
- (list->member)->qgroupid >> 48,
- ((1ll << 48) - 1) & (list->member)->qgroupid);
+ btrfs_qgroup_level(list->member->qgroupid),
+ btrfs_qgroup_subvid(list->member->qgroupid));
if (!list_is_last(&list->next_member, &bq->members))
len += 1;
}
n = rb_prev(n);
}
}
+
+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");
+ else if (flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN)
+ fprintf(stderr,
+ "WARNING: Rescan is running, qgroup data may be incorrect\n");
+ else if (flags & BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT)
+ fprintf(stderr,
+ "WARNING: Qgroup data inconsistent, rescan recommended\n");
+}
+
static int __qgroups_search(int fd, struct qgroup_lookup *qgroup_lookup)
{
int ret;
struct btrfs_ioctl_search_header *sh;
unsigned long off = 0;
unsigned int i;
- int e;
struct btrfs_qgroup_info_item *info;
struct btrfs_qgroup_limit_item *limit;
struct btrfs_qgroup *bq;
sk->tree_id = BTRFS_QUOTA_TREE_OBJECTID;
sk->max_type = BTRFS_QGROUP_RELATION_KEY;
- sk->min_type = BTRFS_QGROUP_INFO_KEY;
+ sk->min_type = BTRFS_QGROUP_STATUS_KEY;
sk->max_objectid = (u64)-1;
sk->max_offset = (u64)-1;
sk->max_transid = (u64)-1;
while (1) {
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
- e = errno;
if (ret < 0) {
fprintf(stderr,
"ERROR: can't perform the search - %s\n",
- strerror(e));
+ strerror(errno));
return ret;
}
/* the ioctl returns the number of item it found in nr_items */
off);
off += sizeof(*sh);
- if (sh->type == BTRFS_QGROUP_INFO_KEY) {
+ if (sh->type == BTRFS_QGROUP_STATUS_KEY) {
+ struct btrfs_qgroup_status_item *si;
+ u64 flags;
+
+ si = (struct btrfs_qgroup_status_item *)
+ (args.buf + off);
+ flags = btrfs_stack_qgroup_status_flags(si);
+ print_status_flag_warning(flags);
+ } else if (sh->type == BTRFS_QGROUP_INFO_KEY) {
info = (struct btrfs_qgroup_info_item *)
(args.buf + off);
a1 = btrfs_stack_qgroup_info_generation(info);
btrfs_stack_qgroup_info_exclusive_compressed
(info);
add_qgroup(qgroup_lookup, sh->offset, a1, a2,
- a3, a4, a5, 0, 0, 0, 0, 0, 0, 0);
+ a3, a4, a5, 0, 0, 0, 0, 0,
+ NULL, NULL);
} else if (sh->type == BTRFS_QGROUP_LIMIT_KEY) {
limit = (struct btrfs_qgroup_limit_item *)
(args.buf + off);
a5 = btrfs_stack_qgroup_limit_rsv_exclusive
(limit);
add_qgroup(qgroup_lookup, sh->offset, 0, 0,
- 0, 0, 0, a1, a2, a3, a4, a5, 0, 0);
+ 0, 0, 0, a1, a2, a3, a4, a5,
+ NULL, NULL);
} else if (sh->type == BTRFS_QGROUP_RELATION_KEY) {
if (sh->offset < sh->objectid)
goto skip;
__free_all_qgroups(&qgroup_lookup);
btrfs_qgroup_free_filter_set(filter_set);
+ btrfs_qgroup_free_comparer_set(comp_set);
return ret;
}
return 0;
}
-u64 parse_qgroupid(char *p)
-{
- char *s = strchr(p, '/');
- char *ptr_src_end = p + strlen(p);
- char *ptr_parse_end = NULL;
- u64 level;
- u64 id;
-
- if (!s) {
- id = strtoull(p, &ptr_parse_end, 10);
- if (ptr_parse_end != ptr_src_end)
- goto err;
- return id;
- }
- level = strtoull(p, &ptr_parse_end, 10);
- if (ptr_parse_end != s)
- goto err;
-
- id = strtoull(s+1, &ptr_parse_end, 10);
- if (ptr_parse_end != ptr_src_end)
- goto err;
-
- return (level << 48) | id;
-err:
- fprintf(stderr, "ERROR:invalid qgroupid\n");
- exit(-1);
-}
-
int qgroup_inherit_size(struct btrfs_qgroup_inherit *p)
{
return sizeof(*p) + sizeof(p->qgroups[0]) *