From patchwork Tue Jun 1 14:17:14 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: 103543 Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o51EHepX009167 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 1 Jun 2010 14:18:16 GMT Received: from localhost ([127.0.0.1] helo=sfs-ml-4.v29.ch3.sourceforge.com) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1OJSHd-0003e9-Rb; Tue, 01 Jun 2010 14:17:33 +0000 Received: from sfi-mx-2.v28.ch3.sourceforge.com ([172.29.28.122] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1OJSHd-0003dx-7U for v9fs-developer@lists.sourceforge.net; Tue, 01 Jun 2010 14:17:33 +0000 Received-SPF: pass (sfi-mx-2.v28.ch3.sourceforge.com: domain of in.ibm.com designates 122.248.162.3 as permitted sender) client-ip=122.248.162.3; envelope-from=mohan@in.ibm.com; helo=e28smtp03.in.ibm.com; Received: from e28smtp03.in.ibm.com ([122.248.162.3]) by sfi-mx-2.v28.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.69) id 1OJSHZ-0001LP-Ay for v9fs-developer@lists.sourceforge.net; Tue, 01 Jun 2010 14:17:33 +0000 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by e28smtp03.in.ibm.com (8.14.4/8.13.1) with ESMTP id o51EHGNw014589 for ; Tue, 1 Jun 2010 19:47:16 +0530 Received: from d28av05.in.ibm.com (d28av05.in.ibm.com [9.184.220.67]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o51EHFZh3121372 for ; Tue, 1 Jun 2010 19:47:15 +0530 Received: from d28av05.in.ibm.com (loopback [127.0.0.1]) by d28av05.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o51EHFDu028840 for ; Wed, 2 Jun 2010 00:17:15 +1000 Received: from localhost.localdomain ([9.77.202.116]) by d28av05.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o51EHEJI028825; Wed, 2 Jun 2010 00:17:15 +1000 From: "M. Mohan Kumar" To: qemu-devel@nongnu.org, v9fs-developer@lists.sourceforge.net Date: Tue, 1 Jun 2010 19:47:14 +0530 Message-Id: <1275401834-27520-1-git-send-email-mohan@in.ibm.com> X-Mailer: git-send-email 1.6.6.1 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 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1OJSHZ-0001LP-Ay Subject: [V9fs-developer] qemu:virtio-9p: [RFC] [PATCH 01/02] Send iounit to client for read/write operations 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 (demeter.kernel.org [140.211.167.41]); Tue, 01 Jun 2010 14:18:16 +0000 (UTC) diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index f087122..4357f1f 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -1,4 +1,4 @@ -/* + /* * Virtio 9p backend * * Copyright IBM, Corp. 2010 @@ -269,6 +269,11 @@ static int v9fs_do_fsync(V9fsState *s, int fd) return s->ops->fsync(&s->ctx, fd); } +static int v9fs_do_statfs(V9fsState *s, V9fsString *path, struct statfs *stbuf) +{ + return s->ops->statfs(&s->ctx, path->data, stbuf); +} + static void v9fs_string_init(V9fsString *str) { str->data = NULL; @@ -1035,11 +1040,10 @@ static void v9fs_fix_path(V9fsString *dst, V9fsString *src, int len) static void v9fs_version(V9fsState *s, V9fsPDU *pdu) { - int32_t msize; V9fsString version; size_t offset = 7; - pdu_unmarshal(pdu, offset, "ds", &msize, &version); + pdu_unmarshal(pdu, offset, "ds", &s->msize, &version); if (!strcmp(version.data, "9P2000.u")) { s->proto_version = V9FS_PROTO_2000U; @@ -1049,7 +1053,7 @@ static void v9fs_version(V9fsState *s, V9fsPDU *pdu) v9fs_string_sprintf(&version, "unknown"); } - offset += pdu_marshal(pdu, offset, "ds", msize, &version); + offset += pdu_marshal(pdu, offset, "ds", s->msize, &version); complete_pdu(s, pdu, offset); v9fs_string_free(&version); @@ -1304,6 +1308,20 @@ out: v9fs_walk_complete(s, vs, err); } +static int32_t get_iounit(V9fsState *s, V9fsString *name) +{ + struct statfs stbuf; + int32_t iounit = 0; + + + if (!v9fs_do_statfs(s, name, &stbuf)) { + iounit = stbuf.f_bsize; + iounit *= (s->msize - P9_IOHDRSZ)/stbuf.f_bsize; + } + + return iounit; +} + static void v9fs_open_post_opendir(V9fsState *s, V9fsOpenState *vs, int err) { if (vs->fidp->dir == NULL) { @@ -1321,12 +1339,15 @@ out: static void v9fs_open_post_open(V9fsState *s, V9fsOpenState *vs, int err) { + int32_t iounit; + if (vs->fidp->fd == -1) { err = -errno; goto out; } - vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, 0); + iounit = get_iounit(s, &vs->fidp->path); + vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, iounit); err = vs->offset; out: complete_pdu(s, vs->pdu, err); @@ -1800,11 +1821,16 @@ out: static void v9fs_post_create(V9fsState *s, V9fsCreateState *vs, int err) { + int32_t iounit; + + iounit = get_iounit(s, &vs->fidp->path); + if (err == 0) { v9fs_string_copy(&vs->fidp->path, &vs->fullname); stat_to_qid(&vs->stbuf, &vs->qid); - vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, 0); + vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, + iounit); err = vs->offset; } @@ -2295,23 +2321,25 @@ out: qemu_free(vs); } -static int v9fs_do_statfs(V9fsState *s, V9fsString *path, struct statfs *stbuf) -{ - return s->ops->statfs(&s->ctx, path->data, stbuf); -} - static void v9fs_statfs_post_statfs(V9fsState *s, V9fsStatfsState *vs, int err) { + int32_t bsize_factor; + if (err) { err = -errno; goto out; } + bsize_factor = (s->msize - P9_IOHDRSZ)/vs->stbuf.f_bsize; + if (!bsize_factor) { + bsize_factor = 1; + } vs->v9statfs.f_type = vs->stbuf.f_type; vs->v9statfs.f_bsize = vs->stbuf.f_bsize; - vs->v9statfs.f_blocks = vs->stbuf.f_blocks; - vs->v9statfs.f_bfree = vs->stbuf.f_bfree; - vs->v9statfs.f_bavail = vs->stbuf.f_bavail; + vs->v9statfs.f_bsize *= bsize_factor; + vs->v9statfs.f_blocks = vs->stbuf.f_blocks/bsize_factor; + vs->v9statfs.f_bfree = vs->stbuf.f_bfree/bsize_factor; + vs->v9statfs.f_bavail = vs->stbuf.f_bavail/bsize_factor; vs->v9statfs.f_files = vs->stbuf.f_files; vs->v9statfs.f_ffree = vs->stbuf.f_ffree; vs->v9statfs.fsid_val = (unsigned int) vs->stbuf.f_fsid.__val[0] | diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h index 6b3d4a4..9264163 100644 --- a/hw/virtio-9p.h +++ b/hw/virtio-9p.h @@ -72,6 +72,8 @@ enum p9_proto_version { #define P9_NOFID (u32)(~0) #define P9_MAXWELEM 16 +#define P9_IOHDRSZ 24 + typedef struct V9fsPDU V9fsPDU; struct V9fsPDU @@ -156,6 +158,7 @@ typedef struct V9fsState uint8_t *tag; size_t config_size; enum p9_proto_version proto_version; + int32_t msize; } V9fsState; typedef struct V9fsCreateState {