Patchwork [V2,05/25,virtio-9p] Move errno into v9fs_do_readlink

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

Comments

jvrao - May 17, 2011, 7:43 p.m.
Signed-off-by: Venkateswararao Jujjuri "<jvrao@linux.vnet.ibm.com>
---
 hw/9pfs/virtio-9p.c |   32 ++++++++++++++++----------------
 1 files changed, 16 insertions(+), 16 deletions(-)
Stefan Hajnoczi - May 18, 2011, 9:31 a.m.
On Tue, May 17, 2011 at 8:43 PM, Venkateswararao Jujjuri (JV)
<jvrao@linux.vnet.ibm.com> wrote:
> Signed-off-by: Venkateswararao Jujjuri "<jvrao@linux.vnet.ibm.com>
> ---
>  hw/9pfs/virtio-9p.c |   32 ++++++++++++++++----------------
>  1 files changed, 16 insertions(+), 16 deletions(-)

Please see my comment from v1:
"The len argument is redundant and not used by any callers, please just
return -errno and drop the len argument.  Callers rely on buf->size
instead."

Stefan
jvrao - May 18, 2011, 6:28 p.m.
On 05/18/2011 02:31 AM, Stefan Hajnoczi wrote:
> On Tue, May 17, 2011 at 8:43 PM, Venkateswararao Jujjuri (JV)
> <jvrao@linux.vnet.ibm.com>  wrote:
>> Signed-off-by: Venkateswararao Jujjuri "<jvrao@linux.vnet.ibm.com>
>> ---
>>   hw/9pfs/virtio-9p.c |   32 ++++++++++++++++----------------
>>   1 files changed, 16 insertions(+), 16 deletions(-)
> Please see my comment from v1:
> "The len argument is redundant and not used by any callers, please just
> return -errno and drop the len argument.  Callers rely on buf->size
> instead."
We took care of this while introducing coroutines in patch 6.
06/25 will modify functions for the new int v9fs_co_readlink(V9fsState 
*s, V9fsString *path, V9fsString *buf)

Thanks,
JV
> Stefan
>

Patch

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index e0e7eed..cc22a1f 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -82,19 +82,21 @@  static int v9fs_do_lstat(V9fsState *s, V9fsString *path, struct stat *stbuf)
     return s->ops->lstat(&s->ctx, path->data, stbuf);
 }
 
-static ssize_t v9fs_do_readlink(V9fsState *s, V9fsString *path, V9fsString *buf)
+static int v9fs_do_readlink(V9fsState *s, V9fsString *path, V9fsString *buf,
+        ssize_t *len)
 {
-    ssize_t len;
-
+    int err;
     buf->data = qemu_malloc(1024);
 
-    len = s->ops->readlink(&s->ctx, path->data, buf->data, 1024 - 1);
-    if (len > -1) {
-        buf->size = len;
-        buf->data[len] = 0;
+    *len = s->ops->readlink(&s->ctx, path->data, buf->data, 1024 - 1);
+    if (*len > -1) {
+        buf->size = *len;
+        buf->data[*len] = 0;
+        err = 0;
+    } else {
+        err = -errno;
     }
-
-    return len;
+    return err;
 }
 
 static int v9fs_do_close(V9fsState *s, int fd)
@@ -1055,13 +1057,11 @@  static int stat_to_v9stat(V9fsState *s, V9fsString *name,
     v9fs_string_null(&v9stat->extension);
 
     if (v9stat->mode & P9_STAT_MODE_SYMLINK) {
-        err = v9fs_do_readlink(s, name, &v9stat->extension);
-        if (err == -1) {
-            err = -errno;
+        ssize_t symlink_len;
+        err = v9fs_do_readlink(s, name, &v9stat->extension, &symlink_len);
+        if (err < 0) {
             return err;
         }
-        v9stat->extension.data[err] = 0;
-        v9stat->extension.size = err;
     } else if (v9stat->mode & P9_STAT_MODE_DEVICE) {
         v9fs_string_sprintf(&v9stat->extension, "%c %u %u",
                 S_ISCHR(stbuf->st_mode) ? 'c' : 'b',
@@ -3591,6 +3591,7 @@  static void v9fs_readlink(void *opaque)
     int32_t fid;
     int err = 0;
     V9fsFidState *fidp;
+    ssize_t symlink_len;
 
     pdu_unmarshal(pdu, offset, "d", &fid);
     fidp = lookup_fid(pdu->s, fid);
@@ -3600,9 +3601,8 @@  static void v9fs_readlink(void *opaque)
     }
 
     v9fs_string_init(&target);
-    err = v9fs_do_readlink(pdu->s, &fidp->path, &target);
+    err = v9fs_do_readlink(pdu->s, &fidp->path, &target, &symlink_len);
     if (err < 0) {
-        err = -errno;
         goto out;
     }
     offset += pdu_marshal(pdu, offset, "s", &target);