Commit Graph

57 Commits (250a58f34d57588de8f0b2f118cb5cd152744158)

Author SHA1 Message Date
David Sterba 330709ee13 btrfs-progs: add command group info strings
They're printed in the 'btrfs' command group summary.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-09 14:26:33 +02:00
Anand Jain fda6638093 btrfs-progs: use the correct variable
It's res instead of ret, wrong error message could be prointed in case
of error.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:07 +02:00
David Sterba c8927d5116 btrfs-progs: cleanup, rename *disk_usage* files to usage
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-04-22 18:21:48 +02:00
Anand Jain 32ca2fa502 btrfs-progs: improve troubleshooting avoid duplicate error strings
my troubleshooting experience says have unique error string per module.

In the below eg, its one additional step to know error line,

cat -n cmds-device.c | egrep "error removing the device"
   185	"ERROR: error removing the device '%s' - %s\n",
   190	"ERROR: error removing the device '%s' - %s\n",

which is completely avoidable.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
[merged the two messages into one]
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-04-14 15:19:04 +02:00
David Sterba 4074ae5f2b btrfs-progs: cleanup option index argument from getopt_long
We're not using it anywhere. The best practice is to add enums with
values > 255 for the long options, option index counting is error prone.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-04-08 17:33:55 +02:00
David Sterba 34c28896e8 btrfs-progs: unify getopt table terminators
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-01-21 18:56:40 +01:00
David Sterba 58a3952461 btrfs-progs: add --human-readable option where applicable
Add an alias to -h to 'filesystem usage', 'filesystem df' and
'device usage' commands, same as the traditional 'df'.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-01-21 18:56:28 +01:00
David Sterba a5b66a81bf btrfs-progs: use predefined getopt values for unit suffixes
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-01-21 18:32:06 +01:00
David Sterba 2b7cdab425 btrfs-progs: make getopt tables static const
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-01-19 13:44:49 +01:00
David Sterba 182f41909f btrfs-progs: unify unit mode parameters and variables
Use unsigned type and a common name everywhere.

Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-18 15:24:45 +01:00
David Sterba abef6fd343 btrfs-progs: dev usage, add switches to set output units
Same set of options as 'fi df': binary and decimal bases, human readable
options etc.

Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-18 15:24:45 +01:00
David Sterba 85a0566d4b btrfs-progs: clean up return codes and paths
Use the common patterns with one return statement at the end, pass down error

Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-04 16:48:11 +01:00
David Sterba 4ed59c256a btrfs-progs: replace df_pretty_sizes with pretty_size_mode
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-04 16:48:11 +01:00
David Sterba 0c67867530 btrfs-progs: cleanup filesystem/device usage code
The main point of this is to load the device and chunk infos at one
place and pass down to the printers. The EPERM is handled separately, in
case kernel does not give us all the information about chunks or
devices, but we want to warn and print at least something.

For non-root users, 'filesystem usage' prints only the overall stats and
warns about RAID5/6.

The sole cleanup changes affect mostly the modified code and the related
functions, should be reasonably small.

Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-04 16:48:11 +01:00
David Sterba da28664bf7 btrfs-progs: compare unallocated space against the correct value
The device may not be fully occupied by the filesystem, the value of
Unallocated should not be calculated against the device size but the
size provided by DEV_INFO.

Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-04 16:48:11 +01:00
David Sterba c7b5293d8d btrfs-progs: Print more info about device sizes
The entire device size may not be available to the filesystem, eg. if
it's modified via resize. Print this information if it can be obtained
from the DEV_INFO ioctl.

Print the device ID on the same line as the device name and move size to
the next line.

Sample:
/dev/sda7, ID: 3
   Device size:            10.00GiB
   FS occupied:             5.00GiB
   Data,RAID10:           512.00MiB
   Metadata,RAID10:       512.00MiB
   System,RAID10:           4.00MiB
   Unallocated:             9.00GiB

Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-04 16:48:11 +01:00
David Sterba f4e73c060d btrfs-progs: move device usage to cmds-device, more cleanups
Move the command definitions where they belong, keep common 'usage'
functions in cmds-fi-disk_usage.c and add exports.

Rename structures containing 'disk' to 'device'.

Fix whitespace in the modified code.

Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-04 16:48:10 +01:00
Goffredo Baroncelli 330903d4ee btrfs-progs: Add btrfs device disk-usage command
Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-04 16:48:09 +01:00
Gui Hecheng a1c3bcf1c2 btrfs-progs: use canonical name for device in btrfs fi show when mounted
When using lvm volumes to check fstests: btrfs/006, it fails like:
     Label: 'TestLabel.006'  uuid: <UUID>
     	Total devices <EXACTNUM> FS bytes used <SIZE>
     	devid <DEVID> size <SIZE> used <SIZE> path SCRATCH_DEV
    +	devid <DEVID> size <SIZE> used <SIZE> path /dev/dm-4
    +	devid <DEVID> size <SIZE> used <SIZE> path /dev/dm-5
    +	devid <DEVID> size <SIZE> used <SIZE> path /dev/dm-6

