[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging] libxl: wire the libxl_device_nic 'mtu' value into xenstore



commit 22cdff931d1239156dea74d8b4a50e91e44c5817
Author:     Paul Durrant <pdurrant@xxxxxxxxxx>
AuthorDate: Tue Aug 11 09:01:59 2020 +0100
Commit:     Wei Liu <wl@xxxxxxx>
CommitDate: Thu Aug 27 10:04:17 2020 +0000

    libxl: wire the libxl_device_nic 'mtu' value into xenstore
    
    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@xxxxxxxxxx>
    Acked-by: Wei Liu <wl@xxxxxxx>
---
 tools/libxl/libxl_nic.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

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);
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.