From patchwork Wed Mar 3 19:01:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 46872 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 D18A1B7CE6 for ; Thu, 4 Mar 2010 06:42:38 +1100 (EST) Received: from localhost ([127.0.0.1]:46025 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NmuL6-0002NY-9g for incoming@patchwork.ozlabs.org; Wed, 03 Mar 2010 14:34:36 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NmtpZ-0007b4-9j for qemu-devel@nongnu.org; Wed, 03 Mar 2010 14:02:01 -0500 Received: from [199.232.76.173] (port=60478 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NmtpX-0007ZQ-Rl for qemu-devel@nongnu.org; Wed, 03 Mar 2010 14:02:00 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NmtpW-0001c7-N2 for qemu-devel@nongnu.org; Wed, 03 Mar 2010 14:01:59 -0500 Received: from e39.co.us.ibm.com ([32.97.110.160]:43353) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NmtpW-0001bo-5W for qemu-devel@nongnu.org; Wed, 03 Mar 2010 14:01:58 -0500 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by e39.co.us.ibm.com (8.14.3/8.13.1) with ESMTP id o23IsFFk008902 for ; Wed, 3 Mar 2010 11:54:15 -0700 Received: from d03av06.boulder.ibm.com (d03av06.boulder.ibm.com [9.17.195.245]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o23J1lkl046034 for ; Wed, 3 Mar 2010 12:01:49 -0700 Received: from d03av06.boulder.ibm.com (loopback [127.0.0.1]) by d03av06.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o23J3jCF010114 for ; Wed, 3 Mar 2010 12:03:45 -0700 Received: from localhost.localdomain (sig-9-76-214-227.mts.ibm.com [9.76.214.227]) by d03av06.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o23J3daI009640; Wed, 3 Mar 2010 12:03:45 -0700 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Wed, 3 Mar 2010 13:01:06 -0600 Message-Id: <1267642874-15001-11-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.6.5.2 In-Reply-To: <1267642874-15001-1-git-send-email-aliguori@us.ibm.com> References: <1267642874-15001-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Anthony Liguori , Venkateswararao Jujjuri , "Aneesh Kumar K.V" Subject: [Qemu-devel] [PATCH 09/17] virtio-9p: Implement P9_TWRITE 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 This gets write to file to work Signed-off-by: Anthony Liguori Signed-off-by: Venkateswararao Jujjuri Signed-off-by: Aneesh Kumar K.V --- hw/virtio-9p-local.c | 7 ++++ hw/virtio-9p.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 102 insertions(+), 2 deletions(-) diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c index 90664a0..441d22d 100644 --- a/hw/virtio-9p-local.c +++ b/hw/virtio-9p-local.c @@ -129,6 +129,12 @@ static off_t local_lseek(void *opaque, int fd, off_t offset, int whence) return lseek(fd, offset, whence); } +static ssize_t local_writev(void *opaque, int fd, const struct iovec *iov, + int iovcnt) +{ + return writev(fd, iov, iovcnt); +} + static V9fsPosixFileOperations ops = { .lstat = local_lstat, .setuid = local_setuid, @@ -143,6 +149,7 @@ static V9fsPosixFileOperations ops = { .seekdir = local_seekdir, .readv = local_readv, .lseek = local_lseek, + .writev = local_writev, }; V9fsPosixFileOperations *virtio_9p_init_local(const char *path) diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index 7822a00..b0662ba 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -168,6 +168,12 @@ static off_t posix_lseek(V9fsState *s, int fd, off_t offset, int whence) return s->ops->lseek(s->ops->opaque, fd, offset, whence); } +static int posix_writev(V9fsState *s, int fd, const struct iovec *iov, + int iovcnt) +{ + return s->ops->writev(s->ops->opaque, fd, iov, iovcnt); +} + static void v9fs_string_init(V9fsString *str) { str->data = NULL; @@ -1321,10 +1327,97 @@ out: complete_pdu(s, pdu, err); } +typedef struct V9fsWriteState { + V9fsPDU *pdu; + size_t offset; + int32_t fid; + int32_t len; + int32_t count; + int32_t total; + int64_t off; + V9fsFidState *fidp; + struct iovec iov[128]; /* FIXME: bad, bad, bad */ + struct iovec *sg; + int cnt; +} V9fsWriteState; + +static void v9fs_write_post_writev(V9fsState *s, V9fsWriteState *vs, + ssize_t err) +{ + BUG_ON(vs->len < 0); + vs->total += vs->len; + vs->sg = adjust_sg(vs->sg, vs->len, &vs->cnt); + if (vs->total < vs->count && vs->len > 0) { + do { + if (0) + print_sg(vs->sg, vs->cnt); + vs->len = posix_writev(s, vs->fidp->fd, vs->sg, vs->cnt); + } while (vs->len == -1 && errno == EINTR); + v9fs_write_post_writev(s, vs, err); + } + vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", vs->total); + + err = vs->offset; + complete_pdu(s, vs->pdu, err); + qemu_free(vs); +} + +static void v9fs_write_post_lseek(V9fsState *s, V9fsWriteState *vs, ssize_t err) +{ + BUG_ON(err == -1); + + vs->sg = cap_sg(vs->sg, vs->count, &vs->cnt); + + if (vs->total < vs->count) { + do { + if (0) + print_sg(vs->sg, vs->cnt); + vs->len = posix_writev(s, vs->fidp->fd, vs->sg, vs->cnt); + } while (vs->len == -1 && errno == EINTR); + + v9fs_write_post_writev(s, vs, err); + return; + } + + complete_pdu(s, vs->pdu, err); + qemu_free(vs); +} + static void v9fs_write(V9fsState *s, V9fsPDU *pdu) { - if (debug_9p_pdu) - pprint_pdu(pdu); + V9fsWriteState *vs; + ssize_t err; + + vs = qemu_malloc(sizeof(*vs)); + + vs->pdu = pdu; + vs->offset = 7; + vs->sg = vs->iov; + vs->total = 0; + vs->len = 0; + + pdu_unmarshal(vs->pdu, vs->offset, "dqdv", &vs->fid, &vs->off, &vs->count, + vs->sg, &vs->cnt); + + vs->fidp = lookup_fid(s, vs->fid); + if (vs->fidp == NULL) { + err = -EINVAL; + goto out; + } + + if (vs->fidp->fd == -1) { + err = -EINVAL; + goto out; + } + + err = posix_lseek(s, vs->fidp->fd, vs->off, SEEK_SET); + + v9fs_write_post_lseek(s, vs, err); + return; + +out: + complete_pdu(s, vs->pdu, err); + qemu_free(vs); } static void v9fs_create(V9fsState *s, V9fsPDU *pdu)