Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core, udev: remove old device on move event #16968

Merged
merged 9 commits into from Oct 14, 2020

Conversation

yuwata
Copy link
Member

@yuwata yuwata commented Sep 7, 2020

Fixes #16967.

Copy link
Member

@keszybz keszybz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK, but the udev rules files somehow doesn't feel right. @poettering do you have a better approach?

rules.d/10-systemd-on-move.rules Outdated Show resolved Hide resolved
@yuwata
Copy link
Member Author

yuwata commented Sep 8, 2020

CentOS CIs are failed. @mrc0mmand Is it related to that the CI uses an old image for the test?

[TASK START] Mon 07 Sep 2020 08:18:29 AM UTC
make: Entering directory '/build/test/TEST-29-UDEV-ID_RENAMING'
TEST-29-UDEV-ID_RENAMING SETUP: UDEV ID_RENAMING property
Reusing existing cached image /systemd-meson-build/test/TEST-29-UDEV-ID_RENAMING/../default.img → /systemd-meson-build/test/default.img
'/systemd-meson-build/test/default.img' -> '/var/tmp/systemd-test-TEST-29-UDEV-ID_RENAMING/default.img'

@yuwata
Copy link
Member Author

yuwata commented Sep 8, 2020

Ah, IMAGE_NAME= needs to be set when non-basic image is used.

@yuwata yuwata force-pushed the remove-old-device-on-move-event branch from c664336 to b0357ae Compare September 8, 2020 05:53
src/core/device.c Show resolved Hide resolved
rules.d/10-systemd-on-move.rules Outdated Show resolved Hide resolved
rules.d/99-systemd.rules.in Outdated Show resolved Hide resolved
@yuwata yuwata force-pushed the remove-old-device-on-move-event branch from b0357ae to 273146f Compare September 8, 2020 22:27
@poettering
Copy link
Member

So, yea, I think we should change "move" actions to not copy the db, it sounds wrong to me if we#d copy it then.

@keszybz
Copy link
Member

keszybz commented Sep 12, 2020

So, yea, I think we should change "move" actions to not copy the db, it sounds wrong to me if we#d copy it then.

Agreed.

@yuwata yuwata force-pushed the remove-old-device-on-move-event branch from 273146f to cee0fb4 Compare September 14, 2020 07:19
@yuwata
Copy link
Member Author

yuwata commented Sep 14, 2020

@poettering and @keszybz Thank you for the comments. Updated. Now udev properties are also flushed on 'move' uevent. However, it makes 'ID_NET_DRIVER=', 'ID_NET_LINK_FILE=' and 'ID_NET_NAME=' dropped after 'move' event. So, I changed 80-net-setup-link.rules to apply .link file also on 'move' event (strictly speaking, all event but except for 'remove' event, I am not sure what we should do e.g., 'change' or 'bind' event). PTAL.

@yuwata
Copy link
Member Author

yuwata commented Sep 14, 2020

semaphoreci failed with internal compiler error. Seems not related.

FAILED: systemd-networkd 
cc  -o systemd-networkd systemd-networkd.p/src_network_networkd.c.o -flto -Wl,--as-needed -Wl,--no-undefined -pie -Wl,-z,relro -Wl,-z,now -fstack-protector -Wl,--gc-sections -g -O2 -fdebug-prefix-map=/tmp/autopkgtest-lxc.fpuyd49n/downtmp/build.naw/src=. -fstack-protector-strong -Wformat -Werror=format-security -Wl,-z,relro -Wl,--start-group src/network/libnetworkd-core.a src/shared/libsystemd-shared-246.so src/libsystemd-network/libsystemd-network.a src/udev/libudev_static.a src/shared/libsystemd-shared-246.a src/libsystemd/libsystemd_static.a src/basic/libbasic.a src/udev/libudev-basic.a -pthread -lacl /usr/lib/x86_64-linux-gnu/libblkid.so /usr/lib/x86_64-linux-gnu/libcap.so -lcrypt -lgcrypt /usr/lib/x86_64-linux-gnu/libidn2.so /usr/lib/x86_64-linux-gnu/libip4tc.so /usr/lib/x86_64-linux-gnu/libip6tc.so /usr/lib/x86_64-linux-gnu/libkmod.so /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/liblz4.so /usr/lib/x86_64-linux-gnu/libmount.so /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib/x86_64-linux-gnu/libcrypto.so -lpam -lrt /usr/lib/x86_64-linux-gnu/libseccomp.so /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libselinux.so /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libzstd.so /usr/lib/x86_64-linux-gnu/liblzma.so -lm -ldl -Wl,--end-group '-Wl,-rpath,$ORIGIN/src/shared' -Wl,-rpath-link,/tmp/autopkgtest-lxc.fpuyd49n/downtmp/build.naw/src/build-deb/src/shared
lto1: internal compiler error: output_operand: invalid expression as operand
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-10/README.Bugs> for instructions.
lto-wrapper: fatal error: cc returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status

