From patchwork Fri Feb 13 03:45:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Yuan X-Patchwork-Id: 439370 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 A39BB1401B1 for ; Fri, 13 Feb 2015 14:46:06 +1100 (AEDT) Received: from localhost ([::1]:53178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YM7Ce-0004cp-JG for incoming@patchwork.ozlabs.org; Thu, 12 Feb 2015 22:46:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32853) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YM7CN-0004FW-LA for qemu-devel@nongnu.org; Thu, 12 Feb 2015 22:45:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YM7CK-0003fT-EN for qemu-devel@nongnu.org; Thu, 12 Feb 2015 22:45:47 -0500 Received: from mail-ig0-x232.google.com ([2607:f8b0:4001:c05::232]:34112) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YM7CK-0003eP-96 for qemu-devel@nongnu.org; Thu, 12 Feb 2015 22:45:44 -0500 Received: by mail-ig0-f178.google.com with SMTP id hl2so8272142igb.5 for ; Thu, 12 Feb 2015 19:45:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CjehqjKvfJn34bYiH/RY6WWS2BwNtgdiy2Xx1YFKp0Y=; b=FzWrtXg36YqM9mN/ZI9Xr/V9zBCjCIT6fFHf1awllQptmzb6tF2Vl+sntd5c4kj5ET 40N1y3hwezktM1TquVCvo8/MGzbpXq+lF+TAXtb8b7BNxW68p0gKYQBiK59Ive6pq7Rh tbuDp0kXXoBoZziuDzGw9yrkzJ472YtmV5u0XWeXQwduuYtxTLLssr+fF4ZbgMmiaZ5p DSwH2OuneDO6xlD24ubWwJyUnQz5lTJBayz9k/EOuNeyUPwzaHS5EpSs6V7i9Zd+161D XiMMYlPAPJgupQ8SSvJalT69b32scHFLzjByPNJs0EkAn+o2sgGtMb0Jpq6oblN5TfHf dEVA== X-Received: by 10.42.172.1 with SMTP id l1mr12310417icz.80.1423799142893; Thu, 12 Feb 2015 19:45:42 -0800 (PST) Received: from localhost.localdomain ([113.205.34.193]) by mx.google.com with ESMTPSA id 199sm3739256ioe.14.2015.02.12.19.45.39 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Feb 2015 19:45:41 -0800 (PST) From: Liu Yuan To: qemu-devel@nongnu.org, armbru@redhat.com Date: Fri, 13 Feb 2015 11:45:42 +0800 Message-Id: <1423799142-21893-1-git-send-email-namei.unix@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <87pp9f1b61.fsf@blackfin.pond.sub.org> References: <87pp9f1b61.fsf@blackfin.pond.sub.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4001:c05::232 Cc: sheepdog@lists.wpkg.org Subject: [Qemu-devel] [PATCH] sheepdog: fix confused return values 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 From: Liu Yuan These functions mix up -1 and -errno in return values and would might cause trouble error handling in the call chain. This patch let them return -errno and add some comments. Reported-by: Markus Armbruster Signed-off-by: Liu Yuan --- block/sheepdog.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/block/sheepdog.c b/block/sheepdog.c index be3176f..c28658c 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -527,6 +527,7 @@ static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov, return acb; } +/* Return -EIO in case of error, file descriptor on success */ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp) { int fd; @@ -546,11 +547,14 @@ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp) if (fd >= 0) { qemu_set_nonblock(fd); + } else { + fd = -EIO; } return fd; } +/* Return 0 on success and -errno in case of error */ static coroutine_fn int send_co_req(int sockfd, SheepdogReq *hdr, void *data, unsigned int *wlen) { @@ -559,11 +563,13 @@ static coroutine_fn int send_co_req(int sockfd, SheepdogReq *hdr, void *data, ret = qemu_co_send(sockfd, hdr, sizeof(*hdr)); if (ret != sizeof(*hdr)) { error_report("failed to send a req, %s", strerror(errno)); + ret = -errno; return ret; } ret = qemu_co_send(sockfd, data, *wlen); if (ret != *wlen) { + ret = -errno; error_report("failed to send a req, %s", strerror(errno)); } @@ -638,6 +644,11 @@ out: srco->finished = true; } +/* + * Send the request to the sheep in a synchronous manner. + * + * Return 0 on success, -errno in case of error. + */ static int do_req(int sockfd, AioContext *aio_context, SheepdogReq *hdr, void *data, unsigned int *wlen, unsigned int *rlen) {