Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1152478

Summary: Execute QMP: "getfd.." will show error: No file descriptor supplied via SCM_RIGHTS
Product: Red Hat Enterprise Linux 7 Reporter: langfang <flang>
Component: qemu-kvm-rhevAssignee: Luiz Capitulino <lcapitulino>
Status: CLOSED NOTABUG QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: low    
Version: 7.1CC: amberzapp, armbru, flang, hhuang, juzhang, lcapitulino, qiguo, sluo, virt-maint, xfu, xiaohli, yiwei
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-10-30 14:23:53 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
/proc/$qemi-pid/fd contents
none
fixed pass-fd program none

Description langfang 2014-10-14 08:59:24 UTC
Description of problem:
Execute QMP: "getfd.." will show error: No file descriptor supplied via SCM_RIGHTS

Version-Release number of selected component (if applicable):
# uname -r
3.10.0-187.el7.x86_64
# rpm -q qemu-kvm-rhev
qemu-kvm-rhev-2.1.2-3.el7.x86_64

Guest:
3.10.0-187.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1.Boot guest
...-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:

 # cd /proc/22197/fd

4. Do a ls -la and verify that /tmp/foo.txt is listed
# ls -la /tmp/qmp-monitor 
srwxr-xr-x. 1 root root 0 Oct 14 15:36 /tmp/qmp-monitor

5. Connect to the QMP socket and run:
#nc  -U  /tmp/qmp-monitor
{"QMP": {"version": {"qemu": {"micro": 2, "minor": 1, "major": 2}, "package": " (qemu-kvm-rhev-2.1.2-3.el7)"}, "capabilities": []}}
{"execute":"qmp_capabilities"}
{"return": {}}

...
 { "execute": "getfd", "arguments": { "fdname": "foo" } }
 


Actual results:
After step 5:
{ "execute": "getfd", "arguments": { "fdname": "foo" } }
{"error": {"class": "GenericError", "desc": "No file descriptor supplied via SCM_RIGHTS"}}



Expected results:


Additional info:
1)My CLI:
 /usr/libexec/qemu-kvm -enable-kvm -cpu SandyBridge -m 2046 -smp 2,maxcpuse rhel7 -uuid 6afa5f93-2d4f-420f-81c6-e5fdddbd1c83 -boot menu=on -vnc :12 -vga std -drive file=/home/RHEL-Server-7.0-64-virtio.qcow2,format=qcow2,if=none,id=drive-ide0-0-0,werror=stop,rerror=stop,cache=none -device virtio-blk-pci,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=0 -monitor stdio -netdev tap,id=hostnet0,script=/etc/qemu-ifup -device virtio-net-pci,netdev=hostnet0,mac=00:11:29:2c:45:23,bus=pci.0,addr=0x9,id=net0 -qmp tcp:0:4444,server,nowait -chardev socket,path=/tmp/qga.sock,server,nowait,id=qga0 -device virtio-serial -device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0,id=sr0 -global PIIX4_PM.disable_s3=0 -global PIIX4_PM.disable_s4=0 -chardev socket,id=test,path=/tmp/qmp-monitor,server,nowait -mon chardev=test,mode=control

2)the content of the directory "/proc/22197/fd",please see attachment

Comment 1 langfang 2014-10-14 09:04:42 UTC
Created attachment 946767 [details]
/proc/$qemi-pid/fd  contents

Comment 3 Luiz Capitulino 2014-10-29 18:03:59 UTC
The fd listing you attached to the BZ doesn't show /tmp/foo.txt.

The reason is probably because the pass-fd program you're using has a stupid bug. I've fixed it and will attach a new one here. Also, you have to execute the test-case in this order:

1. Run QEMU
2. Send the file-description by using the pass-fd program
3. Kill the pass-fd program
4. Only then connect to the QMP socket to run the getfd command

In other words, don't connect to the QMP socket before running the pass-fd program, otherwise things will just not work.

Please, close this BZ as NOTABUG if things work now.

PS: I've tested qemu-kvm and qemu-kvm-rhev myself, they work. But I'll let you close the BZ.

Comment 4 Luiz Capitulino 2014-10-29 18:05:37 UTC
Created attachment 951875 [details]
fixed pass-fd program

