Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5175340ybi; Tue, 28 May 2019 08:44:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzY8DViVjCSZfV+fD37DgUO+B2iSB/kAKOQZwknhMnPXN/gCv6zecJBKezlvdVx+S932LpV X-Received: by 2002:a65:6551:: with SMTP id a17mr37738200pgw.1.1559058287037; Tue, 28 May 2019 08:44:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559058287; cv=none; d=google.com; s=arc-20160816; b=UoFQgXNfp6uzuFSRBRkwgKvtUlOf9T7ECdJQti2WYvAprEWHNafOivZwftsKrcmSRl eO/DomQOuEffP4HmrZLtst73tkWOPIc7kEFf5bDjuET94xadFcNVM12F7Fs/Va2UD8aj UG31sADI5LhzNkgXY1G0/3TId84+MzYkxvpF2vuG020eTXQxGb+gqPfW4vL1LaCETz4k Auhq5n/gAuTDJUIzNSoxtWjkb4pvFs/0ZlEla8gzGODaeiqxw36g3QfK4/OOKL/sgt75 wd47lRsAQoU1munkTpfSdom+rj6qEYOmBXKInIwHThu6GdzeLnuRf45Y+6B7iCJ8XMlE JmFQ== 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:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization; bh=fMEPa1DPFVy3IGENBlJKp32Oc7rbM/LzwF3w4r+Da2c=; b=LO3gMf2aOPABD/UgL9eSs3BCz1p7hQq+TtX5t0yN/HnUs6gnvhNzmdsNOmwCWHYOMF 8hRDc6/xzK4Z/2WkKxm/aNEh3sxF0euDCzy/MPzLaIPTwT5Ownliy3hbePLqqxJdYLz2 XwUOw/x+sOrpMy1rpgiQp66LfVzxWJLr9gy9s+DhM3LwizGJ7b5+FWkhHITaDW2F2K1x aYNVbHogH0JnpmXjKeKVioVyi/sQq6YYJbpaqh7kZkM7hKT2INWRWWGoPods2jWgYQIN vVakbI+Fl5yJWzjyO2wfl6OVZMTyuUQov0JGojdA/x5s2AgLbepcUJtyyVRnaF77cOxb dX4Q== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w4si21770006plp.223.2019.05.28.08.44.31; Tue, 28 May 2019 08:44:47 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727688AbfE1PML (ORCPT + 99 others); Tue, 28 May 2019 11:12:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35616 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727013AbfE1PML (ORCPT ); Tue, 28 May 2019 11:12:11 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8D1AADC8FB; Tue, 28 May 2019 15:12:10 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-125-65.rdu2.redhat.com [10.10.125.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 102258C085; Tue, 28 May 2019 15:12:08 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 08/25] vfs: Add mount notification count [ver #13] From: David Howells To: viro@zeniv.linux.org.uk Cc: dhowells@redhat.com, raven@themaw.net, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, mszeredi@redhat.com Date: Tue, 28 May 2019 16:12:08 +0100 Message-ID: <155905632829.1662.713450430534562121.stgit@warthog.procyon.org.uk> In-Reply-To: <155905626142.1662.18430571708534506785.stgit@warthog.procyon.org.uk> References: <155905626142.1662.18430571708534506785.stgit@warthog.procyon.org.uk> User-Agent: StGit/unknown-version MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 28 May 2019 15:12:10 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a notification count on mount objects so that the user can easily check to see if a mount has changed its attributes or its children. Future patches will: (1) Provide this value through fsinfo() attributes. (2) Hook into the notify_mount() function to provide a notification interface for userspace to monitor. Signed-off-by: David Howells --- fs/mount.h | 22 ++++++++++++++++++++++ fs/namespace.c | 13 +++++++++++++ 2 files changed, 35 insertions(+) diff --git a/fs/mount.h b/fs/mount.h index 6250de544760..47795802f78e 100644 --- a/fs/mount.h +++ b/fs/mount.h @@ -70,6 +70,7 @@ struct mount { struct hlist_head mnt_pins; struct fs_pin mnt_umount; struct dentry *mnt_ex_mountpoint; + atomic_t mnt_notify_counter; /* Number of notifications generated */ } __randomize_layout; #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */ @@ -151,3 +152,24 @@ static inline bool is_anon_ns(struct mnt_namespace *ns) { return ns->seq == 0; } + +/* + * Type of mount topology change notification. + */ +enum mount_notification_subtype { + NOTIFY_MOUNT_NEW_MOUNT = 0, /* New mount added */ + NOTIFY_MOUNT_UNMOUNT = 1, /* Mount removed manually */ + NOTIFY_MOUNT_EXPIRY = 2, /* Automount expired */ + NOTIFY_MOUNT_READONLY = 3, /* Mount R/O state changed */ + NOTIFY_MOUNT_SETATTR = 4, /* Mount attributes changed */ + NOTIFY_MOUNT_MOVE_FROM = 5, /* Mount moved from here */ + NOTIFY_MOUNT_MOVE_TO = 6, /* Mount moved to here (compare op_id) */ +}; + +static inline void notify_mount(struct mount *changed, + struct mount *aux, + enum mount_notification_subtype subtype, + u32 info_flags) +{ + atomic_inc(&changed->mnt_notify_counter); +} diff --git a/fs/namespace.c b/fs/namespace.c index a49a7d9ed482..1450faab96b9 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -513,6 +513,8 @@ static int mnt_make_readonly(struct mount *mnt) smp_wmb(); mnt->mnt.mnt_flags &= ~MNT_WRITE_HOLD; unlock_mount_hash(); + if (ret == 0) + notify_mount(mnt, NULL, NOTIFY_MOUNT_READONLY, 0x10000); return ret; } @@ -521,6 +523,7 @@ static int __mnt_unmake_readonly(struct mount *mnt) lock_mount_hash(); mnt->mnt.mnt_flags &= ~MNT_READONLY; unlock_mount_hash(); + notify_mount(mnt, NULL, NOTIFY_MOUNT_READONLY, 0); return 0; } @@ -833,6 +836,7 @@ static void umount_mnt(struct mount *mnt) { /* old mountpoint will be dropped when we can do that */ mnt->mnt_ex_mountpoint = mnt->mnt_mountpoint; + notify_mount(mnt->mnt_parent, mnt, NOTIFY_MOUNT_UNMOUNT, 0); unhash_mnt(mnt); } @@ -1472,6 +1476,7 @@ static void umount_tree(struct mount *mnt, enum umount_tree_flags how) p = list_first_entry(&tmp_list, struct mount, mnt_list); list_del_init(&p->mnt_expire); list_del_init(&p->mnt_list); + ns = p->mnt_ns; if (ns) { ns->mounts--; @@ -2095,7 +2100,10 @@ static int attach_recursive_mnt(struct mount *source_mnt, lock_mount_hash(); } if (parent_path) { + notify_mount(source_mnt->mnt_parent, source_mnt, + NOTIFY_MOUNT_MOVE_FROM, 0); detach_mnt(source_mnt, parent_path); + notify_mount(dest_mnt, source_mnt, NOTIFY_MOUNT_MOVE_TO, 0); attach_mnt(source_mnt, dest_mnt, dest_mp); touch_mnt_namespace(source_mnt->mnt_ns); } else { @@ -2104,6 +2112,9 @@ static int attach_recursive_mnt(struct mount *source_mnt, list_del_init(&source_mnt->mnt_ns->list); } mnt_set_mountpoint(dest_mnt, dest_mp, source_mnt); + notify_mount(dest_mnt, source_mnt, NOTIFY_MOUNT_NEW_MOUNT, + source_mnt->mnt.mnt_sb->s_flags & SB_SUBMOUNT ? + 0x10000 : 0); commit_tree(source_mnt); } @@ -2480,6 +2491,7 @@ static void set_mount_attributes(struct mount *mnt, unsigned int mnt_flags) mnt->mnt.mnt_flags = mnt_flags; touch_mnt_namespace(mnt->mnt_ns); unlock_mount_hash(); + notify_mount(mnt, NULL, NOTIFY_MOUNT_SETATTR, 0); } /* @@ -2880,6 +2892,7 @@ void mark_mounts_for_expiry(struct list_head *mounts) if (!xchg(&mnt->mnt_expiry_mark, 1) || propagate_mount_busy(mnt, 1)) continue; + notify_mount(mnt, NULL, NOTIFY_MOUNT_EXPIRY, 0); list_move(&mnt->mnt_expire, &graveyard); } while (!list_empty(&graveyard)) {