Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2160931ybv; Fri, 21 Feb 2020 10:02:53 -0800 (PST) X-Google-Smtp-Source: APXvYqxpf0Meyvlf4izMz1N0bKl56qr1C1wzK+QqK4hlXbu+xDkO89crJ8ah87GR/SzFuiEtzRS1 X-Received: by 2002:a05:6830:1317:: with SMTP id p23mr29400282otq.3.1582308173288; Fri, 21 Feb 2020 10:02:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582308173; cv=none; d=google.com; s=arc-20160816; b=r3CUF1nPjT7CTj865sHcgfOIxSZ1qQar+sTrDdhbl125PWNm3X9GZuLWeTvTZrq8Ka hc8jNRIIuLQVTUx43fR7wQt/y2GGyD2iEHx1uxeC6IdXxvZkL5+RAdL2E40WTl2vQnnx RW4I5q2dtJvwNICgl3RDi6Z9StPYr7LceCkViuxfFrXarnVCeua5A93V05RAGmJFYr2O ZsYtUc2/QMOLtws/61k8KzaLkklvIz8pPno4obtLSRMUFFWQUXrlH4ld5lJsbx0dmp5s b4vpiA4kM9inXgiDw8S24HA3wUbO9mwR/j8DgfwPgcQ5T4l0v7/SBnxnQB7Pt8U9bdhs PghQ== 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:dkim-signature; bh=Yz1PYlAw+vwqrPPhOUgTLgnA2ip0cR1UD//JiPCA6VE=; b=wME5CatZmhA3cR8G1fMoItTtSwjz3ShLlzuVB9aek/xNqUF3jqN6GF12gLfgRyvkWv ry24sLIWjiprei2NqkvIGEP0Ym9FuNBZPE8IvafpfRDREeLYPYcuJJnISO9R1czMkxtD WMytBdc71D1saq3bD889PG1PI/8Q5ekLn/rGY893n5tvCHbbPuhurQEg77KceOBVfg70 7uVkM6LMYGOHl9eI30pg2wD/LaLOTLp1S0fAFmtkESqUv/lo8Sm/rh6Fw5FmiKtiDGoM n7jri9a/eJKvy6lTUfs1dS/NdyV2LsI2HHEQplVQ2Rz7CmwFKV8OPgORCwsZB08gGlcH b6hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="S1/H98cM"; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t137si1161595oif.61.2020.02.21.10.02.40; Fri, 21 Feb 2020 10:02:53 -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=@redhat.com header.s=mimecast20190719 header.b="S1/H98cM"; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729360AbgBUSCU (ORCPT + 99 others); Fri, 21 Feb 2020 13:02:20 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:23193 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726066AbgBUSCT (ORCPT ); Fri, 21 Feb 2020 13:02:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582308138; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Yz1PYlAw+vwqrPPhOUgTLgnA2ip0cR1UD//JiPCA6VE=; b=S1/H98cMGk36GAIUK9FMjHLnaMgZIQL8EDrhCkBagN8fta5u7t+G4SrRaAzTomow2zmby+ l7DORsPVnGEjclwEvSufI0EZ1hYsNCjArgcp66qFtXwnew02IWimilzN5ktL7sqYNjwT+Z QFJgBfr7JTtMPrQK2Zl7zOngsFEBhyQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-309-w8iGWSGZMkaykbBOmOtEeQ-1; Fri, 21 Feb 2020 13:02:14 -0500 X-MC-Unique: w8iGWSGZMkaykbBOmOtEeQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0581B8017DF; Fri, 21 Feb 2020 18:02:13 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-122-163.rdu2.redhat.com [10.10.122.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id 432F392960; Fri, 21 Feb 2020 18:02:11 +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 03/17] watch_queue: sample: Display mount tree change notifications [ver #17] From: David Howells To: viro@zeniv.linux.org.uk Cc: dhowells@redhat.com, raven@themaw.net, mszeredi@redhat.com, christian@brauner.io, jannh@google.com, darrick.wong@oracle.com, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 21 Feb 2020 18:02:10 +0000 Message-ID: <158230813054.2185128.14599796644062916018.stgit@warthog.procyon.org.uk> In-Reply-To: <158230810644.2185128.16726948836367716086.stgit@warthog.procyon.org.uk> References: <158230810644.2185128.16726948836367716086.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.21 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.15 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is run like: ./watch_test and watches "/" for changes to the mount topology and the attributes of individual mount objects. # mount -t tmpfs none /mnt # mount -o remount,ro /mnt # mount -o remount,rw /mnt producing: # ./watch_test read() = 16 NOTIFY[000]: ty=000002 sy=00 i=02000010 MOUNT 00000060 change=0[new_mount] aux=416 read() = 16 NOTIFY[000]: ty=000002 sy=04 i=02010010 MOUNT 000001a0 change=4[setattr] aux=0 read() = 16 NOTIFY[000]: ty=000002 sy=04 i=02010010 MOUNT 000001a0 change=4[setattr] aux=0 Signed-off-by: David Howells --- samples/watch_queue/watch_test.c | 39 +++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/samples/watch_queue/watch_test.c b/samples/watch_queue/watch_test.c index 0eaff5dc04c3..49d185150506 100644 --- a/samples/watch_queue/watch_test.c +++ b/samples/watch_queue/watch_test.c @@ -26,6 +26,9 @@ #ifndef __NR_watch_devices #define __NR_watch_devices -1 #endif +#ifndef __NR_watch_mount +#define __NR_watch_mount -1 +#endif #define BUF_SIZE 256 @@ -58,6 +61,27 @@ static void saw_key_change(struct watch_notification *n, size_t len) k->key_id, n->subtype, key_subtypes[n->subtype], k->aux); } +static const char *mount_subtypes[256] = { + [NOTIFY_MOUNT_NEW_MOUNT] = "new_mount", + [NOTIFY_MOUNT_UNMOUNT] = "unmount", + [NOTIFY_MOUNT_EXPIRY] = "expiry", + [NOTIFY_MOUNT_READONLY] = "readonly", + [NOTIFY_MOUNT_SETATTR] = "setattr", + [NOTIFY_MOUNT_MOVE_FROM] = "move_from", + [NOTIFY_MOUNT_MOVE_TO] = "move_to", +}; + +static void saw_mount_change(struct watch_notification *n, size_t len) +{ + struct mount_notification *m = (struct mount_notification *)n; + + if (len != sizeof(struct mount_notification)) + return; + + printf("MOUNT %08x change=%u[%s] aux=%u\n", + m->triggered_on, n->subtype, mount_subtypes[n->subtype], m->changed_mount); +} + /* * Consume and display events. */ @@ -134,6 +158,9 @@ static void consumer(int fd) default: printf("other type\n"); break; + case WATCH_TYPE_MOUNT_NOTIFY: + saw_mount_change(&n.n, len); + break; } p += len; @@ -142,12 +169,17 @@ static void consumer(int fd) } static struct watch_notification_filter filter = { - .nr_filters = 1, + .nr_filters = 2, .filters = { [0] = { .type = WATCH_TYPE_KEY_NOTIFY, .subtype_filter[0] = UINT_MAX, }, + [1] = { + .type = WATCH_TYPE_MOUNT_NOTIFY, + // Reject move-from notifications + .subtype_filter[0] = UINT_MAX & ~(1 << NOTIFY_MOUNT_MOVE_FROM), + }, }, }; @@ -181,6 +213,11 @@ int main(int argc, char **argv) exit(1); } + if (syscall(__NR_watch_mount, AT_FDCWD, "/", 0, fd, 0x02) == -1) { + perror("watch_mount"); + exit(1); + } + consumer(fd); exit(0); }