Skip to content

Commit 6ec8b6c

Browse files
Moshe Shemeshdavem330
Moshe Shemesh
authored andcommitted
devlink: Add health recover notifications on devlink flows
Devlink health recover notifications were added only on driver direct updates of health_state through devlink_health_reporter_state_update(). Add notifications on updates of health_state by devlink flows of report and recover. Moved functions devlink_nl_health_reporter_fill() and devlink_recover_notify() to avoid forward declaration. Fixes: 97ff3bd ("devlink: add devink notification when reporter update health state") Signed-off-by: Moshe Shemesh <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 53c6770 commit 6ec8b6c

File tree

1 file changed

+89
-87
lines changed

1 file changed

+89
-87
lines changed

Diff for: net/core/devlink.c

+89-87
Original file line numberDiff line numberDiff line change
@@ -4843,6 +4843,93 @@ devlink_health_reporter_destroy(struct devlink_health_reporter *reporter)
48434843
}
48444844
EXPORT_SYMBOL_GPL(devlink_health_reporter_destroy);
48454845

4846+
static int
4847+
devlink_nl_health_reporter_fill(struct sk_buff *msg,
4848+
struct devlink *devlink,
4849+
struct devlink_health_reporter *reporter,
4850+
enum devlink_command cmd, u32 portid,
4851+
u32 seq, int flags)
4852+
{
4853+
struct nlattr *reporter_attr;
4854+
void *hdr;
4855+
4856+
hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd);
4857+
if (!hdr)
4858+
return -EMSGSIZE;
4859+
4860+
if (devlink_nl_put_handle(msg, devlink))
4861+
goto genlmsg_cancel;
4862+
4863+
reporter_attr = nla_nest_start_noflag(msg,
4864+
DEVLINK_ATTR_HEALTH_REPORTER);
4865+
if (!reporter_attr)
4866+
goto genlmsg_cancel;
4867+
if (nla_put_string(msg, DEVLINK_ATTR_HEALTH_REPORTER_NAME,
4868+
reporter->ops->name))
4869+
goto reporter_nest_cancel;
4870+
if (nla_put_u8(msg, DEVLINK_ATTR_HEALTH_REPORTER_STATE,
4871+
reporter->health_state))
4872+
goto reporter_nest_cancel;
4873+
if (nla_put_u64_64bit(msg, DEVLINK_ATTR_HEALTH_REPORTER_ERR_COUNT,
4874+
reporter->error_count, DEVLINK_ATTR_PAD))
4875+
goto reporter_nest_cancel;
4876+
if (nla_put_u64_64bit(msg, DEVLINK_ATTR_HEALTH_REPORTER_RECOVER_COUNT,
4877+
reporter->recovery_count, DEVLINK_ATTR_PAD))
4878+
goto reporter_nest_cancel;
4879+
if (reporter->ops->recover &&
4880+
nla_put_u64_64bit(msg, DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD,
4881+
reporter->graceful_period,
4882+
DEVLINK_ATTR_PAD))
4883+
goto reporter_nest_cancel;
4884+
if (reporter->ops->recover &&
4885+
nla_put_u8(msg, DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER,
4886+
reporter->auto_recover))
4887+
goto reporter_nest_cancel;
4888+
if (reporter->dump_fmsg &&
4889+
nla_put_u64_64bit(msg, DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS,
4890+
jiffies_to_msecs(reporter->dump_ts),
4891+
DEVLINK_ATTR_PAD))
4892+
goto reporter_nest_cancel;
4893+
if (reporter->dump_fmsg &&
4894+
nla_put_u64_64bit(msg, DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS_NS,
4895+
reporter->dump_real_ts, DEVLINK_ATTR_PAD))
4896+
goto reporter_nest_cancel;
4897+
4898+
nla_nest_end(msg, reporter_attr);
4899+
genlmsg_end(msg, hdr);
4900+
return 0;
4901+
4902+
reporter_nest_cancel:
4903+
nla_nest_end(msg, reporter_attr);
4904+
genlmsg_cancel:
4905+
genlmsg_cancel(msg, hdr);
4906+
return -EMSGSIZE;
4907+
}
4908+
4909+
static void devlink_recover_notify(struct devlink_health_reporter *reporter,
4910+
enum devlink_command cmd)
4911+
{
4912+
struct sk_buff *msg;
4913+
int err;
4914+
4915+
WARN_ON(cmd != DEVLINK_CMD_HEALTH_REPORTER_RECOVER);
4916+
4917+
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4918+
if (!msg)
4919+
return;
4920+
4921+
err = devlink_nl_health_reporter_fill(msg, reporter->devlink,
4922+
reporter, cmd, 0, 0, 0);
4923+
if (err) {
4924+
nlmsg_free(msg);
4925+
return;
4926+
}
4927+
4928+
genlmsg_multicast_netns(&devlink_nl_family,
4929+
devlink_net(reporter->devlink),
4930+
msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL);
4931+
}
4932+
48464933
void
48474934
devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter)
48484935
{
@@ -4869,6 +4956,7 @@ devlink_health_reporter_recover(struct devlink_health_reporter *reporter,
48694956

48704957
devlink_health_reporter_recovery_done(reporter);
48714958
reporter->health_state = DEVLINK_HEALTH_REPORTER_STATE_HEALTHY;
4959+
devlink_recover_notify(reporter, DEVLINK_CMD_HEALTH_REPORTER_RECOVER);
48724960

48734961
return 0;
48744962
}
@@ -4935,6 +5023,7 @@ int devlink_health_report(struct devlink_health_reporter *reporter,
49355023
reporter->error_count++;
49365024
prev_health_state = reporter->health_state;
49375025
reporter->health_state = DEVLINK_HEALTH_REPORTER_STATE_ERROR;
5026+
devlink_recover_notify(reporter, DEVLINK_CMD_HEALTH_REPORTER_RECOVER);
49385027

49395028
/* abort if the previous error wasn't recovered */
49405029
if (reporter->auto_recover &&
@@ -5017,93 +5106,6 @@ devlink_health_reporter_put(struct devlink_health_reporter *reporter)
50175106
refcount_dec(&reporter->refcount);
50185107
}
50195108

5020-
static int
5021-
devlink_nl_health_reporter_fill(struct sk_buff *msg,
5022-
struct devlink *devlink,
5023-
struct devlink_health_reporter *reporter,
5024-
enum devlink_command cmd, u32 portid,
5025-
u32 seq, int flags)
5026-
{
5027-
struct nlattr *reporter_attr;
5028-
void *hdr;
5029-
5030-
hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd);
5031-
if (!hdr)
5032-
return -EMSGSIZE;
5033-
5034-
if (devlink_nl_put_handle(msg, devlink))
5035-
goto genlmsg_cancel;
5036-
5037-
reporter_attr = nla_nest_start_noflag(msg,
5038-
DEVLINK_ATTR_HEALTH_REPORTER);
5039-
if (!reporter_attr)
5040-
goto genlmsg_cancel;
5041-
if (nla_put_string(msg, DEVLINK_ATTR_HEALTH_REPORTER_NAME,
5042-
reporter->ops->name))
5043-
goto reporter_nest_cancel;
5044-
if (nla_put_u8(msg, DEVLINK_ATTR_HEALTH_REPORTER_STATE,
5045-
reporter->health_state))
5046-
goto reporter_nest_cancel;
5047-
if (nla_put_u64_64bit(msg, DEVLINK_ATTR_HEALTH_REPORTER_ERR_COUNT,
5048-
reporter->error_count, DEVLINK_ATTR_PAD))
5049-
goto reporter_nest_cancel;
5050-
if (nla_put_u64_64bit(msg, DEVLINK_ATTR_HEALTH_REPORTER_RECOVER_COUNT,
5051-
reporter->recovery_count, DEVLINK_ATTR_PAD))
5052-
goto reporter_nest_cancel;
5053-
if (reporter->ops->recover &&
5054-
nla_put_u64_64bit(msg, DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD,
5055-
reporter->graceful_period,
5056-
DEVLINK_ATTR_PAD))
5057-
goto reporter_nest_cancel;
5058-
if (reporter->ops->recover &&
5059-
nla_put_u8(msg, DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER,
5060-
reporter->auto_recover))
5061-
goto reporter_nest_cancel;
5062-
if (reporter->dump_fmsg &&
5063-
nla_put_u64_64bit(msg, DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS,
5064-
jiffies_to_msecs(reporter->dump_ts),
5065-
DEVLINK_ATTR_PAD))
5066-
goto reporter_nest_cancel;
5067-
if (reporter->dump_fmsg &&
5068-
nla_put_u64_64bit(msg, DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS_NS,
5069-
reporter->dump_real_ts, DEVLINK_ATTR_PAD))
5070-
goto reporter_nest_cancel;
5071-
5072-
nla_nest_end(msg, reporter_attr);
5073-
genlmsg_end(msg, hdr);
5074-
return 0;
5075-
5076-
reporter_nest_cancel:
5077-
nla_nest_end(msg, reporter_attr);
5078-
genlmsg_cancel:
5079-
genlmsg_cancel(msg, hdr);
5080-
return -EMSGSIZE;
5081-
}
5082-
5083-
static void devlink_recover_notify(struct devlink_health_reporter *reporter,
5084-
enum devlink_command cmd)
5085-
{
5086-
struct sk_buff *msg;
5087-
int err;
5088-
5089-
WARN_ON(cmd != DEVLINK_CMD_HEALTH_REPORTER_RECOVER);
5090-
5091-
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5092-
if (!msg)
5093-
return;
5094-
5095-
err = devlink_nl_health_reporter_fill(msg, reporter->devlink,
5096-
reporter, cmd, 0, 0, 0);
5097-
if (err) {
5098-
nlmsg_free(msg);
5099-
return;
5100-
}
5101-
5102-
genlmsg_multicast_netns(&devlink_nl_family,
5103-
devlink_net(reporter->devlink),
5104-
msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL);
5105-
}
5106-
51075109
void
51085110
devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
51095111
enum devlink_health_reporter_state state)

0 commit comments

Comments
 (0)