From patchwork Thu Sep 21 07:57:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Kellermann X-Patchwork-Id: 143485 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5634953vqi; Fri, 22 Sep 2023 07:47:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEr/FjWk1BpRsVJpVpXKsFRueYb8Gzmy7F5ZRdFCUq4MCOfqi0e8lBBmZ0KgWs3Q70ud+2V X-Received: by 2002:a9d:730f:0:b0:6bd:c7c3:aabc with SMTP id e15-20020a9d730f000000b006bdc7c3aabcmr8365323otk.19.1695394042073; Fri, 22 Sep 2023 07:47:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695394042; cv=none; d=google.com; s=arc-20160816; b=rxhUpQIANwgyaBd3w+SinG7wHc4XDL4z9zKdKdfweFYbbLYZifiRdLb3QjJpQRfBpT zkrcUJLDnPZmVKDAp9kXIXt+hQmnQOj8Wx4gKL3ASIZN2UcuWCvr3CsO6cMrTI5i/et7 NZ00Yf1PrltPNr71BS4xUGM5ipfPzkCJ8W8LuM4fVvPVTU6CuucZnj2/q0KCLwwl/ZmC Z4MfbmOxhVkX0IPGGuJKOO/wOBJbQGIIzUE71bLaVdH6smx22N4APoNLeM332RADX9wC 67+xgptAgn6Hjrje1LIubqEjBGZHjLYTMISuXFTTdXv3JIGe1t4p+yvqLJoDtnOsn6q4 RJXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=exindjDRedXgd3Z4uqnR6aLnmaUK9oSQ00jryr/8dkk=; fh=/mmUFS5s71yRsPeN08HF9rYndG2tJREJfMy47/3Il/c=; b=XY07piteXCGR8jAK0geMpe7qr2PfQrDHfzzKkdM1VImLhG8MpaXCvQQxgvys9UnOHP +41GwWg7DdR4uwLxFdKwI8L2saXAljXYED7/NNtv97Vplp0vCi4sMJwUFFpEKJYIP0O5 +wMOYJUHfDwdxSJbvRxuZA+EFvqs9mUFv7xrCGAVyFxaGjrTCCVhWl4rV8ZFpsKYQEo0 Xo7d05oW9vVXgZnuzQbQ7n8dKVS/XyqmOseihBu9vuqZZ+uWdoyTxF3ROOlLxjCXafZ+ 7vz2Hbm4U3HYHE3YkKlKGpNNdeIzp0VIsVec/jmhPeW46aaS6Ypj3fMXc3XB0AIKImY5 G+3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b="c2fwadW/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id a5-20020a655c85000000b00564bcae8b64si3655032pgt.846.2023.09.22.07.47.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 07:47:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b="c2fwadW/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id BAE9684D572F; Thu, 21 Sep 2023 16:00:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231925AbjIUXAr (ORCPT + 29 others); Thu, 21 Sep 2023 19:00:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231646AbjIUXAg (ORCPT ); Thu, 21 Sep 2023 19:00:36 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 396898A203 for ; Thu, 21 Sep 2023 10:40:29 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2c00b37ad84so22335401fa.0 for ; Thu, 21 Sep 2023 10:40:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1695318027; x=1695922827; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=exindjDRedXgd3Z4uqnR6aLnmaUK9oSQ00jryr/8dkk=; b=c2fwadW/bxkT2mvxY06pYDFleUPJ6t9rsbDH/sy+z7l+nnQC7aJZB4qTFpHtVV0hTh 10KEl5kps2ChhyFkt+IfPA7+jgu8AIVqfMERwclqAwWZUX16ZKoWbAvuHx/ryzQQKlG3 u3fHkaI3RzRHQMuzKa7s+y4BLtwdUeOAcNU1ZNZM7iVROQkp8yAqQKRjKhlEBOzW0kxs aoYhwEGTg1SoTv1SXozK7ioYt0CiKuGi2x9Ebrz/jMHbDZm3siNU5CWxki1XiPKjyb7p 388ZZRx1GTibwL/j6ABRDrQxlTX5dloByrlQoMVY5fGilZoPMoRop+AAl0Aeh/IwgUfk WhYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695318027; x=1695922827; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=exindjDRedXgd3Z4uqnR6aLnmaUK9oSQ00jryr/8dkk=; b=edCefjok8/MEZx3xSJ6MVfzI/Y1nifqxWlXT4lQyVVk5B7TwdzZo8mXrLmt1EGfnyR Gc9caQQK5XSK9eHDjet7uMHn30snsCzht8bObQwcjwlCXupVaAEXlAvYEwGFFEZNAKZa ShvdxJgHxBlQ+EwfzNMmADdrl0GkymhM3EdTN1X3zmMlgknrOCJGPsI9PUKRWIuUDhIv Je09nZl+wd/CAkmqcz1o8WgDL9bc8C9Vm3rIP8Xu67sLWKkevaiUhJVyHY/hwXtNNr6v wd01i+eWJXw+JlJYJQDonXRqHtE7Msj03AupUNixX2kdTEBz3oDRSM6kuEQtkpSNQeWN IwjA== X-Gm-Message-State: AOJu0YyES0pxTHsGx0I6xl50ItVs1p7Mzi4u3Qafb+mW6gNpxakWdvGs aUNM6PiuyUZhuhbCaGxFTDkjU763u+TGmAhS0VQ= X-Received: by 2002:a05:600c:2109:b0:401:bedd:7d42 with SMTP id u9-20020a05600c210900b00401bedd7d42mr4517741wml.13.1695283081746; Thu, 21 Sep 2023 00:58:01 -0700 (PDT) Received: from heron.intern.cm-ag (p200300dc6f209c00529a4cfffe3dd983.dip0.t-ipconnect.de. [2003:dc:6f20:9c00:529a:4cff:fe3d:d983]) by smtp.gmail.com with ESMTPSA id v4-20020a05600c214400b003fef19bb55csm1151252wml.34.2023.09.21.00.58.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 00:58:01 -0700 (PDT) From: Max Kellermann To: viro@zeniv.linux.org.uk, brauner@kernel.org, howells@redhat.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Max Kellermann Subject: [PATCH 2/4] fs/pipe: move check to pipe_has_watch_queue() Date: Thu, 21 Sep 2023 09:57:53 +0200 Message-Id: <20230921075755.1378787-2-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230921075755.1378787-1-max.kellermann@ionos.com> References: <20230921075755.1378787-1-max.kellermann@ionos.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 16:00:50 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777749503139940548 X-GMAIL-MSGID: 1777749503139940548 This declutters the code by reducing the number of #ifdefs and makes the watch_queue checks simpler. This has no runtime effect; the machine code is identical. Signed-off-by: Max Kellermann --- fs/pipe.c | 12 +++--------- include/linux/pipe_fs_i.h | 13 +++++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/fs/pipe.c b/fs/pipe.c index 6c1a9b1db907..6ecaccb48738 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -437,12 +437,10 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from) goto out; } -#ifdef CONFIG_WATCH_QUEUE - if (pipe->watch_queue) { + if (pipe_has_watch_queue(pipe)) { ret = -EXDEV; goto out; } -#endif /* * If it wasn't empty we try to merge new data into @@ -1325,10 +1323,8 @@ static long pipe_set_size(struct pipe_inode_info *pipe, unsigned int arg) unsigned int nr_slots, size; long ret = 0; -#ifdef CONFIG_WATCH_QUEUE - if (pipe->watch_queue) + if (pipe_has_watch_queue(pipe)) return -EBUSY; -#endif size = round_pipe_size(arg); nr_slots = size >> PAGE_SHIFT; @@ -1380,10 +1376,8 @@ struct pipe_inode_info *get_pipe_info(struct file *file, bool for_splice) if (file->f_op != &pipefifo_fops || !pipe) return NULL; -#ifdef CONFIG_WATCH_QUEUE - if (for_splice && pipe->watch_queue) + if (for_splice && pipe_has_watch_queue(pipe)) return NULL; -#endif return pipe; } diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h index 598a411d7da2..699507c52b72 100644 --- a/include/linux/pipe_fs_i.h +++ b/include/linux/pipe_fs_i.h @@ -124,6 +124,19 @@ struct pipe_buf_operations { bool (*get)(struct pipe_inode_info *, struct pipe_buffer *); }; +/** + * pipe_has_watch_queue - Check whether the pipe is a watch_queue, + * i.e. it was created with O_NOTIFICATION_PIPE + */ +static inline bool pipe_has_watch_queue(const struct pipe_inode_info *pipe) +{ +#ifdef CONFIG_WATCH_QUEUE + return pipe->watch_queue != NULL; +#else + return false; +#endif +} + /** * pipe_empty - Return true if the pipe is empty * @head: The pipe ring head pointer