From patchwork Thu Sep 16 18:54:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 64992 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 628F3B6EF2 for ; Fri, 17 Sep 2010 04:56:44 +1000 (EST) Received: from localhost ([127.0.0.1]:46995 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OwJdR-000062-KL for incoming@patchwork.ozlabs.org; Thu, 16 Sep 2010 14:56:41 -0400 Received: from [140.186.70.92] (port=42583 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OwJbh-0007fG-FA for qemu-devel@nongnu.org; Thu, 16 Sep 2010 14:54:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OwJbf-0005r6-P2 for qemu-devel@nongnu.org; Thu, 16 Sep 2010 14:54:53 -0400 Received: from smtp6-g21.free.fr ([212.27.42.6]:38828) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OwJbf-0005pz-3j for qemu-devel@nongnu.org; Thu, 16 Sep 2010 14:54:51 -0400 Received: from Quad (unknown [78.238.229.36]) by smtp6-g21.free.fr (Postfix) with ESMTP id 2682982317 for ; Thu, 16 Sep 2010 20:54:43 +0200 (CEST) Received: from laurent by Quad with local (Exim 4.71) (envelope-from ) id 1OwJbW-0001xI-B8; Thu, 16 Sep 2010 20:54:42 +0200 From: Laurent Vivier To: qemu-devel Date: Thu, 16 Sep 2010 20:54:38 +0200 Message-Id: <1284663278-7487-1-git-send-email-laurent@vivier.eu> X-Mailer: git-send-email 1.7.0.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: Laurent Vivier Subject: [Qemu-devel] [PATCH] Improve qemu-nbd performance by 4400 % X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch allows to reduce the boot time from an NBD server from 225 seconds to 5 seconds (time between the "boot cd:0" and the kernel init) for the following command lines: ./qemu-nbd -t ../ISO/debian-500-powerpc-netinst.iso and ./ppc-softmmu/qemu-system-ppc -cdrom nbd:localhost:1024 Signed-off-by: Laurent Vivier --- nbd.c | 20 +++++++++++++++----- 1 files changed, 15 insertions(+), 5 deletions(-) diff --git a/nbd.c b/nbd.c index 011b50f..5d7c758 100644 --- a/nbd.c +++ b/nbd.c @@ -655,7 +655,7 @@ int nbd_trip(BlockDriverState *bs, int csock, off_t size, uint64_t dev_offset, if (nbd_receive_request(csock, &request) == -1) return -1; - if (request.len > data_size) { + if (request.len + sizeof(struct nbd_reply) > data_size) { LOG("len (%u) is larger than max len (%u)", request.len, data_size); errno = EINVAL; @@ -687,7 +687,8 @@ 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, + if (bdrv_read(bs, (request.from + dev_offset) / 512, + data + sizeof(struct nbd_reply), request.len / 512) == -1) { LOG("reading from file failed"); errno = EINVAL; @@ -697,12 +698,21 @@ int nbd_trip(BlockDriverState *bs, int csock, off_t size, uint64_t dev_offset, TRACE("Read %u byte(s)", request.len); - if (nbd_send_reply(csock, &reply) == -1) - return -1; + /* Reply + [ 0 .. 3] magic (NBD_REPLY_MAGIC) + [ 4 .. 7] error (0 == no error) + [ 7 .. 15] handle + */ + + cpu_to_be32w((uint32_t*)data, NBD_REPLY_MAGIC); + cpu_to_be32w((uint32_t*)(data + 4), reply.error); + cpu_to_be64w((uint64_t*)(data + 8), reply.handle); TRACE("Sending data to client"); - if (write_sync(csock, data, request.len) != request.len) { + if (write_sync(csock, data, + request.len + sizeof(struct nbd_reply)) != + request.len + sizeof(struct nbd_reply)) { LOG("writing to socket failed"); errno = EINVAL; return -1;