Skip to content

Commit

Permalink
Added mounts module
Browse files Browse the repository at this point in the history
This module lists all the mount points from a given vmcore

Signed-off-by: Gautham Ananthakrishna <[email protected]>
  • Loading branch information
gtmoth committed Nov 21, 2023
1 parent 630e95e commit 35d35d3
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
59 changes: 59 additions & 0 deletions drgn_tools/mounts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 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 = list()

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)
mnt_tbl.insert(0, ["-------", "------", "-------"])
mnt_tbl.insert(0, ["DEVNAME", "TYPE", "DIRNAME"])
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)
30 changes: 30 additions & 0 deletions tests/test_mounts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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

import pytest

from drgn_tools import mounts


def test_print_mounts(prog):
mounts.mountinfo(prog)


def get_proc_mounts():
fields_0_2_1 = itemgetter(0, 2, 1)
proc_mount_table = list()
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


@pytest.mark.skip_vmcore("*")
def test_show_mounts(prog):
prog_table = mounts.get_mountinfo(prog)
proc_table = get_proc_mounts()

for row in proc_table:
assert row in prog_table

0 comments on commit 35d35d3

Please sign in to comment.