diff --git a/cmds/qgroup.c b/cmds/qgroup.c index bffe942b1c..8a78babdb9 100644 --- a/cmds/qgroup.c +++ b/cmds/qgroup.c @@ -799,6 +799,32 @@ static struct btrfs_qgroup *qgroup_tree_search(struct qgroup_lookup *root_tree, return NULL; } +static void __free_btrfs_qgroup(struct btrfs_qgroup *bq) +{ + struct btrfs_qgroup_list *list; + while (!list_empty(&bq->qgroups)) { + list = list_entry((&bq->qgroups)->next, + struct btrfs_qgroup_list, + next_qgroup); + list_del(&list->next_qgroup); + list_del(&list->next_member); + free(list); + } + while (!list_empty(&bq->members)) { + list = list_entry((&bq->members)->next, + struct btrfs_qgroup_list, + next_member); + list_del(&list->next_qgroup); + list_del(&list->next_member); + free(list); + } + if (bq->path) { + printf("freeing path for qgroup %llu\n", bq->qgroupid); + free((void *)bq->path); + } + free(bq); +} + /* * Lookup or insert btrfs_qgroup into qgroup_lookup. * @@ -835,15 +861,17 @@ static struct btrfs_qgroup *get_or_add_qgroup(int fd, char *path; uret = btrfs_util_subvolume_path_fd(fd, qgroupid, &path); - if (uret == BTRFS_UTIL_OK) + if (uret == BTRFS_UTIL_OK) { + printf("got path resolved for qgroup %llu\n", qgroupid); bq->path = path; - else if (uret != BTRFS_UTIL_ERROR_SUBVOLUME_NOT_FOUND) { + } else if (uret != BTRFS_UTIL_ERROR_SUBVOLUME_NOT_FOUND) { error("%s", btrfs_util_strerror(uret)); if (uret == BTRFS_UTIL_ERROR_NO_MEMORY) return ERR_PTR(-ENOMEM); else return ERR_PTR(-EIO); } + printf("no path found for qgroup %llu\n", qgroupid); /* * Do a correct stale detection by searching for the ROOT_ITEM of * the subvolume. @@ -868,7 +896,7 @@ static struct btrfs_qgroup *get_or_add_qgroup(int fd, if (ret) { errno = -ret; error("failed to insert %llu into tree: %m", bq->qgroupid); - free(bq); + __free_btrfs_qgroup(bq); return ERR_PTR(ret); } @@ -950,30 +978,6 @@ static int update_qgroup_relation(struct qgroup_lookup *qgroup_lookup, return 0; } -static void __free_btrfs_qgroup(struct btrfs_qgroup *bq) -{ - struct btrfs_qgroup_list *list; - while (!list_empty(&bq->qgroups)) { - list = list_entry((&bq->qgroups)->next, - struct btrfs_qgroup_list, - next_qgroup); - list_del(&list->next_qgroup); - list_del(&list->next_member); - free(list); - } - while (!list_empty(&bq->members)) { - list = list_entry((&bq->members)->next, - struct btrfs_qgroup_list, - next_member); - list_del(&list->next_qgroup); - list_del(&list->next_member); - free(list); - } - if (bq->path) - free((void *)bq->path); - free(bq); -} - static void __free_all_qgroups(struct qgroup_lookup *root_tree) { struct btrfs_qgroup *entry; diff --git a/libbtrfsutil/subvolume.c b/libbtrfsutil/subvolume.c index 1f0f2d2b31..c14ad8a6b8 100644 --- a/libbtrfsutil/subvolume.c +++ b/libbtrfsutil/subvolume.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "stubs.h" #include "btrfsutil_internal.h" @@ -178,6 +179,8 @@ PUBLIC enum btrfs_util_error btrfs_util_subvolume_path_fd(int fd, uint64_t id, path = malloc(capacity); if (!path) return BTRFS_UTIL_ERROR_NO_MEMORY; + + printf("allocated memory for qgroup %lu\n", id); p = path + capacity - 1; p[0] = '\0';