The /dev/dm-* points to lvm volumes, use @canonicalize_path() to convert them
and we will make it through. Of course we should do the same thing for dev stat.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-14 11:02:33 +01:00
Anand Jain 2f55fd7019 btrfs-progs: optimize btrfs_scan_lblkid() for multiple calls
btrfs_scan_lblikd() is called by most the device related command functions.
And btrfs_scan_lblkid() is most expensive function and it becomes more expensive
as number of devices in the system increase. Further some threads call this
function more than once for absolutely no extra benefit and the real waste of
resources. Below list of threads and number of times btrfs_scan_lblkid()
is called in that thread.

  btrfs-find-root            1
  btrfs rescue super-recover 2
  btrfs-debug-tree           1
  btrfs-image -r             2
  btrfs check                2
  btrfs restore              2
  calc-size                  NC
  btrfs-corrupt-block        NC
  btrfs-image                NC
  btrfs-map-logical          1
  btrfs-select-super         NC
  btrfstune                  2
  btrfs-zero-log             NC
  tester                     NC
  quick-test.c               NC
  btrfs-convert              0
  mkfs                       #number of devices to be mkfs
  btrfs label set unmounted  2
  btrfs get label unmounted  2

This patch will:
  move out calling register_one_device with in btrfs_scan_lblkid()
  and so function setting the BTRFS_UPDATE_KERNEL to yes will
  call btrfs_register_all_devices() separately.

  introduce a global variable scan_done, which is set when scan is
  done succssfully per thread. So that following calls to this function
  will just return success.

  Further if any function needs to force scan after scan_done is set,
  then it can be done when there is such a requirement, but as of now there
  isn't any such requirement.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-03 19:17:11 +01:00
Anand Jain 9662864435 btrfs-progs: code optimize cmd_scan_dev() use btrfs_register_one_device()
cmd_scan_dev() has it own code to register device (calling ioctl
BTRFS_IOC_SCAN_DEV), apparently it could use btrfs_register_one_device().

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-03 18:35:30 +01:00
Anand Jain 5444864e56 btrfs-progs: remove BTRFS_SCAN_PROC scan method
The libblkid scan method which was introduced later, will also
scan devices under /proc/partitions. So we don't have to do
the explicit scan of the same.

Remove the scan method BTRFS_SCAN_PROC.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-10-10 10:38:34 +02:00
Eric Sandeen 4e85e48188 btrfs-progs: scan /proc/partitions not all of /dev with "-d"
We can scan for btrfs devices in a few ways.  By default
libblkid is used for "device scan" and "filesystem show";
with the -m option only mounted filesystems are scanned,
and with -d we physically read every system device.

But there's no reason for the complexity of a descent through
/dev; /proc/partitions has every device known to the kernel, so
just use that when -d is specified.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-10-10 09:32:11 +02:00
Holger Hoffstätte 80d8122896 Btrfs-progs: fix typos
Fix (at least one user-visible) typos: it's its, not it's.

Signed-off-by: Holger Hoffstätte <holger.hoffstaette@googlemail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-09-02 17:05:32 +02:00
Jeff Mahoney b276e4bc50 btrfs-progs: canonicalize pathnames for device commands
mount(8) will canonicalize pathnames before passing them to the kernel.
Links to e.g. /dev/sda will be resolved to /dev/sda. Links to /dev/dm-#
will be resolved using the name of the device mapper table to
/dev/mapper/<name>.

Btrfs will use whatever name the user passes to it, regardless of whether
it is canonical or not. That means that if a 'btrfs device ready' is
issued on any device node pointing to the original device, it will adopt
the new name instead of the name that was used during mount.

Mounting using /dev/sdb2 will result in df:
/dev/sdb2      209715200 39328 207577088   1% /mnt

lrwxrwxrwx 1 root root 4 Jun  4 13:36 /dev/whatever-i-like -> sdb2
/dev/whatever-i-like 209715200 39328 207577088   1% /mnt

Likewise, mounting with /dev/mapper/whatever and using /dev/dm-0 with a
btrfs device command results in df showing /dev/dm-0. This can happen with
multipath devices with friendly names enabled and doing something like
'partprobe' which (at least with our version) ends up issuing a 'change'
uevent on the sysfs node. That *always* uses the dm-# name, and we get
confused users.

