Patchwork [V2,03/25,virtio-9p] Remove post functions for v9fs_readlink.

login
register
mail settings
Submitter jvrao
Date May 17, 2011, 7:43 p.m.
Message ID <1305661431-21289-4-git-send-email-jvrao@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/96011/
State New
Headers show

Comments

jvrao - May 17, 2011, 7:43 p.m.
In the process of preparation for coroutine threads, remove all post functions
and make the function more readable.

Signed-off-by: Venkateswararao Jujjuri "<jvrao@linux.vnet.ibm.com>
---
 hw/9pfs/virtio-9p.c |   25 +++++++------------------
 1 files changed, 7 insertions(+), 18 deletions(-)
Stefan Hajnoczi - May 18, 2011, 9:27 a.m.
On Tue, May 17, 2011 at 8:43 PM, Venkateswararao Jujjuri (JV)
<jvrao@linux.vnet.ibm.com> wrote:
> @@ -3621,8 +3605,13 @@ static void v9fs_readlink(void *opaque)
>
>     v9fs_string_init(&vs->target);
>     err = v9fs_do_readlink(s, &fidp->path, &vs->target);
> -    v9fs_readlink_post_readlink(s, vs, err);
> -    return;
> +    if (err < 0) {
> +        err = -errno;
> +        goto out;
> +    }
> +    vs->offset += pdu_marshal(vs->pdu, vs->offset, "s", &vs->target);
> +    err = vs->offset;
> +    v9fs_string_free(&vs->target);
>  out:

The vs->target string should be freed when v9fs_do_readlink() fails.
v9fs_do_readlink() *always* allocates vs->target.data, it doesn't free
it on error.

Stefan

Patch

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 15bfea7..06da2c9 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3583,21 +3583,6 @@  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(void *opaque)
 {
     V9fsPDU *pdu = opaque;
@@ -3612,7 +3597,6 @@  static void v9fs_readlink(void *opaque)
     vs->offset = 7;
 
     pdu_unmarshal(vs->pdu, vs->offset, "d", &fid);
-
     fidp = lookup_fid(s, fid);
     if (fidp == NULL) {
         err = -ENOENT;
@@ -3621,8 +3605,13 @@  static void v9fs_readlink(void *opaque)
 
     v9fs_string_init(&vs->target);
     err = v9fs_do_readlink(s, &fidp->path, &vs->target);
-    v9fs_readlink_post_readlink(s, vs, err);
-    return;
+    if (err < 0) {
+        err = -errno;
+        goto out;
+    }
+    vs->offset += pdu_marshal(vs->pdu, vs->offset, "s", &vs->target);
+    err = vs->offset;
+    v9fs_string_free(&vs->target);
 out:
     complete_pdu(s, vs->pdu, err);
     qemu_free(vs);