Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3094235pxb; Mon, 18 Oct 2021 08:07:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsnQjiyYmzqtL3LT+34XKDCeDbcCpp0yPCCmvUXWAmGHv1dVJ/0TEPvYMYfz0Tb3N5C5W1 X-Received: by 2002:a05:6402:51c6:: with SMTP id r6mr42629412edd.276.1634569663851; Mon, 18 Oct 2021 08:07:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634569663; cv=none; d=google.com; s=arc-20160816; b=ymqZrtj/7RAL24RtQ/ZpiS9HSU3Tmx3Gb0c9V/KherwHCthJjxvVTU/K+Wu6tRFQ0Q 68DeMjpzVZ2f/sTbrLCco1KXgi96DUtA5E8USorUV62gDD/8PHKqzp8SxqNZ13XYmTs6 n17OoJrDsA7ZK/c6OgQ86PK+n299GRlJfbPEwqziTn7HQk4994jm9TN6nBuB0fK0ac4p h405OVsOSt+sKzYKPC1b2lYva+KsvxMdcB0v96cJl9Y7nS+YWqMScV5G8Tv3f7X9f8jA Iub0z9MZu2lnHJfFbgpTcA/3hlqsKYAQyCRByTO+ErU307+qcAwcwKaKUrc7jkFq47cr yqIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization:dkim-signature; bh=lCtXt/S98B8O04e5eLfCRcYEGlq2GeHKHWlj3+Qmlnw=; b=mO3iGI7vD2vRLfMSQRu5CBcxYBas1PUBOQjSpOtFGrTOCZ8MeTtd3+EXxK7mDtg14n nCStgSd+kAEjVjP1Xl23D0Io3Ywe/rSloFZtafJgorTJdHybf7Woemza+UDbGMXw8BCY GdIn475hX9jvdiLhmj6D+28lAoPRVlF/Ur46LsJk7AoR1WbQ+UAJfS4hR7o6V7yNdYt7 dwfgV80O0tuYlIJY92ZE9HVVEdKsGGhIpqGIDoKO7dblYfngiLVDGiYkw0ct8FcnQzwf 3Xj8N5tRh0YJmjk0msMbxLYPIbHuaydrpl2Phe8A5RlN5MCrVrGSV+5choF/AQy633xn Zbzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dSG9lLil; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 28si19012359ejb.18.2021.10.18.08.07.16; Mon, 18 Oct 2021 08:07:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dSG9lLil; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231811AbhJRPJH (ORCPT + 99 others); Mon, 18 Oct 2021 11:09:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:49837 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233119AbhJRPHo (ORCPT ); Mon, 18 Oct 2021 11:07:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634569532; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lCtXt/S98B8O04e5eLfCRcYEGlq2GeHKHWlj3+Qmlnw=; b=dSG9lLilqzKM9fuQ8O4Fw/z8dv7uwZNHWVctLdMobhbJapuyq3uYQmMdPdB8o6fCXn9UPR u3zzA9RmUdNC9Zh2sHS1TN+kX0A0o3XPErCq483N0A7LNWQOSzZIl7Drsz6IxzvQXcVGuX EHs1BqZjeQ64TJHnhic2YFiyL5KEDjw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-428-eqeM14vVO2quZOXq8ExUyA-1; Mon, 18 Oct 2021 11:05:29 -0400 X-MC-Unique: eqeM14vVO2quZOXq8ExUyA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7272910151E0; Mon, 18 Oct 2021 15:05:27 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id A12FE57CA4; Mon, 18 Oct 2021 15:05:12 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 55/67] afs: Skip truncation on the server of data we haven't written yet From: David Howells To: linux-cachefs@redhat.com Cc: dhowells@redhat.com, Trond Myklebust , Anna Schumaker , Steve French , Dominique Martinet , Jeff Layton , Matthew Wilcox , Alexander Viro , Omar Sandoval , Linus Torvalds , linux-afs@lists.infradead.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs-developer@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 18 Oct 2021 16:05:11 +0100 Message-ID: <163456951186.2614702.16840420880926305225.stgit@warthog.procyon.org.uk> In-Reply-To: <163456861570.2614702.14754548462706508617.stgit@warthog.procyon.org.uk> References: <163456861570.2614702.14754548462706508617.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.23 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Don't send a truncation RPC to the server if we're only shortening data that's in the pagecache and is beyond the server's EOF. Also don't automatically force writeback on setattr, but do wait to store RPCs that are in the region to be removed on a shortening truncation. Signed-off-by: David Howells --- fs/afs/inode.c | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/fs/afs/inode.c b/fs/afs/inode.c index c4af4fda37dd..4c66a2b86add 100644 --- a/fs/afs/inode.c +++ b/fs/afs/inode.c @@ -848,42 +848,67 @@ static const struct afs_operation_ops afs_setattr_operation = { int afs_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, struct iattr *attr) { + const unsigned int supported = + ATTR_SIZE | ATTR_MODE | ATTR_UID | ATTR_GID | + ATTR_MTIME | ATTR_MTIME_SET | ATTR_TIMES_SET | ATTR_TOUCH; struct afs_operation *op; struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry)); + struct inode *inode = &vnode->vfs_inode; + loff_t i_size; int ret; _enter("{%llx:%llu},{n=%pd},%x", vnode->fid.vid, vnode->fid.vnode, dentry, attr->ia_valid); - if (!(attr->ia_valid & (ATTR_SIZE | ATTR_MODE | ATTR_UID | ATTR_GID | - ATTR_MTIME | ATTR_MTIME_SET | ATTR_TIMES_SET | - ATTR_TOUCH))) { + if (!(attr->ia_valid & supported)) { _leave(" = 0 [unsupported]"); return 0; } + i_size = i_size_read(inode); if (attr->ia_valid & ATTR_SIZE) { - if (!S_ISREG(vnode->vfs_inode.i_mode)) + if (!S_ISREG(inode->i_mode)) return -EISDIR; - ret = inode_newsize_ok(&vnode->vfs_inode, attr->ia_size); + ret = inode_newsize_ok(inode, attr->ia_size); if (ret) return ret; - if (attr->ia_size == i_size_read(&vnode->vfs_inode)) + if (attr->ia_size == i_size) attr->ia_valid &= ~ATTR_SIZE; } fscache_use_cookie(afs_vnode_cache(vnode), true); - /* flush any dirty data outstanding on a regular file */ - if (S_ISREG(vnode->vfs_inode.i_mode)) - filemap_write_and_wait(vnode->vfs_inode.i_mapping); - /* Prevent any new writebacks from starting whilst we do this. */ down_write(&vnode->validate_lock); + if ((attr->ia_valid & ATTR_SIZE) && S_ISREG(inode->i_mode)) { + loff_t size = attr->ia_size; + + /* Wait for any outstanding writes to the server to complete */ + loff_t from = min(size, i_size); + loff_t to = max(size, i_size); + ret = filemap_fdatawait_range(inode->i_mapping, from, to); + if (ret < 0) + goto out_unlock; + + /* Don't talk to the server if we're just shortening in-memory + * writes that haven't gone to the server yet. + */ + if (!(attr->ia_valid & (supported & ~ATTR_SIZE & ~ATTR_MTIME)) && + attr->ia_size < i_size && + attr->ia_size > vnode->status.size) { + truncate_pagecache(inode, attr->ia_size); + fscache_resize_cookie(afs_vnode_cache(vnode), + attr->ia_size); + i_size_write(inode, attr->ia_size); + ret = 0; + goto out_unlock; + } + } + op = afs_alloc_operation(((attr->ia_valid & ATTR_FILE) ? afs_file_key(attr->ia_file) : NULL), vnode->volume);