From: Laurent Vivier <Laurent.Vivier@bull.net>
To: "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: [Qemu-devel] [PATCH] qemu-nbd: inetd support
Date: Mon, 08 Sep 2008 11:30:12 +0200 [thread overview]
Message-ID: <1220866212.4147.15.camel@frecb07144> (raw)
[-- 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);
next reply other threads:[~2008-09-08 9:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-08 9:30 Laurent Vivier [this message]
2008-09-10 15:24 ` [Qemu-devel] [PATCH] qemu-nbd: inetd support Anthony Liguori
2008-09-10 16:10 ` Thiemo Seufer
2008-09-10 16:24 ` Laurent Vivier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1220866212.4147.15.camel@frecb07144 \
--to=laurent.vivier@bull.net \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).