mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
The optics monitoring tool opticsmon implements the user-space portion
of reporting optics data to the SE. Its basic functionality is to
collect optical module information equivalent to "ethtool --module-info"
for PCI Physical Functions and forwards this data to the SE using the
new SCLP Write Event Data Action Qualifier 3.
For the part of finding all PFs we need to look at all PCI
functions and determine which ones are PFs and what netdevs they
correspond to. This is a generally useful functionality so this part as
well as the SCLP issuing code go into a new libzpci library which also
includes a standalone example for listing PCI functions and their s390x
specific attributes. Medium term we plan to add this functionality to
lszdev.
For the opticsmon tool itself there are 2 basic operating modes:
* One-shot Mode: Without parameters opticsmon collects optical module
data and prints a summary of the netdevice in JSON format. With
--module-data it also includes a base64 encoded raw dump equivalent to
ethtool --module-info <netdev> raw on.
* Monitor Mode: With the --monitor flag opticsmon runs continuously
usually started via a systemd unit and collects new optical module
data on a time interval (default 24h) or when the operational state
("/sys/class/net/<netdev/operstate") changes. The tool listens for
changes via netlink so no polling on sysfs is necessary
Note: Both modes will *NOT* issues SCLPs without adding the
--send-report flag but will output a JSON summary for each data
collection so can be tested without firmware impact.
Reviewed-by: Halil Pasic <pasic@linux.ibm.com>
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
97 lines
2.0 KiB
C
97 lines
2.0 KiB
C
/*
|
|
* Copyright IBM Corp. 2024
|
|
*
|
|
* s390-tools is free software; you can redistribute it and/or modify
|
|
* it under the terms of the MIT license. See LICENSE for details.
|
|
*/
|
|
|
|
#include <errno.h>
|
|
#include <sys/epoll.h>
|
|
#include <sys/signalfd.h>
|
|
#include <signal.h>
|
|
#include <linux/if.h>
|
|
|
|
#include <netlink/route/link.h>
|
|
#include <netlink/netlink.h>
|
|
|
|
#include "link_mon.h"
|
|
|
|
#define MAX_EVENTS 32
|
|
|
|
static void nl_obj_parsed_cb(struct nl_object *obj, void *arg)
|
|
{
|
|
struct link_mon_nl_ctx *ctx = arg;
|
|
struct rtnl_link *link;
|
|
struct zpci_netdev netdev;
|
|
|
|
if (strcmp(nl_object_get_type(obj), "route/link") != 0)
|
|
return;
|
|
link = (struct rtnl_link *)obj;
|
|
netdev.name = rtnl_link_get_name(link);
|
|
netdev.operstate = rtnl_link_get_operstate(link);
|
|
ctx->cb(&netdev, ctx->arg);
|
|
}
|
|
|
|
static int nl_rtnl_lnkgrp_cb(struct nl_msg *msg, void *arg)
|
|
{
|
|
if (nl_msg_parse(msg, &nl_obj_parsed_cb, arg) < 0)
|
|
fprintf(stderr, "<<EVENT>> Unknown message type\n");
|
|
return NL_STOP;
|
|
}
|
|
|
|
void link_mon_nl_waitfd_read(struct link_mon_nl_ctx *ctx)
|
|
{
|
|
nl_recvmsgs_default(ctx->sk);
|
|
}
|
|
|
|
int link_mon_nl_waitfd_getfd(struct link_mon_nl_ctx *ctx)
|
|
{
|
|
return nl_socket_get_fd(ctx->sk);
|
|
}
|
|
|
|
int link_mon_nl_waitfd_create(struct link_mon_nl_ctx *ctx, link_mon_nl_cb cb, void *arg)
|
|
{
|
|
int ret = 0, rc = 0;
|
|
|
|
ctx->sk = nl_socket_alloc();
|
|
if (!ctx->sk)
|
|
return -ENOMEM;
|
|
ctx->cb = cb;
|
|
ctx->arg = arg;
|
|
nl_socket_disable_seq_check(ctx->sk);
|
|
nl_socket_modify_cb(ctx->sk, NL_CB_VALID, NL_CB_CUSTOM, nl_rtnl_lnkgrp_cb, ctx);
|
|
|
|
rc = nl_connect(ctx->sk, NETLINK_ROUTE);
|
|
if (rc < 0) {
|
|
ret = rc;
|
|
goto err_free;
|
|
}
|
|
|
|
rc = nl_socket_add_membership(ctx->sk, RTNLGRP_LINK);
|
|
if (rc < 0) {
|
|
ret = rc;
|
|
goto err_close;
|
|
}
|
|
|
|
rc = rtnl_link_alloc_cache(ctx->sk, AF_UNSPEC, &ctx->cache);
|
|
if (rc < 0) {
|
|
ret = rc;
|
|
goto err_close;
|
|
}
|
|
nl_cache_mngt_provide(ctx->cache);
|
|
return 0;
|
|
|
|
err_close:
|
|
nl_close(ctx->sk);
|
|
err_free:
|
|
nl_socket_free(ctx->sk);
|
|
return ret;
|
|
}
|
|
|
|
void link_mon_nl_waitfd_destroy(struct link_mon_nl_ctx *ctx)
|
|
{
|
|
nl_cache_free(ctx->cache);
|
|
nl_close(ctx->sk);
|
|
nl_socket_free(ctx->sk);
|
|
}
|