From patchwork Mon Nov 6 22:08:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13447527 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3FBCC4167D for ; Mon, 6 Nov 2023 22:08:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233215AbjKFWIk (ORCPT ); Mon, 6 Nov 2023 17:08:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233201AbjKFWIk (ORCPT ); Mon, 6 Nov 2023 17:08:40 -0500 Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D633D47 for ; Mon, 6 Nov 2023 14:08:37 -0800 (PST) Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-6cd09663b1cso3176162a34.3 for ; Mon, 06 Nov 2023 14:08:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1699308516; x=1699913316; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=tm+FRJ/W+NXgd6Kwdpc/Qv1uQRM6BXRjdtybkaEGYq4=; b=qbobeG9xGxap184SxHyGKgyGq2PgyS6IpoWlojmwYfDuh3dn00WHg4W8ucCbcq2+ug jPPEQQRxoPpmmPkruCwdmTI9bAY4mLVzW3g2y8m/TvZugY5MKdSooovR/zz6D3vfoWEf iCAi20t/6gzW1ymaXBRPfbu1Nv806mksHMgL3soRLo88BEFMNcY/CvIt7jU/E2YuTlPW YbKhIAvYxSSLpYbmjaRDNCvzwKDnth12HlWljgUn4u5kQPSrrfgLmQDAZDa2yyeCdzq6 aW1dJXfVN7BO9opBONdYZluLpPrZ2KPhe5U+PLg8LqO5rlj/jeXlBdgPA+YKRR+B2QHi SpLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699308516; x=1699913316; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tm+FRJ/W+NXgd6Kwdpc/Qv1uQRM6BXRjdtybkaEGYq4=; b=TfFDL1MZr2WnL0xq6liOv1D+OKoosVPJouQYh4fq5ASHVDBxGBJJ8n8HvyN+lFYAl6 1Fa1QXWzZptPIxHHEEac20NahOI/EbUB2BWk375Hoz97SjVxII/2ndjGzfNfnjfWkP7r KMWON8l21HEK/YKzXPUQlfHUe+V/IK/GKFRWajsupKFgdX2ETi5uP9cwrb05W4jRY/Qn f118+b7etyzDyBVoyYtXwxpoBhA/oltj6xNhoC600GRW0zx9VZPNYIzIkU+zhhZ6Keri YJw//aHluGZ59FpBWeQuwX4mdZrmPFd7+bqSG6QwQJGjUudW53LAT06TRcYrOYUrozRa t9ug== X-Gm-Message-State: AOJu0YwqGZ4zyCfk97JPDrwOwZDdJbH5C4d2u0j1SHCbI8MhYABtf6h/ jX+yUxJuIDFdZSE6bnLdypc5qhVz7wXavbZAWkt0Dg== X-Google-Smtp-Source: AGHT+IE8UYS4BfJoDg85VHDCQdvWtIH0Rgry8aTYWqwQxNAxbD70mCkr6GJphA7w4l+kl1LzcZM44w== X-Received: by 2002:a9d:6657:0:b0:6cd:a63:6ed4 with SMTP id q23-20020a9d6657000000b006cd0a636ed4mr28750100otm.14.1699308516501; Mon, 06 Nov 2023 14:08:36 -0800 (PST) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id p16-20020ac87410000000b00419732075b4sm3760788qtq.84.2023.11.06.14.08.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:08:36 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, linux-fsdevel@vger.kernel.org, brauner@kernel.org Subject: [PATCH 01/18] fs: indicate request originates from old mount api Date: Mon, 6 Nov 2023 17:08:09 -0500 Message-ID: <75912547b45b70df4f5b7d19e2de8d5fda5c8167.1699308010.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Christian Brauner We already communicate to filesystems when a remount request comes from the old mount api as some filesystems choose to implement different behavior in the new mount api than the old mount api to e.g., take the chance to fix significant api bugs. Allow the same for regular mount requests. Signed-off-by: Christian Brauner Signed-off-by: Josef Bacik Reviewed-by: Christoph Hellwig --- fs/namespace.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/namespace.c b/fs/namespace.c index e157efc54023..bfc5cff0e196 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2873,7 +2873,12 @@ static int do_remount(struct path *path, int ms_flags, int sb_flags, if (IS_ERR(fc)) return PTR_ERR(fc); + /* + * Indicate to the filesystem that the remount request is coming + * from the legacy mount system call. + */ fc->oldapi = true; + err = parse_monolithic_mount_data(fc, data); if (!err) { down_write(&sb->s_umount); @@ -3322,6 +3327,12 @@ static int do_new_mount(struct path *path, const char *fstype, int sb_flags, if (IS_ERR(fc)) return PTR_ERR(fc); + /* + * Indicate to the filesystem that the mount request is coming + * from the legacy mount system call. + */ + fc->oldapi = true; + if (subtype) err = vfs_parse_fs_string(fc, "subtype", subtype, strlen(subtype)); From patchwork Mon Nov 6 22:08:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13447528 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6384C4167B for ; Mon, 6 Nov 2023 22:08:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233218AbjKFWIm (ORCPT ); Mon, 6 Nov 2023 17:08:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233201AbjKFWIl (ORCPT ); Mon, 6 Nov 2023 17:08:41 -0500 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85EB8D47 for ; Mon, 6 Nov 2023 14:08:38 -0800 (PST) Received: by mail-qv1-xf2c.google.com with SMTP id 6a1803df08f44-67089696545so31698236d6.0 for ; Mon, 06 Nov 2023 14:08:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1699308517; x=1699913317; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Wju2KDo89W0KqnbnN0qwqJupbKYYoKpOCJuF9HTEAq4=; b=VuEPCyVmiv47j8fjcgoD/1AfDaLySV+bMl1MCZY7D9nC/Z5dDqABGUw9pWSV0Qlfq5 co/m7mQ6jpgwyp2TYP5NZg4/2eTdSpcw9UphCLPnt0kSWGBBjk5Utk5yMV2FOfOD8ywY DfqKPopxPBlIfTjs/xETE6dP4Iay+ZUlmVdjdLRiYBbEMZ4MydjRkN2cSR2Zd1SJjsE4 S3f+B/dJNDu8j0SJDhF9OLHJZDb9WFkOA1EQKEXoR89b8Qreamv7vb2BwE4xJFlotRaz Z8krqKQm4JroWbmNV9/Xndac6bt1zjIidHkTVcBr98NC4Pq8mlUBKbTQjTF73AtlXM3K R7aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699308517; x=1699913317; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wju2KDo89W0KqnbnN0qwqJupbKYYoKpOCJuF9HTEAq4=; b=FTeK7lFYhOvLJV7z1dnbIT67RedGNnN6ayxeyE4Jt1Aj24CCd94KwNFQbyUCWywXEp JOyfXdlPBCT6e68TRWWUhZv3sCMGPnxYQMg+KVyH7QpsEz215HTlM+5DTi9516HjuMiL zB3xYVmBI/0FzxV7Stfn/8Igsf28y/YLqfXtfnGXx61LnhH5CJTBqp+iU+uE8TBHshTD EuLWlVHvB806yaN9CuIG4PhDd3SXneGUv04zTRuLttSNW7uk4ECquk4hLgNG0gOlmB1j bht/+Sw4Z3jX8+QYl2X8hTR9cA8BCi/hnUOT82L5GKhs7hmBrrbQ/YlhpwUjdkH47FpI pR/w== X-Gm-Message-State: AOJu0YzyxTcyYd0HDTTFnsV0M/rappx9MEksNNusAxtxXvZI2zhi1zqU c5qLLakkHj48K1Ryiisb7orIUUA9pX6FaoFpYv4FAg== X-Google-Smtp-Source: AGHT+IHTYcyj/yGwLeP8RSSKs+dngQ5QGF5T5Msr4rMOHiK6M/weyhgIwMWFNBolNUanVCRgzi5vpQ== X-Received: by 2002:ad4:4ea7:0:b0:66d:1215:6e3 with SMTP id ed7-20020ad44ea7000000b0066d121506e3mr36732241qvb.10.1699308517534; Mon, 06 Nov 2023 14:08:37 -0800 (PST) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id l8-20020a0ce848000000b0065d89f4d537sm3789905qvo.45.2023.11.06.14.08.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:08:37 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, linux-fsdevel@vger.kernel.org, brauner@kernel.org Subject: [PATCH 02/18] btrfs: split out the mount option validation code into its own helper Date: Mon, 6 Nov 2023 17:08:10 -0500 Message-ID: <83e9157999dd0bc41ef1c267a6d6c0a83b36340d.1699308010.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We're going to need to validate mount options after they're all parsed with the new mount api, split this code out into its own helper so we can use it when we swap over to the new mount api. Signed-off-by: Josef Bacik --- fs/btrfs/super.c | 64 ++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 6ecf78d09694..639601d346d0 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -233,6 +233,39 @@ static bool check_ro_option(struct btrfs_fs_info *fs_info, unsigned long opt, return false; } +static bool check_options(struct btrfs_fs_info *info, unsigned long flags) +{ + if (!(flags & SB_RDONLY) && + (check_ro_option(info, BTRFS_MOUNT_NOLOGREPLAY, "nologreplay") || + check_ro_option(info, BTRFS_MOUNT_IGNOREBADROOTS, "ignorebadroots") || + check_ro_option(info, BTRFS_MOUNT_IGNOREDATACSUMS, "ignoredatacsums"))) + return false; + + if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE) && + !btrfs_test_opt(info, FREE_SPACE_TREE) && + !btrfs_test_opt(info, CLEAR_CACHE)) { + btrfs_err(info, "cannot disable free space tree"); + return false; + } + if (btrfs_fs_compat_ro(info, BLOCK_GROUP_TREE) && + !btrfs_test_opt(info, FREE_SPACE_TREE)) { + btrfs_err(info, "cannot disable free space tree with block-group-tree feature"); + return false; + } + + if (btrfs_check_mountopts_zoned(info)) + return false; + + if (!test_bit(BTRFS_FS_STATE_REMOUNTING, &info->fs_state)) { + if (btrfs_test_opt(info, SPACE_CACHE)) + btrfs_info(info, "disk space caching is enabled"); + if (btrfs_test_opt(info, FREE_SPACE_TREE)) + btrfs_info(info, "using free space tree"); + } + + return true; +} + static int parse_rescue_options(struct btrfs_fs_info *info, const char *options) { char *opts; @@ -311,7 +344,6 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, int saved_compress_level; bool saved_compress_force; int no_compress = 0; - const bool remounting = test_bit(BTRFS_FS_STATE_REMOUNTING, &info->fs_state); if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE)) btrfs_set_opt(info->mount_opt, FREE_SPACE_TREE); @@ -330,7 +362,7 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, * against new flags */ if (!options) - goto check; + goto out; while ((p = strsep(&options, ",")) != NULL) { int token; @@ -774,35 +806,9 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, break; } } -check: - /* We're read-only, don't have to check. */ - if (new_flags & SB_RDONLY) - goto out; - - if (check_ro_option(info, BTRFS_MOUNT_NOLOGREPLAY, "nologreplay") || - check_ro_option(info, BTRFS_MOUNT_IGNOREBADROOTS, "ignorebadroots") || - check_ro_option(info, BTRFS_MOUNT_IGNOREDATACSUMS, "ignoredatacsums")) - ret = -EINVAL; out: - if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE) && - !btrfs_test_opt(info, FREE_SPACE_TREE) && - !btrfs_test_opt(info, CLEAR_CACHE)) { - btrfs_err(info, "cannot disable free space tree"); + if (!ret && !check_options(info, new_flags)) ret = -EINVAL; - } - if (btrfs_fs_compat_ro(info, BLOCK_GROUP_TREE) && - !btrfs_test_opt(info, FREE_SPACE_TREE)) { - btrfs_err(info, "cannot disable free space tree with block-group-tree feature"); - ret = -EINVAL; - } - if (!ret) - ret = btrfs_check_mountopts_zoned(info); - if (!ret && !remounting) { - if (btrfs_test_opt(info, SPACE_CACHE)) - btrfs_info(info, "disk space caching is enabled"); - if (btrfs_test_opt(info, FREE_SPACE_TREE)) - btrfs_info(info, "using free space tree"); - } return ret; } From patchwork Mon Nov 6 22:08:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13447529 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 811BBC4332F for ; Mon, 6 Nov 2023 22:08:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233223AbjKFWIq (ORCPT ); Mon, 6 Nov 2023 17:08:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233201AbjKFWIq (ORCPT ); Mon, 6 Nov 2023 17:08:46 -0500 Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99E4ED47 for ; Mon, 6 Nov 2023 14:08:39 -0800 (PST) Received: by mail-ot1-x32c.google.com with SMTP id 46e09a7af769-6ce31c4a653so3234983a34.3 for ; Mon, 06 Nov 2023 14:08:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1699308519; x=1699913319; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ehBDfIuN7LiSpCRECNrlmwLyhaoGnDe/cfSCFvX9BgQ=; b=v/RPI4Wnk/tEB6JRsCewvwq3vXTbPDvjuCPPhwSABEkdX6Q+UmeAUtdIC07xWPWz1y r6qUnsVRXeIKy0EaCp2GxrAb0y2trKdqJd1p1N/VNzZz523BMtk0lK440y7E3rHVz6Sz VqSeOqcGHFCCwyxVgYjZ/kgc392JD0I3LY/DqOk+USe1oa9RAssxhJeHbs5QAe/pULoY OyDJouLfXMk73T5grfbJABODTHDCaZqLvRd2sGHgNm+mdYVMUZm709++bLOVd3bRHIds 2X6WiAebuZFPOVEg56jAOwXkonH8q/oYa2ZGsATOre24+hPM1LZtvaWu5SpjkfOCCmFZ CoOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699308519; x=1699913319; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ehBDfIuN7LiSpCRECNrlmwLyhaoGnDe/cfSCFvX9BgQ=; b=bsVYpt4gtAqS9GDKtevsx69LCcZ0VE9t+P9DAMPEIOE4PUHW7Q7uBvkFLJe3OSW2wN d+AvEEx6h/U8HOl/1g0aXEdMiYnYKgTKbIVDfd2OZdYRAPv3h+nywktAdRHAOWapC+nR TAHDbXwR56tMT53w+p4lUNvgIHhjIGBOhASF3/RQlwWXobT8eKQJRBtO1FdAmn6bSBvS 01CB3THISSh0n5+DLjA4F+0FfQTWzHYcLaI7sWUg0OyL+9eMKwlkr4AYdgSO00A41xsy J4lftXMumS7dEuhs/9EIs1bj3Hj9y6ulZscvnSrcM5hvGWVfVLmLvTJJcqDzZThpFpsS ha6g== X-Gm-Message-State: AOJu0YyNP3vWdsfGrJx5h5dVwF5Q7S51MoluJxJBNpQrpwXWs7DFMv9C SenEu18L9Ynu3l37dMGPc14DStwQA6GQeXHdLNF+2w== X-Google-Smtp-Source: AGHT+IEgVlaYx/dgmuA2Odvi4lyhjcsKk7FPEE0yixJN6mnEoCCGvYnaMWr/hfwhHvssqOsQvuG5FA== X-Received: by 2002:a9d:4e91:0:b0:6cc:fff0:8eb1 with SMTP id v17-20020a9d4e91000000b006ccfff08eb1mr31502509otk.23.1699308518798; Mon, 06 Nov 2023 14:08:38 -0800 (PST) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id w20-20020ac87194000000b0041969bc2e4csm3792331qto.32.2023.11.06.14.08.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:08:38 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, linux-fsdevel@vger.kernel.org, brauner@kernel.org Subject: [PATCH 03/18] btrfs: set default compress type at btrfs_init_fs_info time Date: Mon, 6 Nov 2023 17:08:11 -0500 Message-ID: <2945ad89590218391019572440f2ec620725ebe3.1699308010.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org With the new mount API we'll be setting our compression well before we call open_ctree. We don't want to overwrite our settings, so set the default in btrfs_init_fs_info instead of open_ctree. Signed-off-by: Josef Bacik --- fs/btrfs/disk-io.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 350e1b02cc8e..27bbe0164425 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2790,6 +2790,9 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info) fs_info->sectorsize_bits = ilog2(4096); fs_info->stripesize = 4096; + /* Default compress algorithm when user does -o compress */ + fs_info->compress_type = BTRFS_COMPRESS_ZLIB; + fs_info->max_extent_size = BTRFS_MAX_EXTENT_SIZE; spin_lock_init(&fs_info->swapfile_pins_lock); @@ -3271,13 +3274,6 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device if (btrfs_super_flags(disk_super) & BTRFS_SUPER_FLAG_ERROR) WRITE_ONCE(fs_info->fs_error, -EUCLEAN); - /* - * In the long term, we'll store the compression type in the super - * block, and it'll be used for per file compression control. - */ - fs_info->compress_type = BTRFS_COMPRESS_ZLIB; - - /* Set up fs_info before parsing mount options */ nodesize = btrfs_super_nodesize(disk_super); sectorsize = btrfs_super_sectorsize(disk_super); From patchwork Mon Nov 6 22:08:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13447532 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 520E7C4167B for ; Mon, 6 Nov 2023 22:08:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233230AbjKFWIr (ORCPT ); Mon, 6 Nov 2023 17:08:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233201AbjKFWIq (ORCPT ); Mon, 6 Nov 2023 17:08:46 -0500 Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA31BD73 for ; Mon, 6 Nov 2023 14:08:40 -0800 (PST) Received: by mail-oi1-x22c.google.com with SMTP id 5614622812f47-3b5aee410f2so537395b6e.1 for ; Mon, 06 Nov 2023 14:08:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1699308520; x=1699913320; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=UexHohZT1zGNjOL7yf4hKV+PGAsUG8V/5z9hjR15Oqk=; b=krXZnqioVUXUBH/oA9IzT839MnVk148JbEdrCLGFgtFU5G2jBYuVkmQnWWFxaqrBOG 7N+5RlT6cre9a4c6c4vOHHX0i/JYsHbcMMPWYG69EyYNlgD6+Qns30hs5PDbUzdyDLsF 2RwrHSgVCcZAabAbvjxBRHbidW1t66eJaxIS2IiyNngTyqAfRJeq5avAGwcs3t0xvsCI rYMigHfG4qVrWt5cpIMAlpjakq/3ICd4wQCCD5PWvqWfU1T8lu05tawhoOsc/hdaPo/z hZ1wsVfBhE7M1MOaHfl1wVetrS2yb4AXzoUGHTPJB7WyGdHRMdz8UWesFSVxAe9CW766 OAsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699308520; x=1699913320; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UexHohZT1zGNjOL7yf4hKV+PGAsUG8V/5z9hjR15Oqk=; b=W7zSe3LIlZr2VVHjtk3hx58imTJgXKLUBu714GyQ8Otj0pHXCeL5yri0Os5NBKfMFW sI2c7tyWuypOvnV59AqBuMylM850Z8pX4xTvNacIp1yhSzcunQZec+ZfWIT6xxlZrcch P9CrBuYJ2lFEGVLAzHKXlCzoWfR3IgflADhM6HquZcOfSDiC3LvSD+FadbUY282CpBwZ 8oF8gqSkik/hyaKX25pAggQojkU5i2FMSB9HljH2+5GWMJc1/bcss1cxpHEq6vTuXJ/R /f/UnN4GLUCqodUw0wuEfNIZWOqOjjeslK5ZwIap9PcoWRDQm1LlSJEhxruQAxe/Yzqx P1AQ== X-Gm-Message-State: AOJu0Yy8iUQEGQiFK8dcchBcRnhj81ZCWqaD/PufYKA4ACnqsQXzOeGl p5YYk19/VdtkwvyUDAHPxvkQNTzS0+qPrtboDynVLw== X-Google-Smtp-Source: AGHT+IEsSkQwqGH/Z2C3WgO1lyNjDiET3eonjemQF3MKYBkI/sWtxgXvCPTVXcEr/xCJAp9Cp+tyDw== X-Received: by 2002:a54:4592:0:b0:3af:26e3:92e with SMTP id z18-20020a544592000000b003af26e3092emr25756972oib.28.1699308519919; Mon, 06 Nov 2023 14:08:39 -0800 (PST) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id u3-20020a0cb403000000b0064f43efc844sm3904755qve.32.2023.11.06.14.08.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:08:39 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, linux-fsdevel@vger.kernel.org, brauner@kernel.org Subject: [PATCH 04/18] btrfs: move space cache settings into open_ctree Date: Mon, 6 Nov 2023 17:08:12 -0500 Message-ID: <93c7e11e73d40b30cd086b0b32ad8b7a86060442.1699308010.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Currently we pre-load the space cache settings in btrfs_parse_options, however when we switch to the new mount API the mount option parsing will happen before we have the super block loaded. Add a helper to set the appropriate options based on the fs settings, this will allow us to have consistent free space cache settings. This also folds in the space cache related decisions we make for subpage sectorsize support, so all of this is done in one place. Signed-off-by: Josef Bacik --- fs/btrfs/disk-io.c | 17 +++++--------- fs/btrfs/free-space-cache.h | 1 + fs/btrfs/super.c | 44 ++++++++++++++++++++++++++----------- fs/btrfs/super.h | 1 + 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 27bbe0164425..b486cbec492b 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3287,6 +3287,12 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device fs_info->csums_per_leaf = BTRFS_MAX_ITEM_SIZE(fs_info) / fs_info->csum_size; fs_info->stripesize = stripesize; + /* + * Handle the space caching options appropriately now that we have the + * super loaded and validated. + */ + btrfs_set_free_space_cache_settings(fs_info); + ret = btrfs_parse_options(fs_info, options, sb->s_flags); if (ret) goto fail_alloc; @@ -3298,17 +3304,6 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device if (sectorsize < PAGE_SIZE) { struct btrfs_subpage_info *subpage_info; - /* - * V1 space cache has some hardcoded PAGE_SIZE usage, and is - * going to be deprecated. - * - * Force to use v2 cache for subpage case. - */ - btrfs_clear_opt(fs_info->mount_opt, SPACE_CACHE); - btrfs_set_and_info(fs_info, FREE_SPACE_TREE, - "forcing free space tree for sector size %u with page size %lu", - sectorsize, PAGE_SIZE); - btrfs_warn(fs_info, "read-write for sector size %u with page size %lu is experimental", sectorsize, PAGE_SIZE); diff --git a/fs/btrfs/free-space-cache.h b/fs/btrfs/free-space-cache.h index 33b4da3271b1..dd0ed730fa7b 100644 --- a/fs/btrfs/free-space-cache.h +++ b/fs/btrfs/free-space-cache.h @@ -152,6 +152,7 @@ int btrfs_trim_block_group_bitmaps(struct btrfs_block_group *block_group, bool btrfs_free_space_cache_v1_active(struct btrfs_fs_info *fs_info); int btrfs_set_free_space_cache_v1_active(struct btrfs_fs_info *fs_info, bool active); + /* Support functions for running our sanity tests */ #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS int test_add_free_space_entry(struct btrfs_block_group *cache, diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 639601d346d0..aef7e67538a3 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -266,6 +266,31 @@ static bool check_options(struct btrfs_fs_info *info, unsigned long flags) return true; } +void btrfs_set_free_space_cache_settings(struct btrfs_fs_info *fs_info) +{ + if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) + btrfs_set_opt(fs_info->mount_opt, FREE_SPACE_TREE); + else if (btrfs_free_space_cache_v1_active(fs_info)) { + if (btrfs_is_zoned(fs_info)) { + btrfs_info(fs_info, + "zoned: clearing existing space cache"); + btrfs_set_super_cache_generation(fs_info->super_copy, 0); + } else { + btrfs_set_opt(fs_info->mount_opt, SPACE_CACHE); + } + } + + if (fs_info->sectorsize < PAGE_SIZE) { + btrfs_clear_opt(fs_info->mount_opt, SPACE_CACHE); + if (!btrfs_test_opt(fs_info, FREE_SPACE_TREE)) { + btrfs_info(fs_info, + "forcing free space tree for sector size %u with page size %lu", + fs_info->sectorsize, PAGE_SIZE); + btrfs_set_opt(fs_info->mount_opt, FREE_SPACE_TREE); + } + } +} + static int parse_rescue_options(struct btrfs_fs_info *info, const char *options) { char *opts; @@ -345,18 +370,6 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, bool saved_compress_force; int no_compress = 0; - if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE)) - btrfs_set_opt(info->mount_opt, FREE_SPACE_TREE); - else if (btrfs_free_space_cache_v1_active(info)) { - if (btrfs_is_zoned(info)) { - btrfs_info(info, - "zoned: clearing existing space cache"); - btrfs_set_super_cache_generation(info->super_copy, 0); - } else { - btrfs_set_opt(info->mount_opt, SPACE_CACHE); - } - } - /* * Even the options are empty, we still need to do extra check * against new flags @@ -649,8 +662,13 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, * compat_ro(FREE_SPACE_TREE) set, and we aren't going * to allow v1 to be set for extent tree v2, simply * ignore this setting if we're extent tree v2. + * + * For subpage blocksize we don't allow space cache v1, + * and we'll turn on v2, so we can skip the settings + * here as well. */ - if (btrfs_fs_incompat(info, EXTENT_TREE_V2)) + if (btrfs_fs_incompat(info, EXTENT_TREE_V2) || + info->sectorsize < PAGE_SIZE) break; if (token == Opt_space_cache || strcmp(args[0].from, "v1") == 0) { diff --git a/fs/btrfs/super.h b/fs/btrfs/super.h index 8dbb909b364f..7c1cd7527e76 100644 --- a/fs/btrfs/super.h +++ b/fs/btrfs/super.h @@ -8,6 +8,7 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, int btrfs_sync_fs(struct super_block *sb, int wait); char *btrfs_get_subvol_name_from_objectid(struct btrfs_fs_info *fs_info, u64 subvol_objectid); +void btrfs_set_free_space_cache_settings(struct btrfs_fs_info *fs_info); static inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb) { From patchwork Mon Nov 6 22:08:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13447530 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9425C4167D for ; Mon, 6 Nov 2023 22:08:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233225AbjKFWIr (ORCPT ); Mon, 6 Nov 2023 17:08:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233222AbjKFWIq (ORCPT ); Mon, 6 Nov 2023 17:08:46 -0500 Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF3B1D75 for ; Mon, 6 Nov 2023 14:08:41 -0800 (PST) Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-6ce37d0f1a9so3168422a34.0 for ; Mon, 06 Nov 2023 14:08:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1699308521; x=1699913321; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=E6T94WyWk3Zy26jisioKXt/NF7e6EzHgDufMAJz5NuM=; b=hW7JSU2XPVE4h7T/hFb2gkLHehvl63D14CVeDZO4QdfPvaLUGh2U1DE8RnD2NC9Arz fNuMA45/uOZkklxeocim24ngD7RsxIQYaSFGLmnLI3Zvx6qlzn2Kn0DjVNOt6+tc8q05 i2SrbkLYA+JGq/bFMXCr3gE+AOp4TizT7K0zMA3qBV0i5JgKTaOE49gvlVk/puVVrRo+ MEP08tZaAb5fC1q4gOUCQtZ5tr4BH0e9knsDf/UlVeQxC69xkBieT8pVDq9VfDzcgpkk SW9OT5Izesk4Kb2kxHtIehkOFWHOL1eKg+ipAdHgOv+GqiOFpYZ5MxRW5Mqr1cDQgT8y YBvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699308521; x=1699913321; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E6T94WyWk3Zy26jisioKXt/NF7e6EzHgDufMAJz5NuM=; b=fyUMZ/B/kWjQt+W5ChA+/l69wACBIGtg9/2eSY5CvRJpc11C6xXl0+UDHr4B6UezOP 2k25VPepI+N98BsxruQ2RszU7VH/GwlxSXCllUUe2ahu9dvRIBfR/MY8870d9AgtQU09 aML//xpT8T1MrDenU6wk4rBogxZ0GYxADauWHbBvlek2fsjLL8Qclyy1Er+DbSAz7TY7 7PQfTCNlJgC9UeH7EHp4SoDigBbralSEA0eGd+4+BTlFGeDA8lKBXqLeHeQ+gzligRXB eSrWRGfUrqnDkOIzLsjjc6aibYiiJNpxegmf/1IZXyI8hGMgmq8MyFRifBkMOaZ1Y3Pb D0Yg== X-Gm-Message-State: AOJu0YyBvj85Ki5Q0Anlbm1O5+H7WJotKH5o7nfIt/nFWqjjZlQuuwmU JGUgkOhYqmb4ehfpMM6EiUi8ShQjYXdfrkApMpQ1Yw== X-Google-Smtp-Source: AGHT+IFf5q3nHxRPUyYMj7n7bYDMtzLSSCOnnSKvWN4mZIj4cNKJ6+P4Po20QjIkN/mV2dU1uu3A/Q== X-Received: by 2002:a05:6830:438a:b0:6d3:165d:f19c with SMTP id s10-20020a056830438a00b006d3165df19cmr24314205otv.11.1699308520924; Mon, 06 Nov 2023 14:08:40 -0800 (PST) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id d18-20020a05622a15d200b0041e211c5d0bsm3772506qty.6.2023.11.06.14.08.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:08:40 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, linux-fsdevel@vger.kernel.org, brauner@kernel.org Subject: [PATCH 05/18] btrfs: do not allow free space tree rebuild on extent tree v2 Date: Mon, 6 Nov 2023 17:08:13 -0500 Message-ID: <2d268c17698104d5ae0b1d355a10ff20223b2bff.1699308010.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We currently don't allow these options to be set if we're extent tree v2 via the mount option parsing. However when we switch to the new mount API we'll no longer have the super block loaded, so won't be able to make this distinction at mount option parsing time. Address this by checking for extent tree v2 at the point where we make the decision to rebuild the free space tree. Signed-off-by: Josef Bacik --- fs/btrfs/disk-io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index b486cbec492b..072c45811c41 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2951,7 +2951,8 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info) bool rebuild_free_space_tree = false; if (btrfs_test_opt(fs_info, CLEAR_CACHE) && - btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { + btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE) && + !btrfs_fs_incompat(fs_info, EXTENT_TREE_V2)) { rebuild_free_space_tree = true; } else if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE) && !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE_VALID)) { From patchwork Mon Nov 6 22:08:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13447533 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 690FAC41535 for ; Mon, 6 Nov 2023 22:08:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233233AbjKFWIt (ORCPT ); Mon, 6 Nov 2023 17:08:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233226AbjKFWIr (ORCPT ); Mon, 6 Nov 2023 17:08:47 -0500 Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C63CD79 for ; Mon, 6 Nov 2023 14:08:43 -0800 (PST) Received: by mail-qk1-x72c.google.com with SMTP id af79cd13be357-7789cc5c8ccso412127185a.0 for ; Mon, 06 Nov 2023 14:08:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1699308522; x=1699913322; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=VYeMWvEhu1+Bmp78UF8eSUChUBLQrH7aUCmO3SKML2c=; b=MW+Mb155zOw+0cfixLVspOpoaLIb4UbRBHkPs+0z5hRPKlkqe2efirqaYvt5lFNGs+ vHj2+XM//Gzy9CvXSGH7l2W5X9PDNojWn6LB4LauJVRWsaUXLVJEqwrwLr+kUAa1MN3t +U0czTlKqwK1GSULRt4a+a1R1XjgY5H3auZZZQusIGToATaY9tnGnL+aIBJWlkB1XmxQ 4pn0YDmzvtEFWkJMr+KCMjDogJSZURP9NvubIdHCw/eDxzYM6NaU7u6nLdGDQJnkp4qA jamd+lePZ3/5Yg//8fQopQd/sjAJ6hHItnXtqJlpLRWbCu7IrsNOcIz28bgVITppL5QE i4Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699308522; x=1699913322; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VYeMWvEhu1+Bmp78UF8eSUChUBLQrH7aUCmO3SKML2c=; b=Si9zUMu7pScjsdbMC6HzFVj29cxDYSy5piwiUgdC3r6qC+nFR13bU2DzIyfbDPA7nF rYUxvabypimz86OIzaujK6X654f1gsaFK8M0JaP06C5iDssJdcoHayZdEud6CCM9AMK0 4+h260XzXz++WZmbXRNmF59+cfvBMt9d56WpUD0F2/y+UuB3Ulh6+qs3nyQmhqQF6FhZ wHpGcIbtvkgPphaowGvdl+HlfkAVq1qJ2c5owejt/coY+D0EksMd2yzeu5OHqRkWgVB7 moQw9zIQvjJ7OcMTW5lubUXThJfqPLwLwWgsbDwOKDth4lCBfCDXSGtUXfwyOJpQwKzE JvNQ== X-Gm-Message-State: AOJu0YyZ2xHN+grT/FyLnhBpJadRCPycTje98OWe7dqHDHdLJE9p1Bn6 iH9gdqJcKwju1CRSvtI1jDnnvuQC3QtYmMO1xSxb/Q== X-Google-Smtp-Source: AGHT+IGgX0TZ/9pOIeWUrKZ9XwtYnPoo5FhIp7tFj2JSSmR6IMbGf4K1sZ1sW1noBTkEpzBa0Vk3Sw== X-Received: by 2002:a05:620a:bd6:b0:76f:5b9:3f29 with SMTP id s22-20020a05620a0bd600b0076f05b93f29mr1397960qki.2.1699308522116; Mon, 06 Nov 2023 14:08:42 -0800 (PST) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id g11-20020ae9e10b000000b0077a7d02cffbsm2365510qkm.24.2023.11.06.14.08.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:08:41 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, linux-fsdevel@vger.kernel.org, brauner@kernel.org Subject: [PATCH 06/18] btrfs: split out ro->rw and rw->ro helpers into their own functions Date: Mon, 6 Nov 2023 17:08:14 -0500 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When we remount ro->rw or rw->ro we have some cleanup tasks that have to be managed. Split these out into their own function to make btrfs_remount smaller. Signed-off-by: Josef Bacik --- fs/btrfs/super.c | 233 ++++++++++++++++++++++++----------------------- 1 file changed, 120 insertions(+), 113 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index aef7e67538a3..d7070269e3ea 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1659,6 +1659,119 @@ static inline void btrfs_remount_cleanup(struct btrfs_fs_info *fs_info, btrfs_set_free_space_cache_v1_active(fs_info, cache_opt); } +static int btrfs_remount_rw(struct btrfs_fs_info *fs_info) +{ + int ret; + + if (BTRFS_FS_ERROR(fs_info)) { + btrfs_err(fs_info, + "Remounting read-write after error is not allowed"); + return -EINVAL; + } + + if (fs_info->fs_devices->rw_devices == 0) + return -EACCES; + + if (!btrfs_check_rw_degradable(fs_info, NULL)) { + btrfs_warn(fs_info, + "too many missing devices, writable remount is not allowed"); + return -EACCES; + } + + if (btrfs_super_log_root(fs_info->super_copy) != 0) { + btrfs_warn(fs_info, + "mount required to replay tree-log, cannot remount read-write"); + return -EINVAL; + } + + /* + * NOTE: when remounting with a change that does writes, don't put it + * anywhere above this point, as we are not sure to be safe to write + * until we pass the above checks. + */ + ret = btrfs_start_pre_rw_mount(fs_info); + if (ret) + return ret; + + btrfs_clear_sb_rdonly(fs_info->sb); + + set_bit(BTRFS_FS_OPEN, &fs_info->flags); + + /* + * If we've gone from readonly -> read/write, we need to get our + * sync/async discard lists in the right state. + */ + btrfs_discard_resume(fs_info); + + return 0; +} + +static int btrfs_remount_ro(struct btrfs_fs_info *fs_info) +{ + /* + * this also happens on 'umount -rf' or on shutdown, when + * the filesystem is busy. + */ + cancel_work_sync(&fs_info->async_reclaim_work); + cancel_work_sync(&fs_info->async_data_reclaim_work); + + btrfs_discard_cleanup(fs_info); + + /* wait for the uuid_scan task to finish */ + down(&fs_info->uuid_tree_rescan_sem); + /* avoid complains from lockdep et al. */ + up(&fs_info->uuid_tree_rescan_sem); + + btrfs_set_sb_rdonly(fs_info->sb); + + /* + * Setting SB_RDONLY will put the cleaner thread to + * sleep at the next loop if it's already active. + * If it's already asleep, we'll leave unused block + * groups on disk until we're mounted read-write again + * unless we clean them up here. + */ + btrfs_delete_unused_bgs(fs_info); + + /* + * The cleaner task could be already running before we set the + * flag BTRFS_FS_STATE_RO (and SB_RDONLY in the superblock). + * We must make sure that after we finish the remount, i.e. after + * we call btrfs_commit_super(), the cleaner can no longer start + * a transaction - either because it was dropping a dead root, + * running delayed iputs or deleting an unused block group (the + * cleaner picked a block group from the list of unused block + * groups before we were able to in the previous call to + * btrfs_delete_unused_bgs()). + */ + wait_on_bit(&fs_info->flags, BTRFS_FS_CLEANER_RUNNING, + TASK_UNINTERRUPTIBLE); + + /* + * We've set the superblock to RO mode, so we might have made + * the cleaner task sleep without running all pending delayed + * iputs. Go through all the delayed iputs here, so that if an + * unmount happens without remounting RW we don't end up at + * finishing close_ctree() with a non-empty list of delayed + * iputs. + */ + btrfs_run_delayed_iputs(fs_info); + + btrfs_dev_replace_suspend_for_unmount(fs_info); + btrfs_scrub_cancel(fs_info); + btrfs_pause_balance(fs_info); + + /* + * Pause the qgroup rescan worker if it is running. We don't want + * it to be still running after we are in RO mode, as after that, + * by the time we unmount, it might have left a transaction open, + * so we would leak the transaction and/or crash. + */ + btrfs_qgroup_wait_for_completion(fs_info, false); + + return btrfs_commit_super(fs_info); +} + static int btrfs_remount(struct super_block *sb, int *flags, char *data) { struct btrfs_fs_info *fs_info = btrfs_sb(sb); @@ -1712,120 +1825,14 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data) } } - if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb)) - goto out; + ret = 0; + if (!sb_rdonly(sb) && (*flags & SB_RDONLY)) + ret = btrfs_remount_ro(fs_info); + else if (sb_rdonly(sb) && !(*flags & SB_RDONLY)) + ret = btrfs_remount_rw(fs_info); + if (ret) + goto restore; - if (*flags & SB_RDONLY) { - /* - * this also happens on 'umount -rf' or on shutdown, when - * the filesystem is busy. - */ - cancel_work_sync(&fs_info->async_reclaim_work); - cancel_work_sync(&fs_info->async_data_reclaim_work); - - btrfs_discard_cleanup(fs_info); - - /* wait for the uuid_scan task to finish */ - down(&fs_info->uuid_tree_rescan_sem); - /* avoid complains from lockdep et al. */ - up(&fs_info->uuid_tree_rescan_sem); - - btrfs_set_sb_rdonly(sb); - - /* - * Setting SB_RDONLY will put the cleaner thread to - * sleep at the next loop if it's already active. - * If it's already asleep, we'll leave unused block - * groups on disk until we're mounted read-write again - * unless we clean them up here. - */ - btrfs_delete_unused_bgs(fs_info); - - /* - * The cleaner task could be already running before we set the - * flag BTRFS_FS_STATE_RO (and SB_RDONLY in the superblock). - * We must make sure that after we finish the remount, i.e. after - * we call btrfs_commit_super(), the cleaner can no longer start - * a transaction - either because it was dropping a dead root, - * running delayed iputs or deleting an unused block group (the - * cleaner picked a block group from the list of unused block - * groups before we were able to in the previous call to - * btrfs_delete_unused_bgs()). - */ - wait_on_bit(&fs_info->flags, BTRFS_FS_CLEANER_RUNNING, - TASK_UNINTERRUPTIBLE); - - /* - * We've set the superblock to RO mode, so we might have made - * the cleaner task sleep without running all pending delayed - * iputs. Go through all the delayed iputs here, so that if an - * unmount happens without remounting RW we don't end up at - * finishing close_ctree() with a non-empty list of delayed - * iputs. - */ - btrfs_run_delayed_iputs(fs_info); - - btrfs_dev_replace_suspend_for_unmount(fs_info); - btrfs_scrub_cancel(fs_info); - btrfs_pause_balance(fs_info); - - /* - * Pause the qgroup rescan worker if it is running. We don't want - * it to be still running after we are in RO mode, as after that, - * by the time we unmount, it might have left a transaction open, - * so we would leak the transaction and/or crash. - */ - btrfs_qgroup_wait_for_completion(fs_info, false); - - ret = btrfs_commit_super(fs_info); - if (ret) - goto restore; - } else { - if (BTRFS_FS_ERROR(fs_info)) { - btrfs_err(fs_info, - "Remounting read-write after error is not allowed"); - ret = -EINVAL; - goto restore; - } - if (fs_info->fs_devices->rw_devices == 0) { - ret = -EACCES; - goto restore; - } - - if (!btrfs_check_rw_degradable(fs_info, NULL)) { - btrfs_warn(fs_info, - "too many missing devices, writable remount is not allowed"); - ret = -EACCES; - goto restore; - } - - if (btrfs_super_log_root(fs_info->super_copy) != 0) { - btrfs_warn(fs_info, - "mount required to replay tree-log, cannot remount read-write"); - ret = -EINVAL; - goto restore; - } - - /* - * NOTE: when remounting with a change that does writes, don't - * put it anywhere above this point, as we are not sure to be - * safe to write until we pass the above checks. - */ - ret = btrfs_start_pre_rw_mount(fs_info); - if (ret) - goto restore; - - btrfs_clear_sb_rdonly(sb); - - set_bit(BTRFS_FS_OPEN, &fs_info->flags); - - /* - * If we've gone from readonly -> read/write, we need to get - * our sync/async discard lists in the right state. - */ - btrfs_discard_resume(fs_info); - } -out: /* * We need to set SB_I_VERSION here otherwise it'll get cleared by VFS, * since the absence of the flag means it can be toggled off by remount. From patchwork Mon Nov 6 22:08:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13447531 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E195EC0018A for ; Mon, 6 Nov 2023 22:08:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233216AbjKFWIs (ORCPT ); Mon, 6 Nov 2023 17:08:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233227AbjKFWIq (ORCPT ); Mon, 6 Nov 2023 17:08:46 -0500 Received: from mail-vk1-xa2d.google.com (mail-vk1-xa2d.google.com [IPv6:2607:f8b0:4864:20::a2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22F0710C1 for ; Mon, 6 Nov 2023 14:08:44 -0800 (PST) Received: by mail-vk1-xa2d.google.com with SMTP id 71dfb90a1353d-4ac28cab4efso881404e0c.0 for ; Mon, 06 Nov 2023 14:08:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1699308523; x=1699913323; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Qn4wfDb6jDre0GFiLqI3t3dfv/iDXvlKvBWKVyZYNgA=; b=ysTkbHTU8iID+jD5wYajxXB1YHDYloGiFBgfOiB7r0byuSyXPAzdEfi/oUDV8UyB5S 3SgqrJXiNJ5VkAY/LC8eFo9E7/33+Qd3zAeZXrw23NpK20WUNT5Q9+qNVB11iGcpGkOB FtP02TbLWojHGW8cRdlgENI+2q32QA6ZlxjtQEPJOe6m5wxjzv0sBubS3jFub8Vjpbm2 aGdTu9HuDSycDvERVVzkCRNVuGefZtQfY7sC+bNz/3pzIxjHEFKlivmCBpcmZscN6bIQ bmP8BXLgNlicVA2+WS6x0mbmR6F1XQcQZmlwe2ojELzTdGZvg77Fb1nqvZYnp569kE9X aDAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699308523; x=1699913323; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Qn4wfDb6jDre0GFiLqI3t3dfv/iDXvlKvBWKVyZYNgA=; b=MIqAL7UyAvE057cBlDKPs195CCNV3+oNSbzdE5ZXzv9ZwatSfBK16ppV84PxRyqU+u qVl8ZsRVIEeZHD3Yp6cSy4+2/37U+3xy6mqipRJJSiWzDL2Kj9cHWJ+XrNywLViES2qH uLeDNJBjGtPG18FaL3vpIduGIUZ9r+cnA8OhbuGpW24QW8f8TeWNBrg2bc6g5RB3Vwgk q91gTgjelsjZAMF8kE+PT8w9mIDDPyuXckfK3dYGAB4fwT1mSjA8lanIg/nanv6IDiXs aEgPuODfTJ7FGqV1WKzCEjcMuJ67cL6nXdfEmzBeJfJUNH2JyF3vITJWzI6GbCLH366d aUTQ== X-Gm-Message-State: AOJu0YzOu9VnAUivHQ3KxGPHjUx5qSkY71cbDODhTpn25GGXMhFapN4Q R+GNjgE+kiccw8pzfvopGHHp2/PB4RUCRHmlphR/pw== X-Google-Smtp-Source: AGHT+IGzjDwWUkB8LX7DQ7zorH80M40pkRDuP9BnGAXmsOru2oCKSePCo909yhMYibpvOivXGd/7UQ== X-Received: by 2002:a1f:2c15:0:b0:49e:2145:1651 with SMTP id s21-20020a1f2c15000000b0049e21451651mr26913118vks.6.1699308523102; Mon, 06 Nov 2023 14:08:43 -0800 (PST) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id df1-20020a05622a0ec100b00403cce833eesm3744457qtb.27.2023.11.06.14.08.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:08:42 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, linux-fsdevel@vger.kernel.org, brauner@kernel.org Subject: [PATCH 07/18] btrfs: add a NOSPACECACHE mount option flag Date: Mon, 6 Nov 2023 17:08:15 -0500 Message-ID: <7723acf40642ab84b48f25f31e2894120d035b5d.1699308010.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org With the old mount API we'd pre-populate the mount options with the space cache settings of the file system, and then the user toggled them on or off with the mount options. When we switch to the new mount API the mount options will be set before we get into opening the file system, so we need a flag to indicate that the user explicitly asked for -o nospace_cache so we can make the appropriate changes after the fact. Signed-off-by: Josef Bacik --- fs/btrfs/disk-io.c | 1 + fs/btrfs/fs.h | 1 + 2 files changed, 2 insertions(+) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 072c45811c41..c70e507a28d0 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2938,6 +2938,7 @@ void btrfs_clear_oneshot_options(struct btrfs_fs_info *fs_info) { btrfs_clear_opt(fs_info->mount_opt, USEBACKUPROOT); btrfs_clear_opt(fs_info->mount_opt, CLEAR_CACHE); + btrfs_clear_opt(fs_info->mount_opt, NOSPACECACHE); } /* diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index 318df6f9d9cb..ecfa13a9c2cf 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -188,6 +188,7 @@ enum { BTRFS_MOUNT_IGNOREBADROOTS = (1UL << 27), BTRFS_MOUNT_IGNOREDATACSUMS = (1UL << 28), BTRFS_MOUNT_NODISCARD = (1UL << 29), + BTRFS_MOUNT_NOSPACECACHE = (1UL << 30), }; /* From patchwork Mon Nov 6 22:08:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13447534 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E513AC001B5 for ; Mon, 6 Nov 2023 22:08:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233234AbjKFWIu (ORCPT ); Mon, 6 Nov 2023 17:08:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233232AbjKFWIs (ORCPT ); Mon, 6 Nov 2023 17:08:48 -0500 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EE34D75 for ; Mon, 6 Nov 2023 14:08:45 -0800 (PST) Received: by mail-qk1-x730.google.com with SMTP id af79cd13be357-778a6c440faso258527885a.3 for ; Mon, 06 Nov 2023 14:08:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1699308524; x=1699913324; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Qi9EDPpqsP1S+XlZ8gl3BYRn+cxn6q4J+q4swfwHv2I=; b=1g7H7GtrZ9mm41v3RmDCdjUIvd/CMTTYIF/68OYqF8p9wWjddWfyA9JHRYxPOgo5qd kv7f5n7KRUNSlZfM51DLxGYx0/j7NLyakDoLwHvfEIGGCgpJWBHGVuHyGMEBwd+vC7uw Utj8cpVDsQ/2Y619rghIcOKgW37WdhBvLSgqeoqxgUsNNS409MwjZy9faUtvxRSnQ3PE DBjzNlSuQ7winLJqu/SsCUZUbA+k3gg7gz6xihdHoNfL5U03APu7Vxogk5v6pTidulfg ZWine5WZS25BuRl2VZODB749Z/uYaGFb4ZRZUjutB1FNK9JziE7y7VmLNMj8NTHxxU/F NhlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699308524; x=1699913324; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Qi9EDPpqsP1S+XlZ8gl3BYRn+cxn6q4J+q4swfwHv2I=; b=RjOa37xpfJe8tpwaZUxYA/s5jFFiN/xI/4C76oIRq9XzF3PN9n7b9XF2r4z44lGt3F Tbm+3UNYPyKbZnJhM02NT4E3Ox0uuqz2D03gvGVyFduR4RiND5d/8lSbaalVy1q8h8l1 17j6HEaCaSTOFISmtGNODFvb5Ka3ttEEM467NjNAZCKcRbGxTU9Rb2451CprmOhpEK1n EotKvaVNBCzQDm1YvSnASRvmr4sKzdbDhegRfHzbKSKlpFepeDQ3yslwO+tq/c+2F0z5 GB61JHLIH/5iVT6+FlobiuxJlcpZLnp/JUUHTchklMijfFKxFtgll18s7xDBwbzY35dg GwiA== X-Gm-Message-State: AOJu0YzNZliAp6XaNCBbvySd6H9e4I5+unqcj1RmpviXNBXNXL9AaDqr WhrdLSoNLEUFgCbjj5dBT8WL/hGFCN0qV4f+eIKsBA== X-Google-Smtp-Source: AGHT+IFPiDb7JWisYnS006hixYyoYr8loyt9iXIWTDKC1Q9M+sYaNa6Us9AC6cgYW9NSl0YLlbyKDA== X-Received: by 2002:ad4:5ca1:0:b0:66d:6af7:4571 with SMTP id q1-20020ad45ca1000000b0066d6af74571mr32971369qvh.17.1699308524086; Mon, 06 Nov 2023 14:08:44 -0800 (PST) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id c10-20020a0cfb0a000000b0065af9d1203dsm3809217qvp.121.2023.11.06.14.08.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:08:43 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, linux-fsdevel@vger.kernel.org, brauner@kernel.org Subject: [PATCH 08/18] btrfs: add fs_parameter definitions Date: Mon, 6 Nov 2023 17:08:16 -0500 Message-ID: <9d0173eef0e37f321da8945cfcfa7d5c923280c3.1699308010.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In order to convert to the new mount api we have to change how we do the mount option parsing. For now we're going to duplicate these helpers to make it easier to follow, and then remove the old code once everything is in place. This patch contains the re-definiton of all of our mount options into the new fs_parameter_spec format. Signed-off-by: Josef Bacik --- fs/btrfs/super.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 127 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index d7070269e3ea..0e9cb9ed6508 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "messages.h" #include "delayed-inode.h" #include "ctree.h" @@ -132,7 +133,7 @@ enum { /* Debugging options */ Opt_enospc_debug, Opt_noenospc_debug, #ifdef CONFIG_BTRFS_DEBUG - Opt_fragment_data, Opt_fragment_metadata, Opt_fragment_all, + Opt_fragment, Opt_fragment_data, Opt_fragment_metadata, Opt_fragment_all, #endif #ifdef CONFIG_BTRFS_FS_REF_VERIFY Opt_ref_verify, @@ -222,6 +223,131 @@ static const match_table_t rescue_tokens = { {Opt_err, NULL}, }; +enum { + Opt_fatal_errors_panic, + Opt_fatal_errors_bug, +}; + +static const struct constant_table btrfs_parameter_fatal_errors[] = { + { "panic", Opt_fatal_errors_panic }, + { "bug", Opt_fatal_errors_bug }, + {} +}; + +enum { + Opt_discard_sync, + Opt_discard_async, +}; + +static const struct constant_table btrfs_parameter_discard[] = { + { "sync", Opt_discard_sync }, + { "async", Opt_discard_async }, + {} +}; + +enum { + Opt_space_cache_v1, + Opt_space_cache_v2, +}; + +static const struct constant_table btrfs_parameter_space_cache[] = { + { "v1", Opt_space_cache_v1 }, + { "v2", Opt_space_cache_v2 }, + {} +}; + +enum { + Opt_rescue_usebackuproot, + Opt_rescue_nologreplay, + Opt_rescue_ignorebadroots, + Opt_rescue_ignoredatacsums, + Opt_rescue_parameter_all, +}; + +static const struct constant_table btrfs_parameter_rescue[] = { + { "usebackuproot", Opt_rescue_usebackuproot }, + { "nologreplay", Opt_rescue_nologreplay }, + { "ignorebadroots", Opt_rescue_ignorebadroots }, + { "ibadroots", Opt_rescue_ignorebadroots }, + { "ignoredatacsums", Opt_rescue_ignoredatacsums }, + { "idatacsums", Opt_rescue_ignoredatacsums }, + { "all", Opt_rescue_parameter_all }, + {} +}; + +#ifdef CONFIG_BTRFS_DEBUG +enum { + Opt_fragment_parameter_data, + Opt_fragment_parameter_metadata, + Opt_fragment_parameter_all, +}; + +static const struct constant_table btrfs_parameter_fragment[] = { + { "data", Opt_fragment_parameter_data }, + { "metadata", Opt_fragment_parameter_metadata }, + { "all", Opt_fragment_parameter_all }, + {} +}; +#endif + +static const struct fs_parameter_spec btrfs_fs_parameters[] __maybe_unused = { + fsparam_flag_no("acl", Opt_acl), + fsparam_flag("clear_cache", Opt_clear_cache), + fsparam_u32("commit", Opt_commit_interval), + fsparam_flag("compress", Opt_compress), + fsparam_string("compress", Opt_compress_type), + fsparam_flag("compress-force", Opt_compress_force), + fsparam_string("compress-force", Opt_compress_force_type), + fsparam_flag("degraded", Opt_degraded), + fsparam_string("device", Opt_device), + fsparam_enum("fatal_errors", Opt_fatal_errors, btrfs_parameter_fatal_errors), + fsparam_flag_no("flushoncommit", Opt_flushoncommit), + fsparam_flag_no("inode_cache", Opt_inode_cache), + fsparam_string("max_inline", Opt_max_inline), + fsparam_flag_no("barrier", Opt_barrier), + fsparam_flag_no("datacow", Opt_datacow), + fsparam_flag_no("datasum", Opt_datasum), + fsparam_flag_no("autodefrag", Opt_defrag), + fsparam_flag_no("discard", Opt_discard), + fsparam_enum("discard", Opt_discard_mode, btrfs_parameter_discard), + fsparam_u32("metadata_ratio", Opt_ratio), + fsparam_flag("rescan_uuid_tree", Opt_rescan_uuid_tree), + fsparam_flag("skip_balance", Opt_skip_balance), + fsparam_flag_no("space_cache", Opt_space_cache), + fsparam_enum("space_cache", Opt_space_cache_version, btrfs_parameter_space_cache), + fsparam_flag_no("ssd", Opt_ssd), + fsparam_flag_no("ssd_spread", Opt_ssd_spread), + fsparam_string("subvol", Opt_subvol), + fsparam_flag("subvol=", Opt_subvol_empty), + fsparam_u64("subvolid", Opt_subvolid), + fsparam_u32("thread_pool", Opt_thread_pool), + fsparam_flag_no("treelog", Opt_treelog), + fsparam_flag("user_subvol_rm_allowed", Opt_user_subvol_rm_allowed), + + /* Rescue options */ + fsparam_enum("rescue", Opt_rescue, btrfs_parameter_rescue), + /* Deprecated, with alias rescue=nologreplay */ + __fsparam(NULL, "nologreplay", Opt_nologreplay, fs_param_deprecated, + NULL), + /* Deprecated, with alias rescue=usebackuproot */ + __fsparam(NULL, "usebackuproot", Opt_usebackuproot, fs_param_deprecated, + NULL), + + /* Deprecated options */ + __fsparam(NULL, "recovery", Opt_recovery, + fs_param_neg_with_no|fs_param_deprecated, NULL), + + /* Debugging options */ + fsparam_flag_no("enospc_debug", Opt_enospc_debug), +#ifdef CONFIG_BTRFS_DEBUG + fsparam_enum("fragment", Opt_fragment, btrfs_parameter_fragment), +#endif +#ifdef CONFIG_BTRFS_FS_REF_VERIFY + fsparam_flag("ref_verify", Opt_ref_verify), +#endif + {} +}; + static bool check_ro_option(struct btrfs_fs_info *fs_info, unsigned long opt, const char *opt_name) { From patchwork Mon Nov 6 22:08:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13447536 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 685E2C4332F for ; Mon, 6 Nov 2023 22:08:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233241AbjKFWIw (ORCPT ); Mon, 6 Nov 2023 17:08:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233236AbjKFWIu (ORCPT ); Mon, 6 Nov 2023 17:08:50 -0500 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D474D73 for ; Mon, 6 Nov 2023 14:08:46 -0800 (PST) Received: by mail-qt1-x831.google.com with SMTP id d75a77b69052e-41eae4ebf61so16499561cf.2 for ; Mon, 06 Nov 2023 14:08:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1699308525; x=1699913325; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=C5SliX57b9MACNLz5ICByCPFC2gtVAeXiFu0pB+tFk0=; b=gWpAN9MAflQpmHx3WQgaghCwbbiEellCj0x4h/UCp5FE5IJNR1x7DggmwZ55RbOXIY DFF4bJxA7fX3uv/koC+bE3GNFxRc3ExhZMvZG5kUczLOqO3fqi4Jl461C2UtawIeiPwo 1WQoCJcKmrerDZh6Qr9xaxaoDtjMDMYCzIvyXCTClu/amAzr5GDH/Ysfcr2Hwvk5LKEx yPwowoHitjtFUdKZBRvzOsgwinjwCtBr0+JEo20nUi5dUL+cPqdRzXIjGksMsha4zpEF 54ec+AdNYPgb6F8L/d9OkGi6A4hJdvVhzD09AOapMeayLS/VIZjX23K2r5lv4CCklYnx BPsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699308525; x=1699913325; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C5SliX57b9MACNLz5ICByCPFC2gtVAeXiFu0pB+tFk0=; b=AUEksH0xl3IGqmoQSXE8Mut073izSq5TM2vmFUW00EnWW4ELijRBTLbesboB4oeOAL MNITEeR+PXm9nsxIHlXnFZ3mWOGTmDfcnuJMdhDzA8p71W6dWT0jTp5zX+qDT0gYxNQy hLHvBkti51Bruo6UmY+ZSt5CSRCom5+wzD0RipjkuRxRPxjs5w+myXtL6Z4Z8et+U2ae ZWmVJthc+lLQF0Y6AB8v8gNm5SFu205I0k0m7vjRUyMvcc04FOJckkJd94tQ0QnLXmaQ sERLsWiEQ1UJNCtTIfmJ/7/Hmvp+FDe3sjNjlfVuMlOWBn8i1SfdcgGhdAaWwPZwg2Lh JHwA== X-Gm-Message-State: AOJu0YyJk0JwwMqG+d+G68/s7O6wI/Mm/bLsv0KpDxENWlqa+wpooowk QY6uOTOw4QChEa1nTGlDxA741lQKO39oXfLRA+fV8w== X-Google-Smtp-Source: AGHT+IHBUo+AWhsssjy5WDDxtA+UmEeNdDlJASWNtzBQRX/hg6hxusZhNSh70PAiOyeK2o+5tmO+rw== X-Received: by 2002:a05:622a:41:b0:41c:e92a:c611 with SMTP id y1-20020a05622a004100b0041ce92ac611mr33603670qtw.38.1699308525165; Mon, 06 Nov 2023 14:08:45 -0800 (PST) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id ku16-20020a05622a0a9000b0041ea59e639bsm2878430qtb.70.2023.11.06.14.08.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:08:44 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, linux-fsdevel@vger.kernel.org, brauner@kernel.org Subject: [PATCH 09/18] btrfs: add parse_param callback for the new mount api Date: Mon, 6 Nov 2023 17:08:17 -0500 Message-ID: <0ed480a27b80538f56d455f4a4c0967c5bc6cc97.1699308010.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The parse_param callback handles one parameter at a time, take our existing mount option parsing loop and adjust it to handle one parameter at a time, and tie it into the fs_context_operations. Create a btrfs_fs_context object that will store the various mount properties, we'll house this in fc->fs_private. This is necessary to separate because remounting will use ->reconfigure, and we'll get a new copy of the parsed parameters, so we can no longer directly mess with the fs_info in this stage. In the future we'll add this to the btrfs_fs_info and update the users to use the new context object instead. Signed-off-by: Josef Bacik --- fs/btrfs/super.c | 390 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 390 insertions(+) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 0e9cb9ed6508..2f7ee78edd11 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -84,6 +84,19 @@ static void btrfs_put_super(struct super_block *sb) close_ctree(btrfs_sb(sb)); } +/* Store the mount options related information. */ +struct btrfs_fs_context { + char *subvol_name; + u64 subvol_objectid; + u64 max_inline; + u32 commit_interval; + u32 metadata_ratio; + u32 thread_pool_size; + unsigned long mount_opt; + unsigned long compress_type:4; + unsigned int compress_level; +}; + enum { Opt_acl, Opt_noacl, Opt_clear_cache, @@ -348,6 +361,379 @@ static const struct fs_parameter_spec btrfs_fs_parameters[] __maybe_unused = { {} }; +static int btrfs_parse_param(struct fs_context *fc, + struct fs_parameter *param) +{ + struct btrfs_fs_context *ctx = fc->fs_private; + struct fs_parse_result result; + int opt; + + opt = fs_parse(fc, btrfs_fs_parameters, param, &result); + if (opt < 0) + return opt; + + switch (opt) { + case Opt_degraded: + btrfs_set_opt(ctx->mount_opt, DEGRADED); + break; + case Opt_subvol_empty: + /* + * This exists because we used to allow it on accident, so we're + * keeping it to maintain ABI. See + * 37becec95ac31b209eb1c8e096f1093a7db00f32. + */ + break; + case Opt_subvol: + kfree(ctx->subvol_name); + ctx->subvol_name = kstrdup(param->string, GFP_KERNEL); + if (!ctx->subvol_name) + return -ENOMEM; + break; + case Opt_subvolid: + ctx->subvol_objectid = result.uint_64; + + /* subvoldi=0 means give me the original fs_tree. */ + if (!ctx->subvol_objectid) + ctx->subvol_objectid = BTRFS_FS_TREE_OBJECTID; + break; + case Opt_device: { + struct btrfs_device *device; + blk_mode_t mode = sb_open_mode(fc->sb_flags); + + mutex_lock(&uuid_mutex); + device = btrfs_scan_one_device(param->string, mode, false); + mutex_unlock(&uuid_mutex); + if (IS_ERR(device)) + return PTR_ERR(device); + break; + } + case Opt_datasum: + if (result.negated) { + btrfs_set_opt(ctx->mount_opt, NODATASUM); + } else { + btrfs_clear_opt(ctx->mount_opt, NODATACOW); + btrfs_clear_opt(ctx->mount_opt, NODATASUM); + } + break; + case Opt_datacow: + if (result.negated) { + btrfs_clear_opt(ctx->mount_opt, COMPRESS); + btrfs_clear_opt(ctx->mount_opt, FORCE_COMPRESS); + btrfs_set_opt(ctx->mount_opt, NODATACOW); + btrfs_set_opt(ctx->mount_opt, NODATASUM); + } else { + btrfs_clear_opt(ctx->mount_opt, NODATACOW); + } + break; + case Opt_compress_force: + case Opt_compress_force_type: + btrfs_set_opt(ctx->mount_opt, FORCE_COMPRESS); + fallthrough; + case Opt_compress: + case Opt_compress_type: + if (opt == Opt_compress || + opt == Opt_compress_force || + strncmp(param->string, "zlib", 4) == 0) { + ctx->compress_type = BTRFS_COMPRESS_ZLIB; + ctx->compress_level = BTRFS_ZLIB_DEFAULT_LEVEL; + /* + * args[0] contains uninitialized data since + * for these tokens we don't expect any + * parameter. + */ + if (opt != Opt_compress && + opt != Opt_compress_force) + ctx->compress_level = + btrfs_compress_str2level( + BTRFS_COMPRESS_ZLIB, + param->string + 4); + btrfs_set_opt(ctx->mount_opt, COMPRESS); + btrfs_clear_opt(ctx->mount_opt, NODATACOW); + btrfs_clear_opt(ctx->mount_opt, NODATASUM); + } else if (strncmp(param->string, "lzo", 3) == 0) { + ctx->compress_type = BTRFS_COMPRESS_LZO; + ctx->compress_level = 0; + btrfs_set_opt(ctx->mount_opt, COMPRESS); + btrfs_clear_opt(ctx->mount_opt, NODATACOW); + btrfs_clear_opt(ctx->mount_opt, NODATASUM); + } else if (strncmp(param->string, "zstd", 4) == 0) { + ctx->compress_type = BTRFS_COMPRESS_ZSTD; + ctx->compress_level = + btrfs_compress_str2level( + BTRFS_COMPRESS_ZSTD, + param->string + 4); + btrfs_set_opt(ctx->mount_opt, COMPRESS); + btrfs_clear_opt(ctx->mount_opt, NODATACOW); + btrfs_clear_opt(ctx->mount_opt, NODATASUM); + } else if (strncmp(param->string, "no", 2) == 0) { + ctx->compress_level = 0; + ctx->compress_type = 0; + btrfs_clear_opt(ctx->mount_opt, COMPRESS); + btrfs_clear_opt(ctx->mount_opt, FORCE_COMPRESS); + } else { + btrfs_err(NULL, "unrecognized compression value %s", + param->string); + return -EINVAL; + } + break; + case Opt_ssd: + if (result.negated) { + btrfs_set_opt(ctx->mount_opt, NOSSD); + btrfs_clear_opt(ctx->mount_opt, SSD); + btrfs_clear_opt(ctx->mount_opt, SSD_SPREAD); + } else { + btrfs_set_opt(ctx->mount_opt, SSD); + btrfs_clear_opt(ctx->mount_opt, NOSSD); + } + break; + case Opt_ssd_spread: + if (result.negated) { + btrfs_clear_opt(ctx->mount_opt, SSD_SPREAD); + } else { + btrfs_set_opt(ctx->mount_opt, SSD); + btrfs_set_opt(ctx->mount_opt, SSD_SPREAD); + btrfs_clear_opt(ctx->mount_opt, NOSSD); + } + break; + case Opt_barrier: + if (result.negated) + btrfs_set_opt(ctx->mount_opt, NOBARRIER); + else + btrfs_clear_opt(ctx->mount_opt, NOBARRIER); + break; + case Opt_thread_pool: + if (result.uint_32 == 0) { + btrfs_err(NULL, "invalid value 0 for thread_pool"); + return -EINVAL; + } + ctx->thread_pool_size = result.uint_32; + break; + case Opt_max_inline: + ctx->max_inline = memparse(param->string, NULL); + break; + case Opt_acl: + if (result.negated) { + fc->sb_flags &= ~SB_POSIXACL; + } else { +#ifdef CONFIG_BTRFS_FS_POSIX_ACL + fc->sb_flags |= SB_POSIXACL; +#else + btrfs_err(NULL, "support for ACL not compiled in!"); + ret = -EINVAL; + goto out; +#endif + } + /* + * VFS limits the ability to toggle ACL on and off via remount, + * despite every file system allowing this. This seems to be an + * oversight since we all do, but it'll fail if we're + * remounting. So don't set the mask here, we'll check it in + * btrfs_reconfigure and do the toggling ourselves. + */ + if (fc->purpose != FS_CONTEXT_FOR_RECONFIGURE) + fc->sb_flags_mask |= SB_POSIXACL; + break; + case Opt_treelog: + if (result.negated) + btrfs_set_opt(ctx->mount_opt, NOTREELOG); + else + btrfs_clear_opt(ctx->mount_opt, NOTREELOG); + break; + case Opt_recovery: + /* + * -o recovery used to be an alias for usebackuproot, and then + * norecovery was an alias for nologreplay, hence the different + * behaviors for negated and not. + */ + if (result.negated) { + btrfs_warn(NULL, + "'norecovery' is deprecated, use 'rescue=nologreplay' instead"); + btrfs_set_opt(ctx->mount_opt, NOLOGREPLAY); + } else { + btrfs_warn(NULL, + "'recovery' is deprecated, use 'rescue=usebackuproot' instead"); + btrfs_set_opt(ctx->mount_opt, USEBACKUPROOT); + } + break; + case Opt_nologreplay: + btrfs_warn(NULL, + "'nologreplay' is deprecated, use 'rescue=nologreplay' instead"); + btrfs_set_opt(ctx->mount_opt, NOLOGREPLAY); + break; + case Opt_flushoncommit: + if (result.negated) + btrfs_clear_opt(ctx->mount_opt, FLUSHONCOMMIT); + else + btrfs_set_opt(ctx->mount_opt, FLUSHONCOMMIT); + break; + case Opt_ratio: + ctx->metadata_ratio = result.uint_32; + break; + case Opt_discard: + if (result.negated) { + btrfs_clear_opt(ctx->mount_opt, DISCARD_SYNC); + btrfs_clear_opt(ctx->mount_opt, DISCARD_ASYNC); + btrfs_set_opt(ctx->mount_opt, NODISCARD); + } else { + btrfs_set_opt(ctx->mount_opt, DISCARD_SYNC); + btrfs_clear_opt(ctx->mount_opt, DISCARD_ASYNC); + } + break; + case Opt_discard_mode: + switch (result.uint_32) { + case Opt_discard_sync: + btrfs_clear_opt(ctx->mount_opt, DISCARD_ASYNC); + btrfs_set_opt(ctx->mount_opt, DISCARD_SYNC); + break; + case Opt_discard_async: + btrfs_clear_opt(ctx->mount_opt, DISCARD_SYNC); + btrfs_set_opt(ctx->mount_opt, DISCARD_ASYNC); + break; + default: + btrfs_err(NULL, "unrecognized discard mode value %s", + param->key); + return -EINVAL; + } + btrfs_clear_opt(ctx->mount_opt, NODISCARD); + break; + case Opt_space_cache: + if (result.negated) { + btrfs_set_opt(ctx->mount_opt, NOSPACECACHE); + btrfs_clear_opt(ctx->mount_opt, SPACE_CACHE); + btrfs_clear_opt(ctx->mount_opt, FREE_SPACE_TREE); + } else { + btrfs_clear_opt(ctx->mount_opt, FREE_SPACE_TREE); + btrfs_set_opt(ctx->mount_opt, SPACE_CACHE); + } + break; + case Opt_space_cache_version: + switch (result.uint_32) { + case Opt_space_cache_v1: + btrfs_set_opt(ctx->mount_opt, SPACE_CACHE); + btrfs_clear_opt(ctx->mount_opt, FREE_SPACE_TREE); + break; + case Opt_space_cache_v2: + btrfs_clear_opt(ctx->mount_opt, SPACE_CACHE); + btrfs_set_opt(ctx->mount_opt, FREE_SPACE_TREE); + break; + default: + btrfs_err(NULL, "unrecognized space_cache value %s", + param->key); + return -EINVAL; + } + break; + case Opt_rescan_uuid_tree: + btrfs_set_opt(ctx->mount_opt, RESCAN_UUID_TREE); + break; + case Opt_inode_cache: + btrfs_warn(NULL, + "the 'inode_cache' option is deprecated and has no effect since 5.11"); + break; + case Opt_clear_cache: + btrfs_set_opt(ctx->mount_opt, CLEAR_CACHE); + break; + case Opt_user_subvol_rm_allowed: + btrfs_set_opt(ctx->mount_opt, USER_SUBVOL_RM_ALLOWED); + break; + case Opt_enospc_debug: + if (result.negated) + btrfs_clear_opt(ctx->mount_opt, ENOSPC_DEBUG); + else + btrfs_set_opt(ctx->mount_opt, ENOSPC_DEBUG); + break; + case Opt_defrag: + if (result.negated) + btrfs_clear_opt(ctx->mount_opt, AUTO_DEFRAG); + else + btrfs_set_opt(ctx->mount_opt, AUTO_DEFRAG); + break; + case Opt_usebackuproot: + btrfs_warn(NULL, + "'usebackuproot' is deprecated, use 'rescue=usebackuproot' instead"); + btrfs_set_opt(ctx->mount_opt, USEBACKUPROOT); + break; + case Opt_skip_balance: + btrfs_set_opt(ctx->mount_opt, SKIP_BALANCE); + break; + case Opt_fatal_errors: + switch (result.uint_32) { + case Opt_fatal_errors_panic: + btrfs_set_opt(ctx->mount_opt, + PANIC_ON_FATAL_ERROR); + break; + case Opt_fatal_errors_bug: + btrfs_clear_opt(ctx->mount_opt, + PANIC_ON_FATAL_ERROR); + break; + default: + btrfs_err(NULL, "unrecognized fatal_errors value %s", + param->key); + return -EINVAL; + } + break; + case Opt_commit_interval: + ctx->commit_interval = result.uint_32; + if (!ctx->commit_interval) + ctx->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL; + break; + case Opt_rescue: + switch (result.uint_32) { + case Opt_rescue_usebackuproot: + btrfs_set_opt(ctx->mount_opt, USEBACKUPROOT); + break; + case Opt_rescue_nologreplay: + btrfs_set_opt(ctx->mount_opt, NOLOGREPLAY); + break; + case Opt_rescue_ignorebadroots: + btrfs_set_opt(ctx->mount_opt, IGNOREBADROOTS); + break; + case Opt_rescue_ignoredatacsums: + btrfs_set_opt(ctx->mount_opt, IGNOREDATACSUMS); + break; + case Opt_rescue_parameter_all: + btrfs_set_opt(ctx->mount_opt, IGNOREDATACSUMS); + btrfs_set_opt(ctx->mount_opt, IGNOREBADROOTS); + btrfs_set_opt(ctx->mount_opt, NOLOGREPLAY); + break; + default: + btrfs_info(NULL, "unrecognized rescue option '%s'", + param->key); + return -EINVAL; + } + break; +#ifdef CONFIG_BTRFS_DEBUG + case Opt_fragment: + switch (result.uint_32) { + case Opt_fragment_parameter_all: + btrfs_set_opt(ctx->mount_opt, FRAGMENT_DATA); + btrfs_set_opt(ctx->mount_opt, FRAGMENT_METADATA); + break; + case Opt_fragment_parameter_metadata: + btrfs_set_opt(ctx->mount_opt, FRAGMENT_METADATA); + break; + case Opt_fragment_parameter_data: + btrfs_set_opt(ctx->mount_opt, FRAGMENT_DATA); + break; + default: + btrfs_info(NULL, "unrecognized fragment option '%s'", + param->key); + return -EINVAL; + } + break; +#endif +#ifdef CONFIG_BTRFS_FS_REF_VERIFY + case Opt_ref_verify: + btrfs_set_opt(ctx->mount_opt, REF_VERIFY); + break; +#endif + default: + btrfs_err(NULL, "unrecognized mount option '%s'", param->key); + return -EINVAL; + } + + return 0; +} + static bool check_ro_option(struct btrfs_fs_info *fs_info, unsigned long opt, const char *opt_name) { @@ -2255,6 +2641,10 @@ static void btrfs_kill_super(struct super_block *sb) btrfs_free_fs_info(fs_info); } +static const struct fs_context_operations btrfs_fs_context_ops __maybe_unused = { + .parse_param = btrfs_parse_param, +}; + static struct file_system_type btrfs_fs_type = { .owner = THIS_MODULE, .name = "btrfs", From patchwork Mon Nov 6 22:08:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13447535 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6869EC4332F for ; Mon, 6 Nov 2023 22:08:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233237AbjKFWIv (ORCPT ); Mon, 6 Nov 2023 17:08:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233235AbjKFWIu (ORCPT ); Mon, 6 Nov 2023 17:08:50 -0500 Received: from mail-ua1-x92c.google.com (mail-ua1-x92c.google.com [IPv6:2607:f8b0:4864:20::92c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AEB8D75 for ; Mon, 6 Nov 2023 14:08:47 -0800 (PST) Received: by mail-ua1-x92c.google.com with SMTP id a1e0cc1a2514c-7b9ba0c07f9so1370080241.3 for ; Mon, 06 Nov 2023 14:08:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1699308526; x=1699913326; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=FNj+yYFj8tqbacxBJz1am0Z6u5J0WjWsVcH94aw05E4=; b=BHVlEeJuuWvNk7U5IB68dWDP4yKfUFn9+sWB+K+z3xNPndQ8cVAP09IFOuSeSwUasv A0gSlFxhzk+bkBtZVDQ+vw6qwsC/4cuyR9yyyjY7SqNifmiKi11wyZznaPBIkxqlX4JZ f9VUoLhCE/45e2IQPZZr1hliQXpz5b2hS1NayGFKBnvJRz3aqAIrnh6a4o112cT9hR6c YuZUMY/XHv3sUlOn49Kd9OBJqywutIruY+2sAqzGMI2wdhFm8ELmMNXF9HmgI5nBGEXr 3Z+bY2KWum68fTbuZNS0smsT2roLIH5EaeuXvA1m3YHR1ls3vBxKNmgwzeiq89Bg2DGn 3xzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699308526; x=1699913326; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FNj+yYFj8tqbacxBJz1am0Z6u5J0WjWsVcH94aw05E4=; b=Hxzao7peHGQHWO69QMBfB4G6R8+VbOSJkuORqs/v5ijNwdBavkr162itGgdP99P60Y M59qqooXcc4+DN+PJP7x5mTZQv4Plq7BR4y4VDJ3B0DQqXwiyxwCainXD61QjN7dw7Rm IlPuoQhZKxUyauCrrzvQFBa987fG8PUdYwSjBMp2MeZzU9efd38QKFMdq8dkhd4/nYFf tVQH8sNzM6CUQHOky3XvHoXoxYdn3T+WeaRVXmNaPr+1dT9mZHzXm1yQ31inr0+hj0GE I7GQ581catfB0CbJrcmWR8XxjWCbA+dKBkEbANam53Ay9I5xQRzmDw9q9XwB1a1p6WKl BQpQ== X-Gm-Message-State: AOJu0YyXcd44nNDJ46z8tPgFzgUFXD7a355ctwIoBsOR33xhIyCDYGhp aLJHhVqJXcwhJL6P/RFl+ugGRECLP7SaYINQtlmMog== X-Google-Smtp-Source: AGHT+IHVhBh30f+JOoAVyc2QKsR/ah623UmoWl1SgIkgpR+dr8rnAw01DthOC2rPkDANWzHKMwaNFA== X-Received: by 2002:a67:c315:0:b0:45d:a616:78c with SMTP id r21-20020a67c315000000b0045da616078cmr5820829vsj.21.1699308526373; Mon, 06 Nov 2023 14:08:46 -0800 (PST) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id ks12-20020ac8620c000000b0041cb8732d57sm3778912qtb.38.2023.11.06.14.08.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:08:45 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, linux-fsdevel@vger.kernel.org, brauner@kernel.org Subject: [PATCH 10/18] btrfs: add fs context handling functions Date: Mon, 6 Nov 2023 17:08:18 -0500 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We are going to use the fs context to hold the mount options, so allocate the btrfs_fs_context when we're asked to init the fs context, and free it in the free callback. Signed-off-by: Josef Bacik Reviewed-by: Christian Brauner --- fs/btrfs/super.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 2f7ee78edd11..facea4632a8d 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2641,10 +2641,44 @@ static void btrfs_kill_super(struct super_block *sb) btrfs_free_fs_info(fs_info); } -static const struct fs_context_operations btrfs_fs_context_ops __maybe_unused = { +static void btrfs_free_fs_context(struct fs_context *fc) +{ + struct btrfs_fs_context *ctx = fc->fs_private; + + if (!ctx) + return; + + kfree(ctx->subvol_name); + kfree(ctx); +} + +static const struct fs_context_operations btrfs_fs_context_ops = { .parse_param = btrfs_parse_param, + .free = btrfs_free_fs_context, }; +static int __maybe_unused btrfs_init_fs_context(struct fs_context *fc) +{ + struct btrfs_fs_context *ctx; + + ctx = kzalloc(sizeof(struct btrfs_fs_context), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + ctx->thread_pool_size = min_t(unsigned long, num_online_cpus() + 2, 8); + ctx->max_inline = BTRFS_DEFAULT_MAX_INLINE; + ctx->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL; + ctx->subvol_objectid = BTRFS_FS_TREE_OBJECTID; +#ifndef CONFIG_BTRFS_FS_POSIX_ACL + ctx->noacl = true; +#endif + + fc->fs_private = ctx; + fc->ops = &btrfs_fs_context_ops; + + return 0; +} + static struct file_system_type btrfs_fs_type = { .owner = THIS_MODULE, .name = "btrfs", From patchwork Mon Nov 6 22:08:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13447538 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DACC4C4167B for ; Mon, 6 Nov 2023 22:08:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233242AbjKFWI6 (ORCPT ); Mon, 6 Nov 2023 17:08:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233238AbjKFWIw (ORCPT ); Mon, 6 Nov 2023 17:08:52 -0500 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B669D79 for ; Mon, 6 Nov 2023 14:08:48 -0800 (PST) Received: by mail-qk1-x732.google.com with SMTP id af79cd13be357-778940531dbso325891985a.0 for ; Mon, 06 Nov 2023 14:08:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1699308527; x=1699913327; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=nn4wl6X2MY9lr0usk/p7POXX8Rwn7mGHQOs/SVjMcjI=; b=mvOddxGGsAxbmyqmRo+ZEofX4UTUy+A/zSCiepqu2HPhllDR44Vyw2ycwEHoHC1x0D q13tVauE+cRjedKWtLgXWD3p0o3H5jFzsdgdznGZO+wYlQ5cFuMdUMzhQVucUGjjUgME 11tObZQZSls3y4YUgeePzPoC3luoE6DtU9YaqvXBI0pgU9LfDMLctOpUBkdn2snI3bwX 194wjOcwOJkGxxxcWLsIjSrkmdu6JHqxnRDJ02RDG20n9/cp2yVzWYlgo0D+wvj57vzL BB2sD4VkxJO8ix0RKpy7aAwVyrUrFjC1aXOeTJGWaxf/N/A2wdj+1LkWjZ9URauDVRHI fkfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699308527; x=1699913327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nn4wl6X2MY9lr0usk/p7POXX8Rwn7mGHQOs/SVjMcjI=; b=kaHuP/nbONFcVjnTOEeGyPNMN4/IdT1KU9+/SQxl2F7uYmTVGidKiVgzgaKZJKJjpu Z4RDi3b+UZvSA5eotPM9qIFp3rzQsf/jtUjy61oDMYSZA8IZjKT6zB7H/D/q4uzjAwgQ nRvZ59yjsINUW/NzQKHNMauLtcwzym5q7lWW9rDG0XxuiRm9pr1scSHXznQ2dirBoO0u LZ6GfN3pWe7wY/MGZIDdmh2R4w0PCEMWrY7a1zGe2k4wETCZ1HRF2SlEQIyf4i3f3Qug Vr9Fx+jNdEDxd/BGxMw+1z17o9hDUwB7YtOxMCwrzR5luZTESe0lKXD3DhcpkAsvsWWC hXuQ== X-Gm-Message-State: AOJu0YxocE5c/yK+w856df1lH9NA546v10T7fkrNuDfL+O3khd5/bnbV 3u1WPV/ubURveWAr/B5IoAN1Z0njFcJOwIZEdo/iAA== X-Google-Smtp-Source: AGHT+IGzmqgHg/NwwmcrhfPkj/ftVZmlblqqF5NLHLnUhn+ChPDmC97l0aqMyJ1ESpaa6EkzZ/havQ== X-Received: by 2002:a05:620a:454d:b0:778:b3e5:f4b8 with SMTP id u13-20020a05620a454d00b00778b3e5f4b8mr35859953qkp.47.1699308527462; Mon, 06 Nov 2023 14:08:47 -0800 (PST) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id m16-20020ae9e710000000b0076e1e2d6496sm3665958qka.104.2023.11.06.14.08.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:08:47 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, linux-fsdevel@vger.kernel.org, brauner@kernel.org Subject: [PATCH 11/18] btrfs: add reconfigure callback for fs_context Date: Mon, 6 Nov 2023 17:08:19 -0500 Message-ID: <1678ab93ebf666a47e42724908b09216f1789413.1699308010.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is what is used to remount the file system with the new mount API. Because the mount options are parsed separately and one at a time I've added a helper to emit the mount options after the fact once the mount is configured, this matches the dmesg output for what happens with the old mount API. Signed-off-by: Josef Bacik --- fs/btrfs/super.c | 243 +++++++++++++++++++++++++++++++++++++++++++---- fs/btrfs/zoned.c | 16 ++-- fs/btrfs/zoned.h | 3 +- 3 files changed, 234 insertions(+), 28 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index facea4632a8d..b5067cf637a2 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -734,10 +734,11 @@ static int btrfs_parse_param(struct fs_context *fc, return 0; } -static bool check_ro_option(struct btrfs_fs_info *fs_info, unsigned long opt, +static bool check_ro_option(struct btrfs_fs_info *fs_info, + unsigned long mount_opt, unsigned long opt, const char *opt_name) { - if (fs_info->mount_opt & opt) { + if (mount_opt & opt) { btrfs_err(fs_info, "%s must be used with ro mount option", opt_name); return true; @@ -745,33 +746,34 @@ static bool check_ro_option(struct btrfs_fs_info *fs_info, unsigned long opt, return false; } -static bool check_options(struct btrfs_fs_info *info, unsigned long flags) +static bool check_options(struct btrfs_fs_info *info, unsigned long *mount_opt, + unsigned long flags) { if (!(flags & SB_RDONLY) && - (check_ro_option(info, BTRFS_MOUNT_NOLOGREPLAY, "nologreplay") || - check_ro_option(info, BTRFS_MOUNT_IGNOREBADROOTS, "ignorebadroots") || - check_ro_option(info, BTRFS_MOUNT_IGNOREDATACSUMS, "ignoredatacsums"))) + (check_ro_option(info, *mount_opt, BTRFS_MOUNT_NOLOGREPLAY, "nologreplay") || + check_ro_option(info, *mount_opt, BTRFS_MOUNT_IGNOREBADROOTS, "ignorebadroots") || + check_ro_option(info, *mount_opt, BTRFS_MOUNT_IGNOREDATACSUMS, "ignoredatacsums"))) return false; if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE) && - !btrfs_test_opt(info, FREE_SPACE_TREE) && - !btrfs_test_opt(info, CLEAR_CACHE)) { + !btrfs_raw_test_opt(*mount_opt, FREE_SPACE_TREE) && + !btrfs_raw_test_opt(*mount_opt, CLEAR_CACHE)) { btrfs_err(info, "cannot disable free space tree"); return false; } if (btrfs_fs_compat_ro(info, BLOCK_GROUP_TREE) && - !btrfs_test_opt(info, FREE_SPACE_TREE)) { + !btrfs_raw_test_opt(*mount_opt, FREE_SPACE_TREE)) { btrfs_err(info, "cannot disable free space tree with block-group-tree feature"); return false; } - if (btrfs_check_mountopts_zoned(info)) + if (btrfs_check_mountopts_zoned(info, mount_opt)) return false; if (!test_bit(BTRFS_FS_STATE_REMOUNTING, &info->fs_state)) { - if (btrfs_test_opt(info, SPACE_CACHE)) + if (btrfs_raw_test_opt(*mount_opt, SPACE_CACHE)) btrfs_info(info, "disk space caching is enabled"); - if (btrfs_test_opt(info, FREE_SPACE_TREE)) + if (btrfs_raw_test_opt(*mount_opt, FREE_SPACE_TREE)) btrfs_info(info, "using free space tree"); } @@ -1337,7 +1339,7 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, } } out: - if (!ret && !check_options(info, new_flags)) + if (!ret && !check_options(info, &info->mount_opt, new_flags)) ret = -EINVAL; return ret; } @@ -2377,6 +2379,203 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data) return ret; } +static void btrfs_ctx_to_info(struct btrfs_fs_info *fs_info, + struct btrfs_fs_context *ctx) +{ + fs_info->max_inline = ctx->max_inline; + fs_info->commit_interval = ctx->commit_interval; + fs_info->metadata_ratio = ctx->metadata_ratio; + fs_info->thread_pool_size = ctx->thread_pool_size; + fs_info->mount_opt = ctx->mount_opt; + fs_info->compress_type = ctx->compress_type; + fs_info->compress_level = ctx->compress_level; +} + +static void btrfs_info_to_ctx(struct btrfs_fs_info *fs_info, + struct btrfs_fs_context *ctx) +{ + ctx->max_inline = fs_info->max_inline; + ctx->commit_interval = fs_info->commit_interval; + ctx->metadata_ratio = fs_info->metadata_ratio; + ctx->thread_pool_size = fs_info->thread_pool_size; + ctx->mount_opt = fs_info->mount_opt; + ctx->compress_type = fs_info->compress_type; + ctx->compress_level = fs_info->compress_level; +} + +#define btrfs_info_if_set(fs_info, old_ctx, opt, fmt, args...) \ +do { \ + if ((!old_ctx || !btrfs_raw_test_opt(old_ctx->mount_opt, opt)) && \ + btrfs_raw_test_opt(fs_info->mount_opt, opt)) \ + btrfs_info(fs_info, fmt, ##args); \ +} while (0) + +#define btrfs_info_if_unset(fs_info, old_ctx, opt, fmt, args...) \ +do { \ + if ((old_ctx && btrfs_raw_test_opt(old_ctx->mount_opt, opt)) && \ + !btrfs_raw_test_opt(fs_info->mount_opt, opt)) \ + btrfs_info(fs_info, fmt, ##args); \ +} while (0) + +static void btrfs_emit_options(struct btrfs_fs_info *fs_info, + struct btrfs_fs_context *old_ctx) +{ + btrfs_info_if_set(fs_info, old_ctx, NODATASUM, "setting nodatasum"); + btrfs_info_if_set(fs_info, old_ctx, DEGRADED, + "allowing degraded mounts"); + btrfs_info_if_set(fs_info, old_ctx, NODATASUM, "setting nodatasum"); + btrfs_info_if_set(fs_info, old_ctx, SSD, "enabling ssd optimizations"); + btrfs_info_if_set(fs_info, old_ctx, SSD_SPREAD, + "using spread ssd allocation scheme"); + btrfs_info_if_set(fs_info, old_ctx, NOBARRIER, "turning off barriers"); + btrfs_info_if_set(fs_info, old_ctx, NOTREELOG, "disabling tree log"); + btrfs_info_if_set(fs_info, old_ctx, NOLOGREPLAY, + "disabling log replay at mount time"); + btrfs_info_if_set(fs_info, old_ctx, FLUSHONCOMMIT, + "turning on flush-on-commit"); + btrfs_info_if_set(fs_info, old_ctx, DISCARD_SYNC, + "turning on sync discard"); + btrfs_info_if_set(fs_info, old_ctx, DISCARD_ASYNC, + "turning on async discard"); + btrfs_info_if_set(fs_info, old_ctx, FREE_SPACE_TREE, + "enabling free space tree"); + btrfs_info_if_set(fs_info, old_ctx, SPACE_CACHE, + "enabling disk space caching"); + btrfs_info_if_set(fs_info, old_ctx, CLEAR_CACHE, + "force clearing of disk cache"); + btrfs_info_if_set(fs_info, old_ctx, AUTO_DEFRAG, + "enabling auto defrag"); + btrfs_info_if_set(fs_info, old_ctx, FRAGMENT_DATA, + "fragmenting data"); + btrfs_info_if_set(fs_info, old_ctx, FRAGMENT_METADATA, + "fragmenting metadata"); + btrfs_info_if_set(fs_info, old_ctx, REF_VERIFY, + "doing ref verification"); + btrfs_info_if_set(fs_info, old_ctx, USEBACKUPROOT, + "trying to use backup root at mount time"); + btrfs_info_if_set(fs_info, old_ctx, IGNOREBADROOTS, + "ignoring bad roots"); + btrfs_info_if_set(fs_info, old_ctx, IGNOREDATACSUMS, + "ignoring data csums"); + + btrfs_info_if_unset(fs_info, old_ctx, NODATACOW, "setting datacow"); + btrfs_info_if_unset(fs_info, old_ctx, SSD, "not using ssd optimizations"); + btrfs_info_if_unset(fs_info, old_ctx, SSD_SPREAD, + "not using spread ssd allocation scheme"); + btrfs_info_if_unset(fs_info, old_ctx, NOBARRIER, + "turning off barriers"); + btrfs_info_if_unset(fs_info, old_ctx, NOTREELOG, "enabling tree log"); + btrfs_info_if_unset(fs_info, old_ctx, SPACE_CACHE, + "disabling disk space caching"); + btrfs_info_if_unset(fs_info, old_ctx, FREE_SPACE_TREE, + "disabling free space tree"); + btrfs_info_if_unset(fs_info, old_ctx, AUTO_DEFRAG, + "disabling auto defrag"); + btrfs_info_if_unset(fs_info, old_ctx, COMPRESS, + "use no compression"); + + /* Did the compression settings change? */ + if (btrfs_test_opt(fs_info, COMPRESS) && + (!old_ctx || + old_ctx->compress_type != fs_info->compress_type || + old_ctx->compress_level != fs_info->compress_level || + (!btrfs_raw_test_opt(old_ctx->mount_opt, FORCE_COMPRESS) && + btrfs_raw_test_opt(fs_info->mount_opt, FORCE_COMPRESS)))) { + char *compress_type = "none"; + + switch (fs_info->compress_type) { + case BTRFS_COMPRESS_ZLIB: + compress_type = "zlib"; + break; + case BTRFS_COMPRESS_LZO: + compress_type = "lzo"; + break; + case BTRFS_COMPRESS_ZSTD: + compress_type = "zstd"; + break; + } + + btrfs_info(fs_info, "%s %s compression, level %d", + btrfs_test_opt(fs_info, FORCE_COMPRESS) ? "force" : "use", + compress_type, fs_info->compress_level); + } + + if (fs_info->max_inline != BTRFS_DEFAULT_MAX_INLINE) + btrfs_info(fs_info, "max_inline at %llu", + fs_info->max_inline); +} + +static int btrfs_reconfigure(struct fs_context *fc) +{ + struct super_block *sb = fc->root->d_sb; + struct btrfs_fs_info *fs_info = btrfs_sb(sb); + struct btrfs_fs_context *ctx = fc->fs_private; + struct btrfs_fs_context old_ctx; + int ret = 0; + + btrfs_info_to_ctx(fs_info, &old_ctx); + + sync_filesystem(sb); + set_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state); + + if (!check_options(fs_info, &ctx->mount_opt, fc->sb_flags)) + return -EINVAL; + + ret = btrfs_check_features(fs_info, !(fc->sb_flags & SB_RDONLY)); + if (ret < 0) + return ret; + + btrfs_ctx_to_info(fs_info, ctx); + btrfs_remount_begin(fs_info, old_ctx.mount_opt, fc->sb_flags); + btrfs_resize_thread_pool(fs_info, fs_info->thread_pool_size, + old_ctx.thread_pool_size); + + if ((bool)btrfs_test_opt(fs_info, FREE_SPACE_TREE) != + (bool)btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE) && + (!sb_rdonly(sb) || (fc->sb_flags & SB_RDONLY))) { + btrfs_warn(fs_info, + "remount supports changing free space tree only from ro to rw"); + /* Make sure free space cache options match the state on disk */ + if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { + btrfs_set_opt(fs_info->mount_opt, FREE_SPACE_TREE); + btrfs_clear_opt(fs_info->mount_opt, SPACE_CACHE); + } + if (btrfs_free_space_cache_v1_active(fs_info)) { + btrfs_clear_opt(fs_info->mount_opt, FREE_SPACE_TREE); + btrfs_set_opt(fs_info->mount_opt, SPACE_CACHE); + } + } + + ret = 0; + if (!sb_rdonly(sb) && (fc->sb_flags & SB_RDONLY)) + ret = btrfs_remount_ro(fs_info); + else if (sb_rdonly(sb) && !(fc->sb_flags & SB_RDONLY)) + ret = btrfs_remount_rw(fs_info); + if (ret) + goto restore; + + /* + * If we set the mask during the parameter parsing vfs would reject the + * remount. Here we can set the mask and the value will be updated + * appropriately. + */ + if ((fc->sb_flags & SB_POSIXACL) != (sb->s_flags & SB_POSIXACL)) + fc->sb_flags_mask |= SB_POSIXACL; + + btrfs_emit_options(fs_info, &old_ctx); + wake_up_process(fs_info->transaction_kthread); + btrfs_remount_cleanup(fs_info, old_ctx.mount_opt); + btrfs_clear_oneshot_options(fs_info); + clear_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state); + + return 0; +restore: + btrfs_ctx_to_info(fs_info, &old_ctx); + btrfs_remount_cleanup(fs_info, old_ctx.mount_opt); + clear_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state); + return ret; +} + /* Used to sort the devices by max_avail(descending sort) */ static int btrfs_cmp_device_free_bytes(const void *a, const void *b) { @@ -2654,6 +2853,7 @@ static void btrfs_free_fs_context(struct fs_context *fc) static const struct fs_context_operations btrfs_fs_context_ops = { .parse_param = btrfs_parse_param, + .reconfigure = btrfs_reconfigure, .free = btrfs_free_fs_context, }; @@ -2665,17 +2865,18 @@ static int __maybe_unused btrfs_init_fs_context(struct fs_context *fc) if (!ctx) return -ENOMEM; - ctx->thread_pool_size = min_t(unsigned long, num_online_cpus() + 2, 8); - ctx->max_inline = BTRFS_DEFAULT_MAX_INLINE; - ctx->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL; - ctx->subvol_objectid = BTRFS_FS_TREE_OBJECTID; -#ifndef CONFIG_BTRFS_FS_POSIX_ACL - ctx->noacl = true; -#endif - fc->fs_private = ctx; fc->ops = &btrfs_fs_context_ops; + if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) { + btrfs_info_to_ctx(btrfs_sb(fc->root->d_sb), ctx); + } else { + ctx->thread_pool_size = + min_t(unsigned long, num_online_cpus() + 2, 8); + ctx->max_inline = BTRFS_DEFAULT_MAX_INLINE; + ctx->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL; + } + return 0; } diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 188378ca19c7..77b065ce3ed3 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -781,7 +781,7 @@ int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info) * Check mount options here, because we might change fs_info->zoned * from fs_info->zone_size. */ - ret = btrfs_check_mountopts_zoned(fs_info); + ret = btrfs_check_mountopts_zoned(fs_info, &fs_info->mount_opt); if (ret) return ret; @@ -789,7 +789,8 @@ int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info) return 0; } -int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info) +int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info, + unsigned long *mount_opt) { if (!btrfs_is_zoned(info)) return 0; @@ -798,18 +799,21 @@ int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info) * Space cache writing is not COWed. Disable that to avoid write errors * in sequential zones. */ - if (btrfs_test_opt(info, SPACE_CACHE)) { + if (btrfs_raw_test_opt(*mount_opt, SPACE_CACHE)) { btrfs_err(info, "zoned: space cache v1 is not supported"); return -EINVAL; } - if (btrfs_test_opt(info, NODATACOW)) { + if (btrfs_raw_test_opt(*mount_opt, NODATACOW)) { btrfs_err(info, "zoned: NODATACOW not supported"); return -EINVAL; } - btrfs_clear_and_info(info, DISCARD_ASYNC, - "zoned: async discard ignored and disabled for zoned mode"); + if (btrfs_raw_test_opt(*mount_opt, DISCARD_ASYNC)) { + btrfs_info(info, + "zoned: async discard ignored and disabled for zoned mode"); + btrfs_clear_opt(*mount_opt, DISCARD_ASYNC); + } return 0; } diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index b9cec523b778..80459d750080 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -45,7 +45,8 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache); void btrfs_destroy_dev_zone_info(struct btrfs_device *device); struct btrfs_zoned_device_info *btrfs_clone_dev_zone_info(struct btrfs_device *orig_dev); int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info); -int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info); +int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info, + unsigned long *mount_opt); int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, u64 *bytenr_ret); int btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw, From patchwork Mon Nov 6 22:08:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13447537 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19CC8C4167D for ; Mon, 6 Nov 2023 22:08:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233240AbjKFWI5 (ORCPT ); Mon, 6 Nov 2023 17:08:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233243AbjKFWIx (ORCPT ); Mon, 6 Nov 2023 17:08:53 -0500 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A535510A for ; Mon, 6 Nov 2023 14:08:49 -0800 (PST) Received: by mail-qv1-xf2f.google.com with SMTP id 6a1803df08f44-66d093265dfso30701026d6.3 for ; Mon, 06 Nov 2023 14:08:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1699308528; x=1699913328; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=6kGqK1HKF88RhaqK+8yI76GTZf9COGfighhf0OCtRSg=; b=ZHlsIBUELLeqRMuMIEyLsSg+16xTVWYyHkIDtSGSj34617hspd1VhqxLh3SC2WaVwt 0k5IX73uPnHW68HGozK+6wNFULFUz+clNgEl8Dc+rko22rMD4fNCj1PgBPlrL9KS+1PX CoQYh6wIEZZgQAiSkcu2t9SDkx1+wHd/8giuz96d08q4SXSkSGAB77Ed4oUsxEChmGer ZzVeE6neyiPxt2W9GHu3eaacOnm7r1QdEhJzNRXLSxtJXN/T1ItH6R+7WBi+7j6cGEoU gNmxCqoWIJf1mP3/nmmhnprJgy2Gyt7x2UCvmxYEmBSS/jXbptFYzXXvRVYUFkL109Up bssQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699308528; x=1699913328; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6kGqK1HKF88RhaqK+8yI76GTZf9COGfighhf0OCtRSg=; b=DFBMkRG95TE9h2e/psWBmOy3UPpxQLchvXrB2otKar3keMpS928YCu/1E7uc9mZIL+ Uieq0ioBDHbrJmvhDBAeIQqi5JyLr8yIZ/tHDn4YLV+e76U7G9m1wKKcujEu+GKHy5eh FVTLsymOtSPcWb0Ew8qau+n/pkHNkIsiHdCcAb+yQuyQYdKInYqjUtk5S38LCCkx6ZYh 8klB9+MINwl8qoUO+5IoQo0MCU9bq7DwkDXu1tIM9xh/2t7K66hnO+vUbbBi5VHT5hw1 TamlgbcbV5mT3N1pFmpDMuBlrIhsm7Gh2OEZ+MO9LEsGn6ElVN94dfoQ1zAK0JD/qqW2 r9bg== X-Gm-Message-State: AOJu0Yx6Z+KAHAp0eJZGFdeddrpqba8hR5S18FCE0L6ngEwGSIF9kc66 ZPveks8qIaf+Kd5Oskio0u7a/kDPon3Su2sduvdjmQ== X-Google-Smtp-Source: AGHT+IE3IHLn8TLG/tItDJNijzGUWqUC1HfQJ0+nQU/0twRoiwkbLNTIMzjGlu/B8iyX6kuuDe+cEQ== X-Received: by 2002:a05:6214:2dc5:b0:675:a120:7a2d with SMTP id nc5-20020a0562142dc500b00675a1207a2dmr2465136qvb.2.1699308528593; Mon, 06 Nov 2023 14:08:48 -0800 (PST) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id h8-20020a05620a400800b007770673e757sm3662246qko.94.2023.11.06.14.08.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:08:48 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, linux-fsdevel@vger.kernel.org, brauner@kernel.org Subject: [PATCH 12/18] btrfs: add get_tree callback for new mount API Date: Mon, 6 Nov 2023 17:08:20 -0500 Message-ID: <01325fa7043a86fb58cddbf821933caf0f1bb965.1699308010.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is the actual mounting callback for the new mount API. Implement this using our current fill super as a guideline, making the appropriate adjustments for the new mount API. Our old mount operation had two fs_types, one to handle the actual opening, and the one that we called to handle the actual opening and then did the subvol lookup for returning the actual root dentry. This is mirrored here, but simply with different behaviors for ->get_tree. We use the existence of ->s_fs_info to tell which part we're in. The initial call allocates the fs_info, then call mount_fc() with a duplicated fc to do the actual open_ctree part. Then we take that vfsmount and use it to look up our subvolume that we're mounting and return that as our s_root. This idea was taken from Christians attempt to convert us to the new mount api. References: https://lore.kernel.org/all/20230626-fs-btrfs-mount-api-v1-2-045e9735a00b@kernel.org/ Signed-off-by: Josef Bacik Reviewed-by: Christian Brauner --- fs/btrfs/super.c | 210 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 206 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index b5067cf637a2..4ace42e08bff 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -95,6 +95,7 @@ struct btrfs_fs_context { unsigned long mount_opt; unsigned long compress_type:4; unsigned int compress_level; + refcount_t refs; }; enum { @@ -2833,6 +2834,181 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) return 0; } +static int btrfs_fc_test_super(struct super_block *s, struct fs_context *fc) +{ + struct btrfs_fs_info *p = fc->s_fs_info; + struct btrfs_fs_info *fs_info = btrfs_sb(s); + + return fs_info->fs_devices == p->fs_devices; +} + +static int btrfs_get_tree_super(struct fs_context *fc) +{ + struct btrfs_fs_info *fs_info = fc->s_fs_info; + struct btrfs_fs_context *ctx = fc->fs_private; + struct btrfs_fs_devices *fs_devices = NULL; + struct block_device *bdev; + struct btrfs_device *device; + struct super_block *s; + blk_mode_t mode = sb_open_mode(fc->sb_flags); + int ret; + + btrfs_ctx_to_info(fs_info, ctx); + mutex_lock(&uuid_mutex); + + /* + * With 'true' passed to btrfs_scan_one_device() (mount time) we expect + * either a valid device or an error. + */ + device = btrfs_scan_one_device(fc->source, mode, true); + ASSERT(device != NULL); + if (IS_ERR(device)) { + mutex_unlock(&uuid_mutex); + return PTR_ERR(device); + } + + fs_devices = device->fs_devices; + fs_info->fs_devices = fs_devices; + + ret = btrfs_open_devices(fs_devices, mode, &btrfs_fs_type); + mutex_unlock(&uuid_mutex); + if (ret) + return ret; + + if (!(fc->sb_flags & SB_RDONLY) && fs_devices->rw_devices == 0) { + ret = -EACCES; + goto error; + } + + bdev = fs_devices->latest_dev->bdev; + + /* + * If successful, this will transfer the fs_info into the super block, + * and fc->s_fs_info will be NULL. However if there's an existing + * super, we'll still have fc->s_fs_info populated. If we error + * completely out it'll be cleaned up when we drop the fs_context, + * otherwise it's tied to the lifetime of the super_block. + * + * Adding this comment because I was horribly confused about the error + * handling from here on out. + */ + s = sget_fc(fc, btrfs_fc_test_super, set_anon_super_fc); + if (IS_ERR(s)) { + ret = PTR_ERR(s); + goto error; + } + + if (s->s_root) { + btrfs_close_devices(fs_devices); + if ((fc->sb_flags ^ s->s_flags) & SB_RDONLY) + ret = -EBUSY; + } else { + snprintf(s->s_id, sizeof(s->s_id), "%pg", bdev); + shrinker_debugfs_rename(&s->s_shrink, "sb-btrfs:%s", s->s_id); + btrfs_sb(s)->bdev_holder = &btrfs_fs_type; + ret = btrfs_fill_super(s, fs_devices, NULL); + } + + if (ret) { + deactivate_locked_super(s); + return ret; + } + + fc->root = dget(s->s_root); + return 0; + +error: + btrfs_close_devices(fs_devices); + return ret; +} + +static int btrfs_get_tree_subvol(struct fs_context *fc) +{ + struct btrfs_fs_info *fs_info = NULL; + struct btrfs_fs_context *ctx = fc->fs_private; + struct fs_context *dup_fc; + struct dentry *dentry; + struct vfsmount *mnt; + + /* + * Setup a dummy root and fs_info for test/set super. This is because + * we don't actually fill this stuff out until open_ctree, but we need + * then open_ctree will properly initialize the file system specific + * settings later. btrfs_init_fs_info initializes the static elements + * of the fs_info (locks and such) to make cleanup easier if we find a + * superblock with our given fs_devices later on at sget() time. + */ + fs_info = kvzalloc(sizeof(struct btrfs_fs_info), GFP_KERNEL); + if (!fs_info) + return -ENOMEM; + + fs_info->super_copy = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_KERNEL); + fs_info->super_for_commit = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_KERNEL); + if (!fs_info->super_copy || !fs_info->super_for_commit) { + btrfs_free_fs_info(fs_info); + return -ENOMEM; + } + btrfs_init_fs_info(fs_info); + + dup_fc = vfs_dup_fs_context(fc); + if (IS_ERR(dup_fc)) { + btrfs_free_fs_info(fs_info); + return PTR_ERR(dup_fc); + } + + /* + * When we do the sget_fc this gets transferred to the sb, so we only + * need to set it on the dup_fc as this is what creates the super block. + */ + dup_fc->s_fs_info = fs_info; + + /* + * We'll do the security settings in our btrfs_get_tree_super() mount + * loop, they were duplicated into dup_fc, we can drop the originals + * here. + */ + security_free_mnt_opts(&fc->security); + fc->security = NULL; + + mnt = fc_mount(dup_fc); + put_fs_context(dup_fc); + if (IS_ERR(mnt)) + return PTR_ERR(mnt); + + /* + * This free's ->subvol_name, because if it isn't set we have to + * allocate a buffer to hold the subvol_name, so we just drop our + * reference to it here. + */ + dentry = mount_subvol(ctx->subvol_name, ctx->subvol_objectid, mnt); + ctx->subvol_name = NULL; + if (IS_ERR(dentry)) + return PTR_ERR(dentry); + + fc->root = dentry; + return 0; +} + +static int btrfs_get_tree(struct fs_context *fc) +{ + /* + * Since we use mount_subtree to mount the default/specified subvol, we + * have to do mounts in two steps. + * + * First pass through we call btrfs_get_tree_subvol(), this is just a + * wrapper around fc_mount() to call back into here again, and this time + * we'll call btrfs_get_tree_super(). This will do the open_ctree() and + * everything to open the devices and file system. Then we return back + * with a fully constructed vfsmount in btrfs_get_tree_subvol(), and + * from there we can do our mount_subvol() call, which will lookup + * whichever subvol we're mounting and setup this fc with the + * appropriate dentry for the subvol. + */ + if (fc->s_fs_info) + return btrfs_get_tree_super(fc); + return btrfs_get_tree_subvol(fc); +} + static void btrfs_kill_super(struct super_block *sb) { struct btrfs_fs_info *fs_info = btrfs_sb(sb); @@ -2843,17 +3019,42 @@ static void btrfs_kill_super(struct super_block *sb) static void btrfs_free_fs_context(struct fs_context *fc) { struct btrfs_fs_context *ctx = fc->fs_private; + struct btrfs_fs_info *fs_info = fc->s_fs_info; - if (!ctx) - return; + if (fs_info) + btrfs_free_fs_info(fs_info); - kfree(ctx->subvol_name); - kfree(ctx); + if (ctx && refcount_dec_and_test(&ctx->refs)) { + kfree(ctx->subvol_name); + kfree(ctx); + } +} + +static int btrfs_dup_fs_context(struct fs_context *fc, + struct fs_context *src_fc) +{ + struct btrfs_fs_context *ctx = src_fc->fs_private; + + /* + * Give a ref to our ctx to this dup, as we want to keep it around for + * our original fc so we can have the subvolume name or objectid. + * + * We unset ->source in the original fc because the dup needs it for + * mounting, and then once we free the dup it'll free ->source, so we + * need to make sure we're only pointing to it in one fc. + */ + refcount_inc(&ctx->refs); + fc->fs_private = ctx; + fc->source = src_fc->source; + src_fc->source = NULL; + return 0; } static const struct fs_context_operations btrfs_fs_context_ops = { .parse_param = btrfs_parse_param, .reconfigure = btrfs_reconfigure, + .get_tree = btrfs_get_tree, + .dup = btrfs_dup_fs_context, .free = btrfs_free_fs_context, }; @@ -2865,6 +3066,7 @@ static int __maybe_unused btrfs_init_fs_context(struct fs_context *fc) if (!ctx) return -ENOMEM; + refcount_set(&ctx->refs, 1); fc->fs_private = ctx; fc->ops = &btrfs_fs_context_ops; From patchwork Mon Nov 6 22:08:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13447540 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C76EFC0018A for ; Mon, 6 Nov 2023 22:08:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233260AbjKFWJA (ORCPT ); Mon, 6 Nov 2023 17:09:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233249AbjKFWIy (ORCPT ); Mon, 6 Nov 2023 17:08:54 -0500 Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE04DD77 for ; Mon, 6 Nov 2023 14:08:50 -0800 (PST) Received: by mail-qk1-x72f.google.com with SMTP id af79cd13be357-77a277eb084so329883385a.2 for ; Mon, 06 Nov 2023 14:08:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1699308530; x=1699913330; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=8j2QVOSc+1ODIU13iTqNOKn0/FDevbwNBM/VRc23N+w=; b=IyTh9e7HrIwWNcZZ97pFellsHOtyW+2/ZwPvhT5LIaVH83NtTGEQVrX8DHvKeWX9+a gSyGhU2CVgyJIhDHt5fkfD1Bew46IflxmoJr/2j8c4ZQz2An4y54pBOyzhWa3QrjB6rm FIM95hCG4WgXNMcPArv0I3C63CcNXE4NwIul6BPl6vr2bOkevmwFCe1XWMcBFN39IqJS sOhPbLt8+/ajDfu5OoK4rAAzPUyWSR6lv6AHH6o+8vHSe6ExO9du7Ka1Cn2kpOhQLJap NPWwpsQeqP97869pjtlGhUibgw8CXCFCrREqYZr894phwZXoCeb6Meo4Ze4DoWJTNtdT 4CPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699308530; x=1699913330; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8j2QVOSc+1ODIU13iTqNOKn0/FDevbwNBM/VRc23N+w=; b=tO1XTHaXlIJWeEQg5i8fu617dA2tQhaRX+eVj970bqKcR5kG7C1gDlC3lEyEzN9VZE Nmp5Ds7KzurxHx7Yw1jCfufhRKV2HG4cNWH5onZul9/q0XtiQ+X6lLQTNKxeVHc41Lm3 Vzsi9JB8PpXwbEblNQ2lv00j3jkn8rTuJSCSKSV7G2/SPMw5vCtRabwfu02iISrjjknl zufAFfCBo8GCaR/PtFKfco/A0ofkUtlIEd5rDqDTtRQvqbg6GRkhoo3s/z9P+uH0RgtN QvlUlagnnG/hMzinnYWOkDCdckWlRKaVVeDUBGSq4AZCldjIGWdprtzhkCocID863ta7 E9fA== X-Gm-Message-State: AOJu0YxSe8AWf1ITmtbVo+wWt9icvQLLA1rkOcbCy7v4yx/Z2sQbvGqA czR77/g+3O0+sHXIHpo0xn7vyGz0lRYt9KTsobMnpA== X-Google-Smtp-Source: AGHT+IEEbklU1ZQ3qsHEK3r5Rhn95AvMaBeSzWOqoxhudvAt2H7ZkC05WSZGBm894QvVjqy/13nAmQ== X-Received: by 2002:a05:620a:4113:b0:76c:e9e1:2b2 with SMTP id j19-20020a05620a411300b0076ce9e102b2mr22998208qko.13.1699308529769; Mon, 06 Nov 2023 14:08:49 -0800 (PST) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id u21-20020ae9c015000000b00774652483b7sm3685338qkk.33.2023.11.06.14.08.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:08:49 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, linux-fsdevel@vger.kernel.org, brauner@kernel.org Subject: [PATCH 13/18] btrfs: handle the ro->rw transition for mounting different subovls Date: Mon, 6 Nov 2023 17:08:21 -0500 Message-ID: <0a73915edbb8d05e30d167351ea8c709a9bfe447.1699308010.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is an oddity that we've carried around since 0723a0473fb4 ("btrfs: allow mounting btrfs subvolumes with different ro/rw options") where we'll under the covers flip the file system to RW if you're mixing and matching ro/rw options with different subvol mounts. The first mount is what the super gets setup as, so we'd handle this by remount the super as rw under the covers to facilitate this behavior. With the new mount API we can't really allow this, because user space has the ability to specify the super block settings, and the mount settings. So if the user explicitly set the super block as read only, and then tried to mount a rw mount with the super block we'll reject this. However the old API was less descriptive and thus we allowed this kind of behavior. This patch preserves this behavior for the old api calls. This is inspired by Christians work, and includes one of his comments, and thus is included in the link below. Link: https://lore.kernel.org/all/20230626-fs-btrfs-mount-api-v1-2-045e9735a00b@kernel.org/ Signed-off-by: Josef Bacik Reviewed-by: Christian Brauner --- fs/btrfs/super.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 132 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 4ace42e08bff..e2ac0801211d 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2513,13 +2513,15 @@ static int btrfs_reconfigure(struct fs_context *fc) struct btrfs_fs_context *ctx = fc->fs_private; struct btrfs_fs_context old_ctx; int ret = 0; + bool mount_reconfigure = (fc->s_fs_info != NULL); btrfs_info_to_ctx(fs_info, &old_ctx); sync_filesystem(sb); set_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state); - if (!check_options(fs_info, &ctx->mount_opt, fc->sb_flags)) + if (!mount_reconfigure && + !check_options(fs_info, &ctx->mount_opt, fc->sb_flags)) return -EINVAL; ret = btrfs_check_features(fs_info, !(fc->sb_flags & SB_RDONLY)); @@ -2922,6 +2924,133 @@ static int btrfs_get_tree_super(struct fs_context *fc) return ret; } +/* + * Christian wrote this long comment about what we're doing here, preserving it + * so the history of this change is preserved. + * + * ever since commit 0723a0473fb4 ("btrfs: allow * mounting btrfs subvolumes + * with different ro/rw * options") the following works: + * + * (i) mount /dev/sda3 -o subvol=foo,ro /mnt/foo + * (ii) mount /dev/sda3 -o subvol=bar,rw /mnt/bar + * + * which looks nice and innocent but is actually pretty * intricate and + * deserves a long comment. + * + * on another filesystem a subvolume mount is close to * something like: + * + * (iii) # create rw superblock + initial mount + * mount -t xfs /dev/sdb /opt/ + * + * # create ro bind mount + * mount --bind -o ro /opt/foo /mnt/foo + * + * # unmount initial mount + * umount /opt + * + * of course, there's some special subvolume sauce and there's the fact that the + * sb->s_root dentry is really swapped after mount_subtree(). but conceptually + * it's very close and will help us understand the issue. + * + * the old mount api didn't cleanly distinguish between a mount being made ro + * and a superblock being made ro. the only way to change the ro state of + * either object was by passing ms_rdonly. if a new mount was created via + * mount(2) such as: + * + * mount("/dev/sdb", "/mnt", "xfs", ms_rdonly, null); + * + * the ms_rdonly flag being specified had two effects: + * + * (1) mnt_readonly was raised -> the resulting mount got + * @mnt->mnt_flags |= mnt_readonly raised. + * + * (2) ms_rdonly was passed to the filesystem's mount method and the filesystems + * made the superblock ro. note, how sb_rdonly has the same value as + * ms_rdonly and is raised whenever ms_rdonly is passed through mount(2). + * + * creating a subtree mount via (iii) ends up leaving a rw superblock with a + * subtree mounted ro. + * + * but consider the effect on the old mount api on btrfs subvolume mounting + * which combines the distinct step in (iii) into a a single step. + * + * by issuing (i) both the mount and the superblock are turned ro. now when (ii) + * is issued the superblock is ro and thus even if the mount created for (ii) is + * rw it wouldn't help. hence, btrfs needed to transition the superblock from ro + * to rw for (ii) which it did using an internal remount call (a bold + * choice...). + * + * iow, subvolume mounting was inherently messy due to the ambiguity of + * ms_rdonly in mount(2). note, this ambiguity has mount(8) always translate + * "ro" to ms_rdonly. iow, in both (i) and (ii) "ro" becomes ms_rdonly when + * passed by mount(8) to mount(2). + * + * enter the new mount api. the new mount api disambiguates making a mount ro + * and making a superblock ro. + * + * (3) to turn a mount ro the mount_attr_rdonly flag can be used with either + * fsmount() or mount_setattr() this is a pure vfs level change for a + * specific mount or mount tree that is never seen by the filesystem itself. + * + * (4) to turn a superblock ro the "ro" flag must be used with + * fsconfig(fsconfig_set_flag, "ro"). this option is seen by the filesytem + * in fc->sb_flags. + * + * this disambiguation has rather positive consequences. mounting a subvolume + * ro will not also turn the superblock ro. only the mount for the subvolume + * will become ro. + * + * so, if the superblock creation request comes from the new mount api the + * caller must've explicitly done: + * + * fsconfig(fsconfig_set_flag, "ro") + * fsmount/mount_setattr(mount_attr_rdonly) + * + * iow, at some point the caller must have explicitly turned the whole + * superblock ro and we shouldn't just undo it like we did for the old mount + * api. in any case, it lets us avoid this nasty hack in the new mount api. + * + * Consequently, the remounting hack must only be used for requests originating + * from the old mount api and should be marked for full deprecation so it can be + * turned off in a couple of years. + * + * The new mount api has no reason to support this hack. + */ +static struct vfsmount *btrfs_reconfigure_for_mount(struct fs_context *fc) +{ + struct vfsmount *mnt; + int ret; + bool ro2rw = !(fc->sb_flags & SB_RDONLY); + + /* + * We got an EBUSY because our SB_RDONLY flag didn't match the existing + * super block, so invert our setting here and re-try the mount so we + * can get our vfsmount. + */ + if (ro2rw) + fc->sb_flags |= SB_RDONLY; + else + fc->sb_flags &= ~SB_RDONLY; + + mnt = fc_mount(fc); + if (IS_ERR(mnt)) + return mnt; + + if (!fc->oldapi || !ro2rw) + return mnt; + + /* We need to convert to rw, call reconfigure */ + fc->sb_flags &= ~SB_RDONLY; + down_write(&mnt->mnt_sb->s_umount); + ret = btrfs_reconfigure(fc); + up_write(&mnt->mnt_sb->s_umount); + if (ret) { + mntput(mnt); + return ERR_PTR(ret); + } + return mnt; +} + static int btrfs_get_tree_subvol(struct fs_context *fc) { struct btrfs_fs_info *fs_info = NULL; @@ -2971,6 +3100,8 @@ static int btrfs_get_tree_subvol(struct fs_context *fc) fc->security = NULL; mnt = fc_mount(dup_fc); + if (PTR_ERR_OR_ZERO(mnt) == -EBUSY) + mnt = btrfs_reconfigure_for_mount(dup_fc); put_fs_context(dup_fc); if (IS_ERR(mnt)) return PTR_ERR(mnt); From patchwork Mon Nov 6 22:08:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13447539 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 169F1C4332F for ; Mon, 6 Nov 2023 22:08:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233243AbjKFWI7 (ORCPT ); Mon, 6 Nov 2023 17:08:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233253AbjKFWIy (ORCPT ); Mon, 6 Nov 2023 17:08:54 -0500 Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E39F010A for ; Mon, 6 Nov 2023 14:08:51 -0800 (PST) Received: by mail-qv1-xf29.google.com with SMTP id 6a1803df08f44-6711dd6595fso27845866d6.3 for ; Mon, 06 Nov 2023 14:08:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1699308531; x=1699913331; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ADddi46ALDimV8M4top5nURYkZGqEm0y0qUDMKyt84M=; b=t+tspPFiKtl115Z8kPo3rIzEdl3/picB/NZBVYM8govrbcfqh3P/qhKc7K/6fnEosx hyLdNviLU2fKeIP6NLp+Nab8xzXIVW22HD1eF82I17KLSbfGQ8QukwHBsA7twN4z/HxM +/CCcQQh+zBQ/w+gM7iItVuUfqwS9jx9hpcXV3tpD+GfkdtV5oaVXSwWlaCojnWHHLOC O1KyFLAl5VgQex7krLJdiKL2EFU70VY77dvyvz73E8q3t/k/keFJrlOOP3v0WismrtUY r0iGjfPiVPSP6iR8GnEsPvFgW/K8EzGUsoZ8yHuTgNumMYLaRMFqxpJHYwrw8N2wj5Mz XB8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699308531; x=1699913331; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ADddi46ALDimV8M4top5nURYkZGqEm0y0qUDMKyt84M=; b=sz6naq7P4i9AenIjEEh8E6K6Mxb7wGUOk0NRebk56zvY1lYgf1oAHewC4AzP1urd4b s2x7bE4/1F0yrsPey7Wi8DMRCXKM7r9MQGmKBVC1aE2juCiG4dOlD332WHV4uuH0pLbS EDdJavHZ7kZatTrUTqIw41rXYBnSq5dE+os/jFA01pgSJOmp7pgcDSNJ9w4+0iZDUNuL +qKdmq/nkTM3q9/S7KA3c4RZjXunr7IF5WTVeZ8rLJO0UTgCUTOO9oPhQTEDbvYbvecM 9fGHx7/+VQv73R1ZmX4nhKHBxP77+sVpTJwMxkuUPLb+ZytynspzjrEjFAahYrH2CORn jRiQ== X-Gm-Message-State: AOJu0YyAE73LgxCh3rHFV7Fj1IybhRWwhQPJgu8BvGnY6NDOQaXgolfy 19ptmS0iabcDB1Ww0VyQ3OOKH14+YEx90b4y9pEQIw== X-Google-Smtp-Source: AGHT+IG0WF2Jny6ZWJmZQrbhjeHmT5dWJZVKvAqfbUfYdtflUwesXPXxQcoOgSBzCaN3QeBcNxC23g== X-Received: by 2002:ad4:5b83:0:b0:66d:169a:d41c with SMTP id 3-20020ad45b83000000b0066d169ad41cmr32381398qvp.19.1699308530828; Mon, 06 Nov 2023 14:08:50 -0800 (PST) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id t2-20020a0cef02000000b0064f53943626sm3799820qvr.89.2023.11.06.14.08.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:08:50 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, linux-fsdevel@vger.kernel.org, brauner@kernel.org Subject: [PATCH 14/18] btrfs: switch to the new mount API Date: Mon, 6 Nov 2023 17:08:22 -0500 Message-ID: <2a6839a7f8a7769e13d03f39064f96180fba7432.1699308010.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Now that we have all of the parts in place to use the new mount API, switch our fs_type to use the new callbacks. There are a few things that have to be done at the same time because of the order of operations changes that come along with the new mount API. These must be done in the same patch otherwise things will go wrong. 1. Export and use btrfs_check_options in open_ctree(). This is because the options are done ahead of time, and we need to check them once we have the feature flags loaded. 2. Update the free space cache settings. Since we're coming in with the options already set we need to make sure we don't undo what the user has asked for. 3. Set our sb_flags at init_fs_context time, the fs_context stuff is trying to manage the sb_flagss itself, so move that into init_fs_context and out of the fill super part. Additionally I've marked the unused functions with __maybe_unused and will remove them in a future patch. Signed-off-by: Josef Bacik --- fs/btrfs/disk-io.c | 5 +-- fs/btrfs/super.c | 88 ++++++++++++++++++++++++++-------------------- fs/btrfs/super.h | 2 ++ 3 files changed, 54 insertions(+), 41 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index c70e507a28d0..ce861f4baf47 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3295,9 +3295,10 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device */ btrfs_set_free_space_cache_settings(fs_info); - ret = btrfs_parse_options(fs_info, options, sb->s_flags); - if (ret) + if (!btrfs_check_options(fs_info, &fs_info->mount_opt, sb->s_flags)) { + ret = -EINVAL; goto fail_alloc; + } ret = btrfs_check_features(fs_info, !sb_rdonly(sb)); if (ret < 0) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index e2ac0801211d..a99af94a7409 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -304,7 +304,7 @@ static const struct constant_table btrfs_parameter_fragment[] = { }; #endif -static const struct fs_parameter_spec btrfs_fs_parameters[] __maybe_unused = { +static const struct fs_parameter_spec btrfs_fs_parameters[] = { fsparam_flag_no("acl", Opt_acl), fsparam_flag("clear_cache", Opt_clear_cache), fsparam_u32("commit", Opt_commit_interval), @@ -747,8 +747,8 @@ static bool check_ro_option(struct btrfs_fs_info *fs_info, return false; } -static bool check_options(struct btrfs_fs_info *info, unsigned long *mount_opt, - unsigned long flags) +bool btrfs_check_options(struct btrfs_fs_info *info, unsigned long *mount_opt, + unsigned long flags) { if (!(flags & SB_RDONLY) && (check_ro_option(info, *mount_opt, BTRFS_MOUNT_NOLOGREPLAY, "nologreplay") || @@ -783,18 +783,6 @@ static bool check_options(struct btrfs_fs_info *info, unsigned long *mount_opt, void btrfs_set_free_space_cache_settings(struct btrfs_fs_info *fs_info) { - if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) - btrfs_set_opt(fs_info->mount_opt, FREE_SPACE_TREE); - else if (btrfs_free_space_cache_v1_active(fs_info)) { - if (btrfs_is_zoned(fs_info)) { - btrfs_info(fs_info, - "zoned: clearing existing space cache"); - btrfs_set_super_cache_generation(fs_info->super_copy, 0); - } else { - btrfs_set_opt(fs_info->mount_opt, SPACE_CACHE); - } - } - if (fs_info->sectorsize < PAGE_SIZE) { btrfs_clear_opt(fs_info->mount_opt, SPACE_CACHE); if (!btrfs_test_opt(fs_info, FREE_SPACE_TREE)) { @@ -804,6 +792,35 @@ void btrfs_set_free_space_cache_settings(struct btrfs_fs_info *fs_info) btrfs_set_opt(fs_info->mount_opt, FREE_SPACE_TREE); } } + + /* + * At this point our mount options are populated, so we only mess with + * these settings if we don't have any settings already. + */ + if (btrfs_test_opt(fs_info, FREE_SPACE_TREE)) + return; + + if (btrfs_is_zoned(fs_info) && + btrfs_free_space_cache_v1_active(fs_info)) { + btrfs_info(fs_info, "zoned: clearing existing space cache"); + btrfs_set_super_cache_generation(fs_info->super_copy, 0); + return; + } + + if (btrfs_test_opt(fs_info, SPACE_CACHE)) + return; + + if (btrfs_test_opt(fs_info, NOSPACECACHE)) + return; + + /* + * At this point we don't have explicit options set by the user, set + * them ourselves based on the state of the file system. + */ + if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) + btrfs_set_opt(fs_info->mount_opt, FREE_SPACE_TREE); + else if (btrfs_free_space_cache_v1_active(fs_info)) + btrfs_set_opt(fs_info->mount_opt, SPACE_CACHE); } static int parse_rescue_options(struct btrfs_fs_info *info, const char *options) @@ -1340,7 +1357,7 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, } } out: - if (!ret && !check_options(info, &info->mount_opt, new_flags)) + if (!ret && !btrfs_check_options(info, &info->mount_opt, new_flags)) ret = -EINVAL; return ret; } @@ -1641,10 +1658,6 @@ static int btrfs_fill_super(struct super_block *sb, #endif sb->s_xattr = btrfs_xattr_handlers; sb->s_time_gran = 1; -#ifdef CONFIG_BTRFS_FS_POSIX_ACL - sb->s_flags |= SB_POSIXACL; -#endif - sb->s_flags |= SB_I_VERSION; sb->s_iflags |= SB_I_CGROUPWB; err = super_setup_bdi(sb); @@ -1924,7 +1937,7 @@ static struct dentry *mount_subvol(const char *subvol_name, u64 subvol_objectid, * Note: This is based on mount_bdev from fs/super.c with a few additions * for multiple device setup. Make sure to keep it in sync. */ -static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, +static __maybe_unused struct dentry *btrfs_mount_root(struct file_system_type *fs_type, int flags, const char *device_name, void *data) { struct block_device *bdev = NULL; @@ -2057,7 +2070,7 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, * 3. Call mount_subvol() to get the dentry of subvolume. Since there is * "btrfs subvolume set-default", mount_subvol() is called always. */ -static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, +static __maybe_unused struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, const char *device_name, void *data) { struct vfsmount *mnt_root; @@ -2521,7 +2534,7 @@ static int btrfs_reconfigure(struct fs_context *fc) set_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state); if (!mount_reconfigure && - !check_options(fs_info, &ctx->mount_opt, fc->sb_flags)) + !btrfs_check_options(fs_info, &ctx->mount_opt, fc->sb_flags)) return -EINVAL; ret = btrfs_check_features(fs_info, !(fc->sb_flags & SB_RDONLY)); @@ -3189,7 +3202,7 @@ static const struct fs_context_operations btrfs_fs_context_ops = { .free = btrfs_free_fs_context, }; -static int __maybe_unused btrfs_init_fs_context(struct fs_context *fc) +static int btrfs_init_fs_context(struct fs_context *fc) { struct btrfs_fs_context *ctx; @@ -3210,24 +3223,22 @@ static int __maybe_unused btrfs_init_fs_context(struct fs_context *fc) ctx->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL; } +#ifdef CONFIG_BTRFS_FS_POSIX_ACL + fc->sb_flags |= SB_POSIXACL; +#endif + fc->sb_flags |= SB_I_VERSION; + return 0; } static struct file_system_type btrfs_fs_type = { - .owner = THIS_MODULE, - .name = "btrfs", - .mount = btrfs_mount, - .kill_sb = btrfs_kill_super, - .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA, -}; - -static struct file_system_type btrfs_root_fs_type = { - .owner = THIS_MODULE, - .name = "btrfs", - .mount = btrfs_mount_root, - .kill_sb = btrfs_kill_super, - .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_ALLOW_IDMAP, -}; + .owner = THIS_MODULE, + .name = "btrfs", + .init_fs_context = btrfs_init_fs_context, + .parameters = btrfs_fs_parameters, + .kill_sb = btrfs_kill_super, + .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, + }; MODULE_ALIAS_FS("btrfs"); @@ -3440,7 +3451,6 @@ static const struct super_operations btrfs_super_ops = { .destroy_inode = btrfs_destroy_inode, .free_inode = btrfs_free_inode, .statfs = btrfs_statfs, - .remount_fs = btrfs_remount, .freeze_fs = btrfs_freeze, .unfreeze_fs = btrfs_unfreeze, }; diff --git a/fs/btrfs/super.h b/fs/btrfs/super.h index 7c1cd7527e76..7f6577d69902 100644 --- a/fs/btrfs/super.h +++ b/fs/btrfs/super.h @@ -3,6 +3,8 @@ #ifndef BTRFS_SUPER_H #define BTRFS_SUPER_H +bool btrfs_check_options(struct btrfs_fs_info *info, unsigned long *mount_opt, + unsigned long flags); int btrfs_parse_options(struct btrfs_fs_info *info, char *options, unsigned long new_flags); int btrfs_sync_fs(struct super_block *sb, int wait); From patchwork Mon Nov 6 22:08:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13447541 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9119C0018C for ; Mon, 6 Nov 2023 22:09:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233263AbjKFWJB (ORCPT ); Mon, 6 Nov 2023 17:09:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233258AbjKFWIz (ORCPT ); Mon, 6 Nov 2023 17:08:55 -0500 Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C42CED71 for ; Mon, 6 Nov 2023 14:08:52 -0800 (PST) Received: by mail-qk1-x72f.google.com with SMTP id af79cd13be357-778ac9c898dso260493685a.0 for ; Mon, 06 Nov 2023 14:08:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1699308532; x=1699913332; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=reEakIOm3rrykETmz3iMDC9rTy9UEkj05xNfQfA4/Qo=; b=CRGWLn5MbEeaHXzo4e+YS0XQhWRmuGRtuzzxc/at5RwjNSz8aEvYN7RpjxZ6MBL6k8 4K/pbPTxNrJ++Tz7NgN9VCtxNzH3v3JflbikWSNi4oy7aa5hSNhx0fTzcSyKbUdARZhT 0cQ9Sb4H/ohGIpFDomFEWhvGgWw4o1d7bS3lpzUlHV7geXTJny0AzwaDAzZuYwO17mlt dWd47aVTEHuxobJa5c3QfuNGjuSTBOxLl92bL10ZykQmHk8Rg3niQyPGwmYcc5EJS6+u b7H+4ScNGTWnQwsXTIVsOVv5I3oYfXc9tvpqG2mJ+ASWoLaxAnPl1E10TmokUdf3DBNi dUnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699308532; x=1699913332; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=reEakIOm3rrykETmz3iMDC9rTy9UEkj05xNfQfA4/Qo=; b=D5XpGcHLlfCC7ErcKhVNSfjk8/QAxjt29tJthNV1gm7TvCyR33If3sDYDM5wNuyVLP tGE3epiRplc4HMRjcxqjfUsiVmzSGJd5718cQkQ9B8zfiSaVQKFl9XXY/EIlRlHY4VBz Z44xHfjbfAMPc1/6d85FYfvarS/+lnX7Qa9o0kZvKwm4L4iFNo7QGXhwOymO8T14xZu/ D3kleMl4QhjLUNDMjJarNA9p3xCm8vh7iAVCnLcJPB+pe8fraqq4ESGLscHVt7z68y/C /txVEvjJtAsB30TI3MyU3Av8o9EjkghRmgL53bFo9dq7G5Rbb9s8g2cHLlRsuvQZVNXr J3CQ== X-Gm-Message-State: AOJu0Yw4bv4zlQJAeypS5NX58JhuNyaO7i8Wn5Ima+iAdVC6AK/z7Emz XDi0O6wSW8XQmJ4/ks2pYCyGPeinc1/kh/VxOwFINQ== X-Google-Smtp-Source: AGHT+IFYfPGuFoc9TZeLp+hR3yvZR4SS9i76z2acWjsVd3QfptcaKByxxEZPVsJmqAjdUV1XgESIsg== X-Received: by 2002:a05:620a:44d2:b0:775:9c22:e901 with SMTP id y18-20020a05620a44d200b007759c22e901mr31734685qkp.15.1699308531791; Mon, 06 Nov 2023 14:08:51 -0800 (PST) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id y13-20020a37e30d000000b007759e9b0eb8sm3660393qki.99.2023.11.06.14.08.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:08:51 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, linux-fsdevel@vger.kernel.org, brauner@kernel.org Subject: [PATCH 15/18] btrfs: move the device specific mount options to super.c Date: Mon, 6 Nov 2023 17:08:23 -0500 Message-ID: <691405bb49db78cc585dab67111835ddde69b2e7.1699308010.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We add these mount options based on the fs_devices settings, which can be set once we've opened the fs_devices. Move these into their own helper and call it from get_tree_super. Signed-off-by: Josef Bacik --- fs/btrfs/disk-io.c | 23 ----------------------- fs/btrfs/super.c | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index ce861f4baf47..50ed7ece0840 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3483,29 +3483,6 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device goto fail_cleaner; } - if (!btrfs_test_opt(fs_info, NOSSD) && - !fs_info->fs_devices->rotating) { - btrfs_set_and_info(fs_info, SSD, "enabling ssd optimizations"); - } - - /* - * For devices supporting discard turn on discard=async automatically, - * unless it's already set or disabled. This could be turned off by - * nodiscard for the same mount. - * - * The zoned mode piggy backs on the discard functionality for - * resetting a zone. There is no reason to delay the zone reset as it is - * fast enough. So, do not enable async discard for zoned mode. - */ - if (!(btrfs_test_opt(fs_info, DISCARD_SYNC) || - btrfs_test_opt(fs_info, DISCARD_ASYNC) || - btrfs_test_opt(fs_info, NODISCARD)) && - fs_info->fs_devices->discardable && - !btrfs_is_zoned(fs_info)) { - btrfs_set_and_info(fs_info, DISCARD_ASYNC, - "auto enabling async discard"); - } - ret = btrfs_read_qgroup_config(fs_info); if (ret) goto fail_trans_kthread; diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index a99af94a7409..e67578dc48de 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -823,6 +823,29 @@ void btrfs_set_free_space_cache_settings(struct btrfs_fs_info *fs_info) btrfs_set_opt(fs_info->mount_opt, SPACE_CACHE); } +static void set_device_specific_options(struct btrfs_fs_info *fs_info) +{ + if (!btrfs_test_opt(fs_info, NOSSD) && + !fs_info->fs_devices->rotating) + btrfs_set_opt(fs_info->mount_opt, SSD); + + /* + * For devices supporting discard turn on discard=async automatically, + * unless it's already set or disabled. This could be turned off by + * nodiscard for the same mount. + * + * The zoned mode piggy backs on the discard functionality for + * resetting a zone. There is no reason to delay the zone reset as it is + * fast enough. So, do not enable async discard for zoned mode. + */ + if (!(btrfs_test_opt(fs_info, DISCARD_SYNC) || + btrfs_test_opt(fs_info, DISCARD_ASYNC) || + btrfs_test_opt(fs_info, NODISCARD)) && + fs_info->fs_devices->discardable && + !btrfs_is_zoned(fs_info)) + btrfs_set_opt(fs_info->mount_opt, DISCARD_ASYNC); +} + static int parse_rescue_options(struct btrfs_fs_info *info, const char *options) { char *opts; @@ -2913,6 +2936,8 @@ static int btrfs_get_tree_super(struct fs_context *fc) goto error; } + set_device_specific_options(fs_info); + if (s->s_root) { btrfs_close_devices(fs_devices); if ((fc->sb_flags ^ s->s_flags) & SB_RDONLY) From patchwork Mon Nov 6 22:08:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13447544 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8AD7C4167D for ; Mon, 6 Nov 2023 22:09:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233267AbjKFWJC (ORCPT ); Mon, 6 Nov 2023 17:09:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233252AbjKFWI7 (ORCPT ); Mon, 6 Nov 2023 17:08:59 -0500 Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 837E2183 for ; Mon, 6 Nov 2023 14:08:54 -0800 (PST) Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-77784edc2edso328597885a.1 for ; Mon, 06 Nov 2023 14:08:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1699308533; x=1699913333; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=rZCWLuPRM7Thgi4A1NOtPXGJ/UOYIa1zCCk9HOaESuA=; b=OpE++HsIzvscjrqEcSby94A9qjv3ykutvH9ZCU4YE/6c1KCHzgqFllFdIacaCI77Yb lLXxcQwFjthYCSkYHnc735fpnOVzgUTklKFfJIJk6+cEM/VLpFRJaZZcqPLf2JvgokyL 3tao27xy0kho0GXHtP5OERN7bGsELOk2k1C+4ZumQdRDUgD3G4loNn2W2hVKhqteag9g 7pWGuRA9u6ak3j31pwVsZjx7DLNsHnXPFnsPdd0rr0b+tWM7r7eEaflJB2byrLGq6hgv kxj2pALK/yee6Z4Uwi28KecG8oWTFiyFS4ng6T+2n2lWBHq7uPItH2wT5iSXMeQhcRYe G1ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699308533; x=1699913333; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rZCWLuPRM7Thgi4A1NOtPXGJ/UOYIa1zCCk9HOaESuA=; b=hAD0k59k5RqnYN1Vb4mcxCSKOhEeuo1BjnaR0UqgoXWvNuK+XAPTRNr8KUbemrbLXN AP2WY7zk7agqMQtK1AL0GQXdrSOn3b59vrkJsyEtbUbM5Y/EKLvTWZFV4CuNvhSaCZQC gAv0NK3ypEPFiqlTIkDiOM7I8PF+wkgXMnISEG3N6xqvg+rwDBIBm8+mIGJxOsDRFEMv t28UmjpMWjMnP7h0NZGf7go+AyeAZ9CD+x3OQPjdcvJSTBDdpkH7hbjzy9Y+QCtCO/9+ rob1MohcnUIQ6NPbz3sQ+NUYjAbkqfpA+ek5ZeWeGwC9wX6jQ091hjvPmrLM1z5Qgsd7 7lvA== X-Gm-Message-State: AOJu0YwyvCPlgeJOxRK2wvLrd319ayi1qMhLr32BtNGhRi6Rdekhtsoy 3dCoeZyS1lMG1+p7iEZgVuxkv/+6yX3IiS0Mkvn/AQ== X-Google-Smtp-Source: AGHT+IG+MBvvG7HRsg7V/qEBPMXoBwscAmRUxrx2yDbOuOBrf6K1c+GatgwEPOmkCO/VWTGekJj2aQ== X-Received: by 2002:a05:620a:1117:b0:779:f645:c203 with SMTP id o23-20020a05620a111700b00779f645c203mr30626738qkk.29.1699308533058; Mon, 06 Nov 2023 14:08:53 -0800 (PST) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id d1-20020a37c401000000b0076f058f5834sm3658195qki.61.2023.11.06.14.08.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:08:52 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, linux-fsdevel@vger.kernel.org, brauner@kernel.org Subject: [PATCH 16/18] btrfs: remove old mount API code Date: Mon, 6 Nov 2023 17:08:24 -0500 Message-ID: <1ad828ba077084571689768f5fa02e047cf17be3.1699308010.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Now that we've switched to the new mount api, remove the old stuff. Signed-off-by: Josef Bacik --- fs/btrfs/fs.h | 14 - fs/btrfs/super.c | 1078 +--------------------------------------------- fs/btrfs/super.h | 2 - 3 files changed, 13 insertions(+), 1081 deletions(-) diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index ecfa13a9c2cf..41be64e7c045 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -961,20 +961,6 @@ void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag, #define btrfs_test_opt(fs_info, opt) ((fs_info)->mount_opt & \ BTRFS_MOUNT_##opt) -#define btrfs_set_and_info(fs_info, opt, fmt, args...) \ -do { \ - if (!btrfs_test_opt(fs_info, opt)) \ - btrfs_info(fs_info, fmt, ##args); \ - btrfs_set_opt(fs_info->mount_opt, opt); \ -} while (0) - -#define btrfs_clear_and_info(fs_info, opt, fmt, args...) \ -do { \ - if (btrfs_test_opt(fs_info, opt)) \ - btrfs_info(fs_info, fmt, ##args); \ - btrfs_clear_opt(fs_info->mount_opt, opt); \ -} while (0) - static inline int btrfs_fs_closing(struct btrfs_fs_info *fs_info) { /* Do it this way so we only ever do one test_bit in the normal case. */ diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index e67578dc48de..6a9561a336f3 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -65,19 +65,7 @@ #include static const struct super_operations btrfs_super_ops; - -/* - * Types for mounting the default subvolume and a subvolume explicitly - * requested by subvol=/path. That way the callchain is straightforward and we - * don't have to play tricks with the mount options and recursive calls to - * btrfs_mount. - * - * The new btrfs_root_fs_type also servers as a tag for the bdev_holder. - */ static struct file_system_type btrfs_fs_type; -static struct file_system_type btrfs_root_fs_type; - -static int btrfs_remount(struct super_block *sb, int *flags, char *data); static void btrfs_put_super(struct super_block *sb) { @@ -99,7 +87,7 @@ struct btrfs_fs_context { }; enum { - Opt_acl, Opt_noacl, + Opt_acl, Opt_clear_cache, Opt_commit_interval, Opt_compress, @@ -109,27 +97,26 @@ enum { Opt_degraded, Opt_device, Opt_fatal_errors, - Opt_flushoncommit, Opt_noflushoncommit, + Opt_flushoncommit, Opt_max_inline, - Opt_barrier, Opt_nobarrier, - Opt_datacow, Opt_nodatacow, - Opt_datasum, Opt_nodatasum, - Opt_defrag, Opt_nodefrag, - Opt_discard, Opt_nodiscard, + Opt_barrier, + Opt_datacow, + Opt_datasum, + Opt_defrag, + Opt_discard, Opt_discard_mode, - Opt_norecovery, Opt_ratio, Opt_rescan_uuid_tree, Opt_skip_balance, - Opt_space_cache, Opt_no_space_cache, + Opt_space_cache, Opt_space_cache_version, - Opt_ssd, Opt_nossd, - Opt_ssd_spread, Opt_nossd_spread, + Opt_ssd, + Opt_ssd_spread, Opt_subvol, Opt_subvol_empty, Opt_subvolid, Opt_thread_pool, - Opt_treelog, Opt_notreelog, + Opt_treelog, Opt_user_subvol_rm_allowed, /* Rescue options */ @@ -142,10 +129,10 @@ enum { /* Deprecated options */ Opt_recovery, - Opt_inode_cache, Opt_noinode_cache, + Opt_inode_cache, /* Debugging options */ - Opt_enospc_debug, Opt_noenospc_debug, + Opt_enospc_debug, #ifdef CONFIG_BTRFS_DEBUG Opt_fragment, Opt_fragment_data, Opt_fragment_metadata, Opt_fragment_all, #endif @@ -155,88 +142,6 @@ enum { Opt_err, }; -static const match_table_t tokens = { - {Opt_acl, "acl"}, - {Opt_noacl, "noacl"}, - {Opt_clear_cache, "clear_cache"}, - {Opt_commit_interval, "commit=%u"}, - {Opt_compress, "compress"}, - {Opt_compress_type, "compress=%s"}, - {Opt_compress_force, "compress-force"}, - {Opt_compress_force_type, "compress-force=%s"}, - {Opt_degraded, "degraded"}, - {Opt_device, "device=%s"}, - {Opt_fatal_errors, "fatal_errors=%s"}, - {Opt_flushoncommit, "flushoncommit"}, - {Opt_noflushoncommit, "noflushoncommit"}, - {Opt_inode_cache, "inode_cache"}, - {Opt_noinode_cache, "noinode_cache"}, - {Opt_max_inline, "max_inline=%s"}, - {Opt_barrier, "barrier"}, - {Opt_nobarrier, "nobarrier"}, - {Opt_datacow, "datacow"}, - {Opt_nodatacow, "nodatacow"}, - {Opt_datasum, "datasum"}, - {Opt_nodatasum, "nodatasum"}, - {Opt_defrag, "autodefrag"}, - {Opt_nodefrag, "noautodefrag"}, - {Opt_discard, "discard"}, - {Opt_discard_mode, "discard=%s"}, - {Opt_nodiscard, "nodiscard"}, - {Opt_norecovery, "norecovery"}, - {Opt_ratio, "metadata_ratio=%u"}, - {Opt_rescan_uuid_tree, "rescan_uuid_tree"}, - {Opt_skip_balance, "skip_balance"}, - {Opt_space_cache, "space_cache"}, - {Opt_no_space_cache, "nospace_cache"}, - {Opt_space_cache_version, "space_cache=%s"}, - {Opt_ssd, "ssd"}, - {Opt_nossd, "nossd"}, - {Opt_ssd_spread, "ssd_spread"}, - {Opt_nossd_spread, "nossd_spread"}, - {Opt_subvol, "subvol=%s"}, - {Opt_subvol_empty, "subvol="}, - {Opt_subvolid, "subvolid=%s"}, - {Opt_thread_pool, "thread_pool=%u"}, - {Opt_treelog, "treelog"}, - {Opt_notreelog, "notreelog"}, - {Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"}, - - /* Rescue options */ - {Opt_rescue, "rescue=%s"}, - /* Deprecated, with alias rescue=nologreplay */ - {Opt_nologreplay, "nologreplay"}, - /* Deprecated, with alias rescue=usebackuproot */ - {Opt_usebackuproot, "usebackuproot"}, - - /* Deprecated options */ - {Opt_recovery, "recovery"}, - - /* Debugging options */ - {Opt_enospc_debug, "enospc_debug"}, - {Opt_noenospc_debug, "noenospc_debug"}, -#ifdef CONFIG_BTRFS_DEBUG - {Opt_fragment_data, "fragment=data"}, - {Opt_fragment_metadata, "fragment=metadata"}, - {Opt_fragment_all, "fragment=all"}, -#endif -#ifdef CONFIG_BTRFS_FS_REF_VERIFY - {Opt_ref_verify, "ref_verify"}, -#endif - {Opt_err, NULL}, -}; - -static const match_table_t rescue_tokens = { - {Opt_usebackuproot, "usebackuproot"}, - {Opt_nologreplay, "nologreplay"}, - {Opt_ignorebadroots, "ignorebadroots"}, - {Opt_ignorebadroots, "ibadroots"}, - {Opt_ignoredatacsums, "ignoredatacsums"}, - {Opt_ignoredatacsums, "idatacsums"}, - {Opt_rescue_all, "all"}, - {Opt_err, NULL}, -}; - enum { Opt_fatal_errors_panic, Opt_fatal_errors_bug, @@ -846,660 +751,6 @@ static void set_device_specific_options(struct btrfs_fs_info *fs_info) btrfs_set_opt(fs_info->mount_opt, DISCARD_ASYNC); } -static int parse_rescue_options(struct btrfs_fs_info *info, const char *options) -{ - char *opts; - char *orig; - char *p; - substring_t args[MAX_OPT_ARGS]; - int ret = 0; - - opts = kstrdup(options, GFP_KERNEL); - if (!opts) - return -ENOMEM; - orig = opts; - - while ((p = strsep(&opts, ":")) != NULL) { - int token; - - if (!*p) - continue; - token = match_token(p, rescue_tokens, args); - switch (token){ - case Opt_usebackuproot: - btrfs_info(info, - "trying to use backup root at mount time"); - btrfs_set_opt(info->mount_opt, USEBACKUPROOT); - break; - case Opt_nologreplay: - btrfs_set_and_info(info, NOLOGREPLAY, - "disabling log replay at mount time"); - break; - case Opt_ignorebadroots: - btrfs_set_and_info(info, IGNOREBADROOTS, - "ignoring bad roots"); - break; - case Opt_ignoredatacsums: - btrfs_set_and_info(info, IGNOREDATACSUMS, - "ignoring data csums"); - break; - case Opt_rescue_all: - btrfs_info(info, "enabling all of the rescue options"); - btrfs_set_and_info(info, IGNOREDATACSUMS, - "ignoring data csums"); - btrfs_set_and_info(info, IGNOREBADROOTS, - "ignoring bad roots"); - btrfs_set_and_info(info, NOLOGREPLAY, - "disabling log replay at mount time"); - break; - case Opt_err: - btrfs_info(info, "unrecognized rescue option '%s'", p); - ret = -EINVAL; - goto out; - default: - break; - } - - } -out: - kfree(orig); - return ret; -} - -/* - * Regular mount options parser. Everything that is needed only when - * reading in a new superblock is parsed here. - * XXX JDM: This needs to be cleaned up for remount. - */ -int btrfs_parse_options(struct btrfs_fs_info *info, char *options, - unsigned long new_flags) -{ - substring_t args[MAX_OPT_ARGS]; - char *p, *num; - int intarg; - int ret = 0; - char *compress_type; - bool compress_force = false; - enum btrfs_compression_type saved_compress_type; - int saved_compress_level; - bool saved_compress_force; - int no_compress = 0; - - /* - * Even the options are empty, we still need to do extra check - * against new flags - */ - if (!options) - goto out; - - while ((p = strsep(&options, ",")) != NULL) { - int token; - if (!*p) - continue; - - token = match_token(p, tokens, args); - switch (token) { - case Opt_degraded: - btrfs_info(info, "allowing degraded mounts"); - btrfs_set_opt(info->mount_opt, DEGRADED); - break; - case Opt_subvol: - case Opt_subvol_empty: - case Opt_subvolid: - case Opt_device: - /* - * These are parsed by btrfs_parse_subvol_options or - * btrfs_parse_device_options and can be ignored here. - */ - break; - case Opt_nodatasum: - btrfs_set_and_info(info, NODATASUM, - "setting nodatasum"); - break; - case Opt_datasum: - if (btrfs_test_opt(info, NODATASUM)) { - if (btrfs_test_opt(info, NODATACOW)) - btrfs_info(info, - "setting datasum, datacow enabled"); - else - btrfs_info(info, "setting datasum"); - } - btrfs_clear_opt(info->mount_opt, NODATACOW); - btrfs_clear_opt(info->mount_opt, NODATASUM); - break; - case Opt_nodatacow: - if (!btrfs_test_opt(info, NODATACOW)) { - if (!btrfs_test_opt(info, COMPRESS) || - !btrfs_test_opt(info, FORCE_COMPRESS)) { - btrfs_info(info, - "setting nodatacow, compression disabled"); - } else { - btrfs_info(info, "setting nodatacow"); - } - } - btrfs_clear_opt(info->mount_opt, COMPRESS); - btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS); - btrfs_set_opt(info->mount_opt, NODATACOW); - btrfs_set_opt(info->mount_opt, NODATASUM); - break; - case Opt_datacow: - btrfs_clear_and_info(info, NODATACOW, - "setting datacow"); - break; - case Opt_compress_force: - case Opt_compress_force_type: - compress_force = true; - fallthrough; - case Opt_compress: - case Opt_compress_type: - saved_compress_type = btrfs_test_opt(info, - COMPRESS) ? - info->compress_type : BTRFS_COMPRESS_NONE; - saved_compress_force = - btrfs_test_opt(info, FORCE_COMPRESS); - saved_compress_level = info->compress_level; - if (token == Opt_compress || - token == Opt_compress_force || - strncmp(args[0].from, "zlib", 4) == 0) { - compress_type = "zlib"; - - info->compress_type = BTRFS_COMPRESS_ZLIB; - info->compress_level = BTRFS_ZLIB_DEFAULT_LEVEL; - /* - * args[0] contains uninitialized data since - * for these tokens we don't expect any - * parameter. - */ - if (token != Opt_compress && - token != Opt_compress_force) - info->compress_level = - btrfs_compress_str2level( - BTRFS_COMPRESS_ZLIB, - args[0].from + 4); - btrfs_set_opt(info->mount_opt, COMPRESS); - btrfs_clear_opt(info->mount_opt, NODATACOW); - btrfs_clear_opt(info->mount_opt, NODATASUM); - no_compress = 0; - } else if (strncmp(args[0].from, "lzo", 3) == 0) { - compress_type = "lzo"; - info->compress_type = BTRFS_COMPRESS_LZO; - info->compress_level = 0; - btrfs_set_opt(info->mount_opt, COMPRESS); - btrfs_clear_opt(info->mount_opt, NODATACOW); - btrfs_clear_opt(info->mount_opt, NODATASUM); - btrfs_set_fs_incompat(info, COMPRESS_LZO); - no_compress = 0; - } else if (strncmp(args[0].from, "zstd", 4) == 0) { - compress_type = "zstd"; - info->compress_type = BTRFS_COMPRESS_ZSTD; - info->compress_level = - btrfs_compress_str2level( - BTRFS_COMPRESS_ZSTD, - args[0].from + 4); - btrfs_set_opt(info->mount_opt, COMPRESS); - btrfs_clear_opt(info->mount_opt, NODATACOW); - btrfs_clear_opt(info->mount_opt, NODATASUM); - btrfs_set_fs_incompat(info, COMPRESS_ZSTD); - no_compress = 0; - } else if (strncmp(args[0].from, "no", 2) == 0) { - compress_type = "no"; - info->compress_level = 0; - info->compress_type = 0; - btrfs_clear_opt(info->mount_opt, COMPRESS); - btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS); - compress_force = false; - no_compress++; - } else { - btrfs_err(info, "unrecognized compression value %s", - args[0].from); - ret = -EINVAL; - goto out; - } - - if (compress_force) { - btrfs_set_opt(info->mount_opt, FORCE_COMPRESS); - } else { - /* - * If we remount from compress-force=xxx to - * compress=xxx, we need clear FORCE_COMPRESS - * flag, otherwise, there is no way for users - * to disable forcible compression separately. - */ - btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS); - } - if (no_compress == 1) { - btrfs_info(info, "use no compression"); - } else if ((info->compress_type != saved_compress_type) || - (compress_force != saved_compress_force) || - (info->compress_level != saved_compress_level)) { - btrfs_info(info, "%s %s compression, level %d", - (compress_force) ? "force" : "use", - compress_type, info->compress_level); - } - compress_force = false; - break; - case Opt_ssd: - btrfs_set_and_info(info, SSD, - "enabling ssd optimizations"); - btrfs_clear_opt(info->mount_opt, NOSSD); - break; - case Opt_ssd_spread: - btrfs_set_and_info(info, SSD, - "enabling ssd optimizations"); - btrfs_set_and_info(info, SSD_SPREAD, - "using spread ssd allocation scheme"); - btrfs_clear_opt(info->mount_opt, NOSSD); - break; - case Opt_nossd: - btrfs_set_opt(info->mount_opt, NOSSD); - btrfs_clear_and_info(info, SSD, - "not using ssd optimizations"); - fallthrough; - case Opt_nossd_spread: - btrfs_clear_and_info(info, SSD_SPREAD, - "not using spread ssd allocation scheme"); - break; - case Opt_barrier: - btrfs_clear_and_info(info, NOBARRIER, - "turning on barriers"); - break; - case Opt_nobarrier: - btrfs_set_and_info(info, NOBARRIER, - "turning off barriers"); - break; - case Opt_thread_pool: - ret = match_int(&args[0], &intarg); - if (ret) { - btrfs_err(info, "unrecognized thread_pool value %s", - args[0].from); - goto out; - } else if (intarg == 0) { - btrfs_err(info, "invalid value 0 for thread_pool"); - ret = -EINVAL; - goto out; - } - info->thread_pool_size = intarg; - break; - case Opt_max_inline: - num = match_strdup(&args[0]); - if (num) { - info->max_inline = memparse(num, NULL); - kfree(num); - - if (info->max_inline) { - info->max_inline = min_t(u64, - info->max_inline, - info->sectorsize); - } - btrfs_info(info, "max_inline at %llu", - info->max_inline); - } else { - ret = -ENOMEM; - goto out; - } - break; - case Opt_acl: -#ifdef CONFIG_BTRFS_FS_POSIX_ACL - info->sb->s_flags |= SB_POSIXACL; - break; -#else - btrfs_err(info, "support for ACL not compiled in!"); - ret = -EINVAL; - goto out; -#endif - case Opt_noacl: - info->sb->s_flags &= ~SB_POSIXACL; - break; - case Opt_notreelog: - btrfs_set_and_info(info, NOTREELOG, - "disabling tree log"); - break; - case Opt_treelog: - btrfs_clear_and_info(info, NOTREELOG, - "enabling tree log"); - break; - case Opt_norecovery: - case Opt_nologreplay: - btrfs_warn(info, - "'nologreplay' is deprecated, use 'rescue=nologreplay' instead"); - btrfs_set_and_info(info, NOLOGREPLAY, - "disabling log replay at mount time"); - break; - case Opt_flushoncommit: - btrfs_set_and_info(info, FLUSHONCOMMIT, - "turning on flush-on-commit"); - break; - case Opt_noflushoncommit: - btrfs_clear_and_info(info, FLUSHONCOMMIT, - "turning off flush-on-commit"); - break; - case Opt_ratio: - ret = match_int(&args[0], &intarg); - if (ret) { - btrfs_err(info, "unrecognized metadata_ratio value %s", - args[0].from); - goto out; - } - info->metadata_ratio = intarg; - btrfs_info(info, "metadata ratio %u", - info->metadata_ratio); - break; - case Opt_discard: - case Opt_discard_mode: - if (token == Opt_discard || - strcmp(args[0].from, "sync") == 0) { - btrfs_clear_opt(info->mount_opt, DISCARD_ASYNC); - btrfs_set_and_info(info, DISCARD_SYNC, - "turning on sync discard"); - } else if (strcmp(args[0].from, "async") == 0) { - btrfs_clear_opt(info->mount_opt, DISCARD_SYNC); - btrfs_set_and_info(info, DISCARD_ASYNC, - "turning on async discard"); - } else { - btrfs_err(info, "unrecognized discard mode value %s", - args[0].from); - ret = -EINVAL; - goto out; - } - btrfs_clear_opt(info->mount_opt, NODISCARD); - break; - case Opt_nodiscard: - btrfs_clear_and_info(info, DISCARD_SYNC, - "turning off discard"); - btrfs_clear_and_info(info, DISCARD_ASYNC, - "turning off async discard"); - btrfs_set_opt(info->mount_opt, NODISCARD); - break; - case Opt_space_cache: - case Opt_space_cache_version: - /* - * We already set FREE_SPACE_TREE above because we have - * compat_ro(FREE_SPACE_TREE) set, and we aren't going - * to allow v1 to be set for extent tree v2, simply - * ignore this setting if we're extent tree v2. - * - * For subpage blocksize we don't allow space cache v1, - * and we'll turn on v2, so we can skip the settings - * here as well. - */ - if (btrfs_fs_incompat(info, EXTENT_TREE_V2) || - info->sectorsize < PAGE_SIZE) - break; - if (token == Opt_space_cache || - strcmp(args[0].from, "v1") == 0) { - btrfs_clear_opt(info->mount_opt, - FREE_SPACE_TREE); - btrfs_set_and_info(info, SPACE_CACHE, - "enabling disk space caching"); - } else if (strcmp(args[0].from, "v2") == 0) { - btrfs_clear_opt(info->mount_opt, - SPACE_CACHE); - btrfs_set_and_info(info, FREE_SPACE_TREE, - "enabling free space tree"); - } else { - btrfs_err(info, "unrecognized space_cache value %s", - args[0].from); - ret = -EINVAL; - goto out; - } - break; - case Opt_rescan_uuid_tree: - btrfs_set_opt(info->mount_opt, RESCAN_UUID_TREE); - break; - case Opt_no_space_cache: - /* - * We cannot operate without the free space tree with - * extent tree v2, ignore this option. - */ - if (btrfs_fs_incompat(info, EXTENT_TREE_V2)) - break; - if (btrfs_test_opt(info, SPACE_CACHE)) { - btrfs_clear_and_info(info, SPACE_CACHE, - "disabling disk space caching"); - } - if (btrfs_test_opt(info, FREE_SPACE_TREE)) { - btrfs_clear_and_info(info, FREE_SPACE_TREE, - "disabling free space tree"); - } - break; - case Opt_inode_cache: - case Opt_noinode_cache: - btrfs_warn(info, - "the 'inode_cache' option is deprecated and has no effect since 5.11"); - break; - case Opt_clear_cache: - /* - * We cannot clear the free space tree with extent tree - * v2, ignore this option. - */ - if (btrfs_fs_incompat(info, EXTENT_TREE_V2)) - break; - btrfs_set_and_info(info, CLEAR_CACHE, - "force clearing of disk cache"); - break; - case Opt_user_subvol_rm_allowed: - btrfs_set_opt(info->mount_opt, USER_SUBVOL_RM_ALLOWED); - break; - case Opt_enospc_debug: - btrfs_set_opt(info->mount_opt, ENOSPC_DEBUG); - break; - case Opt_noenospc_debug: - btrfs_clear_opt(info->mount_opt, ENOSPC_DEBUG); - break; - case Opt_defrag: - btrfs_set_and_info(info, AUTO_DEFRAG, - "enabling auto defrag"); - break; - case Opt_nodefrag: - btrfs_clear_and_info(info, AUTO_DEFRAG, - "disabling auto defrag"); - break; - case Opt_recovery: - case Opt_usebackuproot: - btrfs_warn(info, - "'%s' is deprecated, use 'rescue=usebackuproot' instead", - token == Opt_recovery ? "recovery" : - "usebackuproot"); - btrfs_info(info, - "trying to use backup root at mount time"); - btrfs_set_opt(info->mount_opt, USEBACKUPROOT); - break; - case Opt_skip_balance: - btrfs_set_opt(info->mount_opt, SKIP_BALANCE); - break; - case Opt_fatal_errors: - if (strcmp(args[0].from, "panic") == 0) { - btrfs_set_opt(info->mount_opt, - PANIC_ON_FATAL_ERROR); - } else if (strcmp(args[0].from, "bug") == 0) { - btrfs_clear_opt(info->mount_opt, - PANIC_ON_FATAL_ERROR); - } else { - btrfs_err(info, "unrecognized fatal_errors value %s", - args[0].from); - ret = -EINVAL; - goto out; - } - break; - case Opt_commit_interval: - intarg = 0; - ret = match_int(&args[0], &intarg); - if (ret) { - btrfs_err(info, "unrecognized commit_interval value %s", - args[0].from); - ret = -EINVAL; - goto out; - } - if (intarg == 0) { - btrfs_info(info, - "using default commit interval %us", - BTRFS_DEFAULT_COMMIT_INTERVAL); - intarg = BTRFS_DEFAULT_COMMIT_INTERVAL; - } else if (intarg > 300) { - btrfs_warn(info, "excessive commit interval %d", - intarg); - } - info->commit_interval = intarg; - break; - case Opt_rescue: - ret = parse_rescue_options(info, args[0].from); - if (ret < 0) { - btrfs_err(info, "unrecognized rescue value %s", - args[0].from); - goto out; - } - break; -#ifdef CONFIG_BTRFS_DEBUG - case Opt_fragment_all: - btrfs_info(info, "fragmenting all space"); - btrfs_set_opt(info->mount_opt, FRAGMENT_DATA); - btrfs_set_opt(info->mount_opt, FRAGMENT_METADATA); - break; - case Opt_fragment_metadata: - btrfs_info(info, "fragmenting metadata"); - btrfs_set_opt(info->mount_opt, - FRAGMENT_METADATA); - break; - case Opt_fragment_data: - btrfs_info(info, "fragmenting data"); - btrfs_set_opt(info->mount_opt, FRAGMENT_DATA); - break; -#endif -#ifdef CONFIG_BTRFS_FS_REF_VERIFY - case Opt_ref_verify: - btrfs_info(info, "doing ref verification"); - btrfs_set_opt(info->mount_opt, REF_VERIFY); - break; -#endif - case Opt_err: - btrfs_err(info, "unrecognized mount option '%s'", p); - ret = -EINVAL; - goto out; - default: - break; - } - } -out: - if (!ret && !btrfs_check_options(info, &info->mount_opt, new_flags)) - ret = -EINVAL; - return ret; -} - -/* - * Parse mount options that are required early in the mount process. - * - * All other options will be parsed on much later in the mount process and - * only when we need to allocate a new super block. - */ -static int btrfs_parse_device_options(const char *options, blk_mode_t flags) -{ - substring_t args[MAX_OPT_ARGS]; - char *device_name, *opts, *orig, *p; - struct btrfs_device *device = NULL; - int error = 0; - - lockdep_assert_held(&uuid_mutex); - - if (!options) - return 0; - - /* - * strsep changes the string, duplicate it because btrfs_parse_options - * gets called later - */ - opts = kstrdup(options, GFP_KERNEL); - if (!opts) - return -ENOMEM; - orig = opts; - - while ((p = strsep(&opts, ",")) != NULL) { - int token; - - if (!*p) - continue; - - token = match_token(p, tokens, args); - if (token == Opt_device) { - device_name = match_strdup(&args[0]); - if (!device_name) { - error = -ENOMEM; - goto out; - } - device = btrfs_scan_one_device(device_name, flags, false); - kfree(device_name); - if (IS_ERR(device)) { - error = PTR_ERR(device); - goto out; - } - } - } - -out: - kfree(orig); - return error; -} - -/* - * Parse mount options that are related to subvolume id - * - * The value is later passed to mount_subvol() - */ -static int btrfs_parse_subvol_options(const char *options, char **subvol_name, - u64 *subvol_objectid) -{ - substring_t args[MAX_OPT_ARGS]; - char *opts, *orig, *p; - int error = 0; - u64 subvolid; - - if (!options) - return 0; - - /* - * strsep changes the string, duplicate it because - * btrfs_parse_device_options gets called later - */ - opts = kstrdup(options, GFP_KERNEL); - if (!opts) - return -ENOMEM; - orig = opts; - - while ((p = strsep(&opts, ",")) != NULL) { - int token; - if (!*p) - continue; - - token = match_token(p, tokens, args); - switch (token) { - case Opt_subvol: - kfree(*subvol_name); - *subvol_name = match_strdup(&args[0]); - if (!*subvol_name) { - error = -ENOMEM; - goto out; - } - break; - case Opt_subvolid: - error = match_u64(&args[0], &subvolid); - if (error) - goto out; - - /* we want the original fs_tree */ - if (subvolid == 0) - subvolid = BTRFS_FS_TREE_OBJECTID; - - *subvol_objectid = subvolid; - break; - default: - break; - } - } - -out: - kfree(orig); - return error; -} - char *btrfs_get_subvol_name_from_objectid(struct btrfs_fs_info *fs_info, u64 subvol_objectid) { @@ -1863,22 +1114,6 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry) return 0; } -static int btrfs_test_super(struct super_block *s, void *data) -{ - struct btrfs_fs_info *p = data; - struct btrfs_fs_info *fs_info = btrfs_sb(s); - - return fs_info->fs_devices == p->fs_devices; -} - -static int btrfs_set_super(struct super_block *s, void *data) -{ - int err = set_anon_super(s, data); - if (!err) - s->s_fs_info = data; - return err; -} - /* * subvolumes are identified by ino 256 */ @@ -1954,200 +1189,6 @@ static struct dentry *mount_subvol(const char *subvol_name, u64 subvol_objectid, return root; } -/* - * Find a superblock for the given device / mount point. - * - * Note: This is based on mount_bdev from fs/super.c with a few additions - * for multiple device setup. Make sure to keep it in sync. - */ -static __maybe_unused struct dentry *btrfs_mount_root(struct file_system_type *fs_type, - int flags, const char *device_name, void *data) -{ - struct block_device *bdev = NULL; - struct super_block *s; - struct btrfs_device *device = NULL; - struct btrfs_fs_devices *fs_devices = NULL; - struct btrfs_fs_info *fs_info = NULL; - void *new_sec_opts = NULL; - blk_mode_t mode = sb_open_mode(flags); - int error = 0; - - if (data) { - error = security_sb_eat_lsm_opts(data, &new_sec_opts); - if (error) - return ERR_PTR(error); - } - - /* - * Setup a dummy root and fs_info for test/set super. This is because - * we don't actually fill this stuff out until open_ctree, but we need - * then open_ctree will properly initialize the file system specific - * settings later. btrfs_init_fs_info initializes the static elements - * of the fs_info (locks and such) to make cleanup easier if we find a - * superblock with our given fs_devices later on at sget() time. - */ - fs_info = kvzalloc(sizeof(struct btrfs_fs_info), GFP_KERNEL); - if (!fs_info) { - error = -ENOMEM; - goto error_sec_opts; - } - btrfs_init_fs_info(fs_info); - - fs_info->super_copy = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_KERNEL); - fs_info->super_for_commit = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_KERNEL); - if (!fs_info->super_copy || !fs_info->super_for_commit) { - error = -ENOMEM; - goto error_fs_info; - } - - mutex_lock(&uuid_mutex); - error = btrfs_parse_device_options(data, mode); - if (error) { - mutex_unlock(&uuid_mutex); - goto error_fs_info; - } - - /* - * With 'true' passed to btrfs_scan_one_device() (mount time) we expect - * either a valid device or an error. - */ - device = btrfs_scan_one_device(device_name, mode, true); - ASSERT(device != NULL); - if (IS_ERR(device)) { - mutex_unlock(&uuid_mutex); - error = PTR_ERR(device); - goto error_fs_info; - } - - fs_devices = device->fs_devices; - fs_info->fs_devices = fs_devices; - - error = btrfs_open_devices(fs_devices, mode, fs_type); - mutex_unlock(&uuid_mutex); - if (error) - goto error_fs_info; - - if (!(flags & SB_RDONLY) && fs_devices->rw_devices == 0) { - error = -EACCES; - goto error_close_devices; - } - - bdev = fs_devices->latest_dev->bdev; - s = sget(fs_type, btrfs_test_super, btrfs_set_super, flags | SB_NOSEC, - fs_info); - if (IS_ERR(s)) { - error = PTR_ERR(s); - goto error_close_devices; - } - - if (s->s_root) { - btrfs_close_devices(fs_devices); - btrfs_free_fs_info(fs_info); - if ((flags ^ s->s_flags) & SB_RDONLY) - error = -EBUSY; - } else { - snprintf(s->s_id, sizeof(s->s_id), "%pg", bdev); - shrinker_debugfs_rename(&s->s_shrink, "sb-%s:%s", fs_type->name, - s->s_id); - btrfs_sb(s)->bdev_holder = fs_type; - error = btrfs_fill_super(s, fs_devices, data); - } - if (!error) - error = security_sb_set_mnt_opts(s, new_sec_opts, 0, NULL); - security_free_mnt_opts(&new_sec_opts); - if (error) { - deactivate_locked_super(s); - return ERR_PTR(error); - } - - return dget(s->s_root); - -error_close_devices: - btrfs_close_devices(fs_devices); -error_fs_info: - btrfs_free_fs_info(fs_info); -error_sec_opts: - security_free_mnt_opts(&new_sec_opts); - return ERR_PTR(error); -} - -/* - * Mount function which is called by VFS layer. - * - * In order to allow mounting a subvolume directly, btrfs uses mount_subtree() - * which needs vfsmount* of device's root (/). This means device's root has to - * be mounted internally in any case. - * - * Operation flow: - * 1. Parse subvol id related options for later use in mount_subvol(). - * - * 2. Mount device's root (/) by calling vfs_kern_mount(). - * - * NOTE: vfs_kern_mount() is used by VFS to call btrfs_mount() in the - * first place. In order to avoid calling btrfs_mount() again, we use - * different file_system_type which is not registered to VFS by - * register_filesystem() (btrfs_root_fs_type). As a result, - * btrfs_mount_root() is called. The return value will be used by - * mount_subtree() in mount_subvol(). - * - * 3. Call mount_subvol() to get the dentry of subvolume. Since there is - * "btrfs subvolume set-default", mount_subvol() is called always. - */ -static __maybe_unused struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, - const char *device_name, void *data) -{ - struct vfsmount *mnt_root; - struct dentry *root; - char *subvol_name = NULL; - u64 subvol_objectid = 0; - int error = 0; - - error = btrfs_parse_subvol_options(data, &subvol_name, - &subvol_objectid); - if (error) { - kfree(subvol_name); - return ERR_PTR(error); - } - - /* mount device's root (/) */ - mnt_root = vfs_kern_mount(&btrfs_root_fs_type, flags, device_name, data); - if (PTR_ERR_OR_ZERO(mnt_root) == -EBUSY) { - if (flags & SB_RDONLY) { - mnt_root = vfs_kern_mount(&btrfs_root_fs_type, - flags & ~SB_RDONLY, device_name, data); - } else { - mnt_root = vfs_kern_mount(&btrfs_root_fs_type, - flags | SB_RDONLY, device_name, data); - if (IS_ERR(mnt_root)) { - root = ERR_CAST(mnt_root); - kfree(subvol_name); - goto out; - } - - down_write(&mnt_root->mnt_sb->s_umount); - error = btrfs_remount(mnt_root->mnt_sb, &flags, NULL); - up_write(&mnt_root->mnt_sb->s_umount); - if (error < 0) { - root = ERR_PTR(error); - mntput(mnt_root); - kfree(subvol_name); - goto out; - } - } - } - if (IS_ERR(mnt_root)) { - root = ERR_CAST(mnt_root); - kfree(subvol_name); - goto out; - } - - /* mount_subvol() will free subvol_name and mnt_root */ - root = mount_subvol(subvol_name, subvol_objectid, mnt_root); - -out: - return root; -} - static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info, u32 new_pool_size, u32 old_pool_size) { @@ -2323,99 +1364,6 @@ static int btrfs_remount_ro(struct btrfs_fs_info *fs_info) return btrfs_commit_super(fs_info); } -static int btrfs_remount(struct super_block *sb, int *flags, char *data) -{ - struct btrfs_fs_info *fs_info = btrfs_sb(sb); - unsigned old_flags = sb->s_flags; - unsigned long old_opts = fs_info->mount_opt; - unsigned long old_compress_type = fs_info->compress_type; - u64 old_max_inline = fs_info->max_inline; - u32 old_thread_pool_size = fs_info->thread_pool_size; - u32 old_metadata_ratio = fs_info->metadata_ratio; - int ret; - - sync_filesystem(sb); - set_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state); - - if (data) { - void *new_sec_opts = NULL; - - ret = security_sb_eat_lsm_opts(data, &new_sec_opts); - if (!ret) - ret = security_sb_remount(sb, new_sec_opts); - security_free_mnt_opts(&new_sec_opts); - if (ret) - goto restore; - } - - ret = btrfs_parse_options(fs_info, data, *flags); - if (ret) - goto restore; - - ret = btrfs_check_features(fs_info, !(*flags & SB_RDONLY)); - if (ret < 0) - goto restore; - - btrfs_remount_begin(fs_info, old_opts, *flags); - btrfs_resize_thread_pool(fs_info, - fs_info->thread_pool_size, old_thread_pool_size); - - if ((bool)btrfs_test_opt(fs_info, FREE_SPACE_TREE) != - (bool)btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE) && - (!sb_rdonly(sb) || (*flags & SB_RDONLY))) { - btrfs_warn(fs_info, - "remount supports changing free space tree only from ro to rw"); - /* Make sure free space cache options match the state on disk */ - if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { - btrfs_set_opt(fs_info->mount_opt, FREE_SPACE_TREE); - btrfs_clear_opt(fs_info->mount_opt, SPACE_CACHE); - } - if (btrfs_free_space_cache_v1_active(fs_info)) { - btrfs_clear_opt(fs_info->mount_opt, FREE_SPACE_TREE); - btrfs_set_opt(fs_info->mount_opt, SPACE_CACHE); - } - } - - ret = 0; - if (!sb_rdonly(sb) && (*flags & SB_RDONLY)) - ret = btrfs_remount_ro(fs_info); - else if (sb_rdonly(sb) && !(*flags & SB_RDONLY)) - ret = btrfs_remount_rw(fs_info); - if (ret) - goto restore; - - /* - * We need to set SB_I_VERSION here otherwise it'll get cleared by VFS, - * since the absence of the flag means it can be toggled off by remount. - */ - *flags |= SB_I_VERSION; - - wake_up_process(fs_info->transaction_kthread); - btrfs_remount_cleanup(fs_info, old_opts); - btrfs_clear_oneshot_options(fs_info); - clear_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state); - - return 0; - -restore: - /* We've hit an error - don't reset SB_RDONLY */ - if (sb_rdonly(sb)) - old_flags |= SB_RDONLY; - if (!(old_flags & SB_RDONLY)) - clear_bit(BTRFS_FS_STATE_RO, &fs_info->fs_state); - sb->s_flags = old_flags; - fs_info->mount_opt = old_opts; - fs_info->compress_type = old_compress_type; - fs_info->max_inline = old_max_inline; - btrfs_resize_thread_pool(fs_info, - old_thread_pool_size, fs_info->thread_pool_size); - fs_info->metadata_ratio = old_metadata_ratio; - btrfs_remount_cleanup(fs_info, old_opts); - clear_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state); - - return ret; -} - static void btrfs_ctx_to_info(struct btrfs_fs_info *fs_info, struct btrfs_fs_context *ctx) { diff --git a/fs/btrfs/super.h b/fs/btrfs/super.h index 7f6577d69902..f18253ca280d 100644 --- a/fs/btrfs/super.h +++ b/fs/btrfs/super.h @@ -5,8 +5,6 @@ bool btrfs_check_options(struct btrfs_fs_info *info, unsigned long *mount_opt, unsigned long flags); -int btrfs_parse_options(struct btrfs_fs_info *info, char *options, - unsigned long new_flags); int btrfs_sync_fs(struct super_block *sb, int wait); char *btrfs_get_subvol_name_from_objectid(struct btrfs_fs_info *fs_info, u64 subvol_objectid); From patchwork Mon Nov 6 22:08:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13447542 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 974C7C4332F for ; Mon, 6 Nov 2023 22:09:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233268AbjKFWJD (ORCPT ); Mon, 6 Nov 2023 17:09:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233256AbjKFWJA (ORCPT ); Mon, 6 Nov 2023 17:09:00 -0500 Received: from mail-vk1-xa2d.google.com (mail-vk1-xa2d.google.com [IPv6:2607:f8b0:4864:20::a2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75D3DD47 for ; Mon, 6 Nov 2023 14:08:55 -0800 (PST) Received: by mail-vk1-xa2d.google.com with SMTP id 71dfb90a1353d-49369d29be3so2198995e0c.3 for ; Mon, 06 Nov 2023 14:08:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1699308534; x=1699913334; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=KpFp3rJxU7BfJUsZYH5++O1ZuHpoDOwhNYkZxFVciDA=; b=PXCQ0Q1jbeyWFNWCy0WV/9gYRme/V4aBu0+1iYsLLZG6KTjLJq+85ALP6XtUccAWJg fH0WM53FLREoLfx+Pp9+z62MasBXX2W3QZFRWqoDP8JpeVMgjuvFoV63Z+gWxTQ8VZPp HcTphq5pBTML/7Iol12k/OlSNkbcu5cU1S4irQGkIZn8rdDxJDFytuNG1D1PU6bEDPIr RYGXWSTKzPOTWsAutxmbkrnLN8b2dFctTGfYSbk+V1A6VSg4qIOKIPHi3AmcgaaS0bQV ZhyFM2AZX+SuFhseF1APeV6sfI1i+CyORfL8YNSDhOB2YPzbm76bjABAIrmG5/DTuiHQ Y0CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699308534; x=1699913334; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KpFp3rJxU7BfJUsZYH5++O1ZuHpoDOwhNYkZxFVciDA=; b=mOdMBYLrNcV0QQKy3v9tvG8czwIa1tafgqhvnrWPdM0dN7+1RsJ7hCD2vBaq6XB2+R tcHSfJzyTENIAS7BXPDtjn2p32g3EsJ7X2JPvRMj8tSJqQcmZQULfrnTPTDM1x1Yuztt yG1gBZT1WS9ZAs7jEahnmEkAkB0SNrq9T+n0wTAeBLraB9JVXkM5IV0U6fA7yuaFxlpJ z0FJgkH5z25GTLvgsbMt8uO+g7/4m7jYRkASkESDUOo/WPuxD7RDmw/JJ/bXO7MtZCIE wfmioEMdnoohlrjIeB6VYPr3evfAJF7PFB2Oj3BksDd7ZVPRVmqJ9AmzDWS0UtIZWIx4 ZEJA== X-Gm-Message-State: AOJu0YzTQ2tSbxoMaKoDXbJ1FMkUVGiPU5e89d0P4WuehOEpwOQfjpp5 rVgEO7SrwjosLkduyETluu0dMiy/JO11kmCKpn2qIw== X-Google-Smtp-Source: AGHT+IE1EoDzaK/Q8qpV5gVavwcEqP40pF8KQuhnys9MbBv8qpQ4o3AtHXoqFj5YpNDCygccdvM0nw== X-Received: by 2002:a1f:2702:0:b0:48d:b7c:56c8 with SMTP id n2-20020a1f2702000000b0048d0b7c56c8mr26020211vkn.0.1699308534274; Mon, 06 Nov 2023 14:08:54 -0800 (PST) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id z10-20020a0cfeca000000b0066d11743b3esm3825415qvs.34.2023.11.06.14.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:08:53 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, linux-fsdevel@vger.kernel.org, brauner@kernel.org Subject: [PATCH 17/18] btrfs: move one shot mount option clearing to super.c Date: Mon, 6 Nov 2023 17:08:25 -0500 Message-ID: <105aa05a5e00e8a7634a28db96532834fe4fc7b2.1699308010.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org There's no reason this has to happen in open_ctree, and in fact in the old mount API we had to call this from remount. Move this to super.c, unexport it, and call it from both mount and reconfigure. Signed-off-by: Josef Bacik --- fs/btrfs/disk-io.c | 16 +--------------- fs/btrfs/disk-io.h | 1 - fs/btrfs/super.c | 15 +++++++++++++++ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 50ed7ece0840..8f04d2d5f530 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2929,18 +2929,6 @@ static int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info) return err; } -/* - * Some options only have meaning at mount time and shouldn't persist across - * remounts, or be displayed. Clear these at the end of mount and remount - * code paths. - */ -void btrfs_clear_oneshot_options(struct btrfs_fs_info *fs_info) -{ - btrfs_clear_opt(fs_info->mount_opt, USEBACKUPROOT); - btrfs_clear_opt(fs_info->mount_opt, CLEAR_CACHE); - btrfs_clear_opt(fs_info->mount_opt, NOSPACECACHE); -} - /* * Mounting logic specific to read-write file systems. Shared by open_ctree * and btrfs_remount when remounting from read-only to read-write. @@ -3508,7 +3496,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device } if (sb_rdonly(sb)) - goto clear_oneshot; + return 0; ret = btrfs_start_pre_rw_mount(fs_info); if (ret) { @@ -3536,8 +3524,6 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device if (test_bit(BTRFS_FS_UNFINISHED_DROPS, &fs_info->flags)) wake_up_process(fs_info->cleaner_kthread); -clear_oneshot: - btrfs_clear_oneshot_options(fs_info); return 0; fail_qgroup: diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index e589359e6a68..9413726b329b 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -37,7 +37,6 @@ struct extent_buffer *btrfs_find_create_tree_block( struct btrfs_fs_info *fs_info, u64 bytenr, u64 owner_root, int level); -void btrfs_clear_oneshot_options(struct btrfs_fs_info *fs_info); int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info); int btrfs_check_super_csum(struct btrfs_fs_info *fs_info, const struct btrfs_super_block *disk_sb); diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 6a9561a336f3..f2c90f022233 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -640,6 +640,19 @@ static int btrfs_parse_param(struct fs_context *fc, return 0; } +/* + * Some options only have meaning at mount time and shouldn't persist across + * remounts, or be displayed. Clear these at the end of mount and remount + * code paths. + */ +static void btrfs_clear_oneshot_options(struct btrfs_fs_info *fs_info) +{ + btrfs_clear_opt(fs_info->mount_opt, USEBACKUPROOT); + btrfs_clear_opt(fs_info->mount_opt, CLEAR_CACHE); + btrfs_clear_opt(fs_info->mount_opt, NOSPACECACHE); +} + + static bool check_ro_option(struct btrfs_fs_info *fs_info, unsigned long mount_opt, unsigned long opt, const char *opt_name) @@ -1902,6 +1915,8 @@ static int btrfs_get_tree_super(struct fs_context *fc) return ret; } + btrfs_clear_oneshot_options(fs_info); + fc->root = dget(s->s_root); return 0; From patchwork Mon Nov 6 22:08:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13447543 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AD0AC0018A for ; Mon, 6 Nov 2023 22:09:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233256AbjKFWJE (ORCPT ); Mon, 6 Nov 2023 17:09:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233258AbjKFWJB (ORCPT ); Mon, 6 Nov 2023 17:09:01 -0500 Received: from mail-yw1-x112c.google.com (mail-yw1-x112c.google.com [IPv6:2607:f8b0:4864:20::112c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B56AD73 for ; Mon, 6 Nov 2023 14:08:56 -0800 (PST) Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-5af5b532d8fso57817847b3.2 for ; Mon, 06 Nov 2023 14:08:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1699308535; x=1699913335; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=HXa7qR/dnYgVT16zl6Y+77lu5bJKpb7Bxori4DISc1s=; b=FX48Q+4/lGMAZNB77RVKon8McTyhTLKIqvXr0Zh5MTsf0edwrtGgWYbDLXp1Kwz+9k PGESS67j4V6FKabd85k4robqHMqmW1q/ej93eRutTmeizwqAhCRxE8NbESYIR2q4RZU7 gmQmGOKh8XN+0EMaLwUqaMFVmP1NfDaEdfYSxfupJHlKAOufkkcT0YwO8zJsMrY9TYij Ci/ieEA90eLSzCIwFBaTDg3J7Qq9Gj5s/atsb1Dxldku/FnCHR97G6vweuUinKm7zTp4 dVRWGwMO4vwibyNP8FBK69dwe7YdPLxgDLLXlNVE2w4aAPS6Wy8Q13GU9ToY+XkWXZvT z8dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699308535; x=1699913335; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HXa7qR/dnYgVT16zl6Y+77lu5bJKpb7Bxori4DISc1s=; b=SusCwlj5qHFTQJWLRUM02j8Dyb9xU9Ko3NyfT0AXpNyxUhjGnuXaG+EhfHmj6BmMb7 YzMp8QDfSL5Lxzn11W36ETiwa0amCLi7J/RQ2jlULMTkWr7EsWgoyu+zHdGCczOyxc4D PmWWrNzuq34929fESCubZbHV30jUecLaDS0WR1dDwGhA9IyRsRqC18Ov8YQ60qbLmtgO 8ZyJRKdYKLlhtT+JEBl0NZs7nay7DNhlsPxLZ4NgPYJseVOpHKmlBFpqdtFFqA9bH13b 6a7cx2pecqKy10hs2aSTOxafRkB6lqi9n+dmNsbYMRBKv2asofZazPAzWI9jHQSbsPDc 8T9w== X-Gm-Message-State: AOJu0YwuV8QO+U1rsKob0CWoCLIemqMCJqlVTUq7lHayR4XHTbK3YFfb apH/M5OwtyITQqYB6KTewhBAIvaCWKC1SkgUW2Ai2g== X-Google-Smtp-Source: AGHT+IFtI8R7767Jp4wmekIuVY+aWRbp76qlLyNTBogEzaCjlS2v/IIqM+ql6g9s7ZfIoNNxeUSaRA== X-Received: by 2002:a05:690c:fc1:b0:5b3:4264:416f with SMTP id dg1-20020a05690c0fc100b005b34264416fmr13295460ywb.27.1699308535285; Mon, 06 Nov 2023 14:08:55 -0800 (PST) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id d24-20020a05620a141800b0077412ca0ae1sm3667431qkj.65.2023.11.06.14.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:08:54 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, linux-fsdevel@vger.kernel.org, brauner@kernel.org Subject: [PATCH 18/18] btrfs: set clear_cache if we use usebackuproot Date: Mon, 6 Nov 2023 17:08:26 -0500 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We're currently setting this when we try to load the roots and we see that usebackuproot is set. Instead set this at mount option parsing time. Signed-off-by: Josef Bacik --- fs/btrfs/disk-io.c | 3 --- fs/btrfs/super.c | 12 ++++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 8f04d2d5f530..77f13543fa0e 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2614,9 +2614,6 @@ static int __cold init_tree_roots(struct btrfs_fs_info *fs_info) */ btrfs_set_super_log_root(sb, 0); - /* We can't trust the free space cache either */ - btrfs_set_opt(fs_info->mount_opt, CLEAR_CACHE); - btrfs_warn(fs_info, "try to load backup roots slot %d", i); ret = read_backup_root(fs_info, i); backup_index = ret; diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index f2c90f022233..769c49f0ef97 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -459,6 +459,12 @@ static int btrfs_parse_param(struct fs_context *fc, btrfs_warn(NULL, "'recovery' is deprecated, use 'rescue=usebackuproot' instead"); btrfs_set_opt(ctx->mount_opt, USEBACKUPROOT); + + /* + * If we're loading the backup roots we can't trust the + * space cache. + */ + btrfs_set_opt(ctx->mount_opt, CLEAR_CACHE); } break; case Opt_nologreplay: @@ -557,6 +563,12 @@ static int btrfs_parse_param(struct fs_context *fc, btrfs_warn(NULL, "'usebackuproot' is deprecated, use 'rescue=usebackuproot' instead"); btrfs_set_opt(ctx->mount_opt, USEBACKUPROOT); + + /* + * If we're loading the backup roots we can't trust the space + * cache. + */ + btrfs_set_opt(ctx->mount_opt, CLEAR_CACHE); break; case Opt_skip_balance: btrfs_set_opt(ctx->mount_opt, SKIP_BALANCE);