Skip to contentSkip to conversation

QEMU multicast socket support v6

PATCH In review JuanJo Ciarlante 1 participant 2 messages Dec 15, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 QEMU multicast socket support v6

Hi Fabrice ...

I'm attaching my latest diff, main changes from v4 are the isolation+polishing of dgram sockets functions and support for fd= argument for multicast inherited sockets (including test script: tests/qemu-mcast-test-fd.py).

I'm quite comfortable with this src; fd=N support came almost naturally from the code restructuring.

Changes:
v6 (2005-12-15):
* Added tests/qemu-mcast-test-fd.py

v5 (2005-12-15):
* Reworked code to isolate dgram functions and correctly use IO handlers methods with specific dgram implementations
* net_socket_fd_init() now detects STREAM or DGRAM and calls:
- net_socket_fd_init_stream(): merely renamed from previous net_socket_fd_init impl
- net_socket_fd_init_dgram(): it also supports fd passing

As always, available under GPL from
http://www.irrigacion.gov.ar/juanjo/qemu/

Regards...

Signature · 5 lines
--Juanjo

#  Juan Jose Ciarlante (JuanJo) jjo ;at; mendoza.gov.ar                     #
#  GnuPG Public Key: gpg --keyserver wwwkeys.eu.pgp.net --recv-key 66727177 #
#   Key fingerprint: 0D2F 3E5D 8B5C 729E 0560  F453 A3F7 E249 6672 7177     #
README.qemu-mcast new file +66 -0
new file mode 100644
index 0000000..8a109d6
@@ -0,0 +1,66 @@
+QEMU multicast support v6
+=========================
+Author:   JuanJo Ciarlante jjo()um.edu.ar, juanjosec()gmail.com
+Date:     jue dic 15 13:23:33 ART 2005
+Keywords: qemu, socket, multicast, UDP, mcast, UML
+
+Attached patch (against qemu CVS 2005-12-10) adds multicast support for 
+QEMU socket transport, ie: run several stateless possibly non-local QEMUs 
+on same virtual ethernet "BUS". 
+User-mode-linux (UML) compatible (tested).
+
+An excerpt from qemu-doc.texi:
+
+  `-net socket[,vlan=n][,fd=h][,mcast=maddr:port]'
+        Create a VLAN n shared with another QEMU virtual machines using
+        a UDP multicast socket, effectively making a bus for every QEMU
+        with same multicast address maddr and port. NOTES:
+         1. Several QEMU can be running on different hosts and share same
+            bus (assuming correct multicast setup for these hosts).
+         2. mcast  support  is  compatible with User Mode Linux (argument
+            `ethN=mcast'), see http://user-mode-linux.sf.net.
+  Example:
+	# launch one QEMU instance
+	qemu linux.img -net nic,macaddr=52:54:00:12:34:56 -net socket,mcast=230.0.0.1:1234
+	# launch another QEMU instance on same "bus"
+	qemu linux.img -net nic,macaddr=52:54:00:12:34:57 -net socket,mcast=230.0.0.1:1234
+	# launch yet another QEMU instance on same "bus"
+	qemu linux.img -net nic,macaddr=52:54:00:12:34:58 -net socket,mcast=230.0.0.1:1234
+  Example (User Mode Linux compat.):
+	# launch QEMU instance (note mcast address selected is UML's default)
+	qemu linux.img -net nic,macaddr=52:54:00:12:34:56 -net socket,mcast=239.192.168.1:1102
+	# launch UML
+   	/path/to/linux ubd0=/path/to/root_fs eth0=mcast
+
+Available under GPLv2 from
+  http://www.irrigacion.gov.ar/juanjo/qemu/
+
+
+Changes
+-------
+v6 (2005-12-15):
+	* Added tests/qemu-mcast-test-fd.py
+
+v5 (2005-12-15):
+	* Reworked code to isolate dgram functions and correctly use IO handlers methods with
+	  specific dgram implementations
+	* net_socket_fd_init() now detects STREAM or DGRAM and calls:
+	  - net_socket_fd_init_stream(): merely renamed from previous net_socket_fd_init impl
+	  - net_socket_fd_init_dgram():  it also supports fd passing
+
+v4 (2005-12-12):
+	* Tested mcast user-mode-linux compatibility
+	* Minor tweaks
+
+v3 (2005-12-07):
+	* correctly close fds if any socket syscall fails (ie. close'em don't leak'em ;)
+
+v2 (2005-12-07):
+	* 1st public release
+
+
+--Juanjo
+
+#  Juan Jose Ciarlante (JuanJo) jjo ;at; mendoza.gov.ar                     #
+#  GnuPG Public Key: gpg --keyserver wwwkeys.eu.pgp.net --recv-key 66727177 #
+#   Key fingerprint: 0D2F 3E5D 8B5C 729E 0560  F453 A3F7 E249 6672 7177     #
qemu-doc.texi +51 -0

57 lines not on this page · raw message

tests/qemu-mcast-test-fd.py new file +40 -0
new file mode 100755
index 0000000..99083ef
@@ -0,0 +1,40 @@
+#!/usr/bin/python
+# test script: QEMU mcast support for fd's
+# Author: JuanJo Ciarlante, under GPLv2
+import os
+import sys
+import time
+import string
+import struct
+from socket import *
+
+maddr="239.192.168.1"
+
+bind_addr=(maddr, 1102)
+qemu_bin="./i386-softmmu/qemu" 
+so_img="-cdrom /local/isos/livecd-mini/damnsmalllinux/dsl-2.0.iso"  
+
+def create_mcast_socket():
+	s=socket(AF_INET, SOCK_DGRAM, 0)
+	s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
+	s.bind(bind_addr)
+
+	bytes = map(int, string.split(maddr, "."))
+	grpaddr = 0L
+	for byte in bytes: grpaddr = (grpaddr << 8) | byte
+	mreq = struct.pack('ll', htonl(grpaddr), htonl(INADDR_ANY))
+	s.setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP, mreq)
+	return s
+
+s=create_mcast_socket()
+# Here goes the show: pass mcast socket as: fd=%d
+pids=[]
+cmdline="%s %s -net nic,macaddr=52:54:00:12:34:80 -net socket,fd=%d 1>&2 & echo -n $!" % (qemu_bin, so_img, s.fileno())
+pids.append(int(os.popen(cmdline).read()))
+cmdline="%s %s -net nic,macaddr=52:54:00:12:34:81 -net socket,fd=%d 1>&2 & echo -n $!" % (qemu_bin, so_img, s.fileno())
+pids.append(int(os.popen(cmdline).read()))
+
+time.sleep(1) #lets drain QEMU output...
+sys.stderr.write("Press [Enter] to kill %s and exit ->" % pids)
+sys.stdin.readline()
+map(lambda p: os.kill(p, 15), pids)
vl.c +192 -1

