Skip to content

Commit

Permalink
Added mounts module
Browse files Browse the repository at this point in the history
Signed-off-by: Gautham Ananthakrishna <[email protected]>
  • Loading branch information
gtmoth committed Nov 6, 2023
1 parent 630e95e commit bfc1ee2
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,10 @@ drgn_tools.cpuinfo

.. automodule:: drgn_tools.cpuinfo
:members:


drgn_tools.mounts
-----------------------

.. automodule:: drgn_tools.mounts
:members:
1 change: 1 addition & 0 deletions drgn_tools/corelens.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def all_corelens_modules() -> Dict[str, CorelensModule]:
# with simply maintaining a list of Python modules which contain
# CorelensModule subclasses.
python_mods = [
"drgn_tools.mounts",
"drgn_tools.printk",
"drgn_tools.nvme",
"drgn_tools.virtio",
Expand Down
58 changes: 58 additions & 0 deletions drgn_tools/mounts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright (c) 2023, Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
import argparse
from typing import Any
from typing import List

import drgn.helpers.linux.fs

from drgn_tools.corelens import CorelensModule
from drgn_tools.table import print_table


def get_mountinfo(prog: drgn.Program) -> List[List[Any]]:
"""
Get all the mount points from the vmcore
:param prog: drgn program
:returns: List of mount points
"""

mount_table = [["DEVNAME", "TYPE", "DIRNAME"]]
mount_table.append(["-------", "------", "-------"])

mounts = prog["init_task"].nsproxy.mnt_ns
for mnt in drgn.helpers.linux.fs.for_each_mount(mounts):
devname = mnt.mnt_devname
fstype = mnt.mnt.mnt_sb.s_type.name
mntpt = drgn.helpers.linux.fs.d_path(
mnt.mnt.address_of_(), mnt.mnt_mountpoint
)

mount_stats = [
devname.string_().decode("utf-8"),
fstype.string_().decode("utf-8"),
mntpt.decode("utf-8"),
]
mount_table.append(mount_stats)
return mount_table


def mountinfo(prog: drgn.Program) -> None:
"""
Print all the mount points from the vmcore
:param prog: drgn program
:returns: None
"""
mnt_tbl = get_mountinfo(prog)
print_table(mnt_tbl)


class Mounts(CorelensModule):
"""Print info about all mount points"""

name = "mounts"

def run(self, prog: drgn.Program, args: argparse.Namespace) -> None:
mountinfo(prog)
34 changes: 34 additions & 0 deletions tests/test_mounts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) 2023, Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
from operator import itemgetter

from drgn_tools import mounts
from drgn_tools.table import print_table


def get_proc_mounts():
fields_0_2_1 = itemgetter(0, 2, 1)
proc_mount_table = [["DEVNAME", "TYPE", "DIRNAME"]]
proc_mount_table.append(["-------", "------", "-------"])
with open("/proc/mounts", "r") as f:
for line in f.readlines():
field_0, field_2, field_1 = fields_0_2_1(line.split())
proc_mount_table.append([field_0, field_2, field_1])
return proc_mount_table


def test_show_mounts(prog):
differences = []
prog_table = mounts.get_mountinfo(prog)
proc_table = get_proc_mounts()

for row in prog_table:
if row not in proc_table:
differences.append(row)

difflen = len(differences)
if difflen > 0:
print("The /proc/mount is")
print_table(proc_table)
print("The mounts from the vmcore are")
print_table(prog_table)

0 comments on commit bfc1ee2

Please sign in to comment.