From patchwork Wed Sep 8 13:24:07 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mohan Kumar M X-Patchwork-Id: 64142 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BCF40B6EF7 for ; Thu, 9 Sep 2010 00:12:50 +1000 (EST) Received: from localhost ([127.0.0.1]:41234 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OtKg5-0000qE-3e for incoming@patchwork.ozlabs.org; Wed, 08 Sep 2010 09:27:05 -0400 Received: from [140.186.70.92] (port=45336 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OtKdL-0007Ld-Mo for qemu-devel@nongnu.org; Wed, 08 Sep 2010 09:24:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OtKdH-0004Wd-A1 for qemu-devel@nongnu.org; Wed, 08 Sep 2010 09:24:12 -0400 Received: from e23smtp08.au.ibm.com ([202.81.31.141]:46373) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OtKdG-0004WE-P9 for qemu-devel@nongnu.org; Wed, 08 Sep 2010 09:24:11 -0400 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246]) by e23smtp08.au.ibm.com (8.14.4/8.13.1) with ESMTP id o88DO9Ek027851 for ; Wed, 8 Sep 2010 23:24:09 +1000 Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o88DO95p2195664 for ; Wed, 8 Sep 2010 23:24:09 +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 o88DO9tg011009 for ; Wed, 8 Sep 2010 23:24:09 +1000 Received: from localhost.localdomain ([9.77.192.56]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o88DO7mH011002 for ; Wed, 8 Sep 2010 23:24:08 +1000 From: "M. Mohan Kumar" To: qemu-devel@nongnu.org Date: Wed, 8 Sep 2010 18:54:07 +0530 Message-Id: <1283952247-8739-1-git-send-email-mohan@in.ibm.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1283952219-8700-1-git-send-email-mohan@in.ibm.com> References: <1283952219-8700-1-git-send-email-mohan@in.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Subject: [Qemu-devel] [PATCH 2/2] qemu-virtio9p: Implement TGETLOCK X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 lock If length is 0, lock all bytes starting at the location 'start' through to the end of file proc_id[4] - process id that wants to take lock/owns the task in case of reply client[4] - Client id of the system that owns the process Signed-off-by: M. Mohan Kumar --- hw/virtio-9p-debug.c | 17 +++++++++++++++++ hw/virtio-9p.c | 41 +++++++++++++++++++++++++++++++++++++++++ hw/virtio-9p.h | 21 +++++++++++++++++++++ 3 files changed, 79 insertions(+), 0 deletions(-) diff --git a/hw/virtio-9p-debug.c b/hw/virtio-9p-debug.c index 045774f..85c9900 100644 --- a/hw/virtio-9p-debug.c +++ b/hw/virtio-9p-debug.c @@ -602,6 +602,23 @@ void pprint_pdu(V9fsPDU *pdu) fprintf(llogfile, "RLOCK: ("); pprint_int8(pdu, 0, &offset, "status"); break; + case P9_TGETLOCK: + fprintf(llogfile, "TGETLOCK: ("); + pprint_int32(pdu, 0, &offset, "fid"); + pprint_int8(pdu, 0, &offset, ", type"); + pprint_int64(pdu, 0, &offset, ", start"); + pprint_int64(pdu, 0, &offset, ", length"); + pprint_int32(pdu, 0, &offset, ", proc_id"); + pprint_str(pdu, 0, &offset, ", client_id"); + break; + case P9_RGETLOCK: + fprintf(llogfile, "RGETLOCK: ("); + pprint_int8(pdu, 0, &offset, "type"); + pprint_int64(pdu, 0, &offset, ", start"); + pprint_int64(pdu, 0, &offset, ", length"); + pprint_int32(pdu, 0, &offset, ", proc_id"); + pprint_str(pdu, 0, &offset, ", client_id"); + break; default: fprintf(llogfile, "unknown(%d): (", pdu->id); break; diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index b3d55f1..db3f008 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -3199,6 +3199,46 @@ out: qemu_free(vs); } +/* + * When a TGETLOCK request comes, always return success because all lock + * handling is done by client's VFS layer. + */ + +static void v9fs_getlock(V9fsState *s, V9fsPDU *pdu) +{ + int32_t fid, err = 0; + V9fsGetlockState *vs; + + vs = qemu_mallocz(sizeof(*vs)); + vs->pdu = pdu; + vs->offset = 7; + + vs->glock = qemu_malloc(sizeof(*vs->glock)); + pdu_unmarshal(vs->pdu, vs->offset, "dbqqds", &fid, &vs->glock->type, + &vs->glock->start, &vs->glock->length, &vs->glock->proc_id, + &vs->glock->client_id); + + vs->fidp = lookup_fid(s, fid); + if (vs->fidp == NULL) { + err = -ENOENT; + goto out; + } + + err = v9fs_do_fstat(s, vs->fidp->fs.fd, &vs->stbuf); + if (err < 0) { + err = -errno; + goto out; + } + vs->glock->type = F_UNLCK; + vs->offset += pdu_marshal(vs->pdu, vs->offset, "bqqds", vs->glock->type, + vs->glock->start, vs->glock->length, vs->glock->proc_id, + &vs->glock->client_id); +out: + complete_pdu(s, vs->pdu, err); + qemu_free(vs->glock); + qemu_free(vs); +} + static void v9fs_mkdir_post_lstat(V9fsState *s, V9fsMkState *vs, int err) { if (err == -1) { @@ -3462,6 +3502,7 @@ static pdu_handler_t *pdu_handlers[] = { [P9_TMKNOD] = v9fs_mknod, [P9_TRENAME] = v9fs_rename, [P9_TLOCK] = v9fs_lock, + [P9_TGETLOCK] = v9fs_getlock, [P9_TMKDIR] = v9fs_mkdir, [P9_TVERSION] = v9fs_version, [P9_TLOPEN] = v9fs_open, diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h index 4555f39..6a68895 100644 --- a/hw/virtio-9p.h +++ b/hw/virtio-9p.h @@ -39,6 +39,8 @@ enum { P9_RREADDIR, P9_TLOCK = 52, P9_RLOCK, + P9_TGETLOCK = 54, + P9_RGETLOCK, P9_TLINK = 70, P9_RLINK, P9_TMKDIR = 72, @@ -464,6 +466,25 @@ typedef struct V9fsLockState V9fsFlock *flock; } V9fsLockState; +typedef struct V9fsGetlock +{ + uint8_t type; + uint64_t start; /* absolute offset */ + uint64_t length; + uint32_t proc_id; + V9fsString client_id; +} V9fsGetlock; + +typedef struct V9fsGetlockState +{ + V9fsPDU *pdu; + size_t offset; + struct stat stbuf; + V9fsFidState *fidp; + V9fsGetlock *glock; +} V9fsGetlockState; + + extern size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count, size_t offset, size_t size, int pack);