Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1125741pxu; Sat, 12 Dec 2020 02:59:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJylhZHkY10QmWHNZjbvm7IpOeVbyQwnmW/MaAAmSc1vpMKDT8DH/V+zaYcwrRgQ9MkmG4b0 X-Received: by 2002:aa7:c0c2:: with SMTP id j2mr13278751edp.343.1607770790267; Sat, 12 Dec 2020 02:59:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607770790; cv=none; d=google.com; s=arc-20160816; b=EDnIOzBXsijfJiXsdh3D6F4N/pxxQ+T470Aiw/oeV2G7RTuoHx9yX0eAiMV25AK0XN M3jgx987d6jc3Q/UhKAE36GgPwwvWs/RdhRinYOZIg/lB1vfgtGFKmaFDDj6BKsSW5vC K4kanjSCK1gsiSJEqBYfXwXyBwbXc2+08nAMNnqg+fuS2z7v5wxPZns7TFRd1Jojzru9 S+b7s4ivYxuvXIGvdGcDLF3C7pwftnzObbgzc6Lm7rpSQK/aGjemm6f1OqHlK5BhSUak 2T5ByFWX29hhUu7zvP8tlNF6qNBQw+POM4vLafhUbtyP9C5lsWqiAWA01WEPPeluoTTy SMdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=I7ncP/pCQUTbqZGc0Wu66l8cCH4fmSrCDbFlKXOUvio=; b=y8lfhm/sRZs1oy6Gy3RkCUF6uW/WYRMyh358I+dsueTdRmRMvc6SxWa4Y0AFrDDWn5 ATTcKUZUBPN1iyE7mV+1+ouwuRNYFcl3Xo6CUJO60QT5ZhxDyLHi+RK/4idhfjCKT0BH O5OUqcRqxjzjUjLq5tYNqTGGGOO/VRdj859B6tnTMud7zefVRxcRZ+DV9vhKip3jIRw4 bVfAdjrjrvaunb9Wo/OQ0ecHiQrH/NTEqvnMltQxZ/ZVGRwadDTVnlK/UInjBhRTHmgq LBj9iiGp01+235rqKaEBssWnYlnXawjfy4GvXIYsFuMuM7NsTkW43+H8uVT+Lqzw6DxN QpGA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a23si6918639edu.542.2020.12.12.02.59.27; Sat, 12 Dec 2020 02:59:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728679AbgLKKsW (ORCPT + 99 others); Fri, 11 Dec 2020 05:48:22 -0500 Received: from mx2.suse.de ([195.135.220.15]:53442 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393198AbgLKKr4 (ORCPT ); Fri, 11 Dec 2020 05:47:56 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 41EAFAC10; Fri, 11 Dec 2020 10:47:14 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 8B6C21E1352; Fri, 11 Dec 2020 11:47:13 +0100 (CET) Date: Fri, 11 Dec 2020 11:47:13 +0100 From: Jan Kara To: Amir Goldstein Cc: Hugh Dickins , Jan Kara , linux-fsdevel , linux-kernel Subject: Re: linux-next fsnotify mod breaks tail -f Message-ID: <20201211104713.GA15413@quack2.suse.cz> References: 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-kernel@vger.kernel.org On Fri 11-12-20 10:42:16, Amir Goldstein wrote: > On Fri, Dec 11, 2020 at 1:45 AM Hugh Dickins wrote: > > > > Hi Jan, Amir, > > > > There's something wrong with linux-next commit ca7fbf0d29ab > > ("fsnotify: fix events reported to watching parent and child"). > > > > If I revert that commit, no problem; > > but here's a one-line script "tailed": > > > > for i in 1 2 3 4 5; do date; sleep 1; done & > > > > Then if I run that (same result doing ./tailed after chmod a+x): > > > > sh tailed >log; tail -f log > > > > the "tail -f log" behaves in one of three ways: > > > > 1) On a console, before graphical screen, no problem, > > it shows the five lines coming from "date" as you would expect. > > 2) From xterm or another tty, shows just the first line from date, > > but after I wait and Ctrl-C out, "cat log" shows all five lines. > > 3) From xterm or another tty, doesn't even show that first line. > > > > The before/after graphical screen thing seems particularly weird: > > I expect you'll end up with a simpler explanation for what's > > causing that difference. > > > > tailed and log are on ext4, if that's relevant; > > ah, I just tried on tmpfs, and saw no problem there. > > Nice riddle Hugh :) > Thanks for this early testing! > > I was able to reproduce this. > The outcome does not depend on the type of terminal or filesystem > it depends on the existence of a watch on the parent dir of the log file. > Running ' inotifywait -m . &' will stop tail from getting notifications: > > echo > log > tail -f log & > sleep 1 > echo "can you see this?" >> log > inotifywait -m . & > sleep 1 > echo "how about this?" >> log > kill $(jobs -p) > > I suppose with a graphical screen you have systemd or other services > in the system watching the logs/home dir in your test env. > > Attached fix patch. I suppose Jan will want to sqhash it. > > We missed a subtle logic change in the switch from inode/child marks > to parent/inode marks terminology. > > Before the change (!inode_mark && child_mark) meant that name > was not NULL and should be discarded (which the old code did). > After the change (!parent_mark && inode_mark) is not enough to > determine if name should be discarded (it should be discarded only > for "events on child"), so another check is needed. Thanks for testing Hugh and for a quick fix Amir! I've folded it into the original buggy commit. Honza > > Thanks, > Amir. > From c7ea57c66c8c9f9607928bf7c55fc409eecc3e57 Mon Sep 17 00:00:00 2001 > From: Amir Goldstein > Date: Fri, 11 Dec 2020 10:19:36 +0200 > Subject: [PATCH] fsnotify: fix for fix events reported to watching parent and > child > > The child watch is expecting an event without file name and without > the ON_CHILD flag. > > Reported-by: Hugh Dickins > Signed-off-by: Amir Goldstein > --- > fs/notify/fsnotify.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c > index a0da9e766992..30d422b8c0fc 100644 > --- a/fs/notify/fsnotify.c > +++ b/fs/notify/fsnotify.c > @@ -291,13 +291,18 @@ static int fsnotify_handle_event(struct fsnotify_group *group, __u32 mask, > } > if (!inode_mark) > return 0; > + } > > + if (mask & FS_EVENT_ON_CHILD) { > /* > * Some events can be sent on both parent dir and child marks > * (e.g. FS_ATTRIB). If both parent dir and child are > * watching, report the event once to parent dir with name (if > * interested) and once to child without name (if interested). > + * The child watcher is expecting an event without a file name > + * and without the FS_EVENT_ON_CHILD flag. > */ > + mask &= ~FS_EVENT_ON_CHILD; > dir = NULL; > name = NULL; > } > -- > 2.25.1 > -- Jan Kara SUSE Labs, CR