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

Timofey Titovets nefelim4ag at gmail.com
Fri Oct 31 06:01:45 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 rewrite to parse /proc/self/mountinfo
This only support root device like /dev/???*
I can't support LVM/Luks & etc, i'm not using these setups.

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

v4:
	Again rewrited.
	Search "/" in 5th column and
	parse get name of bdev from 10th column

Not tested while boot process, code in separate binary file working good.

 From 97d259c38da3a32569e30bfaf7df56c062c570a6 Mon Sep 17 00:00:00 2001
From: Timofey Titovets <nefelim4ag at gmail.com>
Date: Fri, 31 Oct 2014 15:43:30 +0300
Subject: [PATCH] Bootchart: use /proc/pid/mountinfo for root bdev

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

diff --git a/src/bootchart/svg.c b/src/bootchart/svg.c
index faf377e..2e9c039 100644
--- a/src/bootchart/svg.c
+++ b/src/bootchart/svg.c
@@ -151,6 +151,22 @@ static void svg_header(void) {
          svg("    ]]>\n   </style>\n</defs>\n\n");
  }

+void get_rootbdev(char *rootbdev) {
+        FILE *file = fopen("/proc/self/mountinfo", "r");
+        char mnt_point[PATH_MAX];
+        char mnt_source[PATH_MAX];
+        char t[256]; // Trash
+        while (file && strcmp(mnt_point, "/") && !feof(file)){
+        fscanf(file, "%s %s %s %s %s %s %s %s %s %s %s",
+               t,t,t,t,
+               mnt_point,  t,t,t,t,
+               mnt_source, t);
+        }
+        if(!strcmp(mnt_point, "/"))
+                strncpy(rootbdev, &mnt_source[5], 3);
+        fclose(file);
+}
+
  static void svg_title(const char *build) {
          char cmdline[256] = "";
          char filename[PATH_MAX];
@@ -159,7 +175,6 @@ static void svg_title(const char *build) {
          char model[256] = "Unknown";
          char date[256] = "Unknown";
          char cpu[256] = "Unknown";
-        char *c;
          FILE *f;
          time_t t;
          int fd, r;
@@ -174,12 +189,10 @@ 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);
-                rootbdev[3] = '\0';
+        f = fopen("/proc/self/mountinfo", "r");
+        if (f) {
+                fclose(f);
+                get_rootbdev(rootbdev);
                  sprintf(filename, "block/%s/device/model", rootbdev);
                  fd = openat(sysfd, filename, O_RDONLY);
                  f = fdopen(fd, "r");
-- 
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: 2174 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20141031/20baf0fe/attachment.bin>


More information about the systemd-devel mailing list