From patchwork Thu Mar 3 11:41:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 63470 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp2896280lbc; Thu, 3 Mar 2016 03:46:51 -0800 (PST) X-Received: by 10.98.43.149 with SMTP id r143mr2948289pfr.7.1457005611224; Thu, 03 Mar 2016 03:46:51 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qp8si41503813pac.244.2016.03.03.03.46.50; Thu, 03 Mar 2016 03:46:51 -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 S932357AbcCCLqt (ORCPT + 30 others); Thu, 3 Mar 2016 06:46:49 -0500 Received: from mail-wm0-f49.google.com ([74.125.82.49]:32928 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756892AbcCCLlZ (ORCPT ); Thu, 3 Mar 2016 06:41:25 -0500 Received: by mail-wm0-f49.google.com with SMTP id l68so30811094wml.0 for ; Thu, 03 Mar 2016 03:41:25 -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=qy+Oz1inWwWYVyJ0aoc68ehdqKtJOBFVUNdeqPg8kno=; b=KM6i+ocVqCmF7MjUcuYgAJh5MP0uEvMoxPP3c64fJecL/Er+C8cY0S/SDXFsLdoP75 VIwTbpWftFnr6EfAtC1HJXJwou86Ut0lVwmfJ5UB/6Iz8T4J0gxA0xn+uLPEYQ9grg7Y NYC2TAZdoq4iHv0lZeh240cLVd8mteVdFuSYI= 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=qy+Oz1inWwWYVyJ0aoc68ehdqKtJOBFVUNdeqPg8kno=; b=T18DagVpfwt1fwQLdrlaC47fC//PZJqaamOwnFdH5SHiDjYRwiAW4NB12R+j5DkSg+ lNK1NVsaAYIkEe4HpuNGyT/HLG026k1+raHQhJVxuFsXPMjKcPfmH50VEzHD91NDJsB4 aY3E5azVarld0SPHvsJIzbZJdiNtHhVaNOH0Uy02Le7z9vSZRQpZWYEUVp8SXDuzk7BN YEw8U2xrpb6fJ/l+xYSrQmHlvxqyDqgShDWIB+XqryIbjAC2ZMdleXNA/J1zayS96mxv 3aBvGcRRxtr2JWaf9cKzaUnw2negHuMq10dpUtswQDCn5WRmSnqiJVzexvsIENkUcUjN 68cw== X-Gm-Message-State: AD7BkJJzYmtb9l4s0SkqWdONkKHyiiFVP4q8voaKYjFl8m6Aex14pSIC4TCVSlf0EF4KTFpp X-Received: by 10.194.115.8 with SMTP id jk8mr2676907wjb.136.1457005284415; Thu, 03 Mar 2016 03:41:24 -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 e19sm8570696wmd.1.2016.03.03.03.41.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Mar 2016 03:41:23 -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: [PATCHv3 08/13] scripts/gdb: Add mount point list command Date: Thu, 3 Mar 2016 11:41:02 +0000 Message-Id: <1457005267-843-9-git-send-email-kieran.bingham@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1457005267-843-1-git-send-email-kieran.bingham@linaro.org> References: <1457005267-843-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 Changes since v2: - dentry path helper moved to utils module --- scripts/gdb/linux/constants.py.in | 21 +++++++++ scripts/gdb/linux/proc.py | 99 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 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..115f20b07a54 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,98 @@ Equivalent to cat /proc/ioports on a running target""" return show_lx_resources("ioport_resource") LxIOPorts() + + +# Mount namespace viewer +# /proc/mounts + +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 = utils.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()