Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1502010ybt; Mon, 15 Jun 2020 01:49:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRH0L69yftS+UmFDX0NuT1MvfRD03S8wY7Jq030cJ4lH1KZG+YOfqkb8j6md1dybxF7jM9 X-Received: by 2002:a17:906:c150:: with SMTP id dp16mr24087290ejc.536.1592210953452; Mon, 15 Jun 2020 01:49:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592210953; cv=none; d=google.com; s=arc-20160816; b=esCzpTHs2PsmP0Jo74m6crBiRfKiE1bZmJgTwdHlM2LtrT75mQQmuroAxJogAfjbTA 4yjIRLnmrJBqOk5LZ8JPtpOjBET+wgADk784KCHfFhdsvMxMkGypZJz+M17I47rznATh YMIIvzxVl2ColCkqYT9zXTC7s7bVUBBli/tRaz2TLkmVYdfdZs4dnCmfR0mLq2NNsFhy 5/ij20uBBjV696gawTIWFbjRIYdsN6K/q1a//axwMxY/cJUWrP962I8PsITDYzltI2/i xV8MUAcVA2RExcYO9qToATuTsUCaMWqB01/rOJHKRgHxKpvjmR+cvdWtumnJ8V58YzLr TLWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=OXy80G/QuWlMsF/9ZGjBxujaTTvUrmfWIzv9XF+RHas=; b=dtPdHgtF+Z6WZ3V37SplxNSQ+C8yTwmzUhXf+5EIPQNbaUDlPhIpSJJv/D8vTUJ9RV JVAGOYMCnFDzARbH4JzBFBtA/xr/0+ZCwSARQRUW9pdTl0bNkgn6Sdt7Ds0+xUHf1Pdh rUb9gzIgZ38Ppu4CztqPkLA8P+h1WwaFwnrdcF5/YDjGlUvw0rla3zmQNNtyKJIp0F8j CjxbEi0X1bq6RsqSkMk6vNRKU9HZDF5Gc2FM/S78vw80qQn7bnWOl93GJeR9yJtNpsgo uZAjMpiPIr/wM2/4Pqplu8g6EHLrmc8KGrp9n12bOK43mxi4UG0D6N2RoTzBhVj0IgLM smtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=mb5wlVjn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k18si9154707ejs.502.2020.06.15.01.48.50; Mon, 15 Jun 2020 01:49:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=mb5wlVjn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729127AbgFOIpL (ORCPT + 99 others); Mon, 15 Jun 2020 04:45:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729037AbgFOIpK (ORCPT ); Mon, 15 Jun 2020 04:45:10 -0400 Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C0C4C08C5C3 for ; Mon, 15 Jun 2020 01:45:09 -0700 (PDT) Received: by mail-ed1-x541.google.com with SMTP id e12so10886284eds.2 for ; Mon, 15 Jun 2020 01:45:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OXy80G/QuWlMsF/9ZGjBxujaTTvUrmfWIzv9XF+RHas=; b=mb5wlVjn0ratQKJ42h3GHcIVlDnVaMT+Y0sd3By4do/QOYmPV7Aq+Y2zatzsI7SOrn uhkPX6n2/5cxQmCMLpHxsYCjwN+0ROujisKn33HA1NeF+zxYT/qIyuzyaqX7GXK3x8+e OxQ+ScFLCE+B8bFFPL0VH/0VJEF8kb46qelzU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OXy80G/QuWlMsF/9ZGjBxujaTTvUrmfWIzv9XF+RHas=; b=fTr8JAK8AO1twuOqQBdebnFgoOLDQZR5cyOCUpxjwHyoNkPA036FNOGWHrFS8IUI5Y kR0wpIXJMbWju7GI7ZKIdOz/tSzlLkCrkcr0WHpN0YUuPt+6NFD1X/Zw5rwu8lqmhQ7X 6e3/i848KcDWKCLbHMZ8WCwh8eCBuOpswbVbXkF8V268+LWwN/AzqTX+qAUF301dliLT eOopqWmlXFgWyh5mpppmSA1HqsP/Q8G/whethk9hKQKS2fob7osjfsIQ4vAW3h4zxBFu AdOqngp9/R6FsXnUym6a/E0F+QIrylI+5z/qoxLagAxpM6uz9s5fsIj7s4s8pGkmU1Ct MUnA== X-Gm-Message-State: AOAM531H0mdQkL3/Lf9QqBc4QFcX3URfcQRJvy5Ozcapuw8CHlFK5qNn dcCjCed6YRKiI+oOWz1294U7B7axFJ20X4mF+dXOfA== X-Received: by 2002:a50:d785:: with SMTP id w5mr22207839edi.212.1592210708330; Mon, 15 Jun 2020 01:45:08 -0700 (PDT) MIME-Version: 1.0 References: <158454378820.2863966.10496767254293183123.stgit@warthog.procyon.org.uk> <158454391302.2863966.1884682840541676280.stgit@warthog.procyon.org.uk> <0991792b6e2af0a5cc1a2c2257b535b5e6b032e4.camel@themaw.net> In-Reply-To: <0991792b6e2af0a5cc1a2c2257b535b5e6b032e4.camel@themaw.net> From: Miklos Szeredi Date: Mon, 15 Jun 2020 10:44:57 +0200 Message-ID: Subject: Re: [PATCH 13/17] watch_queue: Implement mount topology and attribute change notifications [ver #5] To: Ian Kent Cc: David Howells , Linus Torvalds , Al Viro , Casey Schaufler , Stephen Smalley , Nicolas Dichtel , Christian Brauner , andres@anarazel.de, Jeff Layton , dray@redhat.com, Karel Zak , keyrings@vger.kernel.org, Linux API , linux-fsdevel@vger.kernel.org, LSM , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jun 14, 2020 at 5:07 AM Ian Kent wrote: > > On Thu, 2020-04-02 at 17:19 +0200, Miklos Szeredi wrote: > > > > > Firstly, a watch queue needs to be created: > > > > > > pipe2(fds, O_NOTIFICATION_PIPE); > > > ioctl(fds[1], IOC_WATCH_QUEUE_SET_SIZE, 256); > > > > > > then a notification can be set up to report notifications via that > > > queue: > > > > > > struct watch_notification_filter filter = { > > > .nr_filters = 1, > > > .filters = { > > > [0] = { > > > .type = WATCH_TYPE_MOUNT_NOTIFY, > > > .subtype_filter[0] = UINT_MAX, > > > }, > > > }, > > > }; > > > ioctl(fds[1], IOC_WATCH_QUEUE_SET_FILTER, &filter); > > > watch_mount(AT_FDCWD, "/", 0, fds[1], 0x02); > > > > > > In this case, it would let me monitor the mount topology subtree > > > rooted at > > > "/" for events. Mount notifications propagate up the tree towards > > > the > > > root, so a watch will catch all of the events happening in the > > > subtree > > > rooted at the watch. > > > > Does it make sense to watch a single mount? A set of mounts? A > > subtree with an exclusion list (subtrees, types, ???)? > > Yes, filtering, perhaps, I'm not sure a single mount is useful > as changes generally need to be monitored for a set of mounts. > > Monitoring a subtree is obviously possible because the monitor > path doesn't need to be "/". > > Or am I misunderstanding what your trying to get at. > > The notion of filtering types and other things is interesting > but what I've seen that doesn't fit in the current implementation > so far probably isn't appropriate for kernel implementation. > > There's a special case of acquiring a list of mounts where the > path is not a mount point itself but you need all mount below > that path prefix. > > In this case you get all mounts, including the mounts of the mount > containing the path, so you still need to traverse the list to match > the prefix and that can easily mean the whole list of mounts in the > system. > > Point is it leads to multiple traversals of a larger than needed list > of mounts, one to get the list of mounts to check, and one to filter > on the prefix. > > I've seen this use case with fsinfo() and that's where it's needed > although it may be useful to carry it through to notifications as > well. > > While this sounds like it isn't such a big deal it can sometimes > make a considerable difference to the number of mounts you need > to traverse when there are a large number of mounts in the system. > > I didn't consider it appropriate for kernel implementation but > since you asked here it is. OTOH were checking for connectedness > in fsinfo() anyway so maybe this is something that could be done > without undue overhead. Good point. Filtering notifications for mounts outside of the specified path makes sense. Thanks, Miklos