Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1214930rwn; Thu, 8 Sep 2022 15:38:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR464B/I9X562Y2l1kBIfVSW6Y4uao2viUKrH1Y32agT1J8axJxu/r/JTEE44QeV4W6x0eDQ X-Received: by 2002:a05:651c:88b:b0:261:ba8e:717a with SMTP id d11-20020a05651c088b00b00261ba8e717amr3044610ljq.401.1662676699456; Thu, 08 Sep 2022 15:38:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662676699; cv=none; d=google.com; s=arc-20160816; b=PTjR3495BgYS1k7c85yXRaXiNgLP0M1hBnqp0+sABpXTlyWHoU8it8jc4Z1UlLLsJl RZjqIl3I/FpOlHJZyv7c/y61l1efWR/55Qy5XVBGSScuB/Fhu0an8E0exnjV9uMQ6z90 D/NOOsGAyCnqZ86pmLAAGF4xCkG+7+NcUbQJIMOgJZWlA440pOkUW1bK1paz0YiXu6uF PhxQXEiAxpjxCPi+nc8FsTxKdXZGNOZ5z7c1tsMWD1lnNQrzqGFyuA+1JfkDUl/Z7XW1 L2m9y0nSV+LxyQbVyS2WahYnj2E/13TMFDdMw2PVE6XyejOGkWij3OuAY+9V94pEVfdE OEuQ== 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:to:from:subject; bh=F81l4opHcHzOeFS4vfG/b1cKS73loUcwI5PHvvHywhI=; b=HjrFJI5fND+FwbjKq5eAVamLe9+0mBKg1/N9Yw16Tdu54hR+euJi8jKymiMkPE4fAx I8V4bpHemjEEiqWi19CDbcTUKqmrw7gubPXyLHdQw/7WPYniZ0l7Xi1Pp4UBABLlT1bg IHvEjlh1TObhtl4dqWRg9oxsk49hQFJ3eYBE8jTgy9NTt+Fw5F/l1zo3H9vb9s3Yzysn dddPTwyPiwdI1FWc06gjtunKgKkUTHQ+LYK22/xkHjZtuMCyF7CmTdkkJoKHSA3vC2us ZFIheDP4prUDhHMzTBLXij5A7/mv8pcFXkBIs/rtMtdD3Cd8tTvSB2ec4B3wOqXXEzhC Jr6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d26-20020a2e96da000000b00265f3467201si20518ljj.615.2022.09.08.15.37.51; Thu, 08 Sep 2022 15:38:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229607AbiIHWOL (ORCPT + 99 others); Thu, 8 Sep 2022 18:14:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229764AbiIHWOK (ORCPT ); Thu, 8 Sep 2022 18:14:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 280D01098CE for ; Thu, 8 Sep 2022 15:14:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B1C0D61D99 for ; Thu, 8 Sep 2022 22:14:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14FFAC433C1 for ; Thu, 8 Sep 2022 22:14:08 +0000 (UTC) Subject: [PATCH v4 5/8] NFSD: Refactor nfsd_setattr() From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Thu, 08 Sep 2022 18:14:07 -0400 Message-ID: <166267524713.1842.2388707630082157165.stgit@manet.1015granger.net> In-Reply-To: <166267495153.1842.14474564029477470642.stgit@manet.1015granger.net> References: <166267495153.1842.14474564029477470642.stgit@manet.1015granger.net> User-Agent: StGit/1.5.dev2+g9ce680a5 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Move code that will be retried (in a subsequent patch) into a helper function. Signed-off-by: Chuck Lever --- fs/nfsd/vfs.c | 74 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 9f486b788ed0..02f31d8c727a 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -339,6 +339,44 @@ nfsd_get_write_access(struct svc_rqst *rqstp, struct svc_fh *fhp, return nfserrno(get_write_access(inode)); } +static int __nfsd_setattr(struct dentry *dentry, struct iattr *iap) +{ + int host_err; + + if (iap->ia_valid & ATTR_SIZE) { + /* + * RFC5661, Section 18.30.4: + * Changing the size of a file with SETATTR indirectly + * changes the time_modify and change attributes. + * + * (and similar for the older RFCs) + */ + struct iattr size_attr = { + .ia_valid = ATTR_SIZE | ATTR_CTIME | ATTR_MTIME, + .ia_size = iap->ia_size, + }; + + if (iap->ia_size < 0) + return -EFBIG; + + host_err = notify_change(&init_user_ns, dentry, &size_attr, NULL); + if (host_err) + return host_err; + iap->ia_valid &= ~ATTR_SIZE; + + /* + * Avoid the additional setattr call below if the only other + * attribute that the client sends is the mtime, as we update + * it as part of the size change above. + */ + if ((iap->ia_valid & ~ATTR_MTIME) == 0) + return 0; + } + + iap->ia_valid |= ATTR_CTIME; + return notify_change(&init_user_ns, dentry, iap, NULL); +} + /* * Set various file attributes. After this call fhp needs an fh_put. */ @@ -417,41 +455,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, } inode_lock(inode); - if (size_change) { - /* - * RFC5661, Section 18.30.4: - * Changing the size of a file with SETATTR indirectly - * changes the time_modify and change attributes. - * - * (and similar for the older RFCs) - */ - struct iattr size_attr = { - .ia_valid = ATTR_SIZE | ATTR_CTIME | ATTR_MTIME, - .ia_size = iap->ia_size, - }; - - host_err = -EFBIG; - if (iap->ia_size < 0) - goto out_unlock; - - host_err = notify_change(&init_user_ns, dentry, &size_attr, NULL); - if (host_err) - goto out_unlock; - iap->ia_valid &= ~ATTR_SIZE; - - /* - * Avoid the additional setattr call below if the only other - * attribute that the client sends is the mtime, as we update - * it as part of the size change above. - */ - if ((iap->ia_valid & ~ATTR_MTIME) == 0) - goto out_unlock; - } - - iap->ia_valid |= ATTR_CTIME; - host_err = notify_change(&init_user_ns, dentry, iap, NULL); - -out_unlock: + host_err = __nfsd_setattr(dentry, iap); if (attr->na_seclabel && attr->na_seclabel->len) attr->na_labelerr = security_inode_setsecctx(dentry, attr->na_seclabel->data, attr->na_seclabel->len);