From patchwork Sat Feb 24 01:16:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 205764 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp935481dyb; Fri, 23 Feb 2024 17:21:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUQ+F0qXBmZOggsuPm/odcKUr9wHRYgOkoiMKrAkVtjo4DwqUFs3x/HqsBfs0fOM2+cEItXlj85sC++D/MrhXP5+a6fFQ== X-Google-Smtp-Source: AGHT+IGebrn2gz/53LPR/GP8M3dv1Ox25F0l2ECeD1wgYaX0cVXTTLDf73+ATX3Dd20Ad77VxAbO X-Received: by 2002:a05:6a20:4390:b0:1a0:e80a:b79e with SMTP id i16-20020a056a20439000b001a0e80ab79emr2267318pzl.14.1708737695277; Fri, 23 Feb 2024 17:21:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708737695; cv=pass; d=google.com; s=arc-20160816; b=DTSW1PjXUYfsLiC0xdbVwIdtlgkTPDHkgMw2MfnGgXOEPppcMozFi0B0NSZdI0Ei4j EOsRmoMD9WZKJgs3IJyy8YVQ04vgo7OXc2c1lhuqg7QveBSrS3wHzKwKZcIGMm2hDhz5 dVrRrd+h3OUd1tNQSqwslvgsvCWUo2q626BbIkY6ygDDtXpFK6lkcGlU4+FgKKGHHmr7 zBgDN6REGF6hTyOYzO9KfWyaQ/uBAtiD5ki2euP5fJIzdDp9VP0yVjiyLOynr/4qs82G n9snqh14d3qXhT7RcNRzUy2Fi3eCxKxnUTwRSeJgVe1tdqkYAf1uDNwA6OZSOy5A1BP9 bG9g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:cc:to:from:subject:date:dkim-signature; bh=5+lBEMD22J5PNT2pP8TkmyCSZAPq1ThbitjsazbzsqM=; fh=eGotrG2wUAPCtJbO4MhMKF1jcndrbQy7pSZLLDRnPjs=; b=yV7KQBbdbiXiRbM2N1Zb3b1qbhU0p+gBz840WG0exbEIxF+4GzQqON6HuvGNbCtyGx D55t+6WXYYPCtFXvQgnCYkxd0Q2DyTRc3uqEMegLtWbdecpEjSiegSD83ZYW2w8GN68B 7p4Kq5MMuBGdrXy8wZfPwAR7rw2xpW0j2/I3HV4oHBDWxnrkMba8ZXFIB529G8Pxwuki 68rNTLU/DmNRedL4HPbeoMp8uqavm1IlN/k5PDd+IMR9NCGI/EEyTOX+WnbUPgAtXHYa 65OemwZmKb8r5GqBv0YrAmxc6b51D/dNtvW7tTfRsIPm3HkZVf2dduO0AslS/ifKtW+5 /gEg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DvNUddRa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-79414-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79414-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ss3-20020a17090b2ec300b00298dd9da549si199559pjb.23.2024.02.23.17.21.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 17:21:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79414-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=@kernel.org header.s=k20201202 header.b=DvNUddRa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-79414-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79414-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 5E0F9B20EFB for ; Sat, 24 Feb 2024 01:17:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 23733E559; Sat, 24 Feb 2024 01:16:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DvNUddRa" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 71DC14C6B; Sat, 24 Feb 2024 01:16:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708737397; cv=none; b=JFw3tBGAlLla/XdtAcN1cRAq1bTMh4aX8h/VzN2+rp3LC3oMpcqKKAaTMB3ORjDMT3hdzzyLmKOEdc7+ZF7Eg69znF4Y/ZMvt9PWRfAWdnVM3oFGyYFfc6FofMQ3ZlDPy5ea7D4b2Qqxoph8cQ8SemoVKhCfKmCFfv0ExCz/88c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708737397; c=relaxed/simple; bh=N5BbLf22VJJFUcs1rkRIy9TnRfixcYINsE+roESUlYY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jaeUZ2oilxeu413c/acIcd2T+klIGWMnoZ12gw7mIBbUtSih5hBtdEPiNoFKyp05lyNyv8wLjBt+ugyCDnKwwDocWDDPQKQiXmfbsOpayqJtOaOEveQxx2iQVHVSOsIAljYub9A01mH93jZAMZATB8OfFso8PSoU692/EbrCzIo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DvNUddRa; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F11D8C433C7; Sat, 24 Feb 2024 01:16:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708737397; bh=N5BbLf22VJJFUcs1rkRIy9TnRfixcYINsE+roESUlYY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=DvNUddRaPdKJD636x3F8T/hFYH/97iqVGwp9X+vFguzGI54dKbE7Zf5UpnHnUICfh Phm71WuHorVTVBFYF8EJEaShJDE1Jq9MKDLuKrn2BzhKm6IDyplKcHd2I5mEpZ4GSW F8nYrdWu6u+Udgz94PIJquvZed0396HvfI5qVcKJcPenRgF4BetRKf76gemB/UufK2 ZBMGmb/emxXL6PlQAWEgtKLaLH9VjU7fKJf0+7ywSSKNq+82y/GrjPi4OVxKVSYK66 P5QPjPsRdaRDDSgENW+3qKagiKyx/5k5ZWC+LrYdfI6DWNTjX7NtnBzOacfOuHQnkF wkMDZude8VKqw== Date: Fri, 23 Feb 2024 17:16:36 -0800 Subject: [PATCH 1/5] thread_with_file: allow creation of readonly files From: "Darrick J. Wong" To: akpm@linux-foundation.org, daniel@gluo.nz, kent.overstreet@linux.dev, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <170873669417.1861696.15370508953432477102.stgit@frogsfrogsfrogs> In-Reply-To: <170873669390.1861696.14195299906744951144.stgit@frogsfrogsfrogs> References: <170873669390.1861696.14195299906744951144.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791741337565114789 X-GMAIL-MSGID: 1791741337565114789 From: Darrick J. Wong Create a new run_thread_with_stdout function that opens a file in O_RDONLY mode so that the kernel can write things to userspace but userspace cannot write to the kernel. This will be used to convey xfs health event information to userspace. Signed-off-by: Darrick J. Wong Signed-off-by: Kent Overstreet --- include/linux/thread_with_file.h | 3 +++ lib/thread_with_file.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/linux/thread_with_file.h b/include/linux/thread_with_file.h index 54091f7ff3383..5f7e85bc8322b 100644 --- a/include/linux/thread_with_file.h +++ b/include/linux/thread_with_file.h @@ -62,6 +62,9 @@ struct thread_with_stdio { int run_thread_with_stdio(struct thread_with_stdio *, void (*exit)(struct thread_with_stdio *), void (*fn)(struct thread_with_stdio *)); +int run_thread_with_stdout(struct thread_with_stdio *, + void (*exit)(struct thread_with_stdio *), + void (*fn)(struct thread_with_stdio *)); int stdio_redirect_read(struct stdio_redirect *, char *, size_t); int stdio_redirect_readline(struct stdio_redirect *, char *, size_t); diff --git a/lib/thread_with_file.c b/lib/thread_with_file.c index b09dc60ba6280..71028611b8d59 100644 --- a/lib/thread_with_file.c +++ b/lib/thread_with_file.c @@ -344,6 +344,22 @@ static int thread_with_stdio_release(struct inode *inode, struct file *file) return 0; } +static __poll_t thread_with_stdout_poll(struct file *file, struct poll_table_struct *wait) +{ + struct thread_with_stdio *thr = + container_of(file->private_data, struct thread_with_stdio, thr); + + poll_wait(file, &thr->stdio.output.wait, wait); + + __poll_t mask = 0; + + if (stdio_redirect_has_output(&thr->stdio)) + mask |= EPOLLIN; + if (thr->thr.done) + mask |= EPOLLHUP|EPOLLERR; + return mask; +} + static const struct file_operations thread_with_stdio_fops = { .llseek = no_llseek, .read = thread_with_stdio_read, @@ -352,6 +368,13 @@ static const struct file_operations thread_with_stdio_fops = { .release = thread_with_stdio_release, }; +static const struct file_operations thread_with_stdout_fops = { + .llseek = no_llseek, + .read = thread_with_stdio_read, + .poll = thread_with_stdout_poll, + .release = thread_with_stdio_release, +}; + static int thread_with_stdio_fn(void *arg) { struct thread_with_stdio *thr = arg; @@ -375,5 +398,18 @@ int run_thread_with_stdio(struct thread_with_stdio *thr, } EXPORT_SYMBOL_GPL(run_thread_with_stdio); +int run_thread_with_stdout(struct thread_with_stdio *thr, + void (*exit)(struct thread_with_stdio *), + void (*fn)(struct thread_with_stdio *)) +{ + stdio_buf_init(&thr->stdio.input); + stdio_buf_init(&thr->stdio.output); + thr->exit = exit; + thr->fn = fn; + + return run_thread_with_file(&thr->thr, &thread_with_stdout_fops, thread_with_stdio_fn); +} +EXPORT_SYMBOL_GPL(run_thread_with_stdout); + MODULE_AUTHOR("Kent Overstreet"); MODULE_LICENSE("GPL"); From patchwork Sat Feb 24 01:16:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 205758 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp934418dyb; Fri, 23 Feb 2024 17:18:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUAJfrwU5t7j04DwYX4nfzQu8l+6hhZkW7qU1PY7ZwdOOEGBEexXGbeUYfBBukB1fk9+BqLhja58xQWoPGQgAP/VNSnzg== X-Google-Smtp-Source: AGHT+IFDd0HffyiDgdZI6jPoQvtE8BRSTgnRIEjnlYNimqrbBqEISyw5aPUuVxLGxgZFcOjrGSl2 X-Received: by 2002:a05:620a:4088:b0:787:6909:777f with SMTP id f8-20020a05620a408800b007876909777fmr2718827qko.34.1708737484894; Fri, 23 Feb 2024 17:18:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708737484; cv=pass; d=google.com; s=arc-20160816; b=O6kUvYET34M6Ppihf2oNJvqX3igQdARNLdH3f9ZHgO+gNbAmzbxSldC+xlBWzPEj8K Z5ptbz9uolJQXGz2rASI5alq30Cp9Hf2crkUGIsNgueJqJdZsOxn2LqgKYCI2/FU9WxW SGawZAsiExSM6IXr1jZAz3EbzFILpoW++f9YKSLiQepEC72l8MPrleS7e3E2bNqz9toK CgPfjRKVDzYvwL0z9mTRwcbCv/mya8SCr0d9SIGtzXKg/OIPt0unrPXtLcpAdoCETW18 mfIYUewECmloTo4/aFh481uamFpQ3f9e29b0aPGaqW/Icjdhuz2+tY0lQUOM6zyq8hPE 8JyQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:cc:to:from:subject:date:dkim-signature; bh=Wi81AeYxnnovLZKcPq/G0T5rrMuBssJM4Ff6lAC93Qo=; fh=eGotrG2wUAPCtJbO4MhMKF1jcndrbQy7pSZLLDRnPjs=; b=Ot7vTl3sWUpQsiGGzh94Zl0CtDLS0tDLiXXe/VWg1hSyTPI20deqhrCYvkiXoOQk61 bGz36TnqOZ4ECY80rdjM5EgYzwKgkjmM12xKS3Ud23/B7AgiMALQlJb7eGpahhcQFSq7 xGwxJXT9RUGJNS7EPBPAw6eRy+wcYjTfb+ocRbX9W5P8fzsiP1g0kN/DoWPASU4UJDPt 02EIK+Bd/c5Cw+8981mVgipIMIdgw7FA8auPLXgh8/6cckuD22uOMrUHF7VLI3yHJtIl 75gcYJ+szQP2F52loTHNf2PgWQBubgGZw/n1Uf2VPCXI5ZMVNuMe1yl2thexm/9Zdr7r pJow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vOIqvMcy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-79415-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79415-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c21-20020a05620a201500b00787a71e63d5si135772qka.151.2024.02.23.17.18.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 17:18:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79415-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vOIqvMcy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-79415-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79415-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 9AD3E1C227A9 for ; Sat, 24 Feb 2024 01:18:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A047E4A04; Sat, 24 Feb 2024 01:16:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="vOIqvMcy" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F1833AD5E; Sat, 24 Feb 2024 01:16:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708737413; cv=none; b=OWy40jXb9vlNUomKA3F9CtRoi8AvfYDQ1vLJ/wfWUat/LGjcI/puX0Yk2luGxC4FJAH74T2tR2vx1CUAvSVVOMvCygHbCDZ0NOrZITyCbXf1riyuMPYvM5cJnjOkWlsvTjlQy9W2403Y/T0d2x0T0EhALH4/28AeSSdJ0auuGKo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708737413; c=relaxed/simple; bh=9DdYqFD9SCt6Bs3yagJsGZvwLwjDk5KJDyGnik7FRVc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fe5zGy/V0Qfw0I8PZAHZ0jwNM0/wBH8tRrQLSjLObRwFouTOMoIJR3Up+ExpFkUHLUGpDOVunzrx7Pi4NXXrNjjVyd8HtLMUxLvvZKVvV/upy2oc4xnSATYra85Y0bDtk1/86He0em9aMJz8FXpzfMgQEfOa8QCb+JH1ynmVagw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vOIqvMcy; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A9A2C433F1; Sat, 24 Feb 2024 01:16:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708737412; bh=9DdYqFD9SCt6Bs3yagJsGZvwLwjDk5KJDyGnik7FRVc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=vOIqvMcyt+32zXP2UCe88hRtJCelg0FwZfmQBcvXE9j0z1IgTAdoOaFQkHQ/l0rbU 9CjbeiD3ZXFQCIS3hoMbSDyXnuBNdd39egbSvfLmJu1dMSdhN90Bcw09VbzxGQtom+ QUQxqWjLykes47at+0dAhupRIlXPhwsUi8KZ2+0nYbvQ1qGBl4DyCKOIAC8K4U8BM8 nzr5mOYLCybLbmxcUfE+0gHR967oE8lDZ2y1zw3fE2P6qVP1Qzc2dieZ2I4tirC876 0BH4yRRXChejM2VlctRB7MxbZDnLTeUnk1Jqch48Ey488lGOTdo6rORdxFLpryBOvW ztmTQ55BtRteQ== Date: Fri, 23 Feb 2024 17:16:52 -0800 Subject: [PATCH 2/5] thread_with_file: fix various printf problems From: "Darrick J. Wong" To: akpm@linux-foundation.org, daniel@gluo.nz, kent.overstreet@linux.dev, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <170873669433.1861696.1893338653788145361.stgit@frogsfrogsfrogs> In-Reply-To: <170873669390.1861696.14195299906744951144.stgit@frogsfrogsfrogs> References: <170873669390.1861696.14195299906744951144.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791741117090587733 X-GMAIL-MSGID: 1791741117090587733 From: Darrick J. Wong Experimentally fix some problems with stdio_redirect_vprintf by creating a MOO variant with which we can experiment. We can't do a GFP_KERNEL allocation while holding the spinlock, and I don't like how the printf function can silently truncate the output if memory allocation fails. Signed-off-by: Darrick J. Wong Signed-off-by: Kent Overstreet --- include/linux/thread_with_file.h | 4 +-- lib/thread_with_file.c | 55 ++++++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/include/linux/thread_with_file.h b/include/linux/thread_with_file.h index 5f7e85bc8322b..7b133a15d3540 100644 --- a/include/linux/thread_with_file.h +++ b/include/linux/thread_with_file.h @@ -68,7 +68,7 @@ int run_thread_with_stdout(struct thread_with_stdio *, int stdio_redirect_read(struct stdio_redirect *, char *, size_t); int stdio_redirect_readline(struct stdio_redirect *, char *, size_t); -__printf(3, 0) void stdio_redirect_vprintf(struct stdio_redirect *, bool, const char *, va_list); -__printf(3, 4) void stdio_redirect_printf(struct stdio_redirect *, bool, const char *, ...); +__printf(3, 0) ssize_t stdio_redirect_vprintf(struct stdio_redirect *, bool, const char *, va_list); +__printf(3, 4) ssize_t stdio_redirect_printf(struct stdio_redirect *, bool, const char *, ...); #endif /* _LINUX_THREAD_WITH_FILE_H */ diff --git a/lib/thread_with_file.c b/lib/thread_with_file.c index 71028611b8d59..70a805ef017f9 100644 --- a/lib/thread_with_file.c +++ b/lib/thread_with_file.c @@ -108,49 +108,68 @@ int stdio_redirect_readline(struct stdio_redirect *stdio, char *ubuf, size_t len EXPORT_SYMBOL_GPL(stdio_redirect_readline); __printf(3, 0) -static void darray_vprintf(darray_char *out, gfp_t gfp, const char *fmt, va_list args) +static ssize_t darray_vprintf(darray_char *out, gfp_t gfp, const char *fmt, va_list args) { - size_t len; + ssize_t ret; do { va_list args2; + size_t len; + va_copy(args2, args); - len = vsnprintf(out->data + out->nr, darray_room(*out), fmt, args2); - } while (len + 1 > darray_room(*out) && !darray_make_room_gfp(out, len + 1, gfp)); + if (len + 1 <= darray_room(*out)) { + out->nr += len; + return len; + } - out->nr += min(len, darray_room(*out)); + ret = darray_make_room_gfp(out, len + 1, gfp); + } while (ret == 0); + + return ret; } -void stdio_redirect_vprintf(struct stdio_redirect *stdio, bool nonblocking, - const char *fmt, va_list args) +ssize_t stdio_redirect_vprintf(struct stdio_redirect *stdio, bool nonblocking, + const char *fmt, va_list args) { struct stdio_buf *buf = &stdio->output; unsigned long flags; + ssize_t ret; - if (!nonblocking) - wait_event(buf->wait, stdio_redirect_has_output_space(stdio)); - else if (!stdio_redirect_has_output_space(stdio)) - return; - if (stdio->done) - return; - +again: spin_lock_irqsave(&buf->lock, flags); - darray_vprintf(&buf->buf, nonblocking ? GFP_NOWAIT : GFP_KERNEL, fmt, args); + ret = darray_vprintf(&buf->buf, GFP_NOWAIT, fmt, args); spin_unlock_irqrestore(&buf->lock, flags); + if (ret < 0) { + if (nonblocking) + return -EAGAIN; + + ret = wait_event_interruptible(buf->wait, + stdio_redirect_has_output_space(stdio)); + if (ret) + return ret; + goto again; + } + wake_up(&buf->wait); + return ret; + } EXPORT_SYMBOL_GPL(stdio_redirect_vprintf); -void stdio_redirect_printf(struct stdio_redirect *stdio, bool nonblocking, - const char *fmt, ...) +ssize_t stdio_redirect_printf(struct stdio_redirect *stdio, bool nonblocking, + const char *fmt, ...) { va_list args; + ssize_t ret; + va_start(args, fmt); - stdio_redirect_vprintf(stdio, nonblocking, fmt, args); + ret = stdio_redirect_vprintf(stdio, nonblocking, fmt, args); va_end(args); + + return ret; } EXPORT_SYMBOL_GPL(stdio_redirect_printf); From patchwork Sat Feb 24 01:17:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 205766 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp936965dyb; Fri, 23 Feb 2024 17:27:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXepGKmHPXiVU+keKe3mMW1unpizR44sOPvrJI0tAYYzJb8o1msFiiTCPUZ+WIjrsimbE7FknocWmf/ri4UMo6wtP+sGA== X-Google-Smtp-Source: AGHT+IFAZCSupY7Rq1JS5SD3ht30qDIxEUfpjbNX1TyX+XOAZRmCo0694xLJP0muhmnGjUQs3Q8o X-Received: by 2002:aa7:df83:0:b0:564:ded0:6072 with SMTP id b3-20020aa7df83000000b00564ded06072mr1000720edy.1.1708738030709; Fri, 23 Feb 2024 17:27:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708738030; cv=pass; d=google.com; s=arc-20160816; b=KUlZlwqY+nGc0i/UTheoo160QL24bknGI718N0+3mYoa9ofq8lbt80rxF/CF7QXwDS GcnInqbfTDb34GgCbOsA0nBm1vmBUDcirGqhTlhFigGJOMzltW1Wiytk8TbrBl4u0T5J De0rGkWtIh/dw+U/UESujOa9ski3inYC2z4bspmwD0clJNZroFHtgN88D5sUeEVnb58J u0cCiVdiWOwMdlq/N/FPaxO+eMyuPBWPJL4ufdqfny+Z2Lzh52fdFMX/fpKw5lw6GQW6 HGpPI8oKAIlxEQ7iscAH7qMnpXj8CSH2z0TiV+J+wGlNEtfwLwiWaq8J8eF3XS83IO6i iq2Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:cc:to:from:subject:date:dkim-signature; bh=l2f9Lrd3RUDyHGxr8lnkSYc1VUDNFAN0TALXazIrP50=; fh=eGotrG2wUAPCtJbO4MhMKF1jcndrbQy7pSZLLDRnPjs=; b=p2diZnA7fGvQXs5vU1hVS+msVrMDxQHYyjPWrSi/qed4UWr6PQzSC7EpFkIrpeb85P N79/iMw6mmiOnoBx0UHGlBTjTW/MMQ+BXx2Bu71JofuB384Jf5H48wvbgd8v5ER9eOrM ahdK5l363G8SNEvnRsqSnxKUAp3uuufYFZpUzHkFySGyvX8l8mDWtuZjCN4nDZ4rKUic OT6Rv60Qh+m0HB+V8jPemx6yhzlQlhhK/OvVUt4tiGsdcg/sJcCWXzBps02/3Y8J9hVP /ap6gUMhaJgZf8x3XdiAVVxxwop17p25sQ2Ir743rYXPMsJ/oqOqz8vPh5rNcf++8tXJ shuQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uMRrz7yz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-79416-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79416-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id fd13-20020a056402388d00b005644479ae57si83706edb.537.2024.02.23.17.27.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 17:27:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79416-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uMRrz7yz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-79416-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79416-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 6D9B21F27B42 for ; Sat, 24 Feb 2024 01:18:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 50E276FB1; Sat, 24 Feb 2024 01:17:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uMRrz7yz" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 672424691; Sat, 24 Feb 2024 01:17:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708737428; cv=none; b=jWTpPGfK6SnKHVl+1Gj+9D8y5gztKvWzsKt4MvDZYXln4DI3I4GBrDSOWaZKJp/jfrOJ9jiOSXYQTLf1B8gBpD9n4YtwC0gyC4bdus/EeOHxrJ3Nbpz8+FJWR6X0XLjiCi5/G3Nxi7Q6amPCHgLn38XcqJMJ46f9D8Xz74LuwLE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708737428; c=relaxed/simple; bh=DgDuStDbtXbx/gj/++6OCZ66DPB+bjIkuDO5hm8rH/I=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mMQWC6NGLEFCEsrafAHAW5tTkI3Jw0t99g5c8nQLxC0IJyHrfK8dxyrHI8foZzkU6eqgHjrNIpPb+fR4P2ZLsEd03ghuVlHmvfiXpwoEIBMvpZcllzNBfooNqRz7eZIY0FUs6VGyDoF7QHPsVZXVfjUf8g3X+E50YHi9kjG2T5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uMRrz7yz; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AA8FC433F1; Sat, 24 Feb 2024 01:17:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708737428; bh=DgDuStDbtXbx/gj/++6OCZ66DPB+bjIkuDO5hm8rH/I=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=uMRrz7yzMPJu2KLe3x5dsgFpvLeAv7ZuamZcKrPOgZvkHLcF30TOZMru+vrti8nuz gZHAaToYTqL3n85QuOzBXOsrax1jpfQ5eTQ7ZIzxnyE3vhcw9otYeiFGPEwQSvhhMT Lhb5ITjTJnidzrmQeY5sK+aLmhM30iCB69G4XB2UloqeRsRRhjEcD5J331SxiD7ZCu 8BA3AjrNTjtay8OYNCAbowXMJjxP8VIQ3+E57ec9ahU771DdZcoVnBNC1iCUWRnY8D biOvII1pw9NdOYfQN/REYCuhX+5y8nCT7H1BB5jgBEEv9dhjdDOe8WeaxVmaD4BCND TlWL8mtl7bo+w== Date: Fri, 23 Feb 2024 17:17:07 -0800 Subject: [PATCH 3/5] thread_with_file: create ops structure for thread_with_stdio From: "Darrick J. Wong" To: akpm@linux-foundation.org, daniel@gluo.nz, kent.overstreet@linux.dev, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <170873669449.1861696.15191973366470386898.stgit@frogsfrogsfrogs> In-Reply-To: <170873669390.1861696.14195299906744951144.stgit@frogsfrogsfrogs> References: <170873669390.1861696.14195299906744951144.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791741689382990927 X-GMAIL-MSGID: 1791741689382990927 From: Darrick J. Wong Create an ops structure so we can add more file-based functionality in the next few patches. Signed-off-by: Darrick J. Wong Signed-off-by: Kent Overstreet --- fs/bcachefs/chardev.c | 18 ++++++++++++------ include/linux/thread_with_file.h | 16 ++++++++++------ lib/thread_with_file.c | 16 ++++++---------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/fs/bcachefs/chardev.c b/fs/bcachefs/chardev.c index 4cbda66bb6e0f..a2f30f45f93f7 100644 --- a/fs/bcachefs/chardev.c +++ b/fs/bcachefs/chardev.c @@ -165,6 +165,11 @@ static void bch2_fsck_offline_thread_fn(struct thread_with_stdio *stdio) bch2_fs_stop(c); } +static const struct thread_with_stdio_ops bch2_offline_fsck_ops = { + .exit = bch2_fsck_thread_exit, + .fn = bch2_fsck_offline_thread_fn, +}; + static long bch2_ioctl_fsck_offline(struct bch_ioctl_fsck_offline __user *user_arg) { struct bch_ioctl_fsck_offline arg; @@ -217,9 +222,7 @@ static long bch2_ioctl_fsck_offline(struct bch_ioctl_fsck_offline __user *user_a opt_set(thr->opts, stdio, (u64)(unsigned long)&thr->thr.stdio); - ret = run_thread_with_stdio(&thr->thr, - bch2_fsck_thread_exit, - bch2_fsck_offline_thread_fn); + ret = run_thread_with_stdio(&thr->thr, &bch2_offline_fsck_ops); err: if (ret < 0) { if (thr) @@ -794,6 +797,11 @@ static void bch2_fsck_online_thread_fn(struct thread_with_stdio *stdio) bch2_ro_ref_put(c); } +static const struct thread_with_stdio_ops bch2_online_fsck_ops = { + .exit = bch2_fsck_thread_exit, + .fn = bch2_fsck_online_thread_fn, +}; + static long bch2_ioctl_fsck_online(struct bch_fs *c, struct bch_ioctl_fsck_online arg) { @@ -834,9 +842,7 @@ static long bch2_ioctl_fsck_online(struct bch_fs *c, goto err; } - ret = run_thread_with_stdio(&thr->thr, - bch2_fsck_thread_exit, - bch2_fsck_online_thread_fn); + ret = run_thread_with_stdio(&thr->thr, &bch2_online_fsck_ops); err: if (ret < 0) { bch_err_fn(c, ret); diff --git a/include/linux/thread_with_file.h b/include/linux/thread_with_file.h index 7b133a15d3540..445b1b12a0bd6 100644 --- a/include/linux/thread_with_file.h +++ b/include/linux/thread_with_file.h @@ -52,19 +52,23 @@ int run_thread_with_file(struct thread_with_file *, const struct file_operations *, int (*fn)(void *)); +struct thread_with_stdio; + +struct thread_with_stdio_ops { + void (*exit)(struct thread_with_stdio *); + void (*fn)(struct thread_with_stdio *); +}; + struct thread_with_stdio { struct thread_with_file thr; struct stdio_redirect stdio; - void (*exit)(struct thread_with_stdio *); - void (*fn)(struct thread_with_stdio *); + const struct thread_with_stdio_ops *ops; }; int run_thread_with_stdio(struct thread_with_stdio *, - void (*exit)(struct thread_with_stdio *), - void (*fn)(struct thread_with_stdio *)); + const struct thread_with_stdio_ops *); int run_thread_with_stdout(struct thread_with_stdio *, - void (*exit)(struct thread_with_stdio *), - void (*fn)(struct thread_with_stdio *)); + const struct thread_with_stdio_ops *); int stdio_redirect_read(struct stdio_redirect *, char *, size_t); int stdio_redirect_readline(struct stdio_redirect *, char *, size_t); diff --git a/lib/thread_with_file.c b/lib/thread_with_file.c index 70a805ef017f9..2edf33c3e7dc5 100644 --- a/lib/thread_with_file.c +++ b/lib/thread_with_file.c @@ -359,7 +359,7 @@ static int thread_with_stdio_release(struct inode *inode, struct file *file) thread_with_file_exit(&thr->thr); darray_exit(&thr->stdio.input.buf); darray_exit(&thr->stdio.output.buf); - thr->exit(thr); + thr->ops->exit(thr); return 0; } @@ -398,33 +398,29 @@ static int thread_with_stdio_fn(void *arg) { struct thread_with_stdio *thr = arg; - thr->fn(thr); + thr->ops->fn(thr); thread_with_stdio_done(thr); return 0; } int run_thread_with_stdio(struct thread_with_stdio *thr, - void (*exit)(struct thread_with_stdio *), - void (*fn)(struct thread_with_stdio *)) + const struct thread_with_stdio_ops *ops) { stdio_buf_init(&thr->stdio.input); stdio_buf_init(&thr->stdio.output); - thr->exit = exit; - thr->fn = fn; + thr->ops = ops; return run_thread_with_file(&thr->thr, &thread_with_stdio_fops, thread_with_stdio_fn); } EXPORT_SYMBOL_GPL(run_thread_with_stdio); int run_thread_with_stdout(struct thread_with_stdio *thr, - void (*exit)(struct thread_with_stdio *), - void (*fn)(struct thread_with_stdio *)) + const struct thread_with_stdio_ops *ops) { stdio_buf_init(&thr->stdio.input); stdio_buf_init(&thr->stdio.output); - thr->exit = exit; - thr->fn = fn; + thr->ops = ops; return run_thread_with_file(&thr->thr, &thread_with_stdout_fops, thread_with_stdio_fn); } From patchwork Sat Feb 24 01:17:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 205760 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp934624dyb; Fri, 23 Feb 2024 17:18:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW0+Zb7y15UdsWKZ63NGYf30hLFEc0H13EREFz1ysFs7dZ1/FUCNhbbz+4QvuM/6pNa26wAxlHTWWChT0xx4iERi0aE2A== X-Google-Smtp-Source: AGHT+IGDImxfnXESe6WGyBpJnktnELvmiqL1Uivg6dModpPsDe83zgz9u3TciJkEBHf8Zi/1aIgH X-Received: by 2002:a05:6358:6f86:b0:17b:6f52:79d3 with SMTP id s6-20020a0563586f8600b0017b6f5279d3mr1600877rwn.16.1708737519756; Fri, 23 Feb 2024 17:18:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708737519; cv=pass; d=google.com; s=arc-20160816; b=Znabt77V7aX73/sWgF+RsI6XLKdc5yeiQd6hy4dBogVfJTf4W/RlBw1nRHhjBLfNFN aAg2WaAY/lwlu+nAvGh4SVNXcc6kDnZg4NeLpc74BXyCq4Rl7zPZZTXoCyjNuSMowFFf 2EPA/93A7Asq/OzlHS5PiCXZBYy/X7NJDM/2i7PX4qmEvQCgUzz/jl1wjCxTBBMxaHJu gu8URX+zeZ0aGwSC+HCNAMQdLwZkaYf+RzjMEw5OCp78IzANTA49ECXd2WfX1tlOZI/X LKsG8naTHfxRCyqJigqo9IKohtNR2JwypW3NMIYwJXWlCZHs2pEWS/e/bnM4e7KLT0ty D4/w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:cc:to:from:subject:date:dkim-signature; bh=a1rJW3Lr+iPJ+Ur0SLD/bxxfK0CNMm4wPtBgpv4AOe4=; fh=eGotrG2wUAPCtJbO4MhMKF1jcndrbQy7pSZLLDRnPjs=; b=PZXE7c8qFF7kRv456RCUfZHWrwZUoyXbLDrrxHk9uYoYMtInMXbyuIZ6ukhB+InkFZ 31CNNDOhx0KVhTqYyrpjq/MBqEF7NnjJdK5rdmW75h+pX//FR3w4KkhG0dlm9WQ+xLlE 27ZgETuEQCyZQPVAVX8n2jd/dGZZR71tnnGuLlY8QGRqSHh8e52zeKA5nIRn6sOV919N xiefFN7IoUQGw26ZpGT/gXl2QSokY+jhv31pv9LUITGWwETY3nYshXuCLfUx99SGDI8Z G1vruVqicmc9747q3jpZen16cIgvZDlIk/wSKXK2DV36MfgN5q//UO4W5IBjazcK+qm3 BbSw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Wqb8uP3n; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-79417-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79417-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id j2-20020a05620a146200b00787ad2ff7d7si122712qkl.482.2024.02.23.17.18.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 17:18:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79417-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Wqb8uP3n; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-79417-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79417-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 87DA51C2316D for ; Sat, 24 Feb 2024 01:18:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E85ABA2D; Sat, 24 Feb 2024 01:17:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Wqb8uP3n" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6E9C69473; Sat, 24 Feb 2024 01:17:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708737444; cv=none; b=GXo4ngTHdJpPt1VO2/UAoOn7ypaHEaJNQ1ka7ic/J1TVbg624wJZSHfiWx/dn90W2ogCu2AWCwLW9tBbQrKudr33UEihKNYzHzMyuAOKPsIdDo9jCcA8JC1gTKnD51Xk+HUiwYe6+u8lCKPOaczw+maKJ4pikYac5/ZAxHcZqXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708737444; c=relaxed/simple; bh=6IgKAnRC9HZ1+DMx6qKSJXO282zOxYj2aK6NUSak7mk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Bq/VMMMuRs9xZmKZhIQe8Hfal8qItvoPubbCmNpu+fLbiqKc7m45EvrYgxPiHKpNd7S/37z3EvzAGnYsJohP7JphZQHE5kMYUgTVaqiNnCKDfbwxKPKnToz5YGwX9B6kZnrpzndMQpnCXChYiLEWk0rf0SCh7rbECUdH1H2adGg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Wqb8uP3n; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D53E1C433F1; Sat, 24 Feb 2024 01:17:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708737443; bh=6IgKAnRC9HZ1+DMx6qKSJXO282zOxYj2aK6NUSak7mk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Wqb8uP3nEts44NoynAnfg3U+0J8HQh8VOOnAhIr1TugjJfxfrXA4qaUNKp6BfS9C+ teqcKULtwbzl9POLu3eBa8zacMjWL2Z765IgRu4xsVflxDfJ8I+U2yk5NKrOYCiyXT u03WSOHXd/QjYtdMgaiadMd8czDYBng7K1GbFy9F7p7OMyYgqKU08aFQrdjTbNLEaN MQ6odQ2KA8zSf3nK/v/LCi5gcPRt34ZSRlEcy5LN/lNIOW4E0Nk0RIcEr73buYuG4i j33ovb8qtry7TvaJtMwv09qnLwjW7i5el2WsDrWnMA5irxrFJ+FgqcN9DiEt0LWX+7 0YmX5v/KpCYQg== Date: Fri, 23 Feb 2024 17:17:23 -0800 Subject: [PATCH 4/5] thread_with_file: allow ioctls against these files From: "Darrick J. Wong" To: akpm@linux-foundation.org, daniel@gluo.nz, kent.overstreet@linux.dev, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <170873669465.1861696.18118008706761741778.stgit@frogsfrogsfrogs> In-Reply-To: <170873669390.1861696.14195299906744951144.stgit@frogsfrogsfrogs> References: <170873669390.1861696.14195299906744951144.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791741153500077590 X-GMAIL-MSGID: 1791741153500077590 From: Darrick J. Wong Make it so that a thread_with_stdio user can handle ioctls against the file descriptor. Signed-off-by: Darrick J. Wong Signed-off-by: Kent Overstreet --- include/linux/thread_with_file.h | 1 + lib/thread_with_file.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/linux/thread_with_file.h b/include/linux/thread_with_file.h index 445b1b12a0bd6..33770938d5d9a 100644 --- a/include/linux/thread_with_file.h +++ b/include/linux/thread_with_file.h @@ -57,6 +57,7 @@ struct thread_with_stdio; struct thread_with_stdio_ops { void (*exit)(struct thread_with_stdio *); void (*fn)(struct thread_with_stdio *); + long (*unlocked_ioctl)(struct thread_with_stdio *, unsigned int, unsigned long); }; struct thread_with_stdio { diff --git a/lib/thread_with_file.c b/lib/thread_with_file.c index 2edf33c3e7dc5..8b129744a48a3 100644 --- a/lib/thread_with_file.c +++ b/lib/thread_with_file.c @@ -379,12 +379,23 @@ static __poll_t thread_with_stdout_poll(struct file *file, struct poll_table_str return mask; } +static long thread_with_stdio_ioctl(struct file *file, unsigned int cmd, unsigned long p) +{ + struct thread_with_stdio *thr = + container_of(file->private_data, struct thread_with_stdio, thr); + + if (thr->ops->unlocked_ioctl) + return thr->ops->unlocked_ioctl(thr, cmd, p); + return -ENOTTY; +} + static const struct file_operations thread_with_stdio_fops = { .llseek = no_llseek, .read = thread_with_stdio_read, .write = thread_with_stdio_write, .poll = thread_with_stdio_poll, .release = thread_with_stdio_release, + .unlocked_ioctl = thread_with_stdio_ioctl, }; static const struct file_operations thread_with_stdout_fops = { @@ -392,6 +403,7 @@ static const struct file_operations thread_with_stdout_fops = { .read = thread_with_stdio_read, .poll = thread_with_stdout_poll, .release = thread_with_stdio_release, + .unlocked_ioctl = thread_with_stdio_ioctl, }; static int thread_with_stdio_fn(void *arg) From patchwork Sat Feb 24 01:17:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 205765 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp935976dyb; Fri, 23 Feb 2024 17:23:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWHWc2LVBCVxo7kUJ3wqD+j9wGV/5HSP08OeFbYjnxwH7UkSEnudG4I+skUanNwjq96hUmtNqF+0PmUhdld6DEaK5Krew== X-Google-Smtp-Source: AGHT+IHGcVLjtHt4Ebtj7Il2ebEhbK0Gytt/JZjuM1gfVHkog0otZgM9hOHRclMX4rLI8261OTHC X-Received: by 2002:a05:6870:32cd:b0:21f:a138:adf5 with SMTP id r13-20020a05687032cd00b0021fa138adf5mr1594632oac.39.1708737801107; Fri, 23 Feb 2024 17:23:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708737801; cv=pass; d=google.com; s=arc-20160816; b=SjKRd4xTBZqLVmAhnjR8z5+5CiImgNhfVvHo/d+LAzrRhTyIwyQ+v/iau2b/EbLR2T MnpNV6mA9/s/xgGR2JaP/6ibfKmjRBy1ccBO4A5BIJyrROGP/gFqeqxjXodRf8stM2xx lLjIWlsmz1DoENUHd0dFrPgeIPF9KErJGBg4wMR0Q4N+1xMW+PLH5MsThO+UiK8nuETI ILXB7b0/f8KjJr1fNxLU+d0ovb9YGu3Q6qMafqhr+oLbMIDJz4byg9GPyOfw8jyOGh2P ZpMgbCs21vhrmpZVPo8LUFTNoyP7Dlle8cdgRnKxwNlmibEtln8OQoIDSJwPVkFjA1lq a/xg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:cc:to:from:subject:date:dkim-signature; bh=LUtdvo88KWvYhNI8pd2kpp65eWy+nzYyy76NDO7ddA0=; fh=eGotrG2wUAPCtJbO4MhMKF1jcndrbQy7pSZLLDRnPjs=; b=YurTNwbRvT7anV7OBPQR5WCjvVoi1uIbHgkil3zVhnyPMnPZ4sxIlDHpU9HGYjjbkd aMMjJ53liDSVkaYmaufVCagXxIiL81krXIA+JA6RjBpEfScS99/QGO4UvCpGpPUcZsoT B0hStC92FQ3a3YmWe8byxkONXICYmHtbtskUuquLhcH7wzmJavtpJAh38vf2PozWsGPa T1eykl06e4nFGA37cwUNW9ODmqU+/H+zIEbF1rsxvdE7zUPK4FDGbkmYz6T5aYnPeGrv uWvJZMf82sTsgilxCc8rKGRBENnSCVpkQLb5kWv+mUOuuSM8/LUDPXDsqefnfWdhZud1 iJnA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JHfHHYY0; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-79418-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79418-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id c14-20020a65618e000000b005d6d6f8cbddsi159829pgv.360.2024.02.23.17.23.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 17:23:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79418-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JHfHHYY0; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-79418-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79418-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 7D28AB2445D for ; Sat, 24 Feb 2024 01:18:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8EC8810A2C; Sat, 24 Feb 2024 01:17:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JHfHHYY0" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 EE75FAD4E; Sat, 24 Feb 2024 01:17:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708737460; cv=none; b=YSKEMd9U9YmQNHsR1EogAx8bqpCVJdwfWOa6EQd+2GD03zRaniv2q9JIb9J8wtKLDIIJp2NjEL2toLHHlu4NXIhnwMZOIeYSB49fE96xQ0Yj3npoMcMX8nJVZCWG+nMZYRhM+3Tn/PQSvTiRoVKXnUVp42EqAuniyr/hx76h4+c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708737460; c=relaxed/simple; bh=ZFtseLCUuaQeCSzQKjfhYeUT0c1H+3VXLY2EjIC2gqg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BzbUXNEM9NK/S7kGqe4zR9UiBUBSyfZ5dHX3Gs6honJJw3AsVBEaf1xMyZZD9Q7WlwVax/q6APDYls4M/8JrlLZzVkwy0tq2yS+Ut2+6keNiZiE3GhwDzM1OqUhuClfVofN6Y5hMUc1WB5SxVIfMK3nInDqMNpVQOZFQblxmhdk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JHfHHYY0; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65A84C433F1; Sat, 24 Feb 2024 01:17:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708737459; bh=ZFtseLCUuaQeCSzQKjfhYeUT0c1H+3VXLY2EjIC2gqg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=JHfHHYY0pcy3eZfzZLtZAZymX6JMLgMYlKhh2daVfMNrjmKMLcx4NN7u9pL/7k3ZY D9daNNykjjngYcIAleD4RF+b0n6rN+22lYGz2dqXYx9NWFQEE33M3IPafaZGPVjEU8 bGOa4nvcp8M1/UuxB07GQwCmf4DACv0Y+QjPf7nVom5pT1jP2T8/mVQbFYKSTTO90m IkvlE4ajj43pvt+frH7/T/oBFMNckXMwKMwIJeQYkPxXuTYLIeVguXu7mT0kBPBHCN 3jafYG6XjfWdXHsp9qbh3PXubGNpEdY7+dUKbNB+OWbw8Vl9w7uWh6WFlDnmdfJS/c sTeVNrKWbg+Uw== Date: Fri, 23 Feb 2024 17:17:39 -0800 Subject: [PATCH 5/5] thread_with_file: Fix missing va_end() From: "Darrick J. Wong" To: akpm@linux-foundation.org, daniel@gluo.nz, kent.overstreet@linux.dev, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <170873669481.1861696.7555634432474446443.stgit@frogsfrogsfrogs> In-Reply-To: <170873669390.1861696.14195299906744951144.stgit@frogsfrogsfrogs> References: <170873669390.1861696.14195299906744951144.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791741448455838489 X-GMAIL-MSGID: 1791741448455838489 From: Kent Overstreet Fixes: https://lore.kernel.org/linux-bcachefs/202402131603.E953E2CF@keescook/T/#u Signed-off-by: Kent Overstreet Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- lib/thread_with_file.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/thread_with_file.c b/lib/thread_with_file.c index 8b129744a48a3..37a1ea22823ca 100644 --- a/lib/thread_with_file.c +++ b/lib/thread_with_file.c @@ -118,6 +118,8 @@ static ssize_t darray_vprintf(darray_char *out, gfp_t gfp, const char *fmt, va_l va_copy(args2, args); len = vsnprintf(out->data + out->nr, darray_room(*out), fmt, args2); + va_end(args2); + if (len + 1 <= darray_room(*out)) { out->nr += len; return len;