#include <limits.h>
#include <errno.h>
#include <inttypes.h>
+#include <signal.h>
+#include <time.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
#include <sys/sysinfo.h>
#define _LINUX_SYSINFO_H /* avoid collision with musl header */
#include <linux/genetlink.h>
#include <linux/devlink.h>
+#include <linux/netlink.h>
#include <libmnl/libmnl.h>
#include <netinet/ether.h>
+#include <sys/select.h>
+#include <sys/socket.h>
#include <sys/types.h>
#include "SNAPSHOT.h"
#include "list.h"
#include "mnlg.h"
-#include "json_writer.h"
+#include "json_print.h"
#include "utils.h"
#include "namespace.h"
#define DL_OPT_TRAP_POLICER_ID BIT(34)
#define DL_OPT_TRAP_POLICER_RATE BIT(35)
#define DL_OPT_TRAP_POLICER_BURST BIT(36)
+#define DL_OPT_HEALTH_REPORTER_AUTO_DUMP BIT(37)
struct dl_opts {
uint64_t present; /* flags of present items */
const char *reporter_name;
uint64_t reporter_graceful_period;
bool reporter_auto_recover;
+ bool reporter_auto_dump;
const char *trap_name;
const char *trap_group_name;
enum devlink_trap_action trap_action;
if (err)
return err;
o_found |= DL_OPT_HEALTH_REPORTER_AUTO_RECOVER;
+ } else if (dl_argv_match(dl, "auto_dump") &&
+ (o_all & DL_OPT_HEALTH_REPORTER_AUTO_DUMP)) {
+ dl_arg_inc(dl);
+ err = dl_argv_bool(dl, &opts->reporter_auto_dump);
+ if (err)
+ return err;
+ o_found |= DL_OPT_HEALTH_REPORTER_AUTO_DUMP;
} else if (dl_argv_match(dl, "trap") &&
(o_all & DL_OPT_TRAP_NAME)) {
dl_arg_inc(dl);
if (opts->present & DL_OPT_HEALTH_REPORTER_AUTO_RECOVER)
mnl_attr_put_u8(nlh, DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER,
opts->reporter_auto_recover);
+ if (opts->present & DL_OPT_HEALTH_REPORTER_AUTO_DUMP)
+ mnl_attr_put_u8(nlh, DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP,
+ opts->reporter_auto_dump);
if (opts->present & DL_OPT_TRAP_NAME)
mnl_attr_put_strz(nlh, DEVLINK_ATTR_TRAP_NAME,
opts->trap_name);
return err;
}
+static int cmd_region_snapshot_new_cb(const struct nlmsghdr *nlh, void *data)
+{
+ struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
+ struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
+ struct dl *dl = data;
+
+ mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
+ if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
+ !tb[DEVLINK_ATTR_REGION_NAME] ||
+ !tb[DEVLINK_ATTR_REGION_SNAPSHOT_ID])
+ return MNL_CB_ERROR;
+
+ pr_out_region(dl, tb);
+
+ return MNL_CB_OK;
+}
+
+static int cmd_region_snapshot_new(struct dl *dl)
+{
+ struct nlmsghdr *nlh;
+ int err;
+
+ nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_REGION_NEW,
+ NLM_F_REQUEST | NLM_F_ACK);
+
+ err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE_REGION,
+ DL_OPT_REGION_SNAPSHOT_ID);
+ if (err)
+ return err;
+
+ pr_out_section_start(dl, "regions");
+ err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_region_snapshot_new_cb, dl);
+ pr_out_section_end(dl);
+ return err;
+}
+
static void cmd_region_help(void)
{
pr_err("Usage: devlink region show [ DEV/REGION ]\n");
pr_err(" devlink region del DEV/REGION snapshot SNAPSHOT_ID\n");
+ pr_err(" devlink region new DEV/REGION snapshot SNAPSHOT_ID\n");
pr_err(" devlink region dump DEV/REGION [ snapshot SNAPSHOT_ID ]\n");
pr_err(" devlink region read DEV/REGION [ snapshot SNAPSHOT_ID ] address ADDRESS length LENGTH\n");
}
} else if (dl_argv_match(dl, "read")) {
dl_arg_inc(dl);
return cmd_region_read(dl);
+ } else if (dl_argv_match(dl, "new")) {
+ dl_arg_inc(dl);
+ return cmd_region_snapshot_new(dl);
}
pr_err("Command \"%s\" not found\n", dl_argv(dl));
return -ENOENT;
NLM_F_REQUEST | NLM_F_ACK);
err = dl_argv_parse(dl, DL_OPT_HANDLE | DL_OPT_HEALTH_REPORTER_NAME,
DL_OPT_HEALTH_REPORTER_GRACEFUL_PERIOD |
- DL_OPT_HEALTH_REPORTER_AUTO_RECOVER);
+ DL_OPT_HEALTH_REPORTER_AUTO_RECOVER |
+ DL_OPT_HEALTH_REPORTER_AUTO_DUMP);
if (err)
return err;
if (tb[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER])
print_bool(PRINT_ANY, "auto_recover", " auto_recover %s",
mnl_attr_get_u8(tb[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER]));
+ if (tb[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP])
+ print_bool(PRINT_ANY, "auto_dump", " auto_dump %s",
+ mnl_attr_get_u8(tb[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP]));
__pr_out_indent_dec();
pr_out_handle_end(dl);
pr_err(" devlink health set DEV reporter REPORTER_NAME\n");
pr_err(" [ grace_period MSEC ]\n");
pr_err(" [ auto_recover { true | false } ]\n");
+ pr_err(" [ auto_dump { true | false } ]\n");
}
static int cmd_health(struct dl *dl)