Skip to contentSkip to conversation

Logical to Physical Address Mapping/Translation in Btrfs

DISCUSSION [email protected] 2 participants 2 messages Dec 19, 2023 Btrfs file system

lore
Share & tools
lore
#0 lore raw

Hi,

May I know how the logical address is translated to the physical address in Btrfs?

I have read the official documentation of Btrfs available here
(https://btrfs.readthedocs.io/en/latest/Introduction.html). It is not covering the address translation part in detail.

I have also gone through the Btrfs source code
(https://github.com/torvalds/linux/tree/master/fs/btrfs). I could not figure out the address translation from the code also.

After referring to the following functions, what I could understand is that after getting the logical address of Chunk tree root from the superblock, we need to convert it into the corresponding physical address for parsing into the next level.

int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_devices, char *options)

int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info)

static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf,  struct btrfs_chunk *chunk)

Any hints or pointers to the documentation on this is greatly appreciated.

Thanks in advance
Saranya G
CDAC

------------------------------------------------------------------------------------------------------------
[ C-DAC is on Social-Media too. Kindly follow us at:
Facebook: https://www.facebook.com/CDACINDIA & Twitter: @cdacindia ]

This e-mail is for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies and the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email is strictly prohibited and appropriate legal action will be taken.
------------------------------------------------------------------------------------------------------------

#1 lore raw
Quoted 22 lines · On Tue, Dec 19, 2023 at 9:18 AM <[email protected]> wrote:

Hi,

May I know how the logical address is translated to the physical address in Btrfs?

I have read the official documentation of Btrfs available here
(https://btrfs.readthedocs.io/en/latest/Introduction.html). It is not covering the address translation part in detail.

I have also gone through the Btrfs source code
(https://github.com/torvalds/linux/tree/master/fs/btrfs). I could not figure out the address translation from the code also.

After referring to the following functions, what I could understand is that after getting the logical address of Chunk tree root from the superblock, we need to convert it into the corresponding physical address for parsing into the next level.

int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_devices, char *options)

Quoted 7 lines

int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info)

static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf, struct btrfs_chunk *chunk)

Any hints or pointers to the documentation on this is greatly appreciated.

Current btrfs-progs has

btrfs inspect-internal map-swapfile

command that returns a physical offset on the device. You could look there for the implementation.