From patchwork Mon Feb 22 15:24:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 62590 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1303201lbl; Mon, 22 Feb 2016 07:25:21 -0800 (PST) X-Received: by 10.98.10.86 with SMTP id s83mr38879687pfi.85.1456154720986; Mon, 22 Feb 2016 07:25:20 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z2si40305325par.192.2016.02.22.07.25.20; Mon, 22 Feb 2016 07:25:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dkim=pass header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753468AbcBVPZT (ORCPT + 30 others); Mon, 22 Feb 2016 10:25:19 -0500 Received: from mail-wm0-f50.google.com ([74.125.82.50]:35634 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753376AbcBVPYl (ORCPT ); Mon, 22 Feb 2016 10:24:41 -0500 Received: by mail-wm0-f50.google.com with SMTP id c200so176834173wme.0 for ; Mon, 22 Feb 2016 07:24:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YfOQYVWjhLZcQwlX5e2Bl3dIT3eAn9oRAhSQfg54B60=; b=SECWcIWvhS1nHhG9oVNb37OJa6aw5I66N9w04uSg5fCFBs76kWp9RHDLzfOfdAt0gO KVdhRq/nxJhjMq07nX37sF+lVAnTtKh99AbBUe8MP5/3o/eX/8pw/cGYo5SECxXvDRqZ iPtOKS+/sLIhRJQDVpB/dB3603lVdezeYHfUo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YfOQYVWjhLZcQwlX5e2Bl3dIT3eAn9oRAhSQfg54B60=; b=j+bSGYXJws/LYgd+rImku7YfyUd75gDxEmpgn8HE6ivDNKZ57Ey4wKKRGQ3XqlwJId 9RPO6O9SV4ag6e43k9N+WiLdHFCdE+uDEahk9lBLB0kvPljf+TYMKcsYrsRQPwp3fI/7 EmnaJe5jLbyqBGOUPzpngf6RXtLSFPusvJYJoeuh9yUyjCZ7fJOpqGij2O/kwdvf/U4K 3foncb4wCZNMhLIrg7c91hbyl6c37NQeBIGRYH0KmlsUW8ApQTfevodwZVP8iVE/Agmh bk9qE+yrjsAzQa8PuRhaui9p4HN1JGutmn0aVo61t0GB7A1cdAlsek3WfTPWUcu36ary kE3A== X-Gm-Message-State: AG10YOTjumUJZIsgTbtOsmqc7qZ23ViIb6UVlRV6f9/9AiEJ/KptOVAtesBpHt6qjj8425ep X-Received: by 10.194.90.77 with SMTP id bu13mr27927048wjb.60.1456154671408; Mon, 22 Feb 2016 07:24:31 -0800 (PST) Received: from localhost.localdomain (cpc87017-aztw30-2-0-cust65.18-1.cable.virginm.net. [92.232.232.66]) by smtp.gmail.com with ESMTPSA id w66sm21557528wmd.2.2016.02.22.07.24.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Feb 2016 07:24:27 -0800 (PST) From: Kieran Bingham To: jan.kiszka@siemens.com, linux-kernel@vger.kernel.org Cc: lee.jones@linaro.org, peter.griffin@linaro.org, maxime.coquelin@st.com, Kieran Bingham Subject: [PATCH 7/8] scripts/gdb: Add mount point list command Date: Mon, 22 Feb 2016 15:24:11 +0000 Message-Id: <1456154652-29023-8-git-send-email-kieran.bingham@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456154652-29023-1-git-send-email-kieran.bingham@linaro.org> References: <1456154652-29023-1-git-send-email-kieran.bingham@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org lx-mounts will identify current mount points based on the 'init_task' namespace by default, as we do not yet have a kernel thread list implementation to select the current running thread. Optionally, a user can specify a PID to list from that process' namespace Signed-off-by: Kieran Bingham --- Changes from v1: - Updated to use LX_ constant macros - Adjusted for new list_for_each_item() function - Removed unnessary Null check in vfs['mnt_parent'] - Tested and not needed. It probably occured in early testing with a bad iterator --- scripts/gdb/linux/constants.py.in | 21 ++++++++ scripts/gdb/linux/proc.py | 108 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) -- 2.5.0 diff --git a/scripts/gdb/linux/constants.py.in b/scripts/gdb/linux/constants.py.in index 79d9d0092452..57213ad8cf75 100644 --- a/scripts/gdb/linux/constants.py.in +++ b/scripts/gdb/linux/constants.py.in @@ -12,7 +12,11 @@ * */ +#include +#include + /* We need to stringify expanded macros so that they can be parsed */ + #define STRING(x) #x #define XSTRING(x) STRING(x) @@ -30,3 +34,20 @@ import gdb + +/* linux/fs.h */ +LX_VALUE(MS_RDONLY) +LX_VALUE(MS_SYNCHRONOUS) +LX_VALUE(MS_MANDLOCK) +LX_VALUE(MS_DIRSYNC) +LX_VALUE(MS_NOATIME) +LX_VALUE(MS_NODIRATIME) + +/* linux/mount.h */ +LX_VALUE(MNT_NOSUID) +LX_VALUE(MNT_NODEV) +LX_VALUE(MNT_NOEXEC) +LX_VALUE(MNT_NOATIME) +LX_VALUE(MNT_NODIRATIME) +LX_VALUE(MNT_RELATIME) + diff --git a/scripts/gdb/linux/proc.py b/scripts/gdb/linux/proc.py index d855b2fd9a06..44804e10493e 100644 --- a/scripts/gdb/linux/proc.py +++ b/scripts/gdb/linux/proc.py @@ -12,6 +12,10 @@ # import gdb +from linux import constants +from linux import utils +from linux import tasks +from linux import lists class LxCmdLine(gdb.Command): @@ -96,3 +100,107 @@ Equivalent to cat /proc/ioports on a running target""" return show_lx_resources("ioport_resource") LxIOPorts() + + +# Mount namespace viewer +# /proc/mounts + + +def dentry_name(d): + parent = d['d_parent'] + if parent == d or parent == 0: + return "" + p = dentry_name(d['d_parent']) + "/" + return p + d['d_iname'].string() + + +def info_opts(lst, opt): + opts = "" + for key, string in lst.items(): + if opt & key: + opts += string + return opts + + +FS_INFO = {constants.LX_MS_SYNCHRONOUS: ",sync", + constants.LX_MS_MANDLOCK: ",mand", + constants.LX_MS_DIRSYNC: ",dirsync", + constants.LX_MS_NOATIME: ",noatime", + constants.LX_MS_NODIRATIME: ",nodiratime"} + +MNT_INFO = {constants.LX_MNT_NOSUID: ",nosuid", + constants.LX_MNT_NODEV: ",nodev", + constants.LX_MNT_NOEXEC: ",noexec", + constants.LX_MNT_NOATIME: ",noatime", + constants.LX_MNT_NODIRATIME: ",nodiratime", + constants.LX_MNT_RELATIME: ",relatime"} + +mount_type = utils.CachedType("struct mount") +mount_ptr_type = mount_type.get_type().pointer() + + +class LxMounts(gdb.Command): + """Report the VFS mounts of the current process namespace. + +Equivalent to cat /proc/mounts on a running target +An integer value can be supplied to display the mount +values of that process namespace""" + + def __init__(self): + super(LxMounts, self).__init__("lx-mounts", gdb.COMMAND_DATA) + + # Equivalent to proc_namespace.c:show_vfsmnt + # However, that has the ability to call into s_op functions + # whereas we cannot and must make do with the information we can obtain. + def invoke(self, arg, from_tty): + argv = gdb.string_to_argv(arg) + if len(argv) >= 1: + try: + pid = int(argv[0]) + except: + raise gdb.GdbError("Provide a PID as integer value") + else: + pid = 1 + + task = tasks.get_task_by_pid(pid) + if not task: + raise gdb.GdbError("Couldn't find a process with PID {}" + .format(pid)) + + namespace = task['nsproxy']['mnt_ns'] + if not namespace: + raise gdb.GdbError("No namespace for current process") + + for vfs in lists.list_for_each_entry( + namespace['list'], mount_ptr_type, "mnt_list"): + devname = vfs['mnt_devname'].string() + devname = devname if devname else "none" + + pathname = "" + parent = vfs + while True: + mntpoint = parent['mnt_mountpoint'] + pathname = dentry_name(mntpoint) + pathname + if (parent == parent['mnt_parent']): + break + parent = parent['mnt_parent'] + + if (pathname == ""): + pathname = "/" + + superblock = vfs['mnt']['mnt_sb'] + fstype = superblock['s_type']['name'].string() + s_flags = int(superblock['s_flags']) + m_flags = int(vfs['mnt']['mnt_flags']) + rd = "ro" if (s_flags & constants.LX_MS_RDONLY) else "rw" + + gdb.write( + "{} {} {} {}{}{} 0 0\n" + .format(devname, + pathname, + fstype, + rd, + info_opts(FS_INFO, s_flags), + info_opts(MNT_INFO, m_flags))) + +LxMounts()