From: Or Har-Toov <[email protected]>

Allow 'devlink resource show' without specifying a device to dump
resources from all devlink devices.

Signed-off-by: Or Har-Toov <[email protected]>
Signed-off-by: Tariq Toukan <[email protected]>
---
 devlink/devlink.c           | 18 ++++++++++++++----
 man/man8/devlink-resource.8 | 10 ++++++++--
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index ba14c0056b1c..0962ffd861ad 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -7429,6 +7429,12 @@ static void resources_free(struct resources *resources)
                resource_free(resource);
 }
 
+static void resources_reset(struct resources *resources)
+{
+       resources_free(resources);
+       INIT_LIST_HEAD(&resources->resource_list);
+}
+
 static int resource_ctx_init(struct resource_ctx *ctx, struct dl *dl)
 {
        ctx->resources = resources_alloc();
@@ -8986,19 +8992,23 @@ static int cmd_resource_dump_cb(const struct nlmsghdr 
*nlh, void *data)
                return MNL_CB_ERROR;
        }
 
-       if (ctx->print_resources)
+       if (ctx->print_resources) {
                resources_show(ctx, tb);
+               resources_reset(ctx->resources);
+       }
 
        return MNL_CB_OK;
 }
 
 static int cmd_resource_show(struct dl *dl)
 {
+       uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
        struct nlmsghdr *nlh;
        struct resource_ctx resource_ctx = {};
        int err;
 
-       err = dl_argv_parse(dl, DL_OPT_HANDLE, 0);
+       err = dl_argv_parse_with_selector(dl, &flags, DEVLINK_CMD_RESOURCE_DUMP,
+                                         DL_OPT_HANDLE, 0, 0, 0);
        if (err)
                return err;
 
@@ -9008,7 +9018,7 @@ static int cmd_resource_show(struct dl *dl)
 
        resource_ctx.print_resources = true;
        nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_RESOURCE_DUMP,
-                              NLM_F_REQUEST | NLM_F_ACK);
+                                         flags);
        dl_opts_put(nlh, dl);
        pr_out_section_start(dl, "resources");
        err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_resource_dump_cb,
@@ -9020,7 +9030,7 @@ static int cmd_resource_show(struct dl *dl)
 
 static void cmd_resource_help(void)
 {
-       pr_err("Usage: devlink resource show DEV\n"
+       pr_err("Usage: devlink resource show [ DEV ]\n"
               "       devlink resource set DEV path PATH size SIZE\n");
 }
 
diff --git a/man/man8/devlink-resource.8 b/man/man8/devlink-resource.8
index c4f6918c9b03..b55138d950c7 100644
--- a/man/man8/devlink-resource.8
+++ b/man/man8/devlink-resource.8
@@ -19,7 +19,7 @@ devlink-resource \- devlink device resource configuration
 
 .ti -8
 .B devlink resource show
-.IR DEV
+.RI "[ " DEV " ]"
 
 .ti -8
 .B devlink resource help
@@ -31,11 +31,12 @@ devlink-resource \- devlink device resource configuration
 .BI size " RESOURCE_SIZE"
 
 .SH "DESCRIPTION"
-.SS devlink resource show - display devlink device's resosources
+.SS devlink resource show - display devlink device resources
 
 .PP
 .I "DEV"
 - specifies the devlink device to show.
+If omitted, all devices are listed.
 
 .in +4
 Format is:
@@ -58,6 +59,11 @@ The new resource's size.
 
 .SH "EXAMPLES"
 .PP
+devlink resource show
+.RS 4
+Shows resources for all devlink devices.
+.RE
+.PP
 devlink resource show pci/0000:01:00.0
 .RS 4
 Shows the resources of the specified devlink device.
-- 
2.44.0


Reply via email to