Commit Graph

313 Commits (fad531e5233343e34f517e46050d860b6225dae0)

Author SHA1 Message Date
David Sterba e5362f5feb btrfs-progs: move lookup_path_rootid to library utils
The refactoring in commit 1c85c3de5a has
broken use of libbtrfs that does not exhibit during build but at the run
time.

Fixes: 1c85c3de5a
Bugzilla: https://bugs.gentoo.org/show_bug.cgi?id=600078
Reported-by: Mike Gilbert <floppymaster@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-24 13:06:36 +01:00
Qu Wenruo d6ab2fdca4 btrfs-progs: utils: Fix NULL pointer derefernces in string_is_numerical
In get_running_kernel_version() function, we directly pass return
pointer from strtok_r() to string_is_numerical().

Return pointer from strok_r() can be NULL, but string_is_numerical()
can't handle it and will cause NULL pointer derefernces.

Fix it by check if it's a NULL pointer first.

Resolves-Coverity-CID: 1374097
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-23 10:48:13 +01:00
David Sterba ebcd9f7eef btrfs-progs: mkfs: add names of matching sysfs feature names
The mkfs parameters do not match file names exported through sysfs.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-11 16:25:18 +01:00
David Sterba bcccfb52d9 btrfs-progs: mkfs: enhance feature table
Add string and numeric version for later use so we don't have to convert
all the time.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-11 16:25:18 +01:00
David Sterba 9ab0db84ec btrfs-progs: mkfs: extend mkfs features with compat, safe and default versions
Enhance the mkfs_features list with the minimum kernel versions that
will allow for turning on compatible and/or safe options.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-11 16:25:18 +01:00
David Sterba 279609aedf btrfs-progs: mkfs: add temporary variable for fs features
A minor cleanup before other changes.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-11 16:25:17 +01:00
David Sterba c29fea4344 btrfs-progs: use correct type for device id iteration in get_fs_info
Coverity reports (CID 1374096) that there's return value overflow of
ret from get_device_info, but this most likely cannot happen. There's
another minor issue where we use int to iterate over devids.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:35 +01:00
David Sterba 3934ba255d btrfs-progs: fix search tree v2 ioctl detection
The result of the test applies per-filesystem, so we can't simply cache
it. The function hasn't been used yet.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:35 +01:00
David Sterba c6a0cb7d6d btrfs-progs: utils: remove useless check in make_btrfs
A leftover when fs_uuid was dynamically allocated, the condition was
always true, no functional change.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:32 +01:00
David Sterba 5c4d53450b btrfs-progs: mkfs: store creation time of the toplevel subvolume
For unkonwn reasons, the creation time of the toplevel subvolume inode
item hasn't been set.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:30 +01:00
David Sterba d4aa2bc07e btrfs-progs: subvol show: print more details about toplevel subvolume
The toplevel subvolume is special and the other listing code leaves it
out so we have to add several special cases to handle it. There's no
backreference so the path is built artificially. New helper
btrfs_get_toplevel_subvol is a reduced version of btrfs_get_subvol.

There's some information usually missing for the toplevel subvolume, eg.
the uuid or creation info. This has to be fixed on the mkfs side, the
other subvolumes are created by kernel.

