Skip to content

Commit 35d35d3

Browse files
committed
Added mounts module
This module lists all the mount points from a given vmcore Signed-off-by: Gautham Ananthakrishna <[email protected]>
1 parent 630e95e commit 35d35d3

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

drgn_tools/mounts.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright (c) 2023, Oracle and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
import argparse
4+
from typing import Any
5+
from typing import List
6+
7+
import drgn.helpers.linux.fs
8+
9+
from drgn_tools.corelens import CorelensModule
10+
from drgn_tools.table import print_table
11+
12+
13+
def get_mountinfo(prog: drgn.Program) -> List[List[Any]]:
14+
"""
15+
Get all the mount points from the vmcore
16+
17+
:param prog: drgn program
18+
:returns: List of mount points
19+
"""
20+
21+
mount_table = list()
22+
23+
mounts = prog["init_task"].nsproxy.mnt_ns
24+
for mnt in drgn.helpers.linux.fs.for_each_mount(mounts):
25+
devname = mnt.mnt_devname
26+
fstype = mnt.mnt.mnt_sb.s_type.name
27+
mntpt = drgn.helpers.linux.fs.d_path(
28+
mnt.mnt.address_of_(), mnt.mnt_mountpoint
29+
)
30+
31+
mount_stats = [
32+
devname.string_().decode("utf-8"),
33+
fstype.string_().decode("utf-8"),
34+
mntpt.decode("utf-8"),
35+
]
36+
mount_table.append(mount_stats)
37+
return mount_table
38+
39+
40+
def mountinfo(prog: drgn.Program) -> None:
41+
"""
42+
Print all the mount points from the vmcore
43+
44+
:param prog: drgn program
45+
:returns: None
46+
"""
47+
mnt_tbl = get_mountinfo(prog)
48+
mnt_tbl.insert(0, ["-------", "------", "-------"])
49+
mnt_tbl.insert(0, ["DEVNAME", "TYPE", "DIRNAME"])
50+
print_table(mnt_tbl)
51+
52+
53+
class Mounts(CorelensModule):
54+
"""Print info about all mount points"""
55+
56+
name = "mounts"
57+
58+
def run(self, prog: drgn.Program, args: argparse.Namespace) -> None:
59+
mountinfo(prog)

tests/test_mounts.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (c) 2023, Oracle and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
from operator import itemgetter
4+
5+
import pytest
6+
7+
from drgn_tools import mounts
8+
9+
10+
def test_print_mounts(prog):
11+
mounts.mountinfo(prog)
12+
13+
14+
def get_proc_mounts():
15+
fields_0_2_1 = itemgetter(0, 2, 1)
16+
proc_mount_table = list()
17+
with open("/proc/mounts", "r") as f:
18+
for line in f.readlines():
19+
field_0, field_2, field_1 = fields_0_2_1(line.split())
20+
proc_mount_table.append([field_0, field_2, field_1])
21+
return proc_mount_table
22+
23+
24+
@pytest.mark.skip_vmcore("*")
25+
def test_show_mounts(prog):
26+
prog_table = mounts.get_mountinfo(prog)
27+
proc_table = get_proc_mounts()
28+
29+
for row in proc_table:
30+
assert row in prog_table

0 commit comments

Comments
 (0)