Commit Graph

2604 Commits

Author SHA1 Message Date
Yauhen Kharuzhy eba0d8925c btrfs-progs: Check if the FSID was seen by comparing full UUID
is_seen_fsid() uses simple hash to check if FS was seen before at
walking on FS list in 'filesystem show' command: hash key is first byte
of the UUID. This function doesn't check full UUID then, so, if there
are two FS with same first byte in UUIDs exist, only one will be shown:

root@test:~# btrfs fi show
Label: 'System'  uuid: 688cb918-7bac-4c8e-9b11-8d047eb14cf4
        Total devices 2 FS bytes used 1.76GiB
        devid    1 size 3.46TiB used 4.01GiB path /dev/sda2
        devid    2 size 6.91TiB used 4.01GiB path /dev/sdb2

Global spare

root@test:~# grep btrfs /proc/mounts
/dev/sda2 / btrfs rw,relatime,space_cache,subvolid=256,subvol=/root 0 0
/dev/sdc /media/688cb918-7bac-4c8e-9b11-8d047eb14cf4 btrfs rw,relatime,space_cache,subvolid=5,subvol=/ 0 0

root@test:~# btrfs fi show --all-devices
Label: 'System'  uuid: 688cb918-7bac-4c8e-9b11-8d047eb14cf4
        Total devices 2 FS bytes used 1.76GiB
        devid    1 size 3.46TiB used 4.03GiB path /dev/sda2
        devid    2 size 6.91TiB used 4.01GiB path /dev/sdb2

Label: 'test'  uuid: 683b1a80-ca7f-4c4d-b87b-7155401a4d18
        Total devices 7 FS bytes used 2.06MiB
        devid    1 size 7.28TiB used 1.57GiB path /dev/sdc
        devid    2 size 7.28TiB used 1.57GiB path /dev/sdd
        devid    3 size 7.28TiB used 1.57GiB path /dev/sde
        devid    4 size 7.28TiB used 1.57GiB path /dev/sdf
        devid    5 size 7.28TiB used 1.57GiB path /dev/sdg
        devid    6 size 7.28TiB used 1.57GiB path /dev/sdh
        devid    7 size 7.28TiB used 1.57GiB path /dev/sdi

To resolve this collision, search for full FSID in the list of seen
filesystems.

Signed-off-by: Yauhen Kharuzhy <yauhen.kharuzhy@zavadatar.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 14:42:04 +02:00
David Sterba e8ac13098d btrfs-progs: convert: fix typo in original image subvolume name
Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 14:41:58 +02:00
Patrik Lundquist a963abc3d3 btrfs-progs: device stats: Print devid instead of null
Print e.g. "[devid:4].write_io_errs   6" instead of
"[(null)].write_io_errs   6" when device is missing.

Signed-off-by: Patrik Lundquist <patrik.lundquist@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 14:41:54 +02:00
Anand Jain 972cfbe32f btrfs-progs: fix re-declared get_device_info()
The other get_device_info() is in the same file, 4 lines above.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 14:41:47 +02:00
David Sterba 5f8cd780b9 btrfs-progs: check: use add_extent_rec_nolookup after lookups
The lookup was duplicated, use the helper that does not do it.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 14:41:35 +02:00
David Sterba e1a5ecc206 btrfs-progs: check: refactor add_extent_rec, separate lookup
Separate the part of add_extent_rec that comes after the lookup does not
succeed, there are callers interested in just this.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 14:41:27 +02:00
David Sterba e83012d57e btrfs-progs: check: cleanup, move structure definitions to the beginning
Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 14:41:07 +02:00
David Sterba 3be6e3e7c9 btrfs-progs: deprecate and stop using btrfs_level_size
Size of a b-tree node is always nodesize, regardless of the level.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 14:40:23 +02:00
David Sterba 2a796d84af btrfs-progs: replace leafsize with nodesize
Nodesize is used in kernel, the values are always equal. We have to keep
leafsize in headers, similarly the tree setting functions still take and
set leafsize, but it's effectively a no-op.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 14:40:18 +02:00
David Sterba b005ca0249 btrfs-progs: fi sync: make it silent by default
Report only errors returned by the ioctl.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 14:40:09 +02:00
Qu Wenruo 12234d0202 btrfs-progs: fsck: Fix a false metadata extent warning
At least 2 user from mail list reported btrfsck reported false alert of
"bad metadata [XXXX,YYYY) crossing stripe boundary".

