Skip to content

Commit

Permalink
generate: avoid calling 'udevadm control --reload' (LP: #1999178)
Browse files Browse the repository at this point in the history
The udev rules directories are monitored and re-loaded automatically with
modern systemd-udevd. No need to manually reload them in the generator,
causing side-effects.

We can still force-reload them when issuing 'netplan generate' or
'netplan apply' through the CLI, just to be on the safe side.

Replaces: #304
  • Loading branch information
slyon committed Jul 4, 2024
1 parent 039ea1f commit ba807c4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
3 changes: 1 addition & 2 deletions netplan_cli/cli/commands/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,7 @@ def command_apply(self, run_generate=True, sync=False, exit_on_error=True, state
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)

# Reloading of udev rules happens during 'netplan generate' already
# subprocess.check_call(['udevadm', 'control', '--reload-rules'])
subprocess.check_call(['udevadm', 'control', '--reload'])
subprocess.check_call(['udevadm', 'trigger', '--attr-match=subsystem=net'])
subprocess.check_call(['udevadm', 'settle'])

Expand Down
4 changes: 4 additions & 0 deletions netplan_cli/cli/commands/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def command_generate(self):
argv += ['--mapping', self.mapping]
logging.debug('command generate: running %s', argv)
res = subprocess.call(argv)
try:
subprocess.check_call(['udevadm', 'control', '--reload'])
except subprocess.CalledProcessError as e:
logging.debug(f'Could not call "udevadm control --reload": {str(e)}')
# reload systemd, as we might have changed service units, such as
# /run/systemd/system/systemd-networkd-wait-online.service.d/10-netplan.conf
# Skip it if --mapping is used as nothing will be generated
Expand Down
14 changes: 0 additions & 14 deletions src/generate.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ static GOptionEntry options[] = {
{NULL}
};

static void
reload_udevd(void)
{
const gchar *argv[] = { "/bin/udevadm", "control", "--reload", NULL };
g_spawn_sync(NULL, (gchar**)argv, NULL, G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, NULL, NULL, NULL, NULL);
};

/**
* Create enablement symlink for systemd-networkd.service.
*/
Expand Down Expand Up @@ -307,13 +300,6 @@ int main(int argc, char** argv)

CHECK_CALL(netplan_state_finish_nm_write(np_state, rootdir, &error), ignore_errors);
CHECK_CALL(netplan_state_finish_sriov_write(np_state, rootdir, &error), ignore_errors);
/* We may have written .rules & .link files, thus we must
* invalidate udevd cache of its config as by default it only
* invalidates cache at most every 3 seconds. Not sure if this
* should live in `generate' or `apply', but it is confusing
* when udevd ignores just-in-time created rules files.
*/
reload_udevd();
}

/* Disable /usr/lib/NetworkManager/conf.d/10-globally-managed-devices.conf
Expand Down

0 comments on commit ba807c4

Please sign in to comment.