qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qemu-nbd: inetd support
@ 2008-09-08  9:30 Laurent Vivier
  2008-09-10 15:24 ` Anthony Liguori
  0 siblings, 1 reply; 4+ messages in thread
From: Laurent Vivier @ 2008-09-08  9:30 UTC (permalink / raw)
  To: qemu-devel@nongnu.org

[-- Attachment #1: Type: text/plain, Size: 632 bytes --]

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=0".

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-nbd --nocache --read-only --port 0 /ISO/ubuntu-7.10-desktop-amd64.iso

Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
-- 
----------------- Laurent.Vivier@bull.net  ------------------
  "La perfection est atteinte non quand il ne reste rien à
ajouter mais quand il ne reste rien à enlever." Saint Exupéry

[-- Attachment #2: qemu-nbd-inetd.patch --]
[-- Type: text/x-vhdl, Size: 1999 bytes --]

---
 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);

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-09-10 16:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-08  9:30 [Qemu-devel] [PATCH] qemu-nbd: inetd support Laurent Vivier
2008-09-10 15:24 ` Anthony Liguori
2008-09-10 16:10   ` Thiemo Seufer
2008-09-10 16:24   ` Laurent Vivier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).