While the reported number are all inside the same 64K boundary.
After some check, all the false alert have the same bytenr feature,
which can be divided by stripe size (64K).

The result seems to be initial 'max_size' can be 0, causing 'start' +
'max_size' - 1, to cross the stripe boundary.

Fix it by always update extent_record->cross_stripe when the
extent_record is updated, to avoid temporary false alert to be reported.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 14:40:05 +02:00
Alexander Fougner 1a9df1c68b btrfs-progs: update docs and completion for tree-stats
Signed-off-by: Alexander Fougner <fougner89@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 14:39:57 +02:00
Alexander Fougner d4abd0bfb0 btrfs-progs: copy btrfs-calc-size to inspect-internal tree-stats
Signed-off-by: Alexander Fougner <fougner89@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 14:39:53 +02:00
David Sterba d75f0c12d2 btrfs-progs: tests: add support for command line coverage tests
Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 14:39:46 +02:00
David Sterba 350563bf79
Btrfs progs v4.5.1
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-31 17:10:28 +02:00
Julio Montes e2f9dca8bc btrfs-progs: fix unknown type name 'u64' in gccgo
Signed-off-by: Julio Montes <imc.coder@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-31 16:10:06 +02:00
David Sterba a5948c56bf btrfs-progs: docs: update mkfs page for dup on multidev fs
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:56:32 +02:00
David Sterba 39992e60a3 btrfs-progs: tests: update 001-basic-profiles, dup on multidev fs
Testcase for "btrfs-progs: mkfs: fix an error when using DUP on multidev
fs"

Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:26:49 +02:00
Satoru Takeuchi bf928c8e17 btrfs-progs: mkfs: fix an error when using DUP on multidev fs
To accept DUP on multidev fs, in addition to the following
commit, we need to mark DUP as an allowed data/metadata
profile.

commit 42f1279bf8e9 ("btrfs-progs: mkfs: allow DUP on multidev fs, only warn")

* actual result

  =============================================
  # ./mkfs.btrfs -f -m DUP -d DUP /dev/sdb1 /dev/sdb2
  btrfs-progs v4.5-24-ga35b7e6
  See http://btrfs.wiki.kernel.org for more information.

  WARNING: DUP is not recommended on filesystem with multiple devices
  ERROR: unable to create FS with metadata profile DUP (have 2 devices but 1 devices are required)
  =============================================

* expected result

  =============================================
  # ./mkfs.btrfs -f -m dup -d dup /dev/sdb1 /dev/sdb2
  WARNING: DUP is not recommended on filesystem with multiple devices
  btrfs-progs v4.5-25-g1a10a3c
  See http://btrfs.wiki.kernel.org for more information.

  Label:              (null)
  UUID:               010d72ff-c87c-4516-8916-5e635719d110
  Node size:          16384
  Sector size:        4096
  Filesystem size:    28.87GiB
  Block group profiles:
    Data:             DUP               1.01GiB
    Metadata:         DUP               1.01GiB
    System:           DUP              12.00MiB
  SSD detected:       no
  Incompat features:  extref, skinny-metadata
  Number of devices:  2
  Devices:
     ID        SIZE  PATH
      1   953.00MiB  /dev/sdb1
      2    27.94GiB  /dev/sdb2

  ==================================================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:26:46 +02:00
David Sterba 5595263cb6 btrfs-progs: fix fd leak in get_subvol_info
A typo, introduced in "btrfs-progs: create get_subvol_info()".

Resolves-coverity-id: 1357106
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:26:43 +02:00
David Sterba 91b70d4cf1 btrfs-progs: use safe copy for label buffer everywhere
There's a mix of opencoded strncpy + null termination, strncpy, memcppy
without termination etc. Unify them and use the helper.

Resolves-coverity-id: 1357105
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:26:38 +02:00
David Sterba 41f6ae4820 btrfs-progs: rename __strncpy__null to __strncpy_null
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:26:33 +02:00
David Sterba c7f72072bd btrfs-progs: mkfs: allow DUP on multidev fs, only warn
The DUP profile can work on multiple filesystems, the limitation is
rather artificial. Let the user make the decision and print a warning.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:26:27 +02:00
David Sterba 7b80b76386 btrfs-progs: make error message from add_clone_source more generic
Do not hardcode the error message.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:26:21 +02:00
Tsutomu Itoh a260446077 btrfs-progs: send: fix handling of multiple snapshots
We cannot send multiple snapshots at once.

