networkctl: introduce "persistent-storage" command

Then, this introduces systemd-networkd-persistent-storage.service.

systemd-networkd.service is an early starting service. So, at the time
it is started, the persistent storage for the service may not be ready,
and we cannot use StateDirectory=systemd/network in
systemd-networkd.service.

The newly added systemd-networkd-persistent-storage.service creates the
state directory for networkd, and notify systemd-networkd that the
directory is usable.
This commit is contained in:
Yu Watanabe
2024-03-12 01:57:16 +09:00
parent f90eb08627
commit 91676b6458
6 changed files with 86 additions and 18 deletions
+36 -15
View File
@@ -2929,6 +2929,24 @@ static int verb_reconfigure(int argc, char *argv[], void *userdata) {
return 0;
}
static int verb_persistent_storage(int argc, char *argv[], void *userdata) {
_cleanup_(varlink_unrefp) Varlink *vl = NULL;
bool ready;
int r;
r = parse_boolean(argv[1]);
if (r < 0)
return log_error_errno(r, "Failed to parse argument: %s", argv[1]);
ready = r;
r = varlink_connect_networkd(&vl);
if (r < 0)
return r;
return varlink_callb_and_log(vl, "io.systemd.Network.SetPersistentStorage", /* reply = */ NULL,
JSON_BUILD_OBJECT(JSON_BUILD_PAIR_BOOLEAN("Ready", ready)));
}
static int help(void) {
_cleanup_free_ char *link = NULL;
int r;
@@ -2955,6 +2973,8 @@ static int help(void) {
" cat FILES|DEVICES... Show network configuration files\n"
" mask FILES... Mask network configuration files\n"
" unmask FILES... Unmask network configuration files\n"
" persistent-storage BOOL\n"
" Notify systemd-networkd if persistent storage is ready\n"
"\nOptions:\n"
" -h --help Show this help\n"
" --version Show package version\n"
@@ -3098,21 +3118,22 @@ static int parse_argv(int argc, char *argv[]) {
static int networkctl_main(int argc, char *argv[]) {
static const Verb verbs[] = {
{ "list", VERB_ANY, VERB_ANY, VERB_DEFAULT|VERB_ONLINE_ONLY, list_links },
{ "status", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, link_status },
{ "lldp", VERB_ANY, VERB_ANY, 0, link_lldp_status },
{ "label", 1, 1, 0, list_address_labels },
{ "delete", 2, VERB_ANY, 0, link_delete },
{ "up", 2, VERB_ANY, 0, link_up_down },
{ "down", 2, VERB_ANY, 0, link_up_down },
{ "renew", 2, VERB_ANY, VERB_ONLINE_ONLY, link_renew },
{ "forcerenew", 2, VERB_ANY, VERB_ONLINE_ONLY, link_force_renew },
{ "reconfigure", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_reconfigure },
{ "reload", 1, 1, VERB_ONLINE_ONLY, verb_reload },
{ "edit", 2, VERB_ANY, 0, verb_edit },
{ "cat", 2, VERB_ANY, 0, verb_cat },
{ "mask", 2, VERB_ANY, 0, verb_mask },
{ "unmask", 2, VERB_ANY, 0, verb_unmask },
{ "list", VERB_ANY, VERB_ANY, VERB_DEFAULT|VERB_ONLINE_ONLY, list_links },
{ "status", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, link_status },
{ "lldp", VERB_ANY, VERB_ANY, 0, link_lldp_status },
{ "label", 1, 1, 0, list_address_labels },
{ "delete", 2, VERB_ANY, 0, link_delete },
{ "up", 2, VERB_ANY, 0, link_up_down },
{ "down", 2, VERB_ANY, 0, link_up_down },
{ "renew", 2, VERB_ANY, VERB_ONLINE_ONLY, link_renew },
{ "forcerenew", 2, VERB_ANY, VERB_ONLINE_ONLY, link_force_renew },
{ "reconfigure", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_reconfigure },
{ "reload", 1, 1, VERB_ONLINE_ONLY, verb_reload },
{ "edit", 2, VERB_ANY, 0, verb_edit },
{ "cat", 2, VERB_ANY, 0, verb_cat },
{ "mask", 2, VERB_ANY, 0, verb_mask },
{ "unmask", 2, VERB_ANY, 0, verb_unmask },
{ "persistent-storage", 2, 2, 0, verb_persistent_storage },
{}
};