Commit Graph

7471 Commits

Author SHA1 Message Date
Mark Harmstone
0134e755c1 btrfs-progs: mkfs: add --compress option
Add an option --compress to mkfs.btrfs, to allow creating files
using zlib when using --rootdir.

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
2025-01-06 14:19:28 +01:00
Mark Harmstone
0966aa21b3 btrfs-progs: mkfs: refactor add_file_items()
There were two major problems with add_file_items(): it was
writing all files sector-by-sector, making compression impossible, and
it was assuming that pread would never do a short read.

Fix these problems, and create a new helper add_file_item_extent().

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
2025-01-06 14:19:28 +01:00
Qu Wenruo
57512f9027 btrfs-progs: make btrfs_insert_file_extent() accept an on-stack file extent item
Just like insert_reserved_file_extent() from the kernel, we can make
btrfs_insert_file_extent() accept an on-stack file extent item
directly.

This makes btrfs_insert_file_extent() more flex, and it can now handle
the converted file extent where it has an non-zero offset.

And this makes it much easier to expand for future compressed file
extent generation.

Signed-off-by: Qu Wenruo <wqu@suse.com>
2025-01-06 14:19:28 +01:00
Qu Wenruo
9590e5cae9 btrfs-progs: do not call btrfs_record_file_extent() out of btrfs-convert
The function btrfs_record_file_extent() has extra handling that's
specific to convert, like allowing the range to be split by block group
boundary and image file extent boundary.

All of these split can only lead to corruption for non-converted fs.
As the only caller out of btrfs-convert is rootdir, which expects the
file extent item insert to respect the reserved data extent, and never
to be split.

Thankfully this is not going to cause huge problem, as
btrfs_record_file_extent() has extra checks if the data extent overlaps
with any existing one, and if it doesn't the handling will be the same
as the kernel.

But to avoid abuse, change btrfs_record_file_extent() by:

- Rename it to btrfs_convert_file_extent()
  And add extra comments on that it is specific to btrfs-convert.

- Move it to convert/common.[ch]

- Introduce a helper insert_reserved_file_extent() for rootdir.c

Signed-off-by: Qu Wenruo <wqu@suse.com>
2025-01-06 14:19:28 +01:00
David Sterba
85ca0a6d60
Btrfs progs v6.12
Signed-off-by: David Sterba <dsterba@suse.com>
2024-11-29 20:24:16 +01:00
David Sterba
ce552fd050 btrfs-progs: update CHANGES for 6.12
Signed-off-by: David Sterba <dsterba@suse.com>
2024-11-29 20:22:37 +01:00
Dan Čermák
a658055b8e libbtrfsutil: update docstring of btrfs_util_set_default_subvolume()
The docstring was referring to the function itself and not to the
function for which it is the alias
2024-11-29 19:28:15 +01:00
Anand Jain
164145b97e btrfs-progs: docs: fix doc build errors correct hyperlink formatting
Making all in Documentation
    [SPHINX] man
Documentation/Kernel-by-version.rst:: ERROR: Anonymous hyperlink mismatch: 10 references but 0 targets.
See "backrefs" attribute for IDs.
    [PY]     libbtrfsutil

The build is complaining about the missing space after (2) and
<https:...>, as shown in the example below:

  v6.10-rc3 (2)<https://git.kernel.org/linus/07978330e63456a75a6d5c1c5053de24bdc9d16f>__,

