Received: from [140.186.70.92] (port=43315 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oy3YJ-0004qp-Ek for qemu-devel@nongnu.org; Tue, 21 Sep 2010 10:10:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Oy3YD-0000DM-6t for qemu-devel@nongnu.org; Tue, 21 Sep 2010 10:10:35 -0400 Received: from e28smtp09.in.ibm.com ([122.248.162.9]:40836) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oy3YC-0000Cq-IY for qemu-devel@nongnu.org; Tue, 21 Sep 2010 10:10:29 -0400 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by e28smtp09.in.ibm.com (8.14.4/8.13.1) with ESMTP id o8LDpWHl014379 for ; Tue, 21 Sep 2010 19:21:32 +0530 Received: from d28av04.in.ibm.com (d28av04.in.ibm.com [9.184.220.66]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o8LEAM5P3002504 for ; Tue, 21 Sep 2010 19:40:22 +0530 Received: from d28av04.in.ibm.com (loopback [127.0.0.1]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o8LEALcI027675 for ; Wed, 22 Sep 2010 00:10:22 +1000 Received: from localhost.localdomain ([9.77.120.11]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o8LEALYI027646 for ; Wed, 22 Sep 2010 00:10:21 +1000 From: "M. Mohan Kumar" Date: Tue, 21 Sep 2010 19:40:20 +0530 Message-Id: <1285078220-25523-1-git-send-email-mohan@in.ibm.com> Subject: [Qemu-devel] [PATCH] qemu-virtio-9p: Implement TREADLINK operation for 9p2000.L List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Synopsis size[4] TReadlink tag[2] fid[4] size[4] RReadlink tag[2] target[s] Description Readlink is used to return the contents of the symoblic link referred by fid. Contents of symboic link is returned as a response. target[s] - Contents of the symbolic link referred by fid. Signed-off-by: M. Mohan Kumar Reviewed-by: Aneesh Kumar K.V --- hw/virtio-9p-debug.c | 8 ++++++++ hw/virtio-9p.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-9p.h | 9 +++++++++ 3 files changed, 61 insertions(+), 0 deletions(-) diff --git a/hw/virtio-9p-debug.c b/hw/virtio-9p-debug.c index 6f6a0ec..cfaae6b 100644 --- a/hw/virtio-9p-debug.c +++ b/hw/virtio-9p-debug.c @@ -502,6 +502,14 @@ void pprint_pdu(V9fsPDU *pdu) fprintf(llogfile, "RMKNOD: )"); pprint_qid(pdu, 0, &offset, "qid"); break; + case P9_TREADLINK: + fprintf(llogfile, "TREADLINK: ("); + pprint_int32(pdu, 0, &offset, "fid"); + break; + case P9_RREADLINK: + fprintf(llogfile, "RREADLINK: ("); + pprint_str(pdu, 0, &offset, "target"); + break; case P9_TREAD: fprintf(llogfile, "TREAD: ("); pprint_int32(pdu, 0, &offset, "fid"); diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index fd2147e..5d1fbee 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -3403,6 +3403,49 @@ out: qemu_free(vs); } +static void v9fs_readlink_post_readlink(V9fsState *s, V9fsReadLinkState *vs, + int err) +{ + if (err < 0) { + err = -errno; + goto out; + } + vs->offset += pdu_marshal(vs->pdu, vs->offset, "s", &vs->target); + err = vs->offset; +out: + complete_pdu(s, vs->pdu, err); + v9fs_string_free(&vs->target); + qemu_free(vs); +} + +static void v9fs_readlink(V9fsState *s, V9fsPDU *pdu) +{ + int32_t fid; + V9fsReadLinkState *vs; + int err = 0; + V9fsFidState *fidp; + + vs = qemu_malloc(sizeof(*vs)); + vs->pdu = pdu; + vs->offset = 7; + + pdu_unmarshal(vs->pdu, vs->offset, "d", &fid); + + fidp = lookup_fid(s, fid); + if (fidp == NULL) { + err = -ENOENT; + goto out; + } + + v9fs_string_init(&vs->target); + err = v9fs_do_readlink(s, &fidp->path, &vs->target); + v9fs_readlink_post_readlink(s, vs, err); + return; +out: + complete_pdu(s, vs->pdu, err); + qemu_free(vs); +} + typedef void (pdu_handler_t)(V9fsState *s, V9fsPDU *pdu); static pdu_handler_t *pdu_handlers[] = { @@ -3414,6 +3457,7 @@ static pdu_handler_t *pdu_handlers[] = { [P9_TXATTRCREATE] = v9fs_xattrcreate, [P9_TMKNOD] = v9fs_mknod, [P9_TRENAME] = v9fs_rename, + [P9_TREADLINK] = v9fs_readlink, [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 0816ad6..bbc23d5 100644 --- a/hw/virtio-9p.h +++ b/hw/virtio-9p.h @@ -27,6 +27,8 @@ enum { P9_RMKNOD, P9_TRENAME = 20, P9_RRENAME, + P9_TREADLINK = 22, + P9_RREADLINK, P9_TGETATTR = 24, P9_RGETATTR, P9_TSETATTR = 26, @@ -434,6 +436,13 @@ typedef struct V9fsXattrState void *value; } V9fsXattrState; +typedef struct V9fsReadLinkState +{ + V9fsPDU *pdu; + size_t offset; + V9fsString target; +} V9fsReadLinkState; + extern size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count, size_t offset, size_t size, int pack); -- 1.7.0.4