diff mbox

[v2,12/27] 9pfs: use V9fsBlob to transmit xattr

Message ID 1452196584-17259-13-git-send-email-wei.liu2@citrix.com
State New
Headers show

Commit Message

Wei Liu Jan. 7, 2016, 7:56 p.m. UTC
And make v9fs_pack static function. Now we only need to export
v9fs_{,un}marshal to device.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 fsdev/virtio-9p-marshal.c |  4 ++--
 fsdev/virtio-9p-marshal.h |  3 ---
 hw/9pfs/virtio-9p.c       | 21 +++++++++++++--------
 3 files changed, 15 insertions(+), 13 deletions(-)

Comments

Aneesh Kumar K.V Jan. 8, 2016, 8:30 a.m. UTC | #1
Wei Liu <wei.liu2@citrix.com> writes:

> And make v9fs_pack static function. Now we only need to export
> v9fs_{,un}marshal to device.
>
> Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> ---
>  fsdev/virtio-9p-marshal.c |  4 ++--
>  fsdev/virtio-9p-marshal.h |  3 ---
>  hw/9pfs/virtio-9p.c       | 21 +++++++++++++--------
>  3 files changed, 15 insertions(+), 13 deletions(-)
>
> diff --git a/fsdev/virtio-9p-marshal.c b/fsdev/virtio-9p-marshal.c
> index c3ac316..d120bd2 100644
> --- a/fsdev/virtio-9p-marshal.c
> +++ b/fsdev/virtio-9p-marshal.c
> @@ -70,8 +70,8 @@ static ssize_t v9fs_unpack(void *dst, struct iovec *out_sg, int out_num,
>      return v9fs_packunpack(dst, out_sg, out_num, offset, size, 0);
>  }
>
> -ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
> -                  const void *src, size_t size)
> +static ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
> +                         const void *src, size_t size)
>  {
>      return v9fs_packunpack((void *)src, in_sg, in_num, offset, size, 1);
>  }
> diff --git a/fsdev/virtio-9p-marshal.h b/fsdev/virtio-9p-marshal.h
> index 0709bcd..766a48e 100644
> --- a/fsdev/virtio-9p-marshal.h
> +++ b/fsdev/virtio-9p-marshal.h
> @@ -3,9 +3,6 @@
>
>  #include "9p-marshal.h"
>
> -
> -ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
> -                  const void *src, size_t size);
>  ssize_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
>                         int bswap, const char *fmt, ...);
>  ssize_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset,
> diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
> index 30ff828..654c103 100644
> --- a/hw/9pfs/virtio-9p.c
> +++ b/hw/9pfs/virtio-9p.c
> @@ -1561,6 +1561,7 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
>      size_t offset = 7;
>      int read_count;
>      int64_t xattr_len;
> +    V9fsBlob blob;
>
>      xattr_len = fidp->fs.xattr.len;
>      read_count = xattr_len - off;
> @@ -1572,14 +1573,18 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
>           */
>          read_count = 0;
>      }
> -    err = pdu_marshal(pdu, offset, "d", read_count);
> -    if (err < 0) {
> -        return err;
> -    }
> -    offset += err;
> -    err = v9fs_pack(pdu->elem.in_sg, pdu->elem.in_num, offset,
> -                    ((char *)fidp->fs.xattr.value) + off,
> -                    read_count);
> +
> +    v9fs_blob_init(&blob);
> +
> +    blob.data = g_malloc(read_count);
> +    memcpy(blob.data, ((char *)fidp->fs.xattr.value) + off,
> +           read_count);
> +    blob.size = read_count;
> +
> +    err = pdu_marshal(pdu, offset, "dB", read_count, &blob);

Is this correct ?

earlier we had read_count <data>
now we have
read_count, <blob> which is read_count, blob->size, data


