From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:44214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QbXMW-0004JA-B9 for qemu-devel@nongnu.org; Tue, 28 Jun 2011 08:25:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QbXMS-0008Ms-9k for qemu-devel@nongnu.org; Tue, 28 Jun 2011 08:25:52 -0400 Received: from mail-fx0-f47.google.com ([209.85.161.47]:52554) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QbXMR-0008MI-EI for qemu-devel@nongnu.org; Tue, 28 Jun 2011 08:25:48 -0400 Received: by fxg11 with SMTP id 11so194285fxg.34 for ; Tue, 28 Jun 2011 05:25:45 -0700 (PDT) MIME-Version: 1.0 Sender: ico2ico2@gmail.com In-Reply-To: <1307550119-6111-1-git-send-email-sassan@sassan.me.uk> References: <4DD2D1E6.7030300@linux.vnet.ibm.com> <1307550119-6111-1-git-send-email-sassan@sassan.me.uk> Date: Tue, 28 Jun 2011 13:25:45 +0100 Message-ID: From: Sassan Panahinejad Content-Type: multipart/alternative; boundary=002354186e6467355c04a6c4c4bb Subject: Re: [Qemu-devel] [PATCH] Clean up virtio-9p error handling code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: jvrao@linux.vnet.ibm.com Cc: Sassan Panahinejad , qemu-devel@nongnu.org --002354186e6467355c04a6c4c4bb Content-Type: text/plain; charset=ISO-8859-1 Hi JV, Any progress regarding merging this patch (and the fsync patch I submitted)? Is there anything I can do to assist/speed the process? Thanks Sassan On 8 June 2011 17:21, Sassan Panahinejad wrote: > In a lot of cases, the handling of errors was quite ugly. > This patch moves reading of errno to immediately after the system calls and > passes it up through the system more cleanly. > Also, in the case of the xattr functions (and possibly others), completely > the wrong error was being returned. > > > This patch is created against your 9p-coroutine-bh branch, as requested. > Sorry for the delay, I was unexpectedly required to work abroad for 2 weeks. > > Signed-off-by: Sassan Panahinejad > > --- > fsdev/file-op-9p.h | 4 +- > hw/9pfs/codir.c | 14 +---- > hw/9pfs/virtio-9p-local.c | 123 > +++++++++++++++++++++++++-------------------- > hw/9pfs/virtio-9p-xattr.c | 21 +++++++- > 4 files changed, 90 insertions(+), 72 deletions(-) > > diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h > index af9daf7..3d9575b 100644 > --- a/fsdev/file-op-9p.h > +++ b/fsdev/file-op-9p.h > @@ -73,12 +73,12 @@ typedef struct FileOperations > int (*setuid)(FsContext *, uid_t); > int (*close)(FsContext *, int); > int (*closedir)(FsContext *, DIR *); > - DIR *(*opendir)(FsContext *, const char *); > + int (*opendir)(FsContext *, const char *, DIR **); > int (*open)(FsContext *, const char *, int); > int (*open2)(FsContext *, const char *, int, FsCred *); > void (*rewinddir)(FsContext *, DIR *); > off_t (*telldir)(FsContext *, DIR *); > - struct dirent *(*readdir)(FsContext *, DIR *); > + int (*readdir)(FsContext *, DIR *, struct dirent **); > void (*seekdir)(FsContext *, DIR *, off_t); > ssize_t (*preadv)(FsContext *, int, const struct iovec *, int, off_t); > ssize_t (*pwritev)(FsContext *, int, const struct iovec *, int, off_t); > diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c > index 110289f..acbbb39 100644 > --- a/hw/9pfs/codir.c > +++ b/hw/9pfs/codir.c > @@ -25,12 +25,7 @@ int v9fs_co_readdir(V9fsState *s, V9fsFidState *fidp, > struct dirent **dent) > { > errno = 0; > /*FIXME!! need to switch to readdir_r */ > - *dent = s->ops->readdir(&s->ctx, fidp->fs.dir); > - if (!*dent && errno) { > - err = -errno; > - } else { > - err = 0; > - } > + err = s->ops->readdir(&s->ctx, fidp->fs.dir, dent); > }); > return err; > } > @@ -93,12 +88,7 @@ int v9fs_co_opendir(V9fsState *s, V9fsFidState *fidp) > > v9fs_co_run_in_worker( > { > - dir = s->ops->opendir(&s->ctx, fidp->path.data); > - if (!dir) { > - err = -errno; > - } else { > - err = 0; > - } > + err = s->ops->opendir(&s->ctx, fidp->path.data, &dir); > }); > fidp->fs.dir = dir; > return err; > diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9p-local.c > index 77904c3..65f35eb 100644 > --- a/hw/9pfs/virtio-9p-local.c > +++ b/hw/9pfs/virtio-9p-local.c > @@ -28,7 +28,7 @@ static int local_lstat(FsContext *fs_ctx, const char > *path, struct stat *stbuf) > char buffer[PATH_MAX]; > err = lstat(rpath(fs_ctx, path, buffer), stbuf); > if (err) { > - return err; > + return -errno; > } > if (fs_ctx->fs_sm == SM_MAPPED) { > /* Actual credentials are part of extended attrs */ > @@ -53,7 +53,7 @@ static int local_lstat(FsContext *fs_ctx, const char > *path, struct stat *stbuf) > stbuf->st_rdev = tmp_dev; > } > } > - return err; > + return 0; > } > > static int local_set_xattr(const char *path, FsCred *credp) > @@ -63,28 +63,28 @@ static int local_set_xattr(const char *path, FsCred > *credp) > err = setxattr(path, "user.virtfs.uid", &credp->fc_uid, > sizeof(uid_t), > 0); > if (err) { > - return err; > + return -errno; > } > } > if (credp->fc_gid != -1) { > err = setxattr(path, "user.virtfs.gid", &credp->fc_gid, > sizeof(gid_t), > 0); > if (err) { > - return err; > + return -errno; > } > } > if (credp->fc_mode != -1) { > err = setxattr(path, "user.virtfs.mode", &credp->fc_mode, > sizeof(mode_t), 0); > if (err) { > - return err; > + return -errno; > } > } > if (credp->fc_rdev != -1) { > err = setxattr(path, "user.virtfs.rdev", &credp->fc_rdev, > sizeof(dev_t), 0); > if (err) { > - return err; > + return -errno; > } > } > return 0; > @@ -95,7 +95,7 @@ static int local_post_create_passthrough(FsContext > *fs_ctx, const char *path, > { > char buffer[PATH_MAX]; > if (chmod(rpath(fs_ctx, path, buffer), credp->fc_mode & 07777) < 0) { > - return -1; > + return -errno; > } > if (lchown(rpath(fs_ctx, path, buffer), credp->fc_uid, > credp->fc_gid) < 0) { > @@ -104,7 +104,7 @@ static int local_post_create_passthrough(FsContext > *fs_ctx, const char *path, > * using security model none. Ignore the error > */ > if (fs_ctx->fs_sm != SM_NONE) { > - return -1; > + return -errno; > } > } > return 0; > @@ -119,40 +119,42 @@ static ssize_t local_readlink(FsContext *fs_ctx, > const char *path, > int fd; > fd = open(rpath(fs_ctx, path, buffer), O_RDONLY); > if (fd == -1) { > - return -1; > + return -errno; > } > do { > tsize = read(fd, (void *)buf, bufsz); > } while (tsize == -1 && errno == EINTR); > close(fd); > - return tsize; > + return tsize == -1 ? -errno : tsize; > } else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) || > (fs_ctx->fs_sm == SM_NONE)) { > tsize = readlink(rpath(fs_ctx, path, buffer), buf, bufsz); > } > - return tsize; > + return tsize == -1 ? -errno : tsize; > } > > static int local_close(FsContext *ctx, int fd) > { > - return close(fd); > + return close(fd) == -1 ? -errno : 0; > } > > static int local_closedir(FsContext *ctx, DIR *dir) > { > - return closedir(dir); > + return closedir(dir) == -1 ? -errno : 0; > } > > static int local_open(FsContext *ctx, const char *path, int flags) > { > char buffer[PATH_MAX]; > - return open(rpath(ctx, path, buffer), flags); > + int ret = open(rpath(ctx, path, buffer), flags); > + return ret == -1 ? -errno : ret; > } > > -static DIR *local_opendir(FsContext *ctx, const char *path) > +static int local_opendir(FsContext *ctx, const char *path, DIR **dir) > { > char buffer[PATH_MAX]; > - return opendir(rpath(ctx, path, buffer)); > + *dir = opendir(rpath(ctx, path, buffer)); > + return *dir ? 0 : -errno; > } > > static void local_rewinddir(FsContext *ctx, DIR *dir) > @@ -162,12 +164,15 @@ static void local_rewinddir(FsContext *ctx, DIR *dir) > > static off_t local_telldir(FsContext *ctx, DIR *dir) > { > - return telldir(dir); > + int ret = telldir(dir); > + return ret == -1 ? -errno : ret; > } > > -static struct dirent *local_readdir(FsContext *ctx, DIR *dir) > +static int local_readdir(FsContext *ctx, DIR *dir, struct dirent **dirent) > { > - return readdir(dir); > + *dirent = readdir(dir); > + return *dirent ? 0 : -errno; > + > } > > static void local_seekdir(FsContext *ctx, DIR *dir, off_t off) > @@ -178,14 +183,17 @@ static void local_seekdir(FsContext *ctx, DIR *dir, > off_t off) > static ssize_t local_preadv(FsContext *ctx, int fd, const struct iovec > *iov, > int iovcnt, off_t offset) > { > + int err; > #ifdef CONFIG_PREADV > - return preadv(fd, iov, iovcnt, offset); > + err = preadv(fd, iov, iovcnt, offset); > + return err == -1 ? -errno : err; > #else > int err = lseek(fd, offset, SEEK_SET); > if (err == -1) { > - return err; > + return -errno; > } else { > - return readv(fd, iov, iovcnt); > + err = readv(fd, iov, iovcnt); > + return err == -1 ? -errno : err; > } > #endif > } > @@ -193,14 +201,17 @@ static ssize_t local_preadv(FsContext *ctx, int fd, > const struct iovec *iov, > static ssize_t local_pwritev(FsContext *ctx, int fd, const struct iovec > *iov, > int iovcnt, off_t offset) > { > + int err; > #ifdef CONFIG_PREADV > - return pwritev(fd, iov, iovcnt, offset); > + err = pwritev(fd, iov, iovcnt, offset); > + return err == -1 ? -errno : err; > #else > int err = lseek(fd, offset, SEEK_SET); > if (err == -1) { > - return err; > + return -errno; > } else { > - return writev(fd, iov, iovcnt); > + err = writev(fd, iov, iovcnt); > + return err == -1 ? -errno : err; > } > #endif > } > @@ -208,13 +219,16 @@ static ssize_t local_pwritev(FsContext *ctx, int fd, > const struct iovec *iov, > static int local_chmod(FsContext *fs_ctx, const char *path, FsCred *credp) > { > char buffer[PATH_MAX]; > + int ret; > + > if (fs_ctx->fs_sm == SM_MAPPED) { > return local_set_xattr(rpath(fs_ctx, path, buffer), credp); > } else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) || > (fs_ctx->fs_sm == SM_NONE)) { > - return chmod(rpath(fs_ctx, path, buffer), credp->fc_mode); > + ret = chmod(rpath(fs_ctx, path, buffer), credp->fc_mode); > + return ret == -1 ? -errno : ret; > } > - return -1; > + return -ENOTSUP; > } > > static int local_mknod(FsContext *fs_ctx, const char *path, FsCred *credp) > @@ -228,7 +242,7 @@ static int local_mknod(FsContext *fs_ctx, const char > *path, FsCred *credp) > err = mknod(rpath(fs_ctx, path, buffer), > SM_LOCAL_MODE_BITS|S_IFREG, 0); > if (err == -1) { > - return err; > + return -errno; > } > local_set_xattr(rpath(fs_ctx, path, buffer), credp); > if (err == -1) { > @@ -240,7 +254,7 @@ static int local_mknod(FsContext *fs_ctx, const char > *path, FsCred *credp) > err = mknod(rpath(fs_ctx, path, buffer), credp->fc_mode, > credp->fc_rdev); > if (err == -1) { > - return err; > + return -errno; > } > err = local_post_create_passthrough(fs_ctx, path, credp); > if (err == -1) { > @@ -248,12 +262,12 @@ static int local_mknod(FsContext *fs_ctx, const char > *path, FsCred *credp) > goto err_end; > } > } > - return err; > + return 0; > > err_end: > remove(rpath(fs_ctx, path, buffer)); > errno = serrno; > - return err; > + return -errno; > } > > static int local_mkdir(FsContext *fs_ctx, const char *path, FsCred *credp) > @@ -266,7 +280,7 @@ static int local_mkdir(FsContext *fs_ctx, const char > *path, FsCred *credp) > if (fs_ctx->fs_sm == SM_MAPPED) { > err = mkdir(rpath(fs_ctx, path, buffer), SM_LOCAL_DIR_MODE_BITS); > if (err == -1) { > - return err; > + return -errno; > } > credp->fc_mode = credp->fc_mode|S_IFDIR; > err = local_set_xattr(rpath(fs_ctx, path, buffer), credp); > @@ -278,7 +292,7 @@ static int local_mkdir(FsContext *fs_ctx, const char > *path, FsCred *credp) > (fs_ctx->fs_sm == SM_NONE)) { > err = mkdir(rpath(fs_ctx, path, buffer), credp->fc_mode); > if (err == -1) { > - return err; > + return -errno; > } > err = local_post_create_passthrough(fs_ctx, path, credp); > if (err == -1) { > @@ -286,12 +300,12 @@ static int local_mkdir(FsContext *fs_ctx, const char > *path, FsCred *credp) > goto err_end; > } > } > - return err; > + return 0; > > err_end: > remove(rpath(fs_ctx, path, buffer)); > errno = serrno; > - return err; > + return -errno; > } > > static int local_fstat(FsContext *fs_ctx, int fd, struct stat *stbuf) > @@ -299,7 +313,7 @@ static int local_fstat(FsContext *fs_ctx, int fd, > struct stat *stbuf) > int err; > err = fstat(fd, stbuf); > if (err) { > - return err; > + return -errno; > } > if (fs_ctx->fs_sm == SM_MAPPED) { > /* Actual credentials are part of extended attrs */ > @@ -321,7 +335,7 @@ static int local_fstat(FsContext *fs_ctx, int fd, > struct stat *stbuf) > stbuf->st_rdev = tmp_dev; > } > } > - return err; > + return 0; > } > > static int local_open2(FsContext *fs_ctx, const char *path, int flags, > @@ -336,7 +350,7 @@ static int local_open2(FsContext *fs_ctx, const char > *path, int flags, > if (fs_ctx->fs_sm == SM_MAPPED) { > fd = open(rpath(fs_ctx, path, buffer), flags, SM_LOCAL_MODE_BITS); > if (fd == -1) { > - return fd; > + return -errno; > } > credp->fc_mode = credp->fc_mode|S_IFREG; > /* Set cleint credentials in xattr */ > @@ -349,7 +363,7 @@ static int local_open2(FsContext *fs_ctx, const char > *path, int flags, > (fs_ctx->fs_sm == SM_NONE)) { > fd = open(rpath(fs_ctx, path, buffer), flags, credp->fc_mode); > if (fd == -1) { > - return fd; > + return -errno; > } > err = local_post_create_passthrough(fs_ctx, path, credp); > if (err == -1) { > @@ -363,7 +377,7 @@ err_end: > close(fd); > remove(rpath(fs_ctx, path, buffer)); > errno = serrno; > - return err; > + return -errno; > } > > > @@ -381,7 +395,7 @@ static int local_symlink(FsContext *fs_ctx, const char > *oldpath, > fd = open(rpath(fs_ctx, newpath, buffer), O_CREAT|O_EXCL|O_RDWR, > SM_LOCAL_MODE_BITS); > if (fd == -1) { > - return fd; > + return -errno; > } > /* Write the oldpath (target) to the file. */ > oldpath_size = strlen(oldpath); > @@ -407,7 +421,7 @@ static int local_symlink(FsContext *fs_ctx, const char > *oldpath, > (fs_ctx->fs_sm == SM_NONE)) { > err = symlink(oldpath, rpath(fs_ctx, newpath, buffer)); > if (err) { > - return err; > + return -errno; > } > err = lchown(rpath(fs_ctx, newpath, buffer), credp->fc_uid, > credp->fc_gid); > @@ -423,25 +437,24 @@ static int local_symlink(FsContext *fs_ctx, const > char *oldpath, > err = 0; > } > } > - return err; > + return 0; > > err_end: > remove(rpath(fs_ctx, newpath, buffer)); > errno = serrno; > - return err; > + return -errno; > } > > static int local_link(FsContext *ctx, const char *oldpath, const char > *newpath) > { > char buffer[PATH_MAX], buffer1[PATH_MAX]; > - > - return link(rpath(ctx, oldpath, buffer), rpath(ctx, newpath, > buffer1)); > + return link(rpath(ctx, oldpath, buffer), rpath(ctx, newpath, buffer1)) > == -1 ? -errno : 0; > } > > static int local_truncate(FsContext *ctx, const char *path, off_t size) > { > char buffer[PATH_MAX]; > - return truncate(rpath(ctx, path, buffer), size); > + return truncate(rpath(ctx, path, buffer), size) == -1 ? -errno : 0; > } > > static int local_rename(FsContext *ctx, const char *oldpath, > @@ -449,7 +462,7 @@ static int local_rename(FsContext *ctx, const char > *oldpath, > { > char buffer[PATH_MAX], buffer1[PATH_MAX]; > > - return rename(rpath(ctx, oldpath, buffer), rpath(ctx, newpath, > buffer1)); > + return rename(rpath(ctx, oldpath, buffer), rpath(ctx, newpath, > buffer1)) == -1 ? -errno : 0; > } > > static int local_chown(FsContext *fs_ctx, const char *path, FsCred *credp) > @@ -458,15 +471,15 @@ static int local_chown(FsContext *fs_ctx, const char > *path, FsCred *credp) > if ((credp->fc_uid == -1 && credp->fc_gid == -1) || > (fs_ctx->fs_sm == SM_PASSTHROUGH)) { > return lchown(rpath(fs_ctx, path, buffer), credp->fc_uid, > - credp->fc_gid); > + credp->fc_gid) == -1 ? -errno : 0; > } else if (fs_ctx->fs_sm == SM_MAPPED) { > return local_set_xattr(rpath(fs_ctx, path, buffer), credp); > } else if ((fs_ctx->fs_sm == SM_PASSTHROUGH) || > (fs_ctx->fs_sm == SM_NONE)) { > return lchown(rpath(fs_ctx, path, buffer), credp->fc_uid, > - credp->fc_gid); > + credp->fc_gid) == -1 ? -errno : 0; > } > - return -1; > + return -EINVAL; > } > > static int local_utimensat(FsContext *s, const char *path, > @@ -480,22 +493,22 @@ static int local_utimensat(FsContext *s, const char > *path, > static int local_remove(FsContext *ctx, const char *path) > { > char buffer[PATH_MAX]; > - return remove(rpath(ctx, path, buffer)); > + return remove(rpath(ctx, path, buffer)) == -1 ? -errno : 0; > } > > static int local_fsync(FsContext *ctx, int fd, int datasync) > { > if (datasync) { > - return qemu_fdatasync(fd); > + return qemu_fdatasync(fd) == -1 ? -errno : 0; > } else { > - return fsync(fd); > + return fsync(fd) == -1 ? -errno : 0; > } > } > > static int local_statfs(FsContext *s, const char *path, struct statfs > *stbuf) > { > char buffer[PATH_MAX]; > - return statfs(rpath(s, path, buffer), stbuf); > + return statfs(rpath(s, path, buffer), stbuf) == -1 ? -errno : 0; > } > > static ssize_t local_lgetxattr(FsContext *ctx, const char *path, > diff --git a/hw/9pfs/virtio-9p-xattr.c b/hw/9pfs/virtio-9p-xattr.c > index bde0b7f..a5a6134 100644 > --- a/hw/9pfs/virtio-9p-xattr.c > +++ b/hw/9pfs/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; > @@ -118,9 +123,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; > @@ -130,9 +140,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; > -- > 1.7.4.1 > > --002354186e6467355c04a6c4c4bb Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi JV,

Any progress regarding merging this patch (and the fsync patc= h I submitted)?
Is there anything I can do to assist/speed the process?<= br>
Thanks
Sassan


On 8 June 201= 1 17:21, Sassan Panahinejad <sassan@sassan.me.uk> wrote:
In a lot of cases, the ha= ndling of errors was quite ugly.
This patch moves reading of errno to immediately after the system calls and= passes it up through the system more cleanly.
Also, in the case of the xattr functions (and possibly others), completely = the wrong error was being returned.


This patch is created against your 9p-coroutine-bh branch, as request= ed. Sorry for the delay, I was unexpectedly required to work abroad for 2 w= eeks.

Signed-off-by: Sassan Panahinejad <sassan@sassan.me.uk>

---
=A0fsdev/file-op-9p.h =A0 =A0 =A0 =A0| =A0 =A04 +-
=A0hw/9pfs/codir.c =A0 =A0 =A0 =A0 =A0 | =A0 14 +----
=A0hw/9pfs/virtio-9p-local.c | =A0123 +++++++++++++++++++= ++++++--------------------
=A0hw/9pfs/virtio-9p-xattr.c | =A0 21 +++++++-
=A04 files changed, 90 insertions(+), 72 deletions(-)

diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h
index af9daf7..3d9575b 100644
--- a/fsdev/file-op-9p.h
+++ b/fsdev/file-op-9p.h
@@ -73,12 +73,12 @@ typedef struct FileOperations
=A0 =A0 int (*setuid)(FsContext *, uid_t);
=A0 =A0 int (*close)(FsContext *, int);
=A0 =A0 int (*closedir)(FsContext *, DIR *);
- =A0 =A0DIR *(*opendir)(FsContext *, const char *);
+ =A0 =A0int (*opendir)(FsContext *, const char *, DIR **);
=A0 =A0 int (*open)(FsContext *, const char *, int);
=A0 =A0 int (*open2)(FsContext *, const char *, int, FsCred *);
=A0 =A0 void (*rewinddir)(FsContext *, DIR *);
=A0 =A0 off_t (*telldir)(FsContext *, DIR *);
- =A0 =A0struct dirent *(*readdir)(FsContext *, DIR *);
+ =A0 =A0int (*readdir)(FsContext *, DIR *, struct dirent **);
=A0 =A0 void (*seekdir)(FsContext *, DIR *, off_t);
=A0 =A0 ssize_t (*preadv)(FsContext *, int, const struct iovec *, int, off= _t);
=A0 =A0 ssize_t (*pwritev)(FsContext *, int, const struct iovec *, int, of= f_t);
diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c
index 110289f..acbbb39 100644
--- a/hw/9pfs/codir.c
+++ b/hw/9pfs/codir.c
@@ -25,12 +25,7 @@ int v9fs_co_readdir(V9fsState *s, V9fsFidState *fidp, st= ruct dirent **dent)
=A0 =A0 =A0 =A0 {
=A0 =A0 =A0 =A0 =A0 =A0 errno =3D 0;
=A0 =A0 =A0 =A0 =A0 =A0 /*FIXME!! need to switch to readdir_r */
- =A0 =A0 =A0 =A0 =A0 =A0*dent =3D s->ops->readdir(&s->ctx, fi= dp->fs.dir);
- =A0 =A0 =A0 =A0 =A0 =A0if (!*dent && errno) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err =3D -errno;
- =A0 =A0 =A0 =A0 =A0 =A0} else {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err =3D 0;
- =A0 =A0 =A0 =A0 =A0 =A0}
+ =A0 =A0 =A0 =A0 =A0 =A0err =3D s->ops->readdir(&s->ctx, fidp= ->fs.dir, dent);
=A0 =A0 =A0 =A0 });
=A0 =A0 return err;
=A0}
@@ -93,12 +88,7 @@ int v9fs_co_opendir(V9fsState *s, V9fsFidState *fidp)
=A0 =A0 v9fs_co_run_in_worker(
=A0 =A0 =A0 =A0 {
- =A0 =A0 =A0 =A0 =A0 =A0dir =3D s->ops->opendir(&s->ctx, fidp= ->path.data);
- =A0 =A0 =A0 =A0 =A0 =A0if (!dir) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err =3D -errno;
- =A0 =A0 =A0 =A0 =A0 =A0} else {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err =3D 0;
- =A0 =A0 =A0 =A0 =A0 =A0}
+ =A0 =A0 =A0 =A0 =A0 =A0err =3D s->ops->opendir(&s->ctx, fidp= ->path.data, &dir);
=A0 =A0 =A0 =A0 });
=A0 =A0 fidp->fs.dir =3D dir;
=A0 =A0 return err;
diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9= p-local.c
index 77904c3..65f35eb 100644
--- a/hw/9pfs/virtio-9p-local.c
+++ b/hw/9pfs/virtio-9p-local.c
@@ -28,7 +28,7 @@ static int local_lstat(FsContext *fs_ctx, const cha= r *path, struct stat *stbuf)
=A0 =A0 char buffer[PATH_MAX];
=A0 =A0 err =3D =A0lstat(rpath(fs_ctx, path, buffer), stbuf);
=A0 =A0 if (err) {
- =A0 =A0 =A0 =A0return err;
+ =A0 =A0 =A0 =A0return -errno;
=A0 =A0 }
=A0 =A0 if (fs_ctx->fs_sm =3D=3D SM_MAPPED) {
=A0 =A0 =A0 =A0 /* Actual credentials are part of extended attrs */
@@ -53,7 +53,7 @@ static int local_lstat(FsContext *fs_ctx, const cha= r *path, struct stat *stbuf)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 stbuf->st_rdev =3D tm= p_dev;
=A0 =A0 =A0 =A0 }
=A0 =A0 }
- =A0 =A0return err;
+ =A0 =A0return 0;
=A0}

