X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=qgroup.c;h=f17fdaeeb986252616078aca5c67516c5b47231a;hb=ae60006cee1c15f87adee22d4595384ea5ab596b;hp=388e3829646a8e3cac12d83a83afbca96f40f9de;hpb=9922c42701f8a49d3df743a95c4f7a54c84c7452;p=platform%2Fupstream%2Fbtrfs-progs.git diff --git a/qgroup.c b/qgroup.c index 388e382..f17fdae 100644 --- a/qgroup.c +++ b/qgroup.c @@ -237,10 +237,16 @@ static void print_qgroup_column(struct btrfs_qgroup *qgroup, 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); @@ -266,7 +272,7 @@ static void print_single_qgroup_table(struct btrfs_qgroup *qgroup) printf("\n"); } -static void print_table_head() +static void print_table_head(void) { int i; int len; @@ -430,13 +436,12 @@ struct btrfs_qgroup_comparer_set *btrfs_qgroup_alloc_comparer_set(void) 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; @@ -459,12 +464,16 @@ int btrfs_qgroup_setup_comparer(struct btrfs_qgroup_comparer_set **comp_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); } @@ -634,12 +643,11 @@ static int add_qgroup(struct qgroup_lookup *qgroup_lookup, u64 qgroupid, 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); @@ -803,12 +811,11 @@ struct btrfs_qgroup_filter_set *btrfs_qgroup_alloc_filter_set(void) 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; @@ -830,12 +837,16 @@ int btrfs_qgroup_setup_filter(struct btrfs_qgroup_filter_set **filter_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, @@ -1017,6 +1028,20 @@ static void __filter_and_sort_qgroups(struct qgroup_lookup *all_qgroups, 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; @@ -1025,7 +1050,6 @@ static int __qgroups_search(int fd, struct qgroup_lookup *qgroup_lookup) 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; @@ -1040,7 +1064,7 @@ static int __qgroups_search(int fd, struct qgroup_lookup *qgroup_lookup) 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; @@ -1050,11 +1074,10 @@ static int __qgroups_search(int fd, struct qgroup_lookup *qgroup_lookup) 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 */ @@ -1071,7 +1094,17 @@ static int __qgroups_search(int fd, struct qgroup_lookup *qgroup_lookup) off); off += sizeof(*sh); - if (sh->type == BTRFS_QGROUP_INFO_KEY) { + if (btrfs_search_header_type(sh) + == 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 (btrfs_search_header_type(sh) + == BTRFS_QGROUP_INFO_KEY) { info = (struct btrfs_qgroup_info_item *) (args.buf + off); a1 = btrfs_stack_qgroup_info_generation(info); @@ -1083,9 +1116,12 @@ static int __qgroups_search(int fd, struct qgroup_lookup *qgroup_lookup) a5 = 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); - } else if (sh->type == BTRFS_QGROUP_LIMIT_KEY) { + add_qgroup(qgroup_lookup, + btrfs_search_header_offset(sh), a1, + a2, a3, a4, a5, 0, 0, 0, 0, 0, NULL, + NULL); + } else if (btrfs_search_header_type(sh) + == BTRFS_QGROUP_LIMIT_KEY) { limit = (struct btrfs_qgroup_limit_item *) (args.buf + off); @@ -1098,33 +1134,38 @@ static int __qgroups_search(int fd, struct qgroup_lookup *qgroup_lookup) (limit); 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); - } else if (sh->type == BTRFS_QGROUP_RELATION_KEY) { - if (sh->offset < sh->objectid) + add_qgroup(qgroup_lookup, + btrfs_search_header_offset(sh), 0, + 0, 0, 0, 0, a1, a2, a3, a4, a5, + NULL, NULL); + } else if (btrfs_search_header_type(sh) + == BTRFS_QGROUP_RELATION_KEY) { + if (btrfs_search_header_offset(sh) + < btrfs_search_header_objectid(sh)) goto skip; bq = qgroup_tree_search(qgroup_lookup, - sh->offset); + btrfs_search_header_offset(sh)); if (!bq) goto skip; bq1 = qgroup_tree_search(qgroup_lookup, - sh->objectid); + btrfs_search_header_objectid(sh)); if (!bq1) goto skip; - add_qgroup(qgroup_lookup, sh->offset, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, bq, bq1); + add_qgroup(qgroup_lookup, + btrfs_search_header_offset(sh), 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, bq, bq1); } else goto done; skip: - off += sh->len; + off += btrfs_search_header_len(sh); /* * record the mins in sk so we can make sure the * next search doesn't repeat this root */ - sk->min_type = sh->type; - sk->min_offset = sh->offset; - sk->min_objectid = sh->objectid; + sk->min_type = btrfs_search_header_type(sh); + sk->min_offset = btrfs_search_header_offset(sh); + sk->min_objectid = btrfs_search_header_objectid(sh); } sk->nr_items = 4096; /* @@ -1175,6 +1216,7 @@ int btrfs_show_qgroups(int fd, __free_all_qgroups(&qgroup_lookup); btrfs_qgroup_free_filter_set(filter_set); + btrfs_qgroup_free_comparer_set(comp_set); return ret; } @@ -1249,34 +1291,6 @@ int btrfs_qgroup_parse_sort_string(char *opt_arg, 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]) *