Received: from eggs.gnu.org ([2001:4830:134:3::10]:43671) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTyiq-0003en-6u for qemu-devel@nongnu.org; Fri, 06 Mar 2015 15:19:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YTyij-0008VQ-F7 for qemu-devel@nongnu.org; Fri, 06 Mar 2015 15:19:48 -0500 Received: from isrv.corpit.ru ([86.62.121.231]:37737) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTyij-0008Uk-3u for qemu-devel@nongnu.org; Fri, 06 Mar 2015 15:19:41 -0500 From: Michael Tokarev Date: Fri, 6 Mar 2015 23:18:40 +0300 Message-Id: <1425673176-9819-2-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 1/6] 9pfs-proxy: simplify v9fs_request() a bit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Aneesh Kumar K.V" Cc: Michael Tokarev , qemu-devel@nongnu.org This simplifies code in v9fs_request() a bit by replacing several ifs with a common variable check and rearranging error/cleanup code a bit. Signet-off-by: Michael Tokarev --- hw/9pfs/virtio-9p-proxy.c | 48 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c index 59c7445..f252fe4 100644 --- a/hw/9pfs/virtio-9p-proxy.c +++ b/hw/9pfs/virtio-9p-proxy.c @@ -299,7 +299,7 @@ static int v9fs_request(V9fsProxy *proxy, int type, dev_t rdev; va_list ap; int size = 0; - int retval = 0; + int retval = 0, err; uint64_t offset; ProxyHeader header = { 0, 0}; struct timespec spec[2]; @@ -310,10 +310,11 @@ static int v9fs_request(V9fsProxy *proxy, int type, qemu_mutex_lock(&proxy->mutex); - if (proxy->sockfd == -1) { + if (proxy->sockfd < 0) { retval = -EIO; - goto err_out; + goto out; } + iovec = &proxy->out_iovec; reply = &proxy->in_iovec; va_start(ap, fmt); @@ -529,15 +530,15 @@ static int v9fs_request(V9fsProxy *proxy, int type, va_end(ap); if (retval < 0) { - goto err_out; + goto out; } /* marshal the header details */ proxy_marshal(iovec, 0, "dd", header.type, header.size); header.size += PROXY_HDR_SZ; - retval = qemu_write_full(proxy->sockfd, iovec->iov_base, header.size); - if (retval != header.size) { + err = qemu_write_full(proxy->sockfd, iovec->iov_base, header.size); + if (err != header.size) { goto close_error; } @@ -548,9 +549,7 @@ static int v9fs_request(V9fsProxy *proxy, int type, * A file descriptor is returned as response for * T_OPEN,T_CREATE on success */ - if (v9fs_receivefd(proxy->sockfd, &retval) < 0) { - goto close_error; - } + err = v9fs_receivefd(proxy->sockfd, &retval); break; case T_MKNOD: case T_MKDIR: @@ -564,41 +563,34 @@ static int v9fs_request(V9fsProxy *proxy, int type, case T_REMOVE: case T_LSETXATTR: case T_LREMOVEXATTR: - if (v9fs_receive_status(proxy, reply, &retval) < 0) { - goto close_error; - } + err = v9fs_receive_status(proxy, reply, &retval); break; case T_LSTAT: case T_READLINK: case T_STATFS: case T_GETVERSION: - if (v9fs_receive_response(proxy, type, &retval, response) < 0) { - goto close_error; - } + err = v9fs_receive_response(proxy, type, &retval, response); break; case T_LGETXATTR: case T_LLISTXATTR: if (!size) { - if (v9fs_receive_status(proxy, reply, &retval) < 0) { - goto close_error; - } + err = v9fs_receive_status(proxy, reply, &retval); } else { - if (v9fs_receive_response(proxy, type, &retval, response) < 0) { - goto close_error; - } + err = v9fs_receive_response(proxy, type, &retval, response); } break; } -err_out: - qemu_mutex_unlock(&proxy->mutex); - return retval; - + if (err < 0) { close_error: - close(proxy->sockfd); - proxy->sockfd = -1; + close(proxy->sockfd); + proxy->sockfd = -1; + retval = -EIO; + } + +out: qemu_mutex_unlock(&proxy->mutex); - return -EIO; + return retval; } static int proxy_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf) -- 2.1.4