Received: by 10.223.164.202 with SMTP id h10csp3568263wrb; Mon, 20 Nov 2017 01:10:18 -0800 (PST) X-Google-Smtp-Source: AGs4zMaa1izAktiyi1jMOQ8Z9lAXL8+iS/+SGImbMgBdFEQx9b+mz3Qs8v4fVC418VRvDh/LqS5Z X-Received: by 10.84.148.134 with SMTP id k6mr12914123pla.117.1511169018116; Mon, 20 Nov 2017 01:10:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511169018; cv=none; d=google.com; s=arc-20160816; b=su83iJlfWCIdtYZmO8tbwj/9BRB1pjJ1uVhrbAy9g9fFnYsZoID9fHHazZJSMz2FV/ FnO5czEil3fT2Ou5glFFBqCw/7XqLyYFuEuNQ4zG/vrZ9FH4TcjSUErqfCHwPqVKH7UQ uDbYq3bu+lOY1/abgpuxb7sjRxe1vLyg0e9AvP1PvdI7sfRR9abY/BJv2ixfTGjys7rY nb/9HCxMH0FUT1rJXg36tRQqXA03n4nIr2EIF6WHuBMmenrERZV8yIBt8E7nfmk/QLO4 r/8q5OuUNlmAXGBmzQOV/ef02D7SZXvrOGlDU+pkRXaikmIYtgp4UREQPxRTRY0xbiN9 pWlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:references:in-reply-to:reply-to:mime-version :dkim-signature:arc-authentication-results; bh=9u1+5BQ7M6PsI4XYTN2PrbPLzJQBsGdo5QWPZ1J2zlY=; b=o1L/t/CSqUJ4heXQZY/FscVtSuXs/8wGEtvYDakev1iY41aEBHL1pchG44N1tzddki ZtMqti88fznSGBbNKNXt9sZvpM9BnO+ljq4jE2El9jlEGmXFqevyquqkRDmh9XehOYx/ WIaCNS6Q6taQxRrk0dDFkCqVwrEizJ98hm7lSaSHTGmZVlHAxTsrY2HM7H/5dfroncFI loJNxPsk637JNmnlHtvHh/Dz9IaU/b6A81XSwZvh3LhI4zrq7138WbqD4QbUh1K0EUqb x02vTeZAOFSS8qPB2i5It2c9fMCks8IGC4iuyJ40M/r4WlOMhAl7s0fypZxnaOIJJRaw 83Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pQbrtF2q; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p14si7480410pgu.569.2017.11.20.01.10.08; Mon, 20 Nov 2017 01:10:18 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pQbrtF2q; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751042AbdKTJH4 (ORCPT + 68 others); Mon, 20 Nov 2017 04:07:56 -0500 Received: from mail-wm0-f41.google.com ([74.125.82.41]:34400 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751107AbdKTJHv (ORCPT ); Mon, 20 Nov 2017 04:07:51 -0500 Received: by mail-wm0-f41.google.com with SMTP id y82so5511875wmg.1; Mon, 20 Nov 2017 01:07:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:cc:content-transfer-encoding; bh=9u1+5BQ7M6PsI4XYTN2PrbPLzJQBsGdo5QWPZ1J2zlY=; b=pQbrtF2qStDOpa8eAlV2IIszWHzF8G1dr2UpWpoDYKg08BDDfDbtFdlfn81cbh8rFo LpDYbGQtozSnNJkGC2rELCr6YXHEw3+e1AxBWfKk/ylaRbz+8+0PF/jGS3s/GkcM32ye uya7ZQ4p9FnhaA0+W+I4rornblbk+VuXSZRn8369Ostg1LP3i2CSjJEnSglEgcw2NSON 15JpItaIPH7bjl8xwOOJuk7URinkYnn0WbfwPNzh8i6c4w/Yt+jf18Rt7CZWvkloyjF3 CdOWMuDilVOZwAp7SiOXALuWChkrVuiyursI5eRR/hI6AjRxjBoPtK8aAq1KJobXHtYk jg6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:in-reply-to:references :from:date:message-id:subject:to:cc:content-transfer-encoding; bh=9u1+5BQ7M6PsI4XYTN2PrbPLzJQBsGdo5QWPZ1J2zlY=; b=XA/jGZOdzFTkGUf6qggwwjVotcP3JkKWBp8/vgiScIKPn7fUyP2Nl0ZqlaNxMZfsvH 4QDT+rRCRSEyw3mG4f+RUD2msa7tfdQkapDa/AKDvuWbVZZD2ZrmRW2wmCUoiAoRViYK xP6zeJHF1b6n30VlmtgMNULcvCta7Vlleqkg0qOgl2Ql8x+latSd6C+mLdomRcGmC5Fp awW3xQtrH3AFkWTFBb5pse9+RYzc9PFLMhJg+zQyn/03ENT0n3B6vsIroaHbeFCC3cSM 3Ac+oMb9ZMnwcRirzv9GVwEVpfXSpw0MoKgCpxYS+wBVkRXoXG6FBukARNenZxPXnJwi fzlQ== X-Gm-Message-State: AJaThX6YKg6cFsykdWbap6EGmyjGXQ4VPqOHjxbTyYjf/PvfhKV0v+Y3 JUudeG1+eXlCZgA1qwVQyb0MnJVrpGJ3n5UJJ4g= X-Received: by 10.80.208.10 with SMTP id j10mr18531879edf.194.1511168869729; Mon, 20 Nov 2017 01:07:49 -0800 (PST) MIME-Version: 1.0 Received: by 10.80.245.52 with HTTP; Mon, 20 Nov 2017 01:07:29 -0800 (PST) Reply-To: mtk.manpages@gmail.com In-Reply-To: References: <20171113075537.GG5546@ram.oc3035372033.ibm.com> From: "Michael Kerrisk (man-pages)" Date: Mon, 20 Nov 2017 10:07:29 +0100 Message-ID: Subject: Re: Improving documentation of parent-ID field in /proc/PID/mountinfo To: Miklos Szeredi Cc: Ram Pai , lkml , linux-man , Alexander Eder , "linux-fsdevel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Miklos, Sorry for the slow follow-up. On 14 November 2017 at 17:16, Miklos Szeredi wrote: > On Tue, Nov 14, 2017 at 8:08 AM, Michael Kerrisk (man-pages) > wrote: >> Hi Miklos, Ram >> >> Thanks for your comments. A question below. >> >> On 13 November 2017 at 09:11, Miklos Szeredi wrote= : >>> On Mon, Nov 13, 2017 at 8:55 AM, Ram Pai wrote: >>>> On Mon, Nov 13, 2017 at 07:02:21AM +0100, Michael Kerrisk (man-pages) = wrote: >>>>> Hello Ram, >>>>> >>>>> Long ago (2.6.29) you added the /proc/PID/mountinfo file and >>>>> associated documentation in Documentation/filesystems/proc.txt. Later= , >>>>> I pasted much of that documentation into the proc(5) manual page. >>>>> >>>>> That documentation says of the second field in the file: >>>>> >>>>> [[ >>>>> This file contains lines of the form: >>>>> >>>>> 36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors= =3Dcontinue >>>>> (1)(2)(3) (4) (5) (6) (7) (8) (9) (10) (11) >>>>> >>>>> (1) mount ID: unique identifier of the mount (may be reused after um= ount) >>>>> (2) parent ID: ID of parent (or of self for the top of the mount tre= e) >>>>> ... >>>>> ]] >>>>> >>>>> The last piece of the description of field (2) doesn't seem to be >>>>> correct, or is at least rather unclear. I take this to be saying that >>>>> that for the root mount point, /, field (2) will have the same value >>>>> as field (1). I never actually looked at this detail closely, but >>>>> Alexander pointed out that this is obviously not so, as one can >>>>> immediately verify: >>>>> >>>>> $ grep '/ / ' /proc/$$/mountinfo >>>>> 65 0 8:2 / / rw,relatime shared:1 - ext4 /dev/sda2 rw,seclabel,data= =3Dorder >>>>> >>>>> I dug around in the kernel source for a bit. I do not have an exact >>>>> handle on the details, but I can see roughly what is going on. >>>>> Internally, there seems to be one ("hidden") mount ID reserved to eac= h >>>>> mount namespace, and that ID is the parent of the root mount point. >>>>> >>>>> Looking through the (4.14) kernel source, mount IDs are allocated by >>>>> mnt_alloc_id() (in fs/namespace.c), which is in turn called by >>>>> alloc_vfsmnt() which is in turn called by clone_mnt(). >>>>> >>>>> A new mount namespace is created by the kernel function copy_mnt_ns() >>>>> (in fs/namespace.c, called by create_new_namespaces() in >>>>> kernel/nsproxy.c). The copy_mnt_ns() function calls copy_tree() (in >>>>> fs/namespace.c), and copy_tree() calls clone_mnt() in *two* places. >>>>> The first of these is the call that creates the "hidden" mount ID tha= t >>>>> becomes the parent of the root mount point. (I verified this by >>>>> instrumenting the kernel with a few printk() calls to display the >>>>> IDs.) The second place where copy_tree() calls clone_mnt() is in a >>>>> loop that replicates each of the mount points (including the root >>>>> mount point) in the source mount namespace. >>>> >>>> We used to report that mount, ones upon a time. Something has changed >>>> the behavior since then and its not reported any more, thus making it >>>> hidden. >>> >>> The hidden one is the initramfs, I believe. That's the root of the >>> mount namespace, and the when a namespace is cloned, the tree is >>> copied from the namespace root. >>> >>> It is "hidden" because no process has its root there. Note the >>> difference between namespace root and process root: the first is the >>> real root of the mount tree and is unchangeable, the second is >>> pointing to some place in a mount tree and can be changed (chroot). >>> >>> So there's nothing special in this rootfs, it is just hidden because >>> it's not the root of any task. >>> >>> The description of field (2) is correct, it just does not make it >>> clear what it means by "root". >> >> Sorry -- do you mean the old description is correct, or my new >> description (below)? > > Well, both are correct, yours just describes the same thing at the > higher level. But I think rootfs is an implementation detail, so is > the fact that it gets a zero mount ID, so I think the original > description better captures the essence of the interface. Except it > needs to clarify what "top of the mount tree" means. It doesn't mean > current process's root, rather it means the root of the mount tree in > the current mount namespace. Thanks for the further info. But, the problem is that the existing description is at best misleading: (2) parent ID: the ID of the parent mount (or of self for the top of the mount tree). That implies that we'll find one line in the list where field 1 and field 2 are the same. But we don't, because the mountns rootfs entry is not shown in mountinfo. On top of that, the reader is left confused, because when they look at mountinfo, they see one entry where the parent-ID doesn't exist in the list. So, something more than the current text is required. After digging around in the kernel source and noticing that chroot() will also cause this scenario, and taking into account your comments, I revised the text to: (2) parent ID: the ID of the parent mount (or of self for the root of this mount namespace's mount tree). If the parent mount point lies outside the process's root directory (see chroot(2)), the ID shown here won't have a corresponding record in mountinfo whose mount ID (field 1) matches this parent mount ID (because mount points that lie outside the process's root directory are not shown in mountinfo). As a spe=E2= =80=90 cial case of this point, the process's root mount point may have a parent mount (for the initramfs filesystem) that lies outside the process's root directory, and an entry for that mount point will not appear in mountinfo. How does that seem? Cheers, Michael --=20 Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/ From 1584058850409768366@xxx Tue Nov 14 16:17:21 +0000 2017 X-GM-THRID: 1583929638158288060 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread