From: Sidong Yang <realwakka@gmail.com>
To: linux-btrfs@vger.kernel.org, quwenruo.btrfs@gmx.com
Cc: Sidong Yang <realwakka@gmail.com>
Subject: [PATCH] btrfs: qgroup: replace modifing qgroup_flags to bitops
Date: Tue, 1 Feb 2022 12:53:31 +0000 [thread overview]
Message-ID: <20220201125331.260482-1-realwakka@gmail.com> (raw)
This patch replaces the code modifying or checking qgroup_flags to
bitops like set_bit or test_bit. These bit operations works atomically
that it protects qgroup_flags value.
Signed-off-by: Sidong Yang <realwakka@gmail.com>
---
fs/btrfs/ioctl.c | 2 +-
fs/btrfs/qgroup.c | 68 ++++++++++++++++++++++-------------------------
2 files changed, 33 insertions(+), 37 deletions(-)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index cc61813213d8..19b0b59abe77 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -4435,7 +4435,7 @@ static long btrfs_ioctl_quota_rescan_status(struct btrfs_fs_info *fs_info,
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
- if (fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN) {
+ if (test_bit(BTRFS_QGROUP_STATUS_FLAG_RESCAN, &fs_info->qgroup_flags)) {
qsa.flags = 1;
qsa.progress = fs_info->qgroup_rescan_progress.objectid;
}
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index db680f5be745..9fabc62ff2a5 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -499,16 +499,16 @@ int btrfs_read_qgroup_config(struct btrfs_fs_info *fs_info)
out:
btrfs_free_path(path);
fs_info->qgroup_flags |= flags;
- if (!(fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_ON))
+ if (!test_bit(BTRFS_QGROUP_STATUS_FLAG_ON, &fs_info->qgroup_flags))
clear_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags);
- else if (fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN &&
+ else if (test_bit(BTRFS_QGROUP_STATUS_FLAG_RESCAN, &fs_info->qgroup_flags) &&
ret >= 0)
ret = qgroup_rescan_init(fs_info, rescan_progress, 0);
if (ret < 0) {
ulist_free(fs_info->qgroup_ulist);
fs_info->qgroup_ulist = NULL;
- fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN;
+ clear_bit(BTRFS_QGROUP_STATUS_FLAG_RESCAN, &fs_info->qgroup_flags);
btrfs_sysfs_del_qgroups(fs_info);
}
@@ -1197,7 +1197,7 @@ int btrfs_quota_disable(struct btrfs_fs_info *fs_info)
spin_lock(&fs_info->qgroup_lock);
quota_root = fs_info->quota_root;
fs_info->quota_root = NULL;
- fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_ON;
+ clear_bit(BTRFS_QGROUP_STATUS_FLAG_ON, &fs_info->qgroup_flags);
spin_unlock(&fs_info->qgroup_lock);
btrfs_free_qgroup_config(fs_info);
@@ -1353,7 +1353,7 @@ static int quick_update_accounting(struct btrfs_fs_info *fs_info,
}
out:
if (ret)
- fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
+ set_bit(BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT, &fs_info->qgroup_flags);
return ret;
}
@@ -1659,7 +1659,7 @@ int btrfs_limit_qgroup(struct btrfs_trans_handle *trans, u64 qgroupid,
ret = update_qgroup_limit_item(trans, qgroup);
if (ret) {
- fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
+ set_bit(BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT, &fs_info->qgroup_flags);
btrfs_info(fs_info, "unable to update quota limit for %llu",
qgroupid);
}
@@ -1735,7 +1735,7 @@ int btrfs_qgroup_trace_extent_post(struct btrfs_trans_handle *trans,
ret = btrfs_find_all_roots(NULL, trans->fs_info, bytenr, 0, &old_root,
true);
if (ret < 0) {
- trans->fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
+ set_bit(BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT, &trans->fs_info->qgroup_flags);
btrfs_warn(trans->fs_info,
"error accounting new delayed refs extent (err code: %d), quota inconsistent",
ret);
@@ -2211,7 +2211,7 @@ static int qgroup_trace_subtree_swap(struct btrfs_trans_handle *trans,
out:
btrfs_free_path(dst_path);
if (ret < 0)
- fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
+ set_bit(BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT, &fs_info->qgroup_flags);
return ret;
}
@@ -2581,7 +2581,7 @@ int btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans, u64 bytenr,
}
mutex_lock(&fs_info->qgroup_rescan_lock);
- if (fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN) {
+ if (test_bit(BTRFS_QGROUP_STATUS_FLAG_RESCAN, &fs_info->qgroup_flags)) {
if (fs_info->qgroup_rescan_progress.objectid <= bytenr) {
mutex_unlock(&fs_info->qgroup_rescan_lock);
ret = 0;
@@ -2715,23 +2715,23 @@ int btrfs_run_qgroups(struct btrfs_trans_handle *trans)
spin_unlock(&fs_info->qgroup_lock);
ret = update_qgroup_info_item(trans, qgroup);
if (ret)
- fs_info->qgroup_flags |=
- BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
+ set_bit(BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT,
+ &fs_info->qgroup_flags);
ret = update_qgroup_limit_item(trans, qgroup);
if (ret)
- fs_info->qgroup_flags |=
- BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
+ set_bit(BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT,
+ &fs_info->qgroup_flags);
spin_lock(&fs_info->qgroup_lock);
}
if (test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags))
- fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_ON;
+ set_bit(BTRFS_QGROUP_STATUS_FLAG_ON, &fs_info->qgroup_flags);
else
- fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_ON;
+ clear_bit(BTRFS_QGROUP_STATUS_FLAG_ON, &fs_info->qgroup_flags);
spin_unlock(&fs_info->qgroup_lock);
ret = update_qgroup_status_item(trans);
if (ret)
- fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
+ set_bit(BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT, &fs_info->qgroup_flags);
return ret;
}
@@ -2849,7 +2849,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
ret = update_qgroup_limit_item(trans, dstgroup);
if (ret) {
- fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
+ set_bit(BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT, &fs_info->qgroup_flags);
btrfs_info(fs_info,
"unable to update quota limit for %llu",
dstgroup->qgroupid);
@@ -2955,7 +2955,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
if (!committing)
mutex_unlock(&fs_info->qgroup_ioctl_lock);
if (need_rescan)
- fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
+ set_bit(BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT, &fs_info->qgroup_flags);
return ret;
}
@@ -3270,10 +3270,10 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work)
mutex_lock(&fs_info->qgroup_rescan_lock);
if (err > 0 &&
- fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT) {
- fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
+ test_bit(BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT, &fs_info->qgroup_flags)) {
+ clear_bit(BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT, &fs_info->qgroup_flags);
} else if (err < 0) {
- fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
+ set_bit(BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT, &fs_info->qgroup_flags);
}
mutex_unlock(&fs_info->qgroup_rescan_lock);
@@ -3292,7 +3292,7 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work)
mutex_lock(&fs_info->qgroup_rescan_lock);
if (!stopped)
- fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN;
+ clear_bit(BTRFS_QGROUP_STATUS_FLAG_RESCAN, &fs_info->qgroup_flags);
if (trans) {
ret = update_qgroup_status_item(trans);
if (ret < 0) {
@@ -3332,13 +3332,11 @@ qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid,
if (!init_flags) {
/* we're resuming qgroup rescan at mount time */
- if (!(fs_info->qgroup_flags &
- BTRFS_QGROUP_STATUS_FLAG_RESCAN)) {
+ if (!test_bit(BTRFS_QGROUP_STATUS_FLAG_RESCAN, &fs_info->qgroup_flags)) {
btrfs_warn(fs_info,
"qgroup rescan init failed, qgroup rescan is not queued");
ret = -EINVAL;
- } else if (!(fs_info->qgroup_flags &
- BTRFS_QGROUP_STATUS_FLAG_ON)) {
+ } else if (!test_bit(BTRFS_QGROUP_STATUS_FLAG_ON, &fs_info->qgroup_flags)) {
btrfs_warn(fs_info,
"qgroup rescan init failed, qgroup is not enabled");
ret = -EINVAL;
@@ -3351,12 +3349,11 @@ qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid,
mutex_lock(&fs_info->qgroup_rescan_lock);
if (init_flags) {
- if (fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN) {
+ if (test_bit(BTRFS_QGROUP_STATUS_FLAG_RESCAN, fs_info->qgroup_flags)) {
btrfs_warn(fs_info,
"qgroup rescan is already in progress");
ret = -EINPROGRESS;
- } else if (!(fs_info->qgroup_flags &
- BTRFS_QGROUP_STATUS_FLAG_ON)) {
+ } else if (!test_bit(BTRFS_QGROUP_STATUS_FLAG_ON, &fs_info->qgroup_flags)) {
btrfs_warn(fs_info,
"qgroup rescan init failed, qgroup is not enabled");
ret = -EINVAL;
@@ -3366,7 +3363,7 @@ qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid,
mutex_unlock(&fs_info->qgroup_rescan_lock);
return ret;
}
- fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_RESCAN;
+ set_bit(BTRFS_QGROUP_STATUS_FLAG_RESCAN, &fs_info->qgroup_flags);
}
memset(&fs_info->qgroup_rescan_progress, 0,
@@ -3422,12 +3419,12 @@ btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info)
trans = btrfs_join_transaction(fs_info->fs_root);
if (IS_ERR(trans)) {
- fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN;
+ clear_bit(BTRFS_QGROUP_STATUS_FLAG_RESCAN, &fs_info->qgroup_flags);
return PTR_ERR(trans);
}
ret = btrfs_commit_transaction(trans);
if (ret) {
- fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN;
+ clear_bit(BTRFS_QGROUP_STATUS_FLAG_RESCAN, &fs_info->qgroup_flags);
return ret;
}
@@ -3471,7 +3468,7 @@ int btrfs_qgroup_wait_for_completion(struct btrfs_fs_info *fs_info,
void
btrfs_qgroup_rescan_resume(struct btrfs_fs_info *fs_info)
{
- if (fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN) {
+ if (test_bit(BTRFS_QGROUP_STATUS_FLAG_RESCAN, &fs_info->qgroup_flags)) {
mutex_lock(&fs_info->qgroup_rescan_lock);
fs_info->qgroup_rescan_running = true;
btrfs_queue_work(fs_info->qgroup_rescan_workers,
@@ -4167,8 +4164,7 @@ int btrfs_qgroup_add_swapped_blocks(struct btrfs_trans_handle *trans,
spin_unlock(&blocks->lock);
out:
if (ret < 0)
- fs_info->qgroup_flags |=
- BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
+ set_bit(BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT, &fs_info->qgroup_flags);
return ret;
}
@@ -4255,7 +4251,7 @@ int btrfs_qgroup_trace_subtree_after_cow(struct btrfs_trans_handle *trans,
btrfs_err_rl(fs_info,
"failed to account subtree at bytenr %llu: %d",
subvol_eb->start, ret);
- fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
+ set_bit(BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT, &fs_info->qgroup_flags);
}
return ret;
}
--
2.25.1
next reply other threads:[~2022-02-01 12:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-01 12:53 Sidong Yang [this message]
2022-02-01 13:06 ` [PATCH] btrfs: qgroup: replace modifing qgroup_flags to bitops Qu Wenruo
2022-02-01 13:22 ` Sidong Yang
2022-02-01 13:56 ` kernel test robot
2022-02-01 14:02 ` David Sterba
2022-02-01 14:07 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220201125331.260482-1-realwakka@gmail.com \
--to=realwakka@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=quwenruo.btrfs@gmx.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox