Skip to contentSkip to conversation

Questions about mkfs -A option

DISCUSSION Wang Sheng-Hui 2 participants 4 messages Oct 17, 2012 – Oct 25, 2012 1 message not in the archive Btrfs file system

lore
Share & tools
lore
#0 lore raw

Hi,

I'm reading the mkfs code, and confused by its -A option.

Quoted 1 line

From its comments, the value specified by -A should be regarded as

the start of the filesystem. But mkfs will always zero some area at the beginning of the first dev, regardless -r specified or not.

My question is:
Why mkfs zeros the beginning of the first dev? Is that expected? And any use case for -A option?

thanks,

#2 lore raw
In reply to a message not in the archive
Quoted 2 lines · Alex Lyakas

Wang,
I would say that zeroing is done to prevent from seeing some other superblock (besides btrfs) there.

That make sense.

Quoted 4 lines

Alex.

But I still confused by the -A option?

In mkfs, we always write the sb info into BTRFS_SUPER_INFO_OFFSET.

Quoted 1 line

From the -A comment, I think btrfs would be places after the -A value.

What would happen if we specify a -A value larger than it?

Thanks,
Sheng-Hui

#3 lore raw

Hi Wang,
if you just look at the code in find_free_dev_extent():
u64 search_start = 0;
...
search_start = max((u64)1024 * 1024, search_start);
if (root->fs_info->alloc_start + num_bytes <= device->total_bytes)

	search_start = max(root->fs_info->alloc_start, search_start);

...
key.objectid = device->devid;
key.offset = search_start;
key.type = BTRFS_DEV_EXTENT_KEY;

You see that it will search for DEV_EXTENTs (when allocating chunks) that begin after the value you specified. So it will not use some space at the beginning of the device for allocations. Same behavior in the kernel can be caused by using "alloc_start=X" mount option. What is the purpose of this I don't know, but what it does looks pretty clear. The (first copy of the) superblock, though, is always written to BTRFS_SUPER_INFO_OFFSET, as you mentioned.

Alex.

Quoted 23 lines · Wang Sheng-Hui
Quoted 2 lines · Alex Lyakas

Wang,
I would say that zeroing is done to prevent from seeing some other superblock (besides btrfs) there.

That make sense.

Quoted 4 lines

Alex.

But I still confused by the -A option?

In mkfs, we always write the sb info into BTRFS_SUPER_INFO_OFFSET. From the -A comment, I think btrfs would be places after the -A value. What would happen if we specify a -A value larger than it?

Thanks,
Sheng-Hui

#4 lore raw
Quoted 20 lines · Alex Lyakas

Hi Wang,
if you just look at the code in find_free_dev_extent():
u64 search_start = 0;
...
search_start = max((u64)1024 * 1024, search_start);
if (root->fs_info->alloc_start + num_bytes <= device->total_bytes)

	search_start = max(root->fs_info->alloc_start, search_start);

...
key.objectid = device->devid;
key.offset = search_start;
key.type = BTRFS_DEV_EXTENT_KEY;

You see that it will search for DEV_EXTENTs (when allocating chunks) that begin after the value you specified. So it will not use some space at the beginning of the device for allocations. Same behavior in the kernel can be caused by using "alloc_start=X" mount option. What is the purpose of this I don't know, but what it does looks pretty clear. The (first copy of the) superblock, though, is always written to BTRFS_SUPER_INFO_OFFSET, as you mentioned.

Quoted 3 lines

Alex.

Thanks, Alex.

Quoted 26 lines · Wang Sheng-Hui
Quoted 23 lines · Alex Lyakas
Quoted 3 lines

Wang,
I would say that zeroing is done to prevent from seeing some other superblock (besides btrfs) there.

That make sense.

Quoted 4 lines

Alex.

But I still confused by the -A option?

In mkfs, we always write the sb info into BTRFS_SUPER_INFO_OFFSET. From the -A comment, I think btrfs would be places after the -A value. What would happen if we specify a -A value larger than it?

Thanks,
Sheng-Hui