[before fix]
# btrfs send ./snap[12] > snap12.data
At subvol ./snap1
At subvol ./snap2
ERROR: parent determination failed for 0
#

[after fix]
# btrfs send ./snap[12] > snap12.data
At subvol ./snap1
At subvol ./snap2
#

Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:26:13 +02:00
David Sterba d7477bcd0b btrfs-progs: tests: add misc 014-filesystem-label
Test various label lengths on a mounted filesystem.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:26:09 +02:00
David Sterba 10d308d5ea btrfs-progs: tests: introduce mustfail helper
Invalid syntax, expected failure on corrupted data etc. Failure is
success.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:25:59 +02:00
David Sterba 338e5832e7 btrfs-progs: fix build of standalone utilities after clean
$ make clean
$ make btrfs-debug-tree

will fail because the dependency from $(btrfs_debug_tree_objects) is
missing. The variable standalone_deps magically collects all the deps
and will build them in advance. The simple fix to use the existing
substitution based on $@ does not work for pattern rules, as Noah found
out.

Reported-by: Noah Massey <noah.massey@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:25:53 +02:00
David Sterba 113d1ad49c btrfs-progs: cleanup block group helpers types
Use const char and remove stray prototypes.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:25:47 +02:00
David Sterba c1bb7a2d60 btrfs-progs: utils: make more arguments const
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:25:38 +02:00
Anand Jain 37288902fc btrfs-progs: rename get_subvol_name() to subvol_strip_mountpoint()
Signed-off-by: Anand Jain <anand.jain@oracle.com>
[ renamed from subvol_minus_mnt to subvol_strip_mountpoint ]
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:25:33 +02:00
Anand Jain e494f5790f btrfs-progs: create get_subvol_info()
get_subvol_info() is useful as we are adding more features around
subvolume. This function was inline with the function
cmd_subvol_show().

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:25:28 +02:00
Anand Jain 8cec21a7ed btrfs-progs: move get_subvol_name() to utils.c
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:25:23 +02:00
Anand Jain 0f9a5cf70c btrfs-progs: remove duplicate function __is_subvol()
The function test_issubvolume() provides the same check, and
has better logic.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:25:18 +02:00
Anand Jain a5dbd2064e btrfs-progs: move test_issubvolume() to utils.c
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:25:13 +02:00
Anand Jain 906dfb9e38 btrfs-progs: rearrange subvolume functions together
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:25:09 +02:00
Petros Angelatos ee78a83b5e btrfs-progs: utils: make sure set_label_mounted uses correct length buffers
When `btrfs filesystem label /foo bar` command is invoked, it will pass
the buffer allocated in the argv array directly to set_label_mounted()
and then to the BTRFS_IOC_SET_FSLABEL ioctl.

However, the kernel code handling the ioctl will always try to copy
BTRFS_LABEL_SIZE bytes[1] from the userland pointer. Under certain
conditions and when the label is small enough, the command will fail
with:

    [root@localhost /]# btrfs filesystem label /mnt f
    ERROR: unable to set label Bad address

Fix this by making sure we pass a BTRFS_LABEL_SIZE sized buffer to the
ioctl containing the desired label.

