Skip to contentSkip to conversation

migrate to fd - how to use with HMP?

Qemu-devel Alexey Kardashevskiy 2 participants 4 messages Feb 28, 2014

lore
Share & tools
lore
#0 lore raw

Hi!

libvirt uses live migration to fd. I got some bugreports recently and decided to try it without libvirt. So I opened HMP and found "getfd" command. Then with the help of Stefan I tried to use it. And failed.

I run QEMU as this:

/home/aik/qemu-system-ppc64 \
	-enable-kvm \
	-m 1024 \
	-L /home/aik/qemu-ppc64-bios/ \
	-machine pseries \
	-trace events=/home/aik/qemu_trace_events \
	-initrd 1.cpio \
	-kernel vml313 \
	-nographic \
	-vga none \
	-S \
	-chardev socket,id=mon,path=/home/aik/qemu.monitor,server,nowait \
	-mon chardev=mon,mode=readline \
	-chardev socket,id=mon1,host=localhost,port=10000,server,nowait \
	-mon chardev=mon1,mode=readline \
	-chardev stdio,id=id0,signal=off \
	-device spapr-vty,id=id1,chardev=id0,reg=0x71000100

Here is a python3 script I use for QEMU:

qemu = subprocess.Popen(qq, shell=True)
time.sleep(2)
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect("/home/aik/qemu.monitor")
scm_cmd = "/home/aik/socket_scm_helper " + str(sock.fileno()) + " /home/aik/test1"
p = subprocess.Popen(scm_cmd.split(), close_fds = False) p.wait()
sock.close()
add_fd()
qemu.wait()

I checked that without this socket_scm_helper magic both monitors work fine ("telnet localhost 10000" and "socat UNIX-CONNECT:./qemu.monitor STDIN" both give working HMP).

As I see from traces, unix_process_msgfd() receives request and saves fd.

However once socket_scm_helper talked to "mon" (./qemu.monitor), I cannot get any response from it via "socat UNIX-CONNECT:./qemu.monitor STDIN".

And "getfd" command sent to "mon1" responds with "No file descriptor supplied via SCM_RIGHTS" which is true - the fd belongs to "mon".

I tried IO test 042 and that passes. I looked at tests/qemu-iotests/socket_scm_helper.c and I did not find where it actually tries to do anything with the passed file fd. Very confusing.

And here I got stuck. How is it supposed to work? Thanks!

tests/qemu-iotests-quick.sh +1 -1
index cf90de0..91e994c 100755
@@ -12,6 +12,6 @@ export QEMU_IO_PROG="$(pwd)/qemu-io"
 cd $SRC_PATH/tests/qemu-iotests
 
 ret=0
-./check -T -nocache -qcow2 -g quick || ret=1
+./check -T -nocache -raw -g aik || ret=1
 
 exit $ret
tests/qemu-iotests/group +1 -1
index cc750c9..f57f6bb 100644
@@ -51,7 +51,7 @@
 042 rw auto quick
 043 rw auto backing
 044 rw auto
-045 rw auto
+045 rw auto aik
 046 rw auto aio
 047 rw auto
 048 img auto quick
(quoted diff) +0 -0

b/tests/qemu-iotests/socket_scm_helper.c
index 0e2b285..8195983 100644

tests/qemu-iotests/socket_scm_helper.c +1 -1
@@ -52,7 +52,7 @@ static int send_fd(int fd, int fd_to_send)
     cmsg->cmsg_len = CMSG_LEN(sizeof(int));
     cmsg->cmsg_level = SOL_SOCKET;
     cmsg->cmsg_type = SCM_RIGHTS;
-    memcpy(CMSG_DATA(cmsg), &fd, sizeof(int));
+    memcpy(CMSG_DATA(cmsg), &fd_to_send, sizeof(int));
 
     do {
         ret = sendmsg(fd, &msg, 0);
Signature · 1 line
Alexey
#1 lore raw
Quoted 2 lines · Alexey Kardashevskiy

However once socket_scm_helper talked to "mon" (./qemu.monitor), I cannot get any response from it via "socat UNIX-CONNECT:./qemu.monitor STDIN".

Have you tried with QMP? Perhaps the HMP monitor handles connect/disconnect differently from the QMP monitor.

I guess this will require more step-by-step debugging of monitor.c to find out what's going on.

Stefan

#2 lore raw
Quoted 9 lines · Stefan Hajnoczi
Quoted 2 lines · Alexey Kardashevskiy

However once socket_scm_helper talked to "mon" (./qemu.monitor), I cannot get any response from it via "socat UNIX-CONNECT:./qemu.monitor STDIN".

Have you tried with QMP? Perhaps the HMP monitor handles connect/disconnect differently from the QMP monitor.

I guess this will require more step-by-step debugging of monitor.c to find out what's going on.

One of my questions is still unanswered :) Is socket_scm_helper assumed to be correct or it is a bug? Because if it is correct, I do not know what to think. Thanks.

(quoted diff) +0 -0

b/tests/qemu-iotests/socket_scm_helper.c
index 0e2b285..8195983 100644

tests/qemu-iotests/socket_scm_helper.c +1 -1
@@ -52,7 +52,7 @@ static int send_fd(int fd, int fd_to_send)
     cmsg->cmsg_len = CMSG_LEN(sizeof(int));
     cmsg->cmsg_level = SOL_SOCKET;
     cmsg->cmsg_type = SCM_RIGHTS;
-    memcpy(CMSG_DATA(cmsg), &fd, sizeof(int));
+    memcpy(CMSG_DATA(cmsg), &fd_to_send, sizeof(int));
 
 
 
Signature · 1 line
Alexey
#3 lore raw
Quoted 23 lines · Alexey Kardashevskiy
Quoted 9 lines · Stefan Hajnoczi
Quoted 2 lines · Alexey Kardashevskiy

However once socket_scm_helper talked to "mon" (./qemu.monitor), I cannot get any response from it via "socat UNIX-CONNECT:./qemu.monitor STDIN".

Have you tried with QMP? Perhaps the HMP monitor handles connect/disconnect differently from the QMP monitor.

I guess this will require more step-by-step debugging of monitor.c to find out what's going on.

One of my questions is still unanswered :) Is socket_scm_helper assumed to be correct or it is a bug? Because if it is correct, I do not know what to think. Thanks.

tests/qemu-iotests/socket_scm_helper.c +0 -0
index 0e2b285..8195983 100644

tests/qemu-iotests/socket_scm_helper.c static int send_fd(int fd, int fd_to_send) · line 55

Quoted 5 lines
tests/qemu-iotests/socket_scm_helper.c +1 -1
@@ -52,7 +52,7 @@ static int send_fd(int fd, int fd_to_send)
     cmsg->cmsg_len = CMSG_LEN(sizeof(int));
     cmsg->cmsg_level = SOL_SOCKET;
     cmsg->cmsg_type = SCM_RIGHTS;
-    memcpy(CMSG_DATA(cmsg), &fd, sizeof(int));
+    memcpy(CMSG_DATA(cmsg), &fd_to_send, sizeof(int));

Don't assume the 045 test or socket_scm_helper is correct. Your patch makes sense. Please post it to qemu-devel.

Stefan