This patch does the same canonicalization of the paths that mount does
so that we don't end up having inconsistent names reported by ->show_devices
later.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
[use PATH_MAX in canonicalize_dm_name]
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-08-22 14:39:34 +02:00
Qu Wenruo b81dd800fc btrfs-progs: Improve the errno string about open_path_or_dev_mnt()
open_path_or_dev_mnt() is used to on *mounted* btrfs device or mount
point, when a unmounted btrfs device is passed, errno is set to EINVAL to
info the caller.
If ignore the errno and just print "ERROR: can't access '%s'", end users
will get confused.

This patch will add check for open_path_or_dev_mnt() caller and print
more meaningful error message when a unmounted btrfs device path is
given.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-08-22 14:39:30 +02:00
Qu Wenruo 1c1c7caf55 btrfs-progs: Modify the help string to keep consistent with man page.
Help string of "btrfs dev scan" is inconsistent with man page,
which lacks the fact that -d|--all-device is conflict with <device>.
This patch fixes the description

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-04-11 19:05:40 +02:00
Gui Hecheng 0e1b00c666 btrfs-progs: make the device scan logic more clear
1. Use long option to replace the original strcmp() to parse
the "--all-devices".
2. the "int ret" is defined in 2 places, just define it once
and make the return pattern into "goto + single return".

This does not change the actual scan procedure and return values.
Just make it clear, the original seems a little confusing.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
2014-03-21 06:23:32 -07:00
Gui Hecheng 6831721a43 btrfs-progs: cleanup device stat usage prompt
1. use usage() to replace the fprintf()
2. use check_argc_exact() to replace "argc != ..."

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
2014-03-21 06:23:32 -07:00
Mitchel Humpherys ef3f6124f0 btrfs-progs: fix minor grammar issues
Remove the extraneous `to' from `Can't access to X'.

Signed-off-by: Mitchel Humpherys <mitch.special@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
2014-01-31 08:22:28 -08:00
Anand Jain d894378932 btrfs-progs: handle error in the btrfs_prepare_device
this patch will handle the strerror reporting of the error instead of
printing errno,  and also replaced the BUG_ON with the error handling

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
2014-01-31 08:22:21 -08:00
Wang Shilong e3c9596d3f Btrfs-progs: add sanity checks for btrfs device operations
Make sure we are a block device firstly, this can avoid some
unnecessary ioctls operations.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
2014-01-31 08:22:17 -08:00
Josef Bacik f3fb002051 Btrfs-progs: make sure we return an error when we can't add a device
I noticed xfstests was failing in a weird way but it was because our device add
was failing but not actually returning an error so we were failing further down
the test.  Fix this by making sure we return an error if we fail the mkfs tests.
Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-10-24 05:57:44 -04:00
Anand Jain 005d7d2efb btrfs-progs: use the marco BTRFS_UPDATE_KERNEL where needed
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-10-16 08:23:13 -04:00
Anand Jain b4c3cd0bbc btrfs-progs: device scan use BTRFS_SCAN_LBLKID by default
with this patch, BTRFS_SCAN_LBLKID (which leverages lblkid
to look for btrfs disks) would be the default scan method
to look for the btrfs disks. And thus the output as seen
in the latest btrfs fi show and btrfs fi show -m for the
mounted disks will have the consistent disks path.
(it was inconsistent (across disks) because btrfs dev scan
provided a different path from the mount command eg. below)

    devid    1 size 1.98GiB used 435.00MiB path /dev/mapper/mpatha
    devid    2 size 2.00GiB used 415.00MiB path /dev/dm-1

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-10-16 08:23:13 -04:00
Anand Jain 1fdf85a3a3 btrfs-progs: device add should check existing FS before adding
as of now, when 'btrfs device add' adds a device it doesn't
check if the given device contains an existing FS. This
patch will change that to check the same. which when true
add will fail, and ask user to use -f option to overwrite.

further, since now we have test_dev_for_mkfs() function
to check if a disk can be used, so this patch will also
use this function to test the given device before adding.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-10-16 08:23:11 -04:00
David Sterba 992fd23180 btrfs-progs: add nodiscard option to device add
Same as for mkfs.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-10-16 08:20:43 -04:00
Wang Shilong d57dff4183 Btrfs-progs: fix magic return value in cmds-device.c
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-10-16 08:20:41 -04:00
Zach Brown c17a056f38 btrfs-progs: use NULL instead of 0
These were mostly in option structs but there were a few gross string
pointer arguments given as 0.

Signed-off-by: Zach Brown <zab@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-09-03 19:41:11 +02:00
Zach Brown 19a2e1f461 btrfs-progs: fix shadow symbols
This fixes all the instances of warnings that symbols declared in blocks
shadow symbols with the same name in surrounding scopes:

 cmds-device.c:341:22: warning: symbol 'path' shadows an earlier one
 cmds-device.c:285:14: originally declared here

