Received: from eggs.gnu.org ([2001:4830:134:3::10]:47779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTyzD-0005G7-AD for qemu-devel@nongnu.org; Fri, 06 Mar 2015 15:36:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YTyz6-000761-12 for qemu-devel@nongnu.org; Fri, 06 Mar 2015 15:36:43 -0500 Received: from isrv.corpit.ru ([86.62.121.231]:52604) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTyz5-00073T-KU for qemu-devel@nongnu.org; Fri, 06 Mar 2015 15:36:35 -0500 From: Michael Tokarev Date: Fri, 6 Mar 2015 23:19:32 +0300 Message-Id: <1425673176-9819-54-git-send-email-mjt@msgid.tls.msk.ru> In-Reply-To: <1425673176-9819-1-git-send-email-mjt@tls.msk.ru> References: <1425673176-9819-1-git-send-email-mjt@tls.msk.ru> Subject: [Qemu-devel] [PATCH 47/51] 9pfs-proxy: simplify error handling List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Aneesh Kumar K.V" Cc: Michael Tokarev , qemu-devel@nongnu.org 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 --- 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 f252fe4..bd764be 100644 --- a/hw/9pfs/virtio-9p-proxy.c +++ b/hw/9pfs/virtio-9p-proxy.c @@ -590,6 +590,10 @@ close_error: out: qemu_mutex_unlock(&proxy->mutex); + if (retval < 0) { + errno = -retval; + retval = -1; + } return retval; } @@ -597,10 +601,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; } @@ -611,7 +611,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); @@ -631,10 +630,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; } @@ -646,7 +641,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); @@ -732,9 +726,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; } @@ -751,10 +742,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; } @@ -770,11 +757,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; } @@ -803,10 +785,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; } @@ -826,10 +804,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; } @@ -844,20 +818,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; @@ -878,9 +846,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; } @@ -889,9 +854,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; } @@ -903,9 +865,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; } @@ -917,9 +876,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; } @@ -945,10 +901,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; } @@ -963,9 +915,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; } @@ -974,10 +923,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; } @@ -999,9 +945,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; } @@ -1016,9 +959,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; } @@ -1082,10 +1022,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