diff mbox series

[v3,5/8] libxl: wire the libxl_device_nic 'mtu' value into xenstore

Message ID 20200811080202.31163-6-paul@xen.org (mailing list archive)
State New, archived
Headers show
Series tools: propogate MTU to vif frontends | expand

Commit Message

Paul Durrant Aug. 11, 2020, 8:01 a.m. UTC
From: Paul Durrant <pdurrant@amazon.com>

Currently the 'mtu' field of libxl_device_nic objects is effectively ignored:
It is set by libxl__device_nic_setdefault() to a slightly odd default value of
1492 but otherwise ignored.

This patch changes the default value to a more conventional 1500 and modifies
libxl__set_xenstore_nic() to write the value into an 'mtu' node in the
xenstore backend area (if it is a non-default value), as well as a read-only
node of the same name in the frontend area.

The backend node is used to set the value of 'mtu' in
libxl__nic_from_xenstore(), when retrieving the configuration.

NOTE: There is currently no way to set a non-default value of 'mtu', hence
      the backend node is never written. This, however, will be addressed
      by a subsequent patch.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
---
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Wei Liu <wl@xen.org>
Cc: Anthony PERARD <anthony.perard@citrix.com>

v3:
 - New in v3
---
 tools/libxl/libxl_nic.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/tools/libxl/libxl_nic.c b/tools/libxl/libxl_nic.c
index 07880b39e1..0e5d120ae9 100644
--- a/tools/libxl/libxl_nic.c
+++ b/tools/libxl/libxl_nic.c
@@ -53,13 +53,15 @@  int libxl_mac_to_device_nic(libxl_ctx *ctx, uint32_t domid,
     return rc;
 }
 
+#define LIBXL_DEVICE_NIC_MTU_DEFAULT 1500
+
 static int libxl__device_nic_setdefault(libxl__gc *gc, uint32_t domid,
                                         libxl_device_nic *nic, bool hotplug)
 {
     int rc;
 
     if (!nic->mtu)
-        nic->mtu = 1492;
+        nic->mtu = LIBXL_DEVICE_NIC_MTU_DEFAULT;
     if (!nic->model) {
         nic->model = strdup("rtl8139");
         if (!nic->model) return ERROR_NOMEM;
@@ -223,6 +225,11 @@  static int libxl__set_xenstore_nic(libxl__gc *gc, uint32_t domid,
                             nic->rate_interval_usecs));
     }
 
+    if (nic->mtu != LIBXL_DEVICE_NIC_MTU_DEFAULT) {
+        flexarray_append(back, "mtu");
+        flexarray_append(back, GCSPRINTF("%u", nic->mtu));
+    }
+    
     flexarray_append(back, "bridge");
     flexarray_append(back, libxl__strdup(gc, nic->bridge));
     flexarray_append(back, "handle");
@@ -237,6 +244,9 @@  static int libxl__set_xenstore_nic(libxl__gc *gc, uint32_t domid,
     flexarray_append(front, GCSPRINTF(
                                     LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac)));
 
+    flexarray_append(ro_front, "mtu");
+    flexarray_append(ro_front, GCSPRINTF("%u", nic->mtu));
+
     return 0;
 }
 
@@ -275,7 +285,20 @@  static int libxl__nic_from_xenstore(libxl__gc *gc, const char *libxl_path,
     rc = libxl__backendpath_parse_domid(gc, tmp, &nic->backend_domid);
     if (rc) goto out;
 
-    /* nic->mtu = */
+    rc = libxl__xs_read_checked(gc, XBT_NULL,
+                                GCSPRINTF("%s/mtu", libxl_path), &tmp);
+    if (rc) goto out;
+    if (tmp) {
+        char *endptr;
+
+        nic->mtu = strtol(tmp, &endptr, 10);
+        if (*endptr != '\0') {
+            rc = ERROR_INVAL;
+            goto out;
+        }
+    } else {
+        nic->mtu = LIBXL_DEVICE_NIC_MTU_DEFAULT;
+    }
 
     rc = libxl__xs_read_checked(gc, XBT_NULL,
                                 GCSPRINTF("%s/mac", libxl_path), &tmp);