btrfs-progs: mkfs/rootdir: add hard link support
Subsystems (2)
v2 cover btrfs-progs: mkfs/rootdir: add hard link support
[Changelog]
v2:
- Fix several grammar errors and change "can not" to more formal "cannot"
- Initialize the temporary hardlink_entry structure as const
- Double quote the $nr_hardlink used in test case
With the recently reworked --rootdir support, although it solves several hard link related problems, it splits the hard links into new inodes.
And on each split, it shows a warning on each file with hardlinks.
Although the split behavior doesn't cause any data corruption, it can still be pretty noisy for rootfs creation, as there are a lot of distros storing timezone files as hardlinks.
This patchset adds back the hard link detection and creation, with enhanced handling to co-operate with --subvol option.
The details can be found in the first patch, with the new corner case introduced by --subvol option.
The second patch enhances the existing --rootdir and --subvol test case with extra corner cases like hard links, and hard links split by subvolume boundary.
Qu Wenruo (2):
btrfs-progs: mkfs/rootdir: add hard link support
btrfs-progs: mkfs-tests: add hardlink related tests for --subvol
Documentation/mkfs.btrfs.rst | 13 ++ mkfs/rootdir.c | 199 +++++++++++++++++--- tests/mkfs-tests/036-rootdir-subvol/test.sh | 78 ++++++-- 3 files changed, 247 insertions(+), 43 deletions(-)
--
2.46.0
PATCH v2 2/2 btrfs-progs: mkfs-tests: add hardlink related tests for --subvol
This introduces two new cases:
- 3 hardlinks without any subvolume
This should results 3 hard links inside the btrfs.
- 3 hardlinks, but a subvolume will split 2 of them
Then the 2 inside the same subvolume should still report 2 nlinks, but the lone one inside the new subvolume can only report 1 nlink.
--- mkfs/rootdir.c | 8 +-- tests/mkfs-tests/036-rootdir-subvol/test.sh | 78 +++++++++++++++++---- 2 files changed, 68 insertions(+), 18 deletions(-)
mkfs/rootdir.c +3 -5
@@ -721,7 +721,7 @@ static int ftw_add_inode(const char *full_path, const struct stat *st, parent =rootdir_path_last (¤t_path); root = parent->root; -/* For non-directory inode, check if there is already any hard link. */ +/* Check if there is already a hard link record for this. */ if (have_hard_links) {struct hardlink_entry *found;
@@ -767,6 +767,7 @@ static int ftw_add_inode(const char *full_path, const struct stat *st,error ("failed to insert inode item %llu for '%s': %m" , ino, full_path);return ret; } + ret = btrfs_add_link(g_trans, root, ino, parent->ino, full_path + ftwbuf->base, strlen(full_path) - ftwbuf->base,
@@ -778,10 +779,7 @@ static int ftw_add_inode(const char *full_path, const struct stat *st,return ret; } -/* -* Found a possible hard link, add it into the hard link rb tree for -* future detection. -*/ +/* Record this new hard link. */ if (have_hard_links) { ret =add_hard_link (root, ino, st);if (ret <0 ) {
tests/mkfs-tests/036-rootdir-subvol/test.sh +65 -13
88 lines not on this page · raw message
Signature · 1 line
2.46.0
PATCH v2 1/2 btrfs-progs: mkfs/rootdir: add hard link support
In reply to Qu WenruoThe new hard link detection and creation support is done by maintaining an rb tree with the following members:
- st_ino, st_dev
This is to record the stat() report from the host fs. With this two, we can detect if it's really a hard link (st_dev determines one filesystem/subvolume, and st_ino determines the inode number inside the fs).
- root
This is btrfs root pointer. This a special requirement for the recent introduced "--subvol" option.
As we can have the following corner case:
rootdir/
|- foobar_hardlink1 |- foobar_hardlink2 |- subv/ <- To be a subvolume inside btrfs
|- foobar_hardlink3
In above case, on the host fs, subv/ directory is just a regular directory, but in the new btrfs it will be a subvolume.
In that case, foobar_hardlink3 cannot be created as a hard link, but a new inode.
- st_nlink and found_nlink
Records the original reported number of links, and the nlinks we created inside btrfs.
This is recorded in case we created all hard links and can remove the entry early.
- btrfs_ino
This is the inode number inside btrfs.
And since we can handle hard links safely, remove all the related warnings, and add a new note for --subvol option, warning about the case where we need to split hard links due to subvolume boundary.
--- Documentation/mkfs.btrfs.rst | 13 +++ mkfs/rootdir.c | 203 +++++++++++++++++++++++++++++------ 2 files changed, 185 insertions(+), 31 deletions(-)
Documentation/mkfs.btrfs.rst +13 -0
@@ -160,6 +160,19 @@ OPTIONS directory. The option *--rootdir* must also be specified, and *subdir* must be an existing subdirectory within it. This option can be specified multiple times. + If there are hard links inside *rootdir* and *subdir* will split the + subvolumes, like the following case:: + + rootdir/ + |- hardlink1 + |- hardlink2 + |- subdir/ <- will be a subvolume + |- hardlink3 + + In that case we cannot create `hardlink3` as hardlinks of + `hardlink1` and `hardlink2` because hardlink3 will be inside a new + subvolume. + --shrink Shrink the filesystem to its minimal size, only works with *--rootdir* option.
mkfs/rootdir.c +172 -31
268 lines not on this page · raw message
Signature · 1 line
2.46.0