]> git.proxmox.com Git - mirror_lxcfs.git/blob - proc_fuse.c
tree-wide: make fopen() calls cloexec
[mirror_lxcfs.git] / proc_fuse.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #ifndef _GNU_SOURCE
4 #define _GNU_SOURCE
5 #endif
6
7 #ifndef FUSE_USE_VERSION
8 #define FUSE_USE_VERSION 26
9 #endif
10
11 #define _FILE_OFFSET_BITS 64
12
13 #define __STDC_FORMAT_MACROS
14 #include <dirent.h>
15 #include <errno.h>
16 #include <fcntl.h>
17 #include <fuse.h>
18 #include <inttypes.h>
19 #include <libgen.h>
20 #include <pthread.h>
21 #include <sched.h>
22 #include <stdarg.h>
23 #include <stdbool.h>
24 #include <stdint.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <time.h>
29 #include <unistd.h>
30 #include <wait.h>
31 #include <linux/magic.h>
32 #include <linux/sched.h>
33 #include <sys/epoll.h>
34 #include <sys/mman.h>
35 #include <sys/mount.h>
36 #include <sys/param.h>
37 #include <sys/socket.h>
38 #include <sys/syscall.h>
39 #include <sys/sysinfo.h>
40 #include <sys/vfs.h>
41
42 #include "bindings.h"
43 #include "config.h"
44 #include "cgroup_fuse.h"
45 #include "cgroups/cgroup.h"
46 #include "cgroups/cgroup_utils.h"
47 #include "cpuset_parse.h"
48 #include "memory_utils.h"
49 #include "proc_loadavg.h"
50 #include "proc_cpuview.h"
51 #include "utils.h"
52
53 struct memory_stat {
54 uint64_t hierarchical_memory_limit;
55 uint64_t hierarchical_memsw_limit;
56 uint64_t total_cache;
57 uint64_t total_rss;
58 uint64_t total_rss_huge;
59 uint64_t total_shmem;
60 uint64_t total_mapped_file;
61 uint64_t total_dirty;
62 uint64_t total_writeback;
63 uint64_t total_swap;
64 uint64_t total_pgpgin;
65 uint64_t total_pgpgout;
66 uint64_t total_pgfault;
67 uint64_t total_pgmajfault;
68 uint64_t total_inactive_anon;
69 uint64_t total_active_anon;
70 uint64_t total_inactive_file;
71 uint64_t total_active_file;
72 uint64_t total_unevictable;
73 };
74
75 int proc_getattr(const char *path, struct stat *sb)
76 {
77 struct timespec now;
78
79 memset(sb, 0, sizeof(struct stat));
80 if (clock_gettime(CLOCK_REALTIME, &now) < 0)
81 return -EINVAL;
82 sb->st_uid = sb->st_gid = 0;
83 sb->st_atim = sb->st_mtim = sb->st_ctim = now;
84 if (strcmp(path, "/proc") == 0) {
85 sb->st_mode = S_IFDIR | 00555;
86 sb->st_nlink = 2;
87 return 0;
88 }
89 if (strcmp(path, "/proc/meminfo") == 0 ||
90 strcmp(path, "/proc/cpuinfo") == 0 ||
91 strcmp(path, "/proc/uptime") == 0 ||
92 strcmp(path, "/proc/stat") == 0 ||
93 strcmp(path, "/proc/diskstats") == 0 ||
94 strcmp(path, "/proc/swaps") == 0 ||
95 strcmp(path, "/proc/loadavg") == 0) {
96 sb->st_size = 0;
97 sb->st_mode = S_IFREG | 00444;
98 sb->st_nlink = 1;
99 return 0;
100 }
101
102 return -ENOENT;
103 }
104
105 int proc_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
106 off_t offset, struct fuse_file_info *fi)
107 {
108 if (filler(buf, ".", NULL, 0) != 0 ||
109 filler(buf, "..", NULL, 0) != 0 ||
110 filler(buf, "cpuinfo", NULL, 0) != 0 ||
111 filler(buf, "meminfo", NULL, 0) != 0 ||
112 filler(buf, "stat", NULL, 0) != 0 ||
113 filler(buf, "uptime", NULL, 0) != 0 ||
114 filler(buf, "diskstats", NULL, 0) != 0 ||
115 filler(buf, "swaps", NULL, 0) != 0 ||
116 filler(buf, "loadavg", NULL, 0) != 0)
117 return -EINVAL;
118
119 return 0;
120 }
121
122 static off_t get_procfile_size(const char *which)
123 {
124 FILE *f = fopen(which, "re");
125 char *line = NULL;
126 size_t len = 0;
127 ssize_t sz, answer = 0;
128 if (!f)
129 return 0;
130
131 while ((sz = getline(&line, &len, f)) != -1)
132 answer += sz;
133 fclose (f);
134 free(line);
135
136 return answer;
137 }
138
139 int proc_open(const char *path, struct fuse_file_info *fi)
140 {
141 __do_free struct file_info *info = NULL;
142 int type = -1;
143
144 if (strcmp(path, "/proc/meminfo") == 0)
145 type = LXC_TYPE_PROC_MEMINFO;
146 else if (strcmp(path, "/proc/cpuinfo") == 0)
147 type = LXC_TYPE_PROC_CPUINFO;
148 else if (strcmp(path, "/proc/uptime") == 0)
149 type = LXC_TYPE_PROC_UPTIME;
150 else if (strcmp(path, "/proc/stat") == 0)
151 type = LXC_TYPE_PROC_STAT;
152 else if (strcmp(path, "/proc/diskstats") == 0)
153 type = LXC_TYPE_PROC_DISKSTATS;
154 else if (strcmp(path, "/proc/swaps") == 0)
155 type = LXC_TYPE_PROC_SWAPS;
156 else if (strcmp(path, "/proc/loadavg") == 0)
157 type = LXC_TYPE_PROC_LOADAVG;
158 if (type == -1)
159 return -ENOENT;
160
161 info = malloc(sizeof(*info));
162 if (!info)
163 return -ENOMEM;
164
165 memset(info, 0, sizeof(*info));
166 info->type = type;
167
168 info->buflen = get_procfile_size(path) + BUF_RESERVE_SIZE;
169
170 info->buf = malloc(info->buflen);
171 if (!info->buf)
172 return -ENOMEM;
173
174 memset(info->buf, 0, info->buflen);
175 /* set actual size to buffer size */
176 info->size = info->buflen;
177
178 fi->fh = PTR_TO_UINT64(move_ptr(info));
179 return 0;
180 }
181
182 int proc_access(const char *path, int mask)
183 {
184 if (strcmp(path, "/proc") == 0 && access(path, R_OK) == 0)
185 return 0;
186
187 /* these are all read-only */
188 if ((mask & ~R_OK) != 0)
189 return -EACCES;
190 return 0;
191 }
192
193 int proc_release(const char *path, struct fuse_file_info *fi)
194 {
195 do_release_file_info(fi);
196 return 0;
197 }
198
199 static unsigned long get_memlimit(const char *cgroup, bool swap)
200 {
201 int ret;
202 __do_free char *memlimit_str = NULL;
203 unsigned long memlimit = -1;
204
205 if (swap)
206 ret = cgroup_ops->get_memory_swap_max(cgroup_ops, cgroup, &memlimit_str);
207 else
208 ret = cgroup_ops->get_memory_max(cgroup_ops, cgroup, &memlimit_str);
209 if (ret > 0)
210 memlimit = strtoul(memlimit_str, NULL, 10);
211
212 return memlimit;
213 }
214
215 static unsigned long get_min_memlimit(const char *cgroup, bool swap)
216 {
217 __do_free char *copy = NULL;
218 unsigned long memlimit = 0;
219 unsigned long retlimit;
220
221 copy = strdup(cgroup);
222 retlimit = get_memlimit(copy, swap);
223
224 while (strcmp(copy, "/") != 0) {
225 char *it = copy;
226
227 it = dirname(it);
228 memlimit = get_memlimit(it, swap);
229 if (memlimit != -1 && memlimit < retlimit)
230 retlimit = memlimit;
231 };
232
233 return retlimit;
234 }
235
236 static bool startswith(const char *line, const char *pref)
237 {
238 if (strncmp(line, pref, strlen(pref)) == 0)
239 return true;
240 return false;
241 }
242
243 static int proc_swaps_read(char *buf, size_t size, off_t offset,
244 struct fuse_file_info *fi)
245 {
246 __do_free char *cg = NULL, *memswlimit_str = NULL, *memusage_str = NULL,
247 *memswusage_str = NULL;
248 struct fuse_context *fc = fuse_get_context();
249 struct file_info *d = INTTYPE_TO_PTR(fi->fh);
250 unsigned long memswlimit = 0, memlimit = 0, memusage = 0,
251 memswusage = 0, swap_total = 0, swap_free = 0;
252 ssize_t total_len = 0;
253 ssize_t l = 0;
254 char *cache = d->buf;
255 int ret;
256
257 if (offset) {
258 int left;
259
260 if (offset > d->size)
261 return -EINVAL;
262
263 if (!d->cached)
264 return 0;
265
266 left = d->size - offset;
267 total_len = left > size ? size: left;
268 memcpy(buf, cache + offset, total_len);
269
270 return total_len;
271 }
272
273 pid_t initpid = lookup_initpid_in_store(fc->pid);
274 if (initpid <= 1 || is_shared_pidns(initpid))
275 initpid = fc->pid;
276 cg = get_pid_cgroup(initpid, "memory");
277 if (!cg)
278 return read_file_fuse("/proc/swaps", buf, size, d);
279 prune_init_slice(cg);
280
281 memlimit = get_min_memlimit(cg, false);
282
283 ret = cgroup_ops->get_memory_current(cgroup_ops, cg, &memusage_str);
284 if (ret < 0)
285 return 0;
286
287 memusage = strtoul(memusage_str, NULL, 10);
288
289 ret = cgroup_ops->get_memory_swap_max(cgroup_ops, cg, &memswlimit_str);
290 if (ret >= 0)
291 ret = cgroup_ops->get_memory_swap_current(cgroup_ops, cg, &memswusage_str);
292 if (ret >= 0) {
293 memswlimit = get_min_memlimit(cg, true);
294 memswusage = strtoul(memswusage_str, NULL, 10);
295 swap_total = (memswlimit - memlimit) / 1024;
296 swap_free = (memswusage - memusage) / 1024;
297 }
298
299 total_len = snprintf(d->buf, d->size, "Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
300
301 /* When no mem + swap limit is specified or swapaccount=0*/
302 if (!memswlimit) {
303 __do_free char *line = NULL;
304 __do_fclose FILE *f = NULL;
305 size_t linelen = 0;
306
307 f = fopen("/proc/meminfo", "re");
308 if (!f)
309 return 0;
310
311 while (getline(&line, &linelen, f) != -1) {
312 if (startswith(line, "SwapTotal:"))
313 sscanf(line, "SwapTotal: %8lu kB", &swap_total);
314 else if (startswith(line, "SwapFree:"))
315 sscanf(line, "SwapFree: %8lu kB", &swap_free);
316 }
317 }
318
319 if (swap_total > 0) {
320 l = snprintf(d->buf + total_len, d->size - total_len,
321 "none%*svirtual\t\t%lu\t%lu\t0\n", 36, " ",
322 swap_total, swap_free);
323 total_len += l;
324 }
325
326 if (total_len < 0 || l < 0) {
327 perror("Error writing to cache");
328 return 0;
329 }
330
331 d->cached = 1;
332 d->size = (int)total_len;
333
334 if (total_len > size) total_len = size;
335 memcpy(buf, d->buf, total_len);
336 return total_len;
337 }
338
339 static void get_blkio_io_value(char *str, unsigned major, unsigned minor,
340 char *iotype, unsigned long *v)
341 {
342 char *eol;
343 char key[32];
344
345 memset(key, 0, 32);
346 snprintf(key, 32, "%u:%u %s", major, minor, iotype);
347
348 size_t len = strlen(key);
349 *v = 0;
350
351 while (*str) {
352 if (startswith(str, key)) {
353 sscanf(str + len, "%lu", v);
354 return;
355 }
356 eol = strchr(str, '\n');
357 if (!eol)
358 return;
359 str = eol+1;
360 }
361 }
362
363 static int proc_diskstats_read(char *buf, size_t size, off_t offset,
364 struct fuse_file_info *fi)
365 {
366 __do_free char *cg = NULL, *io_serviced_str = NULL,
367 *io_merged_str = NULL, *io_service_bytes_str = NULL,
368 *io_wait_time_str = NULL, *io_service_time_str = NULL,
369 *line = NULL;
370 __do_fclose FILE *f = NULL;
371 struct fuse_context *fc = fuse_get_context();
372 struct file_info *d = INTTYPE_TO_PTR(fi->fh);
373 unsigned long read = 0, write = 0;
374 unsigned long read_merged = 0, write_merged = 0;
375 unsigned long read_sectors = 0, write_sectors = 0;
376 unsigned long read_ticks = 0, write_ticks = 0;
377 unsigned long ios_pgr = 0, tot_ticks = 0, rq_ticks = 0;
378 unsigned long rd_svctm = 0, wr_svctm = 0, rd_wait = 0, wr_wait = 0;
379 char *cache = d->buf;
380 size_t cache_size = d->buflen;
381 size_t linelen = 0, total_len = 0;
382 unsigned int major = 0, minor = 0;
383 int i = 0;
384 int ret;
385 char dev_name[72];
386
387 if (offset){
388 int left;
389
390 if (offset > d->size)
391 return -EINVAL;
392
393 if (!d->cached)
394 return 0;
395
396 left = d->size - offset;
397 total_len = left > size ? size: left;
398 memcpy(buf, cache + offset, total_len);
399
400 return total_len;
401 }
402
403 pid_t initpid = lookup_initpid_in_store(fc->pid);
404 if (initpid <= 1 || is_shared_pidns(initpid))
405 initpid = fc->pid;
406 cg = get_pid_cgroup(initpid, "blkio");
407 if (!cg)
408 return read_file_fuse("/proc/diskstats", buf, size, d);
409 prune_init_slice(cg);
410
411 ret = cgroup_ops->get_io_serviced(cgroup_ops, cg, &io_serviced_str);
412 if (ret < 0) {
413 if (ret == -EOPNOTSUPP)
414 return read_file_fuse("/proc/diskstats", buf, size, d);
415 }
416
417 ret = cgroup_ops->get_io_merged(cgroup_ops, cg, &io_merged_str);
418 if (ret < 0) {
419 if (ret == -EOPNOTSUPP)
420 return read_file_fuse("/proc/diskstats", buf, size, d);
421 }
422
423 ret = cgroup_ops->get_io_service_bytes(cgroup_ops, cg, &io_service_bytes_str);
424 if (ret < 0) {
425 if (ret == -EOPNOTSUPP)
426 return read_file_fuse("/proc/diskstats", buf, size, d);
427 }
428
429 ret = cgroup_ops->get_io_wait_time(cgroup_ops, cg, &io_wait_time_str);
430 if (ret < 0) {
431 if (ret == -EOPNOTSUPP)
432 return read_file_fuse("/proc/diskstats", buf, size, d);
433 }
434
435 ret = cgroup_ops->get_io_service_time(cgroup_ops, cg, &io_service_time_str);
436 if (ret < 0) {
437 if (ret == -EOPNOTSUPP)
438 return read_file_fuse("/proc/diskstats", buf, size, d);
439 }
440
441 f = fopen("/proc/diskstats", "re");
442 if (!f)
443 return 0;
444
445 while (getline(&line, &linelen, f) != -1) {
446 ssize_t l;
447 char lbuf[256];
448
449 i = sscanf(line, "%u %u %71s", &major, &minor, dev_name);
450 if (i != 3)
451 continue;
452
453 get_blkio_io_value(io_serviced_str, major, minor, "Read", &read);
454 get_blkio_io_value(io_serviced_str, major, minor, "Write", &write);
455 get_blkio_io_value(io_merged_str, major, minor, "Read", &read_merged);
456 get_blkio_io_value(io_merged_str, major, minor, "Write", &write_merged);
457 get_blkio_io_value(io_service_bytes_str, major, minor, "Read", &read_sectors);
458 read_sectors = read_sectors/512;
459 get_blkio_io_value(io_service_bytes_str, major, minor, "Write", &write_sectors);
460 write_sectors = write_sectors/512;
461
462 get_blkio_io_value(io_service_time_str, major, minor, "Read", &rd_svctm);
463 rd_svctm = rd_svctm/1000000;
464 get_blkio_io_value(io_wait_time_str, major, minor, "Read", &rd_wait);
465 rd_wait = rd_wait/1000000;
466 read_ticks = rd_svctm + rd_wait;
467
468 get_blkio_io_value(io_service_time_str, major, minor, "Write", &wr_svctm);
469 wr_svctm = wr_svctm/1000000;
470 get_blkio_io_value(io_wait_time_str, major, minor, "Write", &wr_wait);
471 wr_wait = wr_wait/1000000;
472 write_ticks = wr_svctm + wr_wait;
473
474 get_blkio_io_value(io_service_time_str, major, minor, "Total", &tot_ticks);
475 tot_ticks = tot_ticks/1000000;
476
477 memset(lbuf, 0, 256);
478 if (read || write || read_merged || write_merged || read_sectors || write_sectors || read_ticks || write_ticks)
479 snprintf(lbuf, 256, "%u %u %s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
480 major, minor, dev_name, read, read_merged, read_sectors, read_ticks,
481 write, write_merged, write_sectors, write_ticks, ios_pgr, tot_ticks, rq_ticks);
482 else
483 continue;
484
485 l = snprintf(cache, cache_size, "%s", lbuf);
486 if (l < 0) {
487 perror("Error writing to fuse buf");
488 return 0;
489 }
490 if (l >= cache_size) {
491 lxcfs_error("%s\n", "Internal error: truncated write to cache.");
492 return 0;
493 }
494 cache += l;
495 cache_size -= l;
496 total_len += l;
497 }
498
499 d->cached = 1;
500 d->size = total_len;
501 if (total_len > size ) total_len = size;
502 memcpy(buf, d->buf, total_len);
503
504 return total_len;
505 }
506
507 #if RELOADTEST
508 static inline void iwashere(void)
509 {
510 mknod("/tmp/lxcfs-iwashere", S_IFREG, 0644);
511 }
512 #endif
513
514 /* This function retrieves the busy time of a group of tasks by looking at
515 * cpuacct.usage. Unfortunately, this only makes sense when the container has
516 * been given it's own cpuacct cgroup. If not, this function will take the busy
517 * time of all other taks that do not actually belong to the container into
518 * account as well. If someone has a clever solution for this please send a
519 * patch!
520 */
521 static double get_reaper_busy(pid_t task)
522 {
523 __do_free char *cgroup = NULL, *usage_str = NULL;
524 unsigned long usage = 0;
525 pid_t initpid;
526
527 initpid = lookup_initpid_in_store(task);
528 if (initpid <= 0)
529 return 0;
530
531 cgroup = get_pid_cgroup(initpid, "cpuacct");
532 if (!cgroup)
533 return 0;
534 prune_init_slice(cgroup);
535 if (!cgroup_ops->get(cgroup_ops, "cpuacct", cgroup, "cpuacct.usage",
536 &usage_str))
537 return 0;
538
539 usage = strtoul(usage_str, NULL, 10);
540 return ((double)usage / 1000000000);
541 }
542
543 static uint64_t get_reaper_start_time(pid_t pid)
544 {
545 __do_fclose FILE *f = NULL;
546 int ret;
547 uint64_t starttime;
548 /* strlen("/proc/") = 6
549 * +
550 * LXCFS_NUMSTRLEN64
551 * +
552 * strlen("/stat") = 5
553 * +
554 * \0 = 1
555 * */
556 #define __PROC_PID_STAT_LEN (6 + LXCFS_NUMSTRLEN64 + 5 + 1)
557 char path[__PROC_PID_STAT_LEN];
558 pid_t qpid;
559
560 qpid = lookup_initpid_in_store(pid);
561 if (qpid <= 0) {
562 /* Caller can check for EINVAL on 0. */
563 errno = EINVAL;
564 return 0;
565 }
566
567 ret = snprintf(path, __PROC_PID_STAT_LEN, "/proc/%d/stat", qpid);
568 if (ret < 0 || ret >= __PROC_PID_STAT_LEN) {
569 /* Caller can check for EINVAL on 0. */
570 errno = EINVAL;
571 return 0;
572 }
573
574 f = fopen(path, "re");
575 if (!f) {
576 /* Caller can check for EINVAL on 0. */
577 errno = EINVAL;
578 return 0;
579 }
580
581 /* Note that the *scanf() argument supression requires that length
582 * modifiers such as "l" are omitted. Otherwise some compilers will yell
583 * at us. It's like telling someone you're not married and then asking
584 * if you can bring your wife to the party.
585 */
586 ret = fscanf(f, "%*d " /* (1) pid %d */
587 "%*s " /* (2) comm %s */
588 "%*c " /* (3) state %c */
589 "%*d " /* (4) ppid %d */
590 "%*d " /* (5) pgrp %d */
591 "%*d " /* (6) session %d */
592 "%*d " /* (7) tty_nr %d */
593 "%*d " /* (8) tpgid %d */
594 "%*u " /* (9) flags %u */
595 "%*u " /* (10) minflt %lu */
596 "%*u " /* (11) cminflt %lu */
597 "%*u " /* (12) majflt %lu */
598 "%*u " /* (13) cmajflt %lu */
599 "%*u " /* (14) utime %lu */
600 "%*u " /* (15) stime %lu */
601 "%*d " /* (16) cutime %ld */
602 "%*d " /* (17) cstime %ld */
603 "%*d " /* (18) priority %ld */
604 "%*d " /* (19) nice %ld */
605 "%*d " /* (20) num_threads %ld */
606 "%*d " /* (21) itrealvalue %ld */
607 "%" PRIu64, /* (22) starttime %llu */
608 &starttime);
609 if (ret != 1)
610 return ret_set_errno(0, EINVAL);
611
612 return ret_set_errno(starttime, 0);
613 }
614
615 static double get_reaper_start_time_in_sec(pid_t pid)
616 {
617 uint64_t clockticks, ticks_per_sec;
618 int64_t ret;
619 double res = 0;
620
621 clockticks = get_reaper_start_time(pid);
622 if (clockticks == 0 && errno == EINVAL) {
623 lxcfs_debug("failed to retrieve start time of pid %d\n", pid);
624 return 0;
625 }
626
627 ret = sysconf(_SC_CLK_TCK);
628 if (ret < 0 && errno == EINVAL) {
629 lxcfs_debug(
630 "%s\n",
631 "failed to determine number of clock ticks in a second");
632 return 0;
633 }
634
635 ticks_per_sec = (uint64_t)ret;
636 res = (double)clockticks / ticks_per_sec;
637 return res;
638 }
639
640 static double get_reaper_age(pid_t pid)
641 {
642 uint64_t uptime_ms;
643 double procstart, procage;
644
645 /* We need to substract the time the process has started since system
646 * boot minus the time when the system has started to get the actual
647 * reaper age.
648 */
649 procstart = get_reaper_start_time_in_sec(pid);
650 procage = procstart;
651 if (procstart > 0) {
652 int ret;
653 struct timespec spec;
654
655 ret = clock_gettime(CLOCK_BOOTTIME, &spec);
656 if (ret < 0)
657 return 0;
658
659 /* We could make this more precise here by using the tv_nsec
660 * field in the timespec struct and convert it to milliseconds
661 * and then create a double for the seconds and milliseconds but
662 * that seems more work than it is worth.
663 */
664 uptime_ms = (spec.tv_sec * 1000) + (spec.tv_nsec * 1e-6);
665 procage = (uptime_ms - (procstart * 1000)) / 1000;
666 }
667
668 return procage;
669 }
670
671 /*
672 * We read /proc/uptime and reuse its second field.
673 * For the first field, we use the mtime for the reaper for
674 * the calling pid as returned by getreaperage
675 */
676 static int proc_uptime_read(char *buf, size_t size, off_t offset,
677 struct fuse_file_info *fi)
678 {
679 struct fuse_context *fc = fuse_get_context();
680 struct file_info *d = INTTYPE_TO_PTR(fi->fh);
681 double busytime = get_reaper_busy(fc->pid);
682 char *cache = d->buf;
683 ssize_t total_len = 0;
684 double idletime, reaperage;
685
686 #if RELOADTEST
687 iwashere();
688 #endif
689
690 if (offset){
691 if (!d->cached)
692 return 0;
693 if (offset > d->size)
694 return -EINVAL;
695 int left = d->size - offset;
696 total_len = left > size ? size: left;
697 memcpy(buf, cache + offset, total_len);
698 return total_len;
699 }
700
701 reaperage = get_reaper_age(fc->pid);
702 /* To understand why this is done, please read the comment to the
703 * get_reaper_busy() function.
704 */
705 idletime = reaperage;
706 if (reaperage >= busytime)
707 idletime = reaperage - busytime;
708
709 total_len = snprintf(d->buf, d->buflen, "%.2lf %.2lf\n", reaperage, idletime);
710 if (total_len < 0 || total_len >= d->buflen){
711 lxcfs_error("%s\n", "failed to write to cache");
712 return 0;
713 }
714
715 d->size = (int)total_len;
716 d->cached = 1;
717
718 if (total_len > size) total_len = size;
719
720 memcpy(buf, d->buf, total_len);
721 return total_len;
722 }
723
724 #define CPUALL_MAX_SIZE (BUF_RESERVE_SIZE / 2)
725 static int proc_stat_read(char *buf, size_t size, off_t offset,
726 struct fuse_file_info *fi)
727 {
728 __do_free char *cg = NULL, *cpuset = NULL, *line = NULL;
729 __do_free struct cpuacct_usage *cg_cpu_usage = NULL;
730 __do_fclose FILE *f = NULL;
731 struct fuse_context *fc = fuse_get_context();
732 struct file_info *d = INTTYPE_TO_PTR(fi->fh);
733 size_t linelen = 0, total_len = 0;
734 int curcpu = -1; /* cpu numbering starts at 0 */
735 int physcpu = 0;
736 unsigned long user = 0, nice = 0, system = 0, idle = 0, iowait = 0,
737 irq = 0, softirq = 0, steal = 0, guest = 0, guest_nice = 0;
738 unsigned long user_sum = 0, nice_sum = 0, system_sum = 0, idle_sum = 0,
739 iowait_sum = 0, irq_sum = 0, softirq_sum = 0,
740 steal_sum = 0, guest_sum = 0, guest_nice_sum = 0;
741 char cpuall[CPUALL_MAX_SIZE];
742 /* reserve for cpu all */
743 char *cache = d->buf + CPUALL_MAX_SIZE;
744 size_t cache_size = d->buflen - CPUALL_MAX_SIZE;
745 int cg_cpu_usage_size = 0;
746
747 if (offset){
748 if (offset > d->size)
749 return -EINVAL;
750 if (!d->cached)
751 return 0;
752 int left = d->size - offset;
753 total_len = left > size ? size: left;
754 memcpy(buf, d->buf + offset, total_len);
755 return total_len;
756 }
757
758 pid_t initpid = lookup_initpid_in_store(fc->pid);
759 lxcfs_v("initpid: %d\n", initpid);
760 if (initpid <= 0)
761 initpid = fc->pid;
762
763 /*
764 * when container run with host pid namespace initpid == 1, cgroup will "/"
765 * we should return host os's /proc contents.
766 * in some case cpuacct_usage.all in "/" will larger then /proc/stat
767 */
768 if (initpid == 1) {
769 return read_file_fuse("/proc/stat", buf, size, d);
770 }
771
772 cg = get_pid_cgroup(initpid, "cpuset");
773 lxcfs_v("cg: %s\n", cg);
774 if (!cg)
775 return read_file_fuse("/proc/stat", buf, size, d);
776 prune_init_slice(cg);
777
778 cpuset = get_cpuset(cg);
779 if (!cpuset)
780 return 0;
781
782 /*
783 * Read cpuacct.usage_all for all CPUs.
784 * If the cpuacct cgroup is present, it is used to calculate the container's
785 * CPU usage. If not, values from the host's /proc/stat are used.
786 */
787 if (read_cpuacct_usage_all(cg, cpuset, &cg_cpu_usage, &cg_cpu_usage_size) != 0)
788 lxcfs_v("%s\n", "proc_stat_read failed to read from cpuacct, falling back to the host's /proc/stat");
789
790 f = fopen("/proc/stat", "re");
791 if (!f)
792 return 0;
793
794 //skip first line
795 if (getline(&line, &linelen, f) < 0) {
796 lxcfs_error("%s\n", "proc_stat_read read first line failed.");
797 return 0;
798 }
799
800 if (cgroup_ops->can_use_cpuview(cgroup_ops) && cg_cpu_usage) {
801 total_len = cpuview_proc_stat(cg, cpuset, cg_cpu_usage, cg_cpu_usage_size,
802 f, d->buf, d->buflen);
803 goto out;
804 }
805
806 while (getline(&line, &linelen, f) != -1) {
807 ssize_t l;
808 char cpu_char[10]; /* That's a lot of cores */
809 char *c;
810 uint64_t all_used, cg_used, new_idle;
811 int ret;
812
813 if (strlen(line) == 0)
814 continue;
815 if (sscanf(line, "cpu%9[^ ]", cpu_char) != 1) {
816 /* not a ^cpuN line containing a number N, just print it */
817 l = snprintf(cache, cache_size, "%s", line);
818 if (l < 0) {
819 perror("Error writing to cache");
820 return 0;
821 }
822 if (l >= cache_size) {
823 lxcfs_error("%s\n", "Internal error: truncated write to cache.");
824 return 0;
825 }
826 cache += l;
827 cache_size -= l;
828 total_len += l;
829 continue;
830 }
831
832 if (sscanf(cpu_char, "%d", &physcpu) != 1)
833 continue;
834 if (!cpu_in_cpuset(physcpu, cpuset))
835 continue;
836 curcpu++;
837
838 ret = sscanf(line, "%*s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
839 &user,
840 &nice,
841 &system,
842 &idle,
843 &iowait,
844 &irq,
845 &softirq,
846 &steal,
847 &guest,
848 &guest_nice);
849
850 if (ret != 10 || !cg_cpu_usage) {
851 c = strchr(line, ' ');
852 if (!c)
853 continue;
854 l = snprintf(cache, cache_size, "cpu%d%s", curcpu, c);
855 if (l < 0) {
856 perror("Error writing to cache");
857 return 0;
858
859 }
860 if (l >= cache_size) {
861 lxcfs_error("%s\n", "Internal error: truncated write to cache.");
862 return 0;
863 }
864
865 cache += l;
866 cache_size -= l;
867 total_len += l;
868
869 if (ret != 10)
870 continue;
871 }
872
873 if (cg_cpu_usage) {
874 if (physcpu >= cg_cpu_usage_size)
875 break;
876
877 all_used = user + nice + system + iowait + irq + softirq + steal + guest + guest_nice;
878 cg_used = cg_cpu_usage[physcpu].user + cg_cpu_usage[physcpu].system;
879
880 if (all_used >= cg_used) {
881 new_idle = idle + (all_used - cg_used);
882
883 } else {
884 lxcfs_error("cpu%d from %s has unexpected cpu time: %" PRIu64 " in /proc/stat, %" PRIu64 " in cpuacct.usage_all; unable to determine idle time",
885 curcpu, cg, all_used, cg_used);
886 new_idle = idle;
887 }
888
889 l = snprintf(cache, cache_size,
890 "cpu%d %" PRIu64 " 0 %" PRIu64 " %" PRIu64 " 0 0 0 0 0 0\n",
891 curcpu, cg_cpu_usage[physcpu].user,
892 cg_cpu_usage[physcpu].system, new_idle);
893
894 if (l < 0) {
895 perror("Error writing to cache");
896 return 0;
897
898 }
899 if (l >= cache_size) {
900 lxcfs_error("%s\n", "Internal error: truncated write to cache.");
901 return 0;
902 }
903
904 cache += l;
905 cache_size -= l;
906 total_len += l;
907
908 user_sum += cg_cpu_usage[physcpu].user;
909 system_sum += cg_cpu_usage[physcpu].system;
910 idle_sum += new_idle;
911
912 } else {
913 user_sum += user;
914 nice_sum += nice;
915 system_sum += system;
916 idle_sum += idle;
917 iowait_sum += iowait;
918 irq_sum += irq;
919 softirq_sum += softirq;
920 steal_sum += steal;
921 guest_sum += guest;
922 guest_nice_sum += guest_nice;
923 }
924 }
925
926 cache = d->buf;
927
928 int cpuall_len = snprintf(cpuall, CPUALL_MAX_SIZE, "cpu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
929 user_sum,
930 nice_sum,
931 system_sum,
932 idle_sum,
933 iowait_sum,
934 irq_sum,
935 softirq_sum,
936 steal_sum,
937 guest_sum,
938 guest_nice_sum);
939 if (cpuall_len > 0 && cpuall_len < CPUALL_MAX_SIZE) {
940 memcpy(cache, cpuall, cpuall_len);
941 cache += cpuall_len;
942 } else {
943 /* shouldn't happen */
944 lxcfs_error("proc_stat_read copy cpuall failed, cpuall_len=%d.", cpuall_len);
945 cpuall_len = 0;
946 }
947
948 memmove(cache, d->buf + CPUALL_MAX_SIZE, total_len);
949 total_len += cpuall_len;
950
951 out:
952 d->cached = 1;
953 d->size = total_len;
954 if (total_len > size)
955 total_len = size;
956
957 memcpy(buf, d->buf, total_len);
958 return total_len;
959 }
960
961 /* Note that "memory.stat" in cgroup2 is hierarchical by default. */
962 static bool cgroup_parse_memory_stat(const char *cgroup, struct memory_stat *mstat)
963 {
964 __do_close_prot_errno int fd = -EBADF;
965 __do_fclose FILE *f = NULL;
966 __do_free char *line = NULL;
967 bool unified;
968 size_t len = 0;
969 ssize_t linelen;
970
971 fd = cgroup_ops->get_memory_stats_fd(cgroup_ops, cgroup);
972 if (fd < 0)
973 return false;
974
975 f = fdopen(fd, "re");
976 if (!f)
977 return false;
978 /* Transferring ownership to fdopen(). */
979 move_fd(fd);
980
981 unified = pure_unified_layout(cgroup_ops);
982 while ((linelen = getline(&line, &len, f)) != -1) {
983 if (!unified && startswith(line, "hierarchical_memory_limit")) {
984 sscanf(line, "hierarchical_memory_limit %" PRIu64, &(mstat->hierarchical_memory_limit));
985 } else if (!unified && startswith(line, "hierarchical_memsw_limit")) {
986 sscanf(line, "hierarchical_memsw_limit %" PRIu64, &(mstat->hierarchical_memsw_limit));
987 } else if (!unified && startswith(line, "total_cache")) {
988 sscanf(line, "total_cache %" PRIu64, &(mstat->total_cache));
989 } else if (!unified && startswith(line, "total_rss")) {
990 sscanf(line, "total_rss %" PRIu64, &(mstat->total_rss));
991 } else if (!unified && startswith(line, "total_rss_huge")) {
992 sscanf(line, "total_rss_huge %" PRIu64, &(mstat->total_rss_huge));
993 } else if (startswith(line, unified ? "shmem" : "total_shmem")) {
994 sscanf(line, unified ? "shmem %" PRIu64 : "total_shmem %" PRIu64, &(mstat->total_shmem));
995 } else if (startswith(line, unified ? "file_mapped" : "total_mapped_file")) {
996 sscanf(line, unified ? "file_mapped %" PRIu64 : "total_mapped_file %" PRIu64, &(mstat->total_mapped_file));
997 } else if (!unified && startswith(line, "total_dirty")) {
998 sscanf(line, "total_dirty %" PRIu64, &(mstat->total_dirty));
999 } else if (!unified && startswith(line, "total_writeback")) {
1000 sscanf(line, "total_writeback %" PRIu64, &(mstat->total_writeback));
1001 } else if (!unified && startswith(line, "total_swap")) {
1002 sscanf(line, "total_swap %" PRIu64, &(mstat->total_swap));
1003 } else if (!unified && startswith(line, "total_pgpgin")) {
1004 sscanf(line, "total_pgpgin %" PRIu64, &(mstat->total_pgpgin));
1005 } else if (!unified && startswith(line, "total_pgpgout")) {
1006 sscanf(line, "total_pgpgout %" PRIu64, &(mstat->total_pgpgout));
1007 } else if (startswith(line, unified ? "pgfault" : "total_pgfault")) {
1008 sscanf(line, unified ? "pgfault %" PRIu64 : "total_pgfault %" PRIu64, &(mstat->total_pgfault));
1009 } else if (startswith(line, unified ? "pgmajfault" : "total_pgmajfault")) {
1010 sscanf(line, unified ? "pgmajfault %" PRIu64 : "total_pgmajfault %" PRIu64, &(mstat->total_pgmajfault));
1011 } else if (startswith(line, unified ? "inactive_anon" : "total_inactive_anon")) {
1012 sscanf(line, unified ? "inactive_anon %" PRIu64 : "total_inactive_anon %" PRIu64, &(mstat->total_inactive_anon));
1013 } else if (startswith(line, unified ? "active_anon" : "total_active_anon")) {
1014 sscanf(line, unified ? "active_anon %" PRIu64 : "total_active_anon %" PRIu64, &(mstat->total_active_anon));
1015 } else if (startswith(line, unified ? "inactive_file" : "total_inactive_file")) {
1016 sscanf(line, unified ? "inactive_file %" PRIu64 : "total_inactive_file %" PRIu64, &(mstat->total_inactive_file));
1017 } else if (startswith(line, unified ? "active_file" : "total_active_file")) {
1018 sscanf(line, unified ? "active_file %" PRIu64 : "total_active_file %" PRIu64, &(mstat->total_active_file));
1019 } else if (startswith(line, unified ? "unevictable" : "total_unevictable")) {
1020 sscanf(line, unified ? "unevictable %" PRIu64 : "total_unevictable %" PRIu64, &(mstat->total_unevictable));
1021 }
1022 }
1023
1024 return true;
1025 }
1026
1027 static int proc_meminfo_read(char *buf, size_t size, off_t offset,
1028 struct fuse_file_info *fi)
1029 {
1030 __do_free char *cgroup = NULL, *line = NULL,
1031 *memusage_str = NULL, *memstat_str = NULL,
1032 *memswlimit_str = NULL, *memswusage_str = NULL;
1033 __do_fclose FILE *f = NULL;
1034 struct fuse_context *fc = fuse_get_context();
1035 struct lxcfs_opts *opts = (struct lxcfs_opts *) fuse_get_context()->private_data;
1036 struct file_info *d = INTTYPE_TO_PTR(fi->fh);
1037 uint64_t memlimit = 0, memusage = 0, memswlimit = 0, memswusage = 0,
1038 hosttotal = 0;
1039 struct memory_stat mstat = {};
1040 size_t linelen = 0, total_len = 0;
1041 char *cache = d->buf;
1042 size_t cache_size = d->buflen;
1043 int ret;
1044
1045 if (offset) {
1046 int left;
1047
1048 if (offset > d->size)
1049 return -EINVAL;
1050
1051 if (!d->cached)
1052 return 0;
1053
1054 left = d->size - offset;
1055 total_len = left > size ? size : left;
1056 memcpy(buf, cache + offset, total_len);
1057
1058 return total_len;
1059 }
1060
1061 pid_t initpid = lookup_initpid_in_store(fc->pid);
1062 if (initpid <= 1 || is_shared_pidns(initpid))
1063 initpid = fc->pid;
1064
1065 cgroup = get_pid_cgroup(initpid, "memory");
1066 if (!cgroup)
1067 return read_file_fuse("/proc/meminfo", buf, size, d);
1068
1069 prune_init_slice(cgroup);
1070
1071 memlimit = get_min_memlimit(cgroup, false);
1072
1073 ret = cgroup_ops->get_memory_current(cgroup_ops, cgroup, &memusage_str);
1074 if (ret < 0)
1075 return 0;
1076
1077 if (!cgroup_parse_memory_stat(cgroup, &mstat))
1078 return 0;
1079
1080 /*
1081 * Following values are allowed to fail, because swapaccount might be
1082 * turned off for current kernel.
1083 */
1084 ret = cgroup_ops->get_memory_swap_max(cgroup_ops, cgroup, &memswlimit_str);
1085 if (ret >= 0)
1086 ret = cgroup_ops->get_memory_swap_current(cgroup_ops, cgroup, &memswusage_str);
1087 if (ret >= 0) {
1088 memswlimit = get_min_memlimit(cgroup, true);
1089 memswusage = strtoul(memswusage_str, NULL, 10);
1090 memswlimit = memswlimit / 1024;
1091 memswusage = memswusage / 1024;
1092 }
1093
1094 memusage = strtoul(memusage_str, NULL, 10);
1095 memlimit /= 1024;
1096 memusage /= 1024;
1097
1098 f = fopen("/proc/meminfo", "re");
1099 if (!f)
1100 return 0;
1101
1102 while (getline(&line, &linelen, f) != -1) {
1103 ssize_t l;
1104 char *printme, lbuf[100];
1105
1106 memset(lbuf, 0, 100);
1107 if (startswith(line, "MemTotal:")) {
1108 sscanf(line+sizeof("MemTotal:")-1, "%" PRIu64, &hosttotal);
1109 if (hosttotal < memlimit)
1110 memlimit = hosttotal;
1111 snprintf(lbuf, 100, "MemTotal: %8" PRIu64 " kB\n", memlimit);
1112 printme = lbuf;
1113 } else if (startswith(line, "MemFree:")) {
1114 snprintf(lbuf, 100, "MemFree: %8" PRIu64 " kB\n", memlimit - memusage);
1115 printme = lbuf;
1116 } else if (startswith(line, "MemAvailable:")) {
1117 snprintf(lbuf, 100, "MemAvailable: %8" PRIu64 " kB\n", memlimit - memusage + mstat.total_cache / 1024);
1118 printme = lbuf;
1119 } else if (startswith(line, "SwapTotal:") && memswlimit > 0 &&
1120 opts && opts->swap_off == false) {
1121 memswlimit -= memlimit;
1122 snprintf(lbuf, 100, "SwapTotal: %8" PRIu64 " kB\n", memswlimit);
1123 printme = lbuf;
1124 } else if (startswith(line, "SwapTotal:") && opts && opts->swap_off == true) {
1125 snprintf(lbuf, 100, "SwapTotal: %8" PRIu64 " kB\n", (uint64_t)0);
1126 printme = lbuf;
1127 } else if (startswith(line, "SwapFree:") && memswlimit > 0 &&
1128 memswusage > 0 && opts && opts->swap_off == false) {
1129 uint64_t swaptotal = memswlimit,
1130 swapusage = memusage > memswusage
1131 ? 0
1132 : memswusage - memusage,
1133 swapfree = swapusage < swaptotal
1134 ? swaptotal - swapusage
1135 : 0;
1136 snprintf(lbuf, 100, "SwapFree: %8" PRIu64 " kB\n", swapfree);
1137 printme = lbuf;
1138 } else if (startswith(line, "SwapFree:") && opts && opts->swap_off == true) {
1139 snprintf(lbuf, 100, "SwapFree: %8" PRIu64 " kB\n", (uint64_t)0);
1140 printme = lbuf;
1141 } else if (startswith(line, "Slab:")) {
1142 snprintf(lbuf, 100, "Slab: %8" PRIu64 " kB\n", (uint64_t)0);
1143 printme = lbuf;
1144 } else if (startswith(line, "Buffers:")) {
1145 snprintf(lbuf, 100, "Buffers: %8" PRIu64 " kB\n", (uint64_t)0);
1146 printme = lbuf;
1147 } else if (startswith(line, "Cached:")) {
1148 snprintf(lbuf, 100, "Cached: %8" PRIu64 " kB\n",
1149 mstat.total_cache / 1024);
1150 printme = lbuf;
1151 } else if (startswith(line, "SwapCached:")) {
1152 snprintf(lbuf, 100, "SwapCached: %8" PRIu64 " kB\n", (uint64_t)0);
1153 printme = lbuf;
1154 } else if (startswith(line, "Active:")) {
1155 snprintf(lbuf, 100, "Active: %8" PRIu64 " kB\n",
1156 (mstat.total_active_anon +
1157 mstat.total_active_file) /
1158 1024);
1159 printme = lbuf;
1160 } else if (startswith(line, "Inactive:")) {
1161 snprintf(lbuf, 100, "Inactive: %8" PRIu64 " kB\n",
1162 (mstat.total_inactive_anon +
1163 mstat.total_inactive_file) /
1164 1024);
1165 printme = lbuf;
1166 } else if (startswith(line, "Active(anon)")) {
1167 snprintf(lbuf, 100, "Active(anon): %8" PRIu64 " kB\n",
1168 mstat.total_active_anon / 1024);
1169 printme = lbuf;
1170 } else if (startswith(line, "Inactive(anon)")) {
1171 snprintf(lbuf, 100, "Inactive(anon): %8" PRIu64 " kB\n",
1172 mstat.total_inactive_anon / 1024);
1173 printme = lbuf;
1174 } else if (startswith(line, "Active(file)")) {
1175 snprintf(lbuf, 100, "Active(file): %8" PRIu64 " kB\n",
1176 mstat.total_active_file / 1024);
1177 printme = lbuf;
1178 } else if (startswith(line, "Inactive(file)")) {
1179 snprintf(lbuf, 100, "Inactive(file): %8" PRIu64 " kB\n",
1180 mstat.total_inactive_file / 1024);
1181 printme = lbuf;
1182 } else if (startswith(line, "Unevictable")) {
1183 snprintf(lbuf, 100, "Unevictable: %8" PRIu64 " kB\n",
1184 mstat.total_unevictable / 1024);
1185 printme = lbuf;
1186 } else if (startswith(line, "Dirty")) {
1187 snprintf(lbuf, 100, "Dirty: %8" PRIu64 " kB\n",
1188 mstat.total_dirty / 1024);
1189 printme = lbuf;
1190 } else if (startswith(line, "Writeback")) {
1191 snprintf(lbuf, 100, "Writeback: %8" PRIu64 " kB\n",
1192 mstat.total_writeback / 1024);
1193 printme = lbuf;
1194 } else if (startswith(line, "AnonPages")) {
1195 snprintf(lbuf, 100, "AnonPages: %8" PRIu64 " kB\n",
1196 (mstat.total_active_anon +
1197 mstat.total_inactive_anon - mstat.total_shmem) /
1198 1024);
1199 printme = lbuf;
1200 } else if (startswith(line, "Mapped")) {
1201 snprintf(lbuf, 100, "Mapped: %8" PRIu64 " kB\n",
1202 mstat.total_mapped_file / 1024);
1203 printme = lbuf;
1204 } else if (startswith(line, "SReclaimable")) {
1205 snprintf(lbuf, 100, "SReclaimable: %8" PRIu64 " kB\n", (uint64_t)0);
1206 printme = lbuf;
1207 } else if (startswith(line, "SUnreclaim")) {
1208 snprintf(lbuf, 100, "SUnreclaim: %8" PRIu64 " kB\n", (uint64_t)0);
1209 printme = lbuf;
1210 } else if (startswith(line, "Shmem:")) {
1211 snprintf(lbuf, 100, "Shmem: %8" PRIu64 " kB\n",
1212 mstat.total_shmem / 1024);
1213 printme = lbuf;
1214 } else if (startswith(line, "ShmemHugePages")) {
1215 snprintf(lbuf, 100, "ShmemHugePages: %8" PRIu64 " kB\n", (uint64_t)0);
1216 printme = lbuf;
1217 } else if (startswith(line, "ShmemPmdMapped")) {
1218 snprintf(lbuf, 100, "ShmemPmdMapped: %8" PRIu64 " kB\n", (uint64_t)0);
1219 printme = lbuf;
1220 } else if (startswith(line, "AnonHugePages")) {
1221 snprintf(lbuf, 100, "AnonHugePages: %8" PRIu64 " kB\n",
1222 mstat.total_rss_huge / 1024);
1223 printme = lbuf;
1224 } else {
1225 printme = line;
1226 }
1227
1228 l = snprintf(cache, cache_size, "%s", printme);
1229 if (l < 0) {
1230 perror("Error writing to cache");
1231 return 0;
1232
1233 }
1234 if (l >= cache_size) {
1235 lxcfs_error("%s\n", "Internal error: truncated write to cache.");
1236 return 0;
1237 }
1238
1239 cache += l;
1240 cache_size -= l;
1241 total_len += l;
1242 }
1243
1244 d->cached = 1;
1245 d->size = total_len;
1246 if (total_len > size ) total_len = size;
1247 memcpy(buf, d->buf, total_len);
1248
1249 return total_len;
1250 }
1251
1252 int proc_read(const char *path, char *buf, size_t size, off_t offset,
1253 struct fuse_file_info *fi)
1254 {
1255 struct file_info *f = INTTYPE_TO_PTR(fi->fh);
1256
1257 switch (f->type) {
1258 case LXC_TYPE_PROC_MEMINFO:
1259 return proc_meminfo_read(buf, size, offset, fi);
1260 case LXC_TYPE_PROC_CPUINFO:
1261 return proc_cpuinfo_read(buf, size, offset, fi);
1262 case LXC_TYPE_PROC_UPTIME:
1263 return proc_uptime_read(buf, size, offset, fi);
1264 case LXC_TYPE_PROC_STAT:
1265 return proc_stat_read(buf, size, offset, fi);
1266 case LXC_TYPE_PROC_DISKSTATS:
1267 return proc_diskstats_read(buf, size, offset, fi);
1268 case LXC_TYPE_PROC_SWAPS:
1269 return proc_swaps_read(buf, size, offset, fi);
1270 case LXC_TYPE_PROC_LOADAVG:
1271 return proc_loadavg_read(buf, size, offset, fi);
1272 }
1273
1274 return -EINVAL;
1275 }