From patchwork Fri Mar 6 20:18:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 447437 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 95562140161 for ; Sat, 7 Mar 2015 07:38:41 +1100 (AEDT) Received: from localhost ([::1]:60259 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTz15-0000IW-S3 for incoming@patchwork.ozlabs.org; Fri, 06 Mar 2015 15:38:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47781) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTyzD-0005GC-B5 for qemu-devel@nongnu.org; Fri, 06 Mar 2015 15:36:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YTyz6-000760-1W for qemu-devel@nongnu.org; Fri, 06 Mar 2015 15:36:43 -0500 Received: from isrv.corpit.ru ([86.62.121.231]:41184) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTyz5-00073S-KU for qemu-devel@nongnu.org; Fri, 06 Mar 2015 15:36:35 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 9574541085; Fri, 6 Mar 2015 23:36:34 +0300 (MSK) Received: from tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by tsrv.corpit.ru (Postfix) with SMTP id A076D947; Fri, 6 Mar 2015 23:19:42 +0300 (MSK) Received: (nullmailer pid 9980 invoked by uid 1000); Fri, 06 Mar 2015 20:19:38 -0000 From: Michael Tokarev To: "Aneesh Kumar K.V" Date: Fri, 6 Mar 2015 23:18:42 +0300 Message-Id: <1425673176-9819-4-git-send-email-mjt@msgid.tls.msk.ru> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1425673176-9819-1-git-send-email-mjt@tls.msk.ru> References: <1425673176-9819-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 2/6] 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 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; }