Example:
/mnt
        Name:                   <FS_TREE>
        UUID:                   -
        Parent UUID:            -
        Received UUID:          -
        Creation time:          -
        Subvolume ID:           5
        Generation:             233
        Gen at creation:        0
        Parent ID:              0
        Top level ID:           0
        Flags:                  -
        Snapshot(s):
                                subv1

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:29 +01:00
David Sterba 1c85c3de5a btrfs-progs: use existing rootid resolving helper in btrfs_list_get_path_rootid
The utils helper is not verbose in case of an error, for now the helper
used for subvolume listing will print the error message but not
duplicate the ioctl anymore.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:28 +01:00
David Sterba 49cb98e5d6 btrfs-progs: rename lookup_ino_rootid
It does not resolve the inode number but path where fd has been opened.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:28 +01:00
Karel Zak dcc3df7e6d btrfs-progs: rename btrfs_scan_lblkid() to btrfs_scan_devices()
It seems like bad idea to use a library name (lblkid) within generic
function name. The currently used scanning library is implementation
detail and this detail should be hidden for rest of the code.

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2016-10-25 14:28:36 +02:00
David Sterba 508000138c btrfs-progs: mkfs: detect version of running kernel
Use the uname syscall and parse the string.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-25 14:28:36 +02:00
David Sterba 85d608f7ec btrfs-progs: constify string arguments where appropriate
Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-03 15:07:23 +02:00
Domagoj Tršan ff9ee51677 btrfs-progs: change btrfs_csum_final result param type to u8
Signed-off-by: Domagoj Tršan <domagoj.trsan@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-03 11:35:50 +02:00
David Sterba 1ed3426d3f btrfs-progs: use standard allocation functions in non-kenrel code
Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-03 11:33:15 +02:00
David Sterba b80a4641e5 btrfs-progs: improve error handling in btrfs_add_to_fsid
Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-03 11:33:15 +02:00
David Sterba 1424a9b4d9 btrfs-progs: remove redundant check in btrfs_add_to_fsid
The callers do the sanity checks.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-03 11:33:15 +02:00
David Sterba 030fa48b55 btrfs-progs: mkfs: handle block ordering errors in make_btrfs
Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-21 14:12:38 +02:00
David Sterba b318553f33 btrfs-progs: mkfs: check for sane sectorsize earlier
Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-21 14:12:38 +02:00
David Sterba 976f6adfb5 btrfs-progs: more verbose error handling in creation helpers
Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-21 14:12:38 +02:00
David Sterba 2d7c6dc931 btrfs-progs: switch BUG_ON to ASSERT in reserve_free_space
That's not a real error condition, catch bad function usge.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-21 14:12:38 +02:00
David Sterba 7aaa1a92f6 btrfs-progs: mkfs: use preallocated buffers for config uuids
No need for dynamic allocation, the buffers are small, remove the
now-useless error conditions.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-21 13:44:24 +02:00
Qu Wenruo 53c4e289c2 btrfs-progs: mkfs: Warn user for minimal RAID5/6 devices setup
For RAID5, 2 devices setup is just RAID1 with more overhead.
For RAID6, 3 devices setup is RAID1 with 3 copies, not what most user
want.

So warn user at mkfs time for such case, and add explain in man pages.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-21 11:47:31 +02:00
David Sterba 2ff04db5f4 btrfs-progs: two staged filesystem creation
The filesystem existence on a device is manifested by the signature,
during the mkfs process we write it first and then create other
structures. Such filesystem is not valid and should not be registered
during device scan nor listed among devices from blkid.

This patch will introduce two staged creation. In the first phase, the
signature is wrong, but recognized as a partially created filesystem (by
open or scan helpers). Once we successfully create and write everything,
we fixup the signature. At this point automated scanning should find
a valid filesystem on all devices.

We can also rely on the partially created filesystem to do better error
handling during creation. We can just bail out and do not need to clean
up.

The partial signature is '!BHRfS_M', can be shown by

  btrfs inspect-internal dump-super -F image

Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:37:31 +02:00
David Sterba 3c350dec06 btrfs-progs: introduce signature for a partially set up filesystem
Currently the superblock is created first, with a valid signaure, but
the rest of the filesystem is missing. When the creation process is
interrupted, the filesystem still might be considered as valid.

To prevent that, create the filesytem with an invalid signature that
would be still recognized during the mkfs process, and finalize at the
end.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:36:58 +02:00
David Sterba 059832da5f btrfs-progs: make superblock reading/scanning api more generic
We'll add more modes that affect scanning.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-24 14:36:58 +02:00
David Sterba 5407ee85fc btrfs-progs: refactor and extend btrfs_prepare_device arguments
The message about discard is printed unconditionally and does not
conform to the --quite option eg. in mkfs. Consolidate the operation
flags into one argument and add support for verbosity.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-28 14:08:30 +02:00
Wang Shilong 419334be80 btrfs-progs: du: fix to skip not btrfs dir/file
'btrfs file du' is a very useful tool to watch my system
file usage information with snapshot aware.

when trying to run following commands:
[root@localhost btrfs-progs]# btrfs file du /
     Total   Exclusive  Set shared  Filename
ERROR: Failed to lookup root id - Inappropriate ioctl for device
ERROR: cannot check space of '/': Unknown error -1