-aneesh
Wei Liu Jan. 8, 2016, 5:56 p.m. UTC | #2
On Fri, Jan 08, 2016 at 02:00:31PM +0530, Aneesh Kumar K.V wrote:
> Wei Liu <wei.liu2@citrix.com> writes:
> 
> > And make v9fs_pack static function. Now we only need to export
> > v9fs_{,un}marshal to device.
> >
> > Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> > ---
> >  fsdev/virtio-9p-marshal.c |  4 ++--
> >  fsdev/virtio-9p-marshal.h |  3 ---
> >  hw/9pfs/virtio-9p.c       | 21 +++++++++++++--------
> >  3 files changed, 15 insertions(+), 13 deletions(-)
> >
> > diff --git a/fsdev/virtio-9p-marshal.c b/fsdev/virtio-9p-marshal.c
> > index c3ac316..d120bd2 100644
> > --- a/fsdev/virtio-9p-marshal.c
> > +++ b/fsdev/virtio-9p-marshal.c
> > @@ -70,8 +70,8 @@ static ssize_t v9fs_unpack(void *dst, struct iovec *out_sg, int out_num,
> >      return v9fs_packunpack(dst, out_sg, out_num, offset, size, 0);
> >  }
> >
> > -ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
> > -                  const void *src, size_t size)
> > +static ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
> > +                         const void *src, size_t size)
> >  {
> >      return v9fs_packunpack((void *)src, in_sg, in_num, offset, size, 1);
> >  }
> > diff --git a/fsdev/virtio-9p-marshal.h b/fsdev/virtio-9p-marshal.h
> > index 0709bcd..766a48e 100644
> > --- a/fsdev/virtio-9p-marshal.h
> > +++ b/fsdev/virtio-9p-marshal.h
> > @@ -3,9 +3,6 @@
> >
> >  #include "9p-marshal.h"
> >
> > -
> > -ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
> > -                  const void *src, size_t size);
> >  ssize_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
> >                         int bswap, const char *fmt, ...);
> >  ssize_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset,
> > diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
> > index 30ff828..654c103 100644
> > --- a/hw/9pfs/virtio-9p.c
> > +++ b/hw/9pfs/virtio-9p.c
> > @@ -1561,6 +1561,7 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
> >      size_t offset = 7;
> >      int read_count;
> >      int64_t xattr_len;
> > +    V9fsBlob blob;
> >
> >      xattr_len = fidp->fs.xattr.len;
> >      read_count = xattr_len - off;
> > @@ -1572,14 +1573,18 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
> >           */
> >          read_count = 0;
> >      }
> > -    err = pdu_marshal(pdu, offset, "d", read_count);
> > -    if (err < 0) {
> > -        return err;
> > -    }
> > -    offset += err;
> > -    err = v9fs_pack(pdu->elem.in_sg, pdu->elem.in_num, offset,
> > -                    ((char *)fidp->fs.xattr.value) + off,
> > -                    read_count);
> > +
> > +    v9fs_blob_init(&blob);
> > +
> > +    blob.data = g_malloc(read_count);
> > +    memcpy(blob.data, ((char *)fidp->fs.xattr.value) + off,
> > +           read_count);
> > +    blob.size = read_count;
> > +
> > +    err = pdu_marshal(pdu, offset, "dB", read_count, &blob);
> 
> Is this correct ?
> 
> earlier we had read_count <data>
> now we have
> read_count, <blob> which is read_count, blob->size, data
> 

Yes, you're right. There is an error.

The new code should be

    err = pdu_marshal(pdu, offset, "B", &blob);

Thanks for your careful review.

Wei.

> 
> -aneesh
>
Aneesh Kumar K.V Jan. 8, 2016, 6:48 p.m. UTC | #3
Wei Liu <wei.liu2@citrix.com> writes:

