All filesystem methods that call common v9fs_request() function also convert return value to errno. Move this conversion to the common function and remove redundand error handling in methods.
I didn't remove local `retval' variable in simple functions to keep the code consistent. Also, proxy_truncate() seem to prefer zero successful return instead of returning whatever the helper returned, maybe this should be changed. This also removes (harmless) double call to v9fs_string_free() in proxy_mkdir(). Signed-off-by: Michael Tokarev <[email protected]> --- hw/9pfs/virtio-9p-proxy.c | 74 ++++------------------------------------------- 1 file changed, 5 insertions(+), 69 deletions(-) diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c index 13b654d..59c7650 100644 --- a/hw/9pfs/virtio-9p-proxy.c +++ b/hw/9pfs/virtio-9p-proxy.c @@ -513,6 +513,10 @@ close_error: out: qemu_mutex_unlock(&proxy->mutex); + if (retval < 0) { + errno = -retval; + retval = -1; + } return retval; } @@ -520,10 +524,6 @@ static int proxy_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf) { int retval; retval = v9fs_request(fs_ctx->private, T_LSTAT, stbuf, "s", fs_path); - if (retval < 0) { - errno = -retval; - return -1; - } return retval; } @@ -534,7 +534,6 @@ static ssize_t proxy_readlink(FsContext *fs_ctx, V9fsPath *fs_path, retval = v9fs_request(fs_ctx->private, T_READLINK, buf, "sd", fs_path, bufsz); if (retval < 0) { - errno = -retval; return -1; } return strlen(buf); @@ -554,10 +553,6 @@ static int proxy_open(FsContext *ctx, V9fsPath *fs_path, int flags, V9fsFidOpenState *fs) { fs->fd = v9fs_request(ctx->private, T_OPEN, NULL, "sd", fs_path, flags); - if (fs->fd < 0) { - errno = -fs->fd; - fs->fd = -1; - } return fs->fd; } @@ -569,7 +564,6 @@ static int proxy_opendir(FsContext *ctx, fs->dir = NULL; fd = v9fs_request(ctx->private, T_OPEN, NULL, "sd", fs_path, O_DIRECTORY); if (fd < 0) { - errno = -fd; return -1; } fs->dir = fdopendir(fd); @@ -655,9 +649,6 @@ static int proxy_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp) int retval; retval = v9fs_request(fs_ctx->private, T_CHMOD, NULL, "sd", fs_path, credp->fc_mode); - if (retval < 0) { - errno = -retval; - } return retval; } @@ -674,10 +665,6 @@ static int proxy_mknod(FsContext *fs_ctx, V9fsPath *dir_path, &fullname, credp->fc_mode, credp->fc_rdev, credp->fc_uid, credp->fc_gid); v9fs_string_free(&fullname); - if (retval < 0) { - errno = -retval; - retval = -1; - } return retval; } @@ -693,11 +680,6 @@ static int proxy_mkdir(FsContext *fs_ctx, V9fsPath *dir_path, retval = v9fs_request(fs_ctx->private, T_MKDIR, NULL, "sddd", &fullname, credp->fc_mode, credp->fc_uid, credp->fc_gid); v9fs_string_free(&fullname); - if (retval < 0) { - errno = -retval; - retval = -1; - } - v9fs_string_free(&fullname); return retval; } @@ -726,10 +708,6 @@ static int proxy_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name, &fullname, flags, credp->fc_mode, credp->fc_uid, credp->fc_gid); v9fs_string_free(&fullname); - if (fs->fd < 0) { - errno = -fs->fd; - fs->fd = -1; - } return fs->fd; } @@ -749,10 +727,6 @@ static int proxy_symlink(FsContext *fs_ctx, const char *oldpath, &target, &fullname, credp->fc_uid, credp->fc_gid); v9fs_string_free(&fullname); v9fs_string_free(&target); - if (retval < 0) { - errno = -retval; - retval = -1; - } return retval; } @@ -767,20 +741,14 @@ static int proxy_link(FsContext *ctx, V9fsPath *oldpath, retval = v9fs_request(ctx->private, T_LINK, NULL, "ss", oldpath, &newpath); v9fs_string_free(&newpath); - if (retval < 0) { - errno = -retval; - retval = -1; - } return retval; } static int proxy_truncate(FsContext *ctx, V9fsPath *fs_path, off_t size) { int retval; - retval = v9fs_request(ctx->private, T_TRUNCATE, NULL, "sq", fs_path, size); if (retval < 0) { - errno = -retval; return -1; } return 0; @@ -801,9 +769,6 @@ static int proxy_rename(FsContext *ctx, const char *oldpath, &oldname, &newname); v9fs_string_free(&oldname); v9fs_string_free(&newname); - if (retval < 0) { - errno = -retval; - } return retval; } @@ -812,9 +777,6 @@ static int proxy_chown(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp) int retval; retval = v9fs_request(fs_ctx->private, T_CHOWN, NULL, "sdd", fs_path, credp->fc_uid, credp->fc_gid); - if (retval < 0) { - errno = -retval; - } return retval; } @@ -826,9 +788,6 @@ static int proxy_utimensat(FsContext *s, V9fsPath *fs_path, fs_path, buf[0].tv_sec, buf[0].tv_nsec, buf[1].tv_sec, buf[1].tv_nsec); - if (retval < 0) { - errno = -retval; - } return retval; } @@ -840,9 +799,6 @@ static int proxy_remove(FsContext *ctx, const char *path) v9fs_string_sprintf(&name, "%s", path); retval = v9fs_request(ctx->private, T_REMOVE, NULL, "s", &name); v9fs_string_free(&name); - if (retval < 0) { - errno = -retval; - } return retval; } @@ -868,10 +824,6 @@ static int proxy_statfs(FsContext *s, V9fsPath *fs_path, struct statfs *stbuf) { int retval; retval = v9fs_request(s->private, T_STATFS, stbuf, "s", fs_path); - if (retval < 0) { - errno = -retval; - return -1; - } return retval; } @@ -886,9 +838,6 @@ static ssize_t proxy_lgetxattr(FsContext *ctx, V9fsPath *fs_path, retval = v9fs_request(ctx->private, T_LGETXATTR, value, "dss", size, fs_path, &xname); v9fs_string_free(&xname); - if (retval < 0) { - errno = -retval; - } return retval; } @@ -897,10 +846,7 @@ static ssize_t proxy_llistxattr(FsContext *ctx, V9fsPath *fs_path, { int retval; retval = v9fs_request(ctx->private, T_LLISTXATTR, value, "ds", size, - fs_path); - if (retval < 0) { - errno = -retval; - } + fs_path); return retval; } @@ -922,9 +868,6 @@ static int proxy_lsetxattr(FsContext *ctx, V9fsPath *fs_path, const char *name, fs_path, &xname, &xvalue, size, flags); v9fs_string_free(&xname); v9fs_string_free(&xvalue); - if (retval < 0) { - errno = -retval; - } return retval; } @@ -939,9 +882,6 @@ static int proxy_lremovexattr(FsContext *ctx, V9fsPath *fs_path, retval = v9fs_request(ctx->private, T_LREMOVEXATTR, NULL, "ss", fs_path, &xname); v9fs_string_free(&xname); - if (retval < 0) { - errno = -retval; - } return retval; } @@ -1005,10 +945,6 @@ static int proxy_ioc_getversion(FsContext *fs_ctx, V9fsPath *path, return -1; } err = v9fs_request(fs_ctx->private, T_GETVERSION, st_gen, "s", path); - if (err < 0) { - errno = -err; - err = -1; - } return err; } -- 2.1.4
