Skip to contentSkip to conversation

libxc: implement gnttab.set_max_grants for Linux

PATCH Superseded Jan Beulich 2 participants 3 messages May 11, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxc: implement gnttab.set_max_grants for Linux

Legacy (non-pvops) gntdev drivers may require this operation to be performed when the number of grants intended to be used simultaneously exceeds a certain driver specific default limit, and qemu's qdisk driver is an example of needing to do so.

tools/libxc/xc_linux_osdep.c +22 -0
@@ -541,6 +541,27 @@ static int linux_gnttab_close(xc_gnttab 
     return close(fd);
 }
 
+static int linux_gnttab_set_max_grants(xc_gnttab *xch, xc_osdep_handle h,
+                                       uint32_t count)
+{
+    int fd = (int)h, rc;
+    struct ioctl_gntdev_set_max_grants max_grants = { .count = count };
+
+    rc = ioctl(fd, IOCTL_GNTDEV_SET_MAX_GRANTS, &max_grants);
+    if (rc) {
+        /*
+         * Newer (e.g. pv-ops) kernels don't implement this IOCTL,
+         * so ignore the resulting specific failure.
+         */
+        if (errno == ENOTTY)
+            rc = 0;
+        else
+            PERROR("linux_gnttab_set_max_grants: ioctl SET_MAX_GRANTS failed");
+    }
+
+    return rc;
+}
+
 static void *linux_gnttab_grant_map(xc_gnttab *xch, xc_osdep_handle h,
                                     uint32_t count, int flags, int prot,
                                     uint32_t *domids, uint32_t *refs,
@@ -680,6 +701,7 @@ static struct xc_osdep_ops linux_gnttab_
     .close = &linux_gnttab_close,
 
     .u.gnttab = {
+        .set_max_grants = linux_gnttab_set_max_grants,
         .grant_map = &linux_gnttab_grant_map,
         .munmap = &linux_gnttab_munmap,
     },

libxc: implement gnttab.set_max_grants for Linux

Legacy (non-pvops) gntdev drivers may require this operation to be performed when the number of grants intended to be used simultaneously exceeds a certain driver specific default limit, and qemu's qdisk driver is an example of needing to do so.

tools/libxc/xc_linux_osdep.c +22 -0
@@ -541,6 +541,27 @@ static int linux_gnttab_close(xc_gnttab 
     return close(fd);
 }
 
+static int linux_gnttab_set_max_grants(xc_gnttab *xch, xc_osdep_handle h,
+                                       uint32_t count)
+{
+    int fd = (int)h, rc;
+    struct ioctl_gntdev_set_max_grants max_grants = { .count = count };
+
+    rc = ioctl(fd, IOCTL_GNTDEV_SET_MAX_GRANTS, &max_grants);
+    if (rc) {
+        /*
+         * Newer (e.g. pv-ops) kernels don't implement this IOCTL,
+         * so ignore the resulting specific failure.
+         */
+        if (errno == ENOTTY)
+            rc = 0;
+        else
+            PERROR("linux_gnttab_set_max_grants: ioctl SET_MAX_GRANTS failed");
+    }
+
+    return rc;
+}
+
 static void *linux_gnttab_grant_map(xc_gnttab *xch, xc_osdep_handle h,
                                     uint32_t count, int flags, int prot,
                                     uint32_t *domids, uint32_t *refs,
@@ -680,6 +701,7 @@ static struct xc_osdep_ops linux_gnttab_
     .close = &linux_gnttab_close,
 
     .u.gnttab = {
+        .set_max_grants = linux_gnttab_set_max_grants,
         .grant_map = &linux_gnttab_grant_map,
         .munmap = &linux_gnttab_munmap,
     },

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#1 lore raw

tools/libxc/xc_linux_osdep.c static int linux_gnttab_close(xc_gnttab · line 555

Quoted 4 lines · Jan Beulich
tools/libxc/xc_linux_osdep.c +4 -0
+        /*
+         * Newer (e.g. pv-ops) kernels don't implement this IOCTL,
+         * so ignore the resulting specific failure.
+         */ 

pvops doesn't implement this ioctl because it is already more dynamic and therefore setting a max unnecessary?

(I'm pretty sure yes, but just wanted to confirm we shouldn't be fixing anything on the pvops side).

#2 lore raw
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Ian Campbell

tools/libxc/xc_linux_osdep.c static int linux_gnttab_close(xc_gnttab · line 555

Quoted 4 lines · Jan Beulich
tools/libxc/xc_linux_osdep.c +4 -0
+        /*
+         * Newer (e.g. pv-ops) kernels don't implement this IOCTL,
+         * so ignore the resulting specific failure.
+         */ 
Quoted 5 lines

pvops doesn't implement this ioctl because it is already more dynamic and therefore setting a max unnecessary?

(I'm pretty sure yes, but just wanted to confirm we shouldn't be fixing anything on the pvops side).

Correct. The only adjustment I would consider worth doing is to accept the unnecessary ioctl without producing an error or logging any message (perhaps one could in fact return an error for insanely high input values).

Jan