ceph: ignore the truncate when size won't change with Fx caps issued
authorXiubo Li <xiubli@redhat.com>
Fri, 8 Oct 2021 08:23:58 +0000 (16:23 +0800)
committerIlya Dryomov <idryomov@gmail.com>
Mon, 8 Nov 2021 02:29:52 +0000 (03:29 +0100)
If the new size is the same as the current size, the MDS will do nothing
but change the mtime/atime. POSIX doesn't mandate that the filesystems
must update them in this case, so just ignore it instead.

Signed-off-by: Xiubo Li <xiubli@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
fs/ceph/inode.c

index c22c067..e3322fc 100644 (file)
@@ -2103,12 +2103,14 @@ int __ceph_setattr(struct inode *inode, struct iattr *attr)
                loff_t isize = i_size_read(inode);
 
                dout("setattr %p size %lld -> %lld\n", inode, isize, attr->ia_size);
-               if ((issued & CEPH_CAP_FILE_EXCL) && attr->ia_size > isize) {
-                       i_size_write(inode, attr->ia_size);
-                       inode->i_blocks = calc_inode_blocks(attr->ia_size);
-                       ci->i_reported_size = attr->ia_size;
-                       dirtied |= CEPH_CAP_FILE_EXCL;
-                       ia_valid |= ATTR_MTIME;
+               if ((issued & CEPH_CAP_FILE_EXCL) && attr->ia_size >= isize) {
+                       if (attr->ia_size > isize) {
+                               i_size_write(inode, attr->ia_size);
+                               inode->i_blocks = calc_inode_blocks(attr->ia_size);
+                               ci->i_reported_size = attr->ia_size;
+                               dirtied |= CEPH_CAP_FILE_EXCL;
+                               ia_valid |= ATTR_MTIME;
+                       }
                } else if ((issued & CEPH_CAP_FILE_SHARED) == 0 ||
                           attr->ia_size != isize) {
                        req->r_args.setattr.size = cpu_to_le64(attr->ia_size);