> On Fri, Jan 08, 2016 at 02:00:31PM +0530, Aneesh Kumar K.V wrote:
>> Wei Liu <wei.liu2@citrix.com> writes:
>> 
>> > And make v9fs_pack static function. Now we only need to export
>> > v9fs_{,un}marshal to device.
>> >
>> > Signed-off-by: Wei Liu <wei.liu2@citrix.com>
>> > ---
>> >  fsdev/virtio-9p-marshal.c |  4 ++--
>> >  fsdev/virtio-9p-marshal.h |  3 ---
>> >  hw/9pfs/virtio-9p.c       | 21 +++++++++++++--------
>> >  3 files changed, 15 insertions(+), 13 deletions(-)
>> >
>> > diff --git a/fsdev/virtio-9p-marshal.c b/fsdev/virtio-9p-marshal.c
>> > index c3ac316..d120bd2 100644
>> > --- a/fsdev/virtio-9p-marshal.c
>> > +++ b/fsdev/virtio-9p-marshal.c
>> > @@ -70,8 +70,8 @@ static ssize_t v9fs_unpack(void *dst, struct iovec *out_sg, int out_num,
>> >      return v9fs_packunpack(dst, out_sg, out_num, offset, size, 0);
>> >  }
>> >
>> > -ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
>> > -                  const void *src, size_t size)
>> > +static ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
>> > +                         const void *src, size_t size)
>> >  {
>> >      return v9fs_packunpack((void *)src, in_sg, in_num, offset, size, 1);
>> >  }
>> > diff --git a/fsdev/virtio-9p-marshal.h b/fsdev/virtio-9p-marshal.h
>> > index 0709bcd..766a48e 100644
>> > --- a/fsdev/virtio-9p-marshal.h
>> > +++ b/fsdev/virtio-9p-marshal.h
>> > @@ -3,9 +3,6 @@
>> >
>> >  #include "9p-marshal.h"
>> >
>> > -
>> > -ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
>> > -                  const void *src, size_t size);
>> >  ssize_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
>> >                         int bswap, const char *fmt, ...);
>> >  ssize_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset,
>> > diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
>> > index 30ff828..654c103 100644
>> > --- a/hw/9pfs/virtio-9p.c
>> > +++ b/hw/9pfs/virtio-9p.c
>> > @@ -1561,6 +1561,7 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
>> >      size_t offset = 7;
>> >      int read_count;
>> >      int64_t xattr_len;
>> > +    V9fsBlob blob;
>> >
>> >      xattr_len = fidp->fs.xattr.len;
>> >      read_count = xattr_len - off;
>> > @@ -1572,14 +1573,18 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
>> >           */
>> >          read_count = 0;
>> >      }
>> > -    err = pdu_marshal(pdu, offset, "d", read_count);
>> > -    if (err < 0) {
>> > -        return err;
>> > -    }
>> > -    offset += err;
>> > -    err = v9fs_pack(pdu->elem.in_sg, pdu->elem.in_num, offset,
>> > -                    ((char *)fidp->fs.xattr.value) + off,
>> > -                    read_count);
>> > +
>> > +    v9fs_blob_init(&blob);
>> > +
>> > +    blob.data = g_malloc(read_count);
>> > +    memcpy(blob.data, ((char *)fidp->fs.xattr.value) + off,
>> > +           read_count);
>> > +    blob.size = read_count;
>> > +
>> > +    err = pdu_marshal(pdu, offset, "dB", read_count, &blob);
>> 
>> Is this correct ?
>> 
>> earlier we had read_count <data>
>> now we have
>> read_count, <blob> which is read_count, blob->size, data
>> 
>
> Yes, you're right. There is an error.
>
> The new code should be
>
>     err = pdu_marshal(pdu, offset, "B", &blob);
>
> Thanks for your careful review.
>

We would then need 'B' to encode size as int ie, 'd' instead of 'w'

-aneesh
Wei Liu Jan. 8, 2016, 6:54 p.m. UTC | #4
On Sat, Jan 09, 2016 at 12:18:40AM +0530, Aneesh Kumar K.V wrote:
> Wei Liu <wei.liu2@citrix.com> writes:
> 
> > On Fri, Jan 08, 2016 at 02:00:31PM +0530, Aneesh Kumar K.V wrote:
> >> Wei Liu <wei.liu2@citrix.com> writes:
> >> 
> >> > And make v9fs_pack static function. Now we only need to export
> >> > v9fs_{,un}marshal to device.
> >> >
> >> > Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> >> > ---
> >> >  fsdev/virtio-9p-marshal.c |  4 ++--
> >> >  fsdev/virtio-9p-marshal.h |  3 ---
> >> >  hw/9pfs/virtio-9p.c       | 21 +++++++++++++--------
> >> >  3 files changed, 15 insertions(+), 13 deletions(-)
> >> >
> >> > diff --git a/fsdev/virtio-9p-marshal.c b/fsdev/virtio-9p-marshal.c
> >> > index c3ac316..d120bd2 100644
> >> > --- a/fsdev/virtio-9p-marshal.c
> >> > +++ b/fsdev/virtio-9p-marshal.c
> >> > @@ -70,8 +70,8 @@ static ssize_t v9fs_unpack(void *dst, struct iovec *out_sg, int out_num,
> >> >      return v9fs_packunpack(dst, out_sg, out_num, offset, size, 0);
> >> >  }
> >> >
> >> > -ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
> >> > -                  const void *src, size_t size)
> >> > +static ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
> >> > +                         const void *src, size_t size)
> >> >  {
> >> >      return v9fs_packunpack((void *)src, in_sg, in_num, offset, size, 1);
> >> >  }
> >> > diff --git a/fsdev/virtio-9p-marshal.h b/fsdev/virtio-9p-marshal.h
> >> > index 0709bcd..766a48e 100644
> >> > --- a/fsdev/virtio-9p-marshal.h
> >> > +++ b/fsdev/virtio-9p-marshal.h
> >> > @@ -3,9 +3,6 @@
> >> >
> >> >  #include "9p-marshal.h"
> >> >
> >> > -
> >> > -ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
> >> > -                  const void *src, size_t size);
> >> >  ssize_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
> >> >                         int bswap, const char *fmt, ...);
> >> >  ssize_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset,
> >> > diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
> >> > index 30ff828..654c103 100644
> >> > --- a/hw/9pfs/virtio-9p.c
> >> > +++ b/hw/9pfs/virtio-9p.c
> >> > @@ -1561,6 +1561,7 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
> >> >      size_t offset = 7;
> >> >      int read_count;
> >> >      int64_t xattr_len;
> >> > +    V9fsBlob blob;
> >> >
> >> >      xattr_len = fidp->fs.xattr.len;
> >> >      read_count = xattr_len - off;
> >> > @@ -1572,14 +1573,18 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
> >> >           */
> >> >          read_count = 0;
> >> >      }
> >> > -    err = pdu_marshal(pdu, offset, "d", read_count);
> >> > -    if (err < 0) {
> >> > -        return err;
> >> > -    }
> >> > -    offset += err;
> >> > -    err = v9fs_pack(pdu->elem.in_sg, pdu->elem.in_num, offset,
> >> > -                    ((char *)fidp->fs.xattr.value) + off,
> >> > -                    read_count);
> >> > +
> >> > +    v9fs_blob_init(&blob);
> >> > +
> >> > +    blob.data = g_malloc(read_count);
> >> > +    memcpy(blob.data, ((char *)fidp->fs.xattr.value) + off,
> >> > +           read_count);
> >> > +    blob.size = read_count;
> >> > +
> >> > +    err = pdu_marshal(pdu, offset, "dB", read_count, &blob);
> >> 
> >> Is this correct ?
> >> 
> >> earlier we had read_count <data>
> >> now we have
> >> read_count, <blob> which is read_count, blob->size, data
> >> 
> >
> > Yes, you're right. There is an error.
> >
> > The new code should be
> >
> >     err = pdu_marshal(pdu, offset, "B", &blob);
> >
> > Thanks for your careful review.
> >
> 
> We would then need 'B' to encode size as int ie, 'd' instead of 'w'
> 

