Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Documentation/btrfs-property.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ get [-t <type>] <object> [<name>]
device as object. For a mounted filesystem, specify a mount point.
compression
compression algorithm set for an inode, possible values: *lzo*, *zlib*, *zstd*.
To disable compression use "" (empty string), *no* or *none*.
To disable compression use *no* or *none*. Empty value resets the
property and sets a default value.
.. note::
This has changed in version 5.18 of btrfs-progs and
requires kernel 5.14 or newer to work.

list [-t <type>] <object>
Lists available properties with their descriptions for the given object.
Expand Down
23 changes: 15 additions & 8 deletions Documentation/ch-seeding-device.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ UUID that is normally attached to a device is automatically changed to a random
UUID on each mount.

Once the seeding device is mounted, it needs the writable device. After adding
it, something like **remount -o remount,rw /path** makes the filesystem at
*/path* ready for use. The simplest use case is to throw away all changes by
unmounting the filesystem when convenient.

Alternatively, deleting the seeding device from the filesystem can turn it into
it, unmounting and mounting with **umount /path; mount <wr-dev> /path** or
remounting read-write with **remount -o remount,rw** makes the filesystem at
*/path* ready for use. N.B., there is a known bug with using remount to make
the mount writeable: remount will leave the filesystem in a state where it is
unable to clean deleted snapshots, so it will leak space until it is unmounted
and mounted properly.

Furthermore, deleting the seeding device from the filesystem can turn it into
a normal filesystem, provided that the writable device can also contain all the
data from the seeding device.

Expand All @@ -42,8 +45,9 @@ Example how to create and use one seeding device:
# umount /mnt/mnt1
# btrfstune -S 1 /dev/sda
# mount /dev/sda /mnt/mnt1
# btrfs device add /dev/sdb /mnt
# mount -o remount,rw /mnt/mnt1
# btrfs device add /dev/sdb /mnt/mnt1
# umount /mnt/mnt1
# mount /dev/sdb /mnt/mnt1
# ... /mnt/mnt1 is now writable

Now */mnt/mnt1* can be used normally. The device */dev/sda* can be mounted
Expand All @@ -53,7 +57,8 @@ again with a another writable device:

# mount /dev/sda /mnt/mnt2
# btrfs device add /dev/sdc /mnt/mnt2
# mount -o remount,rw /mnt/mnt2
# umount /mnt/mnt2
# mount /dev/sdc /mnt/mnt2
... /mnt/mnt2 is now writable

The writable device (*/dev/sdb*) can be decoupled from the seeding device and
Expand All @@ -74,3 +79,5 @@ A few things to note:
* block group profiles *single* and *dup* support the use cases above
* the label is copied from the seeding device and can be changed by **btrfs filesystem label**
* each new mount of the seeding device gets a new random UUID
* **umount /path; mount wr-dev /path** can be replaced with **mount -o remount,rw /path**
but it has bugs in kernels older than <fix-kernel-version>
41 changes: 11 additions & 30 deletions btrfs-corrupt-block.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,53 +40,34 @@ static int debug_corrupt_block(struct extent_buffer *eb,
struct btrfs_root *root, u64 bytenr, u32 blocksize, u64 copy)
{
int ret;
u64 length;
struct btrfs_multi_bio *multi = NULL;
struct btrfs_device *device;
int num_copies;
int mirror_num = 1;

length = blocksize;
while (1) {
ret = btrfs_map_block(root->fs_info, READ, eb->start, &length,
&multi, mirror_num, NULL);
if (ret) {
error("cannot map block %llu length %llu mirror %d: %d",
(unsigned long long)eb->start,
(unsigned long long)length,
mirror_num, ret);
return ret;
}
device = multi->stripes[0].dev;
eb->fd = device->fd;
device->total_ios++;
eb->dev_bytenr = multi->stripes[0].physical;

fprintf(stdout,
"mirror %d logical %llu physical %llu device %s\n",
mirror_num, (unsigned long long)bytenr,
(unsigned long long)eb->dev_bytenr, device->name);
free(multi);

if (!copy || mirror_num == copy) {
ret = read_extent_from_disk(eb, 0, eb->len);
u64 read_len = eb->len;

ret = read_data_from_disk(eb->fs_info, eb->data,
eb->start, &read_len,
mirror_num);
if (read_len < eb->len)
ret = -EIO;
if (ret < 0) {
errno = -ret;
error("cannot read eb bytenr %llu: %m",
(unsigned long long)eb->dev_bytenr);
(unsigned long long)eb->start);
return ret;
}
printf("corrupting %llu copy %d\n", eb->start,
mirror_num);
memset(eb->data, 0, eb->len);
ret = write_extent_to_disk(eb);
ret = write_and_map_eb(eb->fs_info, eb);
if (ret < 0) {
errno = -ret;
error("cannot write eb bytenr %llu: %m",
(unsigned long long)eb->dev_bytenr);
(unsigned long long)eb->start);
return ret;
}
fsync(eb->fd);
}

