1 /* SPDX-License-Identifier: LGPL-2.1+ */
10 #ifndef FUSE_USE_VERSION
11 #define FUSE_USE_VERSION 30
14 #ifndef FUSE_USE_VERSION
15 #define FUSE_USE_VERSION 26
19 #define _FILE_OFFSET_BITS 64
21 #define __STDC_FORMAT_MACROS
39 #include <linux/magic.h>
40 #include <linux/sched.h>
41 #include <sys/epoll.h>
43 #include <sys/mount.h>
44 #include <sys/param.h>
45 #include <sys/socket.h>
46 #include <sys/syscall.h>
47 #include <sys/sysinfo.h>
51 #include "cgroup_fuse.h"
52 #include "cgroups/cgroup.h"
53 #include "cgroups/cgroup_utils.h"
54 #include "cpuset_parse.h"
55 #include "lxcfs_fuse_compat.h"
56 #include "memory_utils.h"
57 #include "proc_loadavg.h"
58 #include "proc_cpuview.h"
62 uint64_t hierarchical_memory_limit
;
63 uint64_t hierarchical_memsw_limit
;
66 uint64_t total_rss_huge
;
68 uint64_t total_mapped_file
;
70 uint64_t total_writeback
;
72 uint64_t total_pgpgin
;
73 uint64_t total_pgpgout
;
74 uint64_t total_pgfault
;
75 uint64_t total_pgmajfault
;
76 uint64_t total_inactive_anon
;
77 uint64_t total_active_anon
;
78 uint64_t total_inactive_file
;
79 uint64_t total_active_file
;
80 uint64_t total_unevictable
;
83 __lxcfs_fuse_ops
int proc_getattr(const char *path
, struct stat
*sb
)
87 memset(sb
, 0, sizeof(struct stat
));
88 if (clock_gettime(CLOCK_REALTIME
, &now
) < 0)
91 sb
->st_uid
= sb
->st_gid
= 0;
92 sb
->st_atim
= sb
->st_mtim
= sb
->st_ctim
= now
;
93 if (strcmp(path
, "/proc") == 0) {
94 sb
->st_mode
= S_IFDIR
| 00555;
99 if (strcmp(path
, "/proc/meminfo") == 0 ||
100 strcmp(path
, "/proc/cpuinfo") == 0 ||
101 strcmp(path
, "/proc/uptime") == 0 ||
102 strcmp(path
, "/proc/stat") == 0 ||
103 strcmp(path
, "/proc/diskstats") == 0 ||
104 strcmp(path
, "/proc/swaps") == 0 ||
105 strcmp(path
, "/proc/loadavg") == 0) {
107 sb
->st_mode
= S_IFREG
| 00444;
115 __lxcfs_fuse_ops
int proc_readdir(const char *path
, void *buf
,
116 fuse_fill_dir_t filler
, off_t offset
,
117 struct fuse_file_info
*fi
)
119 if (DIR_FILLER(filler
, buf
, ".", NULL
, 0) != 0 ||
120 DIR_FILLER(filler
, buf
, "..", NULL
, 0) != 0 ||
121 DIR_FILLER(filler
, buf
, "cpuinfo", NULL
, 0) != 0 ||
122 DIR_FILLER(filler
, buf
, "meminfo", NULL
, 0) != 0 ||
123 DIR_FILLER(filler
, buf
, "stat", NULL
, 0) != 0 ||
124 DIR_FILLER(filler
, buf
, "uptime", NULL
, 0) != 0 ||
125 DIR_FILLER(filler
, buf
, "diskstats", NULL
, 0) != 0 ||
126 DIR_FILLER(filler
, buf
, "swaps", NULL
, 0) != 0 ||
127 DIR_FILLER(filler
, buf
, "loadavg", NULL
, 0) != 0)
133 static off_t
get_procfile_size(const char *path
)
135 __do_fclose
FILE *f
= NULL
;
136 __do_free
char *line
= NULL
;
138 ssize_t sz
, answer
= 0;
140 f
= fopen(path
, "re");
144 while ((sz
= getline(&line
, &len
, f
)) != -1)
150 __lxcfs_fuse_ops
int proc_open(const char *path
, struct fuse_file_info
*fi
)
152 __do_free
struct file_info
*info
= NULL
;
155 if (strcmp(path
, "/proc/meminfo") == 0)
156 type
= LXC_TYPE_PROC_MEMINFO
;
157 else if (strcmp(path
, "/proc/cpuinfo") == 0)
158 type
= LXC_TYPE_PROC_CPUINFO
;
159 else if (strcmp(path
, "/proc/uptime") == 0)
160 type
= LXC_TYPE_PROC_UPTIME
;
161 else if (strcmp(path
, "/proc/stat") == 0)
162 type
= LXC_TYPE_PROC_STAT
;
163 else if (strcmp(path
, "/proc/diskstats") == 0)
164 type
= LXC_TYPE_PROC_DISKSTATS
;
165 else if (strcmp(path
, "/proc/swaps") == 0)
166 type
= LXC_TYPE_PROC_SWAPS
;
167 else if (strcmp(path
, "/proc/loadavg") == 0)
168 type
= LXC_TYPE_PROC_LOADAVG
;
172 info
= zalloc(sizeof(*info
));
178 info
->buflen
= get_procfile_size(path
) + BUF_RESERVE_SIZE
;
180 info
->buf
= zalloc(info
->buflen
);
183 /* set actual size to buffer size */
184 info
->size
= info
->buflen
;
186 fi
->fh
= PTR_TO_UINT64(move_ptr(info
));
190 __lxcfs_fuse_ops
int proc_access(const char *path
, int mask
)
192 if (strcmp(path
, "/proc") == 0 && access(path
, R_OK
) == 0)
195 /* these are all read-only */
196 if ((mask
& ~R_OK
) != 0)
202 __lxcfs_fuse_ops
int proc_release(const char *path
, struct fuse_file_info
*fi
)
204 do_release_file_info(fi
);
208 static uint64_t get_memlimit(const char *cgroup
, bool swap
)
210 __do_free
char *memlimit_str
= NULL
;
211 uint64_t memlimit
= 0;
215 ret
= cgroup_ops
->get_memory_swap_max(cgroup_ops
, cgroup
, &memlimit_str
);
217 ret
= cgroup_ops
->get_memory_max(cgroup_ops
, cgroup
, &memlimit_str
);
218 if (ret
> 0 && memlimit_str
[0] && safe_uint64(memlimit_str
, &memlimit
, 10) < 0)
219 lxcfs_error("Failed to convert memlimit %s", memlimit_str
);
225 * This function taken from glibc-2.32, as POSIX dirname("/some-dir") will
226 * return "/some-dir" as opposed to "/", which breaks `get_min_memlimit()`
228 static char *gnu_dirname(char *path
)
230 static const char dot
[] = ".";
234 last_slash
= path
!= NULL
? strrchr(path
, '/') : NULL
;
236 if (last_slash
!= NULL
&& last_slash
!= path
&& last_slash
[1] == '\0') {
237 /* Determine whether all remaining characters are slashes. */
240 for (runp
= last_slash
; runp
!= path
; --runp
)
244 /* The '/' is the last character, we have to look further. */
246 last_slash
= memrchr(path
, '/', runp
- path
);
249 if (last_slash
!= NULL
) {
250 /* Determine whether all remaining characters are slashes. */
253 for (runp
= last_slash
; runp
!= path
; --runp
)
257 /* Terminate the path. */
260 * The last slash is the first character in the string.
261 * We have to return "/". As a special case we have to
262 * return "//" if there are exactly two slashes at the
263 * beginning of the string. See XBD 4.10 Path Name
264 * Resolution for more information
266 if (last_slash
== path
+ 1)
269 last_slash
= path
+ 1;
273 last_slash
[0] = '\0';
276 * This assignment is ill-designed but the XPG specs require to
277 * return a string containing "." in any case no directory part
278 * is found and so a static and constant string is required.
286 static uint64_t get_min_memlimit(const char *cgroup
, bool swap
)
288 __do_free
char *copy
= NULL
;
289 uint64_t memlimit
= 0, retlimit
= 0;
291 copy
= strdup(cgroup
);
293 return log_error_errno(0, ENOMEM
, "Failed to allocate memory");
295 retlimit
= get_memlimit(copy
, swap
);
298 * If the cgroup doesn't start with / (probably won't happen), dirname()
299 * will terminate with "" instead of "/"
301 while (*copy
&& strcmp(copy
, "/") != 0) {
304 it
= gnu_dirname(it
);
305 memlimit
= get_memlimit(it
, swap
);
306 if (memlimit
> 0 && memlimit
< retlimit
)
313 static inline bool startswith(const char *line
, const char *pref
)
315 return strncmp(line
, pref
, strlen(pref
)) == 0;
318 static int proc_swaps_read(char *buf
, size_t size
, off_t offset
,
319 struct fuse_file_info
*fi
)
321 __do_free
char *cgroup
= NULL
, *memusage_str
= NULL
,
322 *memswusage_str
= NULL
, *memswpriority_str
= NULL
;
323 struct fuse_context
*fc
= fuse_get_context();
324 struct lxcfs_opts
*opts
= (struct lxcfs_opts
*)fuse_get_context()->private_data
;
325 bool wants_swap
= opts
&& !opts
->swap_off
&& liblxcfs_can_use_swap();
326 struct file_info
*d
= INTTYPE_TO_PTR(fi
->fh
);
327 uint64_t memswlimit
= 0, memlimit
= 0, memusage
= 0, memswusage
= 0,
328 swtotal
= 0, swfree
= 0, swusage
= 0, memswpriority
= 1;
329 ssize_t total_len
= 0;
331 char *cache
= d
->buf
;
337 if (offset
> d
->size
)
343 left
= d
->size
- offset
;
344 total_len
= left
> size
? size
: left
;
345 memcpy(buf
, cache
+ offset
, total_len
);
350 pid_t initpid
= lookup_initpid_in_store(fc
->pid
);
351 if (initpid
<= 1 || is_shared_pidns(initpid
))
354 cgroup
= get_pid_cgroup(initpid
, "memory");
356 return read_file_fuse("/proc/swaps", buf
, size
, d
);
357 prune_init_slice(cgroup
);
359 memlimit
= get_min_memlimit(cgroup
, false);
361 ret
= cgroup_ops
->get_memory_current(cgroup_ops
, cgroup
, &memusage_str
);
365 if (safe_uint64(memusage_str
, &memusage
, 10) < 0)
366 lxcfs_error("Failed to convert memusage %s", memusage_str
);
369 memswlimit
= get_min_memlimit(cgroup
, true);
370 if (memswlimit
> 0) {
371 ret
= cgroup_ops
->get_memory_swap_current(cgroup_ops
, cgroup
, &memswusage_str
);
372 if (ret
>= 0 && safe_uint64(memswusage_str
, &memswusage
, 10) == 0) {
373 if (memlimit
> memswlimit
)
376 swtotal
= (memswlimit
- memlimit
) / 1024;
377 if (memusage
> memswusage
|| swtotal
== 0)
380 swusage
= (memswusage
- memusage
) / 1024;
381 if (swtotal
>= swusage
)
382 swfree
= swtotal
- swusage
;
385 ret
= cgroup_ops
->get_memory_swappiness(cgroup_ops
, cgroup
, &memswpriority_str
);
387 safe_uint64(memswpriority_str
, &memswpriority
, 10);
391 total_len
= snprintf(d
->buf
, d
->size
, "Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
393 /* When no mem + swap limit is specified or swapaccount=0*/
395 __do_free
char *line
= NULL
;
396 __do_free
void *fopen_cache
= NULL
;
397 __do_fclose
FILE *f
= NULL
;
400 f
= fopen_cached("/proc/meminfo", "re", &fopen_cache
);
404 while (getline(&line
, &linelen
, f
) != -1) {
405 if (startswith(line
, "SwapTotal:"))
406 sscanf(line
, "SwapTotal: %8" PRIu64
" kB", &swtotal
);
407 else if (startswith(line
, "SwapFree:"))
408 sscanf(line
, "SwapFree: %8" PRIu64
" kB", &swfree
);
412 // When swappiness is 0, pretend we can't swap.
413 if (memswpriority
== 0) {
418 l
= snprintf(d
->buf
+ total_len
, d
->size
- total_len
,
419 "none%*svirtual\t\t%" PRIu64
"\t%" PRIu64
"\t0\n",
420 36, " ", swtotal
, swusage
);
424 if (total_len
< 0 || l
< 0)
425 return log_error(0, "Failed writing to cache");
428 d
->size
= (int)total_len
;
430 if (total_len
> size
)
432 memcpy(buf
, d
->buf
, total_len
);
437 static void get_blkio_io_value(char *str
, unsigned major
, unsigned minor
,
438 char *iotype
, uint64_t *v
)
445 snprintf(key
, 32, "%u:%u %s", major
, minor
, iotype
);
450 if (startswith(str
, key
)) {
451 sscanf(str
+ len
, "%lu", v
);
454 eol
= strchr(str
, '\n');
461 struct lxcfs_diskstats
{
462 unsigned int major
; /* 1 - major number */
463 unsigned int minor
; /* 2 - minor mumber */
464 char dev_name
[72]; /* 3 - device name */
465 uint64_t read
; /* 4 - reads completed successfully */
466 uint64_t read_merged
; /* 5 - reads merged */
467 uint64_t read_sectors
; /* 6 - sectors read */
468 uint64_t read_ticks
; /* 7 - time spent reading (ms) */
469 uint64_t write
; /* 8 - writes completed */
470 uint64_t write_merged
; /* 9 - writes merged */
471 uint64_t write_sectors
; /* 10 - sectors written */
472 uint64_t write_ticks
; /* 11 - time spent writing (ms) */
473 uint64_t ios_pgr
; /* 12 - I/Os currently in progress */
474 uint64_t total_ticks
; /* 13 - time spent doing I/Os (ms) */
475 uint64_t rq_ticks
; /* 14 - weighted time spent doing I/Os (ms) */
476 uint64_t discard
; /* 15 - discards completed successfully (4.18+) */
477 uint64_t discard_merged
; /* 16 - discards merged (4.18+) */
478 uint64_t discard_sectors
; /* 17 - sectors discarded (4.18+) */
479 uint64_t discard_ticks
; /* 18 - time spent discarding (4.18+) */
482 static int proc_diskstats_read(char *buf
, size_t size
, off_t offset
,
483 struct fuse_file_info
*fi
)
485 __do_free
char *cg
= NULL
, *io_serviced_str
= NULL
,
486 *io_merged_str
= NULL
, *io_service_bytes_str
= NULL
,
487 *io_wait_time_str
= NULL
, *io_service_time_str
= NULL
,
489 __do_free
void *fopen_cache
= NULL
;
490 __do_fclose
FILE *f
= NULL
;
491 struct fuse_context
*fc
= fuse_get_context();
492 struct file_info
*d
= INTTYPE_TO_PTR(fi
->fh
);
493 struct lxcfs_diskstats stats
= {};
495 uint64_t read_service_time
, write_service_time
, discard_service_time
, read_wait_time
,
496 write_wait_time
, discard_wait_time
;
497 char *cache
= d
->buf
;
498 size_t cache_size
= d
->buflen
;
499 size_t linelen
= 0, total_len
= 0;
506 if (offset
> d
->size
)
512 left
= d
->size
- offset
;
513 total_len
= left
> size
? size
: left
;
514 memcpy(buf
, cache
+ offset
, total_len
);
519 pid_t initpid
= lookup_initpid_in_store(fc
->pid
);
520 if (initpid
<= 1 || is_shared_pidns(initpid
))
523 cg
= get_pid_cgroup(initpid
, "blkio");
525 return read_file_fuse("/proc/diskstats", buf
, size
, d
);
526 prune_init_slice(cg
);
528 ret
= cgroup_ops
->get_io_serviced(cgroup_ops
, cg
, &io_serviced_str
);
530 if (ret
== -EOPNOTSUPP
)
531 return read_file_fuse("/proc/diskstats", buf
, size
, d
);
534 ret
= cgroup_ops
->get_io_merged(cgroup_ops
, cg
, &io_merged_str
);
536 if (ret
== -EOPNOTSUPP
)
537 return read_file_fuse("/proc/diskstats", buf
, size
, d
);
540 ret
= cgroup_ops
->get_io_service_bytes(cgroup_ops
, cg
, &io_service_bytes_str
);
542 if (ret
== -EOPNOTSUPP
)
543 return read_file_fuse("/proc/diskstats", buf
, size
, d
);
546 ret
= cgroup_ops
->get_io_wait_time(cgroup_ops
, cg
, &io_wait_time_str
);
548 if (ret
== -EOPNOTSUPP
)
549 return read_file_fuse("/proc/diskstats", buf
, size
, d
);
552 ret
= cgroup_ops
->get_io_service_time(cgroup_ops
, cg
, &io_service_time_str
);
554 if (ret
== -EOPNOTSUPP
)
555 return read_file_fuse("/proc/diskstats", buf
, size
, d
);
558 f
= fopen_cached("/proc/diskstats", "re", &fopen_cache
);
562 while (getline(&line
, &linelen
, f
) != -1) {
566 i
= sscanf(line
, "%u %u %71s", &stats
.major
, &stats
.minor
, stats
.dev_name
);
570 get_blkio_io_value(io_serviced_str
, stats
.major
, stats
.minor
, "Read", &stats
.read
);
571 get_blkio_io_value(io_serviced_str
, stats
.major
, stats
.minor
, "Write", &stats
.write
);
572 get_blkio_io_value(io_serviced_str
, stats
.major
, stats
.minor
, "Discard", &stats
.discard
);
574 get_blkio_io_value(io_merged_str
, stats
.major
, stats
.minor
, "Read", &stats
.read_merged
);
575 get_blkio_io_value(io_merged_str
, stats
.major
, stats
.minor
, "Write", &stats
.write_merged
);
576 get_blkio_io_value(io_merged_str
, stats
.major
, stats
.minor
, "Discard", &stats
.discard_merged
);
578 get_blkio_io_value(io_service_bytes_str
, stats
.major
, stats
.minor
, "Read", &stats
.read_sectors
);
579 stats
.read_sectors
= stats
.read_sectors
/ 512;
580 get_blkio_io_value(io_service_bytes_str
, stats
.major
, stats
.minor
, "Write", &stats
.write_sectors
);
581 stats
.write_sectors
= stats
.write_sectors
/ 512;
582 get_blkio_io_value(io_service_bytes_str
, stats
.major
, stats
.minor
, "Discard", &stats
.discard_sectors
);
583 stats
.discard_sectors
= stats
.discard_sectors
/ 512;
585 get_blkio_io_value(io_service_time_str
, stats
.major
, stats
.minor
, "Read", &read_service_time
);
586 read_service_time
= read_service_time
/ 1000000;
587 get_blkio_io_value(io_wait_time_str
, stats
.major
, stats
.minor
, "Read", &read_wait_time
);
588 read_wait_time
= read_wait_time
/ 1000000;
589 stats
.read_ticks
= read_service_time
+ read_wait_time
;
591 get_blkio_io_value(io_service_time_str
, stats
.major
, stats
.minor
, "Write", &write_service_time
);
592 write_service_time
= write_service_time
/ 1000000;
593 get_blkio_io_value(io_wait_time_str
, stats
.major
, stats
.minor
, "Write", &write_wait_time
);
594 write_wait_time
= write_wait_time
/ 1000000;
595 stats
.write_ticks
= write_service_time
+ write_wait_time
;
597 get_blkio_io_value(io_service_time_str
, stats
.major
, stats
.minor
, "Discard", &discard_service_time
);
598 discard_service_time
= discard_service_time
/ 1000000;
599 get_blkio_io_value(io_wait_time_str
, stats
.major
, stats
.minor
, "Discard", &discard_wait_time
);
600 discard_wait_time
= discard_wait_time
/ 1000000;
601 stats
.discard_ticks
= discard_service_time
+ discard_wait_time
;
603 get_blkio_io_value(io_service_time_str
, stats
.major
, stats
.minor
, "Total", &stats
.total_ticks
);
604 stats
.total_ticks
= stats
.total_ticks
/ 1000000;
606 memset(lbuf
, 0, 256);
607 if (stats
.read
|| stats
.write
|| stats
.read_merged
|| stats
.write_merged
||
608 stats
.read_sectors
|| stats
.write_sectors
|| stats
.read_ticks
||
609 stats
.write_ticks
|| stats
.ios_pgr
|| stats
.total_ticks
|| stats
.rq_ticks
||
610 stats
.discard_merged
|| stats
.discard_sectors
|| stats
.discard_ticks
)
611 snprintf(lbuf
, 256, "%u %u %s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
626 stats
.discard_merged
,
627 stats
.discard_sectors
,
628 stats
.discard_ticks
);
632 l
= snprintf(cache
, cache_size
, "%s", lbuf
);
634 return log_error(0, "Failed to write cache");
636 return log_error(0, "Write to cache was truncated");
645 if (total_len
> size
)
647 memcpy(buf
, d
->buf
, total_len
);
653 static inline void iwashere(void)
655 mknod("/tmp/lxcfs-iwashere", S_IFREG
, 0644);
660 * This function retrieves the busy time of a group of tasks by looking at
661 * cpuacct.usage. Unfortunately, this only makes sense when the container has
662 * been given it's own cpuacct cgroup. If not, this function will take the busy
663 * time of all other taks that do not actually belong to the container into
664 * account as well. If someone has a clever solution for this please send a
667 static double get_reaper_busy(pid_t task
)
669 __do_free
char *cgroup
= NULL
, *usage_str
= NULL
;
673 initpid
= lookup_initpid_in_store(task
);
677 cgroup
= get_pid_cgroup(initpid
, "cpuacct");
680 prune_init_slice(cgroup
);
682 if (!cgroup_ops
->get(cgroup_ops
, "cpuacct", cgroup
, "cpuacct.usage", &usage_str
))
685 if (safe_uint64(usage_str
, &usage
, 10) < 0)
686 lxcfs_error("Failed to convert usage %s", usage_str
);
688 return ((double)usage
/ 1000000000);
691 static uint64_t get_reaper_start_time(pid_t pid
)
693 __do_free
void *fopen_cache
= NULL
;
694 __do_fclose
FILE *f
= NULL
;
697 char path
[STRLITERALLEN("/proc/") + LXCFS_NUMSTRLEN64
+
698 STRLITERALLEN("/stat") + 1];
701 qpid
= lookup_initpid_in_store(pid
);
703 return ret_errno(EINVAL
);
705 ret
= snprintf(path
, sizeof(path
), "/proc/%d/stat", qpid
);
706 if (ret
< 0 || (size_t)ret
>= sizeof(path
))
707 return ret_errno(EINVAL
);
709 f
= fopen_cached(path
, "re", &fopen_cache
);
711 return ret_errno(EINVAL
);
713 /* Note that the *scanf() argument supression requires that length
714 * modifiers such as "l" are omitted. Otherwise some compilers will yell
715 * at us. It's like telling someone you're not married and then asking
716 * if you can bring your wife to the party.
718 ret
= fscanf(f
, "%*d " /* (1) pid %d */
719 "%*s " /* (2) comm %s */
720 "%*c " /* (3) state %c */
721 "%*d " /* (4) ppid %d */
722 "%*d " /* (5) pgrp %d */
723 "%*d " /* (6) session %d */
724 "%*d " /* (7) tty_nr %d */
725 "%*d " /* (8) tpgid %d */
726 "%*u " /* (9) flags %u */
727 "%*u " /* (10) minflt %lu */
728 "%*u " /* (11) cminflt %lu */
729 "%*u " /* (12) majflt %lu */
730 "%*u " /* (13) cmajflt %lu */
731 "%*u " /* (14) utime %lu */
732 "%*u " /* (15) stime %lu */
733 "%*d " /* (16) cutime %ld */
734 "%*d " /* (17) cstime %ld */
735 "%*d " /* (18) priority %ld */
736 "%*d " /* (19) nice %ld */
737 "%*d " /* (20) num_threads %ld */
738 "%*d " /* (21) itrealvalue %ld */
739 "%" PRIu64
, /* (22) starttime %llu */
742 return ret_errno(EINVAL
);
744 return ret_set_errno(starttime
, 0);
747 static double get_reaper_start_time_in_sec(pid_t pid
)
749 uint64_t clockticks
, ticks_per_sec
;
753 clockticks
= get_reaper_start_time(pid
);
755 return log_debug(0, "Failed to retrieve start time of pid %d", pid
);
757 ret
= sysconf(_SC_CLK_TCK
);
759 return log_debug(0, "Failed to determine number of clock ticks in a second");
761 ticks_per_sec
= (uint64_t)ret
;
762 res
= (double)clockticks
/ ticks_per_sec
;
766 static double get_reaper_age(pid_t pid
)
769 double procstart
, procage
;
772 * We need to substract the time the process has started since system
773 * boot minus the time when the system has started to get the actual
776 procstart
= get_reaper_start_time_in_sec(pid
);
780 struct timespec spec
;
782 ret
= clock_gettime(CLOCK_BOOTTIME
, &spec
);
786 uptime_ms
= (spec
.tv_sec
* 1000) + (spec
.tv_nsec
* 1e-6);
787 procage
= (uptime_ms
- (procstart
* 1000)) / 1000;
794 * We read /proc/uptime and reuse its second field.
795 * For the first field, we use the mtime for the reaper for
796 * the calling pid as returned by getreaperage
798 static int proc_uptime_read(char *buf
, size_t size
, off_t offset
,
799 struct fuse_file_info
*fi
)
801 struct fuse_context
*fc
= fuse_get_context();
802 struct file_info
*d
= INTTYPE_TO_PTR(fi
->fh
);
803 char *cache
= d
->buf
;
804 ssize_t total_len
= 0, ret
= 0;
805 double busytime
, idletime
, reaperage
;
814 if (offset
> d
->size
)
820 left
= d
->size
- offset
;
821 total_len
= left
> size
? size
: left
;
822 memcpy(buf
, cache
+ offset
, total_len
);
827 reaperage
= get_reaper_age(fc
->pid
);
829 * To understand why this is done, please read the comment to the
830 * get_reaper_busy() function.
832 idletime
= reaperage
;
833 busytime
= get_reaper_busy(fc
->pid
);
834 if (reaperage
>= busytime
)
835 idletime
= reaperage
- busytime
;
837 ret
= snprintf(d
->buf
, d
->buflen
, "%.2lf %.2lf\n", reaperage
, idletime
);
838 if (ret
< 0 || ret
>= d
->buflen
)
839 return read_file_fuse("/proc/uptime", buf
, size
, d
);
844 if (total_len
> size
)
846 memcpy(buf
, d
->buf
, total_len
);
851 #define CPUALL_MAX_SIZE (BUF_RESERVE_SIZE / 2)
852 static int proc_stat_read(char *buf
, size_t size
, off_t offset
,
853 struct fuse_file_info
*fi
)
855 __do_free
char *cg
= NULL
, *cpuset
= NULL
, *line
= NULL
;
856 __do_free
void *fopen_cache
= NULL
;
857 __do_free
struct cpuacct_usage
*cg_cpu_usage
= NULL
;
858 __do_fclose
FILE *f
= NULL
;
859 struct fuse_context
*fc
= fuse_get_context();
860 struct lxcfs_opts
*opts
= (struct lxcfs_opts
*)fc
->private_data
;
861 struct file_info
*d
= INTTYPE_TO_PTR(fi
->fh
);
862 size_t linelen
= 0, total_len
= 0;
863 int curcpu
= -1; /* cpu numbering starts at 0 */
865 uint64_t user
= 0, nice
= 0, system
= 0, idle
= 0, iowait
= 0, irq
= 0,
866 softirq
= 0, steal
= 0, guest
= 0, guest_nice
= 0;
867 uint64_t user_sum
= 0, nice_sum
= 0, system_sum
= 0, idle_sum
= 0,
868 iowait_sum
= 0, irq_sum
= 0, softirq_sum
= 0, steal_sum
= 0,
869 guest_sum
= 0, guest_nice_sum
= 0;
870 char cpuall
[CPUALL_MAX_SIZE
];
871 /* reserve for cpu all */
872 char *cache
= d
->buf
+ CPUALL_MAX_SIZE
;
873 size_t cache_size
= d
->buflen
- CPUALL_MAX_SIZE
;
874 int cg_cpu_usage_size
= 0;
879 if (offset
> d
->size
)
885 left
= d
->size
- offset
;
886 total_len
= left
> size
? size
: left
;
887 memcpy(buf
, d
->buf
+ offset
, total_len
);
892 pid_t initpid
= lookup_initpid_in_store(fc
->pid
);
893 if (initpid
<= 1 || is_shared_pidns(initpid
))
897 * when container run with host pid namespace initpid == 1, cgroup will "/"
898 * we should return host os's /proc contents.
899 * in some case cpuacct_usage.all in "/" will larger then /proc/stat
902 return read_file_fuse("/proc/stat", buf
, size
, d
);
904 cg
= get_pid_cgroup(initpid
, "cpuset");
906 return read_file_fuse("/proc/stat", buf
, size
, d
);
907 prune_init_slice(cg
);
909 cpuset
= get_cpuset(cg
);
913 f
= fopen_cached("/proc/stat", "re", &fopen_cache
);
917 /* Skip first system cpu line. */
918 if (getline(&line
, &linelen
, f
) < 0)
919 return log_error(0, "proc_stat_read read first line failed");
922 * Read cpuacct.usage_all for all CPUs.
923 * If the cpuacct cgroup is present, it is used to calculate the container's
924 * CPU usage. If not, values from the host's /proc/stat are used.
926 if (read_cpuacct_usage_all(cg
, cpuset
, &cg_cpu_usage
, &cg_cpu_usage_size
) == 0) {
927 if (cgroup_ops
->can_use_cpuview(cgroup_ops
) && opts
&& opts
->use_cfs
) {
928 total_len
= cpuview_proc_stat(cg
, cpuset
, cg_cpu_usage
,
929 cg_cpu_usage_size
, f
,
934 lxcfs_v("proc_stat_read failed to read from cpuacct, falling back to the host's /proc/stat");
937 while (getline(&line
, &linelen
, f
) != -1) {
939 char cpu_char
[10]; /* That's a lot of cores */
941 uint64_t all_used
, cg_used
, new_idle
;
944 if (strlen(line
) == 0)
946 if (sscanf(line
, "cpu%9[^ ]", cpu_char
) != 1) {
947 /* not a ^cpuN line containing a number N, just print it */
948 l
= snprintf(cache
, cache_size
, "%s", line
);
950 return log_error(0, "Failed to write cache");
952 return log_error(0, "Write to cache was truncated");
961 if (sscanf(cpu_char
, "%d", &physcpu
) != 1)
964 if (!cpu_in_cpuset(physcpu
, cpuset
))
969 ret
= sscanf(line
, "%*s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
980 if (ret
!= 10 || !cg_cpu_usage
) {
981 c
= strchr(line
, ' ');
985 l
= snprintf(cache
, cache_size
, "cpu%d%s", curcpu
, c
);
987 return log_error(0, "Failed to write cache");
989 return log_error(0, "Write to cache was truncated");
1000 if (physcpu
>= cg_cpu_usage_size
)
1003 all_used
= user
+ nice
+ system
+ iowait
+ irq
+ softirq
+ steal
+ guest
+ guest_nice
;
1004 cg_used
= cg_cpu_usage
[physcpu
].user
+ cg_cpu_usage
[physcpu
].system
;
1006 if (all_used
>= cg_used
) {
1007 new_idle
= idle
+ (all_used
- cg_used
);
1010 lxcfs_error("cpu%d from %s has unexpected cpu time: %" PRIu64
" in /proc/stat, %" PRIu64
" in cpuacct.usage_all; unable to determine idle time",
1011 curcpu
, cg
, all_used
, cg_used
);
1015 l
= snprintf(cache
, cache_size
,
1016 "cpu%d %" PRIu64
" 0 %" PRIu64
" %" PRIu64
" 0 0 0 0 0 0\n",
1017 curcpu
, cg_cpu_usage
[physcpu
].user
,
1018 cg_cpu_usage
[physcpu
].system
, new_idle
);
1020 return log_error(0, "Failed to write cache");
1021 if (l
>= cache_size
)
1022 return log_error(0, "Write to cache was truncated");
1028 user_sum
+= cg_cpu_usage
[physcpu
].user
;
1029 system_sum
+= cg_cpu_usage
[physcpu
].system
;
1030 idle_sum
+= new_idle
;
1034 system_sum
+= system
;
1036 iowait_sum
+= iowait
;
1038 softirq_sum
+= softirq
;
1041 guest_nice_sum
+= guest_nice
;
1047 int cpuall_len
= snprintf(cpuall
, CPUALL_MAX_SIZE
, "cpu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
1058 if (cpuall_len
> 0 && cpuall_len
< CPUALL_MAX_SIZE
) {
1059 memcpy(cache
, cpuall
, cpuall_len
);
1060 cache
+= cpuall_len
;
1062 /* shouldn't happen */
1063 lxcfs_error("proc_stat_read copy cpuall failed, cpuall_len=%d", cpuall_len
);
1067 memmove(cache
, d
->buf
+ CPUALL_MAX_SIZE
, total_len
);
1068 total_len
+= cpuall_len
;
1072 d
->size
= total_len
;
1073 if (total_len
> size
)
1076 memcpy(buf
, d
->buf
, total_len
);
1080 /* Note that "memory.stat" in cgroup2 is hierarchical by default. */
1081 static bool cgroup_parse_memory_stat(const char *cgroup
, struct memory_stat
*mstat
)
1083 __do_close
int fd
= -EBADF
;
1084 __do_fclose
FILE *f
= NULL
;
1085 __do_free
char *line
= NULL
;
1086 __do_free
void *fdopen_cache
= NULL
;
1091 fd
= cgroup_ops
->get_memory_stats_fd(cgroup_ops
, cgroup
);
1095 f
= fdopen_cached(fd
, "re", &fdopen_cache
);
1099 unified
= pure_unified_layout(cgroup_ops
);
1100 while ((linelen
= getline(&line
, &len
, f
)) != -1) {
1101 if (!unified
&& startswith(line
, "hierarchical_memory_limit")) {
1102 sscanf(line
, "hierarchical_memory_limit %" PRIu64
, &(mstat
->hierarchical_memory_limit
));
1103 } else if (!unified
&& startswith(line
, "hierarchical_memsw_limit")) {
1104 sscanf(line
, "hierarchical_memsw_limit %" PRIu64
, &(mstat
->hierarchical_memsw_limit
));
1105 } else if (startswith(line
, unified
? "file" :"total_cache")) {
1106 sscanf(line
, unified
? "file %" PRIu64
: "total_cache %" PRIu64
, &(mstat
->total_cache
));
1107 } else if (!unified
&& startswith(line
, "total_rss")) {
1108 sscanf(line
, "total_rss %" PRIu64
, &(mstat
->total_rss
));
1109 } else if (!unified
&& startswith(line
, "total_rss_huge")) {
1110 sscanf(line
, "total_rss_huge %" PRIu64
, &(mstat
->total_rss_huge
));
1111 } else if (startswith(line
, unified
? "shmem" : "total_shmem")) {
1112 sscanf(line
, unified
? "shmem %" PRIu64
: "total_shmem %" PRIu64
, &(mstat
->total_shmem
));
1113 } else if (startswith(line
, unified
? "file_mapped" : "total_mapped_file")) {
1114 sscanf(line
, unified
? "file_mapped %" PRIu64
: "total_mapped_file %" PRIu64
, &(mstat
->total_mapped_file
));
1115 } else if (!unified
&& startswith(line
, "total_dirty")) {
1116 sscanf(line
, "total_dirty %" PRIu64
, &(mstat
->total_dirty
));
1117 } else if (!unified
&& startswith(line
, "total_writeback")) {
1118 sscanf(line
, "total_writeback %" PRIu64
, &(mstat
->total_writeback
));
1119 } else if (!unified
&& startswith(line
, "total_swap")) {
1120 sscanf(line
, "total_swap %" PRIu64
, &(mstat
->total_swap
));
1121 } else if (!unified
&& startswith(line
, "total_pgpgin")) {
1122 sscanf(line
, "total_pgpgin %" PRIu64
, &(mstat
->total_pgpgin
));
1123 } else if (!unified
&& startswith(line
, "total_pgpgout")) {
1124 sscanf(line
, "total_pgpgout %" PRIu64
, &(mstat
->total_pgpgout
));
1125 } else if (startswith(line
, unified
? "pgfault" : "total_pgfault")) {
1126 sscanf(line
, unified
? "pgfault %" PRIu64
: "total_pgfault %" PRIu64
, &(mstat
->total_pgfault
));
1127 } else if (startswith(line
, unified
? "pgmajfault" : "total_pgmajfault")) {
1128 sscanf(line
, unified
? "pgmajfault %" PRIu64
: "total_pgmajfault %" PRIu64
, &(mstat
->total_pgmajfault
));
1129 } else if (startswith(line
, unified
? "inactive_anon" : "total_inactive_anon")) {
1130 sscanf(line
, unified
? "inactive_anon %" PRIu64
: "total_inactive_anon %" PRIu64
, &(mstat
->total_inactive_anon
));
1131 } else if (startswith(line
, unified
? "active_anon" : "total_active_anon")) {
1132 sscanf(line
, unified
? "active_anon %" PRIu64
: "total_active_anon %" PRIu64
, &(mstat
->total_active_anon
));
1133 } else if (startswith(line
, unified
? "inactive_file" : "total_inactive_file")) {
1134 sscanf(line
, unified
? "inactive_file %" PRIu64
: "total_inactive_file %" PRIu64
, &(mstat
->total_inactive_file
));
1135 } else if (startswith(line
, unified
? "active_file" : "total_active_file")) {
1136 sscanf(line
, unified
? "active_file %" PRIu64
: "total_active_file %" PRIu64
, &(mstat
->total_active_file
));
1137 } else if (startswith(line
, unified
? "unevictable" : "total_unevictable")) {
1138 sscanf(line
, unified
? "unevictable %" PRIu64
: "total_unevictable %" PRIu64
, &(mstat
->total_unevictable
));
1145 static int proc_meminfo_read(char *buf
, size_t size
, off_t offset
,
1146 struct fuse_file_info
*fi
)
1148 __do_free
char *cgroup
= NULL
, *line
= NULL
, *memusage_str
= NULL
,
1149 *memswusage_str
= NULL
, *memswpriority_str
= NULL
;
1150 __do_free
void *fopen_cache
= NULL
;
1151 __do_fclose
FILE *f
= NULL
;
1152 struct fuse_context
*fc
= fuse_get_context();
1153 struct lxcfs_opts
*opts
= (struct lxcfs_opts
*)fuse_get_context()->private_data
;
1154 bool wants_swap
= opts
&& !opts
->swap_off
&& liblxcfs_can_use_swap();
1155 struct file_info
*d
= INTTYPE_TO_PTR(fi
->fh
);
1156 uint64_t memlimit
= 0, memusage
= 0, memswlimit
= 0, memswusage
= 0,
1157 hosttotal
= 0, swfree
= 0, swusage
= 0, swtotal
= 0,
1159 struct memory_stat mstat
= {};
1160 size_t linelen
= 0, total_len
= 0;
1161 char *cache
= d
->buf
;
1162 size_t cache_size
= d
->buflen
;
1168 if (offset
> d
->size
)
1174 left
= d
->size
- offset
;
1175 total_len
= left
> size
? size
: left
;
1176 memcpy(buf
, cache
+ offset
, total_len
);
1181 pid_t initpid
= lookup_initpid_in_store(fc
->pid
);
1182 if (initpid
<= 1 || is_shared_pidns(initpid
))
1185 cgroup
= get_pid_cgroup(initpid
, "memory");
1187 return read_file_fuse("/proc/meminfo", buf
, size
, d
);
1189 prune_init_slice(cgroup
);
1192 ret
= cgroup_ops
->get_memory_current(cgroup_ops
, cgroup
, &memusage_str
);
1194 return read_file_fuse("/proc/meminfo", buf
, size
, d
);
1196 if (safe_uint64(memusage_str
, &memusage
, 10) < 0)
1197 lxcfs_error("Failed to convert memusage %s", memusage_str
);
1199 if (!cgroup_parse_memory_stat(cgroup
, &mstat
))
1200 return read_file_fuse("/proc/meminfo", buf
, size
, d
);
1202 memlimit
= get_min_memlimit(cgroup
, false);
1205 * Following values are allowed to fail, because swapaccount might be
1206 * turned off for current kernel.
1209 memswlimit
= get_min_memlimit(cgroup
, true);
1210 if (memswlimit
> 0) {
1211 ret
= cgroup_ops
->get_memory_swap_current(cgroup_ops
, cgroup
, &memswusage_str
);
1212 if (ret
>= 0 && safe_uint64(memswusage_str
, &memswusage
, 10) == 0) {
1213 if (memlimit
> memswlimit
)
1216 swtotal
= (memswlimit
- memlimit
) / 1024;
1217 if (memusage
> memswusage
|| swtotal
== 0)
1220 swusage
= (memswusage
- memusage
) / 1024;
1224 ret
= cgroup_ops
->get_memory_swappiness(cgroup_ops
, cgroup
, &memswpriority_str
);
1226 safe_uint64(memswpriority_str
, &memswpriority
, 10);
1229 f
= fopen_cached("/proc/meminfo", "re", &fopen_cache
);
1231 return read_file_fuse("/proc/meminfo", buf
, size
, d
);
1235 while (getline(&line
, &linelen
, f
) != -1) {
1237 char *printme
, lbuf
[100];
1239 memset(lbuf
, 0, 100);
1240 if (startswith(line
, "MemTotal:")) {
1241 sscanf(line
+sizeof("MemTotal:")-1, "%" PRIu64
, &hosttotal
);
1243 memlimit
= hosttotal
;
1245 if (hosttotal
< memlimit
)
1246 memlimit
= hosttotal
;
1247 snprintf(lbuf
, 100, "MemTotal: %8" PRIu64
" kB\n", memlimit
);
1249 } else if (startswith(line
, "MemFree:")) {
1250 snprintf(lbuf
, 100, "MemFree: %8" PRIu64
" kB\n", memlimit
- memusage
);
1252 } else if (startswith(line
, "MemAvailable:")) {
1253 snprintf(lbuf
, 100, "MemAvailable: %8" PRIu64
" kB\n", memlimit
- memusage
+ mstat
.total_cache
/ 1024);
1255 } else if (startswith(line
, "SwapTotal:")) {
1257 uint64_t hostswtotal
= 0;
1259 sscanf(line
+ STRLITERALLEN("SwapTotal:"), "%" PRIu64
, &hostswtotal
);
1261 /* The total amount of swap is always reported to be the
1262 lesser of the RAM+SWAP limit or the SWAP device size.
1263 This is because the kernel can swap as much as it
1264 wants and not only up to swtotal. */
1266 swtotal
= memlimit
+ swtotal
;
1267 if (hostswtotal
< swtotal
) {
1268 swtotal
= hostswtotal
;
1271 /* When swappiness is 0, pretend we can't swap. */
1272 if (memswpriority
== 0) {
1277 snprintf(lbuf
, 100, "SwapTotal: %8" PRIu64
" kB\n", swtotal
);
1279 } else if (startswith(line
, "SwapFree:")) {
1281 swfree
= swtotal
- swusage
;
1284 snprintf(lbuf
, 100, "SwapFree: %8" PRIu64
" kB\n", swfree
);
1286 } else if (startswith(line
, "Slab:")) {
1287 snprintf(lbuf
, 100, "Slab: %8" PRIu64
" kB\n", (uint64_t)0);
1289 } else if (startswith(line
, "Buffers:")) {
1290 snprintf(lbuf
, 100, "Buffers: %8" PRIu64
" kB\n", (uint64_t)0);
1292 } else if (startswith(line
, "Cached:")) {
1293 snprintf(lbuf
, 100, "Cached: %8" PRIu64
" kB\n",
1294 mstat
.total_cache
/ 1024);
1296 } else if (startswith(line
, "SwapCached:")) {
1297 snprintf(lbuf
, 100, "SwapCached: %8" PRIu64
" kB\n", (uint64_t)0);
1299 } else if (startswith(line
, "Active:")) {
1300 snprintf(lbuf
, 100, "Active: %8" PRIu64
" kB\n",
1301 (mstat
.total_active_anon
+
1302 mstat
.total_active_file
) /
1305 } else if (startswith(line
, "Inactive:")) {
1306 snprintf(lbuf
, 100, "Inactive: %8" PRIu64
" kB\n",
1307 (mstat
.total_inactive_anon
+
1308 mstat
.total_inactive_file
) /
1311 } else if (startswith(line
, "Active(anon):")) {
1312 snprintf(lbuf
, 100, "Active(anon): %8" PRIu64
" kB\n",
1313 mstat
.total_active_anon
/ 1024);
1315 } else if (startswith(line
, "Inactive(anon):")) {
1316 snprintf(lbuf
, 100, "Inactive(anon): %8" PRIu64
" kB\n",
1317 mstat
.total_inactive_anon
/ 1024);
1319 } else if (startswith(line
, "Active(file):")) {
1320 snprintf(lbuf
, 100, "Active(file): %8" PRIu64
" kB\n",
1321 mstat
.total_active_file
/ 1024);
1323 } else if (startswith(line
, "Inactive(file):")) {
1324 snprintf(lbuf
, 100, "Inactive(file): %8" PRIu64
" kB\n",
1325 mstat
.total_inactive_file
/ 1024);
1327 } else if (startswith(line
, "Unevictable:")) {
1328 snprintf(lbuf
, 100, "Unevictable: %8" PRIu64
" kB\n",
1329 mstat
.total_unevictable
/ 1024);
1331 } else if (startswith(line
, "Dirty:")) {
1332 snprintf(lbuf
, 100, "Dirty: %8" PRIu64
" kB\n",
1333 mstat
.total_dirty
/ 1024);
1335 } else if (startswith(line
, "Writeback:")) {
1336 snprintf(lbuf
, 100, "Writeback: %8" PRIu64
" kB\n",
1337 mstat
.total_writeback
/ 1024);
1339 } else if (startswith(line
, "AnonPages:")) {
1340 snprintf(lbuf
, 100, "AnonPages: %8" PRIu64
" kB\n",
1341 (mstat
.total_active_anon
+
1342 mstat
.total_inactive_anon
- mstat
.total_shmem
) /
1345 } else if (startswith(line
, "Mapped:")) {
1346 snprintf(lbuf
, 100, "Mapped: %8" PRIu64
" kB\n",
1347 mstat
.total_mapped_file
/ 1024);
1349 } else if (startswith(line
, "SReclaimable:")) {
1350 snprintf(lbuf
, 100, "SReclaimable: %8" PRIu64
" kB\n", (uint64_t)0);
1352 } else if (startswith(line
, "SUnreclaim:")) {
1353 snprintf(lbuf
, 100, "SUnreclaim: %8" PRIu64
" kB\n", (uint64_t)0);
1355 } else if (startswith(line
, "Shmem:")) {
1356 snprintf(lbuf
, 100, "Shmem: %8" PRIu64
" kB\n",
1357 mstat
.total_shmem
/ 1024);
1359 } else if (startswith(line
, "ShmemHugePages:")) {
1360 snprintf(lbuf
, 100, "ShmemHugePages: %8" PRIu64
" kB\n", (uint64_t)0);
1362 } else if (startswith(line
, "ShmemPmdMapped:")) {
1363 snprintf(lbuf
, 100, "ShmemPmdMapped: %8" PRIu64
" kB\n", (uint64_t)0);
1365 } else if (startswith(line
, "AnonHugePages:")) {
1366 snprintf(lbuf
, 100, "AnonHugePages: %8" PRIu64
" kB\n",
1367 mstat
.total_rss_huge
/ 1024);
1373 l
= snprintf(cache
, cache_size
, "%s", printme
);
1375 return log_error(0, "Failed to write cache");
1376 if (l
>= cache_size
)
1377 return log_error(0, "Write to cache was truncated");
1385 d
->size
= total_len
;
1386 if (total_len
> size
)
1388 memcpy(buf
, d
->buf
, total_len
);
1393 __lxcfs_fuse_ops
int proc_read(const char *path
, char *buf
, size_t size
,
1394 off_t offset
, struct fuse_file_info
*fi
)
1396 struct file_info
*f
= INTTYPE_TO_PTR(fi
->fh
);
1399 case LXC_TYPE_PROC_MEMINFO
:
1400 if (liblxcfs_functional())
1401 return proc_meminfo_read(buf
, size
, offset
, fi
);
1403 return read_file_fuse_with_offset(LXC_TYPE_PROC_MEMINFO_PATH
,
1404 buf
, size
, offset
, f
);
1405 case LXC_TYPE_PROC_CPUINFO
:
1406 if (liblxcfs_functional())
1407 return proc_cpuinfo_read(buf
, size
, offset
, fi
);
1409 return read_file_fuse_with_offset(LXC_TYPE_PROC_CPUINFO_PATH
,
1410 buf
, size
, offset
, f
);
1411 case LXC_TYPE_PROC_UPTIME
:
1412 if (liblxcfs_functional())
1413 return proc_uptime_read(buf
, size
, offset
, fi
);
1415 return read_file_fuse_with_offset(LXC_TYPE_PROC_UPTIME_PATH
,
1416 buf
, size
, offset
, f
);
1417 case LXC_TYPE_PROC_STAT
:
1418 if (liblxcfs_functional())
1419 return proc_stat_read(buf
, size
, offset
, fi
);
1421 return read_file_fuse_with_offset(LXC_TYPE_PROC_STAT_PATH
, buf
,
1423 case LXC_TYPE_PROC_DISKSTATS
:
1424 if (liblxcfs_functional())
1425 return proc_diskstats_read(buf
, size
, offset
, fi
);
1427 return read_file_fuse_with_offset(LXC_TYPE_PROC_DISKSTATS_PATH
,
1428 buf
, size
, offset
, f
);
1429 case LXC_TYPE_PROC_SWAPS
:
1430 if (liblxcfs_functional())
1431 return proc_swaps_read(buf
, size
, offset
, fi
);
1433 return read_file_fuse_with_offset(LXC_TYPE_PROC_SWAPS_PATH
, buf
,
1435 case LXC_TYPE_PROC_LOADAVG
:
1436 if (liblxcfs_functional())
1437 return proc_loadavg_read(buf
, size
, offset
, fi
);
1439 return read_file_fuse_with_offset(LXC_TYPE_PROC_LOADAVG_PATH
,
1440 buf
, size
, offset
, f
);