From patchwork Tue Sep 21 08:37:05 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "M. Mohan Kumar" X-Patchwork-Id: 196642 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.3) with ESMTP id o8L8bLVE006128 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 21 Sep 2010 08:37:56 GMT Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1OxyLk-0004Yo-GB; Tue, 21 Sep 2010 08:37:16 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1OxyLj-0004Yb-HM for v9fs-developer@lists.sourceforge.net; Tue, 21 Sep 2010 08:37:15 +0000 Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of in.ibm.com designates 202.81.31.144 as permitted sender) client-ip=202.81.31.144; envelope-from=mohan@in.ibm.com; helo=e23smtp02.au.ibm.com; Received: from e23smtp02.au.ibm.com ([202.81.31.144]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.69) id 1OxyLi-000404-2l for v9fs-developer@lists.sourceforge.net; Tue, 21 Sep 2010 08:37:15 +0000 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [202.81.31.247]) by e23smtp02.au.ibm.com (8.14.4/8.13.1) with ESMTP id o8L8WlLW020802 for ; Tue, 21 Sep 2010 18:32:47 +1000 Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o8L8b6Cx2187368 for ; Tue, 21 Sep 2010 18:37:06 +1000 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 o8L8b61t004329 for ; Tue, 21 Sep 2010 18:37:06 +1000 Received: from localhost.localdomain (explorer.in.ibm.com [9.124.35.87]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o8L8b53f004306; Tue, 21 Sep 2010 18:37:05 +1000 From: "M. Mohan Kumar" To: v9fs-developer@lists.sourceforge.net Date: Tue, 21 Sep 2010 14:07:05 +0530 Message-Id: <1285058225-7451-1-git-send-email-mohan@in.ibm.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1285058185-7419-1-git-send-email-mohan@in.ibm.com> References: <1285058185-7419-1-git-send-email-mohan@in.ibm.com> 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 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1OxyLi-000404-2l Cc: linux-fsdevel@vger.kernel.org Subject: [V9fs-developer] [PATCH 2/2] 9p: Implement TGETLOCK 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 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Tue, 21 Sep 2010 08:37:57 +0000 (UTC) diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c index eb9b7ae..0ae725a 100644 --- a/fs/9p/vfs_file.c +++ b/fs/9p/vfs_file.c @@ -208,6 +208,51 @@ out: return res; } +static int v9fs_file_getlock(struct file *filp, struct file_lock *fl) +{ + struct p9_getlock glock; + struct p9_fid *fid; + int res = 0; + + fid = filp->private_data; + BUG_ON(fid == NULL); + + posix_test_lock(filp, fl); + /* + * if we have a conflicting lock locally, no need to validate + * with server + */ + if (fl->fl_type != F_UNLCK) + return res; + + /* convert posix lock to p9 tgetlock args */ + memset(&glock, 0, sizeof(glock)); + glock.type = fl->fl_type; + glock.start = fl->fl_start; + if (fl->fl_end == OFFSET_MAX) + glock.length = 0; + else + glock.length = fl->fl_end - fl->fl_start + 1; + glock.proc_id = fl->fl_pid; + glock.client_id = utsname()->nodename; + + res = p9_client_getlock_dotl(fid, &glock); + if (res < 0) + return res; + if (glock.type != F_UNLCK) { + fl->fl_type = glock.type; + 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; +} + /** * v9fs_file_lock_dotl - lock a file (or directory) * @filp: file to be locked @@ -235,6 +280,8 @@ static int v9fs_file_lock_dotl(struct file *filp, int cmd, struct file_lock *fl) if (IS_SETLK(cmd) || IS_SETLKW(cmd)) ret = v9fs_file_do_lock(filp, cmd, fl); + else if (IS_GETLK(cmd)) + ret = v9fs_file_getlock(filp, fl); else ret = -EINVAL; out_err: diff --git a/include/net/9p/9p.h b/include/net/9p/9p.h index 0968a25..0c9ad95 100644 --- a/include/net/9p/9p.h +++ b/include/net/9p/9p.h @@ -165,6 +165,8 @@ enum p9_msg_t { P9_RREADDIR, P9_TLOCK = 52, P9_RLOCK, + P9_TGETLOCK = 54, + P9_RGETLOCK, P9_TLINK = 70, P9_RLINK, P9_TMKDIR = 72, @@ -490,6 +492,22 @@ struct p9_flock { char *client_id; }; +/* struct p9_getlock: getlock structure + * @type - type of lock + * @start - starting offset of the lock + * @length - number of bytes + * @proc_id - process id which wants to take lock + * @client_id - client id + */ + +struct p9_getlock { + u8 type; + u64 start; + u64 length; + u32 proc_id; + char *client_id; +}; + /* Structures for Protocol Operations */ struct p9_tstatfs { u32 fid; diff --git a/include/net/9p/client.h b/include/net/9p/client.h index 39df9fd..fb358f5 100644 --- a/include/net/9p/client.h +++ b/include/net/9p/client.h @@ -252,6 +252,7 @@ int p9_client_mknod_dotl(struct p9_fid *oldfid, char *name, int mode, int p9_client_mkdir_dotl(struct p9_fid *fid, char *name, int mode, gid_t gid, struct p9_qid *); int p9_client_lock_dotl(struct p9_fid *fid, struct p9_flock *flock, u8 *status); +int p9_client_getlock_dotl(struct p9_fid *fid, struct p9_getlock *fl); struct p9_req_t *p9_tag_lookup(struct p9_client *, u16); void p9_client_cb(struct p9_client *c, struct p9_req_t *req); diff --git a/net/9p/client.c b/net/9p/client.c index 6329037..4b90b82 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -1860,3 +1860,37 @@ error: } EXPORT_SYMBOL(p9_client_lock_dotl); + +int p9_client_getlock_dotl(struct p9_fid *fid, struct p9_getlock *glock) +{ + int err; + struct p9_client *clnt; + struct p9_req_t *req; + + err = 0; + clnt = fid->clnt; + P9_DPRINTK(P9_DEBUG_9P, ">>> TGETLOCK fid %d, type %i start %lld " + "length %lld proc_id %d client_id %s\n", fid->fid, glock->type, + glock->start, glock->length, glock->proc_id, glock->client_id); + + req = p9_client_rpc(clnt, P9_TGETLOCK, "dbqqds", fid->fid, glock->type, + glock->start, glock->length, glock->proc_id, glock->client_id); + + if (IS_ERR(req)) + return PTR_ERR(req); + + err = p9pdu_readf(req->rc, clnt->proto_version, "bqqds", &glock->type, + &glock->start, &glock->length, &glock->proc_id, + &glock->client_id); + if (err) { + p9pdu_dump(1, req->rc); + goto error; + } + P9_DPRINTK(P9_DEBUG_9P, "<<< RGETLOCK type %i start %lld length %lld " + "proc_id %d client_id %s\n", glock->type, glock->start, + glock->length, glock->proc_id, glock->client_id); +error: + p9_free_req(clnt, req); + return err; +} +EXPORT_SYMBOL(p9_client_getlock_dotl);