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.
Signed-off-by: Gautham Ananthakrishna <[email protected]>
- Loading branch information
Showing
4 changed files
with
100 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
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
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,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) |
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,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) |