From patchwork Wed Nov 22 17:17:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13465274 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="jCGclECB" Received: from mail-yw1-x1132.google.com (mail-yw1-x1132.google.com [IPv6:2607:f8b0:4864:20::1132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC1F2191 for ; Wed, 22 Nov 2023 09:18:04 -0800 (PST) Received: by mail-yw1-x1132.google.com with SMTP id 00721157ae682-5c8c26cf056so56369947b3.1 for ; Wed, 22 Nov 2023 09:18:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1700673484; x=1701278284; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AeAffNckkD9FXOxQ1acHKbqFC9hmQG2oKjxoNh8akn8=; b=jCGclECBK5xH4cq+w4vNZXm5AURbvxSpw8wcz9peBAEtSMahDmTAtzsmcXG8gcm151 Xdjst78hZAl0GIgxs7EwTE8uqQKgH9TNCo58Ttx21VhJwYbRRReRPaow7n5EU0DwDIaB EF/MaxYQeJKsLdxSKoC5JwGJT5+zftuI0FgCGdHdrTZiY/NNetb0DgndvOW7c/MLbyHZ jDrmgtND7/N+aX6XOcuvRG2sF+UrsrxuudVRAdLFGDFQ+kRBUln6ZpE9A8muOpfdGe0Q ARQ1sT/yoi4ROefmFmSHdYVJ8Qibh4lKkIcfZMTpgtkoikNUNRbzIjRhFXvryp1k9UfC xyJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700673484; x=1701278284; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AeAffNckkD9FXOxQ1acHKbqFC9hmQG2oKjxoNh8akn8=; b=oH2b7h3I7ISH1FKIw03vtWm3FZNPGLUbWjMB32TWmepCsHEPzOq+Lv9Cf5/QM9BfG9 y4ckHCoHETEG9jtltqKcgo0yFpbeEDHGqEf9gpmV/11DlAZ1zFTWGWiU3I3DpD+IHkzS R3Z1rjkUUM6hlYPROwv2Ug3CBPMMtKvgyuwKjhEauD+KqQnfwC7pw5NXfF7EinH8VgOa TQPh2eq2A3SqV3Y4rbrvbi6YfexMjvWveXdEJutoUC2Tep3tgVsZdse0lVmHZqDU1CJC +xzlR4brgkPN3udVm5eA4OCGzy0nx9zLG1XZ6luQWhgTx7m7ON/JmHI4DwQzNPJzgSeF 4YQw== X-Gm-Message-State: AOJu0YxKxKzrAA5oDYs0wM+dzQIvtOWjMKFu3ZyISz8tMnicOIekIA8q uCy3iaNMYlGPmk68vIHzDSTIQncmgf2tRVfIsTKUTD+u X-Google-Smtp-Source: AGHT+IEng99RZT2mMcKItvu4HlbSVHqVIY5Lovfq5kXoFcicH5MGY3m+01RKxr34EjR5pXXvqY8zrw== X-Received: by 2002:a0d:ed05:0:b0:5c8:7708:b86c with SMTP id w5-20020a0ded05000000b005c87708b86cmr2710715ywe.47.1700673483874; Wed, 22 Nov 2023 09:18:03 -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 cc2-20020a05690c094200b005cb3510c8b2sm1508279ywb.96.2023.11.22.09.18.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 09:18:03 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Christian Brauner , Christoph Hellwig Subject: [PATCH v3 01/19] fs: indicate request originates from old mount api Date: Wed, 22 Nov 2023 12:17:37 -0500 Message-ID: <2f5e68f38d45e51cc03c16ad7b94bcb9cfbbd8ab.1700673401.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. Fixes: b330966f79fb ("fuse: reject options on reconfigure via fsconfig(2)") Reviewed-by: Christoph Hellwig Signed-off-by: Christian Brauner Signed-off-by: Josef Bacik --- fs/namespace.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/namespace.c b/fs/namespace.c index fbf0e596fcd3..6c39ec020a5f 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2875,7 +2875,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); @@ -3324,6 +3329,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 Wed Nov 22 17:17:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13465276 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="NJaq8b63" Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB2A219D for ; Wed, 22 Nov 2023 09:18:05 -0800 (PST) Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-5cc636d8a21so8986367b3.2 for ; Wed, 22 Nov 2023 09:18:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1700673485; x=1701278285; 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=/wcEQjma5KAu0u3aa0GBWyEj4pLCTyUpOPwDIPpwmFI=; b=NJaq8b6374V/5vZnvJN/aJXqcNDIvOFl66FjZd6nLWe1GeLDyAw4W2OiJiaUGJrrGQ zLD22W2ueO9U4AEWNEvnnJTq+UD95hoJKa5yAHsaPhT0wXJx7kUaMgdLwOIGc2UqRR8D zDKKjFsG3xpDK+LnhKhajnFPBqTC0TNfAnZufQEskbNCTCLV1lY5tMwvgvsGpx+UPP7F aXEqmvPuU4Xyv1el1ZuRF0urlTGaCONui8v3Bj2MLCj/ZCUsyGsPlae7vpIKlQLog53n oI5aP1kP2M+cpbV/Wi1l7w+lrGYzvDkSGJ/PzhlP1Vr6jIDxGJxsz3Ax2RL0svy8AXxa Tzzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700673485; x=1701278285; 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=/wcEQjma5KAu0u3aa0GBWyEj4pLCTyUpOPwDIPpwmFI=; b=kJrP9EGhQTVyLZRjMZ1AzilE4ZO82kiyac3md6qUs297zXh75EYQrvAEH8P2R3SsLi 8FunuxxtEl1l8k23EKyIoFJ80RldCLFxd08fAp7E6bn8P5blI6DQqOWUGwLeqm4qh3Ml ZnlDvTybFyAF7WIwqO+dL1gzc6urvhjkQ7EvcOnPXHOKkSb/07f4vrMdx7slCN3MQgMV SP/N6rSCBpa6IWBuiMRoaYtI3KH5ElnbcyrmQomvwwHGjI3DqM2K9IlI3NWyRSSyd4Hs 7A2SFoB8s8HV18YRaFNaM3mVa1k+49pz4ZTBxIa3mxGusSg1ljacMp86dljOXwMg4p+A hatA== X-Gm-Message-State: AOJu0Yy0vQzbWGZ8lsbp9EpBSEepBnz1txecNxHdnsCbDK0QsIAZZDWc 0OCE5RXd/DW1NQUIA0p5P+x6pnCTEEO+slr/Hf7HZO5M X-Google-Smtp-Source: AGHT+IF2oa1Y617bqKgJ+T+OHErQBcgDqNjBq3d6C0xa5Zn+ahFBtAqVPPas9VhVPSnhAgXvDyNi3g== X-Received: by 2002:a81:9148:0:b0:5ca:c869:8df0 with SMTP id i69-20020a819148000000b005cac8698df0mr3108926ywg.4.1700673484774; Wed, 22 Nov 2023 09:18:04 -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 h7-20020a81dc07000000b005cb331f463esm1520371ywj.8.2023.11.22.09.18.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 09:18:04 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 02/19] btrfs: split out the mount option validation code into its own helper Date: Wed, 22 Nov 2023 12:17:38 -0500 Message-ID: <75d5596daec83241f5cb6dc4cf5d2541346917b5.1700673401.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 66 +++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index ef256b944c72..008e027fea15 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -236,6 +236,41 @@ 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) +{ + bool ret = true; + + 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"))) + ret = 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"); + ret = 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"); + ret = false; + } + + if (btrfs_check_mountopts_zoned(info)) + ret = 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 ret; +} + static int parse_rescue_options(struct btrfs_fs_info *info, const char *options) { char *opts; @@ -314,7 +349,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); @@ -333,7 +367,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; @@ -777,35 +811,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 Wed Nov 22 17:17:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13465275 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="VJ0v0Rjz" Received: from mail-yw1-x1133.google.com (mail-yw1-x1133.google.com [IPv6:2607:f8b0:4864:20::1133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0F061A4 for ; Wed, 22 Nov 2023 09:18:06 -0800 (PST) Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-5ca11922cedso40668237b3.2 for ; Wed, 22 Nov 2023 09:18:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1700673486; x=1701278286; 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=c8iItkIGfxUBmyKnZ9x2I90RbdJJn+uCFaRLMIxu4xY=; b=VJ0v0Rjz4x9WU0PlbzSZz4WRvdbqyi+BZgQyK7pM8UN84idDwzE93krVeVNR/A5BX8 CwMoLcMc/FjyNVmif0mN/egO098sgfKcm0H5b1ycY9OBvuiyMBHkJKr7sbrAMyIdo9tP AM41w95vEzmxkg2qHoqZUVKoppLkfVnl4LSEuvHVz0FpJTBrkGBcJFqBx46z07tGS6zN QPHovDIZsuNWZq99xUIMuEdGjwWyb8+aRn+K+8lEalqfw9R6yCS5bHt/0FXikVG+JGJy EJPELZgRs8L4ZT12ex8h0uwAmuI5uhQ5Bnh8lt2PPH3QvCHgCI6WbFprX617le7kYpEb rbjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700673486; x=1701278286; 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=c8iItkIGfxUBmyKnZ9x2I90RbdJJn+uCFaRLMIxu4xY=; b=DfQb1KI6ufV2v1aCG5Dtanhy+/ykKRNHZKeAbz1eu2ZBlAPZxbb1MwkFzu3Zv/AVXv 1E7jX7GrA0qb1y/Zr1V7YzBV9OLaGZpabNnKd3/2sjatNB/bUOsYHj/abpGvn2OJ6bLL DF5uVqoUyUH2s8Z7ealr6Dw+9toR8mZsjk9k4zez6N43cj6dOM8LZz55YxMMI9Ogdm+Z BS55YllrThATQN2qEIqleVu4niNPy3jiTwKpdnxGLkK78oRKzsK6YbBaJsk8B/i9gk54 AF7RKhivi5OTmzYvoV/xGEiyy51pJobG4Lo4rYnp0BjfY4YkS65FE3fevQKOMAss+SKD PpVg== X-Gm-Message-State: AOJu0YzmCCj1i19FksuXNJrU6pMCv3Ms/QxSFEppVB0fau5dSD5vQnZR pX5GGv4V7QnHs5t0ENyIEeAZ3D2FJP3I/mWv2Ulu9FAD X-Google-Smtp-Source: AGHT+IEgyp1v00kQ7Oo22YPR27kTP9J08NYKAwJhM75B/7z1zTyVBEYmyKjCoM8YaePppjMcvcfjiQ== X-Received: by 2002:a0d:d982:0:b0:5ca:c101:b222 with SMTP id b124-20020a0dd982000000b005cac101b222mr3146652ywe.42.1700673485850; Wed, 22 Nov 2023 09:18:05 -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 a190-20020a0dd8c7000000b005a8d713a91esm3813087ywe.15.2023.11.22.09.18.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 09:18:05 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 03/19] btrfs: set default compress type at btrfs_init_fs_info time Date: Wed, 22 Nov 2023 12:17:39 -0500 Message-ID: <7d94f10916f221daea6257896545a7488bf8f67e.1700673401.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 84a5dc0d984a..347a89f51bfc 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2799,6 +2799,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); @@ -3281,13 +3284,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 Wed Nov 22 17:17:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13465278 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="v8O6Y+L1" Received: from mail-yb1-xb2c.google.com (mail-yb1-xb2c.google.com [IPv6:2607:f8b0:4864:20::b2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DC2E11F for ; Wed, 22 Nov 2023 09:18:08 -0800 (PST) Received: by mail-yb1-xb2c.google.com with SMTP id 3f1490d57ef6-dae7cc31151so6444766276.3 for ; Wed, 22 Nov 2023 09:18:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1700673487; x=1701278287; 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=gm2U8+AV3HIKEIZ5eySC82y23sckawCACxIpTjlXRdc=; b=v8O6Y+L1kr95Ka4eJyxUrE2+16q+L8BTuaz9QDWwO9Qj6LmIDVHLGR8BtOqPKbbJ2e h7+IUJBsNsLdH3GPP3aYhMwkAMLzMn6Hgz+eHrxC8OZhCHwuYe6OpPFAyBecB2PjwwNc b7/p/3rUWoBgNhHine4inC4gsJ4V/68NojVSoooezt9cq1d1kfuL3H0Hvb8DQmEEk+l1 SEgkOy0J3cSi6ZSEfGYZjk71ipYs6e0DebpueRP9AUS/SUqMemuIL6IrLj3O4rIpuWJS n4A7kcgxEiCfBK/C7wS1ItApV+FDF6lob/M/cyzLY+fE6aNUKCx9uXsc8Y5Cl5OBnrFM kG2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700673487; x=1701278287; 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=gm2U8+AV3HIKEIZ5eySC82y23sckawCACxIpTjlXRdc=; b=MPfxNEVbD4WvOg+aO7oblCHnKJv1FronoqmIyG/OK+p6PZAh1UsYi5YZ8s808aYfF3 MRYL7Tc2g6U4O0F2fPzpsylqJ7YOr6IL5SYcHoteHgUr4ZGxkJCyAeP0b4hGtB5+4NHY Ym9a9K0cgZ+tnLHV+EyO3xIo59yuYmZcTttZDYdGgSmyDTgtcSUi0q3aFgVIeqHn0lwW 5374mY4sswXb4ErxH/LYTVnVDYw+qOBRuoAira/wdBn2nn/9ix9/f08aQlLS1RodEVIM pQxhgbx4G1prLsoDoZ1SeOybSrMaI+V12+t2Yj2ZZY1dbamrIUR7ZAK5oHDKEh2FQ0A2 bftw== X-Gm-Message-State: AOJu0YxgYfRYV4z1+HU5aaHyHjOTLik1RqZtR2bv8gFVFB+FJPd/0hK9 0B80zYSjZ3BIXbEm8c/g2rzfCLpA5+cZktn4fMZ8VJKG X-Google-Smtp-Source: AGHT+IFMWJ12RGBl7S1GbUGaaOg29NnqXkb/RbzoFA9to3rCAADWrsLqQpWS8HBOHnIDoJmykGQ6fw== X-Received: by 2002:a25:820d:0:b0:da0:365d:9e21 with SMTP id q13-20020a25820d000000b00da0365d9e21mr3078318ybk.22.1700673487278; Wed, 22 Nov 2023 09:18:07 -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 v17-20020a056902029100b00d7f06aa25c5sm1434428ybh.58.2023.11.22.09.18.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 09:18:06 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 04/19] btrfs: move space cache settings into open_ctree Date: Wed, 22 Nov 2023 12:17:40 -0500 Message-ID: <8d52b2058f4fca311f8358191b6b0da60fce663b.1700673401.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. Since this was being called by parse options it looks like we're changing the behavior of remount, but in fact we aren't. The pre-loading of the free space cache settings is done because we want to handle the case of users not using any space_cache options, we'll derive the appropriate mount option based on the on disk state. On remount this wouldn't reset anything as we'll have cleared the v1 cache generation if we mounted -o nospace_cache. Similarly it's impossible to turn off the free space tree without specifically saying -o nospace_cache,clear_cache, which will delete the free space tree and clear the compat_ro option. Again in this case calling this code in remount wouldn't result in any change. Signed-off-by: Josef Bacik --- fs/btrfs/disk-io.c | 17 +++++--------- fs/btrfs/super.c | 56 +++++++++++++++++++++++++++++++++++----------- fs/btrfs/super.h | 1 + 3 files changed, 50 insertions(+), 24 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 347a89f51bfc..065a2e3831d0 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3297,6 +3297,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; @@ -3308,17 +3314,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/super.c b/fs/btrfs/super.c index 008e027fea15..d3b66e9c2679 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -271,6 +271,43 @@ static bool check_options(struct btrfs_fs_info *info, unsigned long flags) return ret; } +/* + * This is subtle, we only call this during open_ctree(). We need to pre-load + * the mount options with the on-disk settings. Before the new mount API took + * effect we would do this on mount and remount. With the new mount API we'll + * only do this on the initial mount. + * + * This isn't a change in behavior, because we're using the current state of the + * file system to set the current mount options. If you mounted with special + * options to disable these features and then remounted we wouldn't revert the + * settings, because mounting without these features cleared the on-disk + * settings, so this being called on re-mount is not needed. + */ +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; @@ -350,18 +387,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 @@ -654,8 +679,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 Wed Nov 22 17:17:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13465277 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="R+SyihnV" Received: from mail-yb1-xb2d.google.com (mail-yb1-xb2d.google.com [IPv6:2607:f8b0:4864:20::b2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C77831A8 for ; Wed, 22 Nov 2023 09:18:09 -0800 (PST) Received: by mail-yb1-xb2d.google.com with SMTP id 3f1490d57ef6-daf7ed42ea6so25173276.0 for ; Wed, 22 Nov 2023 09:18:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1700673489; x=1701278289; 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=3n+aVZ94c68BQfM0UZeR4DnPly/rOTpXllEpIAZgtwA=; b=R+SyihnVYOe65OMXfLYgS3WMFMwCm0eEOUpWGd/dnJiAaHSjymgn3tAweDTew/1tPm h87T2nzc+iR7q8mzfGE45egJrzsnqsVuC54CboRQ7GlHNtB3iXgxSz2RGOuKFkdNc9yv JJF/LrpWDcVvrl6ih1WwAEufY8aHmGx+P7cfuzNs4h96Q0bQa0+xkZHNmCWJCB/u86/F r1Si1mSGqxoO2CueVotPktDhMV0UDSKIF7raaMEdKOkuagVg6/sG0rLugRLpVcg6caFx Re5l+dTtEqjQ5x46k7Vla3SYSWNYfF/LoUvHLdlt7gy4u5ShJwg+pj+xI+ZQIuvarvGf gKlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700673489; x=1701278289; 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=3n+aVZ94c68BQfM0UZeR4DnPly/rOTpXllEpIAZgtwA=; b=Cp7Sqa2lOOK7Tbf0q5pihwUruFU755ZBJKAKo4klwPjGTuc4p6WBBjNoHpw/GwaggW pP7DnOs4TBxIKaM+HQxHWtch0d8/hAjMePV67+kdcUr3y6x3l9y9KY9exDjADKHIo6LE mii9vtKy+PY+8emiH0Su0/d5Fn39d5PUtg+d+NuNHoKZrX9THsM/YpGUJc6/GSextSY3 I1HcCZIt2Vypuy72aUE14oiq2WRDxU/fbUaitXFGCJfkqJ9DXqy1nL4O80AD8weP6yex 87dYlV+Hi3tqGL9DYbCvwSZknWycxooyhAv5TugIlOC8aUTotebQ4xMt/St4pkcL4oUw DWpw== X-Gm-Message-State: AOJu0YxL2oe7mcFGSQT19MSC96RqTBA3uvWKO2F1MDRVlwUMQa9o/RYQ 4XUYPzSjyYT+TYLJtr7TCVeHusRZQYXZ+OnQJzsbD06x X-Google-Smtp-Source: AGHT+IHzimPvMRejY6ACVnMZicqLUZj/07XGxIX3GzPaToIiDZn6GCo+eLofcFpJrBD0z5AN/xrOcg== X-Received: by 2002:a25:b847:0:b0:daf:6333:17c2 with SMTP id b7-20020a25b847000000b00daf633317c2mr2544519ybm.14.1700673488431; Wed, 22 Nov 2023 09:18:08 -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 u6-20020a25ab06000000b00da076458395sm1476811ybi.43.2023.11.22.09.18.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 09:18:08 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 05/19] btrfs: do not allow free space tree rebuild on extent tree v2 Date: Wed, 22 Nov 2023 12:17:41 -0500 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 065a2e3831d0..42da84a186c7 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2961,7 +2961,11 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info) if (btrfs_test_opt(fs_info, CLEAR_CACHE) && btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { - rebuild_free_space_tree = true; + if (btrfs_fs_incompat(fs_info, EXTENT_TREE_V2)) + btrfs_warn(fs_info, + "'clear_cache' option is ignored with extent tree v2"); + else + 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)) { btrfs_warn(fs_info, "free space tree is invalid"); From patchwork Wed Nov 22 17:17:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13465279 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="lAa4zHnj" Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01EE2197 for ; Wed, 22 Nov 2023 09:18:11 -0800 (PST) Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-dae0ab8ac3eso21204276.0 for ; Wed, 22 Nov 2023 09:18:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1700673490; x=1701278290; 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=Fc1jP1f2IupLr1kIYSPLSEVGQP7LjPerVE2u7Ks+ZiE=; b=lAa4zHnjojhWa1QwGYmyacMYOfmsMskCAYwUenCLCJIfFPRWLqe+2HKdODgVEGTb6b urQcSbvcup69NwomYGyQ0CbuawNnC46kRrb4d6+8EIo/U4MznZZ0HMJeLROowfp+9OHh zSDkEQTCdsUXpR3y3YYwE4+A05uER1uFFPddeoo5ahYEPSw3Q88oyKksb6y6blnyLoi6 CkPxkZDRasfPqOM0hH45P+DGgDTBmpwetQgRXYIoN7f2lSaK2amIBuotQtx8aWcGfY1V P1jRRhlfqxz5BsPbInQDvTKrbCmMuqcT9iWusi0IvhNG9lOE3R/B8eRang2L9DbhprK7 abog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700673490; x=1701278290; 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=Fc1jP1f2IupLr1kIYSPLSEVGQP7LjPerVE2u7Ks+ZiE=; b=De7yqzDAgAOrgQTmrD1j3lSBc+7xez5DdGUiM8eooUH31ssifE4+2pb+BtIqSNZfZj OWH0MrVWMUWhhY+kcceCtxkR5M9znZCcZlu6Bfy1pi4rd2WLm6PP6PjpMoiAKWbyVRLp 0DCJ2bgR8HHwA81ZhzdZskYiZgl3vw3xLfAfhwurwe5CDeeydA/y0X737kGT1gmviRD6 djKSaWQfo4R6GhgNXButMv5+u/tshANmLGii47AFnTg5Ztuwpc9F8Qg8Byr+Qik2pZ/j oc16g6kzceZOre3Q930iiP4u8UORHwiIKeNh2HDfd2gd2J3/3kylYZvsORekioc1iJrL LJBw== X-Gm-Message-State: AOJu0Yx+icSzXsbfqiZNBqUUqHmoDTTW0fLSYgIx1Zj5MJsFxmCXcrWk dZY9ESje+BVdZ7eBP2tz1//JWjlQaLzLpR1JSmOhsFF7 X-Google-Smtp-Source: AGHT+IFubRPRJ9wl4qrJfTD6gMjP//GVWJi9OSu/VdQUhO8dU/Ipac8OyCRu2/RT+5w/AlS+lm5tkQ== X-Received: by 2002:a05:6902:533:b0:db3:fca3:76ea with SMTP id y19-20020a056902053300b00db3fca376eamr2814958ybs.0.1700673489897; Wed, 22 Nov 2023 09:18:09 -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 t12-20020a056902018c00b00d81479172f8sm1444353ybh.5.2023.11.22.09.18.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 09:18:09 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 06/19] btrfs: split out ro->rw and rw->ro helpers into their own functions Date: Wed, 22 Nov 2023 12:17:42 -0500 Message-ID: <8b209e6c48780284a2b7cfd4979783ab909b8011.1700673401.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 d3b66e9c2679..e4ac09bfe0fc 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1676,6 +1676,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); @@ -1729,120 +1842,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 Wed Nov 22 17:17:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13465280 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="gjn8o1pA" Received: from mail-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC0A583 for ; Wed, 22 Nov 2023 09:18:11 -0800 (PST) Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-5cd0af4a7d3so916497b3.0 for ; Wed, 22 Nov 2023 09:18:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1700673491; x=1701278291; 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=Wmo6bUZ2Uooog1uRBxQCT5GQG23bw3r/h7mqFB83zlg=; b=gjn8o1pAg6a1SRXTlwxma2cLtfkkZchS0Ao3ydthY/y+qI2XNOfI5hF4cyYbn+LuCm +aVrHEXvHkJpHAdIaVfu95Ubkzvr52iCWdCZ1aa8LgoQsGVMwl9gUF2CQx/XQFNk4n/2 ckxlBXZiRyMbGEMsLzlJOrmBBfBj+uCQB0RfRChgYhQfJ/UG1LE6JzIfB1vKNd8gHW65 lVbbggrw/s/+r5nMAN7T+jOtsp8OfhnL6BOoEwOzv0XMPTyWGljYU7CPGXEXPieT73X9 YZs8B4y25DzrZ2X4VgWynfFjxCgV2gJGRf2b9ypsQOuCy8MJZw4KUyTEweqRylQSaEPx 6sxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700673491; x=1701278291; 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=Wmo6bUZ2Uooog1uRBxQCT5GQG23bw3r/h7mqFB83zlg=; b=BAMmbY4k1sY7kKN06Re21y8Vy+fDyfgOdUc/spe7rFgXq6xAcUKvvbN3MOwyHfesv6 CGbj6XoeKNDRmDwtNEqBhQb7ZrHV1O+CV1WJDMnZPL18dzKiPchWGDUsD86gQGSDbwGZ ZsWKF/1r623OdWu0e1z9YZS6EYOJb+q/9p90/ykSXzHCcAYopLgLhX/UY2vD3J/E/wzG YozSdHxJYRNa5bgOUN+Dp646sZDo6ParGxy1S5diMSiTIHPaJEinUnYM5oorgPBgwMlj y0+gCa5ZmcA6wa7iN+H/xZz9Gc56uAw0JbRq0iBqE/4miWM1D1RYNDX3J2oMEPbz7nkP 94kw== X-Gm-Message-State: AOJu0YzrXSkttS1TLbin8OJTqCyd7lzLFIJQxSmgdHGKHZyiiLv780s6 ciF0RJrDQ+EnDznL3FB61DoGz2/Ua72dmln2mM9kTFbc X-Google-Smtp-Source: AGHT+IEzN4TfKYU8NK8VOiJ8nPCdQ3O4NXLfBtEw11r9k/9nIFLJNMqw1iP8UwxULF8BUdhLmQsk8Q== X-Received: by 2002:a81:4e01:0:b0:5c9:a998:b4cf with SMTP id c1-20020a814e01000000b005c9a998b4cfmr2756958ywb.10.1700673490991; Wed, 22 Nov 2023 09:18:10 -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 d127-20020a0df485000000b0059b17647dcbsm3782094ywf.69.2023.11.22.09.18.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 09:18:10 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 07/19] btrfs: add a NOSPACECACHE mount option flag Date: Wed, 22 Nov 2023 12:17:43 -0500 Message-ID: <6c1683589158f68afadc876fe427b73b7be3f182.1700673401.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 42da84a186c7..3c72bc1d09a3 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2947,6 +2947,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 a3debac2819a..e6f7ee85032e 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 Wed Nov 22 17:17:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13465281 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="pGMUb/8f" 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 0A4271B3 for ; Wed, 22 Nov 2023 09:18:13 -0800 (PST) Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-5cccd2d4c4dso5084717b3.3 for ; Wed, 22 Nov 2023 09:18:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1700673492; x=1701278292; 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=7fkA3lCitnD/iMODXrJglqig2YV4i0dKVL4SuP4eEJE=; b=pGMUb/8f1dFLx0DwMUBL6XXb3RZNArGon9FeGD1pttolDVLcu2RBcAiKbtq8PBCbLy QhsJyj6/rEv+ncpWmOlMs0oYB83ph8uOEIEfL38GrK/3EH1pg05CxZRTOJMxK/ZghPlO jGuB7EdYLpRZA93gStt7xtOuWLbWFg4E1ZD7fKOzb10bGaWF2KrXZ7FYMeAmHVeicOJv cs73jVInxg5+YOtTOSfUycQtxw5iB0UMWvASIQv4Nk1EGI7y1ucmVbszlTUXifsGWOUD 2LQ7qKxeBP4G6DXdB2hUrED+FAYYCgcMtHjdy+59V+BPoqbvnw3fP3MdVV4xzuCXasbP lh7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700673492; x=1701278292; 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=7fkA3lCitnD/iMODXrJglqig2YV4i0dKVL4SuP4eEJE=; b=BGJcdU3zLBEOlDmoc26/9apAOoNB46UNhtSvrO37NIrr987P/7Jmlp7B0bxtvHgM+j YhINEe9INZKvulEFrhlfm9sifWkf7qyx/6eIIxh6qbEhI9r7AYt7EMgYudMtioH4CR3P EUQK7+fjfeWVuvXUzt3nlQsbuiyKo9nQGYo0iQJydg+7T2BodGwsNnZ+PL5NOLs7Y7zM HkrzE2UmQwi++1ygHLQ6UOBhLLoPaKfBuHhbp+tmAqrMlBPXswV9cOUZZ872KAJOLmQj JQb4l2YZpJvL7oHk3ko6JXJCWhXIKq+Moyavt93aV/4E3hv/Z+DQxYZ7/SH4VMt6zJFf yGHA== X-Gm-Message-State: AOJu0YzBFGaWIiEHkKmljTapy4/vxyuAX2RURJfgnrfPxZtK1Yqe+4Ho HhZMuetiBzXAsSAyxpTdar4Qkm7r8BLkfZhqGnoRA4Bp X-Google-Smtp-Source: AGHT+IETYkKHOM4YSxxN9MqGSDgqilWwCR4w2yYYdc8jjcvyyeXwuXRPM2YH0vRkDFHrdkqkIuTa7Q== X-Received: by 2002:a81:5207:0:b0:5ca:15db:5c66 with SMTP id g7-20020a815207000000b005ca15db5c66mr2915764ywb.18.1700673492034; Wed, 22 Nov 2023 09:18:12 -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 g74-20020a0ddd4d000000b005cc636ddb1esm544961ywe.41.2023.11.22.09.18.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 09:18:11 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 08/19] btrfs: add fs_parameter definitions Date: Wed, 22 Nov 2023 12:17:44 -0500 Message-ID: <3421ce0974e8ab4b156640d2c353e0a6cffd914f.1700673401.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 e4ac09bfe0fc..2366bcf7a23c 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" @@ -135,7 +136,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, @@ -225,6 +226,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 Wed Nov 22 17:17:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13465283 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="scBMGcv8" Received: from mail-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DE6B1A4 for ; Wed, 22 Nov 2023 09:18:14 -0800 (PST) Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-5cc642e4c69so10174047b3.0 for ; Wed, 22 Nov 2023 09:18:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1700673493; x=1701278293; 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=43K70ReJ/ZnydsIdQxXrWAnUohmuvWnf9VmLW+rwBi0=; b=scBMGcv8z0g1Ojys/AaTC0MVrRyzs/JECE7HdaTLwFSUgLeqVtwfBBvuX1EffmUCnt lFcTlDWUYJd481VPWHucr3TIuEU9qQLfH3Oz1To6FIdfwaKOIpaCSQNnJWKb2I8e3+CU 2p3lBq5OtqmZHnFf9SM9+D0MRh0ZFt1vuItVuvVxqfDsY2wAq6Dy6dH2sE6mBSi6JNvG HoslEG2NWXS01xyO26vbDr9DfDDmdzgT1zMP3YhpS30H3ZamxcXySBrQcJL7k9HJJFro 3DZQsyt4baRAbeJCWAYo+ucO6DXvUj/wXVWt5mCqXDg3ZPc2oDZPiy/9g4ZhRhbPIilI A3vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700673493; x=1701278293; 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=43K70ReJ/ZnydsIdQxXrWAnUohmuvWnf9VmLW+rwBi0=; b=KJ4ayTNNzwN1cc4iU2GuQ0ESuiOKv3Z8GiJtFJPBt3RXtMNgFcaoLW9EfgDemvrfz3 vPFiV2c0QKji6kqMHXCuU7RVa9BWyNVzBlFcS/beBeLnBwpgdKycfUIlLmyw3jZYnkMl eI6yo8UrHTaLOuRcalFuKoP9W2XppuQEeZknkXsjsomEVfLHeXku02zL8rUR/JecCAMa 3iEF2o+sj2QFI/YV82whpBLv0mn6eREV5bDrcQhGaYzFsLeG9uipTs/UTOEAY3hDmquD TQBfbLxdNQb14ZkdbGhvZnoLT2NHvB5aufD/3RrS9ukUG74gruXjiEPMd6vBcddLRk8c DnVQ== X-Gm-Message-State: AOJu0YxBdPWasL0Gn5TqeIHtBA4M4qhIbbTb6lCUMAPxM0WaATyMzM4Y cIWARxjyqiKKW3hR7m9CdF7BjRdFvp/laooP2/DzKGVX X-Google-Smtp-Source: AGHT+IFGqAm+YtrZDu5zHWa4AOWXCIsKDqJIL1cCjsARQohQ6UEgcPJ/2xZIEJh8cWwfm1SKzbWbzw== X-Received: by 2002:a0d:fc81:0:b0:59b:eb8:c38a with SMTP id m123-20020a0dfc81000000b0059b0eb8c38amr3041474ywf.30.1700673493022; Wed, 22 Nov 2023 09:18:13 -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 x77-20020a81a050000000b005a7ba08b2acsm3831712ywg.0.2023.11.22.09.18.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 09:18:12 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 09/19] btrfs: add parse_param callback for the new mount api Date: Wed, 22 Nov 2023 12:17:45 -0500 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 382 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 382 insertions(+) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 2366bcf7a23c..b1764efbc8f5 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -87,6 +87,19 @@ static void btrfs_put_super(struct super_block *sb) close_ctree(fs_info); } +/* 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, @@ -351,6 +364,371 @@ 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 37becec95ac3 ("Btrfs: allow + * empty subvol= again"). + */ + 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; + + /* subvolid=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) { + ctx->compress_type = BTRFS_COMPRESS_ZLIB; + ctx->compress_level = BTRFS_ZLIB_DEFAULT_LEVEL; + 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, "zlib", 4) == 0) { + ctx->compress_type = BTRFS_COMPRESS_ZLIB; + 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) { @@ -2272,6 +2650,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 Wed Nov 22 17:17:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13465282 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="jjCoQYd3" Received: from mail-yw1-x1135.google.com (mail-yw1-x1135.google.com [IPv6:2607:f8b0:4864:20::1135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E657911F for ; Wed, 22 Nov 2023 09:18:14 -0800 (PST) Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-5c8c8f731aaso54850617b3.0 for ; Wed, 22 Nov 2023 09:18:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1700673494; x=1701278294; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=In9hJLjWS6zK/dhcsmyoCh7QbuZA4L9Viz0TrhYQUBc=; b=jjCoQYd3NOVH7PqObx0E9sPshXek2W87kqMhlivkOFAzun+i31fUDr4aGXnYIdczv7 f4bTKGWcnDLQbmlot10ZjAiRk5cPia75X3Ih7qc5HznkXZkBpxx0glrJKEWEBtj8cKLP yOe1QA6m88LkejC4PnPhuXeb6hyO4RQ6UI6pZXFePUB8fBWuxIGhyO3uh4RaKB8f7TVW VOQIiS+NoWfO3nqN6Jit1TV1ZZ+MflZ2HW40zJvayMRmG0cASIY+g0n9JD9sLiFjTtgb OvDJsMDhwAdKmucpUjKIR9vJRgQtLak1/569Eq8ZgtGm4EH/yrivijGEmMX3RD3cj3Sj PL0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700673494; x=1701278294; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=In9hJLjWS6zK/dhcsmyoCh7QbuZA4L9Viz0TrhYQUBc=; b=e37FR6jNKd3mSlRKQTvInT8l7VRBr6qPSXVa+KoXMVAiNGk2iyAkmTpLAwGNzh3dsc hJ1ntoZJOh2q3/0309ElTLvC+wCLf8ibONrQ+om9XyN3EgDQkIO1IRty9uRSnvTsHphF uWiCnaNxMV/x5k4/8tbpiPu4QfaYl5pycktK94qvEsB9Y1/CgESGrG0PeDxTzFzXjaXA 75bX9Ka9GPGy3bS/C48IJWrTEmcXB8p4m9CRcca2OtEHXBnECe04YXPWibk3oySbB882 vGCmcSZHcCldtdwnapPmsVh8S/7VRHd6Z9hA+G0WKPUvwp/lWPM6dCD2SgYASPgio4Gj +P5g== X-Gm-Message-State: AOJu0YwFenjjC/QiMHbf7FkkkERItj7V90b6Rf4hX1+0lRJXQDXoOeWu 70AbHT4yYOYk2uwOSPLLzJlSVxYy1U0QrhuAxA0LM4I1 X-Google-Smtp-Source: AGHT+IH4PbK+wpvGEbHamGbl2197DPtnAzDD3QykWVeYddDahHAe/wBRWEj3TfvywkSLL3lTHBLtTQ== X-Received: by 2002:a0d:e60f:0:b0:5cb:e94d:17e1 with SMTP id p15-20020a0de60f000000b005cbe94d17e1mr3018302ywe.10.1700673493993; Wed, 22 Nov 2023 09:18:13 -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 h7-20020a81dc07000000b005cb331f463esm1520443ywj.8.2023.11.22.09.18.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 09:18:13 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Christian Brauner Subject: [PATCH v3 10/19] btrfs: add fs context handling functions Date: Wed, 22 Nov 2023 12:17:46 -0500 Message-ID: <505b7f1e781ae401e1e774cbbd01222776a3f5d2.1700673401.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. Reviewed-by: Christian Brauner Signed-off-by: Josef Bacik --- 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 b1764efbc8f5..ef7de1e6d242 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2650,10 +2650,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 Wed Nov 22 17:17:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13465284 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="mNyyn5h2" Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 529FE191 for ; Wed, 22 Nov 2023 09:18:16 -0800 (PST) Received: by mail-yb1-xb33.google.com with SMTP id 3f1490d57ef6-daf2eda7efaso20925276.0 for ; Wed, 22 Nov 2023 09:18:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1700673495; x=1701278295; 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=cREJeCjECFMqWzZfrEI8pPE/PMHsOEuetZPUQgQFNuE=; b=mNyyn5h2xlX2NofWDkOy3r32rhB9MBbVwsp9Z+y/wlxeO1aQJ4DttRTaWvUrCvD5HL 98ihaBRmBoTkdrxfR5otjBvRLPneHPNfq7m4qdbSnvEJMBK3OkXzOSSG9/VRnSuTVvTg kXgs2UGkEqn2gHyXxLWBZ4G5xwDtD+SgiBLyZktSjK4/J29c7Xy4NF5X5CHxDR8peq8G d36ir+WodDXJ3bxrE3hRUaKAxHI7UXv7wvmCkaprzAr5Nzu1ix9++YRkDtUnaU4CmSPW +ECjAS/jFC/Ocv9iZsUj+MJqWj0K3rJeq87JFmFoFN6gjIkGQhRJ3fhlVALbsUGwSvrO Oi0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700673495; x=1701278295; 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=cREJeCjECFMqWzZfrEI8pPE/PMHsOEuetZPUQgQFNuE=; b=WEuxVeQqnc6Tf5nfIb5Ngg4nusFX9Zg3Q/ZQjDZWj7UDRljNxPh1qmcOvCfpQquOnO GjklyOOuwBM1wGElKaL7Vak5Dm4uFDB9IHI1MMTOZjmpjd7OpRwtwJI8oYKNH4zHaHH/ fb2q95NWscEyD0QeOGhNjgjvIfsInkdZ1Ja1PDM62DGmHL+Yoj4Ok+NjPFGJTtDqxsLm B+16UcQvj1EwwmHU92GqrJE/zqQUV+C1vjyVGT7C/3bJ677v8upw/qeQGREnOklys5o3 EjOLWQIc42nb+Hjr5rrmGPCbUk88asizNy7TcNJS6PazEMKTOSefVkC5GTcjWGDNtrTP MPjw== X-Gm-Message-State: AOJu0Yz1etAghNaEwI0WOx7GK/iRxW9cg7cJxjIySh6QCHyK55U45cp0 bKV0kDycNEL4fhp27A6BU+DqjU68gjNzx32AMyYX6S+Z X-Google-Smtp-Source: AGHT+IFq9B0CTNTwSmHroxx8G42ElNuTKjkgelv851qX9/xRiwnO1hYCln14+nfZ/2NLm8wyHEFDeg== X-Received: by 2002:a25:aa2f:0:b0:daf:6882:6f0a with SMTP id s44-20020a25aa2f000000b00daf68826f0amr3138155ybi.4.1700673495027; Wed, 22 Nov 2023 09:18:15 -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 cf27-20020a056902181b00b00d7360e0b240sm1442645ybb.31.2023.11.22.09.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 09:18:14 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 11/19] btrfs: add reconfigure callback for fs_context Date: Wed, 22 Nov 2023 12:17:47 -0500 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 210 ++++++++++++++++++++++++++++++++++++++++++----- fs/btrfs/zoned.c | 16 ++-- fs/btrfs/zoned.h | 6 +- 3 files changed, 203 insertions(+), 29 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index ef7de1e6d242..63f17dd21d4e 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -729,10 +729,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; @@ -740,35 +741,36 @@ 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) { bool ret = true; 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"))) ret = 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"); ret = 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"); ret = false; } - if (btrfs_check_mountopts_zoned(info)) + if (btrfs_check_mountopts_zoned(info, mount_opt)) ret = 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"); } @@ -1346,7 +1348,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; } @@ -2386,6 +2388,170 @@ 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 *info, + struct btrfs_fs_context *old) +{ + btrfs_info_if_set(info, old, NODATASUM, "setting nodatasum"); + btrfs_info_if_set(info, old, DEGRADED, "allowing degraded mounts"); + btrfs_info_if_set(info, old, NODATASUM, "setting nodatasum"); + btrfs_info_if_set(info, old, SSD, "enabling ssd optimizations"); + btrfs_info_if_set(info, old, SSD_SPREAD, "using spread ssd allocation scheme"); + btrfs_info_if_set(info, old, NOBARRIER, "turning off barriers"); + btrfs_info_if_set(info, old, NOTREELOG, "disabling tree log"); + btrfs_info_if_set(info, old, NOLOGREPLAY, "disabling log replay at mount time"); + btrfs_info_if_set(info, old, FLUSHONCOMMIT, "turning on flush-on-commit"); + btrfs_info_if_set(info, old, DISCARD_SYNC, "turning on sync discard"); + btrfs_info_if_set(info, old, DISCARD_ASYNC, "turning on async discard"); + btrfs_info_if_set(info, old, FREE_SPACE_TREE, "enabling free space tree"); + btrfs_info_if_set(info, old, SPACE_CACHE, "enabling disk space caching"); + btrfs_info_if_set(info, old, CLEAR_CACHE, "force clearing of disk cache"); + btrfs_info_if_set(info, old, AUTO_DEFRAG, "enabling auto defrag"); + btrfs_info_if_set(info, old, FRAGMENT_DATA, "fragmenting data"); + btrfs_info_if_set(info, old, FRAGMENT_METADATA, "fragmenting metadata"); + btrfs_info_if_set(info, old, REF_VERIFY, "doing ref verification"); + btrfs_info_if_set(info, old, USEBACKUPROOT, "trying to use backup root at mount time"); + btrfs_info_if_set(info, old, IGNOREBADROOTS, "ignoring bad roots"); + btrfs_info_if_set(info, old, IGNOREDATACSUMS, "ignoring data csums"); + + btrfs_info_if_unset(info, old, NODATACOW, "setting datacow"); + btrfs_info_if_unset(info, old, SSD, "not using ssd optimizations"); + btrfs_info_if_unset(info, old, SSD_SPREAD, "not using spread ssd allocation scheme"); + btrfs_info_if_unset(info, old, NOBARRIER, "turning off barriers"); + btrfs_info_if_unset(info, old, NOTREELOG, "enabling tree log"); + btrfs_info_if_unset(info, old, SPACE_CACHE, "disabling disk space caching"); + btrfs_info_if_unset(info, old, FREE_SPACE_TREE, "disabling free space tree"); + btrfs_info_if_unset(info, old, AUTO_DEFRAG, "disabling auto defrag"); + btrfs_info_if_unset(info, old, COMPRESS, "use no compression"); + + /* Did the compression settings change? */ + if (btrfs_test_opt(info, COMPRESS) && + (!old || + old->compress_type != info->compress_type || + old->compress_level != info->compress_level || + (!btrfs_raw_test_opt(old->mount_opt, FORCE_COMPRESS) && + btrfs_raw_test_opt(info->mount_opt, FORCE_COMPRESS)))) { + const char *compress_type = + btrfs_compress_type2str(info->compress_type); + + btrfs_info(info, "%s %s compression, level %d", + btrfs_test_opt(info, FORCE_COMPRESS) ? "force" : "use", + compress_type, info->compress_level); + } + + if (info->max_inline != BTRFS_DEFAULT_MAX_INLINE) + btrfs_info(info, "max_inline at %llu", + 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) { @@ -2663,6 +2829,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, }; @@ -2674,17 +2841,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 830f0b6ec89e..25aea5102cf1 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..a5ed2b147f21 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, @@ -123,7 +124,8 @@ static inline int btrfs_check_zoned_mode(const struct btrfs_fs_info *fs_info) return -EOPNOTSUPP; } -static inline int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info) +static inline int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info, + unsigned long *mount_opt) { return 0; } From patchwork Wed Nov 22 17:17:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13465290 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="BF6RVQH+" Received: from mail-yb1-xb44.google.com (mail-yb1-xb44.google.com [IPv6:2607:f8b0:4864:20::b44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 473E31A8 for ; Wed, 22 Nov 2023 09:18:17 -0800 (PST) Received: by mail-yb1-xb44.google.com with SMTP id 3f1490d57ef6-db048181cd3so2511276.3 for ; Wed, 22 Nov 2023 09:18:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1700673496; x=1701278296; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gCFi6Tr6kzrxo3mpf8/EcyxbBk6h1X5ogpDYJERsQJ4=; b=BF6RVQH+urpkWnvU6dHOib6K54ZVUbgq4q7BV4RvfJ2dE8l13AEtvfs5LL3GGl5Og9 g9C22pNRVYkdGcqyeUIoTMIvg6Whb1Ew+akfT+6J3tTNKI/gTCyQ1AjUtp9MQzEhzfRs TncGWSKOjbuDLuJEck3PzrSdEwfcFPmavxRLpfQbKUK2ETcalvmMhkA4fissovE2/7xc jk9M2BxDohd4B9shf20sZjUfZsNAD1Wb1685p9GXHDDNWpZF4qx87ntOgdP7PVmvZ6ec FaCcAZhCSMWM4Ek2MXBVrVsUmI+OB/zbWS31hPONfZMWyei9c0OCvP+ejLb5f0cNjlpr 3e4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700673496; x=1701278296; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gCFi6Tr6kzrxo3mpf8/EcyxbBk6h1X5ogpDYJERsQJ4=; b=JYLLScg2BglD9YTu3za2vYY+gVei7McDbQtJARjPTyuT4M/yGmed86aPCCs5mmM8Jb 50Jh/Tupj3uLaKYElDOUefjfYA6W9aZ6drGfEQvbjVej4yP9jx38d8vQeOvSf7ys/t0b spedDIg7GrvpXP1IPzsi86sKbM9i8DOVCfrp8b63GNrT/oKTNkF6XGZrHvjmWir6x5lq 0AntasNJ5W7QWB92ZHnXwZyVwGyzlGh6g5A9cQTIwPgYy7VDkRg5NxE1kqt9EKDFIpsd ucB0H6bN5CmXKKYx108ZV2s/8ql5WN7NTP69xqM1raYozZrVKrH0TB4ZYWeqzCmKlVKb 3m8g== X-Gm-Message-State: AOJu0Yy7F1gatrA5pKgl8PTwTdjY5AY5GNpNzFkcl3wkqQb6Ix3szYIZ RAc9MUHDqPB6uv/GeSxjQknwdsHL0qJ0dIM+hzCQj7NkMbU= X-Google-Smtp-Source: AGHT+IFr1RLPyXeAlmEqbr28CwctKbTE6vs2ZCtibQednrTEPwibvrJ7HjRSwrv3Pe9dVvZhf54K1w== X-Received: by 2002:a25:400d:0:b0:d9a:3811:9c57 with SMTP id n13-20020a25400d000000b00d9a38119c57mr2666038yba.43.1700673495994; Wed, 22 Nov 2023 09:18:15 -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 k16-20020a056902025000b00d9a36ded1besm1450317ybs.6.2023.11.22.09.18.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 09:18:15 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Christian Brauner Subject: [PATCH v3 12/19] btrfs: add get_tree callback for new mount API Date: Wed, 22 Nov 2023 12:17:48 -0500 Message-ID: <241685ab2b8d20c5985cbd82f8525bd0e816b2b2.1700673401.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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/ Reviewed-by: Christian Brauner Signed-off-by: Josef Bacik --- 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 63f17dd21d4e..184d89c0edfd 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -98,6 +98,7 @@ struct btrfs_fs_context { unsigned long mount_opt; unsigned long compress_type:4; unsigned int compress_level; + refcount_t refs; }; enum { @@ -2809,6 +2810,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); @@ -2819,17 +2995,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, }; @@ -2841,6 +3042,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 Wed Nov 22 17:17:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13465287 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="FEGftSVd" Received: from mail-yw1-x1144.google.com (mail-yw1-x1144.google.com [IPv6:2607:f8b0:4864:20::1144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D86C11F for ; Wed, 22 Nov 2023 09:18:18 -0800 (PST) Received: by mail-yw1-x1144.google.com with SMTP id 00721157ae682-5cd0af4a7d3so917807b3.0 for ; Wed, 22 Nov 2023 09:18:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1700673497; x=1701278297; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QlsY8IVFRzozoVSPtDgNgEBZtdoSVYJjR60tr7DOIq0=; b=FEGftSVdj6Mla0QWdcM7QaMAwoXQXcmzgUGGdyZz8l6g1e5RrX37m0B2Qz1ux4zXyh zxqrFop0+/vYDzOgEeGK/YZnAL/DMVXo8Ah48hsUpmTDrM8aF4kueVDnS+TL1LHy/A6D AaOPmLWLiRwx7L4pQHOHlKE9g/ABBoO/Xi6Fheh2MgDroO71D4bxPjzKXE/xYu/mBHNm TeyPOqpQZqond+yOv3yfZJkKm2I8WfusQD/jiQTUU5xu/cj8FdLRYvPLG4+lfRTsXGtb 4+7BeZ+maDU7M8+IpdIVMicgCkS7EM62uZOjX0jGgBcccwNL2us/3EG76zopHuOGSHiL QMzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700673497; x=1701278297; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QlsY8IVFRzozoVSPtDgNgEBZtdoSVYJjR60tr7DOIq0=; b=oXCHlqBAg/T8p8kBK24RSDR3mWxQ92tA7o80JJ7enBBbypp3JVR5rmOLU3Ow8UAEpv tHBmdJc8k6fDhfpGEru46KyJ5Cebw95PDvXRA0zcueRfyYlhg+/4EswfBG0VRjLggrRm 8SCDZVSpPD6DZ0IE+uk1NPEkh7i63m2CfYGDi6+/y2/6wv5i7GTlFTZw0GTr0TFB/LAK FMUkI8nnhrrz7vVP6UogEmwh0g8Iz6Q7lN7KduvjhERLMMyS20ZusULsuqv3GwB7JQxL 0f7hdCD2s0uM1vk8z7fQXIjGwhi+ExoDQa/c4H1dRW+cVTsKI1nC5FqVGAjfGM4+Mki9 ogjA== X-Gm-Message-State: AOJu0Yz3C9waNqigzIwztetniVdSw6zTYe5OSV2p/5AWGfUVMT7ABpl3 +rueW2SovioQ067vRcUnmnLaQ2PgiyjnHtt+dCiT8C9i7A4= X-Google-Smtp-Source: AGHT+IGUxA4U0CaH/a9KmvLVky1jm3N+Xg8hL4E49AhJLml6bM27yYx3GUABZUgBvOLPo9Rr+xI5QQ== X-Received: by 2002:a0d:dbc3:0:b0:5ca:f2ff:a346 with SMTP id d186-20020a0ddbc3000000b005caf2ffa346mr2786405ywe.13.1700673497062; Wed, 22 Nov 2023 09:18:17 -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 h17-20020a81b411000000b00577269ba9e9sm3788052ywi.86.2023.11.22.09.18.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 09:18:16 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Christian Brauner Subject: [PATCH v3 13/19] btrfs: handle the ro->rw transition for mounting different subovls Date: Wed, 22 Nov 2023 12:17:49 -0500 Message-ID: <72054b19620fda64c1d2052f99a848754891f34b.1700673401.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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/ Reviewed-by: Christian Brauner Signed-off-by: Josef Bacik --- 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 184d89c0edfd..c2b42f0e6a07 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2489,13 +2489,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)); @@ -2898,6 +2900,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_ONLY 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; @@ -2947,6 +3076,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 Wed Nov 22 17:17:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13465285 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="KmJaX3pn" 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 4A22D83 for ; Wed, 22 Nov 2023 09:18:19 -0800 (PST) Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-5cb8440a23cso23687337b3.3 for ; Wed, 22 Nov 2023 09:18:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1700673498; x=1701278298; 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=5aAowW0B1vhc5svaJC1OJMk+SQsoJKCurL9XlqABdxg=; b=KmJaX3pnL6oiqbCqAPKOEEuzR6C3SfmHhtxQLN8ZFw4FCglkZhitK6CwX2ZicfwyOZ FxUhkx7NCbYS6El5ZFRMvFcGvAJRuXMetLGX8OT+xFTfMCWZdyboPUGexlsPbof55TPz SX0y3F4g73UHOvr7EgAveXWmDbR9RxQxlpyqz9dZq8HFeYOEOjnJR0lNfNUww5Vtnw5Q gJAUeX/OCasjS3U9FZu/4cZpkFcMLoqgC85yFSUvuYbbRk3fi83HnHuTLQEW8YyHDdKR HYSHkYlP7IWonSnu3lgBhh6iec/8l0GgmNp2GcK66aF0SxFWi08GzyZS9SwUUYPZl6k4 SrHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700673498; x=1701278298; 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=5aAowW0B1vhc5svaJC1OJMk+SQsoJKCurL9XlqABdxg=; b=WOw+nf2c61VqQWYLuL946y0k28WcGlrqmYXCR6HtvfI9NcX8SXHQVz8i1IuqFyYheb 8wJ2pMQubCDZ3PRqz1dLc3vP6X0f+9gtm3EeIqNQraXBNMQz4ayqcGg5cYxak8+uhxyU qN4AntcmKPyUL6eW19zOtPPjIjJkh28O2I/RQjnEjdaYs6rwgO3HewUex3SjJGwWN91o p+7E1EtIXoNGemgG8dybpjwtC1kq/36XYe1pTjV0EMJLKr2nAwBOtPALqqf1UwdmowpM zgcG4Z5W0clRkdNF0qckS2c/pytgOPRIJHqbKQC9LBDrkrzEpd2V0Fg7/1nTxx4uyC97 FTxQ== X-Gm-Message-State: AOJu0YzW/QG7Ua1A21mI9TnqTztl30kvl1gE1lJIANGyzc3+ytcPrNug Cr/htHUR2aSceiO2coBY49nB+W0kM0Uay0PMG5kW7WfI X-Google-Smtp-Source: AGHT+IGC0Cbv0n/HR2mGWEj9MbZKVQB/pdZMl3RdYVEElESW0zW1NSSmWcylUqgcYDIb63WJw/5W8A== X-Received: by 2002:a81:b726:0:b0:5cc:d0bc:fc24 with SMTP id v38-20020a81b726000000b005ccd0bcfc24mr1286959ywh.22.1700673498206; Wed, 22 Nov 2023 09:18:18 -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 m2-20020a819c02000000b0057a44e20fb8sm3798134ywa.73.2023.11.22.09.18.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 09:18:17 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 14/19] btrfs: switch to the new mount API Date: Wed, 22 Nov 2023 12:17:50 -0500 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 11 ++++-- fs/btrfs/super.c | 88 ++++++++++++++++++++++++++-------------------- fs/btrfs/super.h | 2 ++ 3 files changed, 60 insertions(+), 41 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 3c72bc1d09a3..6df8dbea3581 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3308,14 +3308,21 @@ 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) goto fail_alloc; + /* + * At this point our mount options are validated, if we set ->max_inline + * to something non-standard make sure we truncate it to sectorsize. + */ + fs_info->max_inline = min_t(u64, fs_info->max_inline, fs_info->sectorsize); + if (sectorsize < PAGE_SIZE) { struct btrfs_subpage_info *subpage_info; diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index c2b42f0e6a07..3bb77fb72f03 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -307,7 +307,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), @@ -742,8 +742,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) { bool ret = true; @@ -792,18 +792,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)) { @@ -813,6 +801,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) @@ -1349,7 +1366,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; } @@ -1650,10 +1667,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); @@ -1933,7 +1946,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; @@ -2066,7 +2079,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; @@ -2497,7 +2510,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)); @@ -3165,7 +3178,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; @@ -3186,24 +3199,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_BINARY_MOUNTDATA | FS_ALLOW_IDMAP, + }; MODULE_ALIAS_FS("btrfs"); @@ -3416,7 +3427,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 Wed Nov 22 17:17:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13465286 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="rzC16qit" Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E5DE1B1 for ; Wed, 22 Nov 2023 09:18:20 -0800 (PST) Received: by mail-yb1-xb2e.google.com with SMTP id 3f1490d57ef6-db3a09e96daso3303126276.3 for ; Wed, 22 Nov 2023 09:18:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1700673499; x=1701278299; 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=qfG4hyB4O5XNpX1RJYjLDGWKE4yC6O/Sj1eGyBCJcN4=; b=rzC16qitHtEUDtPpdRTpdljHJcRB6Ng/e52bq3+UmSyFCMcK/Zz0cRsBsBB7gdGzAn KkbKZG0f/EkYzy6rSqgTrRRgEJApSEuYKN9bGTPKgevBz3mRadjsdJCls0M5ewMG1YWe eYboI4EAVIv3aIKXm15RBUjsFsKxtTC2FFXihWVrEhXPQKkH1/GsAZLbHQk1197Xnwk5 cMosl+0rFhH1uaOZC8gs0sKAx+871eZr8Pvon+2ECQnHwbRvKTAKXMMl8POJf0nY/lhW 04UnRNc9MtfAa9SqKGJgCFoBo5fHz6jGcCmZ3Vv6StsbjLdyARVf/GADihKa6aYHPkWc pWCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700673499; x=1701278299; 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=qfG4hyB4O5XNpX1RJYjLDGWKE4yC6O/Sj1eGyBCJcN4=; b=tn0cBhlMYwGLA8gYMGM9g8YgvNiFSjUC8e40BmVAJn5EYz+h3Bfqaf9aP4vGwLuItI U4GQemKTIzWzpzqUNa289+UO05P1RaTkuuI/hVq/bQL69iEQICGZPo9OpRX2wk5XhBPu vsf3Cff0KbH6S6waxwRsPHJgUln9r9r4EiqyQhJJnnwYkXSNatftH2wwni0+AcKBgnUc OWoMpd79l1n8liN+7b2HFgN3iy6qrMFZiTUKxKiOIczr8ShRant6nzwD4u+NwsngCKhI +iG+TTvXKmWA983rYQiHhY0OH+Fuw7WqAiigQANgawsdqtv3EhdYN7GrAJJkdBklNhNx 8mxA== X-Gm-Message-State: AOJu0YxxYNRW+9age2pA4xD6hoLtCMVN4EfUxh8DEzfviITp/UIvf5Z6 oj9fSmtaJy+dMFbBPNyZtgO4Jw8Y3Cx9ImlmuEIAM0pg X-Google-Smtp-Source: AGHT+IHS7b91/ODATFX/M3iG9EwQI8nHpGObE3DCFudOQoDcFDvKF/GdBMLBFlaVM8YfLoXOq93TDA== X-Received: by 2002:a25:8748:0:b0:db3:fd83:e0f with SMTP id e8-20020a258748000000b00db3fd830e0fmr2549769ybn.10.1700673499263; Wed, 22 Nov 2023 09:18:19 -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 d13-20020a5b00cd000000b00d8674371317sm1447110ybp.36.2023.11.22.09.18.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 09:18:18 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 15/19] btrfs: move the device specific mount options to super.c Date: Wed, 22 Nov 2023 12:17:51 -0500 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 6df8dbea3581..367bf31230df 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3502,29 +3502,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 3bb77fb72f03..a6d4bda7330e 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -832,6 +832,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; @@ -2889,6 +2912,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 Wed Nov 22 17:17:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13465292 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="KeP9bUMv" 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 E9160191 for ; Wed, 22 Nov 2023 09:18:21 -0800 (PST) Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-5cce5075bd6so525087b3.0 for ; Wed, 22 Nov 2023 09:18:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1700673501; x=1701278301; 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=pmkfI+/JeyTchEK7Uxn3WAuXiIt70oV672WENtMLxHY=; b=KeP9bUMvKYjpjSZTF1pH0VV0w/RxrVsiOfK7HV2uvqaSP6YgnIMWz8rLgGpoW23BTt UWrxEW5NQmlsZHl6MiqIyhxmEskgkA4wJ5keUMMwETvCVg4kD9V5vE6Upw+Sn3bR0KPB QoRujENsU8iPfpuh7CgczjnblDmY1m1hJFYU0X99aA9j4W3G1OH0L1AgN1C6+AQzpfQ2 oDJpb1K5WMWvyQ7SSQLl97Rt+y5SRTNoUux3HU02PU68qR2Of+X5Jwp0GBQgz/I2U2Ae zq77qK8SO/n84QKNo0vYGaD4H92uFkVuQTkAWgKl4B/p0EWVr61jI052g5+YYpyGBtD4 NUIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700673501; x=1701278301; 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=pmkfI+/JeyTchEK7Uxn3WAuXiIt70oV672WENtMLxHY=; b=bqkBeCHd5ONrLDGbOwkH+ULae28SsqYao/fDo+VRad9mexdr5pkM8URRLgvXZWo3qC p0BigiKtMoqdhBbm3ixPdR9voLqlod2Zb/DKpm/VHeZc+LlsiirFve95wI872v7jQ9TA wOPchN7+POQHuoRjtfrPKKQLOz0bwVvSmB7k6J/v5ZxoKJam5860NcYSdSe4P7JW3mcu 5FwS2UQGXJ8MCHnxc5Nn9CbgimHjlG/m6KankeJRna6bBtZcwnx05g5VpoLiIUU3ccGV 723Ih5Wpn8Ygy8Z593693U5ZxxdZtZOY+iUVoosq3lyfminDgo75+hlUETVT4f2My+TA Tgaw== X-Gm-Message-State: AOJu0YxiX2O5lJvuZrFTHErxGEKMOVtjlSYyaJOiqid1zoHob+iHbDDC 724edaRJ30SMf0eSmmQnVSgIr2T98ZjH9mYwiHZylkTU X-Google-Smtp-Source: AGHT+IHPwwZChZJbjNaw6j5wtmevuMFF+VumkRU8YqaS1TwJ9LunCkRPlvumZPIJzB/5scv5D1Kdag== X-Received: by 2002:a0d:e804:0:b0:5c9:bce2:57d1 with SMTP id r4-20020a0de804000000b005c9bce257d1mr104759ywe.23.1700673500335; Wed, 22 Nov 2023 09:18:20 -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 h138-20020a816c90000000b005cd1401fceasm5364ywc.97.2023.11.22.09.18.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 09:18:19 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 16/19] btrfs: remove old mount API code Date: Wed, 22 Nov 2023 12:17:52 -0500 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 e6f7ee85032e..f8bb73d6ab68 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -962,20 +962,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 a6d4bda7330e..f5bf53f826ef 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) { @@ -102,7 +90,7 @@ struct btrfs_fs_context { }; enum { - Opt_acl, Opt_noacl, + Opt_acl, Opt_clear_cache, Opt_commit_interval, Opt_compress, @@ -112,27 +100,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 */ @@ -145,10 +132,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 @@ -158,88 +145,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, @@ -855,660 +760,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) { @@ -1872,22 +1123,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 */ @@ -1963,200 +1198,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) { @@ -2332,99 +1373,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 Wed Nov 22 17:17:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13465288 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="zvCOagGX" Received: from mail-yb1-xb2f.google.com (mail-yb1-xb2f.google.com [IPv6:2607:f8b0:4864:20::b2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4073C197 for ; Wed, 22 Nov 2023 09:18:22 -0800 (PST) Received: by mail-yb1-xb2f.google.com with SMTP id 3f1490d57ef6-d9b9adaf291so10189276.1 for ; Wed, 22 Nov 2023 09:18:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1700673501; x=1701278301; 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=9f/7IJL9HuJi7e0J8Xeyt7VmGdh90l2ExAlFN14VjDU=; b=zvCOagGX1Rrf0TbOPtOF8onkcz6rW7V5HPG8S08ZnNwQpadaOUV2CW5aMF7v9gN5fD FB+5n/Qwzw5jcOna0Z0HMTF/0Nra0YAPdanUFbL9UpVGhVaiOAcoy2HKSuT1ie6YMk+t 0vLWxFjqIhDNtudDb7lHnJr3pLe43UgeOtUfSUiE9toi0spmANdv8jiLaFSIHQmGBG7t azOvbq2GEvIA/XJFCbvDPYnzV8mWzwAr6rD+RPIZNo03xnwf7TsrzZO0JnjvLUFCQZMn OWEib5DVbi9RaPBwb8VEwZgXBzUVhl6u3qQXzkrC/KyWehB7OL2Vbu9bYN0wmA3W/9C2 1Zfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700673501; x=1701278301; 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=9f/7IJL9HuJi7e0J8Xeyt7VmGdh90l2ExAlFN14VjDU=; b=UvPQwPxbEdkYp6v0E68Sj0ErGc+Z2jqv2AHmGa+yO3xgiOKxuzYh849K28aCIaNl/3 okd2Q7rNX6H3fwHTDv2siB/VGgEAFuGelBhMaQzl4dGH74g9Zn7VlTZvBeqpkUQIuSk5 6xXbJf3MZ/2gHSMOu5TDasZU76VjP3rNiwwnMW1FI/IWjyWKnoYt2AxB+cgFCq7DYUjK ICpXNfv4GWameKHJLsjoB+7fgSX0imN5Tz+Z6Q8eE21kL9Jq6nXQ6Wpzk1Q9r2X+T9Yk Jz51+ECeObx0z47L0dnrnPa7bshrcUQuFJdM+wt9iUx9vgV8kW8i2voKZitmdMw5bKg4 rGgg== X-Gm-Message-State: AOJu0Yx4rHq/GqxIv6gk7L8zZeZk/kOn1yn1QeEJ6x+R9A3V5fsxtOOK XM+bTeuaE6sTABGfTfJRJ+iQEbK6Nxd7AXeh4DBmyPN+ X-Google-Smtp-Source: AGHT+IFDbkBGOCVayyn3PCgTN/nhyKMLuFUowd19wl8yJnnGjAVJ/cZexlV9FpAYD1cX4jdmJYE4kw== X-Received: by 2002:a81:5e83:0:b0:5cb:57da:e607 with SMTP id s125-20020a815e83000000b005cb57dae607mr3175311ywb.30.1700673501252; Wed, 22 Nov 2023 09:18:21 -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 m4-20020a0dfc04000000b005845e6f9b50sm3832508ywf.113.2023.11.22.09.18.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 09:18:20 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 17/19] btrfs: move one shot mount option clearing to super.c Date: Wed, 22 Nov 2023 12:17:53 -0500 Message-ID: <916760deedbcd13112c16879c42e4f657dd78f89.1700673401.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 367bf31230df..c688eba0312f 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2938,18 +2938,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. @@ -3527,7 +3515,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) { @@ -3555,8 +3543,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 f5bf53f826ef..30603248b71c 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -635,6 +635,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) @@ -1878,6 +1891,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 Wed Nov 22 17:17:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13465289 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="WS1sE5Nl" Received: from mail-yw1-x1132.google.com (mail-yw1-x1132.google.com [IPv6:2607:f8b0:4864:20::1132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 470561A4 for ; Wed, 22 Nov 2023 09:18:23 -0800 (PST) Received: by mail-yw1-x1132.google.com with SMTP id 00721157ae682-5cc589c0b90so10957617b3.2 for ; Wed, 22 Nov 2023 09:18:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1700673502; x=1701278302; 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=CAilSxqh1txTS7OyIFklNF4zhihXwft90BLRolkYYzE=; b=WS1sE5NlaQuPT9JM0LLiVOXYDY87x3zNPT43zA8jUJuWcugQc9Z6xOZ5ze4wUxdZMa pd+6spGYx0zUgmlEiNjkLNOtIWGQmKJu5XChZUPdMI7rnsKepsnXNpL6A4/mt3uQBeCu Tp30QUk7tbQY2j8nWXBWmrvLqsSqA3rtA0rhMRlyxRLCWwiAW8qcCUP7PQ3K3d6wOj8G Qlf6a763RBreFOHDVDNDgAqSelgwtiCDv/ikOM4GPD438qfcLys7f0SHZT/wy52Y/HUu I1UXyoyW/m5vkMFYoQGI2qliPGZdMa5qF2Sf2KRjTED8jPg5OSvx0XZLOyyEwx/8dSuw 73/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700673502; x=1701278302; 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=CAilSxqh1txTS7OyIFklNF4zhihXwft90BLRolkYYzE=; b=TfqJwzhavnCi4310NiaUSRDTwN1RIRZe3RPGTxA1FdQBZL4W2vQze8XjpFq9A6MHkQ Qi225bNxAmEP2UoE9f6uuzNY/BLK1ezNPzV2eCzAtVYmgs5yddLQ68VDQ13WUIUSaPe6 vXTKaMlKwptrwkZ5RG/7p97+7wNX13UV0CvvMrL8yDSddTokg/0f/TRv2TVTGognUeQG sjuuBZuC0Ujz9kqsV+h6vEqB7pBjkRTUzpoWYcwO7bwHuFrgDPhxqFBnSQM65dWKSMGx IwEvDRBXvm8McZsMPADHhJPu+D85ilGYjaecG9fgJdeMemN+q152a3YfyDvNcel5M/Qc ZFFA== X-Gm-Message-State: AOJu0YyPUHI7MYeorCh48QmvH0OiiED+emojT/9Tn1h4hn7c7KDIAy3A SUct6/bt+0ppCpFcLzaclOJ/wVHsMbvqMiTWpaMaNSAy X-Google-Smtp-Source: AGHT+IGI6BJKwDRgvPRB6aPNHMEu3cRKwkFEfcQA68SwlTsZH1kBb7C4KZLtN4E6Sbg7xePb62/fUg== X-Received: by 2002:a81:6c07:0:b0:5a9:30c3:c664 with SMTP id h7-20020a816c07000000b005a930c3c664mr3146076ywc.19.1700673502296; Wed, 22 Nov 2023 09:18:22 -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 b1-20020a0dc001000000b005a4da74b869sm3846198ywd.139.2023.11.22.09.18.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 09:18:21 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 18/19] btrfs: set clear_cache if we use usebackuproot Date: Wed, 22 Nov 2023 12:17:54 -0500 Message-ID: <026c5b257818ffc5b29421f7e3b039a626936ea5.1700673401.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 c688eba0312f..719245d73b99 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2622,9 +2622,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 30603248b71c..17fd0a438537 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -456,6 +456,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: @@ -554,6 +560,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); From patchwork Wed Nov 22 17:17:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13465291 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="G7PmPc8u" Received: from mail-yw1-x1133.google.com (mail-yw1-x1133.google.com [IPv6:2607:f8b0:4864:20::1133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DE1B83 for ; Wed, 22 Nov 2023 09:18:24 -0800 (PST) Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-5cbbe2cba33so19023467b3.1 for ; Wed, 22 Nov 2023 09:18:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1700673503; x=1701278303; 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=BiTjWmy4vJZo6BlhqNQcEYY6KSKiyt3LwZZttTCg/UE=; b=G7PmPc8ude4xe7o8U/57d/bvVGthtSOhoTG8yTi3CD4FmgjSb+7azDJzfzUqIKEPKu YB1Q/1shlznt9vSuvhb/PH3Lvm7jyrcSIlD814uGs+At1Ibnmc5H+MaMbm3b3XCUxjU/ eaWyrSkOk+F85QDWX50noZkZ6f3D7bkTEFFqy9YgywzpzVId1UESJc730eUmJVXDuW+q fxE8sTb6S8eOEWoYO+rmne4LLOJwOJXh5ah8WXHYU3//0ZzqAJZ71cw4HVH/PD/mLtQu 1Vpcwdem/OHhTTEZVkzWQ/ZS44Z63xts4HAVJBXKnSgwJp7/D/YhHXuVmFPKqTti+gau h98g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700673503; x=1701278303; 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=BiTjWmy4vJZo6BlhqNQcEYY6KSKiyt3LwZZttTCg/UE=; b=jwAWwVNcoj4xIE8hDqznpbJ7ryxsEopyrmfQwJoERzWNHgZbbUs+QN/HJ1mS2UhhTK ubrZchinhY17ofkjVeEiqadsJ75ulZvv8OrNmHi+FKhZLqhOT4U9PHpNDPegJyr1gM5U H2C2B7Rbguxn05bTeNfstsxSojmWwmr8giC2X/2wfUAMtFscpxTenE/pjZ+9RfH9TZCL 4HI/aqL0mu2PMcUDJFwWlpwLDdNoGTIaULVD/OKmtw6aPnvZp5iTYzSlNaXOnZNsfM+q yl/5poO+IgJnBg8DJMp9LPqZYrlIkP05wZkpy8EEhUllEO/H2yMNnoJKKu8eHOgqI0n6 rZLQ== X-Gm-Message-State: AOJu0YxzQsREbTNcFQZW/Nne8YqkLbSidBwlYjv6xW5D/v86FgXy1Ukl NBe2kzV2Qk+KGH3QFsL2yOLUIHLt+oSKvD62onCG5sLJ X-Google-Smtp-Source: AGHT+IHFt2HnaSBdZqayOZ/jkrIrhK6onRuD2u0+HXeCZlT3pGRtSBS/PCdF45H3N1JkghPQDkNJDA== X-Received: by 2002:a81:5c07:0:b0:5ca:6e:35d3 with SMTP id q7-20020a815c07000000b005ca006e35d3mr2711501ywb.30.1700673503318; Wed, 22 Nov 2023 09:18:23 -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 u65-20020a0deb44000000b005cd091e885dsm43713ywe.30.2023.11.22.09.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 09:18:22 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 19/19] btrfs: remove code for inode_cache and recovery mount options Date: Wed, 22 Nov 2023 12:17:55 -0500 Message-ID: <91c34f25266be07585b75fde0b580b9118f8786e.1700673401.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We've deprecated these a while ago, go ahead and remove the code for them. Signed-off-by: Josef Bacik --- fs/btrfs/super.c | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 17fd0a438537..8ce7c880e9ce 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -130,10 +130,6 @@ enum { Opt_ignoredatacsums, Opt_rescue_all, - /* Deprecated options */ - Opt_recovery, - Opt_inode_cache, - /* Debugging options */ Opt_enospc_debug, #ifdef CONFIG_BTRFS_DEBUG @@ -224,7 +220,6 @@ static const struct fs_parameter_spec btrfs_fs_parameters[] = { 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), @@ -255,10 +250,6 @@ static const struct fs_parameter_spec btrfs_fs_parameters[] = { __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 @@ -442,28 +433,6 @@ static int btrfs_parse_param(struct fs_context *fc, 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); - - /* - * 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: btrfs_warn(NULL, "'nologreplay' is deprecated, use 'rescue=nologreplay' instead"); @@ -534,10 +503,6 @@ static int btrfs_parse_param(struct fs_context *fc, 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;