generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This module lists all the mount points from a given vmcore Signed-off-by: Gautham Ananthakrishna <[email protected]>
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |