From patchwork Thu Dec 21 03:08:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ahelenia_Ziemia=C5=84ska?= X-Patchwork-Id: 181957 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp156377dyi; Wed, 20 Dec 2023 19:10:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IFYC0TI5irPRNd+c5dpiv8vrYLI21l8Cg8RRKyF0BjpBF3BUSmQmC1Z9vLyvIKuxUFPf5G5 X-Received: by 2002:a05:6808:4182:b0:3b9:e5d5:a69e with SMTP id dj2-20020a056808418200b003b9e5d5a69emr22365449oib.119.1703128254083; Wed, 20 Dec 2023 19:10:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703128254; cv=none; d=google.com; s=arc-20160816; b=FEhFrTxpcavG5wDmsM8xPPPVHaWvSnWpD0e5VqpVDjIawGefYtAIinS3ITVq4RKDZ/ DtratLfbOvpf8TL8wXHMDvarF6seosm6ujtvWPcf1i0aT/UdLgHj59jUZ1nwnmpOr8hf ZJlnYWeh5quuADIt4a6PR6ujpivFTEyKiNj8mttYgGZm1pNyH2+QVQyN7S2QfmMvmWAQ D9L/nTr3PF2BNHoph16tk3Bg5pUWTycbnsiCc5PAM5XeAj6oLzBY3D0lqcHdpgVKJI5t YcNbaPIRcyd4TKSRZ9XegztUrbRABLY+cK8oacFlzf3FKSlGffr+Th0M7+X+RV9AIcxo W1kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:from:date:dkim-signature; bh=Fnil9XZXanoy6gw4Gl8IsxDnoRIdfHz9zW5MBbe7txM=; fh=LsYxcfBPSHypNIB9mx6HIShKBua9eb1Phu1SAMWLUSA=; b=nA525wy4H4vTJK85QOSbeddmFp8Nh/6ksnoJg5LUTl/OlCYLPqty6U6gihwXQ8iwqK D/64W+zB6kgSLPdXIDaOB11l2qkSzxLeYr+76QVSGHn30lcEFondXl3J74mCMcvPEVBQ sVSRjx1mHyMqwciIIiRYI3hlJQ4q1nseTuJeNwBZkP+MQ3RBiHY7UzSdWsjg4ctTIv4q if6173T+fSivIZdZEYxk5dkVjIWNNcqpcOJuz/Spip5lSZFIrf0HqhWpP8yV5GkQdsLY TH9yyCezgT8lAHpKn6LmrGzNVJUd8UVe4Uk6ltITyFaeGNhv4zucTr6NAOrSxJ30RaMv tOMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nabijaczleweli.xyz header.s=202305 header.b=TEAPKzrb; spf=pass (google.com: domain of linux-kernel+bounces-7776-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7776-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nabijaczleweli.xyz Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id fz16-20020a17090b025000b0028ad5344f5csi681778pjb.92.2023.12.20.19.10.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 19:10:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7776-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@nabijaczleweli.xyz header.s=202305 header.b=TEAPKzrb; spf=pass (google.com: domain of linux-kernel+bounces-7776-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7776-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nabijaczleweli.xyz Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C989DB24A32 for ; Thu, 21 Dec 2023 03:10:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B1D194A2C; Thu, 21 Dec 2023 03:09:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nabijaczleweli.xyz header.i=@nabijaczleweli.xyz header.b="TEAPKzrb" X-Original-To: linux-kernel@vger.kernel.org Received: from tarta.nabijaczleweli.xyz (tarta.nabijaczleweli.xyz [139.28.40.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8639BA43; Thu, 21 Dec 2023 03:08:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nabijaczleweli.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nabijaczleweli.xyz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202305; t=1703128137; bh=1D/Y9tw4haAsoW32bBmlqxPIXSiFb95Jx1COnFxB8BE=; h=Date:From:Cc:Subject:References:In-Reply-To:From; b=TEAPKzrbGh/rmIZmTSBDQD0YPex0RlH5LAnlgnm2XRnDcZlcPFqXsdwpczOmz2YPy 7S/iyHyo92fgR1f1Ano8nsQHuBUsJkSrcOFI/60cy+VnSJ/1A/S70vldPUG7hnBXyd K+/+9XpfGeXvEH7ELM1A5AGG+03D/lgwqFGvx10Jt4DaHHNzyGahdxlONGfaFni4uN NXBdHLL+vi6pgfYDHhdd5lvJ84bT0Un+3M8OpIl5kCIhD1wNC2WLeukcmafu9+PwTz Zzp9KqAFJsO9Wp7oF174uuBMGtEp+B4wnwtZonopTLPiKp4552LFR0pdXFAmqtu8Sh +6QpItt1+GA8w== Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id F0FFB13C50; Thu, 21 Dec 2023 04:08:56 +0100 (CET) Date: Thu, 21 Dec 2023 04:08:56 +0100 From: Ahelenia =?utf-8?q?Ziemia=C5=84ska?= Cc: Jens Axboe , Christian Brauner , Alexander Viro , linux-fsdevel@vger.kernel.org, Miklos Szeredi , linux-kernel@vger.kernel.org Subject: [PATCH v2 03/11] fuse: fuse_dev_splice_read: use nonblocking I/O Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20231103-116-3b855e-dirty X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785859412253318247 X-GMAIL-MSGID: 1785859412253318247 Otherwise we risk sleeping with the pipe locked for indeterminate lengths of time ‒ since FUSE is usually installed with the fusermount helper suid, given cat > fusedev.c <<^D #define _GNU_SOURCE #include #define FUSE_USE_VERSION 30 #include static void *fop_init(struct fuse_conn_info *conn, struct fuse_config *cfg) { for (;;) splice(3, 0, 4, 0, 128 * 1024 * 1024, 0); } static const struct fuse_operations fops = { .init = fop_init }; int main(int argc, char **argv) { return fuse_main(argc, argv, &fops, NULL); } ^D cc nullsleep.c $(pkg-config fuse3 --cflags --libs) -o nullsleep mkfifo fifo mkdir dir ./nullsleep dir 4>fifo & read -r _ < fifo & sleep 0.1 echo zupa > fifo nullsleep used to sleep in splice and the shell used to enter an uninterruptible sleep in open("fifo"); now the splice returns -EAGAIN and the whole program completes. Signed-off-by: Ahelenia Ziemiańska --- fs/fuse/dev.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 1a8f82f478cb..4e8caf66c01e 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -1202,7 +1202,8 @@ __releases(fiq->lock) * the 'sent' flag. */ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file, - struct fuse_copy_state *cs, size_t nbytes) + struct fuse_copy_state *cs, size_t nbytes, + bool nonblock) { ssize_t err; struct fuse_conn *fc = fud->fc; @@ -1238,7 +1239,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file, break; spin_unlock(&fiq->lock); - if (file->f_flags & O_NONBLOCK) + if (nonblock) return -EAGAIN; err = wait_event_interruptible_exclusive(fiq->waitq, !fiq->connected || request_pending(fiq)); @@ -1364,7 +1365,8 @@ static ssize_t fuse_dev_read(struct kiocb *iocb, struct iov_iter *to) fuse_copy_init(&cs, 1, to); - return fuse_dev_do_read(fud, file, &cs, iov_iter_count(to)); + return fuse_dev_do_read(fud, file, &cs, iov_iter_count(to), + file->f_flags & O_NONBLOCK); } static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos, @@ -1388,7 +1390,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos, fuse_copy_init(&cs, 1, NULL); cs.pipebufs = bufs; cs.pipe = pipe; - ret = fuse_dev_do_read(fud, in, &cs, len); + ret = fuse_dev_do_read(fud, in, &cs, len, true); if (ret < 0) goto out;