All of lore.kernel.org
 help / color / mirror / Atom feed
From: Naohiro Aota <naohiro.aota@wdc.com>
To: David Sterba <dsterba@suse.com>
Cc: linux-btrfs@vger.kernel.org, Josef Bacik <josef@toxicpanda.com>,
	Naohiro Aota <naohiro.aota@wdc.com>
Subject: [PATCH 24/26] btrfs-progs: zoned: wipe temporary superblocks in superblock log zone
Date: Mon, 26 Apr 2021 15:27:40 +0900	[thread overview]
Message-ID: <3425b775916cd02bb7bdf57e018ea0ead833db4e.1619416549.git.naohiro.aota@wdc.com> (raw)
In-Reply-To: <cover.1619416549.git.naohiro.aota@wdc.com>

Mkfs.btrfs uses a temporary superblock during the initialization process.
The temporary superblock uses BTRFS_MAGIC_TEMPORARY as its magic which is
different from a regular superblock. As a result, libblkid, which only
supports the usual magic, cannot recognize the volume as btrfs. So, let's
wipe the temporary magic before writing out the usual superblock.

Technically, we can add the temporary magic to the libblkid's table. But,
it will result in recognizing a half-baked filesystem as btrfs, which is
not ideal.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 kernel-shared/disk-io.c |  6 ++++++
 kernel-shared/zoned.c   | 20 ++++++++++++++++++++
 kernel-shared/zoned.h   |  6 ++++++
 3 files changed, 32 insertions(+)

diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c
index d79d6a00cdf8..355010277ca9 100644
--- a/kernel-shared/disk-io.c
+++ b/kernel-shared/disk-io.c
@@ -1951,6 +1951,12 @@ int close_ctree_fs_info(struct btrfs_fs_info *fs_info)
 	}
 
 	if (fs_info->finalize_on_close) {
+		ret = btrfs_wipe_temporary_sb(fs_info->fs_devices);
+		if (ret) {
+			error("zoned: failed to wipe temporary super blocks: %m");
+			goto skip_commit;
+		}
+
 		btrfs_set_super_magic(fs_info->super_copy, BTRFS_MAGIC);
 		root->fs_info->finalize_on_close = 0;
 		ret = write_all_supers(fs_info);
diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c
index 3c476eebf004..8801ed43157e 100644
--- a/kernel-shared/zoned.c
+++ b/kernel-shared/zoned.c
@@ -975,6 +975,26 @@ int btrfs_reset_chunk_zones(struct btrfs_fs_info *fs_info, u64 devid,
 	return 0;
 }
 
+int btrfs_wipe_temporary_sb(struct btrfs_fs_devices *fs_devices)
+{
+	struct list_head *head = &fs_devices->devices;
+	struct btrfs_device *dev;
+	int ret = 0;
+
+	list_for_each_entry(dev, head, dev_list) {
+		struct btrfs_zoned_device_info *zinfo = dev->zone_info;
+
+		if (!zinfo)
+			continue;
+
+		ret = btrfs_reset_dev_zone(dev->fd, &zinfo->zones[0]);
+		if (ret)
+			break;
+	}
+
+	return ret;
+}
+
 #endif
 
 int btrfs_get_dev_zone_info_all_devices(struct btrfs_fs_info *fs_info)
diff --git a/kernel-shared/zoned.h b/kernel-shared/zoned.h
index 9e1ce3ae103f..a2e84464a221 100644
--- a/kernel-shared/zoned.h
+++ b/kernel-shared/zoned.h
@@ -94,6 +94,7 @@ int btrfs_reset_chunk_zones(struct btrfs_fs_info *fs_info, u64 devid,
 int btrfs_reset_all_zones(int fd, struct btrfs_zoned_device_info *zinfo);
 int zero_zone_blocks(int fd, struct btrfs_zoned_device_info *zinfo, off_t start,
 		     size_t len);
+int btrfs_wipe_temporary_sb(struct btrfs_fs_devices *fs_devices);
 #else
 #define sbread(fd, buf, offset) \
 	pread64(fd, buf, BTRFS_SUPER_INFO_SIZE, offset)
@@ -154,6 +155,11 @@ static inline int zero_zone_blocks(int fd,
 	return -EOPNOTSUPP;
 }
 
+static inline int btrfs_wipe_temporary_sb(struct btrfs_fs_devices *fs_devices)
+{
+	return 0;
+}
+
 #endif /* BTRFS_ZONED */
 
 static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos)
-- 
2.31.1


  parent reply	other threads:[~2021-04-26  6:28 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-26  6:27 [PATCH 00/26] btrfs-progs: zoned: zoned block device support Naohiro Aota
2021-04-26  6:27 ` [PATCH 01/26] btrfs-progs: utils: Introduce queue_param helper function Naohiro Aota
2021-04-26  7:26   ` Johannes Thumshirn
2021-04-26  6:27 ` [PATCH 02/26] btrfs-progs: provide fs_info from btrfs_device Naohiro Aota
2021-04-26  7:25   ` Johannes Thumshirn
2021-04-26  6:27 ` [PATCH 03/26] btrfs-progs: build: zoned: Check zoned block device support Naohiro Aota
2021-04-26  6:27 ` [PATCH 04/26] btrfs-progs: zoned: add new ZONED feature flag Naohiro Aota
2021-04-26  7:45   ` Johannes Thumshirn
2021-04-27 15:45     ` David Sterba
2021-04-27 15:46   ` David Sterba
2021-04-28  0:07     ` Naohiro Aota
2021-04-26  6:27 ` [PATCH 05/26] btrfs-progs: zoned: get zone information of zoned block devices Naohiro Aota
2021-04-26  7:32   ` Su Yue
2021-04-27 16:45     ` David Sterba
2021-04-28  0:09       ` Naohiro Aota
2021-04-26  6:27 ` [PATCH 06/26] btrfs-progs: zoned: check and enable ZONED mode Naohiro Aota
2021-04-26  7:48   ` Johannes Thumshirn
2021-04-26  6:27 ` [PATCH 07/26] btrfs-progs: zoned: introduce max_zone_append_size Naohiro Aota
2021-04-26  7:51   ` Johannes Thumshirn
2021-04-26  6:27 ` [PATCH 08/26] btrfs-progs: zoned: disallow mixed-bg in ZONED mode Naohiro Aota
2021-04-26  7:56   ` Johannes Thumshirn
2021-04-26  6:27 ` [PATCH 09/26] btrfs-progs: zoned: allow zoned filesystems on non-zoned block devices Naohiro Aota
2021-04-26 13:43   ` Johannes Thumshirn
2021-04-26  6:27 ` [PATCH 10/26] btrfs-progs: zoned: implement log-structured superblock for ZONED mode Naohiro Aota
2021-04-26 16:04   ` Johannes Thumshirn
2021-04-26  6:27 ` [PATCH 11/26] btrfs-progs: zoned: implement zoned chunk allocator Naohiro Aota
2021-04-27 17:19   ` David Sterba
2021-04-27 19:58     ` Johannes Thumshirn
2021-04-26  6:27 ` [PATCH 12/26] btrfs-progs: zoned: load zone's allocation offset Naohiro Aota
2021-04-26  6:27 ` [PATCH 13/26] btrfs-progs: zoned: implement sequential extent allocation Naohiro Aota
2021-04-26  6:27 ` [PATCH 14/26] btrfs-progs: zoned: calculate allocation offset for conventional zones Naohiro Aota
2021-04-26  6:27 ` [PATCH 15/26] btrfs-progs: zoned: redirty clean extent buffers in zoned btrfs Naohiro Aota
2021-04-26  6:27 ` [PATCH 16/26] btrfs-progs: zoned: reset zone of freed block group Naohiro Aota
2021-04-26  6:27 ` [PATCH 17/26] btrfs-progs: zoned: support resetting zoned device Naohiro Aota
2021-04-26  6:27 ` [PATCH 18/26] btrfs-progs: zoned: support zero out on zoned block device Naohiro Aota
2021-04-26  6:27 ` [PATCH 19/26] btrfs-progs: zoned: support wiping SB on sequential write zone Naohiro Aota
2021-04-26  6:27 ` [PATCH 20/26] btrfs-progs: mkfs: zoned: detect and enable zoned feature flag Naohiro Aota
2021-04-26  6:27 ` [PATCH 21/26] btrfs-progs: mkfs: zoned: check incompatible features with zoned btrfs Naohiro Aota
2021-04-26  6:27 ` [PATCH 22/26] btrfs-progs: mkfs: zoned: tweak initial system block group placement Naohiro Aota
2021-04-26  6:27 ` [PATCH 23/26] btrfs-progs: mkfs: zoned: use sbwrite to update superblock Naohiro Aota
2021-04-26  6:27 ` Naohiro Aota [this message]
2021-04-26  6:27 ` [PATCH 25/26] btrfs-progs: zoned: device-add: support ZONED device Naohiro Aota
2021-04-26  6:27 ` [PATCH 26/26] btrfs-progs: zoned: introduce zoned support for device replace Naohiro Aota
2021-04-29 15:53 ` [PATCH 00/26] btrfs-progs: zoned: zoned block device support David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3425b775916cd02bb7bdf57e018ea0ead833db4e.1619416549.git.naohiro.aota@wdc.com \
    --to=naohiro.aota@wdc.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.