Skip to contentSkip to conversation

Btrfs: don't update atime on RO subvolumes

PATCH In review Alexander Block 2 participants 4 messages Jun 15, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Btrfs: don't update atime on RO subvolumes

Before the update_time inode operation was indroduced, it was not possible to prevent updates of atime on RO subvolumes. VFS was only able to check for RO on the mount, but did not know anything about btrfs subvolumes.

btrfs_update_time does now check if the root is RO and skip updating of times.

---
 fs/btrfs/inode.c |    5 +++++
 fs/inode.c       |    2 ++
 2 files changed, 7 insertions(+)
fs/btrfs/inode.c +5 -0
index f6ab6f5..4d0ceed 100644
@@ -4478,6 +4478,11 @@ int btrfs_dirty_inode(struct inode *inode)
 static int btrfs_update_time(struct inode *inode, struct timespec *now,
 			     int flags)
 {
+	struct btrfs_root *root = BTRFS_I(inode)->root;
+
+	if (btrfs_root_readonly(root))
+		return -EROFS;
+
 	if (flags & S_VERSION)
 		inode_inc_iversion(inode);
 	if (flags & S_CTIME)
fs/inode.c +2 -0
index c99163b..033529e 100644
@@ -1551,6 +1551,8 @@ void touch_atime(struct path *path)
 	 * Btrfs), but since we touch atime while walking down the path we
 	 * really don't care if we failed to update the atime of the file,
 	 * so just ignore the return value.
+	 * We may also fail on filesystems that have the ability to make parts
+	 * of the fs read only, e.g. subvolumes in Btrfs.
 	 */
 	update_time(inode, &now, S_ATIME);
 	mnt_drop_write(mnt);
Signature · 1 line
1.7.10
#1 lore raw
Quoted 19 lines · Alexander Block

Before the update_time inode operation was indroduced, it was not possible to prevent updates of atime on RO subvolumes. VFS was only able to check for RO on the mount, but did not know anything about btrfs subvolumes.

btrfs_update_time does now check if the root is RO and skip updating of times.

---
 fs/btrfs/inode.c |    5 +++++
 fs/inode.c       |    2 ++
 2 files changed, 7 insertions(+)
fs/btrfs/inode.c +0 -0
index f6ab6f5..4d0ceed 100644

fs/btrfs/inode.c int btrfs_dirty_inode(struct inode *inode) · line 4485

Quoted 8 lines
fs/btrfs/inode.c +5 -0
@@ -4478,6 +4478,11 @@ int btrfs_dirty_inode(struct inode *inode)
 static int btrfs_update_time(struct inode *inode, struct timespec *now,
 			     int flags)
 {
+	struct btrfs_root *root = BTRFS_I(inode)->root;
+
+	if (btrfs_root_readonly(root))
+		return -EROFS;
+

It also needs to acquire root->fs_info->subvol_sem, doesn't it?

thanks,
liubo

Quoted 16 lines
fs/btrfs/inode.c +0 -0
 	if (flags & S_VERSION)
 		inode_inc_iversion(inode);
 	if (flags & S_CTIME)
fs/inode.c +2 -0
index c99163b..033529e 100644
@@ -1551,6 +1551,8 @@ void touch_atime(struct path *path)
 	 * Btrfs), but since we touch atime while walking down the path we
 	 * really don't care if we failed to update the atime of the file,
 	 * so just ignore the return value.
+	 * We may also fail on filesystems that have the ability to make parts
+	 * of the fs read only, e.g. subvolumes in Btrfs.
 	 */
 	update_time(inode, &now, S_ATIME);
 	mnt_drop_write(mnt);
#2 lore raw
Quoted 17 lines · Liu Bo

fs/btrfs/inode.c int btrfs_dirty_inode(struct inode *inode) · line 4485

Quoted 13 lines
fs/btrfs/inode.c +5 -0
index f6ab6f5..4d0ceed 100644
@@ -4478,6 +4478,11 @@ int btrfs_dirty_inode(struct inode *inode)
 static int btrfs_update_time(struct inode *inode, struct timespec *now,
                           int flags)
 {
+     struct btrfs_root *root = BTRFS_I(inode)->root;
+
+     if (btrfs_root_readonly(root))
+             return -EROFS;
+

It also needs to acquire root->fs_info->subvol_sem, doesn't it?

Quoted 3 lines

thanks,
liubo

Normally yes I think. But does it matter at this point? If the flags are modified at the same time as we access them, wouldn't it be still random which value (old/new) we get, even with subvol_sem?

(sorry for the double mail Liu...as always forgot Reply All)

#3 lore raw
Quoted 21 lines · Alexander Block
Quoted 16 lines · Liu Bo

fs/btrfs/inode.c int btrfs_dirty_inode(struct inode *inode) · line 4485

Quoted 13 lines
fs/btrfs/inode.c +5 -0
index f6ab6f5..4d0ceed 100644
@@ -4478,6 +4478,11 @@ int btrfs_dirty_inode(struct inode *inode)
 static int btrfs_update_time(struct inode *inode, struct timespec *now,
                           int flags)
 {
+     struct btrfs_root *root = BTRFS_I(inode)->root;
+
+     if (btrfs_root_readonly(root))
+             return -EROFS;
+

It also needs to acquire root->fs_info->subvol_sem, doesn't it?

Quoted 3 lines

thanks,
liubo

Quoted 6 lines

Normally yes I think. But does it matter at this point? If the flags are modified at the same time as we access them, wouldn't it be still random which value (old/new) we get, even with subvol_sem?

(sorry for the double mail Liu...as always forgot Reply All)

I find other callers use btrfs_root_readonly without subvol_sem either, anyway, I'm ok with this patch.

thanks,
liubo