[systemd-devel] [PATCH v3] Bootchart: use /proc/pid/mountinfo for root bdev

Timofey Titovets nefelim4ag at gmail.com
Thu Oct 30 07:45:53 PDT 2014


Good time of day, list.
I have try to fix "Fixme" in svg.c:
/* FIXME: this works only in the simple case */

By default function try to get only root=/dev/*
I also attach patch. Thanks.

v2:
	Rewrited with use fstab_node_to_udev_node() and 
canonicalize_file_name() functions.
v3:
	Rewrited for parsing /proc/self/mountinfo

Please test it, i'm can't test because i not have /proc/schedstat file 
(custom kernel)

I use " 0 " for searching root device its correct?
For test:
[$]: grep " 0 " /proc/self/mountinfo

I'm not use major:minor because on some setups it useless.
As example, my system root:
50 0 0:28 /@ / rw,relatime shared:1 - btrfs /dev/sda3 
rw,compress=zlib,space_cache,autodefrag

0:28 What?
But my system partition have 8:3
But i have only: /sys/class/bdi/8:0 and 8:1
What i missed?


 From df889766a0dae0700cbc1378699e1abbad6b3f8d Mon Sep 17 00:00:00 2001
From: Timofey Titovets <nefelim4ag at gmail.com>
Date: Thu, 30 Oct 2014 17:23:32 +0300
Subject: [PATCH] Bootchart: use /proc/pid/mountinfo for root bdev

---
  src/bootchart/svg.c | 16 +++++++++-------
  1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/bootchart/svg.c b/src/bootchart/svg.c
index faf377e..a6a69c1 100644
--- a/src/bootchart/svg.c
+++ b/src/bootchart/svg.c
@@ -33,6 +33,7 @@
  #include <sys/stat.h>
  #include <fcntl.h>

+#include "fileio.h"
  #include "util.h"
  #include "macro.h"
  #include "store.h"
@@ -153,16 +154,16 @@ static void svg_header(void) {

  static void svg_title(const char *build) {
          char cmdline[256] = "";
-        char filename[PATH_MAX];
          char buf[256];
          char rootbdev[16] = "Unknown";
          char model[256] = "Unknown";
          char date[256] = "Unknown";
          char cpu[256] = "Unknown";
-        char *c;
+        char *ptr = NULL;
          FILE *f;
          time_t t;
          int fd, r;
+        size_t length = 0;
          struct utsname uts;

          /* grab /proc/cmdline */
@@ -174,11 +175,12 @@ static void svg_title(const char *build) {
                  fclose(f);
          }

-        /* extract root fs so we can find disk model name in sysfs */
-        /* FIXME: this works only in the simple case */
-        c = strstr(cmdline, "root=/dev/");
-        if (c) {
-                strncpy(rootbdev, &c[10], 3);
+        r = read_full_file("/proc/self/mountinfo", &ptr, &length);
+        if (!r) {
+                char filename[PATH_MAX]="";
+                ptr = strtok(ptr, " 0 ");
+                ptr = strtok(ptr, " /dev/");
+                strncpy(rootbdev, &ptr[6], 3);
                  rootbdev[3] = '\0';
                  sprintf(filename, "block/%s/device/model", rootbdev);
                  fd = openat(sysfd, filename, O_RDONLY);
-- 
2.1.3


-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Bootchart-use-proc-pid-mountinfo-for-root-bdev.patch
Type: text/x-patch
Size: 1924 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20141030/b3490473/attachment.bin>


More information about the systemd-devel mailing list