From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=48422 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OwdZh-0005qp-Oi for qemu-devel@nongnu.org; Fri, 17 Sep 2010 12:14:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OwdZg-0000ft-Ag for qemu-devel@nongnu.org; Fri, 17 Sep 2010 12:14:09 -0400 Received: from smtp6-g21.free.fr ([212.27.42.6]:45453) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OwdZf-0000fC-DF for qemu-devel@nongnu.org; Fri, 17 Sep 2010 12:14:08 -0400 Received: from Quad (unknown [78.238.229.36]) by smtp6-g21.free.fr (Postfix) with ESMTP id 28AFB82331 for ; Fri, 17 Sep 2010 18:14:00 +0200 (CEST) From: Laurent Vivier Date: Fri, 17 Sep 2010 18:13:57 +0200 Message-Id: <1284740037-6374-1-git-send-email-laurent@vivier.eu> In-Reply-To: <1284663278-7487-1-git-send-email-laurent@vivier.eu> References: <1284663278-7487-1-git-send-email-laurent@vivier.eu> Subject: [Qemu-devel] [PATCH][v2] Improve qemu-nbd performance by 4400 % List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel Cc: Laurent Vivier 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 This patch combines the reply header and payload send operation. Signed-off-by: Laurent Vivier --- v2: use NBD_REPLY_SIZE instead of sizeof(struct nbd_reply) nbd.c | 25 ++++++++++++++++++------- 1 files changed, 18 insertions(+), 7 deletions(-) diff --git a/nbd.c b/nbd.c index 011b50f..4bf2eb7 100644 --- a/nbd.c +++ b/nbd.c @@ -49,6 +49,7 @@ /* This is all part of the "official" NBD API */ +#define NBD_REPLY_SIZE (4 + 4 + 8) #define NBD_REQUEST_MAGIC 0x25609513 #define NBD_REPLY_MAGIC 0x67446698 @@ -588,7 +589,7 @@ static int nbd_receive_request(int csock, struct nbd_request *request) int nbd_receive_reply(int csock, struct nbd_reply *reply) { - uint8_t buf[4 + 4 + 8]; + uint8_t buf[NBD_REPLY_SIZE]; uint32_t magic; memset(buf, 0xAA, sizeof(buf)); @@ -655,9 +656,9 @@ 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 + NBD_REPLY_SIZE > data_size) { LOG("len (%u) is larger than max len (%u)", - request.len, data_size); + request.len + NBD_REPLY_SIZE, data_size); errno = EINVAL; return -1; } @@ -687,7 +688,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 + NBD_REPLY_SIZE, request.len / 512) == -1) { LOG("reading from file failed"); errno = EINVAL; @@ -697,12 +699,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 + NBD_REPLY_SIZE) != + request.len + NBD_REPLY_SIZE) { LOG("writing to socket failed"); errno = EINVAL; return -1; -- 1.7.0.4