diff mbox series

[ovs-dev,26/41] dpif: Add dpif_get_features() API.

Message ID c010e28c1e19f7bfa5b4ea4218de37dce97afa54.1762950453.git.echaudro@redhat.com
State Changes Requested
Headers show
Series Architectural refactoring of hardware offload infrastructure | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/github-robot-_Build_and_Test success github build: passed

Commit Message

Eelco Chaudron Nov. 12, 2025, 3:35 p.m. UTC
Currently, the dpif layer provides an API to set specific features,
but not to retrieve their current values. This patch adds a new API,
dpif_get_features(), to query the currently configured features.

Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
---
 lib/dpif-netdev.c   |  1 +
 lib/dpif-netlink.c  | 11 +++++++++++
 lib/dpif-provider.h |  1 +
 lib/dpif.c          | 12 +++++++++++-
 lib/dpif.h          |  1 +
 5 files changed, 25 insertions(+), 1 deletion(-)

Comments

0-day Robot Nov. 14, 2025, 2:17 p.m. UTC | #1
git sha: c010e28c1e19f7bfa5b4ea4218de37dce97afa54
Author: Eelco Chaudron <echaudro@redhat.com>
dpif: Add dpif_get_features() API.

This patch adds a new dpif_get_features() API to query currently
configured features, complementing the existing dpif_set_features() API.

> diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
> index fa265b8fc..c09b1c7c7 100644
> --- a/lib/dpif-netdev.c
> +++ b/lib/dpif-netdev.c
> @@ -9973,6 +9973,7 @@ const struct dpif_class dpif_netdev_class = {
>      dpif_netdev_wait,
>      dpif_netdev_get_stats,
>      NULL,                      /* set_features */
> +    NULL,                      /* get_features */
>      dpif_netdev_port_add,
>      dpif_netdev_port_del,
>      dpif_netdev_port_set_config,
> diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
> index 04d7c8ed6..e161930be 100644
> --- a/lib/dpif-netlink.c
> +++ b/lib/dpif-netlink.c
> @@ -121,6 +121,8 @@ static int dpif_netlink_dp_get(const struct dpif *,
>                                 struct ofpbuf **bufp);
>  static int
>  dpif_netlink_set_features(struct dpif *dpif_, uint32_t new_features);
> +static uint32_t
> +dpif_netlink_get_features(struct dpif *dpif_);
> 
>  static void
>  dpif_netlink_unixctl_dispatch_mode(struct unixctl_conn *conn, int argc,
> @@ -880,6 +882,14 @@ dpif_netlink_set_features(struct dpif *dpif_, uint32_t new_features)
>      return error;
>  }
> 
> +static uint32_t
> +dpif_netlink_get_features(struct dpif *dpif_)
> +{
> +    struct dpif_netlink *dpif = dpif_netlink_cast(dpif_);
> +
> +    return dpif->user_features;
> +}

The implementation looks correct - it returns the cached user_features
value maintained by the dpif_netlink structure.

> @@ -4373,6 +4383,7 @@ const struct dpif_class dpif_netlink_class = {
>      NULL,                       /* wait */
>      dpif_netlink_get_stats,
>      dpif_netlink_set_features,
> +    dpif_netlink_get_features,
>      dpif_netlink_port_add,
>      dpif_netlink_port_del,
>      NULL,                       /* port_set_config */

[ ... ]

> diff --git a/lib/dpif.c b/lib/dpif.c
> index e8bbd65b7..4b068b013 100644
> --- a/lib/dpif.c
> +++ b/lib/dpif.c
> @@ -566,12 +566,22 @@ dpif_get_dp_stats(const struct dpif *dpif, struct dpif_dp_stats *stats)
>  int
>  dpif_set_features(struct dpif *dpif, uint32_t new_features)
>  {
> -    int error = dpif->dpif_class->set_features(dpif, new_features);
> +    int error = dpif->dpif_class->set_features
> +                    ? dpif->dpif_class->set_features(dpif, new_features)
> +                    : EOPNOTSUPP;

The existing code in the same function at the top of the diff shows 
"dpif->dpif_class->set_features(dpif, new_features)" being called
directly. Is the original code missing NULL checks or does this patch
introduce a behavioral change by adding NULL checks where none existed
before?

> +uint32_t
> +dpif_get_features(struct dpif *dpif)
> +{
> +    return dpif->dpif_class->get_features
> +               ? dpif->dpif_class->get_features(dpif)
> +               : 0;
> +}

Should dpif_get_features() log the operation similar to how
dpif_set_features() calls log_operation()?

[ ... ]
diff mbox series

Patch

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index fa265b8fc..c09b1c7c7 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -9973,6 +9973,7 @@  const struct dpif_class dpif_netdev_class = {
     dpif_netdev_wait,
     dpif_netdev_get_stats,
     NULL,                      /* set_features */
+    NULL,                      /* get_features */
     dpif_netdev_port_add,
     dpif_netdev_port_del,
     dpif_netdev_port_set_config,
diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
index 04d7c8ed6..e161930be 100644
--- a/lib/dpif-netlink.c
+++ b/lib/dpif-netlink.c
@@ -121,6 +121,8 @@  static int dpif_netlink_dp_get(const struct dpif *,
                                struct ofpbuf **bufp);
 static int
 dpif_netlink_set_features(struct dpif *dpif_, uint32_t new_features);
+static uint32_t
+dpif_netlink_get_features(struct dpif *dpif_);
 
 static void
 dpif_netlink_unixctl_dispatch_mode(struct unixctl_conn *conn, int argc,
@@ -880,6 +882,14 @@  dpif_netlink_set_features(struct dpif *dpif_, uint32_t new_features)
     return error;
 }
 
+static uint32_t
+dpif_netlink_get_features(struct dpif *dpif_)
+{
+    struct dpif_netlink *dpif = dpif_netlink_cast(dpif_);
+
+    return dpif->user_features;
+}
+
 static const char *
 get_vport_type(const struct dpif_netlink_vport *vport)
 {
@@ -4373,6 +4383,7 @@  const struct dpif_class dpif_netlink_class = {
     NULL,                       /* wait */
     dpif_netlink_get_stats,
     dpif_netlink_set_features,
+    dpif_netlink_get_features,
     dpif_netlink_port_add,
     dpif_netlink_port_del,
     NULL,                       /* port_set_config */
diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h
index 02bcae12f..d27ad5165 100644
--- a/lib/dpif-provider.h
+++ b/lib/dpif-provider.h
@@ -227,6 +227,7 @@  struct dpif_class {
     int (*get_stats)(const struct dpif *dpif, struct dpif_dp_stats *stats);
 
     int (*set_features)(struct dpif *dpif, uint32_t user_features);
+    uint32_t (*get_features)(struct dpif *dpif);
 
     /* Adds 'netdev' as a new port in 'dpif'.  If '*port_no' is not
      * ODPP_NONE, attempts to use that as the port's port number.
diff --git a/lib/dpif.c b/lib/dpif.c
index e8bbd65b7..4b068b013 100644
--- a/lib/dpif.c
+++ b/lib/dpif.c
@@ -566,12 +566,22 @@  dpif_get_dp_stats(const struct dpif *dpif, struct dpif_dp_stats *stats)
 int
 dpif_set_features(struct dpif *dpif, uint32_t new_features)
 {
-    int error = dpif->dpif_class->set_features(dpif, new_features);
+    int error = dpif->dpif_class->set_features
+                    ? dpif->dpif_class->set_features(dpif, new_features)
+                    : EOPNOTSUPP;
 
     log_operation(dpif, "set_features", error);
     return error;
 }
 
+uint32_t
+dpif_get_features(struct dpif *dpif)
+{
+    return dpif->dpif_class->get_features
+               ? dpif->dpif_class->get_features(dpif)
+               : 0;
+}
+
 const char *
 dpif_port_open_type(const char *datapath_type, const char *port_type)
 {
diff --git a/lib/dpif.h b/lib/dpif.h
index f3301ae85..c1b0daa3e 100644
--- a/lib/dpif.h
+++ b/lib/dpif.h
@@ -440,6 +440,7 @@  struct dpif_dp_stats {
 int dpif_get_dp_stats(const struct dpif *, struct dpif_dp_stats *);
 
 int dpif_set_features(struct dpif *, uint32_t new_features);
+uint32_t dpif_get_features(struct dpif *dpif);
 
 
 /* Port operations. */