[1] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/fs/btrfs/ioctl.c?id=refs/tags/v4.5#n5231

Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:23:21 +02:00
David Sterba 90104b2618 btrfs-progs: fragments: fix build
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:23:10 +02:00
Austin S. Hemmelgarn 1c36022fe7 btrfs-progs: fix fi du so it works in more cases
Currently, btrfs fi du uses open_file_or_dir(), which tries to open
it's argument with O_RDWR.  Because of POSIX semantics, this fails for
non-root users when the file is read-only or is an executable that
is being run currently, or for all users (including root) when the
filesystem is read-only.  This results in a somewhat confusing 'Unknown
error -1' message when trying to check such files.  Switch to using
open_file_or_dir3() with O_RDONLY passed in the flags, as this avoids
the limitations listed above, and we have no need to write to the files
anyway (and thus shouldn't be opening them writable).

Signed-off-by: Austin S. Hemmelgarn <ahferroin7@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:22:53 +02:00
Noah Massey 74a5d7478a btrfs-progs: build: fix static standalone utilities
commit b5e7979 "btrfs-progs: build: extend per-binary objects" allows
the standalone utilities to link against object files shared with the
main binary. However, the btrfs-*.static targets need to be adjusted
to build against the static versions of the common files.

Signed-off-by: Noah Massey <noah.massey@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:22:47 +02:00
David Sterba 03142f99bb
Btrfs progs v4.5
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-20 23:59:05 +01:00
David Sterba 92e922bafe btrfs-progs: tests: enumerate RWX in convert tests
Generating all valid combinations takes too much time.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-18 17:11:25 +01:00
Lakshmipathi.G 971d8e7476 btrfs-progs: tests: populate fs with small dataset for convert tests
Signed-off-by: Lakshmipathi.G <Lakshmipathi.G@giis.co.in>
[ minor tweaks ]
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-18 17:03:58 +01:00
David Sterba 274b1d9121 btrfs-progs: switch to common message helpers in open_ctree_fs_info
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-18 16:38:14 +01:00
David Sterba c921544bba btrfs-progs: handle stat errors in open_ctree_fs_info
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-18 16:38:14 +01:00
Austin S. Hemmelgarn 3519f83574 btrfs-progs: add stat check in open_ctree_fs_info
Currently, open_ctree_fs_info will open whatever path you pass it and try
to interpret it as a BTRFS filesystem.  While this is not nessecarily
dangerous (except possibly if done on a character device), it does
result in some rather cryptic and non-sensical error messages when
trying to run certain commands in ways they weren't intended to be run.
Add a check using stat(2) to verify that the path we've been passed is
in fact a regular file or a block device, or a symlink pointing to a
regular file or block device.

This causes the following commands to provide a helpful error message
when run on a FIFO, directory, character device, or socket:
    * btrfs check
    * btrfs restore
    * btrfs-image
    * btrfs-find-root
    * btrfs inspect-internal dump-tree

stat(2) is used instead of lstat(2), as stat(2) follows symlinks just
like open(2) does, which means we check the same inode that open(2)
opens, and thus don't need special handling for symlinks.

Signed-off-by: Austin S. Hemmelgarn <ahferroin7@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-18 16:38:14 +01:00
Alexander Fougner f7fb93d558 btrfs-progs: fi du: fix incorrect column order
Signed-off-by: Alexander Fougner <fougner89@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-18 14:29:26 +01:00
Satoru Takeuchi 9fa1f12caa btrfs-progs: qgroup assign: handle --no-rescan option
* actual result

   ==================================================
   # btrfs qgroup assign --no-rescan 0/260 1/261 /btrfs
   btrfs qgroup assign: unrecognized option '--no-rescan'
   usage: btrfs qgroup assign [options] <src> <dst> <path>

       Assign SRC as the child qgroup of DST

       --rescan       schedule qutoa rescan if needed
       --no-rescan

   ==================================================

* expected result

   ==================================================
   # ./btrfs qgroup assign --no-rescan 0/260 1/261 /btrfs
   #
   ==================================================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-18 14:19:29 +01:00
Satoru Takeuchi 208ba29007 btrfs-progs: qgroup assign: can't handle options
"qgroup assign" is considered as working without any options
from the following commit.

commit 176aeca9a148 ("btrfs-progs: add getopt stubs where needed")

However, we can pass options to this command.

* actual result

   ==================================================
   # ./btrfs qgroup assign --rescan 0/260 1/261 /btrfs
   btrfs qgroup assign: unrecognized option '--rescan'
   usage: btrfs qgroup assign [options] <src> <dst> <path>

       Assign SRC as the child qgroup of DST

       --rescan       schedule qutoa rescan if needed
       --no-rescan

   ==================================================

* expected result

   ==================================================
   # ./btrfs qgroup assign --rescan 0/260 1/261 /btrfs
   #
   ==================================================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-18 14:17:11 +01:00
Satoru Takeuchi f4f4fb2061 btrfs-progs: inspect subvolid-resolve: fix argument parsing
"inspect-internal subvolid-resolve" doesn't work from the following commit.

commit 176aeca9a148 ("btrfs-progs: add getopt stubs where needed")

It's because 1st argument, subvolid, is also used for the pathname of
filesystem. 2nd argument should be used for this purpose instead.

* actual result

   ==================================================
   # ./btrfs inspect-internal subvolid-resolve 260 /btrfs
   ERROR: cannot access '260': No such file or directory
   ==================================================

* expected result

   ==================================================
   # btrfs inspect-internal subvolid-resolve 260 /btrfs
   snap
   ==================================================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-18 14:14:03 +01:00