=A0static int local_set_xattr(const char *path, FsCred *credp)
@@ -63,28 +63,28 @@ static int local_set_xattr(const char *path, FsCr= ed *credp)
=A0 =A0 =A0 =A0 err =3D setxattr(path, "user.virtfs= .uid", &credp->fc_uid, sizeof(uid_t),
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 0);
=A0 =A0 =A0 =A0 if (err) {
- =A0 =A0 =A0 =A0 =A0 =A0return err;
+ =A0 =A0 =A0 =A0 =A0 =A0return -errno;
=A0 =A0 =A0 =A0 }
=A0 =A0 }
=A0 =A0 if (credp->fc_gid !=3D -1) {
=A0 =A0 =A0 =A0 err =3D setxattr(path, "user.virtfs.gid", &c= redp->fc_gid, sizeof(gid_t),
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 0);
=A0 =A0 =A0 =A0 if (err) {
- =A0 =A0 =A0 =A0 =A0 =A0return err;
+ =A0 =A0 =A0 =A0 =A0 =A0return -errno;
=A0 =A0 =A0 =A0 }
=A0 =A0 }
=A0 =A0 if (credp->fc_mode !=3D -1) {
=A0 =A0 =A0 =A0 err =3D setxattr(path, "user.virtfs.mode", &= credp->fc_mode,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 sizeof(mode_t), 0);
=A0 =A0 =A0 =A0 if (err) {
- =A0 =A0 =A0 =A0 =A0 =A0return err;
+ =A0 =A0 =A0 =A0 =A0 =A0return -errno;
=A0 =A0 =A0 =A0 }
=A0 =A0 }
=A0 =A0 if (credp->fc_rdev !=3D -1) {
=A0 =A0 =A0 =A0 err =3D setxattr(path, "user.virtfs.rdev", &= credp->fc_rdev,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 sizeof(dev_t), 0);
=A0 =A0 =A0 =A0 if (err) {
- =A0 =A0 =A0 =A0 =A0 =A0return err;
+ =A0 =A0 =A0 =A0 =A0 =A0return -errno;
=A0 =A0 =A0 =A0 }
=A0 =A0 }
=A0 =A0 return 0;
@@ -95,7 +95,7 @@ static int local_post_create_passthrough(FsContext = *fs_ctx, const char *path,
=A0{
=A0 =A0 char buffer[PATH_MAX];
=A0 =A0 if (chmod(rpath(fs_ctx, path, buffer), credp->fc_mode & 077= 77) < 0) {
- =A0 =A0 =A0 =A0return -1;
+ =A0 =A0 =A0 =A0return -errno;
=A0 =A0 }
=A0 =A0 if (lchown(rpath(fs_ctx, path, buffer), credp->fc_uid,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 credp->fc_gid) < 0) {
@@ -104,7 +104,7 @@ static int local_post_create_passthrough(FsContext *fs_= ctx, const char *path,
=A0 =A0 =A0 =A0 =A0* using security model none. Ignore t= he error
=A0 =A0 =A0 =A0 =A0*/
=A0 =A0 =A0 =A0 if (fs_ctx->fs_sm !=3D SM_NONE) {
- =A0 =A0 =A0 =A0 =A0 =A0return -1;
+ =A0 =A0 =A0 =A0 =A0 =A0return -errno;
=A0 =A0 =A0 =A0 }
=A0 =A0 }
=A0 =A0 return 0;
@@ -119,40 +119,42 @@ static ssize_t local_readlink(FsContext *fs_ctx= , const char *path,
=A0 =A0 =A0 =A0 int fd;
=A0 =A0 =A0 =A0 fd =3D open(rpath(fs_ctx, path, buffer), O_RDONLY);
=A0 =A0 =A0 =A0 if (fd =3D=3D -1) {
- =A0 =A0 =A0 =A0 =A0 =A0return -1;
+ =A0 =A0 =A0 =A0 =A0 =A0return -errno;
=A0 =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 do {
=A0 =A0 =A0 =A0 =A0 =A0 tsize =3D read(fd, (void *)buf, bufsz);
=A0 =A0 =A0 =A0 } while (tsize =3D=3D -1 && errno =3D=3D EINTR); =A0 =A0 =A0 =A0 close(fd);
- =A0 =A0 =A0 =A0return tsize;
+ =A0 =A0 =A0 =A0return tsize =3D=3D -1 ? -errno : tsize;
=A0 =A0 } else if ((fs_ctx->fs_sm =3D=3D SM_PASSTHROUGH) ||
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(fs_ctx->fs_sm =3D=3D SM_NONE)) {
=A0 =A0 =A0 =A0 tsize =3D readlink(rpath(fs_ctx, path, buffer), buf,= bufsz);
=A0 =A0 }
- =A0 =A0return tsize;
+ =A0 =A0return tsize =3D=3D -1 ? -errno : tsize;
=A0}

=A0static int local_close(FsContext *ctx, int fd)
=A0{
- =A0 =A0return close(fd);
+ =A0 =A0return close(fd) =3D=3D -1 ? -errno : 0;
=A0}

=A0static int local_closedir(FsContext *ctx, DIR *dir)
=A0{
- =A0 =A0return closedir(dir);
+ =A0 =A0return closedir(dir) =3D=3D -1 ? -errno : 0;
=A0}

=A0static int local_open(FsContext *ctx, const char *path, int flags)
=A0{
=A0 =A0 char buffer[PATH_MAX];
- =A0 =A0return open(rpath(ctx, path, buffer), flags);
+ =A0 =A0int ret =3D open(rpath(ctx, path, buffer), flags);
+ =A0 =A0return ret =3D=3D -1 ? -errno : ret;
=A0}

-static DIR *local_opendir(FsContext *ctx, const char *path)
+static int local_opendir(FsContext *ctx, const char *path, DIR **dir)
=A0{
=A0 =A0 char buffer[PATH_MAX];
- =A0 =A0return opendir(rpath(ctx, path, buffer));
+ =A0 =A0*dir =3D opendir(rpath(ctx, path, buffer));
+ =A0 =A0return *dir ? 0 : -errno;
=A0}

=A0static void local_rewinddir(FsContext *ctx, DIR *dir)
@@ -162,12 +164,15 @@ static void local_rewinddir(FsContext *ctx, DIR= *dir)

=A0static off_t local_telldir(FsContext *ctx, DIR *dir)
=A0{
- =A0 =A0return telldir(dir);
+ =A0 =A0int ret =3D telldir(dir);
+ =A0 =A0return ret =3D=3D -1 ? -errno : ret;
=A0}

-static struct dirent *local_readdir(FsContext *ctx, DIR *dir)
+static int local_readdir(FsContext *ctx, DIR *dir, struct dirent **dirent)=
=A0{
- =A0 =A0return readdir(dir);
+ =A0 =A0*dirent =3D readdir(dir);
+ =A0 =A0return *dirent ? 0 : -errno;
+
=A0}

=A0static void local_seekdir(FsContext *ctx, DIR *dir, off_t off)
@@ -178,14 +183,17 @@ static void local_seekdir(FsContext *ctx, DIR *= dir, off_t off)
=A0static ssize_t local_preadv(FsContext *ctx, int fd, co= nst struct iovec *iov,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int iovcnt, off_t = offset)
=A0{
+ =A0 =A0int err;
=A0#ifdef CONFIG_PREADV
- =A0 =A0return preadv(fd, iov, iovcnt, offset);
+ =A0 =A0err =3D preadv(fd, iov, iovcnt, offset);
+ =A0 =A0return err =3D=3D -1 ? -errno : err;
=A0#else
=A0 =A0 int err =3D lseek(fd, offset, SEEK_SET);
=A0 =A0 if (err =3D=3D -1) {
- =A0 =A0 =A0 =A0return err;
+ =A0 =A0 =A0 =A0return -errno;
=A0 =A0 } else {
- =A0 =A0 =A0 =A0return readv(fd, iov, iovcnt);
+ =A0 =A0 =A0 =A0err =3D readv(fd, iov, iovcnt);
+ =A0 =A0 =A0 =A0return err =3D=3D -1 ? -errno : err;
=A0 =A0 }
=A0#endif
=A0}
@@ -193,14 +201,17 @@ static ssize_t local_preadv(FsContext *ctx, int= fd, const struct iovec *iov,
=A0static ssize_t local_pwritev(FsContext *ctx, int fd, c= onst struct iovec *iov,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int iovcnt, off_t = offset)
=A0{
+ =A0 =A0int err;
=A0#ifdef CONFIG_PREADV
- =A0 =A0return pwritev(fd, iov, iovcnt, offset);
+ =A0 =A0err =3D pwritev(fd, iov, iovcnt, offset);
+ =A0 =A0return err =3D=3D -1 ? -errno : err;
=A0#else
=A0 =A0 int err =3D lseek(fd, offset, SEEK_SET);
=A0 =A0 if (err =3D=3D -1) {
- =A0 =A0 =A0 =A0return err;
+ =A0 =A0 =A0 =A0return -errno;
=A0 =A0 } else {
- =A0 =A0 =A0 =A0return writev(fd, iov, iovcnt);
+ =A0 =A0 =A0 =A0err =3D writev(fd, iov, iovcnt);
+ =A0 =A0 =A0 =A0return err =3D=3D -1 ? -errno : err;
=A0 =A0 }
=A0#endif
=A0}
@@ -208,13 +219,16 @@ static ssize_t local_pwritev(FsContext *ctx, in= t fd, const struct iovec *iov,
=A0static int local_chmod(FsContext *fs_ctx, const char *= path, FsCred *credp)
=A0{
=A0 =A0 char buffer[PATH_MAX];
+ =A0 =A0int ret;
+
=A0 =A0 if (fs_ctx->fs_sm =3D=3D SM_MAPPED) {
=A0 =A0 =A0 =A0 return local_set_xattr(rpath(fs_ctx, path, buffer), = credp);
=A0 =A0 } else if ((fs_ctx->fs_sm =3D=3D SM_PASSTHROU= GH) ||
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(fs_ctx->fs_sm =3D=3D SM_NONE)) {
- =A0 =A0 =A0 =A0return chmod(rpath(fs_ctx, path, buffer), credp->= fc_mode);
+ =A0 =A0 =A0 =A0ret =3D chmod(rpath(fs_ctx, path, buffer), credp->fc_mo= de);
+ =A0 =A0 =A0 =A0return ret =3D=3D -1 ? -errno : ret;
=A0 =A0 }
- =A0 =A0return -1;
+ =A0 =A0return -ENOTSUP;
=A0}

=A0static int local_mknod(FsContext *fs_ctx, const char *path, FsCred *cred= p)
@@ -228,7 +242,7 @@ static int local_mknod(FsContext *fs_ctx, const c= har *path, FsCred *credp)
=A0 =A0 =A0 =A0 err =3D mknod(rpath(fs_ctx, path, buffer),
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 SM_LOCAL_MODE_BITS|S_IFR= EG, 0);
=A0 =A0 =A0 =A0 if (err =3D=3D -1) {
- =A0 =A0 =A0 =A0 =A0 =A0return err;
+ =A0 =A0 =A0 =A0 =A0 =A0return -errno;
=A0 =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 local_set_xattr(rpath(fs_ctx, path, buffer), credp);=
=A0 =A0 =A0 =A0 if (err =3D=3D -1) {
@@ -240,7 +254,7 @@ static int local_mknod(FsContext *fs_ctx, const char *p= ath, FsCred *credp)
=A0 =A0 =A0 =A0 err =3D mknod(rpath(fs_ctx, path, buffer), credp->fc_mo= de,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 credp->fc_rdev);
=A0 =A0 =A0 =A0 if (err =3D=3D -1) {
- =A0 =A0 =A0 =A0 =A0 =A0return err;
+ =A0 =A0 =A0 =A0 =A0 =A0return -errno;
=A0 =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 err =3D local_post_create_passthrough(fs_ctx, path, credp)= ;
=A0 =A0 =A0 =A0 if (err =3D=3D -1) {
@@ -248,12 +262,12 @@ static int local_mknod(FsContext *fs_ctx, const= char *path, FsCred *credp)
=A0 =A0 =A0 =A0 =A0 =A0 goto err_end;
=A0 =A0 =A0 =A0 }
=A0 =A0 }
- =A0 =A0return err;
+ =A0 =A0return 0;

=A0err_end:
=A0 =A0 remove(rpath(fs_ctx, path, buffer));
=A0 =A0 errno =3D serrno;
- =A0 =A0return err;
+ =A0 =A0return -errno;
=A0}

=A0static int local_mkdir(FsContext *fs_ctx, const char *path, FsCred *cred= p)
@@ -266,7 +280,7 @@ static int local_mkdir(FsContext *fs_ctx, const c= har *path, FsCred *credp)
=A0 =A0 if (fs_ctx->fs_sm =3D=3D SM_MAPPED) {
=A0 =A0 =A0 =A0 err =3D mkdir(rpath(fs_ctx, path, buffer), SM_LOCAL_= DIR_MODE_BITS);
=A0 =A0 =A0 =A0 if (err =3D=3D -1) {
- =A0 =A0 =A0 =A0 =A0 =A0return err;
+ =A0 =A0 =A0 =A0 =A0 =A0return -errno;
=A0 =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 credp->fc_mode =3D credp->fc_mode|S_IFDIR;
=A0 =A0 =A0 =A0 err =3D local_set_xattr(rpath(fs_ctx, path, buffer),= credp);
@@ -278,7 +292,7 @@ static int local_mkdir(FsContext *fs_ctx, const char *p= ath, FsCred *credp)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(fs_ctx->fs_sm =3D=3D = SM_NONE)) {
=A0 =A0 =A0 =A0 err =3D mkdir(rpath(fs_ctx, path, buffer), credp->= ;fc_mode);
=A0 =A0 =A0 =A0 if (err =3D=3D -1) {
- =A0 =A0 =A0 =A0 =A0 =A0return err;
+ =A0 =A0 =A0 =A0 =A0 =A0return -errno;
=A0 =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 err =3D local_post_create_passthrough(fs_ctx, path, credp)= ;
=A0 =A0 =A0 =A0 if (err =3D=3D -1) {
@@ -286,12 +300,12 @@ static int local_mkdir(FsContext *fs_ctx, const= char *path, FsCred *credp)
=A0 =A0 =A0 =A0 =A0 =A0 goto err_end;
=A0 =A0 =A0 =A0 }
=A0 =A0 }
- =A0 =A0return err;
+ =A0 =A0return 0;

=A0err_end:
=A0 =A0 remove(rpath(fs_ctx, path, buffer));
=A0 =A0 errno =3D serrno;
- =A0 =A0return err;
+ =A0 =A0return -errno;
=A0}

=A0static int local_fstat(FsContext *fs_ctx, int fd, struct stat *stbuf)
@@ -299,7 +313,7 @@ static int local_fstat(FsContext *fs_ctx, int fd,= struct stat *stbuf)
=A0 =A0 int err;
=A0 =A0 err =3D fstat(fd, stbuf);
=A0 =A0 if (err) {
- =A0 =A0 =A0 =A0return err;
+ =A0 =A0 =A0 =A0return -errno;
=A0 =A0 }
=A0 =A0 if (fs_ctx->fs_sm =3D=3D SM_MAPPED) {
=A0 =A0 =A0 =A0 /* Actual credentials are part of extended attrs */
@@ -321,7 +335,7 @@ static int local_fstat(FsContext *fs_ctx, int fd,= struct stat *stbuf)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 stbuf->st_rdev =3D tm= p_dev;
=A0 =A0 =A0 =A0 }
=A0 =A0 }
- =A0 =A0return err;
+ =A0 =A0return 0;
=A0}

=A0static int local_open2(FsContext *fs_ctx, const char *path, int flags,
@@ -336,7 +350,7 @@ static int local_open2(FsContext *fs_ctx, const c= har *path, int flags,
=A0 =A0 if (fs_ctx->fs_sm =3D=3D SM_MAPPED) {
=A0 =A0 =A0 =A0 fd =3D open(rpath(fs_ctx, path, buffer), flags, SM_L= OCAL_MODE_BITS);
=A0 =A0 =A0 =A0 if (fd =3D=3D -1) {
- =A0 =A0 =A0 =A0 =A0 =A0return fd;
+ =A0 =A0 =A0 =A0 =A0 =A0return -errno;
=A0 =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 credp->fc_mode =3D credp->fc_mode|S_IFREG;
=A0 =A0 =A0 =A0 /* Set cleint credentials in xattr */
@@ -349,7 +363,7 @@ static int local_open2(FsContext *fs_ctx, const c= har *path, int flags,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(fs_ctx->fs_sm =3D=3D = SM_NONE)) {
=A0 =A0 =A0 =A0 fd =3D open(rpath(fs_ctx, path, buffer), flags, cred= p->fc_mode);
=A0 =A0 =A0 =A0 if (fd =3D=3D -1) {
- =A0 =A0 =A0 =A0 =A0 =A0return fd;
+ =A0 =A0 =A0 =A0 =A0 =A0return -errno;
=A0 =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 err =3D local_post_create_passthrough(fs_ctx, path, credp)= ;
=A0 =A0 =A0 =A0 if (err =3D=3D -1) {
@@ -363,7 +377,7 @@ err_end:
=A0 =A0 close(fd);
=A0 =A0 remove(rpath(fs_ctx, path, buffer));
=A0 =A0 errno =3D serrno;
- =A0 =A0return err;
+ =A0 =A0return -errno;
=A0}


@@ -381,7 +395,7 @@ static int local_symlink(FsContext *fs_ctx, const= char *oldpath,
=A0 =A0 =A0 =A0 fd =3D open(rpath(fs_ctx, newpath, buffer), O_CREAT|O_EXCL= |O_RDWR,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 SM_LOCAL_MODE_BITS);
=A0 =A0 =A0 =A0 if (fd =3D=3D -1) {
- =A0 =A0 =A0 =A0 =A0 =A0return fd;
+ =A0 =A0 =A0 =A0 =A0 =A0return -errno;
=A0 =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 /* Write the oldpath (target) to the file. */
=A0 =A0 =A0 =A0 oldpath_size =3D strlen(oldpath);
@@ -407,7 +421,7 @@ static int local_symlink(FsContext *fs_ctx, const= char *oldpath,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(fs_ctx->fs_sm =3D=3D = SM_NONE)) {
=A0 =A0 =A0 =A0 err =3D symlink(oldpath, rpath(fs_ctx, newpath, buff= er));
=A0 =A0 =A0 =A0 if (err) {
- =A0 =A0 =A0 =A0 =A0 =A0return err;
+ =A0 =A0 =A0 =A0 =A0 =A0return -errno;
=A0 =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 err =3D lchown(rpath(fs_ctx, newpath, buffer), credp= ->fc_uid,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 credp->fc_gid);
@@ -423,25 +437,24 @@ static int local_symlink(FsContext *fs_ctx, const cha= r *oldpath,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 err =3D 0;
=A0 =A0 =A0 =A0 }
=A0 =A0 }
- =A0 =A0return err;
+ =A0 =A0return 0;

=A0err_end:
=A0 =A0 remove(rpath(fs_ctx, newpath, buffer));
=A0 =A0 errno =3D serrno;
- =A0 =A0return err;
+ =A0 =A0return -errno;
=A0}

=A0static int local_link(FsContext *ctx, const char *oldpath, const char *n= ewpath)
=A0{
=A0 =A0 char buffer[PATH_MAX], buffer1[PATH_MAX];
-
- =A0 =A0return link(rpath(ctx, oldpath, buffer), rpath(ctx, newpath, buffe= r1));
+ =A0 =A0return link(rpath(ctx, oldpath, buffer), rpath(ctx, newpath, buffe= r1)) =3D=3D -1 ? -errno : 0;
=A0}

=A0static int local_truncate(FsContext *ctx, const char *path, off_t size)<= br> =A0{
=A0 =A0 char buffer[PATH_MAX];
- =A0 =A0return truncate(rpath(ctx, path, buffer), size);
+ =A0 =A0return truncate(rpath(ctx, path, buffer), size) =3D=3D -1 ? -errno= : 0;
=A0}

=A0static int local_rename(FsContext *ctx, const char *oldpath,
@@ -449,7 +462,7 @@ static int local_rename(FsContext *ctx, const cha= r *oldpath,
=A0{
=A0 =A0 char buffer[PATH_MAX], buffer1[PATH_MAX];

- =A0 =A0return rename(rpath(ctx, oldpath, buffer), rpath(ctx, newpath, buf= fer1));
+ =A0 =A0return rename(rpath(ctx, oldpath, buffer), rpath(ctx, newpath, buf= fer1)) =3D=3D -1 ? -errno : 0;
=A0}

=A0static int local_chown(FsContext *fs_ctx, const char *path, FsCred *cred= p)
@@ -458,15 +471,15 @@ static int local_chown(FsContext *fs_ctx, const= char *path, FsCred *credp)
=A0 =A0 if ((credp->fc_uid =3D=3D -1 && credp= ->fc_gid =3D=3D -1) ||
=A0 =A0 =A0 =A0 =A0 =A0 (fs_ctx->fs_sm =3D=3D SM_PASSTHROUGH)) {
=A0 =A0 =A0 =A0 return lchown(rpath(fs_ctx, path, buffer), credp->= ;fc_uid,
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0credp->fc_gid);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0credp->fc_gid) =3D=3D= -1 ? -errno : 0;
=A0 =A0 } else if (fs_ctx->fs_sm =3D=3D SM_MAPPED) {
=A0 =A0 =A0 =A0 return local_set_xattr(rpath(fs_ctx, path, buffer), = credp);
=A0 =A0 } else if ((fs_ctx->fs_sm =3D=3D SM_PASSTHROU= GH) ||
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(fs_ctx->fs_sm =3D=3D SM_NONE)) {
=A0 =A0 =A0 =A0 return lchown(rpath(fs_ctx, path, buffer), credp->= ;fc_uid,
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0credp->fc_gid);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0credp->fc_gid) =3D=3D= -1 ? -errno : 0;
=A0 =A0 }
- =A0 =A0return -1;
+ =A0 =A0return -EINVAL;
=A0}

=A0static int local_utimensat(FsContext *s, const char *path,
@@ -480,22 +493,22 @@ static int local_utimensat(FsContext *s, const = char *path,
=A0static int local_remove(FsContext *ctx, const char *pa= th)
=A0{
=A0 =A0 char buffer[PATH_MAX];
- =A0 =A0return remove(rpath(ctx, path, buffer));
+ =A0 =A0return remove(rpath(ctx, path, buffer)) =3D=3D -1 ? -errno : 0;
=A0}

=A0static int local_fsync(FsContext *ctx, int fd, int datasync)
=A0{
=A0 =A0 if (datasync) {
- =A0 =A0 =A0 =A0return qemu_fdatasync(fd);
+ =A0 =A0 =A0 =A0return qemu_fdatasync(fd) =3D=3D -1 ? -errno : 0;
=A0 =A0 } else {
- =A0 =A0 =A0 =A0return fsync(fd);
+ =A0 =A0 =A0 =A0return fsync(fd) =3D=3D -1 ? -errno : 0;
=A0 =A0 }
=A0}

=A0static int local_statfs(FsContext *s, const char *path, struct statfs *s= tbuf)
=A0{
=A0 =A0 char buffer[PATH_MAX];
- =A0 return statfs(rpath(s, path, buffer), stbuf);
+ =A0 return statfs(rpath(s, path, buffer), stbuf) =3D=3D -1 ? -errno : 0;<= br>
=A0}

=A0static ssize_t local_lgetxattr(FsContext *ctx, const char *path,
diff --git a/hw/9pfs/virtio-9p-xattr.c b/hw/9pfs/virtio-9p-xattr.c
index bde0b7f..a5a6134 100644
--- a/hw/9pfs/virtio-9p-xattr.c
+++ b/hw/9pfs/virtio-9p-xattr.c
@@ -32,9 +32,14 @@ static XattrOperations *get_xattr_operations(XattrOperat= ions **h,
=A0ssize_t v9fs_get_xattr(FsContext *ctx, const char *path,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0const char *name, void *val= ue, size_t size)
=A0{
+ =A0 =A0int ret;
=A0 =A0 XattrOperations *xops =3D get_xattr_operations(ctx->xops, name)= ;
=A0 =A0 if (xops) {
- =A0 =A0 =A0 =A0return xops->getxattr(ctx, path, name, value, size); + =A0 =A0 =A0 =A0ret =3D xops->getxattr(ctx, path, name, value, size); + =A0 =A0 =A0 =A0if (ret < 0) {
+ =A0 =A0 =A0 =A0 =A0 =A0return -errno;
+ =A0 =A0 =A0 =A0}
+ =A0 =A0 =A0 =A0return ret;
=A0 =A0 }
=A0 =A0 errno =3D -EOPNOTSUPP;
=A0 =A0 return -1;
@@ -118,9 +123,14 @@ err_out:
=A0int v9fs_set_xattr(FsContext *ctx, const char *path, c= onst char *name,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0void *value, size_t size, int flags= )
=A0{
+ =A0 =A0int ret;
=A0 =A0 XattrOperations *xops =3D get_xattr_operations(ctx->xops, name)= ;
=A0 =A0 if (xops) {
- =A0 =A0 =A0 =A0return xops->setxattr(ctx, path, name, value, size, fla= gs);
+ =A0 =A0 =A0 =A0ret =3D xops->setxattr(ctx, path, name, value, size, fl= ags);
+ =A0 =A0 =A0 =A0if (ret < 0) {
+ =A0 =A0 =A0 =A0 =A0 =A0return -errno;
+ =A0 =A0 =A0 =A0}
+ =A0 =A0 =A0 =A0return ret;
=A0 =A0 }
=A0 =A0 errno =3D -EOPNOTSUPP;
=A0 =A0 return -1;
@@ -130,9 +140,14 @@ int v9fs_set_xattr(FsContext *ctx, const char *p= ath, const char *name,
=A0int v9fs_remove_xattr(FsContext *ctx,<= br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const char *path, const char *= name)
=A0{
+ =A0 =A0int ret;
=A0 =A0 XattrOperations *xops =3D get_xattr_operations(ctx->xops, name)= ;
=A0 =A0 if (xops) {
- =A0 =A0 =A0 =A0return xops->removexattr(ctx, path, name);
+ =A0 =A0 =A0 =A0ret =3D xops->removexattr(ctx, path, name);
+ =A0 =A0 =A0 =A0if (ret < 0) {
+ =A0 =A0 =A0 =A0 =A0 =A0return -errno;
+ =A0 =A0 =A0 =A0}
+ =A0 =A0 =A0 =A0return ret;
=A0 =A0 }
=A0 =A0 errno =3D -EOPNOTSUPP;
=A0 =A0 return -1;
--
1.7.4.1


--002354186e6467355c04a6c4c4bb--