Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp16300344rwd; Mon, 26 Jun 2023 08:14:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4vUOAT1p6oZbIPfIK1KTwaRDstuDpEj8JuK9NEKz2JGykSIvImn5+YuG2HbbzMgYmXXwgP X-Received: by 2002:a05:6808:188f:b0:3a0:59e7:bedc with SMTP id bi15-20020a056808188f00b003a059e7bedcmr12427423oib.31.1687792448498; Mon, 26 Jun 2023 08:14:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687792448; cv=none; d=google.com; s=arc-20160816; b=IT9zqR3As13JM2Cn7j8KrGJZpVvDNbQhZ+a93S7K0pwGUMY6OgtOB7OTPvkXpg5IEc d1IS7nU/kDwB7tM33z7aIA7nRYleUt2YgfGNbwAqogjxQghIdEoAXGc/btyqqq5B0BIk v0R0rv2C63iMRZSqqUTwBzAU230fZ16tcYzSH7vSIPH5UeuelYeUTnj8Om4Op5bGxLrB KQ3cx366c46ILuqRhsmlTAi3W3XJVqMZcsRIz6nmZGxAclJnFGJpBBcBP5DtrsP3qS9+ 56T1mzYJPR41XFUzcuO296krpJn/Le0/hZvis0v5vk4jRm7NwZbpnybSfBTKVF05w8gV fwWA== 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=8/fcn1wEBMDdvJkCRUpesNLbZjcfRf1Q6JhGJbtYFGM=; fh=S91C9CNp4RlWCqSr1Jrutrv9rwI1f8+tZcSMmrIf45o=; b=UBUuq7/e7NgCbDi9fBLd74da7Xyg3ropzx+QRsCeI0SHgtmvWPrlAG0pjQDnGCqQ9h bPPlv4UFK/y0fgkQymbtVwh1arneoUModQIwTCnwZn6PSTq3xrX75W2qnSsJwooptX1Z AFqqdb3iZ0AXw1+ewpVMVOXuWG+hkxvnfqe72N/d3afLzGSTUhhp0mfpOXf5RPoK6CsF Go9B882MFCD2ehGXTimFnb/kHKiwAhNoA4VyveYO7ONIH1w+EWbyEiUD1RAi9GXRZqZv LXFX5nGj7HJV0H0pt6BawaG28BH3pnWJiIQfIPU5iOMdEWnKp6hP7RZU7bfJTDaG64Pu WvnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=kNPTIn5F; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=yleeCvhS; 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 22-20020a630216000000b00550fc1b301esi5192036pgc.779.2023.06.26.08.13.55; Mon, 26 Jun 2023 08:14:08 -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=kNPTIn5F; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=yleeCvhS; 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 S230280AbjFZPAO (ORCPT + 99 others); Mon, 26 Jun 2023 11:00:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229573AbjFZPAI (ORCPT ); Mon, 26 Jun 2023 11:00:08 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A398AE3; Mon, 26 Jun 2023 08:00:03 -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 5BDE91F898; Mon, 26 Jun 2023 15:00:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1687791602; 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=8/fcn1wEBMDdvJkCRUpesNLbZjcfRf1Q6JhGJbtYFGM=; b=kNPTIn5F4pQQdYxCdqkjSDtrhtS6wCYfy//PxaiScW5+w9czZ50b47LQdo0HadTtcAd592 f6Yy0WLwZLe/7cl/50nNPAnLJTzfzifHq7ZbHQYETgtSLV+aNrVxwrW0zD9EVjBPgR7Cc0 +bxv0z356jtET4U9Fpokg/c5GQlcwmk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1687791602; 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=8/fcn1wEBMDdvJkCRUpesNLbZjcfRf1Q6JhGJbtYFGM=; b=yleeCvhSwIf7GKb0Ikeh9xTqqSJ4gEotTr9+CRjmYu5s5qgCPIlw3FQBcnKGz2WeXvsGaE VdcDytLIwDorsqCg== 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 4C4F113905; Mon, 26 Jun 2023 15:00:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0nCVEvKnmWSeFwAAMHmgww (envelope-from ); Mon, 26 Jun 2023 15:00:02 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id C87A4A0754; Mon, 26 Jun 2023 17:00:01 +0200 (CEST) Date: Mon, 26 Jun 2023 17:00:01 +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: <20230626150001.rl7m7ngjsus4hzcs@quack3> References: <20230626135159.wzbtjgo6qryfet4e@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=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_PASS, T_SCC_BODY_TEXT_LINE,T_SPF_HELO_TEMPERROR 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 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). b) when you get POLLHUP, just close the fd and open it again. In these cases poll(3) will behave as you need (tested)... Honza > -- >8 -- > #define _GNU_SOURCE > #include > #include > #include > #include > #include > int main() { > char buf[64 * 1024]; > struct pollfd pf = {.fd = 0, .events = POLLIN}; > size_t consec = 0; > for (ssize_t rd;;) { > while (poll(&pf, 1, -1) <= 0) > ; > if (pf.revents & POLLIN) { > while ((rd = read(0, buf, sizeof(buf))) == -1 && errno == EINTR) > ; > fprintf(stderr, "\nrd=%zd: %m\n", rd); > } > if (pf.revents & POLLHUP) { > if (!consec++) > fprintf(stderr, "\n\tPOLLHUPs"); > fprintf(stderr, "\r%zu", consec); > } else > consec = 0; > } > } > -- >8 -- > > And > -- >8 -- > $ ./rdr < fifo > > rd=12: Success > > 1779532 POLLHUPs > rd=5: Success > > 945087 POLLHUPs > rd=12: Success > ^C > -- >8 -- > corresponding to > -- >8 -- > $ cat > fifo > abc > def > ghi > ^D > $ echo zupa > fifo > $ cat > fifo > as > dsaa > asd > ^C > -- >8 -- -- Jan Kara SUSE Labs, CR