From patchwork Wed Oct 5 07:17:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 117766 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B9924B6F8E for ; Wed, 5 Oct 2011 19:32:54 +1100 (EST) Received: from localhost ([::1]:47580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RBLkc-0000tM-5c for incoming@patchwork.ozlabs.org; Wed, 05 Oct 2011 03:18:46 -0400 Received: from eggs.gnu.org ([140.186.70.92]:33207) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RBLjs-0007SG-PE for qemu-devel@nongnu.org; Wed, 05 Oct 2011 03:18:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RBLjp-0006GR-Pl for qemu-devel@nongnu.org; Wed, 05 Oct 2011 03:18:00 -0400 Received: from mail-wy0-f173.google.com ([74.125.82.173]:35870) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RBLjp-0006EY-IH for qemu-devel@nongnu.org; Wed, 05 Oct 2011 03:17:57 -0400 Received: by mail-wy0-f173.google.com with SMTP id 22so1507475wyh.4 for ; Wed, 05 Oct 2011 00:17:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=1coKawr2ipkHaxLhh+cXdYYkK1kV93CmRm9xanQNwmQ=; b=qoGAX812Jg4cOkTd9pBQijp1y54DpYcXPAJGOJQwxDlfV5v7kpGAB934SGiLdLnEd4 o2aOfBVKwihxDpWsXd8yZE5kC1L/8+C/W1VBgBkkKkSKcU5RRxT6TmlcZFFmVN0uW3/y k3wPS1XS25116ooK0RH9vk/IpUkRh5eZUQHDA= Received: by 10.216.11.209 with SMTP id 59mr1075501wex.58.1317799077215; Wed, 05 Oct 2011 00:17:57 -0700 (PDT) Received: from localhost.localdomain (93-34-218-143.ip51.fastwebnet.it. [93.34.218.143]) by mx.google.com with ESMTPS id p2sm1192306wbo.17.2011.10.05.00.17.56 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 05 Oct 2011 00:17:56 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 5 Oct 2011 09:17:39 +0200 Message-Id: <1317799065-29668-10-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1317799065-29668-1-git-send-email-pbonzini@redhat.com> References: <1317799065-29668-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 74.125.82.173 Subject: [Qemu-devel] [PATCH v3 09/15] nbd: fix error handling in the server 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 bdrv_read and bdrv_write return negative errno values, not -1. Signed-off-by: Paolo Bonzini --- nbd.c | 21 ++++++++++++--------- 1 files changed, 12 insertions(+), 9 deletions(-) diff --git a/nbd.c b/nbd.c index fb5e424..5df9745 100644 --- a/nbd.c +++ b/nbd.c @@ -580,6 +580,7 @@ int nbd_trip(BlockDriverState *bs, int csock, off_t size, uint64_t dev_offset, { struct nbd_request request; struct nbd_reply reply; + int ret; TRACE("Reading request."); @@ -618,12 +619,13 @@ int nbd_trip(BlockDriverState *bs, int csock, off_t size, uint64_t dev_offset, case NBD_CMD_READ: TRACE("Request type is READ"); - if (bdrv_read(bs, (request.from + dev_offset) / 512, - data + NBD_REPLY_SIZE, - request.len / 512) == -1) { + ret = bdrv_read(bs, (request.from + dev_offset) / 512, + data + NBD_REPLY_SIZE, + request.len / 512); + if (ret < 0) { LOG("reading from file failed"); - errno = EINVAL; - return -1; + reply.error = -ret; + request.len = 0; } *offset += request.len; @@ -666,11 +668,12 @@ int nbd_trip(BlockDriverState *bs, int csock, off_t size, uint64_t dev_offset, } else { TRACE("Writing to device"); - if (bdrv_write(bs, (request.from + dev_offset) / 512, - data, request.len / 512) == -1) { + ret = bdrv_write(bs, (request.from + dev_offset) / 512, + data, request.len / 512); + if (ret < 0) { LOG("writing to file failed"); - errno = EINVAL; - return -1; + reply.error = -ret; + request.len = 0; } *offset += request.len;