浏览代码

fs: fix iversion handling

Currently notify_change directly updates i_version for size updates,
which not only is counter to how all other fields are updated through
struct iattr, but also breaks XFS, which need inode updates to happen
under its own lock, and synchronized to the structure that gets written
to the log.

Remove the update in the common code, and it to btrfs and ext4,
XFS already does a proper updaste internally and currently gets a
double update with the existing code.

IMHO this is 3.13 and -stable material and should go in through the XFS
tree.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Acked-by: Jan Kara <jack@suse.cz>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Chris Mason <clm@fb.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
Christoph Hellwig 11 年之前
父节点
当前提交
dff6efc326
共有 3 个文件被更改,包括 10 次插入7 次删除
  1. 0 5
      fs/attr.c
  2. 6 2
      fs/btrfs/inode.c
  3. 4 0
      fs/ext4/inode.c

+ 0 - 5
fs/attr.c

@@ -202,11 +202,6 @@ int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **de
 			return -EPERM;
 			return -EPERM;
 	}
 	}
 
 
-	if ((ia_valid & ATTR_SIZE) && IS_I_VERSION(inode)) {
-		if (attr->ia_size != inode->i_size)
-			inode_inc_iversion(inode);
-	}
-
 	if ((ia_valid & ATTR_MODE)) {
 	if ((ia_valid & ATTR_MODE)) {
 		umode_t amode = attr->ia_mode;
 		umode_t amode = attr->ia_mode;
 		/* Flag setting protected by i_mutex */
 		/* Flag setting protected by i_mutex */

+ 6 - 2
fs/btrfs/inode.c

@@ -4354,8 +4354,12 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
 	 * these flags set.  For all other operations the VFS set these flags
 	 * these flags set.  For all other operations the VFS set these flags
 	 * explicitly if it wants a timestamp update.
 	 * explicitly if it wants a timestamp update.
 	 */
 	 */
-	if (newsize != oldsize && (!(mask & (ATTR_CTIME | ATTR_MTIME))))
-		inode->i_ctime = inode->i_mtime = current_fs_time(inode->i_sb);
+	if (newsize != oldsize) {
+		inode_inc_iversion(inode);
+		if (!(mask & (ATTR_CTIME | ATTR_MTIME)))
+			inode->i_ctime = inode->i_mtime =
+				current_fs_time(inode->i_sb);
+	}
 
 
 	if (newsize > oldsize) {
 	if (newsize > oldsize) {
 		truncate_pagecache(inode, newsize);
 		truncate_pagecache(inode, newsize);

+ 4 - 0
fs/ext4/inode.c

@@ -4598,6 +4598,10 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
 			if (attr->ia_size > sbi->s_bitmap_maxbytes)
 			if (attr->ia_size > sbi->s_bitmap_maxbytes)
 				return -EFBIG;
 				return -EFBIG;
 		}
 		}
+
+		if (IS_I_VERSION(inode) && attr->ia_size != inode->i_size)
+			inode_inc_iversion(inode);
+
 		if (S_ISREG(inode->i_mode) &&
 		if (S_ISREG(inode->i_mode) &&
 		    (attr->ia_size < inode->i_size)) {
 		    (attr->ia_size < inode->i_size)) {
 			if (ext4_should_order_data(inode)) {
 			if (ext4_should_order_data(inode)) {