From patchwork Tue Aug 2 15:58:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jim Garlick X-Patchwork-Id: 1029652 X-Patchwork-Delegate: ericvh@gmail.com Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p72FwUvE002158 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 2 Aug 2011 15:58:52 GMT Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1QoHMD-0007V8-Co; Tue, 02 Aug 2011 15:58:13 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1QoHMB-0007Uu-9m for v9fs-developer@lists.sourceforge.net; Tue, 02 Aug 2011 15:58:11 +0000 Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of llnl.gov designates 128.115.41.82 as permitted sender) client-ip=128.115.41.82; envelope-from=garlick@llnl.gov; helo=nspiron-2.llnl.gov; Received: from nspiron-2.llnl.gov ([128.115.41.82]) by sog-mx-2.v43.ch3.sourceforge.com with esmtp (Exim 4.76) id 1QoHMB-00025c-3C for v9fs-developer@lists.sourceforge.net; Tue, 02 Aug 2011 15:58:11 +0000 X-Attachments: None Received: from eris.llnl.gov ([134.9.2.84]) by nspiron-2.llnl.gov with ESMTP; 02 Aug 2011 08:58:05 -0700 Received: from localhost (mrhankey [192.168.1.135]) by eris.llnl.gov (Postfix) with ESMTP id 53D1E7C4A5; Tue, 2 Aug 2011 08:58:05 -0700 (PDT) Date: Tue, 2 Aug 2011 08:58:05 -0700 From: Jim Garlick To: Eric Van Hensbergen Message-ID: <20110802155805.GA14768@llnl.gov> References: <20110721002355.GA2964@llnl.gov> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-12-10) X-Headers-End: 1QoHMB-00025c-3C Cc: "v9fs-developer@lists.sourceforge.net" Subject: Re: [V9fs-developer] 9p2000.L constants for lock type 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: , Errors-To: v9fs-developer-bounces@lists.sourceforge.net X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 02 Aug 2011 15:58:52 +0000 (UTC) X-MIME-Autoconverted: from quoted-printable to 8bit by demeter1.kernel.org id p72FwUvE002158 On Wed, Jul 20, 2011 at 05:46:05PM -0700, Eric Van Hensbergen wrote: > On Wed, Jul 20, 2011 at 7:23 PM, Jim Garlick wrote: > > Hi, I seem to recall a similar topic coming up on this list but can't > > find the thread (sorry if I'm repeating earlier comments). > > > > For the advisory locking ops (.L), v9fs just puts the kernel l_type values, > > e.g. F_UNLCK, F_RDLCK, and F_WRLCK on the wire. > > > > In my server, I have a unit test that (inadvertantly) fails if > > l_type is defined differently on a test system compared to the system > > where I created the test.  Someone found this to be the case and > > opened a bug: > > > > http://code.google.com/p/diod/issues/detail?id=69 > > > > We should probably be defining these values in the protocol and remapping > > in the kernel, assuming 9P2000.L is to work in heterogenous environments. > > > > Thoughts? > > > > Agreed. For that matter all existing flags, constants, modes, etc. > should probably be defined in the protocol. Linux will undoubtably > change underneath us, but then we just need to start incrementing > protocol version to update the mappings. > > -eric Something like the following? I chose values for P9_LOCK_TYPE_* that will not overlap with the native ones so servers can handle both, thus not breaking compatability with released kernels. This seems to me to be a good general strategy for other constants that need to be defined in the protocol. What do you think? Jim commit 99741798ea1d1a594d9cc69174a28387ba865adf Author: Jim Garlick Date: Wed Jul 27 16:34:39 2011 -0700 Use protocol-defined value for lock/getlock 'type' field. ------------------------------------------------------------------------------ BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA The must-attend event for mobile developers. Connect with experts. Get tools for creating Super Apps. See the latest technologies. Sessions, hands-on labs, demos & much more. Register early & save! http://p.sf.net/sfu/rim-blackberry-1 diff --git a/include/net/9p/9p.h b/include/net/9p/9p.h index 071fd7a..98d9ae3 100644 --- a/include/net/9p/9p.h +++ b/include/net/9p/9p.h @@ -478,6 +478,10 @@ struct p9_iattr_dotl { #define P9_LOCK_FLAGS_BLOCK 1 #define P9_LOCK_FLAGS_RECLAIM 2 +#define P9_LOCK_TYPE_RDLCK 97 +#define P9_LOCK_TYPE_WRLCK 98 +#define P9_LOCK_TYPE_UNLCK 99 + /* struct p9_flock: POSIX lock structure * @type - type of lock * @flags - lock flags diff --git a/v9fs/vfs_file.c b/v9fs/vfs_file.c index 80bddcf..4e1c620 100644 --- a/v9fs/vfs_file.c +++ b/v9fs/vfs_file.c @@ -154,7 +154,17 @@ static int v9fs_file_do_lock(struct file *filp, int cmd, struct file_lock *fl) /* convert posix lock to p9 tlock args */ memset(&flock, 0, sizeof(flock)); - flock.type = fl->fl_type; + switch (fl->fl_type) { + case F_RDLCK: + flock.type = P9_LOCK_TYPE_RDLCK; + break; + case F_WRLCK: + flock.type = P9_LOCK_TYPE_WRLCK; + break; + case F_UNLCK: + flock.type = P9_LOCK_TYPE_UNLCK; + break; + } flock.start = fl->fl_start; if (fl->fl_end == OFFSET_MAX) flock.length = 0; @@ -242,16 +252,25 @@ static int v9fs_file_getlock(struct file *filp, struct file_lock *fl) res = p9_client_getlock_dotl(fid, &glock); if (res < 0) return res; - if (glock.type != F_UNLCK) { - fl->fl_type = glock.type; + switch (glock.type) { + case P9_LOCK_TYPE_RDLCK: + fl->fl_type = F_RDLCK; + break; + case P9_LOCK_TYPE_WRLCK: + fl->fl_type = F_WRLCK; + break; + case P9_LOCK_TYPE_UNLCK: + fl->fl_type = F_UNLCK; + break; + } + if (glock.type != P9_LOCK_TYPE_UNLCK) { fl->fl_start = glock.start; if (glock.length == 0) fl->fl_end = OFFSET_MAX; else fl->fl_end = glock.start + glock.length - 1; fl->fl_pid = glock.proc_id; - } else - fl->fl_type = F_UNLCK; + } return res; }