From patchwork Fri Mar 6 09:23:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 447050 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 626561400EA for ; Fri, 6 Mar 2015 20:25:24 +1100 (AEDT) Received: from localhost ([::1]:57005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YToVW-0002tN-Bp for incoming@patchwork.ozlabs.org; Fri, 06 Mar 2015 04:25:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YToUM-0001Kr-Sq for qemu-devel@nongnu.org; Fri, 06 Mar 2015 04:24:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YToUF-00038D-58 for qemu-devel@nongnu.org; Fri, 06 Mar 2015 04:24:10 -0500 Received: from isrv.corpit.ru ([86.62.121.231]:41776) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YToUE-00036g-MZ for qemu-devel@nongnu.org; Fri, 06 Mar 2015 04:24:03 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 7D77F40F73; Fri, 6 Mar 2015 12:23:55 +0300 (MSK) Received: from tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by tsrv.corpit.ru (Postfix) with SMTP id 6DA0D91D; Fri, 6 Mar 2015 12:23:55 +0300 (MSK) Received: (nullmailer pid 3155 invoked by uid 1000); Fri, 06 Mar 2015 09:23:55 -0000 From: Michael Tokarev To: "Aneesh Kumar K.V" Date: Fri, 6 Mar 2015 12:23:49 +0300 Message-Id: <1425633831-3101-4-git-send-email-mjt@msgid.tls.msk.ru> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1425633831-3101-1-git-send-email-mjt@tls.msk.ru> References: <1425633831-3101-1-git-send-email-mjt@tls.msk.ru> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 86.62.121.231 Cc: Michael Tokarev , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 3/5] 9pfs-proxy: simplify error handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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 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; }