Commit Graph

758 Commits

Author SHA1 Message Date
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
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
Mark Harmstone
fa70df7e78 btrfs-progs: mkfs: add default flag to --subvol
Change --subvol that it can accept flags, and add a "default" flag that
allows you to mark a subvolume as the default.

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
2024-09-17 17:00:03 +02:00
Mark Harmstone
e844ffcaad btrfs-progs: mkfs: add new option --subvol
Add a new option --subvol, which tells mkfs.btrfs to create the
specified directories as subvolumes when used with --rootdir.

Given a populated directory dir, the command

  $ mkfs.btrfs --rootdir dir --subvol usr --subvol home --subvol home/username img

will create subvolumes 'usr' and 'home' within the toplevel subvolume,
and subvolume 'username' within the 'home' subvolume. It will fail if
any of the directories do not yet exist.

Pull-request: #868
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Mark Harmstone <maharmstone@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-09-17 17:00:03 +02:00
Omar Sandoval
a4d2d1b498 btrfs-progs: subvolume delete: add new option for recursive deletion
Add new option --recursive 'btrfs subvol delete', causing it to pass the
BTRFS_UTIL_DELETE_SUBVOLUME_RECURSIVE flag through to libbtrfsutil.

This can work in two modes, depending on the user:

- regular user - this will skip subvolumes that are not accessible
- root (CAP_SYS_ADMIN) - no limitations

