Skip to content

Commit d810ef2

Browse files
Qu Wenruomasoncl
authored andcommitted
btrfs: qgroup: Add function qgroup_update_refcnt().
This function is used to update refcnt for qgroups. And is one of the two core functions used in the new qgroup implement. This is based on the old update_old/new_refcnt, but provides a unified logic and behavior. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: Chris Mason <clm@fb.com>
1 parent c682f9b commit d810ef2

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

fs/btrfs/qgroup.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,6 +1806,64 @@ static int qgroup_calc_new_refcnt(struct btrfs_fs_info *fs_info,
18061806
return 0;
18071807
}
18081808

1809+
#define UPDATE_NEW 0
1810+
#define UPDATE_OLD 1
1811+
/*
1812+
* Walk all of the roots that points to the bytenr and adjust their refcnts.
1813+
*/
1814+
static int qgroup_update_refcnt(struct btrfs_fs_info *fs_info,
1815+
struct ulist *roots, struct ulist *tmp,
1816+
struct ulist *qgroups, u64 seq, int update_old)
1817+
{
1818+
struct ulist_node *unode;
1819+
struct ulist_iterator uiter;
1820+
struct ulist_node *tmp_unode;
1821+
struct ulist_iterator tmp_uiter;
1822+
struct btrfs_qgroup *qg;
1823+
int ret = 0;
1824+
1825+
if (!roots)
1826+
return 0;
1827+
ULIST_ITER_INIT(&uiter);
1828+
while ((unode = ulist_next(roots, &uiter))) {
1829+
qg = find_qgroup_rb(fs_info, unode->val);
1830+
if (!qg)
1831+
continue;
1832+
1833+
ulist_reinit(tmp);
1834+
ret = ulist_add(qgroups, qg->qgroupid, ptr_to_u64(qg),
1835+
GFP_ATOMIC);
1836+
if (ret < 0)
1837+
return ret;
1838+
ret = ulist_add(tmp, qg->qgroupid, ptr_to_u64(qg), GFP_ATOMIC);
1839+
if (ret < 0)
1840+
return ret;
1841+
ULIST_ITER_INIT(&tmp_uiter);
1842+
while ((tmp_unode = ulist_next(tmp, &tmp_uiter))) {
1843+
struct btrfs_qgroup_list *glist;
1844+
1845+
qg = u64_to_ptr(tmp_unode->aux);
1846+
if (update_old)
1847+
btrfs_qgroup_update_old_refcnt(qg, seq, 1);
1848+
else
1849+
btrfs_qgroup_update_new_refcnt(qg, seq, 1);
1850+
list_for_each_entry(glist, &qg->groups, next_group) {
1851+
ret = ulist_add(qgroups, glist->group->qgroupid,
1852+
ptr_to_u64(glist->group),
1853+
GFP_ATOMIC);
1854+
if (ret < 0)
1855+
return ret;
1856+
ret = ulist_add(tmp, glist->group->qgroupid,
1857+
ptr_to_u64(glist->group),
1858+
GFP_ATOMIC);
1859+
if (ret < 0)
1860+
return ret;
1861+
}
1862+
}
1863+
}
1864+
return 0;
1865+
}
1866+
18091867
/*
18101868
* This adjusts the counters for all referenced qgroups if need be.
18111869
*/

0 commit comments

Comments
 (0)