diff options
author | Borislav Petkov <bp@suse.de> | 2013-02-20 10:32:33 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-03-15 12:06:01 -0400 |
commit | 5a439645eaf3c0c64ae303ca57f9a4467cbdc6f3 (patch) | |
tree | cd68923374361de371c8bf168de814e20fe38995 | |
parent | 1355915ac626da30a0c02ccd4569c1e5ce2cbb82 (diff) |
tools/vm: Switch to liblk library
page-flags.c had some older version of debugfs_mount copied from perf so
convert it to using the version in the tools library.
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Link: http://lkml.kernel.org/r/1361374353-30385-8-git-send-email-bp@alien8.de
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/vm/Makefile | 17 | ||||
-rw-r--r-- | tools/vm/page-types.c | 85 |
2 files changed, 21 insertions, 81 deletions
diff --git a/tools/vm/Makefile b/tools/vm/Makefile index 8e30e5c40f8a..24e9ddd93fa4 100644 --- a/tools/vm/Makefile +++ b/tools/vm/Makefile | |||
@@ -1,11 +1,22 @@ | |||
1 | # Makefile for vm tools | 1 | # Makefile for vm tools |
2 | # | ||
3 | TARGETS=page-types slabinfo | ||
4 | |||
5 | LK_DIR = ../lib/lk | ||
6 | LIBLK = $(LK_DIR)/liblk.a | ||
2 | 7 | ||
3 | CC = $(CROSS_COMPILE)gcc | 8 | CC = $(CROSS_COMPILE)gcc |
4 | CFLAGS = -Wall -Wextra | 9 | CFLAGS = -Wall -Wextra -I../lib/ |
10 | LDFLAGS = $(LIBLK) | ||
11 | |||
12 | $(TARGETS): liblk | ||
13 | |||
14 | liblk: | ||
15 | make -C $(LK_DIR) | ||
5 | 16 | ||
6 | all: page-types slabinfo | ||
7 | %: %.c | 17 | %: %.c |
8 | $(CC) $(CFLAGS) -o $@ $^ | 18 | $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) |
9 | 19 | ||
10 | clean: | 20 | clean: |
11 | $(RM) page-types slabinfo | 21 | $(RM) page-types slabinfo |
22 | make -C ../lib/lk clean | ||
diff --git a/tools/vm/page-types.c b/tools/vm/page-types.c index b76edf2f8333..71c9c2511ee7 100644 --- a/tools/vm/page-types.c +++ b/tools/vm/page-types.c | |||
@@ -36,7 +36,7 @@ | |||
36 | #include <sys/statfs.h> | 36 | #include <sys/statfs.h> |
37 | #include "../../include/uapi/linux/magic.h" | 37 | #include "../../include/uapi/linux/magic.h" |
38 | #include "../../include/uapi/linux/kernel-page-flags.h" | 38 | #include "../../include/uapi/linux/kernel-page-flags.h" |
39 | 39 | #include <lk/debugfs.h> | |
40 | 40 | ||
41 | #ifndef MAX_PATH | 41 | #ifndef MAX_PATH |
42 | # define MAX_PATH 256 | 42 | # define MAX_PATH 256 |
@@ -178,7 +178,7 @@ static int kpageflags_fd; | |||
178 | static int opt_hwpoison; | 178 | static int opt_hwpoison; |
179 | static int opt_unpoison; | 179 | static int opt_unpoison; |
180 | 180 | ||
181 | static char hwpoison_debug_fs[MAX_PATH+1]; | 181 | static char *hwpoison_debug_fs; |
182 | static int hwpoison_inject_fd; | 182 | static int hwpoison_inject_fd; |
183 | static int hwpoison_forget_fd; | 183 | static int hwpoison_forget_fd; |
184 | 184 | ||
@@ -458,81 +458,6 @@ static uint64_t kpageflags_flags(uint64_t flags) | |||
458 | return flags; | 458 | return flags; |
459 | } | 459 | } |
460 | 460 | ||
461 | /* verify that a mountpoint is actually a debugfs instance */ | ||
462 | static int debugfs_valid_mountpoint(const char *debugfs) | ||
463 | { | ||
464 | struct statfs st_fs; | ||
465 | |||
466 | if (statfs(debugfs, &st_fs) < 0) | ||
467 | return -ENOENT; | ||
468 | else if (st_fs.f_type != (long) DEBUGFS_MAGIC) | ||
469 | return -ENOENT; | ||
470 | |||
471 | return 0; | ||
472 | } | ||
473 | |||
474 | /* find the path to the mounted debugfs */ | ||
475 | static const char *debugfs_find_mountpoint(void) | ||
476 | { | ||
477 | const char *const *ptr; | ||
478 | char type[100]; | ||
479 | FILE *fp; | ||
480 | |||
481 | ptr = debugfs_known_mountpoints; | ||
482 | while (*ptr) { | ||
483 | if (debugfs_valid_mountpoint(*ptr) == 0) { | ||
484 | strcpy(hwpoison_debug_fs, *ptr); | ||
485 | return hwpoison_debug_fs; | ||
486 | } | ||
487 | ptr++; | ||
488 | } | ||
489 | |||
490 | /* give up and parse /proc/mounts */ | ||
491 | fp = fopen("/proc/mounts", "r"); | ||
492 | if (fp == NULL) | ||
493 | perror("Can't open /proc/mounts for read"); | ||
494 | |||
495 | while (fscanf(fp, "%*s %" | ||
496 | STR(MAX_PATH) | ||
497 | "s %99s %*s %*d %*d\n", | ||
498 | hwpoison_debug_fs, type) == 2) { | ||
499 | if (strcmp(type, "debugfs") == 0) | ||
500 | break; | ||
501 | } | ||
502 | fclose(fp); | ||
503 | |||
504 | if (strcmp(type, "debugfs") != 0) | ||
505 | return NULL; | ||
506 | |||
507 | return hwpoison_debug_fs; | ||
508 | } | ||
509 | |||
510 | /* mount the debugfs somewhere if it's not mounted */ | ||
511 | |||
512 | static void debugfs_mount(void) | ||
513 | { | ||
514 | const char *const *ptr; | ||
515 | |||
516 | /* see if it's already mounted */ | ||
517 | if (debugfs_find_mountpoint()) | ||
518 | return; | ||
519 | |||
520 | ptr = debugfs_known_mountpoints; | ||
521 | while (*ptr) { | ||
522 | if (mount(NULL, *ptr, "debugfs", 0, NULL) == 0) { | ||
523 | /* save the mountpoint */ | ||
524 | strcpy(hwpoison_debug_fs, *ptr); | ||
525 | break; | ||
526 | } | ||
527 | ptr++; | ||
528 | } | ||
529 | |||
530 | if (*ptr == NULL) { | ||
531 | perror("mount debugfs"); | ||
532 | exit(EXIT_FAILURE); | ||
533 | } | ||
534 | } | ||
535 | |||
536 | /* | 461 | /* |
537 | * page actions | 462 | * page actions |
538 | */ | 463 | */ |
@@ -541,7 +466,11 @@ static void prepare_hwpoison_fd(void) | |||
541 | { | 466 | { |
542 | char buf[MAX_PATH + 1]; | 467 | char buf[MAX_PATH + 1]; |
543 | 468 | ||
544 | debugfs_mount(); | 469 | hwpoison_debug_fs = debugfs_mount(NULL); |
470 | if (!hwpoison_debug_fs) { | ||
471 | perror("mount debugfs"); | ||
472 | exit(EXIT_FAILURE); | ||
473 | } | ||
545 | 474 | ||
546 | if (opt_hwpoison && !hwpoison_inject_fd) { | 475 | if (opt_hwpoison && !hwpoison_inject_fd) { |
547 | snprintf(buf, MAX_PATH, "%s/hwpoison/corrupt-pfn", | 476 | snprintf(buf, MAX_PATH, "%s/hwpoison/corrupt-pfn", |