Message ID | e2938504101b0832739b3421f8d07b809a9f5232.1730818481.git.fdmanana@suse.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | btrfs: simplify logic to decrement snapshot counter at btrfs_mksnapshot() | expand |
On Tue, Nov 05, 2024 at 02:57:23PM +0000, fdmanana@kernel.org wrote: > From: Filipe Manana <fdmanana@suse.com> > > There's no point in having a 'snapshot_force_cow' variable to track if we > need to decrement the root->snapshot_force_cow counter, as we never jump > to the 'out' label after incrementing the counter. Simplify this by > removing the variable and always decrementing the counter before the 'out' > label, right after the call to btrfs_mksubvol(). > > Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com>
在 2024/11/6 01:27, fdmanana@kernel.org 写道: > From: Filipe Manana <fdmanana@suse.com> > > There's no point in having a 'snapshot_force_cow' variable to track if we > need to decrement the root->snapshot_force_cow counter, as we never jump > to the 'out' label after incrementing the counter. Simplify this by > removing the variable and always decrementing the counter before the 'out' > label, right after the call to btrfs_mksubvol(). > > Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Thanks, Qu > --- > fs/btrfs/ioctl.c | 5 +---- > 1 file changed, 1 insertion(+), 4 deletions(-) > > diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c > index cd3e82cc842b..26a07cbeb3a4 100644 > --- a/fs/btrfs/ioctl.c > +++ b/fs/btrfs/ioctl.c > @@ -1049,7 +1049,6 @@ static noinline int btrfs_mksnapshot(const struct path *parent, > struct btrfs_qgroup_inherit *inherit) > { > int ret; > - bool snapshot_force_cow = false; > > /* > * Force new buffered writes to reserve space even when NOCOW is > @@ -1068,15 +1067,13 @@ static noinline int btrfs_mksnapshot(const struct path *parent, > * creation. > */ > atomic_inc(&root->snapshot_force_cow); > - snapshot_force_cow = true; > > btrfs_wait_ordered_extents(root, U64_MAX, NULL); > > ret = btrfs_mksubvol(parent, idmap, name, namelen, > root, readonly, inherit); > + atomic_dec(&root->snapshot_force_cow); > out: > - if (snapshot_force_cow) > - atomic_dec(&root->snapshot_force_cow); > btrfs_drew_read_unlock(&root->snapshot_lock); > return ret; > }
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index cd3e82cc842b..26a07cbeb3a4 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1049,7 +1049,6 @@ static noinline int btrfs_mksnapshot(const struct path *parent, struct btrfs_qgroup_inherit *inherit) { int ret; - bool snapshot_force_cow = false; /* * Force new buffered writes to reserve space even when NOCOW is @@ -1068,15 +1067,13 @@ static noinline int btrfs_mksnapshot(const struct path *parent, * creation. */ atomic_inc(&root->snapshot_force_cow); - snapshot_force_cow = true; btrfs_wait_ordered_extents(root, U64_MAX, NULL); ret = btrfs_mksubvol(parent, idmap, name, namelen, root, readonly, inherit); + atomic_dec(&root->snapshot_force_cow); out: - if (snapshot_force_cow) - atomic_dec(&root->snapshot_force_cow); btrfs_drew_read_unlock(&root->snapshot_lock); return ret; }