mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
zpcimon: Factor out JSON printing of common PCI adapter attributes
Some of the attributes printed as JSON by opticsmon are common to all PCI adapters factor these out into reusable helper functions zpci_adapter_json_print_start() and zpci_adapter_json_print_end(). Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com> Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
78dd82d129
commit
a9dbb8a1a2
@@ -45,7 +45,6 @@ static int opticsmon_collect_adapter_data(struct zpcimon_ctx *ctx, struct zpci_d
|
||||
struct options *opts = &ctx->opts;
|
||||
struct optics **ois;
|
||||
int num_ois = 0;
|
||||
char *pci_addr;
|
||||
int i, rc;
|
||||
|
||||
/* Filter non-NIC devices and VFs */
|
||||
@@ -60,21 +59,12 @@ static int opticsmon_collect_adapter_data(struct zpcimon_ctx *ctx, struct zpci_d
|
||||
num_ois++;
|
||||
}
|
||||
if (!opts->quiet) {
|
||||
util_fmt_obj_start(FMT_DEFAULT, "adapter");
|
||||
util_fmt_pair(FMT_QUOTE, "pft", zpci_pft_str(zdev));
|
||||
util_fmt_obj_start(FMT_DEFAULT, "ids");
|
||||
util_fmt_pair(FMT_QUOTE, "fid", "0x%0x", zdev->fid);
|
||||
if (zdev->uid_is_unique)
|
||||
util_fmt_pair(FMT_QUOTE, "uid", "0x%0x", zdev->uid);
|
||||
pci_addr = zpci_pci_addr(zdev);
|
||||
util_fmt_pair(FMT_QUOTE, "pci_address", pci_addr);
|
||||
free(pci_addr);
|
||||
util_fmt_obj_end();
|
||||
zpci_adapter_json_print_start(zdev);
|
||||
util_fmt_obj_start(FMT_LIST, "netdevs");
|
||||
for (i = 0; i < zdev->num_netdevs; i++)
|
||||
optics_json_print(opts, &zdev->netdevs[i], ois[i]);
|
||||
util_fmt_obj_end(); /* netdevs list */
|
||||
util_fmt_obj_end(); /* adapter */
|
||||
zpci_adapter_json_print_end();
|
||||
fflush(stdout);
|
||||
}
|
||||
if (opts->report) {
|
||||
|
||||
@@ -112,6 +112,27 @@ static void parse_cmdline(int argc, char *argv[], struct options *opts)
|
||||
} while (cmd != -1);
|
||||
}
|
||||
|
||||
void zpci_adapter_json_print_start(struct zpci_dev *zdev)
|
||||
{
|
||||
char *pci_addr;
|
||||
|
||||
util_fmt_obj_start(FMT_DEFAULT, "adapter");
|
||||
util_fmt_pair(FMT_QUOTE, "pft", zpci_pft_str(zdev));
|
||||
util_fmt_obj_start(FMT_DEFAULT, "ids");
|
||||
util_fmt_pair(FMT_QUOTE, "fid", "0x%0x", zdev->fid);
|
||||
if (zdev->uid_is_unique)
|
||||
util_fmt_pair(FMT_QUOTE, "uid", "0x%0x", zdev->uid);
|
||||
pci_addr = zpci_pci_addr(zdev);
|
||||
util_fmt_pair(FMT_QUOTE, "pci_address", pci_addr);
|
||||
free(pci_addr);
|
||||
util_fmt_obj_end();
|
||||
}
|
||||
|
||||
void zpci_adapter_json_print_end(void)
|
||||
{
|
||||
util_fmt_obj_end(); /* adapter */
|
||||
}
|
||||
|
||||
void zpcimon_json_base64_pair(char *name, uint8_t *buf, int len)
|
||||
{
|
||||
int b64_calclen, b64len;
|
||||
|
||||
@@ -48,5 +48,7 @@ struct zpcimon_ops {
|
||||
|
||||
void zpci_list_reload(struct util_list **zpci_list);
|
||||
|
||||
void zpci_adapter_json_print_start(struct zpci_dev *zdev);
|
||||
void zpci_adapter_json_print_end(void);
|
||||
void zpcimon_json_base64_pair(char *name, uint8_t *buf, int len);
|
||||
#endif /* ZPCIMON_ZPCIMON_H */
|
||||
|
||||
Reference in New Issue
Block a user