diff --git a/cmds-qgroup.c b/cmds-qgroup.c index c5082f72..2d6d84b8 100644 --- a/cmds-qgroup.c +++ b/cmds-qgroup.c @@ -52,7 +52,7 @@ static int qgroup_assign(int assign, int argc, char **argv) /* * FIXME src should accept subvol path */ - if ((args.src >> 48) >= (args.dst >> 48)) { + if (btrfs_qgroup_level(args.src) >= btrfs_qgroup_level(args.dst)) { fprintf(stderr, "ERROR: bad relation requested '%s'\n", path); return 1; } diff --git a/ctree.h b/ctree.h index 901c3400..51fc8208 100644 --- a/ctree.h +++ b/ctree.h @@ -868,11 +868,21 @@ struct btrfs_csum_item { */ #define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49) -#define BTRFS_QGROUP_STATUS_OFF 0 -#define BTRFS_QGROUP_STATUS_ON 1 -#define BTRFS_QGROUP_STATUS_SCANNING 2 +#define BTRFS_QGROUP_LEVEL_SHIFT 48 -#define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1 << 0) +static inline u64 btrfs_qgroup_level(u64 qgroupid) +{ + return qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT; +} + +static inline u64 btrfs_qgroup_subvid(u64 qgroupid) +{ + return qgroupid & ((1ULL << BTRFS_QGROUP_LEVEL_SHIFT) - 1); +} + +#define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0) +#define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << 1) +#define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2) struct btrfs_qgroup_status_item { __le64 version; diff --git a/print-tree.c b/print-tree.c index 931a321a..30adc1a3 100644 --- a/print-tree.c +++ b/print-tree.c @@ -645,8 +645,8 @@ static void print_objectid(u64 objectid, u8 type) printf("%llu", (unsigned long long)objectid); /* device id */ return; case BTRFS_QGROUP_RELATION_KEY: - printf("%llu/%llu", objectid >> 48, - objectid & ((1ll << 48) - 1)); + printf("%llu/%llu", btrfs_qgroup_level(objectid), + btrfs_qgroup_subvid(objectid)); return; case BTRFS_UUID_KEY_SUBVOL: case BTRFS_UUID_KEY_RECEIVED_SUBVOL: @@ -743,8 +743,8 @@ void btrfs_print_key(struct btrfs_disk_key *disk_key) case BTRFS_QGROUP_RELATION_KEY: case BTRFS_QGROUP_INFO_KEY: case BTRFS_QGROUP_LIMIT_KEY: - printf(" %llu/%llu)", (unsigned long long)(offset >> 48), - (unsigned long long)(offset & ((1ll << 48) - 1))); + printf(" %llu/%llu)", btrfs_qgroup_level(offset), + btrfs_qgroup_subvid(offset)); break; case BTRFS_UUID_KEY_SUBVOL: case BTRFS_UUID_KEY_RECEIVED_SUBVOL: diff --git a/qgroup.c b/qgroup.c index 5a4e3938..388e3829 100644 --- a/qgroup.c +++ b/qgroup.c @@ -172,8 +172,9 @@ static int print_parent_column(struct btrfs_qgroup *qgroup) 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(","); } @@ -189,8 +190,9 @@ static int print_child_column(struct btrfs_qgroup *qgroup) 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(","); } @@ -219,8 +221,9 @@ static void print_qgroup_column(struct btrfs_qgroup *qgroup, 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: @@ -921,8 +924,9 @@ static void __update_columns_max_len(struct btrfs_qgroup *bq, 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; @@ -951,8 +955,8 @@ static void __update_columns_max_len(struct btrfs_qgroup *bq, 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; } @@ -963,8 +967,8 @@ static void __update_columns_max_len(struct btrfs_qgroup *bq, 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; }