From patchwork Tue Feb 5 08:55:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "M. Mohan Kumar" X-Patchwork-Id: 2097181 Return-Path: X-Original-To: patchwork-v9fs-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by patchwork1.kernel.org (Postfix) with ESMTP id 79CBE3FC23 for ; Tue, 5 Feb 2013 10:05:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-4.v29.ch3.sourceforge.com) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1U2fPN-0004KC-O1; Tue, 05 Feb 2013 10:05:45 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1U2fPM-0004K5-1N for v9fs-developer@lists.sourceforge.net; Tue, 05 Feb 2013 10:05:44 +0000 Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of in.ibm.com designates 202.81.31.143 as permitted sender) client-ip=202.81.31.143; envelope-from=mohan@in.ibm.com; helo=e23smtp01.au.ibm.com; Received: from e23smtp01.au.ibm.com ([202.81.31.143]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1U2fPI-0007Aa-2R for v9fs-developer@lists.sourceforge.net; Tue, 05 Feb 2013 10:05:44 +0000 Received: from /spool/local by e23smtp01.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 5 Feb 2013 18:49:54 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp01.au.ibm.com (202.81.31.207) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 5 Feb 2013 18:49:53 +1000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [9.190.235.21]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 89E312CE804C for ; Tue, 5 Feb 2013 19:55:07 +1100 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r158t6xK4653388 for ; Tue, 5 Feb 2013 19:55:06 +1100 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r158t7nA002632 for ; Tue, 5 Feb 2013 19:55:07 +1100 Received: from explorer.in.ibm.com (explorer.in.ibm.com [9.124.35.78]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r158t5f3002605; Tue, 5 Feb 2013 19:55:06 +1100 From: "M. Mohan Kumar" To: v9fs-developer@lists.sourceforge.net Date: Tue, 5 Feb 2013 14:25:05 +0530 Message-Id: <1360054505-4431-1-git-send-email-mohan@in.ibm.com> X-Mailer: git-send-email 1.7.11.7 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13020508-1618-0000-0000-0000034A8FA1 X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-Headers-End: 1U2fPI-0007Aa-2R Subject: [V9fs-developer] [PATCH] fs/9p: Fix atomic_open X-BeenThere: v9fs-developer@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: v9fs-developer-bounces@lists.sourceforge.net From: "M. Mohan Kumar" Return EEXISTS if requested file already exists, without this patch open call will always succeed even if the file exists and user specified O_CREAT|O_EXCL. Following test code can be used to verify this patch. Without this patch executing following test code on 9p mount will result in printing 'test case failed' always. #include #include main() { int fd; /* first create the file */ fd = open("./file", O_CREAT|O_WRONLY); if (fd < 0) { perror("open"); return -1; } close(fd); /* Now opening same file with O_CREAT|O_EXCL should fail */ fd = open("./file", O_CREAT|O_EXCL); if (fd < 0 && errno == EEXIST) printf("test case pass\n"); else printf("test case failed\n"); close(fd); return 0; } Signed-off-by: M. Mohan Kumar --- fs/9p/vfs_inode_dotl.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c index edd41d9..8d24ad6 100644 --- a/fs/9p/vfs_inode_dotl.c +++ b/fs/9p/vfs_inode_dotl.c @@ -267,8 +267,14 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry, } /* Only creates */ - if (!(flags & O_CREAT) || dentry->d_inode) - return finish_no_open(file, res); + if (!(flags & O_CREAT)) + return finish_no_open(file, res); + else if (dentry->d_inode) { + if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) + return -EEXIST; + else + return finish_no_open(file, res); + } v9ses = v9fs_inode2v9ses(dir);