Patchwork Fix bug with virtio-9p xattr functions return values

login
register
mail settings
Submitter Sassan Panahinejad
Date April 28, 2011, 1:48 p.m.
Message ID <1303998537-18128-1-git-send-email-sassan@sassan.me.uk>
Download mbox | patch
Permalink /patch/93219/
State New
Headers show

Comments

Sassan Panahinejad - April 28, 2011, 1:48 p.m.
Several functions in virtio-9p-xattr.c are passing the return value of the associated host system call back to the client instead of errno.
Since this value is -1 for any error (which, when received in the guest app as errno, indicates "operation not permitted") it is causing guest applications to fail in cases where the operation is not supported by the host.
This causes a number of problems with dpkg and with install.
This patch fixes the bug and returns the correct value, which means that guest applications are able to handle the error correctly.

Signed-off-by: Sassan Panahinejad <sassan@sassan.me.uk>
---
 hw/virtio-9p-xattr.c |   21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)

Patch

diff --git a/hw/virtio-9p-xattr.c b/hw/virtio-9p-xattr.c
index 1aab081..fd6d892 100644
--- a/hw/virtio-9p-xattr.c
+++ b/hw/virtio-9p-xattr.c
@@ -32,9 +32,14 @@  static XattrOperations *get_xattr_operations(XattrOperations **h,
 ssize_t v9fs_get_xattr(FsContext *ctx, const char *path,
                        const char *name, void *value, size_t size)
 {
+    int ret;
     XattrOperations *xops = get_xattr_operations(ctx->xops, name);
     if (xops) {
-        return xops->getxattr(ctx, path, name, value, size);
+        ret = xops->getxattr(ctx, path, name, value, size);
+        if (ret < 0) {
+            return -errno;
+        }
+        return ret;
     }
     errno = -EOPNOTSUPP;
     return -1;
@@ -117,9 +122,14 @@  err_out:
 int v9fs_set_xattr(FsContext *ctx, const char *path, const char *name,
                    void *value, size_t size, int flags)
 {
+    int ret;
     XattrOperations *xops = get_xattr_operations(ctx->xops, name);
     if (xops) {
-        return xops->setxattr(ctx, path, name, value, size, flags);
+        ret = xops->setxattr(ctx, path, name, value, size, flags);
+        if (ret < 0) {
+            return -errno;
+        }
+        return ret;
     }
     errno = -EOPNOTSUPP;
     return -1;
@@ -129,9 +139,14 @@  int v9fs_set_xattr(FsContext *ctx, const char *path, const char *name,
 int v9fs_remove_xattr(FsContext *ctx,
                       const char *path, const char *name)
 {
+    int ret;
     XattrOperations *xops = get_xattr_operations(ctx->xops, name);
     if (xops) {
-        return xops->removexattr(ctx, path, name);
+        ret = xops->removexattr(ctx, path, name);
+        if (ret < 0) {
+            return -errno;
+        }
+        return ret;
     }
     errno = -EOPNOTSUPP;
     return -1;