From patchwork Wed Aug 26 13:10:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 7076951 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C15E8C05AC for ; Wed, 26 Aug 2015 13:11:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C626D2092C for ; Wed, 26 Aug 2015 13:11:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E580D20592 for ; Wed, 26 Aug 2015 13:11:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756474AbbHZNLJ (ORCPT ); Wed, 26 Aug 2015 09:11:09 -0400 Received: from mail-pa0-f41.google.com ([209.85.220.41]:33741 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756130AbbHZNLH (ORCPT ); Wed, 26 Aug 2015 09:11:07 -0400 Received: by pacti10 with SMTP id ti10so88106329pac.0 for ; Wed, 26 Aug 2015 06:11:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=+BB6yEgwZfoxKi8H1BdTuwtqGhE7aSL7nQ8OA39v6wE=; b=U8HqlDtaEfz+RkTZgXI3C+CiY5LfSxrjpYrsoBQT0Kb9tsYbN/aDDaoM2SOCc2/yVx 28m5EUO4+T8muOXdg3mMAMGmvSaMI0GcrFGM26Lsw+oEbwmSWUszYCD3FD1Q8Soh7evm PufVRXHVCWsm1DoWVoz7TduPoBBjUsxPFvlC7iYke+bwoTcGlaEHda/oLoP1jT9ML2KZ 3naE4+gJn07uO0DyVWTjj/7mr3wGrhtOrvyJ07qAXhII/s+rXy1MDSIHfFsugNePoU13 GP9sV38VRaH4n+dYv5WA9b95Iq5J9Sfq/qTErOcrGILbzZqrgcz9aOUkMyi1hD+0qUsc 84yg== X-Received: by 10.66.196.233 with SMTP id ip9mr68963831pac.79.1440594667079; Wed, 26 Aug 2015 06:11:07 -0700 (PDT) Received: from [192.168.99.14] ([104.143.41.79]) by smtp.googlemail.com with ESMTPSA id em1sm24698920pbd.42.2015.08.26.06.11.02 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Aug 2015 06:11:06 -0700 (PDT) Subject: [PATCH 1/5 v3] NFS: Check size by inode_newsize_ok in nfs_setattr To: Trond Myklebust References: <55DDBA9E.1040008@gmail.com> Cc: "linux-nfs@vger.kernel.org" , kinglongmee@gmail.com From: Kinglong Mee Message-ID: <55DDBADF.2040602@gmail.com> Date: Wed, 26 Aug 2015 21:10:55 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: <55DDBA9E.1040008@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Set rlimit for NFS's files is useless right now. For local process's rlimit, it should be checked by nfs client. The same, CIFS also call inode_change_ok checking rlimit at its client in cifs_setattr_nounix() and cifs_setattr_unix(). v3, fix bad using of error Signed-off-by: Kinglong Mee --- fs/nfs/inode.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index 0adc7d2..a8b7ae8 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -504,7 +504,7 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr) { struct inode *inode = d_inode(dentry); struct nfs_fattr *fattr; - int error = -ENOMEM; + int error = 0; nfs_inc_stats(inode, NFSIOS_VFSSETATTR); @@ -513,15 +513,14 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr) attr->ia_valid &= ~ATTR_MODE; if (attr->ia_valid & ATTR_SIZE) { - loff_t i_size; - BUG_ON(!S_ISREG(inode->i_mode)); - i_size = i_size_read(inode); - if (attr->ia_size == i_size) + error = inode_newsize_ok(inode, attr->ia_size); + if (error) + return error; + + if (attr->ia_size == i_size_read(inode)) attr->ia_valid &= ~ATTR_SIZE; - else if (attr->ia_size < i_size && IS_SWAPFILE(inode)) - return -ETXTBSY; } /* Optimization: if the end result is no change, don't RPC */ @@ -536,8 +535,11 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr) nfs_sync_inode(inode); fattr = nfs_alloc_fattr(); - if (fattr == NULL) + if (fattr == NULL) { + error = -ENOMEM; goto out; + } + /* * Return any delegations if we're going to change ACLs */