241 lines not on this page · raw message

#1 lore raw
Quoted 20 lines · JuanJo Ciarlante

Hi Fabrice ...

I'm attaching my latest diff, main changes from v4 are the isolation+polishing of dgram sockets functions and support for fd= argument for multicast inherited sockets (including test script: tests/qemu-mcast-test-fd.py).

I'm quite comfortable with this src; fd=N support came almost naturally from the code restructuring.

Changes:
v6 (2005-12-15):
* Added tests/qemu-mcast-test-fd.py

v5 (2005-12-15):
* Reworked code to isolate dgram functions and correctly use IO handlers methods with specific dgram implementations
* net_socket_fd_init() now detects STREAM or DGRAM and calls:
- net_socket_fd_init_stream(): merely renamed from previous net_socket_fd_init impl
- net_socket_fd_init_dgram(): it also supports fd passing

Quoted 2 lines

As always, available under GPL from
http://www.irrigacion.gov.ar/juanjo/qemu/

Correction: vl.c is under BSD license, and so are my changes.

Saludos

Signature · 5 lines
--Juanjo

#  Juan Jose Ciarlante (JuanJo) jjo ;at; mendoza.gov.ar                     #
#  GnuPG Public Key: gpg --keyserver wwwkeys.eu.pgp.net --recv-key 66727177 #
#   Key fingerprint: 0D2F 3E5D 8B5C 729E 0560  F453 A3F7 E249 6672 7177     #