The compiler interprets this as a backref attribute. Add a space to make
it render as text.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-11-28 14:40:46 +01:00
Anand Jain
bb44f70bb1 btrfs-progs: docs: fix doc build issue caused by confusion between BTRFS_ and target
Text ending with `_` is treated as an anonymous hyperlink. Use an escape
character `\` to prevent this.

Making all in Documentation
    [SPHINX] man
btrfs-progs/Documentation/dev/On-disk-format.rst:32: ERROR: Unknown target name: "btrfs".

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-11-28 14:40:46 +01:00
Anand Jain
fd3da2e9cc btrfs-progs: docs: fix sphinx build errors in CHANGES
On python3-sphinx 7.2.6. and python3-sphinx_rtd_theme 2.0.0 there are
build errors.

Making all in Documentation
    [SPHINX] man
../CHANGES:26: ERROR: Unexpected indentation.
../CHANGES:29: WARNING: Block quote ends without a blank line; unexpected unindent.
../CHANGES:204: ERROR: Unexpected indentation.
../CHANGES:205: WARNING: Block quote ends without a blank line; unexpected unindent.

Fix them by adjusting the indentation in the CHANGES file. The sublist
should be indented two spaces further than the main list.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-11-28 14:40:46 +01:00
Qu Wenruo
528313dd8d btrfs-progs: improve error handling in btrfs_split_item()
This involves the following error cases:

- Unable to find the original item
  Return -EAGAIN and release the path (which is not done in the original
  code)

- Error from split_leaf()
  Remove the BUG_ON() and handle the error.
  The most common error is ENOSPC.

- Error from kmalloc()
  Just handle the error and return -ENOMEM.

Issue: #312
Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-11-28 14:40:46 +01:00
Dominique Martinet
a1355f7776 btrfs-progs: utils: flush stdout after prompt in ask_user()
When stdio is line buffered printf will not flush anything (on musl?),
leaving the program hanging without displaying any prompt and weird
dialogs such as the following:

  alpine:~# btrfstune -S 0 /dev/mmcblk1p1
  WARNING: this is dangerous, clearing the seeding flag may cause the derived device not to be mountable!
  y
  WARNING: seeding flag is not set on /dev/mmcblk1p1
  We are going to clear the seeding flag, are you sure? [y/N]: alpine:~#

Forcing flush makes the prompt display properly.

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
2024-11-28 14:40:46 +01:00
David Sterba
09b715396d btrfs-progs: docs: add 6.12 kernel development statistics
Update graphs.

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-11-28 14:40:46 +01:00
(@silopolis)
46c1715035 btrfs-progs: docs: checksumming editing 2024-11-28 14:40:46 +01:00
(@silopolis)
8b55d2cf37 btrfs-progs: docs: auto-repair editing 2024-11-28 14:40:46 +01:00
Jérémie Tarot
968b156128 btrfs-progs: docs: subvolume intro editing
* fix repetition
* wording and punctuation in 'Nested subvolumes'
* wording and punctuation in 'system root layouts'
* wording and punctuation in 'Mount options'
* wording in 'Inode numbers'
* wording and punctuation in 'Performance'
2024-11-28 14:40:46 +01:00
Jérémie Tarot
4c62876d02 btrfs-progs: docs: fix double word in intro 2024-11-28 14:40:46 +01:00
Colin Snover
dbebb78051 btrfs-progs: docs: enhance the scrub chapter
- Explain that scrub is device based

- Add extra warning on NOCOW files
  Which implies NODATASUM, and can cause unexpected stale data to be
  returned.

- Explain the limitation of scrub
  As it can only do very basic checksum verification and very basic
  mirror based repair.

Signed-off-by: Colin Snover <csnover@users.noreply.github.com>
[ Add an SoB line and commit message, remove the mention of btrfs-check errors,
  as there is no evidence/example where btrfs-check failed to choose a good mirror. ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-11-28 14:40:46 +01:00
Colin Snover
960b2991f4 btrfs-progs: docs: add warning about balance to replace failing device
Since balance is copying the old good data/metadata into a new chunk
(which can be on the same failed device), it's not a safe way to handle
failed devices.

Signed-off-by: Colin Snover <csnover@users.noreply.github.com>
[ Add an SoB and simple commit message, remove the unnecessary
  explanation, and guide the user to use `btrfs dev replace` ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-11-28 14:40:46 +01:00
Colin Snover
9c532d3c4e btrfs-progs: docs: clarify how btrfs check works with replicas
- btrfs-check does device assembly automatically
  Thus no difference when specifying different devices of the same
  filesystem

- btrfs-check automatically chooses good metadata
  Thus as long as there is any good mirror for metadata, it will not
  report error for that repariable metadata.

Signed-off-by: Colin Snover <csnover@users.noreply.github.com>
[ Add an SoB line, remove the scrub recommendation as btrfs-check is
  supposed to choose the good mirror ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-11-28 14:40:46 +01:00
Colin Snover
763866b746 btrfs-progs: docs: clarify transid verify error recoverability
- Fix the format of the transid mismatch reason and type

- Fix a typo in the reason

- Explain more on the recoverable case
  That both a regular metadata read and read-write scrub can do the
  same trick.

- Add an extra data salvage method using "rescue=all,ro" mount option

Signed-off-by: Colin Snover <csnover@users.noreply.github.com>
[ Add an SoB line ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-11-26 21:05:34 +01:00
Colin Snover
7a9af54345 btrfs-progs: docs: say where to get help
- The IRC channel
- The mailling list
- The btrfs-progs repo for user space bugs

Signed-off-by: Colin Snover <csnover@users.noreply.github.com>
[ Add an SoB line ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-11-26 21:05:34 +01:00
Qu Wenruo
5ae55dc90b btrfs-progs: print-tree: use readable_flag_entry for inode flags
The current print-tree can not handle unsupported inode flags, e.g.
created by Synology's out-of-tree btrfs implementation.

The existing one just checks all the supported flags, and if no flag
hits, it will output "none" no matter if there is any unsupported one.

Fix this by implementing sprint_readable_flag(), and use the same
handling of print_readable_flag().
Although for inode flag, adds one extra handling to output "none" if no
flag hit at all.

Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-11-26 21:05:34 +01:00
Qu Wenruo
07c5f9e636 btrfs-progs: print-tree: cleanup __print_readable_flag()
This includes:

- Remove the "__" prefix
  Now the "__" is no longer recommended, and there is no function taking
  the "print_readable_flag" in the first place.

- Move the supported flags calculation into print_readable_flag()
  Since all callers are doing the same work before calling the function.

Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-11-26 21:05:34 +01:00
Qu Wenruo
d2f554971a btrfs-progs: print-tree: use ARRAY_SIZE() to replace open-coded ones
For compat_ro_flags_num and incompat_flags_num, just use ARRAY_SIZE().

Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-11-26 21:05:34 +01:00
Mark Harmstone
969f403686 btrfs-progs: tests: add image to fsck-tests/065-valid-log-tree where csum already exists
Adds a test that btrfs check doesn't report an error because of a
missing csum entry in the log tree, if that csum is already in the
normal csum tree. See commit 6c7d2a32.

The checksum tree in already-present.img.xz:

checksum tree key (CSUM_TREE ROOT_ITEM 0)
leaf 5390336 items 1 free space 16254 generation 5 owner CSUM_TREE
leaf 5390336 flags 0x1(WRITTEN) backref revision 1
checksum stored ff20c282
checksum calced ff20c282
fs uuid 70d417f0-0173-49ca-bdf1-b789a798974d
chunk uuid b7ec3806-ea09-4f18-a5ef-126a2d79105e
        item 0 key (EXTENT_CSUM EXTENT_CSUM 13631488) itemoff 16279 itemsize 4
                range start 13631488 end 13635584 length 4096

The log tree in already-present.img.xz:

log tree key (TREE_LOG ROOT_ITEM 5)
leaf 5373952 items 3 free space 15981 generation 7 owner TREE_LOG
leaf 5373952 flags 0x1(WRITTEN) backref revision 1
checksum stored 63afa0e5
checksum calced 63afa0e5
fs uuid 70d417f0-0173-49ca-bdf1-b789a798974d
chunk uuid b7ec3806-ea09-4f18-a5ef-126a2d79105e
        item 0 key (257 INODE_ITEM 0) itemoff 16123 itemsize 160
                generation 7 transid 7 size 4096 nbytes 0
                block group 0 mode 100644 links 1 uid 0 gid 0 rdev 0
                sequence 1 flags 0x0(none)
                atime 1721050040.375996658 (2024-07-15 14:27:20)
                ctime 1721050040.375996658 (2024-07-15 14:27:20)
                mtime 1721050040.375996658 (2024-07-15 14:27:20)
                otime 0.2820488960 (1970-01-01 01:00:00)
        item 1 key (257 INODE_REF 256) itemoff 16109 itemsize 14
                index 2 namelen 4 name: file
        item 2 key (257 EXTENT_DATA 0) itemoff 16056 itemsize 53
                generation 7 type 1 (regular)
                extent data disk byte 13631488 nr 4096
                extent data offset 0 nr 4096 ram 4096
                extent compression 0 (none)

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
[ Move the image to 065-valid-log tree ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-11-26 21:05:34 +01:00
Mark Harmstone
0e85411f8f btrfs-progs: tests: add image with compressed extent to fsck-tests/065-valid-log-tree
Adds a test that when checking for missing csums in the log tree, btrfs
check considers the compressed rather than uncompressed size of the
extent. See commit 175cbfc5.

The log tree in compressed.img.xz:

log tree key (TREE_LOG ROOT_ITEM 5)
leaf 5373952 items 4 free space 15952 generation 7 owner TREE_LOG
leaf 5373952 flags 0x1(WRITTEN) backref revision 1
checksum stored 61faf6f2
checksum calced 61faf6f2
fs uuid 70d417f0-0173-49ca-bdf1-b789a798974d
chunk uuid b7ec3806-ea09-4f18-a5ef-126a2d79105e
        item 0 key (257 INODE_ITEM 0) itemoff 16123 itemsize 160
                generation 7 transid 7 size 4096 nbytes 0
                block group 0 mode 100644 links 1 uid 0 gid 0 rdev 0
                sequence 1 flags 0x0(none)
                atime 1721050040.375996658 (2024-07-15 14:27:20)
                ctime 1721050040.375996658 (2024-07-15 14:27:20)
                mtime 1721050040.375996658 (2024-07-15 14:27:20)
                otime 0.2820488960 (1970-01-01 01:00:00)
        item 1 key (257 INODE_REF 256) itemoff 16109 itemsize 14
                index 2 namelen 4 name: file
        item 2 key (257 EXTENT_DATA 0) itemoff 16056 itemsize 53
                generation 7 type 1 (regular)
                extent data disk byte 13631488 nr 4096
                extent data offset 0 nr 8192 ram 8192
                extent compression 1 (zlib)
        item 3 key (EXTENT_CSUM EXTENT_CSUM 13631488) itemoff 16052 itemsize 4
                range start 13631488 end 13635584 length 4096

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
[ Move the image to 065-valid-log tree ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-11-26 21:05:34 +01:00
Mark Harmstone
cc63af8670 btrfs-progs: tests: add image with explicit hole to fsck-tests/065-valid-log-tree
Adds a test that btrfs check doesn't flag a file extent in the log tree as
an error because of no corresponding csum entry, if the file extent is
actually an explicit hole. See commit f6dc0e86.

The log tree in hole.img.xz:

log tree key (TREE_LOG ROOT_ITEM 5)
leaf 5373952 items 3 free space 15981 generation 7 owner TREE_LOG
leaf 5373952 flags 0x1(WRITTEN) backref revision 1
checksum stored 091c2f32
checksum calced 091c2f32
fs uuid 70d417f0-0173-49ca-bdf1-b789a798974d
chunk uuid b7ec3806-ea09-4f18-a5ef-126a2d79105e
        item 0 key (257 INODE_ITEM 0) itemoff 16123 itemsize 160
                generation 7 transid 7 size 4096 nbytes 0
                block group 0 mode 100644 links 1 uid 0 gid 0 rdev 0
                sequence 1 flags 0x0(none)
                atime 1721050040.375996658 (2024-07-15 14:27:20)
                ctime 1721050040.375996658 (2024-07-15 14:27:20)
                mtime 1721050040.375996658 (2024-07-15 14:27:20)
                otime 0.2820488960 (1970-01-01 01:00:00)
        item 1 key (257 INODE_REF 256) itemoff 16109 itemsize 14
                index 2 namelen 4 name: file
        item 2 key (257 EXTENT_DATA 0) itemoff 16056 itemsize 53
                generation 7 type 1 (regular)
                extent data disk byte 0 nr 0
                extent data offset 0 nr 4096 ram 4096
                extent compression 0 (none)

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
[ Move the image to 065-valid-log tree ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-11-26 21:05:34 +01:00
HAN Yuwei
0ccaa82066 btrfs-progs: docs: add DEV_ITEM object item description
Added DEV_ITEM object id to the reserved object id list. It's historical reason
to let both of DEV_ITEM and ROOT_TREE have same object id. Developers should
be aware of it.

Signed-off-by: HAN Yuwei <hrx@bupt.moe>
[ Replace immediate number with key names ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-11-26 21:05:34 +01:00
Qu Wenruo
3ad5a16450 btrfs-progs: docs: fix a typo in Kernel-by-version
This "stil" -> "still" typo is causing the latest CI spellchecks to fail.

Fix that so we can get a good CI run.

Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-11-26 21:05:34 +01:00
Mark Harmstone
b982c4007d btrfs-progs: check: check main csum root if csum not in log tree
Fixes false positive in btrfs check that was causing btrfs/192 to fail.

It looks like there's circumstances in which btrfs_log_changed_extents
can also log unmodified extents, but not their csums. If that happens,
check the main csum root as well before showing an error.

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
2024-11-26 21:05:34 +01:00
Mark Harmstone
357c385f0a btrfs-progs: check: handle compressed extents when checking tree log
Use the correct address and size when looking for the csums for a
compressed extent in the tree log.

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
2024-11-26 21:05:34 +01:00
Mark Harmstone
88dc309aca btrfs-progs: check: explicit holes in log tree don't get csummed
Fix a false positive in btrfs check, where we were returning an error
because an explicit hole in the log tree had no associated csum entry.

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
2024-11-26 21:05:34 +01:00
Mark Harmstone
e8223cd20b btrfs-progs: docs: fix typo and dead link
The slides for the talk "Kernel maintainership: an oral tradition",
linked to in the documentation, seem to have gone from the Linux
Foundation website. Change to the version on bootlin.com.

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
2024-11-26 21:05:34 +01:00
David Sterba
7ec6db8a38 btrfs-progs: docs: add kernel changelogs for 6.9, 6.10 and 6.11
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-11-26 21:05:34 +01:00
David Sterba
4d50579d19 btrfs-progs: docs: update 6.11 contribution graphs
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-11-26 21:05:34 +01:00
Anand Jain
b332feb3b4 btrfs-progs: fix usage warning in common/help.c
On systems with glibc 2.34 and 2.39, the following warning appears when
building the binary:

    [CC]     common/help.o
common/help.c: In function ‘usage’:
common/help.c:315:58: warning: ‘%s’ directive argument is null [-Wformat-overflow=]
  315 |                 fprintf(outf, "No short description for '%s'\n", token);
      |                                                          ^~
common/help.c:312:46: warning: ‘%s’ directive argument is null [-Wformat-overflow=]
  312 |                 fprintf(outf, "No usage for '%s'\n", token);
      |                                              ^~

This happens for usage() which passes NULL pointer as token. Normally
this is fine, as fprintf() will output "(null)" for the NULL pointer,
but it's still not ideal.

Fix the warning by changing the token to "" if it's NULL.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
2024-11-26 21:05:34 +01:00
Mark Harmstone
27099790d9 btrfs-progs: tests: also test --subvol modifiers in mkfs-tests/036-rootdir-subvol
Adds tests to mkfs-tests/036-rootdir-subvol for the modifiers to
mkfs.btrfs --subvol: ro, rw, default, and default-ro.

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
2024-11-26 21:05:34 +01:00
Mark Harmstone
9d1f706703 btrfs-progs: mkfs: avoid dynamic allocation when doing --subvol
Reworks mkfs.btrfs --subvol so that dir and full_path in struct
rootdir_subvol are stored as arrays rather than pointers.

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
2024-11-26 21:05:34 +01:00
Mark Harmstone
8ba72e45c8 btrfs-progs: mkfs: rework format of --subvol option value
Change mkfs.btrfs --subvol so that instead of being of the form --subvol
DIR:FLAGS, it's instead --subvol MODIFIER:DIR, with MODIFIER being ro,
rw, default, or ro-default.

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
2024-11-26 21:05:34 +01:00
Sebastian Hamann
494325bede btrfs-progs: receive: make option quiet work for chroot
With --chroot, the receive subcommand unconditionally sent a non-error
status message to stderr, e.g.:

$ btrfs --quiet receive --chroot /some/path
Chroot to /some/path

Signed-off-by: Sebastian Hamann <code@ares-macrotechnology.com>
2024-11-26 21:05:34 +01:00
Qu Wenruo
074cb6d25b libbtrfsutil: python: reuse existing README.md for long description
Instead of copying the file during custom build commands, just use a
soft link to re-use the existing README.d from libbtrfsutil.

Issue: #310
Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-11-26 21:05:34 +01:00
Qu Wenruo
acda1fdba0 libbtrfsutil: python: use MANIFEST.in for headers
[BUG]
Currently with python3.12, the python binding will always result the
following warning:

    [PY]     libbtrfsutil
/usr/lib/python3.12/site-packages/setuptools/_distutils/extension.py:134: UserWarning: Unknown Extension options: 'headers'
  warnings.warn(msg)

[CAUSE]
In the setup.py which specifies the files to be included into the package,
we use setuptools::Extension to specify the file lists and include paths.

But there is no handling of Extension::headers member, thus resulting the
above warning.

[FIX]
According to the docs of setuptools, MANIFEST.in is the file controlling
what files should be included.
So instead of the non-supported headers, use MANIFEST.in to include the
needed headers.

Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-11-26 21:05:34 +01:00
David Sterba
7736f36274 libbtrfsutil: bump btrfsutil version, add release steps
[ ci skip ]

Issue: #310
Signed-off-by: David Sterba <dsterba@suse.com>
2024-11-26 21:05:33 +01:00
Qu Wenruo
5ff9f6243e btrfs-progs: tests: add hardlink related tests for mkfs --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.

Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-09-17 17:00:03 +02:00
Qu Wenruo
ef11574733 btrfs-progs: mkfs: add hard link support for --rootdir
The 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.

Pull-request: #873
Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-09-17 17:00:03 +02:00
Mark Harmstone
e55ee92017 btrfs-progs: remove unused qgroup functions
Remove functions that after the previous two patches are no longer
referenced.

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
Co-authored-by: Omar Sandoval <osandov@fb.com>
2024-09-17 17:00:03 +02:00
Mark Harmstone
4419306730 btrfs-progs: subvolume snapshot: use libbtrfsutil for snapshot
Call btrfs_util_subvolume_snapshot in cmd_subvolume_snapshot rather than
calling the ioctl directly.

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
Co-authored-by: Omar Sandoval <osandov@fb.com>
2024-09-17 17:00:03 +02:00
Mark Harmstone
3ff4bf3dd8 btrfs-progs: subvolume create: use libbtrfsutil for creation
Call btrfs_util_subvolume_create in create_one_subvolume rather than
calling the ioctl directly.

Pull-request: #878
Signed-off-by: Mark Harmstone <maharmstone@fb.com>
Co-authored-by: Omar Sandoval <osandov@fb.com>
2024-09-17 17:00:03 +02:00
Mark Harmstone
ec8a6b1536 btrfs-progs: mkfs: add ro flag to --subvol
Adds a flag to mkfs.btrfs --subvol to allow subvolumes to be created
readonly.

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
2024-09-17 17:00:03 +02:00