libsysprof-analyze: parse various data from mountinfo

We still need to parse optional fields for filesystem type and what not
so that we can resolve btrfs subvolumes and more.
This commit is contained in:
Christian Hergert
2023-05-11 13:58:34 -07:00
parent f914580675
commit a393dd9acd
2 changed files with 69 additions and 11 deletions

View File

@ -34,8 +34,10 @@ SysprofMount *sysprof_mount_new_for_mountinfo (SysprofStrings *strings,
const char *mountinfo); const char *mountinfo);
int sysprof_mount_get_device_major (SysprofMount *self); int sysprof_mount_get_device_major (SysprofMount *self);
int sysprof_mount_get_device_minor (SysprofMount *self); int sysprof_mount_get_device_minor (SysprofMount *self);
int sysprof_mount_get_mount_id (SysprofMount *self);
int sysprof_mount_get_parent_mount_id (SysprofMount *self);
const char *sysprof_mount_get_root (SysprofMount *self); const char *sysprof_mount_get_root (SysprofMount *self);
const char *sysprof_mount_get_mount_path (SysprofMount *self); const char *sysprof_mount_get_mount_point (SysprofMount *self);
const char *sysprof_mount_get_mount_source (SysprofMount *self); const char *sysprof_mount_get_mount_source (SysprofMount *self);
const char *sysprof_mount_get_filesystem_type (SysprofMount *self); const char *sysprof_mount_get_filesystem_type (SysprofMount *self);
const char *sysprof_mount_get_superblock_option (SysprofMount *self, const char *sysprof_mount_get_superblock_option (SysprofMount *self,

View File

@ -20,15 +20,19 @@
#include "config.h" #include "config.h"
#include <stdio.h>
#include "sysprof-mount-private.h" #include "sysprof-mount-private.h"
struct _SysprofMount struct _SysprofMount
{ {
GObject parent_instance; GObject parent_instance;
int mount_id;
int parent_mount_id;
int device_major; int device_major;
int device_minor; int device_minor;
GRefString *root; GRefString *root;
GRefString *mount_path; GRefString *mount_point;
GRefString *mount_source; GRefString *mount_source;
GRefString *filesystem_type; GRefString *filesystem_type;
GRefString *superblock_options; GRefString *superblock_options;
@ -39,8 +43,10 @@ enum {
PROP_DEVICE_MAJOR, PROP_DEVICE_MAJOR,
PROP_DEVICE_MINOR, PROP_DEVICE_MINOR,
PROP_ROOT, PROP_ROOT,
PROP_MOUNT_PATH, PROP_MOUNT_ID,
PROP_MOUNT_POINT,
PROP_MOUNT_SOURCE, PROP_MOUNT_SOURCE,
PROP_PARENT_MOUNT_ID,
PROP_FILESYSTEM_TYPE, PROP_FILESYSTEM_TYPE,
N_PROPS N_PROPS
}; };
@ -55,7 +61,7 @@ sysprof_mount_finalize (GObject *object)
SysprofMount *self = (SysprofMount *)object; SysprofMount *self = (SysprofMount *)object;
g_clear_pointer (&self->root, g_ref_string_release); g_clear_pointer (&self->root, g_ref_string_release);
g_clear_pointer (&self->mount_path, g_ref_string_release); g_clear_pointer (&self->mount_point, g_ref_string_release);
g_clear_pointer (&self->mount_source, g_ref_string_release); g_clear_pointer (&self->mount_source, g_ref_string_release);
g_clear_pointer (&self->filesystem_type, g_ref_string_release); g_clear_pointer (&self->filesystem_type, g_ref_string_release);
g_clear_pointer (&self->superblock_options, g_ref_string_release); g_clear_pointer (&self->superblock_options, g_ref_string_release);
@ -85,14 +91,22 @@ sysprof_mount_get_property (GObject *object,
g_value_set_string (value, sysprof_mount_get_root (self)); g_value_set_string (value, sysprof_mount_get_root (self));
break; break;
case PROP_MOUNT_PATH: case PROP_MOUNT_ID:
g_value_set_string (value, sysprof_mount_get_mount_path (self)); g_value_set_int (value, sysprof_mount_get_mount_id (self));
break;
case PROP_MOUNT_POINT:
g_value_set_string (value, sysprof_mount_get_mount_point (self));
break; break;
case PROP_MOUNT_SOURCE: case PROP_MOUNT_SOURCE:
g_value_set_string (value, sysprof_mount_get_mount_source (self)); g_value_set_string (value, sysprof_mount_get_mount_source (self));
break; break;
case PROP_PARENT_MOUNT_ID:
g_value_set_int (value, sysprof_mount_get_parent_mount_id (self));
break;
case PROP_FILESYSTEM_TYPE: case PROP_FILESYSTEM_TYPE:
g_value_set_string (value, sysprof_mount_get_filesystem_type (self)); g_value_set_string (value, sysprof_mount_get_filesystem_type (self));
break; break;
@ -125,8 +139,18 @@ sysprof_mount_class_init (SysprofMountClass *klass)
NULL, NULL,
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
properties[PROP_MOUNT_PATH] = properties[PROP_MOUNT_ID] =
g_param_spec_string ("mount-path", NULL, NULL, g_param_spec_int ("mount-id", NULL, NULL,
G_MININT, G_MAXINT, 0,
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
properties[PROP_PARENT_MOUNT_ID] =
g_param_spec_int ("parent-mount-id", NULL, NULL,
G_MININT, G_MAXINT, 0,
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
properties[PROP_MOUNT_POINT] =
g_param_spec_string ("mount-point", NULL, NULL,
NULL, NULL,
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
@ -152,7 +176,27 @@ SysprofMount *
sysprof_mount_new_for_mountinfo (SysprofStrings *strings, sysprof_mount_new_for_mountinfo (SysprofStrings *strings,
const char *mountinfo) const char *mountinfo)
{ {
return NULL; g_autoptr(SysprofMount) self = NULL;
g_auto(GStrv) parts = NULL;
gsize n_parts;
g_return_val_if_fail (strings != NULL, NULL);
g_return_val_if_fail (mountinfo != NULL, NULL);
parts = g_strsplit (mountinfo, " ", 20);
n_parts = g_strv_length (parts);
if (n_parts < 10)
return NULL;
self = g_object_new (SYSPROF_TYPE_MOUNT, NULL);
self->mount_id = g_ascii_strtoll (parts[0], NULL, 10);
self->parent_mount_id = g_ascii_strtoll (parts[1], NULL, 10);
sscanf (parts[2], "%d:%d", &self->device_major, &self->device_minor);
self->root = sysprof_strings_get (strings, parts[3]);
self->mount_point = sysprof_strings_get (strings, parts[4]);
return g_steal_pointer (&self);
} }
int int
@ -174,9 +218,9 @@ sysprof_mount_get_root (SysprofMount *self)
} }
const char * const char *
sysprof_mount_get_mount_path (SysprofMount *self) sysprof_mount_get_mount_point (SysprofMount *self)
{ {
return self->mount_path; return self->mount_point;
} }
const char * const char *
@ -197,3 +241,15 @@ sysprof_mount_get_superblock_option (SysprofMount *self,
{ {
return NULL; return NULL;
} }
int
sysprof_mount_get_mount_id (SysprofMount *self)
{
return self->mount_id;
}
int
sysprof_mount_get_parent_mount_id (SysprofMount *self)
{
return self->parent_mount_id;
}