Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mounts module #17

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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[str]]:
"""
Get all the mount points from the vmcore

:param prog: drgn program
:returns: List of mount points
brenns10 marked this conversation as resolved.
Show resolved Hide resolved
"""

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
brenns10 marked this conversation as resolved.
Show resolved Hide resolved
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):
gtmoth marked this conversation as resolved.
Show resolved Hide resolved
prog_table = mounts.get_mountinfo(prog)
proc_table = get_proc_mounts()

for row in proc_table:
assert row in prog_table