From patchwork Wed Aug 17 00:52:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "J. Bruce Fields" X-Patchwork-Id: 1072722 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7H0pB2H021106 for ; Wed, 17 Aug 2011 00:52:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752452Ab1HQAwX (ORCPT ); Tue, 16 Aug 2011 20:52:23 -0400 Received: from fieldses.org ([174.143.236.118]:47077 "EHLO fieldses.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751983Ab1HQAwX (ORCPT ); Tue, 16 Aug 2011 20:52:23 -0400 Received: from bfields by fieldses.org with local (Exim 4.72) (envelope-from ) id 1QtUMm-00037K-PB; Tue, 16 Aug 2011 20:52:20 -0400 Date: Tue, 16 Aug 2011 20:52:20 -0400 From: "J. Bruce Fields" To: "Myklebust, Trond" Cc: linux-nfs@vger.kernel.org, steved@redhat.com, nfsv4@ietf.org Subject: Re: open() of device special files Message-ID: <20110817005220.GA11879@fieldses.org> References: <20110815153637.GD28629@fieldses.org> <2E1EB2CF9ED1CB4AA966F0EB76EAB4430AA9B9FB@SACMVEXC2-PRD.hq.netapp.com> <20110815212539.GA32181@fieldses.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20110815212539.GA32181@fieldses.org> User-Agent: Mutt/1.5.20 (2009-06-14) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 17 Aug 2011 00:52:24 +0000 (UTC) > Confirmed the fix; I'll apply. Actually that changed NFS4ERR_INVAL's to NFS4ERR_SYMLINK's all over the place, which I'd rather not do; the following just affects the OPEN. --b. commit 618459ca1f7613f0dde4f09138e9acbe02690264 Author: J. Bruce Fields Date: Mon Aug 15 16:55:02 2011 -0400 nfsd4: return nfserr_symlink on v4 OPEN of non-regular file Without this, an attempt to open a device special file without first stat'ing it will fail. Signed-off-by: J. Bruce Fields --- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 9bf0a66..d784ceb 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -168,6 +168,24 @@ do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfs return status; } +static __be32 nfsd_check_obj_isreg(struct svc_fh *fh) +{ + umode_t mode = fh->fh_dentry->d_inode->i_mode; + + if (S_ISREG(mode)) + return nfs_ok; + if (S_ISDIR(mode)) + return nfserr_isdir; + /* + * Using err_symlink as our catch-all case may look odd; but + * there's no other obvious error for this case in 4.0, and we + * happen to know that it will cause the linux v4 client to do + * the right thing on attempts to open something other than a + * regular file. + */ + return nfserr_symlink; +} + static __be32 do_open_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open) { @@ -216,6 +234,9 @@ do_open_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_o status = nfsd_lookup(rqstp, current_fh, open->op_fname.data, open->op_fname.len, &resfh); fh_unlock(current_fh); + if (status) + goto out; + status = nfsd_check_obj_isreg(&resfh); } if (status) goto out;