Comment 5 langfang 2014-10-30 05:11:32 UTC
(In reply to Luiz Capitulino from comment #4)
> Created attachment 951875 [details]
> fixed pass-fd program

Test on latest version:
Host
# uname -r
3.10.0-191.el7.x86_64
# rpm -q qemu-kvm-rhev
qemu-kvm-rhev-2.1.2-5.el7.x86_64

Guest:rhel7

Steps:
1.Boot guest 
...-chardev socket,id=test,path=/tmp/qmp-monitor,server,nowait -mon chardev=test,mode=control...

2.Get the pass-fd program from comment4

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

3.Kill pass-fd program

4.telnet $ip 4444
{"execute":"qmp_capabilities"}
{"return": {}}
{ "execute": "getfd", "arguments": { "fdname": "foo" } }
{"return": {}}



Test on latest qemu-kvm version(qemu-kvm-1.5.3-75.el7.x86_64),work well

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


BUt i hit the same error info when i try to "add-fd/getfd" the second time.The steps as same as above:

Resutls:

# nc  -U  /tmp/qmp-monitor
{"QMP": {"version": {"qemu": {"micro": 2, "minor": 1, "major": 2}, "package": " (qemu-kvm-rhev-2.1.2-5.el7)"}, "capabilities": []}}
{"execute":"qmp_capabilities"}
{"return": {}}
{ "execute": "add-fd", "arguments": { "fdset-id": 1 } }
{"return": {"fd": 84, "fdset-id": 1}}
{ "execute": "add-fd", "arguments": { "fdset-id": 1 } }
{"error": {"class": "GenericError", "desc": "No file descriptor supplied via SCM_RIGHTS"}}
{ "execute": "query-fdsets"}
{"return": [{"fds": [{"fd": 84}], "fdset-id": 1}]}
{ "execute": "add-fd", "arguments": { "fdset-id": 1 } }
{"error": {"class": "GenericError", "desc": "No file descriptor supplied via SCM_RIGHTS"}}



Hi, Luiz
    Is this the expect result? thanks

best regards
fang lang

Comment 6 Luiz Capitulino 2014-10-30 14:23:53 UTC
Yes, because you can add an FD, which as passed via SCM_RIGHTS, only once.

As there's no getfd bug, I'm closing this as NOTABUG.

Comment 7 Yiqian Wei 2017-04-20 03:38:42 UTC
Hi, Luiz

    when i try to "add-fd/getfd" the first time,i hit the same error.

Resutls:
nc -U /tmp/qmp-monitor 
{"QMP": {"version": {"qemu": {"micro": 92, "minor": 8, "major": 2}, "package": "(qemu-kvm-rhev-2.9.0-0.el7.patchwork201703291116)"}, "capabilities": []}}
{"execute":"qmp_capabilities"}
{"return": {}}
{"execute":"getfd","arguments":{"fdname":"/home/foo1"}}
{"error": {"class": "GenericError", "desc": "No file descriptor supplied via SCM_RIGHTS"}}
{ "execute": "query-fdsets"}
{"return": []}
{ "execute": "add-fd", "arguments": { "fdset-id": 1 } }
{"error": {"class": "GenericError", "desc": "No file descriptor supplied via SCM_RIGHTS"}}

 Is this the expect result? 

thanks
yiqian

Comment 8 Luiz Capitulino 2017-04-20 13:07:36 UTC
It's hard to tell without knowing what you're doing. For example, if you're not using another program to send the fd then what you're very probably doing this wrong and the result is the expect one.

What I recommend if for you to try the steps from comment 3. If you have any issues, please open a new BZ.

Comment 9 Li Xiaohui 2019-01-17 09:02:49 UTC
(In reply to Luiz Capitulino from comment #8)
> It's hard to tell without knowing what you're doing. For example, if you're
> not using another program to send the fd then what you're very probably
> doing this wrong and the result is the expect one.
> 
> What I recommend if for you to try the steps from comment 3. If you have any
> issues, please open a new BZ.

Hi Luiz,
I test this case in qemu-img-3.1.0-4.module+el8+2681+819ab34d.x86_64 & kernel-4.18.0-57.el8.x86_64, and hit this issue, too.
Please help to see whether my operations are right, if right, I will open a new bug for rhel8.

1.Test steps:
(1)boot guest with commands:
-chardev socket,id=test,path=/tmp/qmp-monitor,server,nowait \
-mon chardev=test,mode=control \
-qmp tcp:0:4441,server,nowait \

(2)use your Comment 4's pass fd program:
[root@ibm-x3250m6-07 qemu-sh]# gcc -g -Wall -o pass-fd pass-fd.c 
[root@ibm-x3250m6-07 qemu-sh]# touch /tmp/foo.txt
[root@ibm-x3250m6-07 qemu-sh]# ./pass-fd /tmp/foo.txt /tmp/qmp-monitor 

(3)then use "Ctrl + c" to kill pass fd program:
[root@ibm-x3250m6-07 qemu-sh]# ./pass-fd /tmp/foo.txt /tmp/qmp-monitor 
sent fd 3


^C

(4)connect qmp and execute "getfd" operation:
[root@ibm-x3250m6-07 qemu-sh]# telnet 10.73.73.87 4441
Trying 10.73.73.87...
Connected to 10.73.73.87.
Escape character is '^]'.
{"QMP": {"version": {"qemu": {"micro": 0, "minor": 1, "major": 3}, "package": "qemu-kvm-3.1.0-4.module+el8+2681+819ab34d"}, "capabilities": []}}
{"execute":"qmp_capabilities"}
{"return": {}}
{ "execute": "getfd", "arguments": { "fdname": "foo" } }
{"error": {"class": "GenericError", "desc": "No file descriptor supplied via SCM_RIGHTS"}}

Comment 10 Luiz Capitulino 2019-01-17 13:32:29 UTC
Oh, good memories :)

But I think the guy you need is Markus.

Comment 11 Markus Armbruster 2019-01-17 15:49:08 UTC
QEMU receives file descriptors with SCM_RIGHTS from Unix domain sockets, and buffers them until 

* QEMU code (such as QMP command getfd) retrieves them, or

* another SCM_RIGHTS message is received, or

* the socket is closed.

Your test case behaves as intended: when the pass-fd process terminates, the connection gets closed, and the buffered file descriptors get closed.  The new connection (telnet) starts with a clean slate, i.e. *no* file descriptors buffered.  getfd duly fails.

To test getfd with pass-fd, pass-fd needs to send the getfd command itself.

Note that iotest case 045 already covers getfd and setfd.  Perhaps that test can satisfy your needs.

Comment 12 amberzapp 2019-02-16 02:36:19 UTC
Hi Markus!

This test procedure is not working for me. I followed the steps above to test if get fd works and failed. I am using qemu-2.5+dfsg-5ubuntu10.31. Here are the steps that I took:

1. Booted qemu with "-chardev socket,id=test,path=/tmp/qmp-monitor,server,nowait -mon chardev=test,mode=control" added to the arguments.
2. Did 'cd /proc/$qemu_pid/fd' and 'ls -la /tmp/qmp-monitor': showed up correctly
3. Run pass_fd program (did not kill it): ./pass-fd /tmp/foo.txt /tmp/qmp-monitor 
4. In another terminal use QMP to run getfd: Got "No file descriptor supplied via SCM_RIGHTS"

What is the correct way to do this? You mentioned the test pass-fd should run the getfd command itself. Why is that necessary for Qemu to get the file descriptor? 

Thank you in advance! I would like to use getfd to be able to hotplug tap devices into a running qemu vm. I would really appreciate some help!

Comment 13 Markus Armbruster 2019-02-18 06:47:50 UTC
The buffer I mentioned in comment#11 is per monitor (really: per underlying character device).  The file descriptors you passed with pass_fd got buffered in the monitor it connected to.  Your step 4 uses *another* monitor, which had none buffered, so getfd failed as you described.

Comment 14 amberzapp 2019-02-19 00:56:38 UTC
Hi Markus,

Thanks to you I realized I was connecting to the wrong monitor to do getfd (I had two, one on the unix socket /tmp/qmp-monitor and one on telnet). The test is working now, thank you!