Ack. I will make the change.

Wei.

> -aneesh
> 
>
diff mbox

Patch

diff --git a/fsdev/virtio-9p-marshal.c b/fsdev/virtio-9p-marshal.c
index c3ac316..d120bd2 100644
--- a/fsdev/virtio-9p-marshal.c
+++ b/fsdev/virtio-9p-marshal.c
@@ -70,8 +70,8 @@  static ssize_t v9fs_unpack(void *dst, struct iovec *out_sg, int out_num,
     return v9fs_packunpack(dst, out_sg, out_num, offset, size, 0);
 }
 
-ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
-                  const void *src, size_t size)
+static ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
+                         const void *src, size_t size)
 {
     return v9fs_packunpack((void *)src, in_sg, in_num, offset, size, 1);
 }
diff --git a/fsdev/virtio-9p-marshal.h b/fsdev/virtio-9p-marshal.h
index 0709bcd..766a48e 100644
--- a/fsdev/virtio-9p-marshal.h
+++ b/fsdev/virtio-9p-marshal.h
@@ -3,9 +3,6 @@ 
 
 #include "9p-marshal.h"
 
-
-ssize_t v9fs_pack(struct iovec *in_sg, int in_num, size_t offset,
-                  const void *src, size_t size);
 ssize_t v9fs_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
                        int bswap, const char *fmt, ...);
 ssize_t v9fs_marshal(struct iovec *in_sg, int in_num, size_t offset,
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 30ff828..654c103 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -1561,6 +1561,7 @@  static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
     size_t offset = 7;
     int read_count;
     int64_t xattr_len;
+    V9fsBlob blob;
 
     xattr_len = fidp->fs.xattr.len;
     read_count = xattr_len - off;
@@ -1572,14 +1573,18 @@  static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
          */
         read_count = 0;
     }
-    err = pdu_marshal(pdu, offset, "d", read_count);
-    if (err < 0) {
-        return err;
-    }
-    offset += err;
-    err = v9fs_pack(pdu->elem.in_sg, pdu->elem.in_num, offset,
-                    ((char *)fidp->fs.xattr.value) + off,
-                    read_count);
+
+    v9fs_blob_init(&blob);
+
+    blob.data = g_malloc(read_count);
+    memcpy(blob.data, ((char *)fidp->fs.xattr.value) + off,
+           read_count);
+    blob.size = read_count;
+
+    err = pdu_marshal(pdu, offset, "dB", read_count, &blob);
+
+    v9fs_blob_free(&blob);
+
     if (err < 0) {
         return err;
     }