Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3439019imm; Fri, 25 May 2018 05:51:53 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp5SO60eALU48okarYuAMxrT0li3y96wJ4Chv5+edC/TfJn07TrWhopgufZsDW1sq//utX+ X-Received: by 2002:a63:ae4c:: with SMTP id e12-v6mr1855803pgp.181.1527252713786; Fri, 25 May 2018 05:51:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527252713; cv=none; d=google.com; s=arc-20160816; b=GHRKrTr5gSiemDajSewZIeaUjNSyTWiSrz6rXW5ihZLmdyzaZkNGZNk70AHagdFSdj 0wc+RB7WcAUdN+CyyNeh9C/4HiHoaew/BdSk7Y3kFqxRs1qzpRq/ClrlBWUZ5pRGYj8/ bZxSIV7gLoTG01if/3WjQVSvu+uO2wzaeCP2eO8wa21P1rHSQv8hPgLzyw9rm0v5qkFd jD0U8T++Ou8z+ve0M7tuhbDe78kBN1cwohvG7q7xyyobpcYYf3vDWIK8490dQrEdr13D PC0cq7WrLaQgx1Byvmny0qa+t8zJ82pL1GlS3p+I0PrUBe1txaDrkEpAPKZJQpX/UYOQ TUkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=3+005uVsOxbzZHGBXqqratKsvyuD2VpH24uGWjXT8xg=; b=R9kDS/MNDjMpxY5W4bjE8G/LjQ/QekQJVeETKDLhrBReYGNqkvbVQZhwDf5svlzGhx 7pfimJ8FSNjhnDZHA3mztzu1NpdJx9rSLdBivPoKDJKPYUf9DN30sEK4hFL+FlvNDU+l JkaL+E2/hah7yP3g/7sisS+6gP+PYBIVzPCeMewtGYNeiAE0bdi0X7mpCuf4ib3gzl3I A5G6ts2XCqH/CjwH0aExywcr2GgwD1zlY3ZAbFVt9q0+QaSJJndF8g69EwapvI0/Yn2w gFK4Fg5CU7ayy/0Fgal07PhILRj+6BNri2J8pxDnDXerlEsmy6swMxof+4iU4362BymD o5qw== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y16-v6si22849995pfm.140.2018.05.25.05.51.38; Fri, 25 May 2018 05:51:53 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933238AbeEYMto (ORCPT + 99 others); Fri, 25 May 2018 08:49:44 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:36962 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751949AbeEYMtm (ORCPT ); Fri, 25 May 2018 08:49:42 -0400 Received: by mail-wm0-f65.google.com with SMTP id l1-v6so14346611wmb.2; Fri, 25 May 2018 05:49:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=3+005uVsOxbzZHGBXqqratKsvyuD2VpH24uGWjXT8xg=; b=jbMT//uDaxTSCPo+9cyjHIeZFzJexmqQjAYpv4RMGdZmzMwUj/jByg1EgJpjRZg5qy G/156IAJQtUVJ6qwfc3eIxLvok4X8yUZ36zCKS2421hSX+oeylAVBdssteNErW2pDqVP wKfb1p0OjBor6z214hP89oM44HJV1oMXPBMsKy0yo47XoI3+//gghEQ5tQ4ono9B2dhE kmCQXPgnvoFheoKA4X9Z9PnxHqkaKlOVglK4UDz2yKRtZowF0DeWCz1jxZz5sveaAoit KuARlao41ry2+4EFoVzuB0C6qcIvuSh3tnxP7AySfuhKQTZWqr4V2oV1+pHNKwbV4Vtf cP1g== X-Gm-Message-State: ALKqPwdoFPfAXz7b/VLLtTOFNLo+ZNIMhhbAWoH+Ieaj1JeuYbRwd043 4rX/lTtRb2jTlM8f8zntCCQf/yOIqyg= X-Received: by 2002:a1c:7a0b:: with SMTP id v11-v6mr1811434wmc.58.1527252580831; Fri, 25 May 2018 05:49:40 -0700 (PDT) Received: from localhost.localdomain ([2a02:8070:8895:9700:c80a:973d:8254:7f55]) by smtp.gmail.com with ESMTPSA id u8-v6sm6053292wmc.40.2018.05.25.05.49.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 May 2018 05:49:39 -0700 (PDT) From: Christian Brauner To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: torvalds@linux-foundation.org, tglx@linutronix.de, kstewart@linuxfoundation.org, gregkh@linuxfoundation.org, pombredanne@nexb.com, linux-api@vger.kernel.org, ebiederm@xmission.com, seth.forshee@canonical.com, viro@zeniv.linux.org.uk, Christian Brauner Subject: [PATCH 0/6 v1 resend] statfs: handle mount propagation Date: Fri, 25 May 2018 14:48:19 +0200 Message-Id: <20180525124825.23875-1-christian@brauner.io> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christian Brauner Hey, This is v1 of this patchset. All changes from v0 to v1 are non-functional. Specifically, the commit messages and justification have been extended as requested by Linus and Al. This little series does the following: - unify the definition of constants in statfs.h and fs.h: The definitions for MS_* flags are currently a mixture between hex values and bit-shifts. All higher values are already initialized with bit-shifts for MS_* constants starting with (1<<16). This patch switches the definitions for MS_* constants over to uniformly use bit-shifts and alignes the definitions of ST_* flags too. Initializing them identically let's userspace easily detect when flags indicate the same property but use a different value in doing so. - extend statfs to handle mount propagation: For all cases the only way to do this right now is by parsing /proc//mountinfo. Yes, it is doable but still it is somewhat costly and annoying as e.g. those mount propagation fields are optional. 1. prevent propagation from happening: From a userspace perspective we often run into the case where we simply want to know whether a given mountpoint is MS_SHARED or is MS_SLAVE. If it is we remount it as MS_PRIVATE to prevent any propagation from happening. We don't care about the peer relationship or how the propagation is exactly setup. We only want to prevent any propagation from happening. These mountpoints might be known in advance so parsing /proc//mountinfo should not be needed. 2. differentiate between MS_SLAVE and MS_SHARED mountpoints: Mountpoints that are MS_SLAVE are kept intact and mountpoints that are MS_SHARED are made MS_PRIVATE. These mountpoint might be known in advance so parsing /proc//mountinfo should not be needed. 3. retrieve propagation properties when procfs is not mounted: When the set of interesting mountpoints is known and /proc is not mounted calling statfs() is the only good way to reliably determine the propagation property of a mountpoint. 4. inspecting file descriptors to mountpoints for propagation properties: When file descriptors to mountpoints are passed around between processes it is useful to have fstatvfs() handle mount propagation properties too. To this end the flags: - ST_UNBINDABLE - ST_SHARED - ST_PRIVATE - ST_SLAVE are added. They have the same value as their MS_* counterparts. - Testing: I verified that now userspace can do e.g. int ret; char *s = "/some/path"; struct statvfs sb; ret = statvfs(s, &sb); if (ret < 0) return false; if (sb.f_flag & ST_SHARED) { ret = mount("", s, NULL, MS_SLAVE | MS_REC, NULL); if (ret < 0) return -1; } Thanks! Christian Christian Brauner (6): fs: use << for MS_* flags statfs: use << to align with fs header statfs: add ST_UNBINDABLE statfs: add ST_SHARED statfs: add ST_SLAVE statfs: add ST_PRIVATE fs/statfs.c | 16 +++++++++++++++- include/linux/statfs.h | 30 +++++++++++++++++------------- include/uapi/linux/fs.h | 33 +++++++++++++++++---------------- 3 files changed, 49 insertions(+), 30 deletions(-) -- 2.17.0