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 1538630

Summary: Restarted write to bonding sysfs attribute returns -EINVAL
Product: Red Hat Enterprise Linux 7 Reporter: Michael Burman <mburman>
Component: kernelAssignee: Jarod Wilson <jarod>
Status: CLOSED DUPLICATE QA Contact: Red Hat Kernel QE team <kernel-qe>
Severity: high Docs Contact:
Priority: high    
Version: 7.5CC: aloughla, atragler, bgalvani, danken, edwardh, fgiudici, jarod, jkurik, lrintel, mburman, rkhan, skozina, spower, sukulkar, thaller
Target Milestone: rcKeywords: Regression
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-02-20 17:11:38 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:
Bug Depends On:    
Bug Blocks: 1534258, 1540451, 1546839    
Attachments:
Description Flags
Logs
none
strace output
none
Systemtap script
none
Systemtap output none

Description Michael Burman 2018-01-25 13:39:13 UTC
Created attachment 1386084 [details]
Logs

Description of problem:
NM attempts to manage externally-created bond devices, in our case vdsm. We have a race between NM and vdsm's bondscan.

Jan 25 12:26:46 orchid-vds2 kernel: bonding: bondscan-EjVfYT is being deleted...
Jan 25 12:26:46 orchid-vds2 kernel: (unregistered net_device): Released all slaves
Jan 25 12:26:46 orchid-vds2 NetworkManager[702]: <info>  [1516876005.9791] manager: (bondscan-dvthDE): new Bond device (/org/freedesktop/NetworkManager/Devices/12)
Jan 25 12:26:46 orchid-vds2 kernel: bonding: bondscan-EjVfYT is being created...
Jan 25 12:26:46 orchid-vds2 vdsm-tool: Traceback (most recent call last):
Jan 25 12:26:46 orchid-vds2 vdsm-tool: File "/usr/bin/vdsm-tool", line 219, in main
Jan 25 12:26:46 orchid-vds2 vdsm-tool: return tool_command[cmd]["command"](*args)
Jan 25 12:26:46 orchid-vds2 vdsm-tool: File "/usr/lib/python2.7/site-packages/vdsm/tool/network.py", line 94, in dump_bonding_options
Jan 25 12:26:46 orchid-vds2 vdsm-tool: sysfs_options_mapper.dump_bonding_options()
Jan 25 12:26:46 orchid-vds2 vdsm-tool: File "/usr/lib/python2.7/site-packages/vdsm/network/link/bond/sysfs_options_mapper.py", line 50, in dump_bonding_options
Jan 25 12:26:46 orchid-vds2 NetworkManager[702]: <info>  [1516876006.0081] manager: (bondscan-EjVfYT): new Bond device (/org/freedesktop/NetworkManager/Devices/13)
Jan 25 12:26:46 orchid-vds2 vdsm-tool: jdump(_get_bonding_options_name2numeric(), f)
Jan 25 12:26:46 orchid-vds2 vdsm-tool: File "/usr/lib/python2.7/site-packages/vdsm/network/link/bond/sysfs_options_mapper.py", line 90, in _get_bonding_options_name2numeric
Jan 25 12:26:46 orchid-vds2 vdsm-tool: with _bond_device(bond_name, mode):
Jan 25 12:26:46 orchid-vds2 vdsm-tool: File "/usr/lib64/python2.7/contextlib.py", line 17, in __enter__
Jan 25 12:26:46 orchid-vds2 vdsm-tool: return self.gen.next()
Jan 25 12:26:46 orchid-vds2 vdsm-tool: File "/usr/lib/python2.7/site-packages/vdsm/network/link/bond/sysfs_options_mapper.py", line 102, in _bond_device
Jan 25 12:26:46 orchid-vds2 vdsm-tool: _change_mode(bond_name, mode)
Jan 25 12:26:46 orchid-vds2 vdsm-tool: File "/usr/lib/python2.7/site-packages/vdsm/network/link/bond/sysfs_options_mapper.py", line 112, in _change_mode
Jan 25 12:26:46 orchid-vds2 vdsm-tool: opt.write(mode)
Jan 25 12:26:46 orchid-vds2 vdsm-tool: IOError: [Errno 22] Invalid argument
Jan 25 12:26:46 orchid-vds2 NetworkManager[702]: <info>  [1516876006.0864] manager: (bondscan-EjVfYT): new Bond device (/org/freedesktop/NetworkManager/Devices/14)
Jan 25 12:26:46 orchid-vds2 systemd: vdsm-network-init.service: main process exited, code=exited, status=1/FAILURE

Looks like this bug is blocking our fix for BZ 1534258

Version-Release number of selected component (if applicable):
NetworkManager-1.10.2-4.el7.x86_64
3.10.0-830.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1. Install latest rhel7.5 and latest vdsmd 
2. Try to start vdsmd 

Actual results:
Race between NM and vdsm

Expected results:
NM shouldn't try to manage externally created bond devices

Additional info:
Attaching logs + NM in debug

Comment 2 Edward Haas 2018-01-30 14:09:19 UTC
Please note that this issue is blocking RHV 4.2 and will introduce a regression on RHEV 4.1.

If it cannot be handled in time for RHEL 7.5, we will need to come up with our own workaround.

Comment 3 Beniamino Galvani 2018-02-05 10:04:35 UTC
Hi, thanks for attaching logs.

I see that a write to the 'mode' attribute fails with "[Errno 22]
Invalid argument". It's not clear why that would happen, and
especially how NM is related to that, since according to logs it
treats bond interfaces as unmanaged.

Do you have a reproducer I can run? Or would it be possible to run
vdsm under strace (or maybe instrument it to print which bond options
it is trying to write)?

Comment 4 Michael Burman 2018-02-05 11:39:29 UTC
Hi Beniamino,
I will reproduce and contact you. Thanks

Comment 5 Edward Haas 2018-02-05 12:46:14 UTC
(In reply to Beniamino Galvani from comment #3)
> Hi, thanks for attaching logs.
> 
> I see that a write to the 'mode' attribute fails with "[Errno 22]
> Invalid argument". It's not clear why that would happen, and
> especially how NM is related to that, since according to logs it
> treats bond interfaces as unmanaged.
> 

When the hypervisor is loading, a bond property mapping is executed to map all possible bond modes and their default properties onto a json file. It is later on used by VDSM to calculate when a bond property is to be persisted in the config.
The mapping is done by creating a bond and setting it to a mode, scanning all its options and then removing it, repeating all of this for other modes (new bond is created for each mode).
There is another mapping, between the bond property value ID (numeric) and its string representation. For that, we change the value by ID and read its string representation.
Both mapping are expected to cause errors, especially when trying to input non existing value ID/s or modes (it is a scan after all).

Comment 7 Beniamino Galvani 2018-02-13 09:08:52 UTC
Hi,

were you able to reproduce the problem? Is this a blocker?

Comment 8 Michael Burman 2018-02-13 11:48:57 UTC
(In reply to Beniamino Galvani from comment #7)
> Hi,
> 
> were you able to reproduce the problem? Is this a blocker?

Unfortunately no, i didn't manage to reproduce the issue, which is quite weird as it used to happen 100%. 

Dan, did you managed to reproduce the issue?

Comment 9 Michael Burman 2018-02-18 15:01:33 UTC
We have a reproduction. Beniamino, i have wrote the host details in the e-mail.

Comment 10 Beniamino Galvani 2018-02-19 14:13:18 UTC
Hello,

I was able to reproduce the problem and I believe NetworkManager is
not involved here (the fact the problem happens only when NM is
running is probably because it causes more contention on sysfs
access).

Running the vdsm-tool gives the following error:


 [root@lynx23 ~]# /usr/bin/vdsm-tool dump-bonding-options
 (setting bondscan-jjJjsP mode to 0)
 (setting bondscan-jjJjsP mode to 1)
 Traceback (most recent call last):
   File "/usr/bin/vdsm-tool", line 219, in main
     return tool_command[cmd]["command"](*args)
   File "/usr/lib/python2.7/site-packages/vdsm/tool/network.py", line 94, in dump_bonding_options
     sysfs_options_mapper.dump_bonding_options()
   File "/usr/lib/python2.7/site-packages/vdsm/network/link/bond/sysfs_options_mapper.py", line 48, in dump_bonding_options
     jdump(_get_default_bonding_options(), f)
   File "/usr/lib/python2.7/site-packages/vdsm/network/link/bond/sysfs_options_mapper.py", line 70, in _get_default_bonding_options
     with _bond_device(bond_name, mode):
   File "/usr/lib64/python2.7/contextlib.py", line 17, in __enter__
     return self.gen.next()
   File "/usr/lib/python2.7/site-packages/vdsm/network/link/bond/sysfs_options_mapper.py", line 103, in _bond_device
     _change_mode(bond_name, mode)
   File "/usr/lib/python2.7/site-packages/vdsm/network/link/bond/sysfs_options_mapper.py", line 114, in _change_mode
     opt.write(mode)
 IOError: [Errno 22] Invalid argument
 

The strace output shows that a write to the 'mode' sysfs file fails
with ERESTARTNOINTR, which triggers a system call restart. The second
call fails with EINVAL:


 open("/sys/class/net/bondscan-b5c6gn/bonding/mode", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 5
 fstat(5, {st_mode=S_IFREG|0644, st_size=4096, ...}) = 0
 fstat(5, {st_mode=S_IFREG|0644, st_size=4096, ...}) = 0
 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f14c8260000
 write(5, "1", 1)                        = ? ERESTARTNOINTR (To be restarted)
 write(5, "1", 1)                        = -1 EINVAL (Invalid argument)
 close(5)                                = 0


Running the attached systemtap script shows that the second write()
syscall has a wrong 'pos' argument (-513 instead of 1), which causes a
EINVAL error:


 ### (write '1' to 'mode' file)
 rw_verify_area: pos 0 count 1, ret 1 (vdsm-tool)
 bond_opt_tryset_rtnl: write option 0 value 1, ret -513 (vdsm-tool) <--- rtnl_lock busy
 bonding_sysfs_store_option: ret -513 (vdsm-tool)
 dev_attr_store: ret -513 (vdsm-tool)
 sysfs_kf_write: ret -513 (vdsm-tool)
 kernfs_fop_write: ret -513 (vdsm-tool)
 vfs_write: count 1 pos 0 file 0xffff8ae323a2a200 kernfs_fop_write, return -513 (vdsm-tool)
 ### (restarted syscall)
 rw_verify_area: pos -513 count 1, ret -22 (vdsm-tool)
 vfs_write: count 1 pos -513 file 0xffff8ae323a2a200 kernfs_fop_write, return -22 (vdsm-tool) <-- wrong pos


I suspect this is a bug in kernel.

Comment 11 Beniamino Galvani 2018-02-19 14:14:13 UTC
Created attachment 1397870 [details]
strace output

Comment 12 Beniamino Galvani 2018-02-19 14:14:45 UTC
Created attachment 1397871 [details]
Systemtap script

Comment 13 Beniamino Galvani 2018-02-19 14:15:36 UTC
Created attachment 1397872 [details]
Systemtap output

Comment 14 Beniamino Galvani 2018-02-19 14:20:22 UTC
Reassigning to kernel component for investigation...

Comment 15 Michael Burman 2018-02-19 14:29:59 UTC
The issue reproduced with 
3.10.0-829.el7.x86_64
3.10.0-830.el7.x86_64

Comment 16 Neil Horman 2018-02-19 21:53:24 UTC
I'd compare the strace above to a working case (just echo "1" > /sysfs/class/net/<ifc>/bonding/mode (or whatever the sysfs path is).  It looks to me like the problem is how vdsm is submitting the mode change:
write(5, "1", 1)
Thats the write call being made, and that looks to be a non-null terminated string (character length of 1), which is likely breaking the bonding option parsing code.  If you strace an echo call above, you will likely see the length is longer and an newline is included, which is what the bonding driver expects.

Comment 17 Edward Haas 2018-02-20 10:16:06 UTC
(In reply to Neil Horman from comment #16)
> I'd compare the strace above to a working case (just echo "1" >
> /sysfs/class/net/<ifc>/bonding/mode (or whatever the sysfs path is).  It
> looks to me like the problem is how vdsm is submitting the mode change:
> write(5, "1", 1)
> Thats the write call being made, and that looks to be a non-null terminated
> string (character length of 1), which is likely breaking the bonding option
> parsing code.  If you strace an echo call above, you will likely see the
> length is longer and an newline is included, which is what the bonding
> driver expects.

If you use echo, then it implicitly adds a newline ('\n'), the null termination is not sent in most cases.
strace sh -c "echo '1' > mode.txt" 2>&1 | grep write
write(1, "1\n", 2)

I do not think it is a requirement to pass a newline, especially that we always used it until now and only recently see a problem (which is not easy to recreate).

AFAIK, null termination is usually used internally by the language to detect the end of a string, I would not expect any back-end to require it, especially when by default it is not passed on as seen in the traces.

Comment 18 Jarod Wilson 2018-02-20 14:54:22 UTC
Almost nothing has changed in the bonding sysfs code for nearly two years, and this looks more like a core sysfs bug, nothing really bonding-specific. There was a sysfs namespace patchset that went into 828 though, the timing of which looks suspect to me, given that 829 is the first version where I see the bug reported (comment #15). Please try the most recent kernel that doesn't include commit b10eb5a72fd7de51ecadeea97e9921b0bf31cdc5 '[fs] sysfs: make attr namespace interface less convoluted' -- that looks to be kernel-3.10.0-827.el7.

Comment 19 Michael Burman 2018-02-20 15:27:12 UTC
The bug reproduced with kernel-3.10.0-830.el7 and reported against this kernel version

Comment 20 Beniamino Galvani 2018-02-20 15:52:10 UTC
An easy reproducer:

----
#!/bin/sh

ip l add dummy1 type dummy
ip l add bond1 type bond
ip l add bond2 type bond

ip l set dummy1 master bond1
ip l set dummy1 up
ip l set bond1 up

while true; do cat /sys/class/net/bond1/bonding/slaves > /dev/null; done &

for i in $(seq 100000); do echo 2 > /sys/class/net/bond2/bonding/mode; done 
----

With kernel 3.10.0-830.el7.x86_64:
# ./rh1538630.sh
./rh1538630.sh: line 13: echo: write error: Invalid argument
./rh1538630.sh: line 13: echo: write error: Invalid argument
./rh1538630.sh: line 13: echo: write error: Invalid argument
./rh1538630.sh: line 13: echo: write error: Invalid argument
./rh1538630.sh: line 13: echo: write error: Invalid argument
./rh1538630.sh: line 13: echo: write error: Invalid argument
#


With kernel 3.10.0-843.el7.x86_64
# ./rh1538630.sh
#

The problem seems solved on recent kernels.

Comment 21 Jarod Wilson 2018-02-20 17:10:10 UTC
(In reply to Michael Burman from comment #19)
> The bug reproduced with kernel-3.10.0-830.el7 and reported against this
> kernel version

Yes, but I asked you to try a kernel from BEFORE this, to see if the patchset I referenced might be the cause of the regression. However, Beniamino is now saying that the problem appears to be resolved in even more recent kernels, so in that case, the bug can just be closed, no point in chasing our tails.

Comment 22 Jarod Wilson 2018-02-20 17:11:38 UTC
Based on comment #20, this is already fixed in the latest RHEL-7.5 development kernels.

Comment 23 Michael Burman 2018-02-21 06:45:16 UTC
What is the kernel version that resolves this issue? we currently have 3.10.0-851.el7.x86_64 latest available, does this version good for us?

Comment 25 Jarod Wilson 2018-02-21 13:54:04 UTC
(In reply to Michael Burman from comment #23)
> What is the kernel version that resolves this issue? we currently have
> 3.10.0-851.el7.x86_64 latest available, does this version good for us?

I don't know exactly what kernel resolved things, but if you read comment #20, you can see that Beniamino says it doesn't reproduce any longer on 843, so 851 is presumably also fine, but I'd suggest you test it to be certain.

Comment 26 Beniamino Galvani 2018-02-21 14:14:59 UTC
I think this is a dupe of bug 1534483.

Comment 27 Jarod Wilson 2018-02-22 15:01:15 UTC
(In reply to Beniamino Galvani from comment #26)
> I think this is a dupe of bug 1534483.

Looks like it. In which case, the fix went into 837. Adjusting closed resolution to duplicate.

*** This bug has been marked as a duplicate of bug 1534483 ***