]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
option to disable swap in meminfo
authordm@localhost <dm@localhost>
Mon, 18 Feb 2019 05:17:30 +0000 (06:17 +0100)
committerSerge Hallyn <shallyn@cisco.com>
Tue, 19 Feb 2019 18:38:04 +0000 (12:38 -0600)
Signed-off-by: Dieter Maier <dma@web.de>
README.md
bindings.c
bindings.h
lxcfs.c

index 4c1434a247fe2fc22b9cd41373f76cc18a6ed699..7ff2ec94fef47bcdaefde2ae69eab415b7f7c3bb 100644 (file)
--- a/README.md
+++ b/README.md
@@ -60,3 +60,20 @@ send `SIGUSR1` to the pid of the running `LXCFS` process. This can be as simple
 as doing:
 
     kill -s USR1 $(pidof lxcfs)
+
+## Using with Docker
+
+```
+docker run -it -m 256m --memory-swap 256m \
+      -v /var/lib/lxcfs/proc/cpuinfo:/proc/cpuinfo:rw \
+      -v /var/lib/lxcfs/proc/diskstats:/proc/diskstats:rw \
+      -v /var/lib/lxcfs/proc/meminfo:/proc/meminfo:rw \
+      -v /var/lib/lxcfs/proc/stat:/proc/stat:rw \
+      -v /var/lib/lxcfs/proc/swaps:/proc/swaps:rw \
+      -v /var/lib/lxcfs/proc/uptime:/proc/uptime:rw \
+      ubuntu:18.04 /bin/bash
+ ```
+
+ In a system with swap enabled, the parameter "-u" can be used to set all values in "meminfo" that refer to the swap to 0.
+
+ sudo lxcfs -u /var/lib/lxcfs
index 097ca81573539f03987568bd5f8c1bcc853c0004..049418c3391bc59c8a6e42d4ef0313431c79203d 100644 (file)
@@ -3437,6 +3437,7 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
                struct fuse_file_info *fi)
 {
        struct fuse_context *fc = fuse_get_context();
+       struct lxcfs_opts *opts = (struct lxcfs_opts *) fuse_get_context()->private_data;
        struct file_info *d = (struct file_info *)fi->fh;
        char *cg;
        char *memusage_str = NULL, *memstat_str = NULL,
@@ -3517,18 +3518,24 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
                } else if (startswith(line, "MemAvailable:")) {
                        snprintf(lbuf, 100, "MemAvailable:   %8lu kB\n", memlimit - memusage + cached);
                        printme = lbuf;
-               } else if (startswith(line, "SwapTotal:") && memswlimit > 0) {
+               } else if (startswith(line, "SwapTotal:") && memswlimit > 0 && opts->swap_off == false) {
                        sscanf(line+sizeof("SwapTotal:")-1, "%lu", &hostswtotal);
                        if (hostswtotal < memswlimit)
                                memswlimit = hostswtotal;
                        snprintf(lbuf, 100, "SwapTotal:      %8lu kB\n", memswlimit);
                        printme = lbuf;
-               } else if (startswith(line, "SwapFree:") && memswlimit > 0 && memswusage > 0) {
+               } else if (startswith(line, "SwapTotal:") && opts->swap_off == true) {
+                       snprintf(lbuf, 100, "SwapTotal:      %8lu kB\n", 0UL);
+                       printme = lbuf;
+               } else if (startswith(line, "SwapFree:") && memswlimit > 0 && memswusage > 0 && opts->swap_off == false) {
                        unsigned long swaptotal = memswlimit,
                                        swapusage = memswusage - memusage,
                                        swapfree = swapusage < swaptotal ? swaptotal - swapusage : 0;
                        snprintf(lbuf, 100, "SwapFree:       %8lu kB\n", swapfree);
                        printme = lbuf;
+               } else if (startswith(line, "SwapFree:") && opts->swap_off == true) {
+                       snprintf(lbuf, 100, "SwapFree:       %8lu kB\n", 0UL);
+                       printme = lbuf;
                } else if (startswith(line, "Slab:")) {
                        snprintf(lbuf, 100, "Slab:        %8lu kB\n", 0UL);
                        printme = lbuf;
index f1a4627d489a6d7cd21a59e20008f5c8486ea3f9..20df78cf0872a21a9e8c13d95759bc7aacba182c 100644 (file)
@@ -7,6 +7,10 @@
 #define BASEDIR RUNTIME_PATH "/lxcfs/controllers"
 #define ROOTDIR RUNTIME_PATH "/lxcfs/root"
 
+struct lxcfs_opts {
+       bool swap_off;
+};
+
 extern int cg_write(const char *path, const char *buf, size_t size, off_t offset,
             struct fuse_file_info *fi);
 extern int cg_mkdir(const char *path, mode_t mode);
diff --git a/lxcfs.c b/lxcfs.c
index 76b3ea26f9ca2166f61e5c4de849b007b0240ca7..2247fcbcc2326b936b4c5371773f5dd581214455 100644 (file)
--- a/lxcfs.c
+++ b/lxcfs.c
@@ -792,9 +792,10 @@ static void usage()
 {
        fprintf(stderr, "Usage:\n");
        fprintf(stderr, "\n");
-       fprintf(stderr, "lxcfs [-f|-d] -l [-p pidfile] mountpoint\n");
+       fprintf(stderr, "lxcfs [-f|-d] -u -l -n [-p pidfile] mountpoint\n");
        fprintf(stderr, "  -f running foreground by default; -d enable debug output \n");
        fprintf(stderr, "  -l use loadavg \n");
+       fprintf(stderr, "  -u no swap \n");
        fprintf(stderr, "  Default pidfile is %s/lxcfs.pid\n", RUNTIME_PATH);
        fprintf(stderr, "lxcfs -h\n");
        exit(1);
@@ -904,6 +905,14 @@ int main(int argc, char *argv[])
        int nargs = 5, cnt = 0;
        char *newargv[6];
 
+       struct lxcfs_opts *opts;
+       opts = malloc(sizeof(struct lxcfs_opts));
+       if (opts == NULL) {
+               fprintf(stderr, "Error allocating memory for options.\n");
+               goto out;
+       }
+       opts->swap_off = false;
+
        /* accomodate older init scripts */
        swallow_arg(&argc, argv, "-s");
        swallow_arg(&argc, argv, "-f");
@@ -911,6 +920,9 @@ int main(int argc, char *argv[])
        if (swallow_arg(&argc, argv, "-l")) {
                load_use = true;
        }
+       if (swallow_arg(&argc, argv, "-u")) {
+               opts->swap_off = true;
+       }
        if (swallow_option(&argc, argv, "-o", &v)) {
                /* Parse multiple values */
                for (; (token = strtok_r(v, ",", &saveptr)); v = NULL) {
@@ -967,7 +979,7 @@ int main(int argc, char *argv[])
        if (load_use && start_loadavg() != 0)
                goto out;
 
-       if (!fuse_main(nargs, newargv, &lxcfs_ops, NULL))
+       if (!fuse_main(nargs, newargv, &lxcfs_ops, opts))
                ret = EXIT_SUCCESS;
        if (load_use)
                stop_loadavg();