num_copies = btrfs_num_copies(root->fs_info, eb->start,
Expand Down Expand Up @@ -162,7 +143,7 @@ static void corrupt_keys(struct btrfs_trans_handle *trans,
u16 csum_type = fs_info->csum_type;

csum_tree_block_size(eb, csum_size, 0, csum_type);
write_extent_to_disk(eb);
write_and_map_eb(eb->fs_info, eb);
}
}

Expand Down
5 changes: 3 additions & 2 deletions btrfs-map-logical.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ static int write_extent_content(struct btrfs_fs_info *fs_info, int out_fd,

while (cur_offset < length) {
cur_len = min_t(u64, length - cur_offset, BUFFER_SIZE);
ret = read_extent_data(fs_info, buffer,
logical + cur_offset, &cur_len, mirror);
ret = read_data_from_disk(fs_info, buffer,
logical + cur_offset, &cur_len,
mirror);
if (ret < 0) {
errno = -ret;
fprintf(stderr,
Expand Down
3 changes: 2 additions & 1 deletion btrfstune.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ static int populate_csum(struct btrfs_trans_handle *trans,

while (offset < len) {
sectorsize = fs_info->sectorsize;
ret = read_extent_data(fs_info, buf, start + offset, &sectorsize, 0);
ret = read_data_from_disk(fs_info, buf, start + offset,
&sectorsize, 0);
if (ret)
break;
ret = btrfs_csum_file_block(trans, start + len, start + offset,
Expand Down
2 changes: 1 addition & 1 deletion check/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5791,7 +5791,7 @@ static int check_extent_csums(struct btrfs_root *root, u64 bytenr,
for (mirror = 1; mirror <= num_copies; mirror++) {
read_len = num_bytes - offset;
/* read as much space once a time */
ret = read_extent_data(gfs_info, (char *)data + offset,
ret = read_data_from_disk(gfs_info, (char *)data + offset,
bytenr + offset, &read_len, mirror);
if (ret)
goto out;
Expand Down
4 changes: 2 additions & 2 deletions check/mode-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1203,8 +1203,8 @@ static int populate_csum(struct btrfs_trans_handle *trans,

while (offset < len) {
sectorsize = gfs_info->sectorsize;
ret = read_extent_data(gfs_info, buf, start + offset,
&sectorsize, 0);
ret = read_data_from_disk(gfs_info, buf, start + offset,
&sectorsize, 0);
if (ret)
break;
ret = btrfs_csum_file_block(trans, start + len, start + offset,
Expand Down
2 changes: 0 additions & 2 deletions cmds/property.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ static int prop_compression(enum prop_object_type type,
xattr_name[XATTR_BTRFS_PREFIX_LEN + strlen(name)] = '\0';

if (value) {
if (strcmp(value, "no") == 0 || strcmp(value, "none") == 0)
value = "";
sret = fsetxattr(fd, xattr_name, value, strlen(value), 0);
} else {
sret = fgetxattr(fd, xattr_name, NULL, 0);
Expand Down
4 changes: 2 additions & 2 deletions cmds/restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ static int copy_one_extent(struct btrfs_root *root, int fd,
cur = bytenr;
while (cur < bytenr + size_left) {
length = bytenr + size_left - cur;
ret = read_extent_data(root->fs_info, inbuf + cur - bytenr, cur,
&length, mirror_num);
ret = read_data_from_disk(root->fs_info, inbuf + cur - bytenr, cur,
&length, mirror_num);
if (ret < 0) {
mirror_num++;
if (mirror_num > num_copies) {
Expand Down
2 changes: 1 addition & 1 deletion image/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ static int read_data_extent(struct metadump_struct *md,
for (cur_mirror = 1; cur_mirror <= num_copies; cur_mirror++) {
while (bytes_left) {
read_len = bytes_left;
ret = read_extent_data(fs_info,
ret = read_data_from_disk(fs_info,
(char *)(async->buffer + offset),
logical, &read_len, cur_mirror);
if (ret < 0)
Expand Down
5 changes: 2 additions & 3 deletions kernel-shared/ctree.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,9 @@ static void generic_err(const struct extent_buffer *buf, int slot,
{
va_list args;

fprintf(stderr, "corrupt %s: root=%lld block=%llu physical=%llu slot=%d, ",
fprintf(stderr, "corrupt %s: root=%lld block=%llu slot=%d, ",
btrfs_header_level(buf) == 0 ? "leaf": "node",
btrfs_header_owner(buf), btrfs_header_bytenr(buf),
buf->dev_bytenr, slot);
btrfs_header_owner(buf), btrfs_header_bytenr(buf), slot);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
Expand Down
Loading