Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4189278pxy; Mon, 26 Apr 2021 21:43:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9XeFCbc9vg7ZbRdPmbEYuADSHnkFtd7C3n2MRiBEsAgvXL2WspTQeUZhPFupp4RWJbE+L X-Received: by 2002:a17:906:ae8f:: with SMTP id md15mr5189103ejb.244.1619498586127; Mon, 26 Apr 2021 21:43:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619498586; cv=none; d=google.com; s=arc-20160816; b=VFLtebPEgHf61FT3zB3Cj9CnN6zY0Ht5JtPUQbD201r7yi5xsU0IvnHuNiWN8hT57o 3jREbyC116Gd59XSxDZlcrd7Qb+zzhAAj8ufjvOyfAa+v8cCmGqQUOOboZmJ4iXRmOKD JXCbq/Nq8W5bS6HvNboRRW0UVsvXK2N/96dPRcEC97xgP9KsgxUK11M2jmrot+9MsrRy N3CJ8X1IFCah3XzNHZ86T22I6WRb1lLmt5qk7zBZ5hy+MBDeSlOZcQ0CvCmUCUodkupS dN1Tngv8ZKg1D4kFZRoeHHkUljga4qh4EzZlCM/750C0OVdfV4CblvPZJ7tZJAjhiwBY +xKQ== 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=EzSe38NJjrCvosP/G6D4PJaz045LslJADhZl0Vyj2/E=; b=fLykXWzyhu6Dc5LCQh3qpcawjUoL3kzGVL32jlXXJvT/1IrL2Q20NEtbvpILonsBt+ MF0lYS0Vbs82KRnVygvhcVyXWNKudQsZNtMEzT2MdXt64x20uJcz/hUxnhCvTZ0GCJCS FfO0TbTw31vJvgfI5J9A/jemTLWeYa1km/V5T9RQsvq+2jkR0eS716/kaUNLecDK1Xil ihULIA1JSaJEwXshyOLBfMJGLLSYwCZD9c/oblq/JE7c5mNViN5isE+yC9cV10qBaYYv bJFhblkeUHEAWQJtpnxsRTQpQ0DAOjrXrzksDVpNiKkkZLN0Mr7tRrJU4r12aIM7RoZF vB1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qWk7oZvN; 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 jg11si14685664ejc.175.2021.04.26.21.42.40; Mon, 26 Apr 2021 21:43:06 -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=qWk7oZvN; 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 S234015AbhD0EnV (ORCPT + 99 others); Tue, 27 Apr 2021 00:43:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233421AbhD0EnU (ORCPT ); Tue, 27 Apr 2021 00:43:20 -0400 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A745C061574; Mon, 26 Apr 2021 21:42:38 -0700 (PDT) Received: by mail-io1-xd2d.google.com with SMTP id t21so7546505iob.2; Mon, 26 Apr 2021 21:42: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=EzSe38NJjrCvosP/G6D4PJaz045LslJADhZl0Vyj2/E=; b=qWk7oZvNsF5EgbGk6j9nzCrBtUiofXrtCMUQ3l09zo+Mf6GRFAcjwaKCowYR/+ZsO1 veKJBI0kwyFCeSUd7I4WYKnNfK+C9cGYnDHk4OL5lo3leGvq1S7RONH7APV/ipC6wf4m cZALgfdXTgdESYUrYU4mhcvHf46sDlGiQjPUOIKlxK6fllS32sGgPneK1968aAH8yE2M Phv1W+hBx5pE/Bh9389gbc7QDN1S17gj2of9EWIje7nPiew9StwbvkQsUGacveX2qhVE 62Jf0vXdBXIFiqFITB2FZSZyXvxUgxvmYyNdWnxrcx6CjdHk4y8R7WdvWOKZb8qOzcAZ hPkw== 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=EzSe38NJjrCvosP/G6D4PJaz045LslJADhZl0Vyj2/E=; b=LwoN9zJ9tEXOua5QqGwg6FDXq/hnrOTnRYoI6a2aIVVKC3nrnaCt6wEwHBbX0j1oZO M/Yx+vjdsvpPBkhtstf6ZjKLV9jzLMhxWG8mjjQt7r4UW1fJgdpe5fi3okbfMaJWIZfd UH91D2w+O8IrqoWGe70ODwYHswvBmpqo9NjgYhIi6z6JlhTaiN8abt8lQx1D/hecfR+M PzVyJkzjWUVOsm5duFQCfB72Gx2P8hAmNYKjm2bH0vNLu2lU8nyActdmsiZ0VXK9veHD qbnZIwRWRNx6KNjiWFQxOpQfHUwRpJhteYU2vA9OxRCl7Fh9Ca6LuPIt3sasPzKPMzyS HqCA== X-Gm-Message-State: AOAM533fAjvifxaxwD7Nk2ietFJ6KwDcDTdo+VxhgvokLnRhkC5Onhb+ NomGo41hk+heWsSfCMOtskfXd4sFrpH7RFS80is= X-Received: by 2002:a6b:f115:: with SMTP id e21mr17625161iog.5.1619498558076; Mon, 26 Apr 2021 21:42:38 -0700 (PDT) MIME-Version: 1.0 References: <20210426184201.4177978-1-krisman@collabora.com> <20210426184201.4177978-2-krisman@collabora.com> In-Reply-To: <20210426184201.4177978-2-krisman@collabora.com> From: Amir Goldstein Date: Tue, 27 Apr 2021 07:42:27 +0300 Message-ID: Subject: Re: [PATCH RFC 01/15] fanotify: Fold event size calculation to its own function To: Gabriel Krisman Bertazi Cc: Theodore Tso , "Darrick J. Wong" , Dave Chinner , Jan Kara , David Howells , Khazhismel Kumykov , linux-fsdevel , Ext4 , kernel@collabora.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Mon, Apr 26, 2021 at 9:42 PM Gabriel Krisman Bertazi wrote: > > Every time this function is invoked, it is immediately added to > FAN_EVENT_METADATA_LEN, since there is no need to just calculate the > length of info records. This minor clean up folds the rest of the > calculation into the function, which now operates in terms of events, > returning the size of the entire event, including metadata. > > Signed-off-by: Gabriel Krisman Bertazi Nice Reviewed-by: Amir Goldstein > --- > fs/notify/fanotify/fanotify_user.c | 40 +++++++++++++++++------------- > 1 file changed, 23 insertions(+), 17 deletions(-) > > diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c > index 9e0c1afac8bd..0332c4afeec3 100644 > --- a/fs/notify/fanotify/fanotify_user.c > +++ b/fs/notify/fanotify/fanotify_user.c > @@ -64,17 +64,24 @@ static int fanotify_fid_info_len(int fh_len, int name_len) > return roundup(FANOTIFY_INFO_HDR_LEN + info_len, FANOTIFY_EVENT_ALIGN); > } > > -static int fanotify_event_info_len(unsigned int fid_mode, > - struct fanotify_event *event) > +static size_t fanotify_event_len(struct fanotify_event *event, > + unsigned int fid_mode) > { > - struct fanotify_info *info = fanotify_event_info(event); > - int dir_fh_len = fanotify_event_dir_fh_len(event); > - int fh_len = fanotify_event_object_fh_len(event); > - int info_len = 0; > + size_t event_len = FAN_EVENT_METADATA_LEN; > + struct fanotify_info *info; > + int dir_fh_len; > + int fh_len; > int dot_len = 0; > > + if (!fid_mode) > + return event_len; > + > + info = fanotify_event_info(event); > + dir_fh_len = fanotify_event_dir_fh_len(event); > + fh_len = fanotify_event_object_fh_len(event); > + > if (dir_fh_len) { > - info_len += fanotify_fid_info_len(dir_fh_len, info->name_len); > + event_len += fanotify_fid_info_len(dir_fh_len, info->name_len); > } else if ((fid_mode & FAN_REPORT_NAME) && (event->mask & FAN_ONDIR)) { > /* > * With group flag FAN_REPORT_NAME, if name was not recorded in > @@ -84,9 +91,9 @@ static int fanotify_event_info_len(unsigned int fid_mode, > } > > if (fh_len) > - info_len += fanotify_fid_info_len(fh_len, dot_len); > + event_len += fanotify_fid_info_len(fh_len, dot_len); > > - return info_len; > + return event_len; > } > > /* > @@ -98,7 +105,8 @@ static int fanotify_event_info_len(unsigned int fid_mode, > static struct fanotify_event *get_one_event(struct fsnotify_group *group, > size_t count) > { > - size_t event_size = FAN_EVENT_METADATA_LEN; > + size_t event_size; > + struct fsnotify_event *fse; > struct fanotify_event *event = NULL; > unsigned int fid_mode = FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS); > > @@ -108,16 +116,15 @@ static struct fanotify_event *get_one_event(struct fsnotify_group *group, > if (fsnotify_notify_queue_is_empty(group)) > goto out; > > - if (fid_mode) { > - event_size += fanotify_event_info_len(fid_mode, > - FANOTIFY_E(fsnotify_peek_first_event(group))); > - } > + fse = fsnotify_peek_first_event(group); > + event = FANOTIFY_E(fse); > + event_size = fanotify_event_len(event, fid_mode); > > if (event_size > count) { > event = ERR_PTR(-EINVAL); > goto out; > } > - event = FANOTIFY_E(fsnotify_remove_first_event(group)); > + fsnotify_remove_queued_event(group, fse); > if (fanotify_is_perm_event(event->mask)) > FANOTIFY_PERM(event)->state = FAN_EVENT_REPORTED; > out: > @@ -334,8 +341,7 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group, > > pr_debug("%s: group=%p event=%p\n", __func__, group, event); > > - metadata.event_len = FAN_EVENT_METADATA_LEN + > - fanotify_event_info_len(fid_mode, event); > + metadata.event_len = fanotify_event_len(event, fid_mode); > metadata.metadata_len = FAN_EVENT_METADATA_LEN; > metadata.vers = FANOTIFY_METADATA_VERSION; > metadata.reserved = 0; > -- > 2.31.0 >