diff mbox

[v3,2/3] 9pfs: use V9fsBlob to transmit xattr

Message ID 1452504577-26751-3-git-send-email-wei.liu2@citrix.com
State New
Headers show

Commit Message

Wei Liu Jan. 11, 2016, 9:29 a.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>
---
v3: fix bug discovered by Aneesh
---
 fsdev/9p-iov-marshal.c |  4 ++--
 fsdev/9p-iov-marshal.h |  3 ---
 hw/9pfs/9p.c           | 21 +++++++++++++--------
 3 files changed, 15 insertions(+), 13 deletions(-)

Comments

Aneesh Kumar K.V Jan. 11, 2016, 1:56 p.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>
> ---
> v3: fix bug discovered by Aneesh
> ---
>  fsdev/9p-iov-marshal.c |  4 ++--
>  fsdev/9p-iov-marshal.h |  3 ---
>  hw/9pfs/9p.c           | 21 +++++++++++++--------
>  3 files changed, 15 insertions(+), 13 deletions(-)
>
> diff --git a/fsdev/9p-iov-marshal.c b/fsdev/9p-iov-marshal.c
> index 1f9edf3..5c911c8 100644
> --- a/fsdev/9p-iov-marshal.c
> +++ b/fsdev/9p-iov-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/9p-iov-marshal.h b/fsdev/9p-iov-marshal.h
> index 6bccbfb..410a1ea 100644
> --- a/fsdev/9p-iov-marshal.h
> +++ b/fsdev/9p-iov-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_iov_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
>                             int bswap, const char *fmt, ...);
>  ssize_t v9fs_iov_marshal(struct iovec *in_sg, int in_num, size_t offset,
> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> index a904403..84cb1d9 100644
> --- a/hw/9pfs/9p.c
> +++ b/hw/9pfs/9p.c
> @@ -1585,6 +1585,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;
> @@ -1596,14 +1597,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);

Can we do this without the malloc and memcpy ? . I am sure you need this
for Xen abstraction. But for now i am inclined to drop this from the
series and add this later with Xen transport.  v9fs_xattr_read is
essentially T_READ on a xattr fid and we don't use blob ("B") in other
code path. We also want to avoid that extra malloc and memcpy.



> +    blob.size = read_count;
> +
> +    err = pdu_marshal(pdu, offset, "B", &blob);
> +
> +    v9fs_blob_free(&blob);
> +
>      if (err < 0) {
>          return err;
>      }
> -- 
> 2.1.4

-aneesh
Wei Liu Jan. 11, 2016, 2:05 p.m. UTC | #2
On Mon, Jan 11, 2016 at 07:26:39PM +0530, Aneesh Kumar K.V wrote:
[...]
> >      xattr_len = fidp->fs.xattr.len;
> >      read_count = xattr_len - off;
> > @@ -1596,14 +1597,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);
> 
> Can we do this without the malloc and memcpy ? . I am sure you need this
> for Xen abstraction. But for now i am inclined to drop this from the
> series and add this later with Xen transport.  v9fs_xattr_read is
> essentially T_READ on a xattr fid and we don't use blob ("B") in other
> code path. We also want to avoid that extra malloc and memcpy.
> 

That's fine.

Do you want me to resend the whole series or just this one patch
(assuming you don't have other comments on my other patches)?


Wei.
diff mbox

Patch

diff --git a/fsdev/9p-iov-marshal.c b/fsdev/9p-iov-marshal.c
index 1f9edf3..5c911c8 100644
--- a/fsdev/9p-iov-marshal.c
+++ b/fsdev/9p-iov-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/9p-iov-marshal.h b/fsdev/9p-iov-marshal.h
index 6bccbfb..410a1ea 100644
--- a/fsdev/9p-iov-marshal.h
+++ b/fsdev/9p-iov-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_iov_unmarshal(struct iovec *out_sg, int out_num, size_t offset,
                            int bswap, const char *fmt, ...);
 ssize_t v9fs_iov_marshal(struct iovec *in_sg, int in_num, size_t offset,
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index a904403..84cb1d9 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -1585,6 +1585,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;
@@ -1596,14 +1597,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, "B", &blob);
+
+    v9fs_blob_free(&blob);
+
     if (err < 0) {
         return err;
     }