health.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (c) 2016 Mellanox Technologies. All rights reserved.
  4. * Copyright (c) 2016 Jiri Pirko <jiri@mellanox.com>
  5. */
  6. #include <net/genetlink.h>
  7. #include <net/sock.h>
  8. #include <trace/events/devlink.h>
  9. #include "devl_internal.h"
  10. struct devlink_fmsg_item {
  11. struct list_head list;
  12. int attrtype;
  13. u8 nla_type;
  14. u16 len;
  15. int value[];
  16. };
  17. struct devlink_fmsg {
  18. struct list_head item_list;
  19. int err; /* first error encountered on some devlink_fmsg_XXX() call */
  20. bool putting_binary; /* This flag forces enclosing of binary data
  21. * in an array brackets. It forces using
  22. * of designated API:
  23. * devlink_fmsg_binary_pair_nest_start()
  24. * devlink_fmsg_binary_pair_nest_end()
  25. */
  26. };
  27. static struct devlink_fmsg *devlink_fmsg_alloc(void)
  28. {
  29. struct devlink_fmsg *fmsg;
  30. fmsg = kzalloc(sizeof(*fmsg), GFP_KERNEL);
  31. if (!fmsg)
  32. return NULL;
  33. INIT_LIST_HEAD(&fmsg->item_list);
  34. return fmsg;
  35. }
  36. static void devlink_fmsg_free(struct devlink_fmsg *fmsg)
  37. {
  38. struct devlink_fmsg_item *item, *tmp;
  39. list_for_each_entry_safe(item, tmp, &fmsg->item_list, list) {
  40. list_del(&item->list);
  41. kfree(item);
  42. }
  43. kfree(fmsg);
  44. }
  45. struct devlink_health_reporter {
  46. struct list_head list;
  47. void *priv;
  48. const struct devlink_health_reporter_ops *ops;
  49. struct devlink *devlink;
  50. struct devlink_port *devlink_port;
  51. struct devlink_fmsg *dump_fmsg;
  52. u64 graceful_period;
  53. bool auto_recover;
  54. bool auto_dump;
  55. u8 health_state;
  56. u64 dump_ts;
  57. u64 dump_real_ts;
  58. u64 error_count;
  59. u64 recovery_count;
  60. u64 last_recovery_ts;
  61. };
  62. void *
  63. devlink_health_reporter_priv(struct devlink_health_reporter *reporter)
  64. {
  65. return reporter->priv;
  66. }
  67. EXPORT_SYMBOL_GPL(devlink_health_reporter_priv);
  68. static struct devlink_health_reporter *
  69. __devlink_health_reporter_find_by_name(struct list_head *reporter_list,
  70. const char *reporter_name)
  71. {
  72. struct devlink_health_reporter *reporter;
  73. list_for_each_entry(reporter, reporter_list, list)
  74. if (!strcmp(reporter->ops->name, reporter_name))
  75. return reporter;
  76. return NULL;
  77. }
  78. static struct devlink_health_reporter *
  79. devlink_health_reporter_find_by_name(struct devlink *devlink,
  80. const char *reporter_name)
  81. {
  82. return __devlink_health_reporter_find_by_name(&devlink->reporter_list,
  83. reporter_name);
  84. }
  85. static struct devlink_health_reporter *
  86. devlink_port_health_reporter_find_by_name(struct devlink_port *devlink_port,
  87. const char *reporter_name)
  88. {
  89. return __devlink_health_reporter_find_by_name(&devlink_port->reporter_list,
  90. reporter_name);
  91. }
  92. static struct devlink_health_reporter *
  93. __devlink_health_reporter_create(struct devlink *devlink,
  94. const struct devlink_health_reporter_ops *ops,
  95. u64 graceful_period, void *priv)
  96. {
  97. struct devlink_health_reporter *reporter;
  98. if (WARN_ON(graceful_period && !ops->recover))
  99. return ERR_PTR(-EINVAL);
  100. reporter = kzalloc(sizeof(*reporter), GFP_KERNEL);
  101. if (!reporter)
  102. return ERR_PTR(-ENOMEM);
  103. reporter->priv = priv;
  104. reporter->ops = ops;
  105. reporter->devlink = devlink;
  106. reporter->graceful_period = graceful_period;
  107. reporter->auto_recover = !!ops->recover;
  108. reporter->auto_dump = !!ops->dump;
  109. return reporter;
  110. }
  111. /**
  112. * devl_port_health_reporter_create() - create devlink health reporter for
  113. * specified port instance
  114. *
  115. * @port: devlink_port to which health reports will relate
  116. * @ops: devlink health reporter ops
  117. * @graceful_period: min time (in msec) between recovery attempts
  118. * @priv: driver priv pointer
  119. */
  120. struct devlink_health_reporter *
  121. devl_port_health_reporter_create(struct devlink_port *port,
  122. const struct devlink_health_reporter_ops *ops,
  123. u64 graceful_period, void *priv)
  124. {
  125. struct devlink_health_reporter *reporter;
  126. devl_assert_locked(port->devlink);
  127. if (__devlink_health_reporter_find_by_name(&port->reporter_list,
  128. ops->name))
  129. return ERR_PTR(-EEXIST);
  130. reporter = __devlink_health_reporter_create(port->devlink, ops,
  131. graceful_period, priv);
  132. if (IS_ERR(reporter))
  133. return reporter;
  134. reporter->devlink_port = port;
  135. list_add_tail(&reporter->list, &port->reporter_list);
  136. return reporter;
  137. }
  138. EXPORT_SYMBOL_GPL(devl_port_health_reporter_create);
  139. struct devlink_health_reporter *
  140. devlink_port_health_reporter_create(struct devlink_port *port,
  141. const struct devlink_health_reporter_ops *ops,
  142. u64 graceful_period, void *priv)
  143. {
  144. struct devlink_health_reporter *reporter;
  145. struct devlink *devlink = port->devlink;
  146. devl_lock(devlink);
  147. reporter = devl_port_health_reporter_create(port, ops,
  148. graceful_period, priv);
  149. devl_unlock(devlink);
  150. return reporter;
  151. }
  152. EXPORT_SYMBOL_GPL(devlink_port_health_reporter_create);
  153. /**
  154. * devl_health_reporter_create - create devlink health reporter
  155. *
  156. * @devlink: devlink instance which the health reports will relate
  157. * @ops: devlink health reporter ops
  158. * @graceful_period: min time (in msec) between recovery attempts
  159. * @priv: driver priv pointer
  160. */
  161. struct devlink_health_reporter *
  162. devl_health_reporter_create(struct devlink *devlink,
  163. const struct devlink_health_reporter_ops *ops,
  164. u64 graceful_period, void *priv)
  165. {
  166. struct devlink_health_reporter *reporter;
  167. devl_assert_locked(devlink);
  168. if (devlink_health_reporter_find_by_name(devlink, ops->name))
  169. return ERR_PTR(-EEXIST);
  170. reporter = __devlink_health_reporter_create(devlink, ops,
  171. graceful_period, priv);
  172. if (IS_ERR(reporter))
  173. return reporter;
  174. list_add_tail(&reporter->list, &devlink->reporter_list);
  175. return reporter;
  176. }
  177. EXPORT_SYMBOL_GPL(devl_health_reporter_create);
  178. struct devlink_health_reporter *
  179. devlink_health_reporter_create(struct devlink *devlink,
  180. const struct devlink_health_reporter_ops *ops,
  181. u64 graceful_period, void *priv)
  182. {
  183. struct devlink_health_reporter *reporter;
  184. devl_lock(devlink);
  185. reporter = devl_health_reporter_create(devlink, ops,
  186. graceful_period, priv);
  187. devl_unlock(devlink);
  188. return reporter;
  189. }
  190. EXPORT_SYMBOL_GPL(devlink_health_reporter_create);
  191. static void
  192. devlink_health_reporter_free(struct devlink_health_reporter *reporter)
  193. {
  194. if (reporter->dump_fmsg)
  195. devlink_fmsg_free(reporter->dump_fmsg);
  196. kfree(reporter);
  197. }
  198. /**
  199. * devl_health_reporter_destroy() - destroy devlink health reporter
  200. *
  201. * @reporter: devlink health reporter to destroy
  202. */
  203. void
  204. devl_health_reporter_destroy(struct devlink_health_reporter *reporter)
  205. {
  206. devl_assert_locked(reporter->devlink);
  207. list_del(&reporter->list);
  208. devlink_health_reporter_free(reporter);
  209. }
  210. EXPORT_SYMBOL_GPL(devl_health_reporter_destroy);
  211. void
  212. devlink_health_reporter_destroy(struct devlink_health_reporter *reporter)
  213. {
  214. struct devlink *devlink = reporter->devlink;
  215. devl_lock(devlink);
  216. devl_health_reporter_destroy(reporter);
  217. devl_unlock(devlink);
  218. }
  219. EXPORT_SYMBOL_GPL(devlink_health_reporter_destroy);
  220. static int
  221. devlink_nl_health_reporter_fill(struct sk_buff *msg,
  222. struct devlink_health_reporter *reporter,
  223. enum devlink_command cmd, u32 portid,
  224. u32 seq, int flags)
  225. {
  226. struct devlink *devlink = reporter->devlink;
  227. struct nlattr *reporter_attr;
  228. void *hdr;
  229. hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd);
  230. if (!hdr)
  231. return -EMSGSIZE;
  232. if (devlink_nl_put_handle(msg, devlink))
  233. goto genlmsg_cancel;
  234. if (reporter->devlink_port) {
  235. if (nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX, reporter->devlink_port->index))
  236. goto genlmsg_cancel;
  237. }
  238. reporter_attr = nla_nest_start_noflag(msg,
  239. DEVLINK_ATTR_HEALTH_REPORTER);
  240. if (!reporter_attr)
  241. goto genlmsg_cancel;
  242. if (nla_put_string(msg, DEVLINK_ATTR_HEALTH_REPORTER_NAME,
  243. reporter->ops->name))
  244. goto reporter_nest_cancel;
  245. if (nla_put_u8(msg, DEVLINK_ATTR_HEALTH_REPORTER_STATE,
  246. reporter->health_state))
  247. goto reporter_nest_cancel;
  248. if (nla_put_u64_64bit(msg, DEVLINK_ATTR_HEALTH_REPORTER_ERR_COUNT,
  249. reporter->error_count, DEVLINK_ATTR_PAD))
  250. goto reporter_nest_cancel;
  251. if (nla_put_u64_64bit(msg, DEVLINK_ATTR_HEALTH_REPORTER_RECOVER_COUNT,
  252. reporter->recovery_count, DEVLINK_ATTR_PAD))
  253. goto reporter_nest_cancel;
  254. if (reporter->ops->recover &&
  255. nla_put_u64_64bit(msg, DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD,
  256. reporter->graceful_period,
  257. DEVLINK_ATTR_PAD))
  258. goto reporter_nest_cancel;
  259. if (reporter->ops->recover &&
  260. nla_put_u8(msg, DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER,
  261. reporter->auto_recover))
  262. goto reporter_nest_cancel;
  263. if (reporter->dump_fmsg &&
  264. nla_put_u64_64bit(msg, DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS,
  265. jiffies_to_msecs(reporter->dump_ts),
  266. DEVLINK_ATTR_PAD))
  267. goto reporter_nest_cancel;
  268. if (reporter->dump_fmsg &&
  269. nla_put_u64_64bit(msg, DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS_NS,
  270. reporter->dump_real_ts, DEVLINK_ATTR_PAD))
  271. goto reporter_nest_cancel;
  272. if (reporter->ops->dump &&
  273. nla_put_u8(msg, DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP,
  274. reporter->auto_dump))
  275. goto reporter_nest_cancel;
  276. nla_nest_end(msg, reporter_attr);
  277. genlmsg_end(msg, hdr);
  278. return 0;
  279. reporter_nest_cancel:
  280. nla_nest_cancel(msg, reporter_attr);
  281. genlmsg_cancel:
  282. genlmsg_cancel(msg, hdr);
  283. return -EMSGSIZE;
  284. }
  285. static struct devlink_health_reporter *
  286. devlink_health_reporter_get_from_attrs(struct devlink *devlink,
  287. struct nlattr **attrs)
  288. {
  289. struct devlink_port *devlink_port;
  290. char *reporter_name;
  291. if (!attrs[DEVLINK_ATTR_HEALTH_REPORTER_NAME])
  292. return NULL;
  293. reporter_name = nla_data(attrs[DEVLINK_ATTR_HEALTH_REPORTER_NAME]);
  294. devlink_port = devlink_port_get_from_attrs(devlink, attrs);
  295. if (IS_ERR(devlink_port))
  296. return devlink_health_reporter_find_by_name(devlink,
  297. reporter_name);
  298. else
  299. return devlink_port_health_reporter_find_by_name(devlink_port,
  300. reporter_name);
  301. }
  302. static struct devlink_health_reporter *
  303. devlink_health_reporter_get_from_info(struct devlink *devlink,
  304. struct genl_info *info)
  305. {
  306. return devlink_health_reporter_get_from_attrs(devlink, info->attrs);
  307. }
  308. int devlink_nl_health_reporter_get_doit(struct sk_buff *skb,
  309. struct genl_info *info)
  310. {
  311. struct devlink *devlink = info->user_ptr[0];
  312. struct devlink_health_reporter *reporter;
  313. struct sk_buff *msg;
  314. int err;
  315. reporter = devlink_health_reporter_get_from_info(devlink, info);
  316. if (!reporter)
  317. return -EINVAL;
  318. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  319. if (!msg)
  320. return -ENOMEM;
  321. err = devlink_nl_health_reporter_fill(msg, reporter,
  322. DEVLINK_CMD_HEALTH_REPORTER_GET,
  323. info->snd_portid, info->snd_seq,
  324. 0);
  325. if (err) {
  326. nlmsg_free(msg);
  327. return err;
  328. }
  329. return genlmsg_reply(msg, info);
  330. }
  331. static int devlink_nl_health_reporter_get_dump_one(struct sk_buff *msg,
  332. struct devlink *devlink,
  333. struct netlink_callback *cb,
  334. int flags)
  335. {
  336. struct devlink_nl_dump_state *state = devlink_dump_state(cb);
  337. const struct genl_info *info = genl_info_dump(cb);
  338. struct devlink_health_reporter *reporter;
  339. unsigned long port_index_end = ULONG_MAX;
  340. struct nlattr **attrs = info->attrs;
  341. unsigned long port_index_start = 0;
  342. struct devlink_port *port;
  343. unsigned long port_index;
  344. int idx = 0;
  345. int err;
  346. if (attrs && attrs[DEVLINK_ATTR_PORT_INDEX]) {
  347. port_index_start = nla_get_u32(attrs[DEVLINK_ATTR_PORT_INDEX]);
  348. port_index_end = port_index_start;
  349. flags |= NLM_F_DUMP_FILTERED;
  350. goto per_port_dump;
  351. }
  352. list_for_each_entry(reporter, &devlink->reporter_list, list) {
  353. if (idx < state->idx) {
  354. idx++;
  355. continue;
  356. }
  357. err = devlink_nl_health_reporter_fill(msg, reporter,
  358. DEVLINK_CMD_HEALTH_REPORTER_GET,
  359. NETLINK_CB(cb->skb).portid,
  360. cb->nlh->nlmsg_seq,
  361. flags);
  362. if (err) {
  363. state->idx = idx;
  364. return err;
  365. }
  366. idx++;
  367. }
  368. per_port_dump:
  369. xa_for_each_range(&devlink->ports, port_index, port,
  370. port_index_start, port_index_end) {
  371. list_for_each_entry(reporter, &port->reporter_list, list) {
  372. if (idx < state->idx) {
  373. idx++;
  374. continue;
  375. }
  376. err = devlink_nl_health_reporter_fill(msg, reporter,
  377. DEVLINK_CMD_HEALTH_REPORTER_GET,
  378. NETLINK_CB(cb->skb).portid,
  379. cb->nlh->nlmsg_seq,
  380. flags);
  381. if (err) {
  382. state->idx = idx;
  383. return err;
  384. }
  385. idx++;
  386. }
  387. }
  388. return 0;
  389. }
  390. int devlink_nl_health_reporter_get_dumpit(struct sk_buff *skb,
  391. struct netlink_callback *cb)
  392. {
  393. return devlink_nl_dumpit(skb, cb,
  394. devlink_nl_health_reporter_get_dump_one);
  395. }
  396. int devlink_nl_health_reporter_set_doit(struct sk_buff *skb,
  397. struct genl_info *info)
  398. {
  399. struct devlink *devlink = info->user_ptr[0];
  400. struct devlink_health_reporter *reporter;
  401. reporter = devlink_health_reporter_get_from_info(devlink, info);
  402. if (!reporter)
  403. return -EINVAL;
  404. if (!reporter->ops->recover &&
  405. (info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD] ||
  406. info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER]))
  407. return -EOPNOTSUPP;
  408. if (!reporter->ops->dump &&
  409. info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP])
  410. return -EOPNOTSUPP;
  411. if (info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD])
  412. reporter->graceful_period =
  413. nla_get_u64(info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD]);
  414. if (info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER])
  415. reporter->auto_recover =
  416. nla_get_u8(info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER]);
  417. if (info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP])
  418. reporter->auto_dump =
  419. nla_get_u8(info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP]);
  420. return 0;
  421. }
  422. static void devlink_recover_notify(struct devlink_health_reporter *reporter,
  423. enum devlink_command cmd)
  424. {
  425. struct devlink *devlink = reporter->devlink;
  426. struct devlink_obj_desc desc;
  427. struct sk_buff *msg;
  428. int err;
  429. WARN_ON(cmd != DEVLINK_CMD_HEALTH_REPORTER_RECOVER);
  430. ASSERT_DEVLINK_REGISTERED(devlink);
  431. if (!devlink_nl_notify_need(devlink))
  432. return;
  433. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  434. if (!msg)
  435. return;
  436. err = devlink_nl_health_reporter_fill(msg, reporter, cmd, 0, 0, 0);
  437. if (err) {
  438. nlmsg_free(msg);
  439. return;
  440. }
  441. devlink_nl_obj_desc_init(&desc, devlink);
  442. if (reporter->devlink_port)
  443. devlink_nl_obj_desc_port_set(&desc, reporter->devlink_port);
  444. devlink_nl_notify_send_desc(devlink, msg, &desc);
  445. }
  446. void
  447. devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter)
  448. {
  449. reporter->recovery_count++;
  450. reporter->last_recovery_ts = jiffies;
  451. }
  452. EXPORT_SYMBOL_GPL(devlink_health_reporter_recovery_done);
  453. static int
  454. devlink_health_reporter_recover(struct devlink_health_reporter *reporter,
  455. void *priv_ctx, struct netlink_ext_ack *extack)
  456. {
  457. int err;
  458. if (reporter->health_state == DEVLINK_HEALTH_REPORTER_STATE_HEALTHY)
  459. return 0;
  460. if (!reporter->ops->recover)
  461. return -EOPNOTSUPP;
  462. err = reporter->ops->recover(reporter, priv_ctx, extack);
  463. if (err)
  464. return err;
  465. devlink_health_reporter_recovery_done(reporter);
  466. reporter->health_state = DEVLINK_HEALTH_REPORTER_STATE_HEALTHY;
  467. devlink_recover_notify(reporter, DEVLINK_CMD_HEALTH_REPORTER_RECOVER);
  468. return 0;
  469. }
  470. static void
  471. devlink_health_dump_clear(struct devlink_health_reporter *reporter)
  472. {
  473. if (!reporter->dump_fmsg)
  474. return;
  475. devlink_fmsg_free(reporter->dump_fmsg);
  476. reporter->dump_fmsg = NULL;
  477. }
  478. static int devlink_health_do_dump(struct devlink_health_reporter *reporter,
  479. void *priv_ctx,
  480. struct netlink_ext_ack *extack)
  481. {
  482. int err;
  483. if (!reporter->ops->dump)
  484. return 0;
  485. if (reporter->dump_fmsg)
  486. return 0;
  487. reporter->dump_fmsg = devlink_fmsg_alloc();
  488. if (!reporter->dump_fmsg)
  489. return -ENOMEM;
  490. devlink_fmsg_obj_nest_start(reporter->dump_fmsg);
  491. err = reporter->ops->dump(reporter, reporter->dump_fmsg,
  492. priv_ctx, extack);
  493. if (err)
  494. goto dump_err;
  495. devlink_fmsg_obj_nest_end(reporter->dump_fmsg);
  496. err = reporter->dump_fmsg->err;
  497. if (err)
  498. goto dump_err;
  499. reporter->dump_ts = jiffies;
  500. reporter->dump_real_ts = ktime_get_real_ns();
  501. return 0;
  502. dump_err:
  503. devlink_health_dump_clear(reporter);
  504. return err;
  505. }
  506. int devlink_health_report(struct devlink_health_reporter *reporter,
  507. const char *msg, void *priv_ctx)
  508. {
  509. enum devlink_health_reporter_state prev_health_state;
  510. struct devlink *devlink = reporter->devlink;
  511. unsigned long recover_ts_threshold;
  512. int ret;
  513. /* write a log message of the current error */
  514. WARN_ON(!msg);
  515. trace_devlink_health_report(devlink, reporter->ops->name, msg);
  516. reporter->error_count++;
  517. prev_health_state = reporter->health_state;
  518. reporter->health_state = DEVLINK_HEALTH_REPORTER_STATE_ERROR;
  519. devlink_recover_notify(reporter, DEVLINK_CMD_HEALTH_REPORTER_RECOVER);
  520. /* abort if the previous error wasn't recovered */
  521. recover_ts_threshold = reporter->last_recovery_ts +
  522. msecs_to_jiffies(reporter->graceful_period);
  523. if (reporter->auto_recover &&
  524. (prev_health_state != DEVLINK_HEALTH_REPORTER_STATE_HEALTHY ||
  525. (reporter->last_recovery_ts && reporter->recovery_count &&
  526. time_is_after_jiffies(recover_ts_threshold)))) {
  527. trace_devlink_health_recover_aborted(devlink,
  528. reporter->ops->name,
  529. reporter->health_state,
  530. jiffies -
  531. reporter->last_recovery_ts);
  532. return -ECANCELED;
  533. }
  534. if (reporter->auto_dump) {
  535. devl_lock(devlink);
  536. /* store current dump of current error, for later analysis */
  537. devlink_health_do_dump(reporter, priv_ctx, NULL);
  538. devl_unlock(devlink);
  539. }
  540. if (!reporter->auto_recover)
  541. return 0;
  542. devl_lock(devlink);
  543. ret = devlink_health_reporter_recover(reporter, priv_ctx, NULL);
  544. devl_unlock(devlink);
  545. return ret;
  546. }
  547. EXPORT_SYMBOL_GPL(devlink_health_report);
  548. void
  549. devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
  550. enum devlink_health_reporter_state state)
  551. {
  552. if (WARN_ON(state != DEVLINK_HEALTH_REPORTER_STATE_HEALTHY &&
  553. state != DEVLINK_HEALTH_REPORTER_STATE_ERROR))
  554. return;
  555. if (reporter->health_state == state)
  556. return;
  557. reporter->health_state = state;
  558. trace_devlink_health_reporter_state_update(reporter->devlink,
  559. reporter->ops->name, state);
  560. devlink_recover_notify(reporter, DEVLINK_CMD_HEALTH_REPORTER_RECOVER);
  561. }
  562. EXPORT_SYMBOL_GPL(devlink_health_reporter_state_update);
  563. int devlink_nl_health_reporter_recover_doit(struct sk_buff *skb,
  564. struct genl_info *info)
  565. {
  566. struct devlink *devlink = info->user_ptr[0];
  567. struct devlink_health_reporter *reporter;
  568. reporter = devlink_health_reporter_get_from_info(devlink, info);
  569. if (!reporter)
  570. return -EINVAL;
  571. return devlink_health_reporter_recover(reporter, NULL, info->extack);
  572. }
  573. static void devlink_fmsg_err_if_binary(struct devlink_fmsg *fmsg)
  574. {
  575. if (!fmsg->err && fmsg->putting_binary)
  576. fmsg->err = -EINVAL;
  577. }
  578. static void devlink_fmsg_nest_common(struct devlink_fmsg *fmsg, int attrtype)
  579. {
  580. struct devlink_fmsg_item *item;
  581. if (fmsg->err)
  582. return;
  583. item = kzalloc(sizeof(*item), GFP_KERNEL);
  584. if (!item) {
  585. fmsg->err = -ENOMEM;
  586. return;
  587. }
  588. item->attrtype = attrtype;
  589. list_add_tail(&item->list, &fmsg->item_list);
  590. }
  591. void devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg)
  592. {
  593. devlink_fmsg_err_if_binary(fmsg);
  594. devlink_fmsg_nest_common(fmsg, DEVLINK_ATTR_FMSG_OBJ_NEST_START);
  595. }
  596. EXPORT_SYMBOL_GPL(devlink_fmsg_obj_nest_start);
  597. static void devlink_fmsg_nest_end(struct devlink_fmsg *fmsg)
  598. {
  599. devlink_fmsg_err_if_binary(fmsg);
  600. devlink_fmsg_nest_common(fmsg, DEVLINK_ATTR_FMSG_NEST_END);
  601. }
  602. void devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg)
  603. {
  604. devlink_fmsg_nest_end(fmsg);
  605. }
  606. EXPORT_SYMBOL_GPL(devlink_fmsg_obj_nest_end);
  607. #define DEVLINK_FMSG_MAX_SIZE (GENLMSG_DEFAULT_SIZE - GENL_HDRLEN - NLA_HDRLEN)
  608. static void devlink_fmsg_put_name(struct devlink_fmsg *fmsg, const char *name)
  609. {
  610. struct devlink_fmsg_item *item;
  611. devlink_fmsg_err_if_binary(fmsg);
  612. if (fmsg->err)
  613. return;
  614. if (strlen(name) + 1 > DEVLINK_FMSG_MAX_SIZE) {
  615. fmsg->err = -EMSGSIZE;
  616. return;
  617. }
  618. item = kzalloc(sizeof(*item) + strlen(name) + 1, GFP_KERNEL);
  619. if (!item) {
  620. fmsg->err = -ENOMEM;
  621. return;
  622. }
  623. item->nla_type = NLA_NUL_STRING;
  624. item->len = strlen(name) + 1;
  625. item->attrtype = DEVLINK_ATTR_FMSG_OBJ_NAME;
  626. memcpy(&item->value, name, item->len);
  627. list_add_tail(&item->list, &fmsg->item_list);
  628. }
  629. void devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name)
  630. {
  631. devlink_fmsg_err_if_binary(fmsg);
  632. devlink_fmsg_nest_common(fmsg, DEVLINK_ATTR_FMSG_PAIR_NEST_START);
  633. devlink_fmsg_put_name(fmsg, name);
  634. }
  635. EXPORT_SYMBOL_GPL(devlink_fmsg_pair_nest_start);
  636. void devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg)
  637. {
  638. devlink_fmsg_nest_end(fmsg);
  639. }
  640. EXPORT_SYMBOL_GPL(devlink_fmsg_pair_nest_end);
  641. void devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
  642. const char *name)
  643. {
  644. devlink_fmsg_pair_nest_start(fmsg, name);
  645. devlink_fmsg_nest_common(fmsg, DEVLINK_ATTR_FMSG_ARR_NEST_START);
  646. }
  647. EXPORT_SYMBOL_GPL(devlink_fmsg_arr_pair_nest_start);
  648. void devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg)
  649. {
  650. devlink_fmsg_nest_end(fmsg);
  651. devlink_fmsg_nest_end(fmsg);
  652. }
  653. EXPORT_SYMBOL_GPL(devlink_fmsg_arr_pair_nest_end);
  654. void devlink_fmsg_binary_pair_nest_start(struct devlink_fmsg *fmsg,
  655. const char *name)
  656. {
  657. devlink_fmsg_arr_pair_nest_start(fmsg, name);
  658. fmsg->putting_binary = true;
  659. }
  660. EXPORT_SYMBOL_GPL(devlink_fmsg_binary_pair_nest_start);
  661. void devlink_fmsg_binary_pair_nest_end(struct devlink_fmsg *fmsg)
  662. {
  663. if (fmsg->err)
  664. return;
  665. if (!fmsg->putting_binary)
  666. fmsg->err = -EINVAL;
  667. fmsg->putting_binary = false;
  668. devlink_fmsg_arr_pair_nest_end(fmsg);
  669. }
  670. EXPORT_SYMBOL_GPL(devlink_fmsg_binary_pair_nest_end);
  671. static void devlink_fmsg_put_value(struct devlink_fmsg *fmsg,
  672. const void *value, u16 value_len,
  673. u8 value_nla_type)
  674. {
  675. struct devlink_fmsg_item *item;
  676. if (fmsg->err)
  677. return;
  678. if (value_len > DEVLINK_FMSG_MAX_SIZE) {
  679. fmsg->err = -EMSGSIZE;
  680. return;
  681. }
  682. item = kzalloc(sizeof(*item) + value_len, GFP_KERNEL);
  683. if (!item) {
  684. fmsg->err = -ENOMEM;
  685. return;
  686. }
  687. item->nla_type = value_nla_type;
  688. item->len = value_len;
  689. item->attrtype = DEVLINK_ATTR_FMSG_OBJ_VALUE_DATA;
  690. memcpy(&item->value, value, item->len);
  691. list_add_tail(&item->list, &fmsg->item_list);
  692. }
  693. static void devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value)
  694. {
  695. devlink_fmsg_err_if_binary(fmsg);
  696. devlink_fmsg_put_value(fmsg, &value, sizeof(value), NLA_FLAG);
  697. }
  698. static void devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value)
  699. {
  700. devlink_fmsg_err_if_binary(fmsg);
  701. devlink_fmsg_put_value(fmsg, &value, sizeof(value), NLA_U8);
  702. }
  703. void devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value)
  704. {
  705. devlink_fmsg_err_if_binary(fmsg);
  706. devlink_fmsg_put_value(fmsg, &value, sizeof(value), NLA_U32);
  707. }
  708. EXPORT_SYMBOL_GPL(devlink_fmsg_u32_put);
  709. static void devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value)
  710. {
  711. devlink_fmsg_err_if_binary(fmsg);
  712. devlink_fmsg_put_value(fmsg, &value, sizeof(value), NLA_U64);
  713. }
  714. void devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value)
  715. {
  716. devlink_fmsg_err_if_binary(fmsg);
  717. devlink_fmsg_put_value(fmsg, value, strlen(value) + 1, NLA_NUL_STRING);
  718. }
  719. EXPORT_SYMBOL_GPL(devlink_fmsg_string_put);
  720. void devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
  721. u16 value_len)
  722. {
  723. if (!fmsg->err && !fmsg->putting_binary)
  724. fmsg->err = -EINVAL;
  725. devlink_fmsg_put_value(fmsg, value, value_len, NLA_BINARY);
  726. }
  727. EXPORT_SYMBOL_GPL(devlink_fmsg_binary_put);
  728. void devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
  729. bool value)
  730. {
  731. devlink_fmsg_pair_nest_start(fmsg, name);
  732. devlink_fmsg_bool_put(fmsg, value);
  733. devlink_fmsg_pair_nest_end(fmsg);
  734. }
  735. EXPORT_SYMBOL_GPL(devlink_fmsg_bool_pair_put);
  736. void devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
  737. u8 value)
  738. {
  739. devlink_fmsg_pair_nest_start(fmsg, name);
  740. devlink_fmsg_u8_put(fmsg, value);
  741. devlink_fmsg_pair_nest_end(fmsg);
  742. }
  743. EXPORT_SYMBOL_GPL(devlink_fmsg_u8_pair_put);
  744. void devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
  745. u32 value)
  746. {
  747. devlink_fmsg_pair_nest_start(fmsg, name);
  748. devlink_fmsg_u32_put(fmsg, value);
  749. devlink_fmsg_pair_nest_end(fmsg);
  750. }
  751. EXPORT_SYMBOL_GPL(devlink_fmsg_u32_pair_put);
  752. void devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
  753. u64 value)
  754. {
  755. devlink_fmsg_pair_nest_start(fmsg, name);
  756. devlink_fmsg_u64_put(fmsg, value);
  757. devlink_fmsg_pair_nest_end(fmsg);
  758. }
  759. EXPORT_SYMBOL_GPL(devlink_fmsg_u64_pair_put);
  760. void devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
  761. const char *value)
  762. {
  763. devlink_fmsg_pair_nest_start(fmsg, name);
  764. devlink_fmsg_string_put(fmsg, value);
  765. devlink_fmsg_pair_nest_end(fmsg);
  766. }
  767. EXPORT_SYMBOL_GPL(devlink_fmsg_string_pair_put);
  768. void devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
  769. const void *value, u32 value_len)
  770. {
  771. u32 data_size;
  772. u32 offset;
  773. devlink_fmsg_binary_pair_nest_start(fmsg, name);
  774. for (offset = 0; offset < value_len; offset += data_size) {
  775. data_size = value_len - offset;
  776. if (data_size > DEVLINK_FMSG_MAX_SIZE)
  777. data_size = DEVLINK_FMSG_MAX_SIZE;
  778. devlink_fmsg_binary_put(fmsg, value + offset, data_size);
  779. }
  780. devlink_fmsg_binary_pair_nest_end(fmsg);
  781. fmsg->putting_binary = false;
  782. }
  783. EXPORT_SYMBOL_GPL(devlink_fmsg_binary_pair_put);
  784. static int
  785. devlink_fmsg_item_fill_type(struct devlink_fmsg_item *msg, struct sk_buff *skb)
  786. {
  787. switch (msg->nla_type) {
  788. case NLA_FLAG:
  789. case NLA_U8:
  790. case NLA_U32:
  791. case NLA_U64:
  792. case NLA_NUL_STRING:
  793. case NLA_BINARY:
  794. return nla_put_u8(skb, DEVLINK_ATTR_FMSG_OBJ_VALUE_TYPE,
  795. msg->nla_type);
  796. default:
  797. return -EINVAL;
  798. }
  799. }
  800. static int
  801. devlink_fmsg_item_fill_data(struct devlink_fmsg_item *msg, struct sk_buff *skb)
  802. {
  803. int attrtype = DEVLINK_ATTR_FMSG_OBJ_VALUE_DATA;
  804. u8 tmp;
  805. switch (msg->nla_type) {
  806. case NLA_FLAG:
  807. /* Always provide flag data, regardless of its value */
  808. tmp = *(bool *)msg->value;
  809. return nla_put_u8(skb, attrtype, tmp);
  810. case NLA_U8:
  811. return nla_put_u8(skb, attrtype, *(u8 *)msg->value);
  812. case NLA_U32:
  813. return nla_put_u32(skb, attrtype, *(u32 *)msg->value);
  814. case NLA_U64:
  815. return nla_put_u64_64bit(skb, attrtype, *(u64 *)msg->value,
  816. DEVLINK_ATTR_PAD);
  817. case NLA_NUL_STRING:
  818. return nla_put_string(skb, attrtype, (char *)&msg->value);
  819. case NLA_BINARY:
  820. return nla_put(skb, attrtype, msg->len, (void *)&msg->value);
  821. default:
  822. return -EINVAL;
  823. }
  824. }
  825. static int
  826. devlink_fmsg_prepare_skb(struct devlink_fmsg *fmsg, struct sk_buff *skb,
  827. int *start)
  828. {
  829. struct devlink_fmsg_item *item;
  830. struct nlattr *fmsg_nlattr;
  831. int err = 0;
  832. int i = 0;
  833. fmsg_nlattr = nla_nest_start_noflag(skb, DEVLINK_ATTR_FMSG);
  834. if (!fmsg_nlattr)
  835. return -EMSGSIZE;
  836. list_for_each_entry(item, &fmsg->item_list, list) {
  837. if (i < *start) {
  838. i++;
  839. continue;
  840. }
  841. switch (item->attrtype) {
  842. case DEVLINK_ATTR_FMSG_OBJ_NEST_START:
  843. case DEVLINK_ATTR_FMSG_PAIR_NEST_START:
  844. case DEVLINK_ATTR_FMSG_ARR_NEST_START:
  845. case DEVLINK_ATTR_FMSG_NEST_END:
  846. err = nla_put_flag(skb, item->attrtype);
  847. break;
  848. case DEVLINK_ATTR_FMSG_OBJ_VALUE_DATA:
  849. err = devlink_fmsg_item_fill_type(item, skb);
  850. if (err)
  851. break;
  852. err = devlink_fmsg_item_fill_data(item, skb);
  853. break;
  854. case DEVLINK_ATTR_FMSG_OBJ_NAME:
  855. err = nla_put_string(skb, item->attrtype,
  856. (char *)&item->value);
  857. break;
  858. default:
  859. err = -EINVAL;
  860. break;
  861. }
  862. if (!err)
  863. *start = ++i;
  864. else
  865. break;
  866. }
  867. nla_nest_end(skb, fmsg_nlattr);
  868. return err;
  869. }
  870. static int devlink_fmsg_snd(struct devlink_fmsg *fmsg,
  871. struct genl_info *info,
  872. enum devlink_command cmd, int flags)
  873. {
  874. struct nlmsghdr *nlh;
  875. struct sk_buff *skb;
  876. bool last = false;
  877. int index = 0;
  878. void *hdr;
  879. int err;
  880. if (fmsg->err)
  881. return fmsg->err;
  882. while (!last) {
  883. int tmp_index = index;
  884. skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
  885. if (!skb)
  886. return -ENOMEM;
  887. hdr = genlmsg_put(skb, info->snd_portid, info->snd_seq,
  888. &devlink_nl_family, flags | NLM_F_MULTI, cmd);
  889. if (!hdr) {
  890. err = -EMSGSIZE;
  891. goto nla_put_failure;
  892. }
  893. err = devlink_fmsg_prepare_skb(fmsg, skb, &index);
  894. if (!err)
  895. last = true;
  896. else if (err != -EMSGSIZE || tmp_index == index)
  897. goto nla_put_failure;
  898. genlmsg_end(skb, hdr);
  899. err = genlmsg_reply(skb, info);
  900. if (err)
  901. return err;
  902. }
  903. skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
  904. if (!skb)
  905. return -ENOMEM;
  906. nlh = nlmsg_put(skb, info->snd_portid, info->snd_seq,
  907. NLMSG_DONE, 0, flags | NLM_F_MULTI);
  908. if (!nlh) {
  909. err = -EMSGSIZE;
  910. goto nla_put_failure;
  911. }
  912. return genlmsg_reply(skb, info);
  913. nla_put_failure:
  914. nlmsg_free(skb);
  915. return err;
  916. }
  917. static int devlink_fmsg_dumpit(struct devlink_fmsg *fmsg, struct sk_buff *skb,
  918. struct netlink_callback *cb,
  919. enum devlink_command cmd)
  920. {
  921. struct devlink_nl_dump_state *state = devlink_dump_state(cb);
  922. int index = state->idx;
  923. int tmp_index = index;
  924. void *hdr;
  925. int err;
  926. if (fmsg->err)
  927. return fmsg->err;
  928. hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
  929. &devlink_nl_family, NLM_F_ACK | NLM_F_MULTI, cmd);
  930. if (!hdr) {
  931. err = -EMSGSIZE;
  932. goto nla_put_failure;
  933. }
  934. err = devlink_fmsg_prepare_skb(fmsg, skb, &index);
  935. if ((err && err != -EMSGSIZE) || tmp_index == index)
  936. goto nla_put_failure;
  937. state->idx = index;
  938. genlmsg_end(skb, hdr);
  939. return skb->len;
  940. nla_put_failure:
  941. genlmsg_cancel(skb, hdr);
  942. return err;
  943. }
  944. int devlink_nl_health_reporter_diagnose_doit(struct sk_buff *skb,
  945. struct genl_info *info)
  946. {
  947. struct devlink *devlink = info->user_ptr[0];
  948. struct devlink_health_reporter *reporter;
  949. struct devlink_fmsg *fmsg;
  950. int err;
  951. reporter = devlink_health_reporter_get_from_info(devlink, info);
  952. if (!reporter)
  953. return -EINVAL;
  954. if (!reporter->ops->diagnose)
  955. return -EOPNOTSUPP;
  956. fmsg = devlink_fmsg_alloc();
  957. if (!fmsg)
  958. return -ENOMEM;
  959. devlink_fmsg_obj_nest_start(fmsg);
  960. err = reporter->ops->diagnose(reporter, fmsg, info->extack);
  961. if (err)
  962. goto out;
  963. devlink_fmsg_obj_nest_end(fmsg);
  964. err = devlink_fmsg_snd(fmsg, info,
  965. DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE, 0);
  966. out:
  967. devlink_fmsg_free(fmsg);
  968. return err;
  969. }
  970. static struct devlink_health_reporter *
  971. devlink_health_reporter_get_from_cb_lock(struct netlink_callback *cb)
  972. {
  973. const struct genl_info *info = genl_info_dump(cb);
  974. struct devlink_health_reporter *reporter;
  975. struct nlattr **attrs = info->attrs;
  976. struct devlink *devlink;
  977. devlink = devlink_get_from_attrs_lock(sock_net(cb->skb->sk), attrs,
  978. false);
  979. if (IS_ERR(devlink))
  980. return NULL;
  981. reporter = devlink_health_reporter_get_from_attrs(devlink, attrs);
  982. if (!reporter) {
  983. devl_unlock(devlink);
  984. devlink_put(devlink);
  985. }
  986. return reporter;
  987. }
  988. int devlink_nl_health_reporter_dump_get_dumpit(struct sk_buff *skb,
  989. struct netlink_callback *cb)
  990. {
  991. struct devlink_nl_dump_state *state = devlink_dump_state(cb);
  992. struct devlink_health_reporter *reporter;
  993. struct devlink *devlink;
  994. int err;
  995. reporter = devlink_health_reporter_get_from_cb_lock(cb);
  996. if (!reporter)
  997. return -EINVAL;
  998. devlink = reporter->devlink;
  999. if (!reporter->ops->dump) {
  1000. devl_unlock(devlink);
  1001. devlink_put(devlink);
  1002. return -EOPNOTSUPP;
  1003. }
  1004. if (!state->idx) {
  1005. err = devlink_health_do_dump(reporter, NULL, cb->extack);
  1006. if (err)
  1007. goto unlock;
  1008. state->dump_ts = reporter->dump_ts;
  1009. }
  1010. if (!reporter->dump_fmsg || state->dump_ts != reporter->dump_ts) {
  1011. NL_SET_ERR_MSG(cb->extack, "Dump trampled, please retry");
  1012. err = -EAGAIN;
  1013. goto unlock;
  1014. }
  1015. err = devlink_fmsg_dumpit(reporter->dump_fmsg, skb, cb,
  1016. DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET);
  1017. unlock:
  1018. devl_unlock(devlink);
  1019. devlink_put(devlink);
  1020. return err;
  1021. }
  1022. int devlink_nl_health_reporter_dump_clear_doit(struct sk_buff *skb,
  1023. struct genl_info *info)
  1024. {
  1025. struct devlink *devlink = info->user_ptr[0];
  1026. struct devlink_health_reporter *reporter;
  1027. reporter = devlink_health_reporter_get_from_info(devlink, info);
  1028. if (!reporter)
  1029. return -EINVAL;
  1030. if (!reporter->ops->dump)
  1031. return -EOPNOTSUPP;
  1032. devlink_health_dump_clear(reporter);
  1033. return 0;
  1034. }
  1035. int devlink_nl_health_reporter_test_doit(struct sk_buff *skb,
  1036. struct genl_info *info)
  1037. {
  1038. struct devlink *devlink = info->user_ptr[0];
  1039. struct devlink_health_reporter *reporter;
  1040. reporter = devlink_health_reporter_get_from_info(devlink, info);
  1041. if (!reporter)
  1042. return -EINVAL;
  1043. if (!reporter->ops->test)
  1044. return -EOPNOTSUPP;
  1045. return reporter->ops->test(reporter, info->extack);
  1046. }