From patchwork Tue Jun 1 09:28:46 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 54157 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 CFE47B7D24 for ; Tue, 1 Jun 2010 19:34:02 +1000 (EST) Received: from localhost ([127.0.0.1]:57700 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OJNrC-0007Xe-Nf for incoming@patchwork.ozlabs.org; Tue, 01 Jun 2010 05:33:58 -0400 Received: from [140.186.70.92] (port=37103 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OJNmS-00063z-Jr for qemu-devel@nongnu.org; Tue, 01 Jun 2010 05:29:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OJNmQ-0005KW-OP for qemu-devel@nongnu.org; Tue, 01 Jun 2010 05:29:04 -0400 Received: from e28smtp04.in.ibm.com ([122.248.162.4]:45062) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJNmP-0005JG-6X for qemu-devel@nongnu.org; Tue, 01 Jun 2010 05:29:02 -0400 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by e28smtp04.in.ibm.com (8.14.4/8.13.1) with ESMTP id o519St86018275 for ; Tue, 1 Jun 2010 14:58:55 +0530 Received: from d28av05.in.ibm.com (d28av05.in.ibm.com [9.184.220.67]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o519St2L970980 for ; Tue, 1 Jun 2010 14:58:55 +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 o519Ssmb028837 for ; Tue, 1 Jun 2010 19:28:55 +1000 Received: from skywalker.in.ibm.com (K50wks273996wss.in.ibm.com [9.124.35.158]) by d28av05.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o519SsSN028832; Tue, 1 Jun 2010 19:28:54 +1000 From: "Aneesh Kumar K.V" To: qemu-devel@nongnu.org Date: Tue, 1 Jun 2010 14:58:46 +0530 Message-Id: <1275384529-28757-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1.236.g81fa0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: ericvh@gmail.com, v9fs-developer@lists.sourceforge.net, aliguori@us.ibm.com, "Aneesh Kumar K.V" Subject: [Qemu-devel] [PATCH 1/4] virtio-9p: Add fidtype so that we can do type specific operation 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 We want to add type specific operation during read/write Signed-off-by: Aneesh Kumar K.V --- hw/virtio-9p.c | 99 +++++++++++++++++++++++++++++++------------------------- hw/virtio-9p.h | 24 ++++++++++++- 2 files changed, 77 insertions(+), 46 deletions(-) diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index 1c7a428..2558e0e 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -415,8 +415,7 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t fid) f = qemu_mallocz(sizeof(V9fsFidState)); f->fid = fid; - f->fd = -1; - f->dir = NULL; + f->fid_type = P9_FID_NONE; f->next = s->fid_list; s->fid_list = f; @@ -441,11 +440,20 @@ static int free_fid(V9fsState *s, int32_t fid) fidp = *fidpp; *fidpp = fidp->next; - if (fidp->fd != -1) { - v9fs_do_close(s, fidp->fd); + if (fidp->fid_type == P9_FID_FILE) { + if (fidp->fs.fd != -1) { + v9fs_do_close(s, fidp->fs.fd); + } + } + if (fidp->fid_type == P9_FID_DIR) { + if (fidp->fs.dir) { + v9fs_do_closedir(s, fidp->fs.dir); + } } - if (fidp->dir) { - v9fs_do_closedir(s, fidp->dir); + if (fidp->fid_type == P9_FID_XATTR) { + if (fidp->fs.xattr.value) { + qemu_free(fidp->fs.xattr.value); + } } v9fs_string_free(&fidp->path); qemu_free(fidp); @@ -1343,8 +1351,7 @@ static void v9fs_walk(V9fsState *s, V9fsPDU *pdu) /* FIXME: is this really valid? */ if (fid == newfid) { - BUG_ON(vs->fidp->fd != -1); - BUG_ON(vs->fidp->dir); + BUG_ON(vs->fidp->fid_type != P9_FID_NONE); v9fs_string_init(&vs->path); vs->name_idx = 0; @@ -1388,11 +1395,12 @@ out: static void v9fs_open_post_opendir(V9fsState *s, V9fsOpenState *vs, int err) { - if (vs->fidp->dir == NULL) { + if (vs->fidp->fs.dir == NULL) { err = -errno; goto out; } + vs->fidp->fid_type = P9_FID_DIR; vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, 0); err = vs->offset; out: @@ -1403,11 +1411,12 @@ out: static void v9fs_open_post_open(V9fsState *s, V9fsOpenState *vs, int err) { - if (vs->fidp->fd == -1) { + if (vs->fidp->fs.fd == -1) { err = -errno; goto out; } + vs->fidp->fid_type = P9_FID_FILE; vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, 0); err = vs->offset; out: @@ -1425,10 +1434,10 @@ static void v9fs_open_post_lstat(V9fsState *s, V9fsOpenState *vs, int err) stat_to_qid(&vs->stbuf, &vs->qid); if (S_ISDIR(vs->stbuf.st_mode)) { - vs->fidp->dir = v9fs_do_opendir(s, &vs->fidp->path); + vs->fidp->fs.dir = v9fs_do_opendir(s, &vs->fidp->path); v9fs_open_post_opendir(s, vs, err); } else { - vs->fidp->fd = v9fs_do_open(s, &vs->fidp->path, + vs->fidp->fs.fd = v9fs_do_open(s, &vs->fidp->path, omode_to_uflags(vs->mode)); v9fs_open_post_open(s, vs, err); } @@ -1457,8 +1466,7 @@ static void v9fs_open(V9fsState *s, V9fsPDU *pdu) goto out; } - BUG_ON(vs->fidp->fd != -1); - BUG_ON(vs->fidp->dir); + BUG_ON(vs->fidp->fid_type != P9_FID_NONE); err = v9fs_do_lstat(s, &vs->fidp->path, &vs->stbuf); @@ -1522,7 +1530,7 @@ static void v9fs_read_post_dir_lstat(V9fsState *s, V9fsReadState *vs, &vs->v9stat); if ((vs->len != (vs->v9stat.size + 2)) || ((vs->count + vs->len) > vs->max_count)) { - v9fs_do_seekdir(s, vs->fidp->dir, vs->dir_pos); + v9fs_do_seekdir(s, vs->fidp->fs.dir, vs->dir_pos); v9fs_read_post_seekdir(s, vs, err); return; } @@ -1530,11 +1538,11 @@ static void v9fs_read_post_dir_lstat(V9fsState *s, V9fsReadState *vs, v9fs_stat_free(&vs->v9stat); v9fs_string_free(&vs->name); vs->dir_pos = vs->dent->d_off; - vs->dent = v9fs_do_readdir(s, vs->fidp->dir); + vs->dent = v9fs_do_readdir(s, vs->fidp->fs.dir); v9fs_read_post_readdir(s, vs, err); return; out: - v9fs_do_seekdir(s, vs->fidp->dir, vs->dir_pos); + v9fs_do_seekdir(s, vs->fidp->fs.dir, vs->dir_pos); v9fs_read_post_seekdir(s, vs, err); return; @@ -1562,7 +1570,7 @@ static void v9fs_read_post_readdir(V9fsState *s, V9fsReadState *vs, ssize_t err) static void v9fs_read_post_telldir(V9fsState *s, V9fsReadState *vs, ssize_t err) { - vs->dent = v9fs_do_readdir(s, vs->fidp->dir); + vs->dent = v9fs_do_readdir(s, vs->fidp->fs.dir); v9fs_read_post_readdir(s, vs, err); return; } @@ -1570,7 +1578,7 @@ static void v9fs_read_post_telldir(V9fsState *s, V9fsReadState *vs, ssize_t err) static void v9fs_read_post_rewinddir(V9fsState *s, V9fsReadState *vs, ssize_t err) { - vs->dir_pos = v9fs_do_telldir(s, vs->fidp->dir); + vs->dir_pos = v9fs_do_telldir(s, vs->fidp->fs.dir); v9fs_read_post_telldir(s, vs, err); return; } @@ -1589,7 +1597,7 @@ static void v9fs_read_post_readv(V9fsState *s, V9fsReadState *vs, ssize_t err) if (0) { print_sg(vs->sg, vs->cnt); } - vs->len = v9fs_do_readv(s, vs->fidp->fd, vs->sg, vs->cnt); + vs->len = v9fs_do_readv(s, vs->fidp->fs.fd, vs->sg, vs->cnt); } while (vs->len == -1 && errno == EINTR); if (vs->len == -1) { err = -errno; @@ -1619,7 +1627,7 @@ static void v9fs_read_post_lseek(V9fsState *s, V9fsReadState *vs, ssize_t err) if (0) { print_sg(vs->sg, vs->cnt); } - vs->len = v9fs_do_readv(s, vs->fidp->fd, vs->sg, vs->cnt); + vs->len = v9fs_do_readv(s, vs->fidp->fs.fd, vs->sg, vs->cnt); } while (vs->len == -1 && errno == EINTR); if (vs->len == -1) { err = -errno; @@ -1653,18 +1661,18 @@ static void v9fs_read(V9fsState *s, V9fsPDU *pdu) goto out; } - if (vs->fidp->dir) { + if (vs->fidp->fs.dir) { vs->max_count = vs->count; vs->count = 0; if (vs->off == 0) { - v9fs_do_rewinddir(s, vs->fidp->dir); + v9fs_do_rewinddir(s, vs->fidp->fs.dir); } v9fs_read_post_rewinddir(s, vs, err); return; - } else if (vs->fidp->fd != -1) { + } else if (vs->fidp->fs.fd != -1) { vs->sg = vs->iov; pdu_marshal(vs->pdu, vs->offset + 4, "v", vs->sg, &vs->cnt); - err = v9fs_do_lseek(s, vs->fidp->fd, vs->off, SEEK_SET); + err = v9fs_do_lseek(s, vs->fidp->fs.fd, vs->off, SEEK_SET); v9fs_read_post_lseek(s, vs, err); return; } else { @@ -1711,7 +1719,7 @@ static void v9fs_readdir_post_readdir(V9fsState *s, V9fsReadDirState *vs) if ((vs->count + V9_READDIR_DATA_SZ) > vs->max_count) { /* Ran out of buffer. Set dir back to old position and return */ - v9fs_do_seekdir(s, vs->fidp->dir, vs->saved_dir_pos); + v9fs_do_seekdir(s, vs->fidp->fs.dir, vs->saved_dir_pos); v9fs_readdir_post_seekdir(s, vs); return; } @@ -1722,7 +1730,7 @@ static void v9fs_readdir_post_readdir(V9fsState *s, V9fsReadDirState *vs) vs->count += len; v9fs_string_free(&vs->name); vs->saved_dir_pos = vs->dent->d_off; - vs->dent = v9fs_do_readdir(s, vs->fidp->dir); + vs->dent = v9fs_do_readdir(s, vs->fidp->fs.dir); v9fs_readdir_post_readdir(s, vs); return; } @@ -1736,14 +1744,14 @@ static void v9fs_readdir_post_readdir(V9fsState *s, V9fsReadDirState *vs) static void v9fs_readdir_post_telldir(V9fsState *s, V9fsReadDirState *vs) { - vs->dent = v9fs_do_readdir(s, vs->fidp->dir); + vs->dent = v9fs_do_readdir(s, vs->fidp->fs.dir); v9fs_readdir_post_readdir(s, vs); return; } static void v9fs_readdir_post_setdir(V9fsState *s, V9fsReadDirState *vs) { - vs->saved_dir_pos = v9fs_do_telldir(s, vs->fidp->dir); + vs->saved_dir_pos = v9fs_do_telldir(s, vs->fidp->fs.dir); v9fs_readdir_post_telldir(s, vs); return; } @@ -1764,15 +1772,17 @@ static void v9fs_readdir(V9fsState *s, V9fsPDU *pdu) &vs->max_count); vs->fidp = lookup_fid(s, fid); - if (vs->fidp == NULL || !(vs->fidp->dir)) { + if (vs->fidp == NULL || + vs->fidp->fid_type != P9_FID_DIR || + !(vs->fidp->fs.dir)) { err = -EINVAL; goto out; } if (vs->initial_offset == 0) { - v9fs_do_rewinddir(s, vs->fidp->dir); + v9fs_do_rewinddir(s, vs->fidp->fs.dir); } else { - v9fs_do_seekdir(s, vs->fidp->dir, vs->initial_offset); + v9fs_do_seekdir(s, vs->fidp->fs.dir, vs->initial_offset); } v9fs_readdir_post_setdir(s, vs); @@ -1799,7 +1809,7 @@ static void v9fs_write_post_writev(V9fsState *s, V9fsWriteState *vs, if (0) { print_sg(vs->sg, vs->cnt); } - vs->len = v9fs_do_writev(s, vs->fidp->fd, vs->sg, vs->cnt); + vs->len = v9fs_do_writev(s, vs->fidp->fs.fd, vs->sg, vs->cnt); } while (vs->len == -1 && errno == EINTR); if (vs->len == -1) { err = -errno; @@ -1828,7 +1838,7 @@ static void v9fs_write_post_lseek(V9fsState *s, V9fsWriteState *vs, ssize_t err) if (0) { print_sg(vs->sg, vs->cnt); } - vs->len = v9fs_do_writev(s, vs->fidp->fd, vs->sg, vs->cnt); + vs->len = v9fs_do_writev(s, vs->fidp->fs.fd, vs->sg, vs->cnt); } while (vs->len == -1 && errno == EINTR); if (vs->len == -1) { err = -errno; @@ -1865,12 +1875,12 @@ static void v9fs_write(V9fsState *s, V9fsPDU *pdu) goto out; } - if (vs->fidp->fd == -1) { + if (vs->fidp->fs.fd == -1) { err = -EINVAL; goto out; } - err = v9fs_do_lseek(s, vs->fidp->fd, vs->off, SEEK_SET); + err = v9fs_do_lseek(s, vs->fidp->fs.fd, vs->off, SEEK_SET); v9fs_write_post_lseek(s, vs, err); return; @@ -1909,9 +1919,10 @@ static void v9fs_create_post_perms(V9fsState *s, V9fsCreateState *vs, int err) static void v9fs_create_post_opendir(V9fsState *s, V9fsCreateState *vs, int err) { - if (!vs->fidp->dir) { + if (!vs->fidp->fs.dir) { err = -errno; } + vs->fidp->fid_type = P9_FID_DIR; v9fs_post_create(s, vs, err); } @@ -1923,7 +1934,7 @@ static void v9fs_create_post_dir_lstat(V9fsState *s, V9fsCreateState *vs, goto out; } - vs->fidp->dir = v9fs_do_opendir(s, &vs->fullname); + vs->fidp->fs.dir = v9fs_do_opendir(s, &vs->fullname); v9fs_create_post_opendir(s, vs, err); return; @@ -1949,7 +1960,7 @@ out: static void v9fs_create_post_fstat(V9fsState *s, V9fsCreateState *vs, int err) { if (err) { - vs->fidp->fd = -1; + vs->fidp->fs.fd = -1; err = -errno; } @@ -1959,12 +1970,12 @@ static void v9fs_create_post_fstat(V9fsState *s, V9fsCreateState *vs, int err) static void v9fs_create_post_open2(V9fsState *s, V9fsCreateState *vs, int err) { - if (vs->fidp->fd == -1) { + if (vs->fidp->fs.fd == -1) { err = -errno; goto out; } - - err = v9fs_do_fstat(s, vs->fidp->fd, &vs->stbuf); + vs->fidp->fid_type = P9_FID_FILE; + err = v9fs_do_fstat(s, vs->fidp->fs.fd, &vs->stbuf); v9fs_create_post_fstat(s, vs, err); return; @@ -2031,7 +2042,7 @@ static void v9fs_create_post_lstat(V9fsState *s, V9fsCreateState *vs, int err) err = v9fs_do_mknod(s, vs, S_IFSOCK | (vs->perm & 0777), 0); v9fs_post_create(s, vs, err); } else { - vs->fidp->fd = v9fs_do_open2(s, vs); + vs->fidp->fs.fd = v9fs_do_open2(s, vs); v9fs_create_post_open2(s, vs, err); } @@ -2420,7 +2431,7 @@ static void v9fs_wstat(V9fsState *s, V9fsPDU *pdu) /* do we need to sync the file? */ if (donttouch_stat(&vs->v9stat)) { - err = v9fs_do_fsync(s, vs->fidp->fd); + err = v9fs_do_fsync(s, vs->fidp->fs.fd); v9fs_wstat_post_fsync(s, vs, err); return; } diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h index d033271..942e448 100644 --- a/hw/virtio-9p.h +++ b/hw/virtio-9p.h @@ -137,12 +137,32 @@ typedef struct V9fsStat int32_t n_muid; } V9fsStat; +enum { + P9_FID_NONE = 0, + P9_FID_FILE, + P9_FID_DIR, + P9_FID_XATTR, +}; + +typedef struct V9fsXattr +{ + int64_t copied_len; + int64_t len; + void *value; + V9fsString name; + int flags; +} V9fsXattr; + struct V9fsFidState { + int fid_type; int32_t fid; V9fsString path; - int fd; - DIR *dir; + union { + int fd; + DIR *dir; + V9fsXattr xattr; + } fs; uid_t uid; V9fsFidState *next; };