From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: ericvh@gmail.com, aliguori@us.ibm.com,
"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH -V3 20/32] virtio-9p: Remove BUG_ON and add proper error handling
Date: Thu, 25 Mar 2010 22:13:28 +0530 [thread overview]
Message-ID: <1269535420-31206-21-git-send-email-aneesh.kumar@linux.vnet.ibm.com> (raw)
In-Reply-To: <1269535420-31206-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
hw/virtio-9p.c | 106 ++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 84 insertions(+), 22 deletions(-)
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 1237bac..3ce26ca 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -244,7 +244,6 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t fid)
return NULL;
f = qemu_mallocz(sizeof(V9fsFidState));
- BUG_ON(f == NULL);
f->fid = fid;
f->fd = -1;
@@ -320,15 +319,18 @@ static void stat_to_qid(const struct stat *stbuf, V9fsQID *qidp)
qidp->type |= P9_QID_TYPE_SYMLINK;
}
-static void fid_to_qid(V9fsState *s, V9fsFidState *fidp, V9fsQID *qidp)
+static int fid_to_qid(V9fsState *s, V9fsFidState *fidp, V9fsQID *qidp)
{
struct stat stbuf;
int err;
err = posix_lstat(s, &fidp->path, &stbuf);
- BUG_ON(err == -1);
+ if (err) {
+ return err;
+ }
stat_to_qid(&stbuf, qidp);
+ return 0;
}
static V9fsPDU *alloc_pdu(V9fsState *s)
@@ -653,7 +655,7 @@ static uint32_t stat_to_v9mode(const struct stat *stbuf)
return mode;
}
-static void stat_to_v9stat(V9fsState *s, V9fsString *name,
+static int stat_to_v9stat(V9fsState *s, V9fsString *name,
const struct stat *stbuf,
V9fsStat *v9stat)
{
@@ -681,7 +683,10 @@ static void stat_to_v9stat(V9fsState *s, V9fsString *name,
if (v9stat->mode & P9_STAT_MODE_SYMLINK) {
err = posix_readlink(s, name, &v9stat->extension);
- BUG_ON(err == -1);
+ if (err == -1) {
+ err = -errno;
+ return err;
+ }
v9stat->extension.data[err] = 0;
v9stat->extension.size = err;
} else if (v9stat->mode & P9_STAT_MODE_DEVICE) {
@@ -708,6 +713,7 @@ static void stat_to_v9stat(V9fsState *s, V9fsString *name,
v9fs_string_size(&v9stat->gid) +
v9fs_string_size(&v9stat->muid) +
v9fs_string_size(&v9stat->extension);
+ return 0;
}
static void v9fs_version(V9fsState *s, V9fsPDU *pdu)
@@ -745,7 +751,12 @@ static void v9fs_attach(V9fsState *s, V9fsPDU *pdu)
fidp->uid = n_uname;
v9fs_string_sprintf(&fidp->path, "%s", "/");
- fid_to_qid(s, fidp, &qid);
+ err = fid_to_qid(s, fidp, &qid);
+ if (err) {
+ err = -EINVAL;
+ free_fid(s, fid);
+ goto out;
+ }
offset += pdu_marshal(pdu, offset, "Q", &qid);
@@ -772,7 +783,10 @@ static void v9fs_stat_post_lstat(V9fsState *s, V9fsStatState *vs, int err)
goto out;
}
- stat_to_v9stat(s, &vs->fidp->path, &vs->stbuf, &vs->v9stat);
+ err = stat_to_v9stat(s, &vs->fidp->path, &vs->stbuf, &vs->v9stat);
+ if (err) {
+ goto out;
+ }
vs->offset += pdu_marshal(vs->pdu, vs->offset, "wS", 0, &vs->v9stat);
err = vs->offset;
@@ -925,10 +939,8 @@ static void v9fs_walk(V9fsState *s, V9fsPDU *pdu)
if(vs->nwnames) {
vs->wnames = qemu_mallocz(sizeof(vs->wnames[0]) * vs->nwnames);
- BUG_ON(vs->wnames == NULL);
vs->qids = qemu_mallocz(sizeof(vs->qids[0]) * vs->nwnames);
- BUG_ON(vs->qids == NULL);
for (i = 0; i < vs->nwnames; i++) {
vs->offset += pdu_unmarshal(vs->pdu, vs->offset, "s",
@@ -1070,7 +1082,10 @@ out:
static void v9fs_open_post_lstat(V9fsState *s, V9fsOpenState *vs, int err)
{
- BUG_ON(err == -1);
+ if (err) {
+ err = -errno;
+ goto out;
+ }
stat_to_qid(&vs->stbuf, &vs->qid);
@@ -1082,7 +1097,10 @@ static void v9fs_open_post_lstat(V9fsState *s, V9fsOpenState *vs, int err)
omode_to_uflags(vs->mode));
v9fs_open_post_open(s, vs, err);
}
-
+ return;
+out:
+ complete_pdu(s, vs->pdu, err);
+ qemu_free(vs);
}
static void v9fs_open(V9fsState *s, V9fsPDU *pdu)
@@ -1186,11 +1204,15 @@ static void v9fs_read_post_readdir(V9fsState *, V9fsReadState *, ssize_t );
static void v9fs_read_post_seekdir(V9fsState *s, V9fsReadState *vs, ssize_t err)
{
+ if (err) {
+ goto out;
+ }
v9fs_stat_free(&vs->v9stat);
v9fs_string_free(&vs->name);
vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", vs->count);
vs->offset += vs->count;
err = vs->offset;
+out:
complete_pdu(s, vs->pdu, err);
qemu_free(vs);
return;
@@ -1199,8 +1221,14 @@ static void v9fs_read_post_seekdir(V9fsState *s, V9fsReadState *vs, ssize_t err)
static void v9fs_read_post_dir_lstat(V9fsState *s, V9fsReadState *vs,
ssize_t err)
{
- BUG_ON(err == -1);
- stat_to_v9stat(s, &vs->name, &vs->stbuf, &vs->v9stat);
+ if (err) {
+ err = -errno;
+ goto out;
+ }
+ err = stat_to_v9stat(s, &vs->name, &vs->stbuf, &vs->v9stat);
+ if (err) {
+ goto out;
+ }
vs->len = pdu_marshal(vs->pdu, vs->offset + 4 + vs->count, "S",
&vs->v9stat);
@@ -1217,6 +1245,11 @@ static void v9fs_read_post_dir_lstat(V9fsState *s, V9fsReadState *vs,
vs->dent = posix_readdir(s, vs->fidp->dir);
v9fs_read_post_readdir(s, vs, err);
return;
+out:
+ posix_seekdir(s, vs->fidp->dir, vs->dir_pos);
+ v9fs_read_post_seekdir(s, vs, err);
+ return;
+
}
static void v9fs_read_post_readdir(V9fsState *s, V9fsReadState *vs, ssize_t err)
@@ -1256,7 +1289,11 @@ static void v9fs_read_post_rewinddir(V9fsState *s, V9fsReadState *vs,
static void v9fs_read_post_readv(V9fsState *s, V9fsReadState *vs, ssize_t err)
{
- BUG_ON(vs->len < 0);
+ if (err < 0) {
+ /* IO error return the error */
+ err = -errno;
+ goto out;
+ }
vs->total += vs->len;
vs->sg = adjust_sg(vs->sg, vs->len, &vs->cnt);
if (vs->total < vs->count && vs->len > 0) {
@@ -1266,19 +1303,27 @@ static void v9fs_read_post_readv(V9fsState *s, V9fsReadState *vs, ssize_t err)
}
vs->len = posix_readv(s, vs->fidp->fd, vs->sg, vs->cnt);
} while (vs->len == -1 && errno == EINTR);
+ if (vs->len == -1) {
+ err = -errno;
+ }
v9fs_read_post_readv(s, vs, err);
return;
}
vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", vs->total);
vs->offset += vs->count;
err = vs->offset;
+
+out:
complete_pdu(s, vs->pdu, err);
qemu_free(vs);
}
static void v9fs_read_post_lseek(V9fsState *s, V9fsReadState *vs, ssize_t err)
{
- BUG_ON(err == -1);
+ if (err == -1) {
+ err = -errno;
+ goto out;
+ }
vs->sg = cap_sg(vs->sg, vs->count, &vs->cnt);
if (vs->total < vs->count) {
@@ -1288,9 +1333,15 @@ static void v9fs_read_post_lseek(V9fsState *s, V9fsReadState *vs, ssize_t err)
}
vs->len = posix_readv(s, vs->fidp->fd, vs->sg, vs->cnt);
} while (vs->len == -1 && errno == EINTR);
+ if (vs->len == -1) {
+ err = -errno;
+ }
v9fs_read_post_readv(s, vs, err);
return;
}
+out:
+ complete_pdu(s, vs->pdu, err);
+ qemu_free(vs);
}
static void v9fs_read(V9fsState *s, V9fsPDU *pdu)
@@ -1370,7 +1421,11 @@ typedef struct V9fsWriteState {
static void v9fs_write_post_writev(V9fsState *s, V9fsWriteState *vs,
ssize_t err)
{
- BUG_ON(vs->len < 0);
+ if (err < 0) {
+ /* IO error return the error */
+ err = -errno;
+ goto out;
+ }
vs->total += vs->len;
vs->sg = adjust_sg(vs->sg, vs->len, &vs->cnt);
if (vs->total < vs->count && vs->len > 0) {
@@ -1379,19 +1434,26 @@ static void v9fs_write_post_writev(V9fsState *s, V9fsWriteState *vs,
print_sg(vs->sg, vs->cnt);
vs->len = posix_writev(s, vs->fidp->fd, vs->sg, vs->cnt);
} while (vs->len == -1 && errno == EINTR);
+ if (vs->len == -1) {
+ err = -errno;
+ }
v9fs_write_post_writev(s, vs, err);
+ return;
}
vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", vs->total);
err = vs->offset;
+out:
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);
-
+ if (err == -1) {
+ err = -errno;
+ goto out;
+ }
vs->sg = cap_sg(vs->sg, vs->count, &vs->cnt);
if (vs->total < vs->count) {
@@ -1400,11 +1462,14 @@ static void v9fs_write_post_lseek(V9fsState *s, V9fsWriteState *vs, ssize_t err)
print_sg(vs->sg, vs->cnt);
vs->len = posix_writev(s, vs->fidp->fd, vs->sg, vs->cnt);
} while (vs->len == -1 && errno == EINTR);
-
+ if (vs->len == -1) {
+ err = -errno;
+ }
v9fs_write_post_writev(s, vs, err);
return;
}
+out:
complete_pdu(s, vs->pdu, err);
qemu_free(vs);
}
@@ -1834,7 +1899,6 @@ static void v9fs_wstat_post_chown(V9fsState *s, V9fsWstatState *vs, int err)
end = old_name;
new_name = qemu_malloc(end - old_name + vs->v9stat.name.size + 1);
- BUG_ON(new_name == NULL);
memset(new_name, 0, end - old_name + vs->v9stat.name.size + 1);
memcpy(new_name, old_name, end - old_name);
@@ -2104,7 +2168,6 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
s->pdus[i].next = NULL;
s->vq = virtio_add_queue(&s->vdev, MAX_REQ, handle_9p_output);
- BUG_ON(s->vq == NULL);
if (!conf->share_path || !conf->tag) {
/* we haven't specified a mount_tag */
@@ -2127,7 +2190,6 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
s->tag = qemu_malloc(len);
memcpy(s->tag, conf->tag, len);
s->tag_len = len;
- BUG_ON(s->fs_root == NULL);
s->uid = -1;
s->ops = virtio_9p_init_local(conf->share_path);
--
1.7.0.2.323.g0d092
next prev parent reply other threads:[~2010-03-25 16:44 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-25 16:43 [Qemu-devel] [PATCH -V3 00/32] virtio-9p: paravirtual file system passthrough Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 01/32] vitio-9p: Add a virtio 9p device to qemu Aneesh Kumar K.V
2010-03-25 21:04 ` Anthony Liguori
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 02/32] vrtio-9p: Implement P9_TVERSION for 9P Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 03/32] virtio-9p: Implement P9_TATTACH Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 04/32] virtio-9p: Implement P9_TSTAT Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 05/32] virtio-9p: Implement P9_TWALK Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 06/32] virtio-9p: Implement P9_TOPEN Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 07/32] virtio-9p: Implement P9_TREAD Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 08/32] virtio-9p: Implement P9_TCLUNK Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 09/32] virtio-9p: Implement P9_TWRITE Aneesh Kumar K.V
2010-03-29 6:36 ` [Qemu-devel] [PATCH -V3 09/32] virtio-9p: Implement P9_TWRITE/ Thread model in QEMU jvrao
2010-03-29 15:00 ` Anthony Liguori
2010-03-29 20:31 ` Avi Kivity
2010-03-29 20:42 ` Anthony Liguori
2010-03-29 20:54 ` Avi Kivity
2010-03-29 21:23 ` Anthony Liguori
2010-03-30 10:24 ` Avi Kivity
2010-03-30 13:13 ` Anthony Liguori
2010-03-30 13:28 ` Avi Kivity
2010-03-30 13:54 ` Anthony Liguori
2010-03-30 14:03 ` Avi Kivity
2010-03-30 14:07 ` Anthony Liguori
2010-03-30 14:23 ` Avi Kivity
2010-03-30 14:59 ` Anthony Liguori
2010-03-29 21:17 ` jvrao
2010-03-30 10:28 ` Avi Kivity
2010-04-01 13:14 ` Paul Brook
2010-04-01 14:34 ` Avi Kivity
2010-04-01 15:30 ` Paul Brook
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 10/32] virtio-9p: Implement P9_TCREATE Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 11/32] virtio-9p: Implement P9_TWSTAT Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 12/32] virtio-9p: Implement P9_TREMOVE Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 13/32] virtio-9p: Implement P9_TFLUSH Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 14/32] virtio-9p: Add multiple mount point support Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 15/32] virtio-9p: Use little endian format on virtio Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 16/32] virtio-9p: Add support for hardlink Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 17/32] Implement sync support in 9p server Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 18/32] virtio-9p: Fix sg usage in the code Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 19/32] virtio-9p: Get the correct count values from the pdu Aneesh Kumar K.V
2010-03-25 16:43 ` Aneesh Kumar K.V [this message]
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 21/32] virtio-9p: Remove unnecessary definition of fid Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 22/32] virtio-9p: Update existing fid path on rename Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 23/32] vritio-9p: Fix chmod bug with directory Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 24/32] qemu-malloc: Add qemu_asprintf Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 25/32] virtio-9p: Move V9fs File system specific options to a separate header file Aneesh Kumar K.V
2010-03-29 0:52 ` jvrao
2010-03-29 1:09 ` jvrao
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 26/32] virtio-9p: Create a commandline option -fsdev Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 27/32] virtio-9p: Create qemu_fsdev_opts Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 28/32] virtio-9p: Handle the fsdev command line options Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 29/32] virtio-9p: Decouple share_path details from virtio-9p-dev Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 30/32] virtio-9p: Create a syntactic shortcut for the file-system pass-thru Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 31/32] virtio-9p: Return proper errors from create paths Aneesh Kumar K.V
2010-03-25 16:43 ` [Qemu-devel] [PATCH -V3 32/32] virtio-9p: Handle unknown 9P protocol versions as per the standards Aneesh Kumar K.V
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1269535420-31206-21-git-send-email-aneesh.kumar@linux.vnet.ibm.com \
--to=aneesh.kumar@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=ericvh@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).