aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBorislav Petkov <bp@suse.de>2013-02-20 10:32:33 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-03-15 12:06:01 -0400
commit5a439645eaf3c0c64ae303ca57f9a4467cbdc6f3 (patch)
treecd68923374361de371c8bf168de814e20fe38995
parent1355915ac626da30a0c02ccd4569c1e5ce2cbb82 (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/Makefile17
-rw-r--r--tools/vm/page-types.c85
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#
3TARGETS=page-types slabinfo
4
5LK_DIR = ../lib/lk
6LIBLK = $(LK_DIR)/liblk.a
2 7
3CC = $(CROSS_COMPILE)gcc 8CC = $(CROSS_COMPILE)gcc
4CFLAGS = -Wall -Wextra 9CFLAGS = -Wall -Wextra -I../lib/
10LDFLAGS = $(LIBLK)
11
12$(TARGETS): liblk
13
14liblk:
15 make -C $(LK_DIR)
5 16
6all: page-types slabinfo
7%: %.c 17%: %.c
8 $(CC) $(CFLAGS) -o $@ $^ 18 $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
9 19
10clean: 20clean:
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;
178static int opt_hwpoison; 178static int opt_hwpoison;
179static int opt_unpoison; 179static int opt_unpoison;
180 180
181static char hwpoison_debug_fs[MAX_PATH+1]; 181static char *hwpoison_debug_fs;
182static int hwpoison_inject_fd; 182static int hwpoison_inject_fd;
183static int hwpoison_forget_fd; 183static 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 */
462static 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 */
475static 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
512static 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",