I just renamed or removed the risky shadow symbols instead of pulling
their blocks out into functions.

Signed-off-by: Zach Brown <zab@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-09-03 19:41:02 +02:00
Zach Brown 7eab7f2a9c btrfs-progs: remove __CHECKER__ from main code
__CHECKER__ is only for the type juggling used to tell sparse which
types need conversion between address spaces.  It is not OK to use to
change the code that gets checked to avoid bugs elsewhere in the build
infrastructure.  We want to check the code that builds when the checker
isn't enabled.

Signed-off-by: Zach Brown <zab@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-09-03 19:41:01 +02:00
Anand Jain b8e23d4fb2 btrfs-progs: device delete to get errors from the kernel
when user runs command btrfs dev del the raid requisite error if any
goes to the /var/log/messages, its not good idea to clutter messages
with these user (knowledge) errors, further user don't have to review
the system messages to know problem with the cli it should be dropped
to the user as part of the cli return.

to bring this feature created a set of the ERROR defined
BTRFS_ERROR_DEV* error codes and created their error string.

I expect this enum to be added with other error which we might
want to communicate to the user land

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-08-09 14:32:36 +02:00
Anand Jain 5333445574 btrfs-progs: congregate dev scan
the dev scan to find btrfs is performed at two locations
all most the same way one at filesystem show and another
at device scan. They both follow the same steps. This
patch does not alter anything except that it brings these
two same logic into the function scan_for_btrfs so that
we can play tweaking it.

the patch which recommends to use /dev/mapper
will also need it

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-08-09 14:32:36 +02:00
Anand Jain 8f7c5897e9 btrfs-progs: update device scan usage
the btrfs device scan usage didnt publish --all-devices
option so add it

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-08-09 14:32:36 +02:00
Wang Shilong c125b7cf43 Btrfs-progs: fix closing of opendir()
valgrind complains open_file_or_dir() causes a memory leak.That is because
if we open a directoy by opendir(), and then we should call closedir()
to free memory.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-08-09 14:32:36 +02:00
David Sterba 309e50c763 btrfs-progs: Fix getopt on arm/ppc platforms
(same as commit bb0eabc383)
There, 'char' is unsigned, so once assigned '-1' from getopt, it gets
the value 255. Then, it compared to '-1' gives false.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-08-09 14:32:34 +02:00
Eric Sandeen 7a355379ea btrfs-progs: rework get_fs_info to remove side effects
get_fs_info() has been silently switching from a device to a mounted
path as needed; the caller's filehandle was unexpectedly closed &
reopened outside the caller's scope.  Not so great.

The callers do want "fdmnt" to be the filehandle for the mount point
in all cases, though - the various ioctls act on this (not on an fd
for the device).  But switching it in the local scope of get_fs_info
is incorrect; it just so happens that *usually* the fd number is
unchanged.

So - use the new helpers to detect when an argument is a block
device, and open the the mounted path more obviously / explicitly
for ioctl use, storing the filehandle in fdmnt.

Then, in get_fs_info, ignore the fd completely, and use the path on
the argument to determine if the caller wanted to act on just that
device, or on all devices for the filesystem.

Affects those commands which are documented to accept either
a block device or a path:

* btrfs device stats
* btrfs replace start
* btrfs scrub start
* btrfs scrub status

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-03-12 17:07:40 +01:00
Eric Sandeen b26746e462 btrfs-progs: Remove write-only var fdres in cmd_dev_stats()
fdres is initialized to -1, then later tested, but never
set.  Just remove it.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-02-27 14:39:24 +01:00
Eric Sandeen bcb2b73358 btrfs-progs: simplify ioctl name copy and null termination
In the places where we copy a string into the name
member of btrfs_ioctl_vol_args or btrfs_ioctl_vol_args_v2,
we use strncopy (to not overflow the name array) and then
set the last position to the null character.

Howver, in both cases the arrays are defined with:

        char name[MAX+1];

hence the last array position is name[MAX].

In most cases, we now insert the null at name[MAX-1]
which deprives us of one useful character.

Even the above isn't consistent through the code, so
make some helper code to make it simple, i.e.
strncpy_null(dest, src) which automatically does the
right thing based on the size of dest.

Thanks to Zach Brown for the macro suggestion.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-02-05 16:09:41 -08:00
Zach Brown 7c9f323a7c btrfs-progs: check for open failure, don't close
Check for failure by testing for a negative file descriptor, not a
descriptor of 0.  And if it failed we have nothing to close().

Signed-off-by: Zach Brown <zab@redhat.com>
2013-02-05 16:09:39 -08:00