mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-08-08 08:49:00 +00:00
devlink: extend reload command to add support for network namespace change
Extend existing devlink reload command by adding option "netns" by which user can instruct kernel to reload the devlink instance into specified network namespace. Example: $ ip netns add testns1 $ devlink dev reload netdevsim/netdevsim10 netns testns1 Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David Ahern <dsahern@kernel.org>
This commit is contained in:
parent
29993df876
commit
08e8e1ca3e
@ -261,6 +261,7 @@ static void ifname_map_free(struct ifname_map *ifname_map)
|
|||||||
#define DL_OPT_TRAP_NAME BIT(30)
|
#define DL_OPT_TRAP_NAME BIT(30)
|
||||||
#define DL_OPT_TRAP_ACTION BIT(31)
|
#define DL_OPT_TRAP_ACTION BIT(31)
|
||||||
#define DL_OPT_TRAP_GROUP_NAME BIT(32)
|
#define DL_OPT_TRAP_GROUP_NAME BIT(32)
|
||||||
|
#define DL_OPT_NETNS BIT(33)
|
||||||
|
|
||||||
struct dl_opts {
|
struct dl_opts {
|
||||||
uint64_t present; /* flags of present items */
|
uint64_t present; /* flags of present items */
|
||||||
@ -300,6 +301,8 @@ struct dl_opts {
|
|||||||
const char *trap_name;
|
const char *trap_name;
|
||||||
const char *trap_group_name;
|
const char *trap_group_name;
|
||||||
enum devlink_trap_action trap_action;
|
enum devlink_trap_action trap_action;
|
||||||
|
bool netns_is_pid;
|
||||||
|
uint32_t netns;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct dl {
|
struct dl {
|
||||||
@ -1440,6 +1443,22 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
|
|||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
o_found |= DL_OPT_TRAP_ACTION;
|
o_found |= DL_OPT_TRAP_ACTION;
|
||||||
|
} else if (dl_argv_match(dl, "netns") &&
|
||||||
|
(o_all & DL_OPT_NETNS)) {
|
||||||
|
const char *netns_str;
|
||||||
|
|
||||||
|
dl_arg_inc(dl);
|
||||||
|
err = dl_argv_str(dl, &netns_str);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
opts->netns = netns_get_fd(netns_str);
|
||||||
|
if (opts->netns < 0) {
|
||||||
|
err = dl_argv_uint32_t(dl, &opts->netns);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
opts->netns_is_pid = true;
|
||||||
|
}
|
||||||
|
o_found |= DL_OPT_NETNS;
|
||||||
} else {
|
} else {
|
||||||
pr_err("Unknown option \"%s\"\n", dl_argv(dl));
|
pr_err("Unknown option \"%s\"\n", dl_argv(dl));
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -1562,7 +1581,11 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
|
|||||||
if (opts->present & DL_OPT_TRAP_ACTION)
|
if (opts->present & DL_OPT_TRAP_ACTION)
|
||||||
mnl_attr_put_u8(nlh, DEVLINK_ATTR_TRAP_ACTION,
|
mnl_attr_put_u8(nlh, DEVLINK_ATTR_TRAP_ACTION,
|
||||||
opts->trap_action);
|
opts->trap_action);
|
||||||
|
if (opts->present & DL_OPT_NETNS)
|
||||||
|
mnl_attr_put_u32(nlh,
|
||||||
|
opts->netns_is_pid ? DEVLINK_ATTR_NETNS_PID :
|
||||||
|
DEVLINK_ATTR_NETNS_FD,
|
||||||
|
opts->netns);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl,
|
static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl,
|
||||||
@ -1623,7 +1646,7 @@ static void cmd_dev_help(void)
|
|||||||
pr_err(" devlink dev eswitch show DEV\n");
|
pr_err(" devlink dev eswitch show DEV\n");
|
||||||
pr_err(" devlink dev param set DEV name PARAMETER value VALUE cmode { permanent | driverinit | runtime }\n");
|
pr_err(" devlink dev param set DEV name PARAMETER value VALUE cmode { permanent | driverinit | runtime }\n");
|
||||||
pr_err(" devlink dev param show [DEV name PARAMETER]\n");
|
pr_err(" devlink dev param show [DEV name PARAMETER]\n");
|
||||||
pr_err(" devlink dev reload DEV\n");
|
pr_err(" devlink dev reload DEV [ netns { PID | NAME | ID } ]\n");
|
||||||
pr_err(" devlink dev info [ DEV ]\n");
|
pr_err(" devlink dev info [ DEV ]\n");
|
||||||
pr_err(" devlink dev flash DEV file PATH [ component NAME ]\n");
|
pr_err(" devlink dev flash DEV file PATH [ component NAME ]\n");
|
||||||
}
|
}
|
||||||
@ -2724,7 +2747,7 @@ static int cmd_dev_show(struct dl *dl)
|
|||||||
|
|
||||||
static void cmd_dev_reload_help(void)
|
static void cmd_dev_reload_help(void)
|
||||||
{
|
{
|
||||||
pr_err("Usage: devlink dev reload [ DEV ]\n");
|
pr_err("Usage: devlink dev reload DEV [ netns { PID | NAME | ID } ]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmd_dev_reload(struct dl *dl)
|
static int cmd_dev_reload(struct dl *dl)
|
||||||
@ -2740,7 +2763,7 @@ static int cmd_dev_reload(struct dl *dl)
|
|||||||
nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RELOAD,
|
nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RELOAD,
|
||||||
NLM_F_REQUEST | NLM_F_ACK);
|
NLM_F_REQUEST | NLM_F_ACK);
|
||||||
|
|
||||||
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0);
|
err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, DL_OPT_NETNS);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
@ -62,6 +62,9 @@ devlink-dev \- devlink device configuration
|
|||||||
.ti -8
|
.ti -8
|
||||||
.BR "devlink dev reload"
|
.BR "devlink dev reload"
|
||||||
.IR DEV
|
.IR DEV
|
||||||
|
.RI "[ "
|
||||||
|
.BI "netns { " PID " | " NAME " | " ID " }
|
||||||
|
.RI "]"
|
||||||
|
|
||||||
.ti -8
|
.ti -8
|
||||||
.BR "devlink dev info"
|
.BR "devlink dev info"
|
||||||
@ -167,6 +170,10 @@ If this argument is omitted all parameters supported by devlink devices are list
|
|||||||
.I "DEV"
|
.I "DEV"
|
||||||
- Specifies the devlink device to reload.
|
- Specifies the devlink device to reload.
|
||||||
|
|
||||||
|
.BR netns
|
||||||
|
.BI { " PID " | " NAME " | " ID " }
|
||||||
|
- Specifies the network namespace to reload into, either by pid, name or id.
|
||||||
|
|
||||||
.SS devlink dev info - display device information.
|
.SS devlink dev info - display device information.
|
||||||
Display device information provided by the driver. This command can be used
|
Display device information provided by the driver. This command can be used
|
||||||
to query versions of the hardware components or device components which
|
to query versions of the hardware components or device components which
|
||||||
|
Loading…
Reference in New Issue
Block a user