From patchwork Fri Sep 16 14:25:46 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 114944 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 94A2AB70C6 for ; Sat, 17 Sep 2011 01:04:33 +1000 (EST) Received: from localhost ([::1]:51174 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R4ZOI-0006ex-6D for incoming@patchwork.ozlabs.org; Fri, 16 Sep 2011 10:27:42 -0400 Received: from eggs.gnu.org ([140.186.70.92]:58723) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R4ZN1-0003KR-9f for qemu-devel@nongnu.org; Fri, 16 Sep 2011 10:26:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R4ZN0-00051p-34 for qemu-devel@nongnu.org; Fri, 16 Sep 2011 10:26:23 -0400 Received: from mail-ww0-f53.google.com ([74.125.82.53]:48095) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R4ZMz-0004wc-RF for qemu-devel@nongnu.org; Fri, 16 Sep 2011 10:26:22 -0400 Received: by mail-ww0-f53.google.com with SMTP id 14so4633242wwg.10 for ; Fri, 16 Sep 2011 07:26:21 -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=jj6p9RgXWD+enNXWkTEGddJG2Q5WF7DmFOy8BMGAz+o=; b=QW0+wjtGOgYrotffxqHF00h0cWvp/O/gEBonWrz4O9qJAWnePlungX4X92OPL3E1dT WV4g6ljx6QJQEmVsdZ7ZzP/6H3Hr/LAAgYmxQaIz2BSpaPEdIXjM7YXIrzLTkXeF9aZh iS1BN/tuwZ2y5ksX2E35HfKxQQW4LqYFk/JFE= Received: by 10.216.169.74 with SMTP id m52mr1239235wel.33.1316183181379; Fri, 16 Sep 2011 07:26:21 -0700 (PDT) Received: from localhost.localdomain (93-34-199-31.ip51.fastwebnet.it. [93.34.199.31]) by mx.google.com with ESMTPS id ek13sm12701198wbb.23.2011.09.16.07.26.19 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 16 Sep 2011 07:26:20 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 16 Sep 2011 16:25:46 +0200 Message-Id: <1316183152-5481-10-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1316183152-5481-1-git-send-email-pbonzini@redhat.com> References: <1316183152-5481-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.53 Subject: [Qemu-devel] [PATCH v2 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 595f4d8..a7fa507 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;