and My Filesystem looks like this:
[root@localhost btrfs-progs]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
devtmpfs       devtmpfs   16G     0   16G   0% /dev
tmpfs          tmpfs      16G  368K   16G   1% /dev/shm
tmpfs          tmpfs      16G  1.4M   16G   1% /run
tmpfs          tmpfs      16G     0   16G   0% /sys/fs/cgroup
/dev/sda3      btrfs      60G   19G   40G  33% /
tmpfs          tmpfs      16G  332K   16G   1% /tmp
/dev/sdc       btrfs     2.8T  166G  1.7T   9% /data
/dev/sda2      xfs       2.0G  452M  1.6G  23% /boot
/dev/sda1      vfat      1.9G   11M  1.9G   1% /boot/efi
tmpfs          tmpfs     3.2G   24K  3.2G   1% /run/user/1000

So I installed Btrfs as my root partition, but boot partition
can be other fs.

We can Let btrfs tool aware of this is not a btrfs file or
directory and skip those files, so that someone like me
could just run 'btrfs file du /' to scan all btrfs filesystems.

After patch, it will look like:
   Total   Exclusive  Set shared  Filename
     0.00B       0.00B           -  //root/.bash_logout
     0.00B       0.00B           -  //root/.bash_profile
     0.00B       0.00B           -  //root/.bashrc
     0.00B       0.00B           -  //root/.cshrc
     0.00B       0.00B           -  //root/.tcshrc

This works for me to analysis system usage and analysis
performaces.

Signed-off-by: Wang Shilong <wangshilong1991@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-13 18:44:52 +02:00
David Sterba 18c6850fe1 btrfs-progs: new helper for option parsing, more permissive for "no options"
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-17 17:01:25 +02:00
Qu Wenruo fca2f8a8fd btrfs-progs: Introduce function to setup temporary extent tree
Introduce new function, setup_temporary_extent_tree() to build a
temporary extent tree for make_btrfs_v2().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-07 18:15:19 +02:00
Qu Wenruo 1b8851ec40 btrfs-progs: Introduce function to initialize csum tree
Introduce new function, setup_temp_csum_tree(), to setup temporary
csum tree for make_btrfs_v2().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-07 18:15:19 +02:00
Qu Wenruo b2da12034a btrfs-progs: Introduce function to initialize fs tree
Introudce new function, setup_temp_fs_tree(), to setup temporary fs tree
for make_btrfs_v2().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-07 18:15:19 +02:00
Qu Wenruo f0a81c88d0 btrfs-progs: Introduce function to initialize device tree
Introduce new function, setup_temp_device_tree(), to setup temporary
device tree for make_btrfs_v2().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-07 18:15:19 +02:00
Qu Wenruo 56f26c533e btrfs-progs: Introduce function to setup temporary chunk root
Introduce new function, setup_temp_chunk_root(), to initialize temporary
chunk root for make_btrfs_v2().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-07 18:15:19 +02:00
Qu Wenruo df20ed3e5e btrfs-progs: Introduce function to setup temporary tree root
Introduce new function, setup_temp_tree_root(), to initialize temporary
tree root for make_btrfs_v2().

The new function will setup tree root at metadata chunk and ensure data
won't be written into metadata chunk.

Also, new make_btrfs_v2() will have a much better code structure than
old make_btrfs().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-07 18:15:19 +02:00
Qu Wenruo e86e5441a0 btrfs-progs: Introduce function to setup temporary superblock
Introduce a new function, setup_temp_super(), to setup temporary super
for make_btrfs_v2().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[ use __strncpy_null in setup_temp_super ]
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-07 18:15:19 +02:00
Qu Wenruo 330ca2d6df btrfs-progs: utils: Introduce new function for convert
Introduce new function make_convert_btrfs() for convert.

This new function will have the following features:
1) Allocate temporary sb/metadata/system chunk, avoiding old used data
2) More structured functions
   No more over 1000 lines function, better function split and code
   reuse

This will finally replace current make_btrfs(), but now only used for
convert.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-07 18:15:19 +02:00
Qu Wenruo 17239a9c89 btrfs-progs: utils: Introduce new pseudo random API
David has reported some quite chaos usage of pseudo random numbers.
Like using static srand seed, or even calling rand() without setting
seed correctly.

The new pseudo random API will initialize the random seed on its first
calling and use uniformly distributed pseudo random number generator as
backend.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[ renamed variables and functions, added prefixes ]
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 16:43:25 +02:00
David Sterba c74214c29b btrfs-progs: switch to common message helpers in utils.c
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +02:00
Nicholas D Steeves bd2cc320af btrfs-progs: typo review of strings and comments
Signed-off-by: Nicholas D Steeves <nsteeves@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-06-01 14:56:56 +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 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