Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp981378pxj; Fri, 21 May 2021 03:48:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3TYfG2dHcVeitLdgPxjgNtHPlB10fFnmhCHZOPpCP4hv/IwfLuKmx76eulrVFalbeb2HS X-Received: by 2002:aa7:d491:: with SMTP id b17mr10772296edr.376.1621594093070; Fri, 21 May 2021 03:48:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621594093; cv=none; d=google.com; s=arc-20160816; b=XsyQf9hP2k6+ehpHqoVqoxo5hCxMlq1L2m5IKOBak4tluG1Oh9u/Hkk6g9uTF1rLoQ RigwPyj71bLU/WaGjT58MLrXH5ILHFa5F1DHKpfdfMk0EatkNRQLkz8L0FCwIOfPHIuu pbM7bzjgGFgBOKoTnPHWYrdauBxQoKMrDSCjOESXnA4+9rSbqyTLRMBG3dC11n5gRnko 6aIJsXMv/ynkDfYCQgeB2Hvmu0HrISKRFLoJM7yYztA2pjQTOERDzZCw0J0gQPQXMPOJ cxwBx17l2MfV30ATZSHhPAx3pITu6w7WBtcaBj4h9Xd/6ObcyNC5Im2k6pFDa1i8HgvV pMFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=qOSLP82Ez+kx0oIloOtL79Asfs1CDEhRsGH99eTYvPw=; b=WOAK8G/CvzQG0K5wvzzeS+PTJBwmzVG3HyXCZCebQECcEz8prhwTdmMGRUFN3hxxj8 +WQ5lvEWODLKp7h7aix7XnPDdw/+3+1I112xKaGVg8ilJB8DbHZZPADuN8Nx3vTnoIcu OXjjeCI8JkwnpO8x1dxpbdjNP9z1/ZjKJD5GcRvh4hZt03N9YKq/LDmBYVq+QXImTsmh tedwjKtkHvCI3CY+x7ArrTAAolPk62F3nLbOa3FKR4pEOOsajm9nFsoI+dP+Yj9YEIwH kCZSXA0ua1pPjuRJeHpEQwcDYcHgU26az70EYNwq7K5Pv7m4fopyqeo89fNt4qxj58Jg CD+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nm5r1mty; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t16si6294458edi.299.2021.05.21.03.47.46; Fri, 21 May 2021 03:48:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nm5r1mty; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235356AbhEUJH4 (ORCPT + 99 others); Fri, 21 May 2021 05:07:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234628AbhEUJHy (ORCPT ); Fri, 21 May 2021 05:07:54 -0400 Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 347D2C061574; Fri, 21 May 2021 02:06:31 -0700 (PDT) Received: by mail-il1-x12d.google.com with SMTP id c4so272073iln.7; Fri, 21 May 2021 02:06:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=qOSLP82Ez+kx0oIloOtL79Asfs1CDEhRsGH99eTYvPw=; b=nm5r1mtytT5B5L8p0bJPZN8aIqCjc0Gk3jUqLorWnFV2tx2ZnsxuqVaEU/m/Rt/C67 Poe5FkAri0W6HbQimZk2QSPxmAim1WHZPOzNyqeTuWSYh0IM4h4hZ//vSpez7MOlnjS3 VNsY2nQdZZLQvVQjaP3PlpuonMFdNuogODbSnb9umS9vvcD+PgDCbkizjFYfYGtXAXGL w/KyTOCtiEU1X7Py9i4Bnzr45IZZhAiHRJVWU5e1btGtQTfCCPfXj2/tKdVK4cO6cDIL +gMxyiqPdtGjIqaXtB72f0v+wXeoAjb0KLnHQXj4G6wnw1vYjW4ws6iynSmLArTNOEwZ JcIA== 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=qOSLP82Ez+kx0oIloOtL79Asfs1CDEhRsGH99eTYvPw=; b=G5+sAdTh9PXXA1b5PMn3FoSTnoVf/tUgcIoINGkxupNJ18Tkacw/6D/SM4hZmRI4Ba NGPSGwX9bo5NSZzGur22EdwxagviIbJuYng5W2jatifDIFLy9lg+67Xqt/7yqCnMB9cU G5dNlDhg5cbGwEocXjlQVrXrfU8FpLBBY9/QItO46Efwi289PtbgXkHSuovBBMhaIWUI nmnnjDwf0kDsNHqatxhVbYAoUutZQbXOLG53G1R8lQV5C8dzCB/AaYgeyx1fXVdRmSka VXK8yBrESOBG4pf0tSClgVE7Iwxx+IKlHC1dtZylsiI0fjkEnGBE6caSe5ox4Ln6Stjd +wyA== X-Gm-Message-State: AOAM530a1dd87D9SnxODJCs5L/jBhy1X2wP+v07IkBxfhrqcb54AsLuT zk1QnceUG56e3G9lwR3V8/hIs8Suk6JwUbCQNSA= X-Received: by 2002:a92:cc43:: with SMTP id t3mr11753988ilq.250.1621587989830; Fri, 21 May 2021 02:06:29 -0700 (PDT) MIME-Version: 1.0 References: <20210521024134.1032503-1-krisman@collabora.com> <20210521024134.1032503-5-krisman@collabora.com> In-Reply-To: <20210521024134.1032503-5-krisman@collabora.com> From: Amir Goldstein Date: Fri, 21 May 2021 12:06:18 +0300 Message-ID: Subject: Re: [PATCH 04/11] fanotify: Expose fanotify_mark To: Gabriel Krisman Bertazi Cc: kernel@collabora.com, "Darrick J . Wong" , "Theodore Ts'o" , Dave Chinner , Jan Kara , David Howells , Khazhismel Kumykov , linux-fsdevel , Ext4 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Fri, May 21, 2021 at 5:42 AM Gabriel Krisman Bertazi wrote: > > FAN_ERROR will require an error structure to be stored per mark. > Therefore, wrap fsnotify_mark in a fanotify specific structure in > preparation for that. > > Signed-off-by: Gabriel Krisman Bertazi > --- > fs/notify/fanotify/fanotify.c | 4 +++- > fs/notify/fanotify/fanotify.h | 10 ++++++++++ > fs/notify/fanotify/fanotify_user.c | 14 +++++++------- > 3 files changed, 20 insertions(+), 8 deletions(-) > > diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c > index 711b36a9483e..34e2ee759b39 100644 > --- a/fs/notify/fanotify/fanotify.c > +++ b/fs/notify/fanotify/fanotify.c > @@ -869,7 +869,9 @@ static void fanotify_freeing_mark(struct fsnotify_mark *mark, > > static void fanotify_free_mark(struct fsnotify_mark *fsn_mark) > { > - kmem_cache_free(fanotify_mark_cache, fsn_mark); > + struct fanotify_mark *mark = FANOTIFY_MARK(fsn_mark); > + > + kmem_cache_free(fanotify_mark_cache, mark); > } > > const struct fsnotify_ops fanotify_fsnotify_ops = { > diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h > index 4a5e555dc3d2..a399c5e2615d 100644 > --- a/fs/notify/fanotify/fanotify.h > +++ b/fs/notify/fanotify/fanotify.h > @@ -129,6 +129,16 @@ static inline void fanotify_info_copy_name(struct fanotify_info *info, > name->name); > } > > +struct fanotify_mark { > + struct fsnotify_mark fsn_mark; > + struct fanotify_error_event *error_event; I don't think fanotify_error_event is defined at this point in the series. You can add this field later in the series. > +}; > + > +static inline struct fanotify_mark *FANOTIFY_MARK(struct fsnotify_mark *mark) > +{ > + return container_of(mark, struct fanotify_mark, fsn_mark); > +} > + > /* > * Common structure for fanotify events. Concrete structs are allocated in > * fanotify_handle_event() and freed when the information is retrieved by > diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c > index 9cc6c8808ed5..00210535a78e 100644 > --- a/fs/notify/fanotify/fanotify_user.c > +++ b/fs/notify/fanotify/fanotify_user.c > @@ -914,7 +914,7 @@ static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group, > __kernel_fsid_t *fsid) > { > struct ucounts *ucounts = group->fanotify_data.ucounts; > - struct fsnotify_mark *mark; > + struct fanotify_mark *mark; > int ret; > > /* > @@ -926,20 +926,20 @@ static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group, > !inc_ucount(ucounts->ns, ucounts->uid, UCOUNT_FANOTIFY_MARKS)) > return ERR_PTR(-ENOSPC); > > - mark = kmem_cache_alloc(fanotify_mark_cache, GFP_KERNEL); > + mark = kmem_cache_zalloc(fanotify_mark_cache, GFP_KERNEL); > if (!mark) { > ret = -ENOMEM; > goto out_dec_ucounts; > } > > - fsnotify_init_mark(mark, group); > - ret = fsnotify_add_mark_locked(mark, connp, type, 0, fsid); > + fsnotify_init_mark(&mark->fsn_mark, group); > + ret = fsnotify_add_mark_locked(&mark->fsn_mark, connp, type, 0, fsid); > if (ret) { > - fsnotify_put_mark(mark); > + fsnotify_put_mark(&mark->fsn_mark); > goto out_dec_ucounts; > } > > - return mark; > + return &mark->fsn_mark; > > out_dec_ucounts: > if (!FAN_GROUP_FLAG(group, FAN_UNLIMITED_MARKS)) > @@ -1477,7 +1477,7 @@ static int __init fanotify_user_setup(void) > BUILD_BUG_ON(HWEIGHT32(FANOTIFY_INIT_FLAGS) != 10); > BUILD_BUG_ON(HWEIGHT32(FANOTIFY_MARK_FLAGS) != 9); > > - fanotify_mark_cache = KMEM_CACHE(fsnotify_mark, > + fanotify_mark_cache = KMEM_CACHE(fanotify_mark, > SLAB_PANIC|SLAB_ACCOUNT); Thinking out loud: Do we want to increase the size of all fanotify marks or just the size of sb marks? In this WIP branch [1], I took the latter approach. The greater question is, do we want/need to allow setting FAN_ERROR on inode marks mask at all? My feeling is that we should not allow that at this time, because the use case of watching for critical errors on a specific inode is a non-requirement IMO. OTOH, if we treat this change as a stepping stone towards adding writeback error events in the future then we should also think about whether watching specific files for writeback error in a sensible use case I don't think that it is, because when application can always keep an open fd for file of interest and fysnc on any reported writeback error on the filesystem, as those events are supposed to be rare. Another point to consider - in future revisions of [1] fanotify sb marks may grow more fields (e.g. subtree_root, userns), so while adding a single pointer field to all fanotify inode marks may not be the end of the world, going forward, we will need to have a separate kmem_cache for sb marks anyway, so maybe better to split it now already. Thoughts? Amir. [1] https://github.com/amir73il/linux/commits/fanotify_idmapped