btrfs-progs: Update qgroup status flags and replace qgroup level/subvid calculation with inline function

Ctree.h of btrfs-progs contains wrong flags for btrfs_qgroup_status.
Update it with the one in kernel.

Also, introduce the inline function btrfs_qgroup_(level/subvid) to get
the level/subvolid of qgroup, to replace the old open-coded bit
operations.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
This commit is contained in:
Qu Wenruo 2015-02-27 16:26:33 +08:00 committed by David Sterba
parent f18f8b7afc
commit 9922c42701
4 changed files with 35 additions and 21 deletions

View File

@ -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;
}

18
ctree.h
View File

@ -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;

View File

@ -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:

View File

@ -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;
}