Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp100601pxb; Tue, 17 Aug 2021 20:25:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNlDOpBn9f3m+XiJfCbhZmVi+/3u1lnHawQHpsV+HsjdUxLRp3ibQyf6y2aGk0AwIIyBld X-Received: by 2002:a17:906:270f:: with SMTP id z15mr7552523ejc.348.1629257129113; Tue, 17 Aug 2021 20:25:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629257129; cv=none; d=google.com; s=arc-20160816; b=PpQ0ujBr7fRCX6JSudPOgU1P+BS3EcPKAswbBMUW9dFTQW2FqydeFmnlXRnMS6aMlT NwKnhhgtlU8DksapFFaxmp/yAso+KW5nAqZ/XJgLgA7UfLki3C+NgNviKjkvMs6bMbcl oQ4FD3cKj146eFU1+sB4H8wzHEivv50FCHGCECq3h+T8SJiBwXPoJyJO/+YNUGoZPYff MCjUaoJhoIEuXd1Z+RGI8n5wr0KJ8JG1MQ4HAsf9fiiaPPLb0+WVMzfmLiRgf+t6ptKh NA68QWDnuGJ9FEKDF/B1M+XcATRtZgGO8fzaSN6kwaR6kJSqpS+3erni22C4NTEQpVfZ FKEw== 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=lxgMShP02OzqCyU4HZns8XCd8Gu3vaU5BWxjPBu+pfw=; b=imlCLzGdGu59r2RILXDWoExEGw5ohG6eSeXKljrCZWU6tyOvBC0tfefhd10giWJqUh huIpeyCwkGZKtscfMOtMD3cBWfgl1+aDJyTmV6jyv3uhMh4kdLmEv1zc93uCWZwQroBL BLigkayLgOyGdu23G+8zcTBHgU5emjSqEGPH2C0nYakrQ3ggr9TzjRKtthU8C2xpTB8I mU06oXn1F71rX6VKNqTy+Ly/HXiTa9iOFDUXBTIL1fncRGqKABHTcO2mrZecvS0P/cRi pGLW/VeiYX7TVboSygxpfIePiKFJpL8aWEd0LrOLzmEVBE7EjZxySbWSJSc/E5J+2VfW D4Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=u3LYM3iJ; 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 hk18si4401969ejb.238.2021.08.17.20.24.58; Tue, 17 Aug 2021 20:25:29 -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=u3LYM3iJ; 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 S234435AbhHRDZO (ORCPT + 99 others); Tue, 17 Aug 2021 23:25:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230433AbhHRDZL (ORCPT ); Tue, 17 Aug 2021 23:25:11 -0400 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DE69C061764; Tue, 17 Aug 2021 20:24:38 -0700 (PDT) Received: by mail-io1-xd31.google.com with SMTP id a21so884472ioq.6; Tue, 17 Aug 2021 20:24:38 -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=lxgMShP02OzqCyU4HZns8XCd8Gu3vaU5BWxjPBu+pfw=; b=u3LYM3iJ/eYoRW9wyogu1URuW3TOynqVuereHTK/XKefc+T4xpqktPy6C2xUiZkYCs UUuU+uF2vnD0bGG7/CCa+W3jddLc7xeeHMlrDNS1oFCBMd7gyQyyi2Quu26Vi1SBDlN0 WSqz3F3tLusStN6TP99VAM3YUQ9qtHrWRcNOTcngExTMOmSmwaM9erbdfKrQAMxISshq ijhe7a8eWGaHu8Yy4iL9m5UvUAvcE43B4FsKM7o9eZttd9RLv7iKTQxoS3B0elctGNfU vC1BhxJloyEGer+5mMG9jQYHY9kcsse7OvD+h1yLmlEfU46kSr8h+iOsHHLrPfErnAgU YQ1w== 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=lxgMShP02OzqCyU4HZns8XCd8Gu3vaU5BWxjPBu+pfw=; b=LM3FrjaMiiztbUujm+ydRLpTBvSXpTppAULS6yjBRxd4jIRPbHEBngPvW0W+wzgPRb NY586c1FhtgQcVPo3YqN3mJ9FpIPZ4zHFRxj6PtArVYzQozO+UUInqnGcZsw1fUCKvLK unI0CffWNk0WcB0JCyhX1Y+QAFte2NGHEwmPKcK7k/aA8Mfq+REE8Re86jyFGQih+PYj j93EsZtccyZ8swAOheuX7zuom5fWDL77p8rBxTyRwcF3uh2y0y+9AI3QmN4LkYGDgAF+ +8H0TrBxl3GE+N9G97MpaoIhxc1HO5WhPTmngMUdGVwOTS0Bjvm5xNm+MLS8PnJ9aA7p GTcQ== X-Gm-Message-State: AOAM533FrlVME6J5hdmaYow8xR7hGlsHRhI9ZEzYjnNPAv8td6QjyP8h ZjY6NPqfKWbIQGDGH49dPOfKV8aQ8P9HA0GDc2Q= X-Received: by 2002:a05:6602:200f:: with SMTP id y15mr5349155iod.64.1629257077539; Tue, 17 Aug 2021 20:24:37 -0700 (PDT) MIME-Version: 1.0 References: <20210812214010.3197279-1-krisman@collabora.com> <20210812214010.3197279-19-krisman@collabora.com> <20210816214103.GA12664@magnolia> <20210817090538.GA26181@quack2.suse.cz> <20210818001632.GD12664@magnolia> In-Reply-To: <20210818001632.GD12664@magnolia> From: Amir Goldstein Date: Wed, 18 Aug 2021 06:24:26 +0300 Message-ID: Subject: Re: [PATCH v6 18/21] fanotify: Emit generic error info type for error event To: "Darrick J. Wong" Cc: Jan Kara , Gabriel Krisman Bertazi , Jan Kara , Linux API , Ext4 , linux-fsdevel , Khazhismel Kumykov , David Howells , Dave Chinner , Theodore Tso , Matthew Bobrowski , kernel@collabora.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org [...] > > Just keep in mind that the current scheme pre-allocates the single event slot > > on fanotify_mark() time and (I think) we agreed to pre-allocate > > sizeof(fsnotify_error_event) + MAX_HDNALE_SZ. > > If filesystems would want to store some variable length fs specific info, > > a future implementation will have to take that into account. > > I /think/ for the fs and AG metadata we could preallocate these, > so long as fsnotify doesn't free them out from under us. fs won't get notified when the event is freed, so fsnotify must take ownership on the data structure. I was thinking more along the lines of limiting maximum size for fs specific info and pre-allocating that size for the event. > For inodes... > there are many more of those, so they'd have to be allocated > dynamically. The current scheme is that the size of the queue for error events is one and the single slot is pre-allocated. The reason for pre-allocate is that the assumption is that fsnotify_error() could be called from contexts where memory allocation would be inconvenient. Therefore, we can store the encoded file handle of the first erroneous inode, but we do not store any more events until user read this one event. > Hmm. For handling accumulated errors, can we still access the > fanotify_event_info_* object once we've handed it to fanotify? If the > user hasn't picked up the event yet, it might be acceptable to set more > bits in the type mask and bump the error count. In other words, every > time userspace actually reads the event, it'll get the latest error > state. I /think/ that's where the design of this patchset is going, > right? Sort of. fsnotify does have a concept of "merging" new event with an event already in queue. With most fsnotify events, merge only happens if the info related to the new event (e.g. sb,inode) is the same as that off the queued event and the "merge" is only in the event mask (e.g. FS_OPEN|FS_CLOSE). However, the current scheme for "merge" of an FS_ERROR event is only bumping err_count, even if the new reported error or inode do not match the error/inode in the queued event. If we define error event subtypes (e.g. FS_ERROR_WRITEBACK, FS_ERROR_METADATA), then the error event could contain a field for subtype mask and user could read the subtype mask along with the accumulated error count, but this cannot be done by providing the filesystem access to modify an internal fsnotify event, so those have to be generic UAPI defined subtypes. If you think that would be useful, then we may want to consider reserving the subtype mask field in fanotify_event_info_error in advance. > > > > > 2) If a program written for today's notification events sees a > > > > fanotify_event_info_header from future-XFS with a header length that is > > > > larger than FANOTIFY_INFO_ERROR_LEN, will it be able to react > > > > appropriately? Which is to say, ignore it on the grounds that the > > > > length is unexpectedly large? > > > > > > That is the expected behavior :). But I guess separate info type for > > > fs-specific blob might be more foolproof in this sense - when parsing > > > events, you are expected to just skip info_types you don't understand > > > (based on 'len' and 'type' in the common header) and generally different > > > events have different sets of infos attached to them so you mostly have to > > > implement this logic to be able to process events. > > > > > > > It /looks/ like this is the case; really I'm just fishing around here > > > > to make sure nothing in the design of /this/ patchset would make it Very > > > > Difficult(tm) to add more information later. > > > > > > > > 3) Once we let filesystem implementations create their own extended > > > > error notifications, should we have a "u32 magic" to aid in decoding? > > > > Or even add it to fanotify_event_info_error now? > > > > > > If we go via the 'separate info type' route, then the magic can go into > > > that structure and there's no great use for 'magic' in > > > fanotify_event_info_error. > > > > My 0.02$: > > With current patch set, filesystem reports error using: > > fsnotify_sb_error(sb, inode, error) > > > > The optional @inode argument is encoded to a filesystem opaque > > blob using exportfs_encode_inode_fh(), recorded in the event > > as a blob and reported to userspace as a blob. > > > > If filesystem would like to report a different type of opaque blob > > (e.g. xfs_perag_info), the interface should be extended to: > > fsnotify_sb_error(sb, inode, error, info, info_len) > > and the 'separate info type' route seems like the best and most natural > > way to deal with the case of information that is only emitted from > > a specific filesystem with a specific feature enabled (online fsck). > > This seems reasonable to me. > > > IOW, there is no need for fanotify_event_info_xfs_perag_error > > in fanotify UAPI if you ask me. > > > > Regarding 'magic' in fanotify_event_info_error, I also don't see the > > need for that, because the event already has fsid which can be > > used to identify the filesystem in question. > > > > Keep in mind that the value of handle_type inside struct file_handle > > inside struct fanotify_event_info_fid is not a universal classifier. > > Specifically, the type 0x81 means "XFS_FILEID_INO64_GEN" > > only in the context of XFS and it can mean something else in the > > context of another type of filesystem. > > Can you pass the handle into the kernel to open a fd to file mentioned > in the report? I don't think userspace is supposed to know what's > inside a file handle, and it would be helpful if it didn't matter here > either. :) > User gets a file handle and can do whatever users can do with file handles... that is, open_by_handle_at() (if filesystem and inode are still alive and healthy) and for less privileged users, compare with result of name_to_handle_at() of another object. Obviously, filesystem specialized tools could parse the file handle to extract more information. > > If we add a new info record fanotify_event_info_fs_private > > it could even be an alias to fanotify_event_info_fid with the only > > difference that the handle[0] member is not expected to be > > struct file_handle, but some other fs private struct. > > I ... think I prefer it being a separate info blob. > Yes. That is what I meant. Separate info record INFO_TYPE_ERROR_FS_DATA, whose info record format is quite the same as that of INFO_TYPE_FID, but the blob is a different type of blob. Thanks, Amir.