From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kcd4d-000544-Cs for qemu-devel@nongnu.org; Mon, 08 Sep 2008 05:30:19 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kcd4b-00051O-I7 for qemu-devel@nongnu.org; Mon, 08 Sep 2008 05:30:18 -0400 Received: from [199.232.76.173] (port=36495 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kcd4b-00050r-Ab for qemu-devel@nongnu.org; Mon, 08 Sep 2008 05:30:17 -0400 Received: from ecfrec.frec.bull.fr ([129.183.4.8]:48021) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Kcd4a-0003qV-VM for qemu-devel@nongnu.org; Mon, 08 Sep 2008 05:30:17 -0400 Received: from localhost (localhost [127.0.0.1]) by ecfrec.frec.bull.fr (Postfix) with ESMTP id 2A4611A100A for ; Mon, 8 Sep 2008 11:30:11 +0200 (CEST) Received: from ecfrec.frec.bull.fr ([127.0.0.1]) by localhost (ecfrec.frec.bull.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 00475-10 for ; Mon, 8 Sep 2008 11:30:08 +0200 (CEST) Received: from cyclope.frec.bull.fr (cyclope.frec.bull.fr [129.183.4.9]) by ecfrec.frec.bull.fr (Postfix) with ESMTP id 556301A100E for ; Mon, 8 Sep 2008 11:30:08 +0200 (CEST) Received: from [129.183.101.63] (frecb007144.frec.bull.fr [129.183.101.63]) by cyclope.frec.bull.fr (Postfix) with ESMTP id 463F72728D for ; Mon, 8 Sep 2008 11:30:06 +0200 (CEST) From: Laurent Vivier Content-Type: multipart/mixed; boundary="=-QdcEf5QyyW5LRSfHwpZ1" Date: Mon, 08 Sep 2008 11:30:12 +0200 Message-Id: <1220866212.4147.15.camel@frecb07144> Mime-Version: 1.0 Subject: [Qemu-devel] [PATCH] qemu-nbd: inetd support Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "qemu-devel@nongnu.org" --=-QdcEf5QyyW5LRSfHwpZ1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable This patch allows to put qemu-nbd in inetd.conf by using stdin/stdout instead of a socket. This behavior is enabled by specifying "--port=3D0". example: # add in /etc/services.conf nbd 1024/tcp # add in /etc/inetd.conf nbd stream tcp nowait root /usr/local/bin/qemu-nbd /usr/local/bin/qemu-n= bd --nocache --read-only --port 0 /ISO/ubuntu-7.10-desktop-amd64.iso Signed-off-by: Laurent Vivier --=20 ----------------- Laurent.Vivier@bull.net ------------------ "La perfection est atteinte non quand il ne reste rien =C3=A0 ajouter mais quand il ne reste rien =C3=A0 enlever." Saint Exup=C3=A9ry --=-QdcEf5QyyW5LRSfHwpZ1 Content-Disposition: attachment; filename=qemu-nbd-inetd.patch Content-Type: text/x-vhdl; name=qemu-nbd-inetd.patch; charset=UTF-8 Content-Transfer-Encoding: 7bit --- qemu-nbd.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) Index: qemu/qemu-nbd.c =================================================================== --- qemu.orig/qemu-nbd.c 2008-09-07 11:36:14.000000000 +0200 +++ qemu/qemu-nbd.c 2008-09-07 11:37:28.000000000 +0200 @@ -242,7 +242,7 @@ int main(int argc, char **argv) if (*end) { errx(EINVAL, "Invalid port `%s'", optarg); } - if (li < 1 || li > 65535) { + if (li < 0 || li > 65535) { errx(EINVAL, "Port out of range `%s'", optarg); } port = (uint16_t)li; @@ -326,6 +326,10 @@ int main(int argc, char **argv) return 0; } + if (port == 0 && shared != 1) { + errx(EINVAL, "You cannot set port to 0 and use shared"); + } + bdrv_init(); bs = bdrv_new("hda"); @@ -412,9 +416,24 @@ int main(int argc, char **argv) if (sharing_fds == NULL) errx(ENOMEM, "Cannot allocate sharing fds"); + data = qemu_memalign(512, NBD_BUFFER_SIZE); + if (data == NULL) + errx(ENOMEM, "Cannot allocate data buffer"); + if (socket) { sharing_fds[0] = unix_socket_incoming(socket); } else { + if (port == 0) { + /* read and write on stdin/stdout */ + ret = nbd_negotiate(STDIN_FILENO, fd_size); + while (ret != -1) { + ret = nbd_trip(bs, STDIN_FILENO, fd_size, dev_offset, + &offset, readonly, data, NBD_BUFFER_SIZE); + } + qemu_free(data); + bdrv_close(bs); + return 0; + } sharing_fds[0] = tcp_socket_incoming(bindto, port); } @@ -423,10 +442,6 @@ int main(int argc, char **argv) max_fd = sharing_fds[0]; nb_fds++; - data = qemu_memalign(512, NBD_BUFFER_SIZE); - if (data == NULL) - errx(ENOMEM, "Cannot allocate data buffer"); - do { FD_ZERO(&fds); --=-QdcEf5QyyW5LRSfHwpZ1--