Bug 1001994 - add QMP/HMP support for the getfd/closefd command
add QMP/HMP support for the getfd/closefd command
Status: CLOSED WORKSFORME
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: qemu-kvm (Show other bugs)
6.5
Unspecified Unspecified
medium Severity medium
: rc
: ---
Assigned To: Luiz Capitulino
Virtualization Bugs
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2013-08-28 05:32 EDT by Sibiao Luo
Modified: 2013-08-28 23:05 EDT (History)
11 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2013-08-28 23:05:07 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Sibiao Luo 2013-08-28 05:32:44 EDT
Description of problem:
as bug 994124#6 mentioned getfd/closefd command and i check it in {"execute":"query-commands"} but it did not execute correctly.

Version-Release number of selected component (if applicable):
host info:
# uname -r && rpm -q qemu-kvm
2.6.32-413.el6.x86_64
qemu-kvm-0.12.1.2-2.398.el6.x86_64

How reproducible:
100%

Steps to Reproduce:
1.boot guest with QMP server.
2.connect to QMP and check it.
{"execute":"qmp_capabilities"}
{"return": {}}

{"execute":"query-commands"}
{"return": [...{"name": "getfd"}, {"name": "closefd"}...]}
3.execute getfd/closefd commands.
(qemu) ? getfd
getfd getfd name -- receive a file descriptor via SCM rights and assign it a name
(qemu) ? closefd
closefd closefd name -- close a file descriptor previously passed via SCM rights
(qemu) getfd sluo
No file descriptor supplied via SCM_RIGHTS
(qemu) closefd sluo
File descriptor named 'sluo' not found

{ "execute": "getfd", "arguments": { "fdname": "fd1" } }
{"error": {"class": "FdNotSupplied", "desc": "No file descriptor supplied via SCM_RIGHTS", "data": {}}}
{ "execute": "closefd", "arguments": { "fdname": "fd1" } }
{"error": {"class": "FdNotFound", "desc": "File descriptor named 'fd1' not found", "data": {"name": "fd1"}}}

Actual results:


Expected results:
Add QMP/HMP support for the getfd/closefd command.
getfd
-----
Receive a file descriptor via SCM rights and assign it a name.

Example:

-> { "execute": "getfd", "arguments": { "fdname": "fd1" } }
<- { "return": xx }

closefd
-------

Close a file descriptor previously passed via SCM rights.

Example:

-> { "execute": "closefd", "arguments": { "fdname": "fd1" } }
<- { "return": xx }

Additional info:
Comment 1 Luiz Capitulino 2013-08-28 09:12:46 EDT
What's the problem here? Did you even try to pass a fd to QEMU?

You have to have another process to pass QEMU a fd before you can use getfd. Besides, you run getfd in the monitor that got the fd sent to. That is, if you're running HMP then the sending process has to send the fd to the HMP socket; you won't see a fd sent to QMP in HMP.
Comment 2 Sibiao Luo 2013-08-28 23:05:07 EDT
(In reply to Luiz Capitulino from comment #1)
> What's the problem here? Did you even try to pass a fd to QEMU?
> 
> You have to have another process to pass QEMU a fd before you can use getfd.
> Besides, you run getfd in the monitor that got the fd sent to. That is, if
> you're running HMP then the sending process has to send the fd to the HMP
> socket; you won't see a fd sent to QMP in HMP.
Ok, tried it as your instructor as following, it worked well.

host info:
# uname -r && rpm -q qemu-kvm
2.6.32-413.el6.x86_64
qemu-kvm-0.12.1.2-2.398.el6.x86_64

Steps and results:
1. Start QEMU with a QMP UDP socket.
e.g:...-chardev socket,id=test,path=/tmp/qmp-monitor,server,nowait -mon chardev=test,mode=control

2. Build the attached program and run it, like this:
 (1) Get the pass-fd.c from : https://bugzilla.redhat.com/show_bug.cgi?id=959308#c27

# cc -Wall -o pass-fd pass-fd.c
# touch /tmp/foo.txt
# ./pass-fd /tmp/foo.txt /tmp/qmp-monitor
 sent fd 3

3. Find out QEMU's pid with ps and enter its /proc/*/fd dir, like:
# pidof qemu-kvm
18706
# cd /proc/18706/fd

4. Do a ls -la and verify that /tmp/foo.txt is listed.
fd]# ls -la
...
lrwx------. 1 root root 64 Aug 28 22:48 35 -> /tmp/foo.txt
...

5. Connect to the QMP socket and run:
# nc -U /tmp/qmp-monitor
{"QMP": {"version": {"qemu": {"micro": 1, "minor": 12, "major": 0}, "package": "(qemu-kvm-0.12.1.2)"}, "capabilities": []}}
{"execute":"qmp_capabilities"}
{"return": {}}
{ "execute": "getfd", "arguments": { "fdname": "foo" } }
{"return": {}}

{ "execute": "closefd", "arguments": { "fdname": "foo" } }
{"return": {}}

6. Check it:
# pidof qemu-kvm
18706
# cd /proc/18706/fd
fd]# ls -la
...           <------------/tmp/foo.txt was not listed here.

Base on above, it works for me now, so close it, thanks for your kindly reminds.

Best Regards,
sluo

Note You need to log in before you can comment on or make changes to this bug.