[Libguestfs] [PATCH supermin] Add support for a DAX root filesystem.

Richard W.M. Jones rjones at redhat.com
Mon May 16 18:09:45 UTC 2016


With these changes you can provide an ext4 root filesystem on a
virtual NVDIMM.  The filesystem will be mounted using DAX, so files
are directly read, mmapped etc from the underlying host file, saving
guest memory both directly and in the guest page cache.
---
 init/init.c        | 19 ++++++++++++++++---
 src/ext2_initrd.ml |  3 +++
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/init/init.c b/init/init.c
index 3014de2..106be02 100644
--- a/init/init.c
+++ b/init/init.c
@@ -154,11 +154,14 @@ main ()
    */
   char *root, *path;
   size_t len;
+  int dax = 0;
   root = strstr (cmdline, "root=");
   if (root) {
     root += 5;
     if (strncmp (root, "/dev/", 5) == 0)
       root += 5;
+    if (strncmp (root, "pmem", 4) == 0)
+      dax = 1;
     len = strcspn (root, " ");
     root[len] = '\0';
 
@@ -243,10 +246,20 @@ main ()
     exit (EXIT_FAILURE);
   }
 
+  /* Construct the filesystem mount options. */
+  const char *mount_options = "";
+  if (dax)
+    mount_options = "dax";
+
   /* Mount new root and chroot to it. */
-  if (!quiet)
-    fprintf (stderr, "supermin: mounting new root on /root\n");
-  if (mount ("/dev/root", "/root", "ext2", MS_NOATIME, "") == -1) {
+  if (!quiet) {
+    fprintf (stderr, "supermin: mounting new root on /root");
+    if (mount_options[0] != '\0')
+      fprintf (stderr, " (%s)", mount_options);
+    fprintf (stderr, "\n");
+  }
+  if (mount ("/dev/root", "/root", "ext2", MS_NOATIME,
+             mount_options) == -1) {
     perror ("mount: /root");
     exit (EXIT_FAILURE);
   }
diff --git a/src/ext2_initrd.ml b/src/ext2_initrd.ml
index 55a38d0..dd7d5a3 100644
--- a/src/ext2_initrd.ml
+++ b/src/ext2_initrd.ml
@@ -45,6 +45,9 @@ let kmods = [
   "crc*.ko*";
   "libcrc*.ko*";
   "ibmvscsic.ko*";
+  "nd_pmem.ko*";
+  "nd_btt.ko*";
+  "nfit.ko*";
 ]
 
 (* A blacklist of kmods which match the above patterns, but which we
-- 
2.7.4




More information about the Libguestfs mailing list