From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE4D5E64000 for ; Thu, 21 Nov 2024 18:37:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 830386B0085; Thu, 21 Nov 2024 13:37:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7DF416B0088; Thu, 21 Nov 2024 13:37:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A7076B0089; Thu, 21 Nov 2024 13:37:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4C9676B0085 for ; Thu, 21 Nov 2024 13:37:59 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E95C4C0C83 for ; Thu, 21 Nov 2024 18:37:58 +0000 (UTC) X-FDA: 82810958748.01.253F806 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) by imf14.hostedemail.com (Postfix) with ESMTP id 12DB510001C for ; Thu, 21 Nov 2024 18:36:57 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=T1sbGpnX; spf=pass (imf14.hostedemail.com: domain of amir73il@gmail.com designates 209.85.218.54 as permitted sender) smtp.mailfrom=amir73il@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732214215; h=from:from:sender: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:dkim-signature; bh=o7o6YG1r7Hvwm2rqRHDEPpPeTuZqrDtGk2bZdDwk4Qk=; b=IAFh0dBOGWvxXBER1/HKebDd0f9k04gb62rP86XjhSjCVelGDQ/J92Y6vcIGGOlOTSkE4r N3tg2zVugx7SzqtcReB+iiajC0Ym8hEli9gum0x+FkAghpTT5msh2v0cO/yr8YN1u/YWdE 9jC7dngY6vvVjivxkpyQOaind+6jbrE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732214215; a=rsa-sha256; cv=none; b=wvgtAfSsp3wvNy+zMi1vfUcWWk5IWjNAQdx6hqrPqfCSpViTJRRuRxW1s9vMvmt/4joFE1 O47SkTY6GJjCK7XOU6dR4eJ4rWnhpJYwstakbGhxS2WI2svEEXd3lhbYrqIGXWaBp8UpfJ ACLGIXYK7sri+dM1V5rQSaYIEtNIbSg= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=T1sbGpnX; spf=pass (imf14.hostedemail.com: domain of amir73il@gmail.com designates 209.85.218.54 as permitted sender) smtp.mailfrom=amir73il@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a9ec86a67feso226144666b.1 for ; Thu, 21 Nov 2024 10:37:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732214275; x=1732819075; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=o7o6YG1r7Hvwm2rqRHDEPpPeTuZqrDtGk2bZdDwk4Qk=; b=T1sbGpnXC/1NIAtIJG3lH687j9XTfDNovsfRPndef/RhCFrh9x6CjPlq/pKdOJXKu1 ezMJeVtm/6qIwSFAtAKo1eYd2iDacbgcj0By3P8urWXWKvslzV3WKjFJxphC1n2/RTqA qn/Lt2ApZCL3khzWspxH9ytqpJ33DWuKP7ijmas2AFd1EZ+/etCve9Z9GNkUsFuGv8di F2iC3itFOKgawscqcFK6bRLGxZBwiZZyaBx8ix5GESztA1gCecxCUVqmF2N/oXdRDYO6 dc7hoGQqY21Z5V+jN95HlZuvIfLdpYz0nae3FSHMsUKl+GbjbCYNMQ4XP7gWFyKHPykH P88A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732214275; x=1732819075; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o7o6YG1r7Hvwm2rqRHDEPpPeTuZqrDtGk2bZdDwk4Qk=; b=avKI90LGRAvYKeS2Y2zWH3//tB/8PS7q/S0h0K/yBXLkZQTksDuga7qjTiltkmVSvz bsWh3RnZJxNOBOGio4by9fO9tVPZI/mA6bM7xamaX6wEQ3HcGpQ3NhuCj1gTiFNUq6Ed bYJaURK4poAjpkPkBk9JAiC2KM67rIerFg0ZC5+T7F3LAzlBaLC3oF247dc8sMhUS9SP jh0RjaiCxuvR0BdJ2RYkZh0rqEthX9LVKlPu6IDEY7zTdvwmEcuJ8RNo3wR7h1xB/HW1 e0m5Oq9FP6uvz8M2D9XmjjBk6ToeVHw5O0/9ykQrgDmFGnDICV8G4EJBi/JpYCXiBDNE IheQ== X-Forwarded-Encrypted: i=1; AJvYcCVyRDKWLG9ErSjxBJNoDWV2WK8Sfafmi1cHgdgwnOgBaGcXyp0VgeeuPWlPH8NWgP7FltKRiOJ9Fg==@kvack.org X-Gm-Message-State: AOJu0YxlyIIQEKYESCMvJHw+FfluZysqyO+4vc7CUidouBinCpQ3kS6I ikW2HQ+gzQ5X/goSNLBZ2RwTDMNtjnqhXsI9XygtVsxCn0QdPyoLrP80l1aPfNs74Mv89eEKlV5 Ce1Cj/FP4wbqoJwkDiTGD81OlRZA= X-Gm-Gg: ASbGncvohTvMR9MRdZYP1awh4llHLE5VMLq48waRzFc+nIFvbYGcTb6MRW1HpEeJliS d9e8SeJztNvCz61ANKgqZc4Gnuh+QmZc= X-Google-Smtp-Source: AGHT+IEorAjckwDToOujNx0EuXDqrQ9VD8gBqiBM+3DSRRW1VXzYujlBwDfZLVLYJiWoKbQslITNjSKdF77KCW19lgQ= X-Received: by 2002:a17:907:3f9b:b0:a9a:a891:b43e with SMTP id a640c23a62f3a-aa509d0a2afmr21791666b.50.1732214274751; Thu, 21 Nov 2024 10:37:54 -0800 (PST) MIME-Version: 1.0 References: <20241121104428.wtlrfhadcvipkjia@quack3> <20241121163618.ubz7zplrnh66aajw@quack3> In-Reply-To: From: Amir Goldstein Date: Thu, 21 Nov 2024 19:37:43 +0100 Message-ID: Subject: Re: [PATCH v8 10/19] fanotify: introduce FAN_PRE_ACCESS permission event To: Jan Kara Cc: Josef Bacik , kernel-team@fb.com, linux-fsdevel@vger.kernel.org, brauner@kernel.org, torvalds@linux-foundation.org, viro@zeniv.linux.org.uk, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: cqtie9enay7qzi4takh9krdydhyxeunw X-Rspam-User: X-Rspamd-Queue-Id: 12DB510001C X-Rspamd-Server: rspam02 X-HE-Tag: 1732214217-620739 X-HE-Meta: U2FsdGVkX1/3LTCPTo6TDrCHkhGOwPGxoVbiQx3LQwUgExbW+8AykKOHk4t5v8U04SL768p8Wy/BfsTP1YgIivf8fAA/YYbhkpSit3Ef0I4ejAyQOLHpRxEC3DqFG0k2QzkhQPWt/vlPYJ6a2yuF2kQ+drbjfJmoYt5LySQ8a+GZnR54Nk1SGtiyt9vVbOnwmj4A7lwS+SvsIZNddRZID1Q6bF7zgDRGBgaYPukUrVhv+IGKLBhK0+FtyYTKrl1ntC785yM6K3LY5bCxbEn9LyN1s9r+Li410LM41BJzR/ba4wxJ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1WqqZr37sJ1x07GSk6JMY2+j2HSs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, Nov 21, 2024 at 7:31=E2=80=AFPM Amir Goldstein = wrote: > > On Thu, Nov 21, 2024 at 5:36=E2=80=AFPM Jan Kara wrote: > > > > On Thu 21-11-24 15:18:36, Amir Goldstein wrote: > > > On Thu, Nov 21, 2024 at 11:44=E2=80=AFAM Jan Kara wrot= e: > > > > > > > > On Fri 15-11-24 10:30:23, Josef Bacik wrote: > > > > > From: Amir Goldstein > > > > > > > > > > Similar to FAN_ACCESS_PERM permission event, but it is only allow= ed with > > > > > class FAN_CLASS_PRE_CONTENT and only allowed on regular files and= dirs. > > > > > > > > > > Unlike FAN_ACCESS_PERM, it is safe to write to the file being acc= essed > > > > > in the context of the event handler. > > > > > > > > > > This pre-content event is meant to be used by hierarchical storag= e > > > > > managers that want to fill the content of files on first read acc= ess. > > > > > > > > > > Signed-off-by: Amir Goldstein > > > > > > > > Here I was wondering about one thing: > > > > > > > > > + /* > > > > > + * Filesystems need to opt-into pre-content evnets (a.k.a H= SM) > > > > > + * and they are only supported on regular files and directo= ries. > > > > > + */ > > > > > + if (mask & FANOTIFY_PRE_CONTENT_EVENTS) { > > > > > + if (!(path->mnt->mnt_sb->s_iflags & SB_I_ALLOW_HSM)= ) > > > > > + return -EINVAL; > > > > > + if (!is_dir && !d_is_reg(path->dentry)) > > > > > + return -EINVAL; > > > > > + } > > > > > > > > AFAICS, currently no pre-content events are generated for directori= es. So > > > > perhaps we should refuse directories here as well for now? I'd like= to > > > > > > readdir() does emit PRE_ACCESS (without a range) > > > > Ah, right. > > > > > and also always emitted ACCESS_PERM. > > > > I know that and it's one of those mostly useless events AFAICT. > > > > > my POC is using that PRE_ACCESS to populate > > > directories on-demand, although the functionality is incomplete witho= ut the > > > "populate on lookup" event. > > > > Exactly. Without "populate on lookup" doing "populate on readdir" is ok= for > > a demo but not really usable in practice because you can get spurious > > ENOENT from a lookup. > > > > > > avoid the mistake of original fanotify which had some events availa= ble on > > > > directories but they did nothing and then you have to ponder hard w= hether > > > > you're going to break userspace if you actually start emitting them= ... > > > > > > But in any case, the FAN_ONDIR built-in filter is applicable to PRE_A= CCESS. > > > > Well, I'm not so concerned about filtering out uninteresting events. I'= m > > more concerned about emitting the event now and figuring out later that= we > > need to emit it in different places or with some other info when actual > > production users appear. > > > > But I've realized we must allow pre-content marks to be placed on dirs = so > > that such marks can be placed on parents watching children. What we'd n= eed > > to forbid is a combination of FAN_ONDIR and FAN_PRE_ACCESS, wouldn't we= ? > > Yes, I think that can work well for now. > Only it does not require only check at API time that both flags are not set, because FAN_ONDIR can be set earlier and then FAN_PRE_ACCESS can be added later and vice versa, so need to do this in fanotify_may_update_existing_mark() AFAICT. Thanks, Amir.