@keszybz
Copy link
Member

keszybz commented Sep 14, 2020

Hmm, so with your patch, we don't set ID_NET_NAME. But we don't know for sure if end-user rules or other consumers of the udev db don't make some other use of ID_NET_NAME. So... shouldn't we instead set ID_NET_NAME unconditionally, and tweak rules.d/80-net-setup-link.rules so simply skip the rename when ACTION!="add" ? I don't know what better.

@yuwata yuwata force-pushed the remove-old-device-on-move-event branch from cee0fb4 to e822a42 Compare September 14, 2020 09:33
@yuwata
Copy link
Member Author

yuwata commented Sep 14, 2020

Updated. Now ID_NET_NAME= is also re-assigned. Note that interface renaming is done only on 'add' uevent:

if (!device_for_action(dev, DEVICE_ACTION_ADD))
return 0; /* Rename the interface only when it is added. */

So, it is safe to set NAME= on all uevent in 80-net-setup-link.rules.

@poettering
Copy link
Member

@poettering and @keszybz Thank you for the comments. Updated. Now udev properties are also flushed on 'move' uevent. However, it makes 'ID_NET_DRIVER=', 'ID_NET_LINK_FILE=' and 'ID_NET_NAME=' dropped after 'move' event. So, I changed 80-net-setup-link.rules to apply .link file also on 'move' event (strictly speaking, all event but except for 'remove' event, I am not sure what we should do e.g., 'change' or 'bind' event). PTAL.

So in the in NEWS file we actually suggest people should always use !="remove" rather than == add|change or so, hence this change is very much in line with what we suggest there, so that sounds good at first sight.

Hmm, but then again, the net setup stuff might readjust device parameters, and we probably shouldn't do that on "change" or so, but only on "add" (and maybe "bind"?) So maybe, the net setup code itself should check the event action, and if it's "add" or "bind" make device changes, but if it's anything else it should just generate props...

Hmm, that said: we probably should manually import specific props that we cannot regenerate on each event, like before b081b27. i.e. once a device is renamed and otherwise changed we might not be able to determine anymore whether it was us that renamed the thing and based on which .link file, hence we should probably import the props that is stored in over manually by focussed udev rules.

src/udev/net/link-config.c Outdated Show resolved Hide resolved
src/udev/net/link-config.c Outdated Show resolved Hide resolved
…ev_t"

This reverts commit b081b27.

If a network interface get a 'move' event, then previously SYSTEMD_ALIAS=
property still contains an old alias, and the old alias .device unit
will not be removed.

This makes all properties cleared on 'move' event, and then old alias
.device unit will be removed by pid1.

Fixes systemd#16967.
@yuwata yuwata force-pushed the remove-old-device-on-move-event branch 2 times, most recently from ee80f9d to 6059187 Compare September 15, 2020 02:22
@yuwata
Copy link
Member Author

yuwata commented Sep 15, 2020

@poettering Thank you for the comments. Updated.

Hmm, but then again, the net setup stuff might readjust device parameters, and we probably shouldn't do that on "change" or so, but only on "add" (and maybe "bind"?) So maybe, the net setup code itself should check the event action, and if it's "add" or "bind" make device changes, but if it's anything else it should just generate props...

Now, .link settings are applied on 'add', 'bind', and also 'move' events. On 'move' event, Name= and NamePolicy= settings are ignored, as it may re-generate 'move' event. But, I have no reason to not apply other settings on 'move' event.

Hmm, that said: we probably should manually import specific props that we cannot regenerate on each event, like before b081b27. i.e. once a device is renamed and otherwise changed we might not be able to determine anymore whether it was us that renamed the thing and based on which .link file, hence we should probably import the props that is stored in over manually by focussed udev rules.

Not sure. what is the difference between IMPORT{builtin}="net_setup_link" and just importing the three properties?

…rties on non-'add' uevent

Previous commit makes drop ID_NET_DRIVER=, ID_NET_LINK_FILE=, and
ID_NET_NAME= properties for network interfaces on 'move' uevent.
ID_NET_DRIVER= and ID_NET_LINK_FILE= properties are used by networkctl.
ID_NET_NAME= may be used by end-user rules or programs. So, let's
re-assign them on 'move' uevent. (Note that strictly speaking, this
makes them re-assigned on all but 'remove' uevent.)
@yuwata yuwata force-pushed the remove-old-device-on-move-event branch from 6059187 to efdaeb8 Compare September 15, 2020 02:30
@yuwata yuwata added this to the v247 milestone Oct 5, 2020
@yuwata
Copy link
Member Author

yuwata commented Oct 6, 2020

@poettering and @keszybz Could you review this again?

@poettering
Copy link
Member

Not sure. what is the difference between IMPORT{builtin}="net_setup_link" and just importing the three properties?

Hmm, the ID_NET_LINK_FILE gets dropped that caused the interface to be renamed. But maybe that's actually OK, since it probably should be set to whatever counts now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Previous device units not removed when renaming network interface
3 participants