]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
9p: Implement TGETLOCK
authorM. Mohan Kumar <mohan@in.ibm.com>
Mon, 27 Sep 2010 06:52:13 +0000 (12:22 +0530)
committerEric Van Hensbergen <ericvh@gmail.com>
Thu, 28 Oct 2010 14:08:47 +0000 (09:08 -0500)
Synopsis

    size[4] TGetlock tag[2] fid[4] getlock[n]
    size[4] RGetlock tag[2] getlock[n]

Description

TGetlock is used to test for the existence of byte range posix locks on a file
identified by given fid. The reply contains getlock structure. If the lock could
be placed it returns F_UNLCK in type field of getlock structure.  Otherwise it
returns the details of the conflicting locks in the getlock structure

    getlock structure:
      type[1] - Type of lock: F_RDLCK, F_WRLCK
      start[8] - Starting offset for lock
      length[8] - Number of bytes to check for the lock
             If length is 0, check for lock in all bytes starting at the location
            'start' through to the end of file
      pid[4] - PID of the process that wants to take lock/owns the task
               in case of reply
      client[4] - Client id of the system that owns the process which
                  has the conflicting lock

Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
fs/9p/vfs_file.c
include/net/9p/9p.h
include/net/9p/client.h
net/9p/client.c

index 6f77abd23184240276dfc4284865ce7b7450c6b1..3a4352f23a984d3656420523fe34f2642c232e78 100644 (file)
@@ -211,6 +211,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
@@ -238,6 +283,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:
index 1859a2560cc5f8de8750f6e42f9c1d8a3e3f8ff9..6367a71d84fc9ec3fdc15beb2b3915db25ed7506 100644 (file)
@@ -167,6 +167,8 @@ enum p9_msg_t {
        P9_RFSYNC,
        P9_TLOCK = 52,
        P9_RLOCK,
+       P9_TGETLOCK = 54,
+       P9_RGETLOCK,
        P9_TLINK = 70,
        P9_RLINK,
        P9_TMKDIR = 72,
@@ -492,6 +494,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;
index d7dcb142e3bb4b89a0ae304998c60415d434d12d..127c9f2a9cb810a9a09d960a4ac0ca88e16cd8eb 100644 (file)
@@ -250,6 +250,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);
 
index fbd2b195801c80a50edb922cc1f1dad374fecc1c..fc1b0579016ab1fab02fe4953a75a3f4558a9aef 100644 (file)
@@ -1836,3 +1836,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);