diff mbox

Btrfs: atomically set inode->i_flags in btrfs_update_iflags

Message ID 1403732162-22405-1-git-send-email-fdmanana@gmail.com (mailing list archive)
State Accepted
Headers show

Commit Message

Filipe Manana June 25, 2014, 9:36 p.m. UTC
This change is based on the corresponding recent change for ext4:

  ext4: atomically set inode->i_flags in ext4_set_inode_flags()

That has the following commit message that applies to btrfs as well:

  "Use cmpxchg() to atomically set i_flags instead of clearing out the
   S_IMMUTABLE, S_APPEND, etc. flags and then setting them from the
   EXT4_IMMUTABLE_FL, EXT4_APPEND_FL flags, since this opens up a race
   where an immutable file has the immutable flag cleared for a brief
   window of time."

Replacing EXT4_IMMUTABLE_FL and EXT4_APPEND_FL with BTRFS_INODE_IMMUTABLE
and BTRFS_INODE_APPEND, respectively.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
---
 fs/btrfs/ioctl.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

Comments

David Sterba July 1, 2014, 11:56 p.m. UTC | #1
On Wed, Jun 25, 2014 at 10:36:02PM +0100, Filipe David Borba Manana wrote:
> This change is based on the corresponding recent change for ext4:
> 
>   ext4: atomically set inode->i_flags in ext4_set_inode_flags()
> 
> That has the following commit message that applies to btrfs as well:
> 
>   "Use cmpxchg() to atomically set i_flags instead of clearing out the
>    S_IMMUTABLE, S_APPEND, etc. flags and then setting them from the
>    EXT4_IMMUTABLE_FL, EXT4_APPEND_FL flags, since this opens up a race
>    where an immutable file has the immutable flag cleared for a brief
>    window of time."
> 
> Replacing EXT4_IMMUTABLE_FL and EXT4_APPEND_FL with BTRFS_INODE_IMMUTABLE
> and BTRFS_INODE_APPEND, respectively.
> 
> Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>

Reviewed-by: David Sterba <dsterba@suse.cz>
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Satoru Takeuchi July 2, 2014, 12:25 a.m. UTC | #2
(2014/07/02 8:56), David Sterba wrote:
> On Wed, Jun 25, 2014 at 10:36:02PM +0100, Filipe David Borba Manana wrote:
>> This change is based on the corresponding recent change for ext4:
>>
>>    ext4: atomically set inode->i_flags in ext4_set_inode_flags()
>>
>> That has the following commit message that applies to btrfs as well:
>>
>>    "Use cmpxchg() to atomically set i_flags instead of clearing out the
>>     S_IMMUTABLE, S_APPEND, etc. flags and then setting them from the
>>     EXT4_IMMUTABLE_FL, EXT4_APPEND_FL flags, since this opens up a race
>>     where an immutable file has the immutable flag cleared for a brief
>>     window of time."
>>
>> Replacing EXT4_IMMUTABLE_FL and EXT4_APPEND_FL with BTRFS_INODE_IMMUTABLE
>> and BTRFS_INODE_APPEND, respectively.
>>
>> Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
>
> Reviewed-by: David Sterba <dsterba@suse.cz>

Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>

> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 6ea1546..02dc64b 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -136,19 +136,22 @@  static unsigned int btrfs_flags_to_ioctl(unsigned int flags)
 void btrfs_update_iflags(struct inode *inode)
 {
 	struct btrfs_inode *ip = BTRFS_I(inode);
-
-	inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
+	unsigned int new_fl = 0;
 
 	if (ip->flags & BTRFS_INODE_SYNC)
-		inode->i_flags |= S_SYNC;
+		new_fl |= S_SYNC;
 	if (ip->flags & BTRFS_INODE_IMMUTABLE)
-		inode->i_flags |= S_IMMUTABLE;
+		new_fl |= S_IMMUTABLE;
 	if (ip->flags & BTRFS_INODE_APPEND)
-		inode->i_flags |= S_APPEND;
+		new_fl |= S_APPEND;
 	if (ip->flags & BTRFS_INODE_NOATIME)
-		inode->i_flags |= S_NOATIME;
+		new_fl |= S_NOATIME;
 	if (ip->flags & BTRFS_INODE_DIRSYNC)
-		inode->i_flags |= S_DIRSYNC;
+		new_fl |= S_DIRSYNC;
+
+	set_mask_bits(&inode->i_flags,
+		      S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME | S_DIRSYNC,
+		      new_fl);
 }
 
 /*