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); }