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 X-Spam-Level: X-Spam-Status: No, score=-12.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8EDE9C4320A for ; Fri, 13 Aug 2021 12:10:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 718306109E for ; Fri, 13 Aug 2021 12:10:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240203AbhHMMK1 (ORCPT ); Fri, 13 Aug 2021 08:10:27 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:52662 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239981AbhHMMKZ (ORCPT ); Fri, 13 Aug 2021 08:10:25 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id C01FB2232F; Fri, 13 Aug 2021 12:09:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1628856597; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZDrASliUDxQKAR4lqmIWyOYaRQOJ3szPxAVZ9aYxObM=; b=wnxard6CyPLNJOUa12qVcYR3ZxXLFFRV50NSoCVIL8M1na6T8UEsg8zHI0xFrNoJGUTFEV qTUE77u548MiwB0pGGpbgVMxQAodVgMk+6F9MXqugNdZw89OCsCnx5dEQU0JMOjKMF8TeB HeILTO3ukcLuaSLA/X9+/Wu8oTAMpNs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1628856597; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZDrASliUDxQKAR4lqmIWyOYaRQOJ3szPxAVZ9aYxObM=; b=9eh9YddJ4JzR+mPw8Myo306KnLpGaU5X+Gnhgl1RkfrCmXmPWg3hFmJwom7PF5b3jNorBV rounD5JBNxfsZmAg== Received: from quack2.suse.cz (unknown [10.100.224.230]) by relay2.suse.de (Postfix) with ESMTP id A1F43A3B84; Fri, 13 Aug 2021 12:09:57 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 7EC891E423D; Fri, 13 Aug 2021 14:09:54 +0200 (CEST) Date: Fri, 13 Aug 2021 14:09:54 +0200 From: Jan Kara To: Amir Goldstein Cc: Jan Kara , Gabriel Krisman Bertazi , Jan Kara , "Darrick J. Wong" , Theodore Tso , Dave Chinner , David Howells , Khazhismel Kumykov , linux-fsdevel , Ext4 , Linux API , kernel@collabora.com Subject: Re: [PATCH v5 14/23] fanotify: Encode invalid file handler when no inode is provided Message-ID: <20210813120954.GA11955@quack2.suse.cz> References: <20210804160612.3575505-1-krisman@collabora.com> <20210804160612.3575505-15-krisman@collabora.com> <20210805095618.GF14483@quack2.suse.cz> <87fsvf65zu.fsf@collabora.com> <20210812142047.GG14675@quack2.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Thu 12-08-21 18:17:10, Amir Goldstein wrote: > On Thu, Aug 12, 2021 at 5:20 PM Jan Kara wrote: > > > > On Wed 11-08-21 17:12:05, Gabriel Krisman Bertazi wrote: > > > Jan Kara writes: > > > >> @@ -376,14 +371,24 @@ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, > > > >> fh->flags |= FANOTIFY_FH_FLAG_EXT_BUF; > > > >> } > > > >> > > > >> - dwords = fh_len >> 2; > > > >> - type = exportfs_encode_inode_fh(inode, buf, &dwords, NULL); > > > >> - err = -EINVAL; > > > >> - if (!type || type == FILEID_INVALID || fh_len != dwords << 2) > > > >> - goto out_err; > > > >> - > > > >> - fh->type = type; > > > >> - fh->len = fh_len; > > > >> + if (inode) { > > > >> + dwords = fh_len >> 2; > > > >> + type = exportfs_encode_inode_fh(inode, buf, &dwords, NULL); > > > >> + err = -EINVAL; > > > >> + if (!type || type == FILEID_INVALID || fh_len != dwords << 2) > > > >> + goto out_err; > > > >> + fh->type = type; > > > >> + fh->len = fh_len; > > > >> + } else { > > > >> + /* > > > >> + * Invalid FHs are used on FAN_FS_ERROR for errors not > > > >> + * linked to any inode. Caller needs to guarantee the fh > > > >> + * has at least FANOTIFY_NULL_FH_LEN bytes of space. > > > >> + */ > > > >> + fh->type = FILEID_INVALID; > > > >> + fh->len = FANOTIFY_NULL_FH_LEN; > > > >> + memset(buf, 0, FANOTIFY_NULL_FH_LEN); > > > >> + } > > > > > > > > Maybe it will become clearer later during the series but why do you set > > > > fh->len to FANOTIFY_NULL_FH_LEN and not 0? > > > > > > Jan, > > > > > > That is how we encode a NULL file handle (i.e. superblock error). Amir > > > suggested it would be an invalid FILEID_INVALID, with a zeroed handle of > > > size 8. I will improve the comment on the next iteration. > > > > Thanks for info. Then I have a question for Amir I guess :) Amir, what's > > the advantage of zeroed handle of size 8 instead of just 0 length file > > handle? > > With current code, zero fh->len means we are not reporting an FID info > record (e.g. due to encode error), see copy_info_records_to_user(). > > This is because fh->len plays a dual role for indicating the length of the > file handle and the existence of FID info. I see, thanks for info. > I figured that keeping a positive length for the special NULL_FH is an > easy way to workaround this ambiguity and keep the code simpler. > We don't really need to pay any cost for keeping the 8 bytes zero buffer. There are two separate questions: 1) How do we internally propagate the information that we don't have file_handle to report but we do want fsid reported. 2) What do we report to userspace in file_handle. For 2) I think we should report fsid + FILEID_INVALID, 0-length filehandle. Currently the non-zero lenght FILEID_INVALID filehandle was propagating to userspace and IMO that's confusing. For 1), whatever is the simplest to propagate the information "we want only fsid reported" internally is fine by me. Honza -- Jan Kara SUSE Labs, CR