Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp16446882rwd; Mon, 26 Jun 2023 10:04:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ilFw6L1Kx+/VZr4tC7RpXdHCzym0PXjtvsIehVxisaDy537kuan+OHOc9spbwjhFlH9Ys X-Received: by 2002:aa7:c754:0:b0:51d:7d5c:f686 with SMTP id c20-20020aa7c754000000b0051d7d5cf686mr5077204eds.0.1687799051743; Mon, 26 Jun 2023 10:04:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687799051; cv=none; d=google.com; s=arc-20160816; b=E90aRwBVJd6sq/syD9n9X6x6Xv2CFAFY2PBTXBfOy82/TH1ZGFeF7ViJoATtck6NoQ Bswjym3+miiyvCDlL2LOk6aj8fOb4swr9Tz1yxNecp8D/K0k5kzmv2cxGZkDwwJ8SsIu 2lwEXKPiQErU8/NsS9KVAdNypeTugqpwEndOWXdHb06NnzxdtxGLl24MOYM09vKUSYqX 4hpHa3ioO8HRyzA8IPLXSsDgLTlcoy38coQH/uB1SzGP6Hv5qGKbU888ppCZtOsJoMB6 HmeR2cDbqvlnI28UcNxyB6m55RgBJGhcHEMmghxF2qip/DJ7ve+2nBaGIUiO7uIRKrCx 84+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature; bh=ix/uWItcnnwsKrXY7YkKCqWMvLxQFgNVJE2AJR1BvvM=; fh=S91C9CNp4RlWCqSr1Jrutrv9rwI1f8+tZcSMmrIf45o=; b=DRj8N3r2/+GIZts5IqiGt92yNf8u8uJ3CuSwDcg3im5/VsCBOADUcQsw6m2o4p3eZ7 79ThOjZQ6nTkIsGC4uV4IkfowdVbMmFD77eXIV38rqAAbUlqTlfDdp/XPQbaHyo3qsRO tVhFILf24rETYomr57NkEAL7qjq/1LEU1Ek2cYTWZqHzegeTFuOvPrxNjKGi9nPK9olR rtax+sKX02uf/haVXA/1mAX4Cw7VZMA7FPt6/XlRvpqbHBbwRF2SBgDkxZSLHwKJu4DT PE40GcHpLshsATN4CfAH82KB3KIa4tlZt/Ffs0TFhpGRR/qo6oU4YClDgFMeP/m+HUqu O//w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=3AdjnVjh; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u7-20020a05640207c700b0051d893c60cdsi2647713edy.318.2023.06.26.10.03.45; Mon, 26 Jun 2023 10:04:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=3AdjnVjh; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230149AbjFZQw1 (ORCPT + 99 others); Mon, 26 Jun 2023 12:52:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229823AbjFZQw0 (ORCPT ); Mon, 26 Jun 2023 12:52:26 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81BAD1B1; Mon, 26 Jun 2023 09:52:22 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 066651F896; Mon, 26 Jun 2023 16:52:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1687798341; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ix/uWItcnnwsKrXY7YkKCqWMvLxQFgNVJE2AJR1BvvM=; b=3AdjnVjh+55mJOWVxSTPtswQuxxsNYoASuG3LhbZls0wQtg6HMooN6NhLAe4D4D67hPrIK L5aPVXoomk3R8gAJNOkGwlJdJYmhnURezZH3WChSmdgmMoD5ud4l2AnOGx42U1E+jSAzR2 S4Arr/8lkUNgUJqoeLv5PT2PmU9H93g= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1687798341; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ix/uWItcnnwsKrXY7YkKCqWMvLxQFgNVJE2AJR1BvvM=; b=GBDSwTaixfVefWGt/NTLHkhLaMhQ99c3l4DAY2EUmv+fY2mslsTHYAZTIwySkgvNg8p4qc clD0OYP0XiYJx2CQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id EA32013905; Mon, 26 Jun 2023 16:52:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kacnOUTCmWR3TAAAMHmgww (envelope-from ); Mon, 26 Jun 2023 16:52:20 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 74AE3A0754; Mon, 26 Jun 2023 18:52:20 +0200 (CEST) Date: Mon, 26 Jun 2023 18:52:20 +0200 From: Jan Kara To: Ahelenia =?utf-8?Q?Ziemia=C5=84ska?= Cc: Jan Kara , Amir Goldstein , Alexander Viro , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: splice(-> FIFO) never wakes up inotify IN_MODIFY? Message-ID: <20230626165220.elo4xwfqq6sjboh7@quack3> References: <20230626135159.wzbtjgo6qryfet4e@quack3> <20230626150001.rl7m7ngjsus4hzcs@quack3> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 26-06-23 17:15:23, Ahelenia Ziemiańska wrote: > On Mon, Jun 26, 2023 at 05:00:01PM +0200, Jan Kara wrote: > > On Mon 26-06-23 16:25:41, Ahelenia Ziemiańska wrote: > > > On Mon, Jun 26, 2023 at 03:51:59PM +0200, Jan Kara wrote: > > > > On Mon 26-06-23 14:57:55, Ahelenia Ziemiańska wrote: > > > > > On Mon, Jun 26, 2023 at 02:19:42PM +0200, Ahelenia Ziemiańska wrote: > > > > > > > splice(2) differentiates three different cases: > > > > > > > if (ipipe && opipe) { > > > > > > > ... > > > > > > > if (ipipe) { > > > > > > > ... > > > > > > > if (opipe) { > > > > > > > ... > > > > > > > > > > > > > > IN_ACCESS will only be generated for non-pipe input > > > > > > > IN_MODIFY will only be generated for non-pipe output > > > > > > > > > > > > > > Similarly FAN_ACCESS_PERM fanotify permission events > > > > > > > will only be generated for non-pipe input. > > > > > Sorry, I must've misunderstood this as "splicing to a pipe generates > > > > > *ACCESS". Testing reveals this is not the case. So is it really true > > > > > that the only way to poll a pipe is a sleep()/read(O_NONBLOCK) loop? > > > > So why doesn't poll(3) work? AFAIK it should... > > > poll returns instantly with revents=POLLHUP for pipes that were closed > > > by the last writer. > > > > > > Thus, you're either in a hot loop or you have to explicitly detect this > > > and fall back to sleeping, which defeats the point of polling: > > I see. There are two ways around this: > > > > a) open the file descriptor with O_RDWR (so there's always at least one > > writer). > Not allowed in the general case, since you need to be able to tail -f > files you can't write to. Hum, fair point. > > b) when you get POLLHUP, just close the fd and open it again. > Not allowed semantically, since tail -f follows the file, not the name. Well, you can workaround that by using /proc//fd/ magic links for reopening. > > In these cases poll(3) will behave as you need (tested)... > Alas, those are not applicable to the standard use-case. > If only linux exposed a way to see if a file was written to! I agree that having to jump through the hoops with poll for this relatively standard usage is annoying. Looking into the code, the kernel actually has extra code to generate these repeated POLLHUPs because apparently that was how the poll was behaving ages ago. Hum, researching some more about this, epoll(7) actually doesn't have this problem. I've tested using epoll(2) (in edge-triggered case) instead of poll(2) and that doesn't return repeated POLLHUP events. > For reference with other implementations, > this just works and is guaranteed to work under kqueue(2) EVFILT_READ > (admittedly, kqueue(2) is an epoll(7)-style system and not an > inotify(7)-style one, but it solves the issue, > and that's what NetBSD tail -f uses). > > Maybe this is short-sighted but I don't actually really see why inotify > is... expected? To only generate file-was-written events only for some > writes? Well, inotify similarly as fanotify have been created as filesystem monitoring APIs. Not as general "file descriptor monitoring" APIs. So they work well with regular files and directories but for other objects such as sockets or pipes or even for these "looking like files" objects in virtual filesystems like /proc, the results are pretty much undefined. Honza -- Jan Kara SUSE Labs, CR