Pull-request: #861
Signed-off-by: Mark Harmstone <maharmstone@meta.com>
Co-authored-by: Omar Sandoval <osandov@osandov.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
[ Add details to man page, fix indent in the doc. ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-09-17 17:00:03 +02:00
David Sterba
5b7f6a4a5b btrfs-progs: docs: add path-utils.h API docs
[ ci skip ]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-09-17 16:47:42 +02:00
David Sterba
4ca6444fba btrfs-progs: docs: inline files vs tail packing
Explain the difference, in case somebody want's to use it as a source to
correct that on Wikipedia.

[ ci skip ]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-09-17 16:47:42 +02:00
David Sterba
158a25af0d btrfs-progs: fi resize: warn if new size is < 256M
The lower kernel limit is 256M otherwise it's considered an invalid
parameter.

Issue: #875
Signed-off-by: David Sterba <dsterba@suse.com>
2024-09-17 16:19:03 +02:00
David Sterba
aca8a3a05b btrfs-progs: docs: add heading for 6.11
Still TBD.

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-09-17 16:19:03 +02:00
David Sterba
ec236d38b9 btrfs-progs: docs: update feature status
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-09-17 16:19:03 +02:00
David Sterba
e1e070642c btrfs-progs: docs: add 6.11 kernel development statistics
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-09-17 16:19:03 +02:00
Mark Harmstone
08c1e627a8 btrfs-progs: install btrfs-ioctl manual page
btrfs-ioctl.rst was laid out like it should be a man page, including
having a section number, but it wasn't getting installed because there
was not enough content.

Pull-request: #892
Signed-off-by: Mark Harmstone <maharmstone@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-09-17 14:33:22 +02:00
Han Yuwei
17b9e3f2af btrfs-progs: docs: clarify number represention in on-disk-format tables
Added 0x prefix to HEX numbers and transform some tables to new format.

Pull-request: #881
Signed-off-by: Yuwei Han <hrx@bupt.moe>
[ Fix RST grammar errors ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-09-17 14:33:22 +02:00
rhn
07b8c74bc8 btrfs-progs: docs: clarify btrfs-send checksum
The way the CRC32C checksum used for btrfs-send differs from the way
it's used elsewhere in btrfs. Without making the distinction, it's easy
to make the flawed assumption that CRC32C always refers to the same, and
end up with code that produces the wrong checksums.

This small note should guide the reader to the right function.

The best notes on the protocol I found are here:
https://archive.kernel.org/oldwiki/btrfs.wiki.kernel.org/index.php/Design_notes_on_Send/Receive.html

The crc32c might be used in two meanings and this could be confusing
when implementing the send stream protocol.

Rust code describing the algorithm for the crc crate that worked for me:

pub const CRC_32_BTRFS_SEND: crc::Algorithm<u32> = crc::Algorithm {
	width: 32, poly: 0x1edc6f41, init: 0, refin: true, refout: true,
	xorout: 0, check: 0xe3069283, residue: 0xb798b438
};

(it's a slight variation on the one used in ISCSI)

Note: Documentation/dev/dev-send-stream.rst briefly mentions that

Pull-request: #794
Author: rhn <gihu.rhn@porcupinefactory.org>
[ rephrase changelog and copy text from pull request and add link to
  developer documentation of the send stream ]
Signed-off-by: David Sterba <dsterba@suse.com>
2024-08-14 23:59:47 +02:00
David Sterba
720b1f3ab4 btrfs-progs: docs: fix new typos
Last minute documentation changes before release that did not go through
CI.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-08-14 23:58:14 +02:00
David Sterba
cbc15a9161 btrfs-progs: docs: update sysfs descriptions
[ci skip]

Issue: #374
Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 20:05:11 +02:00
David Sterba
e6966e6770 btrfs-progs: docs: move Interoperability to the first section
The page is not complete but mentions at least NFS, cgroups and
fsverity.

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 20:05:11 +02:00
David Sterba
ef1f99fde6 btrfs-progs: docs: include sysfs to Administration
The sysfs file description is hard to find. Also link to btrfs(5) from
administration.

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 20:05:11 +02:00
David Sterba
bf2eb30e0c btrfs-progs: docs: list supported fs-verity ioctls
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 20:05:11 +02:00
David Sterba
6b99f901df btrfs-progs: docs: add new encoded rw ioctls to the list
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 20:05:11 +02:00
David Sterba
4cab3f8c97 btrfs-progs: docs: add example for nested subvolumes
Make it more visible what the result of snapshotted subvolume is. This
partially duplicates the other section.

[ci skip]

Issue: #644
Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 20:05:11 +02:00
David Sterba
fca2fe3316 btrfs-progs: docs: add zone reclaim
[ci skip]

Issue: #768
Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 20:05:11 +02:00
David Sterba
42dad5ea65 btrfs-progs: docs: update source repositories, workflows
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 20:05:11 +02:00
David Sterba
39470a52b5 btrfs-progs: docs: clarify swapfile an multi-device filesystem
It is possible to create swapfile on a multi-device filesystem but it's
not reliable. The check that verifies that in kernel:

10698                 } else if (device != map->stripes[0].dev) {
10699                         btrfs_warn(fs_info, "swapfile must be on one device");
10700                         ret = -EINVAL;
10701                         goto out;
10702                 }

This does not count devices but rather the actual placement of the
swapfile extents, so multi-device filesystem with single profile can
create it as long as there's enough space and the allocator decides to
place it properly.

[ci skip]

Pull-request: #839
Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 20:05:11 +02:00
Qu Wenruo
c58266504e btrfs-progs: docs: add warning for -s option of btrfs-image
The filename sanitization is not recommended as it introduces mismatches
between DIR_ITEM and INODE_REF.

Even hash collision mode (double "-s" option) is not ensured to always
find a hash collision, and when fails to find one, a mismatch happens.

And when a mismatch happens, the kernel will not resolve the path
correctly since kernel uses the hash from DIR_ITEM to lookup the child
inode.

So add a warning into the "-s" option of btrfs-image.

Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-07-30 19:56:41 +02:00
Yaroslav Halchenko
16a7cbca91 btrfs-progs: run codespell throughout fixing typos automagically
Spell checking can now run in automated mode.

=== Do not change lines below ===
{
 "chain": [],
 "cmd": "codespell -w",
 "exit": 0,
 "extra_inputs": [],
 "inputs": [],
 "outputs": [],
 "pwd": "."
}
^^^ Do not change lines above ^^^

Author: Yaroslav Halchenko <debian@onerussian.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 19:56:08 +02:00
Yaroslav Halchenko
5b3bb3973a btrfs-progs: do interactive fixing of some ambigous typos
Typos fixed manually using the following:

=== Do not change lines below ===
{
 "chain": [],
 "cmd": "codespell -w -i 3 -C 2",
 "exit": 0,
 "extra_inputs": [],
 "inputs": [],
 "outputs": [],
 "pwd": "."
}
^^^ Do not change lines above ^^^

Author: Yaroslav Halchenko <debian@onerussian.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 19:56:08 +02:00
David Sterba
4a1acc205a btrfs-progs: list-chunks: update help and documentation
Sync help text with current implementation (sorting, no usage nor empty
options).

Issue: #559
Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 19:53:33 +02:00
David Sterba
0eb8a65844 btrfs-progs: tree-stats: add options for size output units
Add the usual long options for all byte size related values in the
output.

Issue: #268
Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 19:53:33 +02:00
David Sterba
ef73193623 btrfs-progs: dump-tree: escape special characters in paths or xattrs
Filenames can contain a newline (or other funny characters), this makes
the dump-tree output confusing, same for xattr names or values that can
binary data.  Encode the special characters in the C-style ('\e' ->
"\e", or \NNN if there's no single letter representation). This is based
on the isprint() as it's espected either on a terminal or in a dump
file.

Issue: #350
Issue: #407
Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 19:53:33 +02:00
David Sterba
5308564ca7 btrfs-progs: docs: document github PR workflow
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 19:53:33 +02:00
David Sterba
023b20421c btrfs-progs: docs: add headings for 6.9 and 6.10 changes
Add headings for now, contents to be added later.

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 19:53:33 +02:00
David Sterba
f68dc323da btrfs-progs: docs: update 6.10 contribution graphs
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 19:53:33 +02:00
David Sterba
a1945b28fb btrfs-progs: docs: add 6.10 kernel development statistics
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 19:53:32 +02:00
David Sterba
fb9c0feec8 btrfs-progs: ci: build html manual page previews if source changed
Similar to the manual page on terminal preview, also do the html output
that will be on the RTD page. Due to the way how it's displayed in the
CI action summary the CSS is missing and there are some visual
artifacts, e.g. in the option lists or special characters.

Issue: #824
Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 19:53:32 +02:00
Chung-Chiang Cheng
ef8e050d64 btrfs-progs: inspect tree-stats: support to show a specified tree
tree-stats currently displays only some global trees and fs-tree 5. Add
support to show the stats of a specified tree.

Issue: #268
Signed-off-by: Chung-Chiang Cheng <cccheng@synology.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 19:53:32 +02:00
David Sterba
2eadd15e6b btrfs-progs: ci: build manual page previews if source changed
Extend CI workflow of devel branch to generate manual page preview as it
would be rendered in a terminal. The output is in the workflow summary
page, for each file changed (if any).

Issue: #824
Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 19:53:32 +02:00
Qu Wenruo
ed1f7ac5ed btrfs-progs: docs: update the rescue mount options
Enhance the rescue mount option group by:

- Add a simple explanation on each rescue option

- Add the new 'ignoremetacsums' option

Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-06-24 19:20:18 +02:00
David Sterba
824888191c btrfs-progs: docs: clarify receive --dump encoding
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-24 19:19:04 +02:00
David Sterba
5644dc5d18 btrfs-progs: docs: update 6.9 contribution graphs
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-03 23:01:11 +02:00
David Sterba
5dad958662 btrfs-progs: docs: document more fstests requirements
Newly added parted, for btrfs/318. Keep the list sorted.

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-03 22:25:08 +02:00
David Sterba
c147aaa59b btrfs-progs: clarify unlinked and deleted terminology for subvolumes
Recent patches updated stale qgroup handling, using 'unlinked' and
'dropped' where we otherwise use 'deleted' and 'cleaned'.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-05-17 18:13:18 +02:00
Qu Wenruo
7f3ab46400 btrfs-progs: qgroup: add more special statuses for qgroups
Currently `btrfs qgroup show` command shows any 0 level qgroup without a
root backref as `<stale>`, which is not correct.

There are several more cases:

- Under deletion
  The subvolume is not yet full dropped, but unlinked.
  In that case we would not have a root backref item, but the qgroup is
  not stale.

- Squota space holder
  This is for squota mode, that a fully dropped subvolume still have
  extents accounting on the already-gone subvolume.
  In this case it's not stale either, and future accounting relies on
  it.

This patch would add above special cases, and add an extra `SPECIAL
PATHS` section to explain all the cases, including `<stale>`.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-05-17 18:01:49 +02:00
David Sterba
24d8119b98 btrfs-progs: docs: update feature status
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-05-13 18:29:04 +02:00
David Sterba
c7d02a77cc btrfs-progs: docs: add 6.9 kernel development statistics
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-05-13 18:22:24 +02:00
David Sterba
3b899063bd btrfs-progs: check: remove --clear-ino-cache option
The inode_cache functionality is long gone and the 'rescue' group
provides the clearning functionality, no point keeping it in check.
Move the --clear-space-cache option to the deprecaeted section so it can
be removed soon.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-05-02 14:02:50 +02:00
Qu Wenruo
99447fb708 Revert "btrfs-progs: subvol delete: add options to delete the qgroup"
This reverts commit 9da773aa46.

There are several problems related to the --delete-qgroup option:

- Currently kernel doesn't allow to delete non-empty qgroups

- A qgroup can only be empty after fully dropped and a transaction is
  committed
  The tool doesn't take either factor into consideration

- Things like drop_subtree_threshold or other operations can mark qgroup
  inconsistent and skip accounting
  This can mean the target qgroup will never be empty until next rescan

On the other hand, even we do it the proper way, it would hugely delay
the command (wait until the subvolume to be cleaned).

Furthermore, even if the waiting is handled properly,
drop_subtree_threshold can still prevent us deleting the qgroup (qgroup
numbers are inconsistent, and accounting is skipped completely).

So the qgroup cleanup needs kernel to make it work properly.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-04-30 21:49:15 +02:00
Qu Wenruo
40588d4aa9 btrfs-progs: docs: fix build due to phony contents.rst
[BUG]
Since commit 8049446bb0 ("btrfs-progs: docs: placeholder for
contents.rst file on older sphinx version"), on systems with much newer
sphinx-build, "make" would not work for Documentation directory:

  $ make clean-all && ./autogen.sh && ./configure --prefix=/usr/ && make -j12
  $ ls -alh Documentation/_build
  ls: cannot access 'Documentation/_build': No such file or directory

The sphinx-build has a much newer version:

  $ sphinx-build --version
  sphinx-build 7.2.6

[CAUSE]
On systems which don't need the workaround, the phony target of
contents.rst seems to cause a dependency loop:

  GNU Make 4.4.1
  Built for x86_64-pc-linux-gnu
  Copyright (C) 1988-2023 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
  This is free software: you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.
  Reading makefiles...
  Reading makefile 'Makefile'...
  Updating makefiles....
   Considering target file 'Makefile'.
    Looking for an implicit rule for 'Makefile'.
     Trying pattern rule '%:' with stem 'Makefile'.
    Found implicit rule '%:' for 'Makefile'.
   Finished prerequisites of target file 'Makefile'.
   No need to remake target 'Makefile'.
  Updating goal targets....
  Considering target file 'contents.rst'.
   File 'contents.rst' does not exist.
  Finished prerequisites of target file 'contents.rst'.
  Must remake target 'contents.rst'.
  Makefile:35: update target 'contents.rst' due to: target is .PHONY
  if [ "$(sphinx-build --version | cut -d' ' -f2)" \< "1.7.7" ]; then \
  	touch contents.rst; \
  fi
  Putting child 0x64ee81960130 (contents.rst) PID 66833 on the chain.
  Live child 0x64ee81960130 (contents.rst) PID 66833
  Reaping winning child 0x64ee81960130 PID 66833
  Removing child 0x64ee81960130 PID 66833 from chain.
  Successfully remade target file 'contents.rst'.

All the default make doing is just try to generate contents.rst, but
since we have much newer version, we won't generate the file at all.

[FIX]
Instead of a phony target, just move the contents.rst generation into
man page target so that we won't cause loop target on contents.rst.

Fixes: 8049446bb0 ("btrfs-progs: docs: placeholder for contents.rst file on older sphinx version")
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-04-30 21:49:15 +02:00
David Sterba
152c708944 btrfs-progs: docs: update feature status
Add some missing entries. Changes to supported levels:

- increase to 6.8 from 6.7 where applicable, there were fixes to squota
  and temp-fsid

- raid-stripe-tree declares support from 6.7, however this is still
  behind CONFIG_BTRFS_DEBUG option in kernel, there are some bugs
  and the known lack of RAID56 support

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-04-30 21:49:15 +02:00
Christoph Anton Mitterer
5a956bb3b1 btrfs-progs: docs: how to get the length of the portion used by btrfs on a device
A user who wants to shrink a btrfs filesystem within some other logical
device (like a partition) will likely want to adapt the size of the
underlying device, too.

This commit adds documentation that describes how the length of the
portion that btrfs uses of some device can be found out.

Thanks go out to Roman Mamedov <rm@romanrm.net> for hinting `btrfs
filesystem show` as alternative command.

Note: the granularity is one sectorsize and the input values are
silently rounded down to avoid bugs from converted filesystems that
would not adhere to the native btrfs constraints.

[ci skip]

Pull-request: #775
Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-04-30 21:34:46 +02:00