Commit Graph

99 Commits (886a8565e03bfacddc1383fe61439303226a8802)

Author SHA1 Message Date
David Sterba 11c83cefb8 btrfs-progs: move more mkfs declarations to the common header
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:46 +01:00
David Sterba 1c880f34f1 btrfs-progs: move help defines to own header
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:45 +01:00
David Sterba d62902e95b btrfs-progs: dev stats: update option name for checking non-zero status
Rename the option to -c|--check and update documentation.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-12-14 15:06:36 +01:00
David Sterba b67e9a1b13 btrfs-progs: docs: update dev stats help and manual page
Signed-off-by: David Sterba <dsterba@suse.com>
2016-12-14 15:06:36 +01:00
David Sterba 01bafdbc90 btrfs-progs: dev stats: add long option for -z
Signed-off-by: David Sterba <dsterba@suse.com>
2016-12-14 15:06:36 +01:00
David Sterba 9468d9285a btrfs-progs: dev stats: use table based printing of items
Fewer lines, less code.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-12-14 15:06:36 +01:00
David Sterba 76be45599a btrfs-progs: dev stats: use char type path
Signed-off-by: David Sterba <dsterba@suse.com>
2016-12-14 15:06:35 +01:00
David Sterba 9fa02c427d btrfs-progs: dev stats: adjust some error messages
- use commonly used ioctl name spelling
- more specific error message after reading device info

Signed-off-by: David Sterba <dsterba@suse.com>
2016-12-14 15:06:35 +01:00
Austin S. Hemmelgarn afd1e7b4e3 btrfs-progs: dev stats: add dev stats returncode option
Currently, `btrfs device stats` returns non-zero only when there was an
error getting the counter values.  This is fine for when it gets run by a
user directly, but is a serious pain when trying to use it in a script or
for monitoring since you need to parse the (not at all machine friendly)
output to check the counter values.

This patch adds an option ('-s') which causes `btrfs device stats`
to set bit 6 in the return code if any of the counters are non-zero.
This greatly simplifies checking from a script or monitoring software if
any errors have been recorded.  In the event that this switch is passed
and an error occurs reading the stats, the return code will have bit
0 set (so if there are errors reading counters, and the counters which
were read were non-zero, the return value will be 65).

Signed-off-by: Austin S. Hemmelgarn <ahferroin7@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-12-14 15:06:35 +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 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
David Sterba f551548372 btrfs-progs: do not set optind if not necessary
In the subcommand callbacks that are called just once, we don't need to
explicitly reset optind.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-13 19:41:55 +02:00
David Sterba 5fcc6e93f0 btrfs-progs: handle memory allocation error in cmd_device_stats
Resolves-coverity-id: 1359012
Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 15:03:24 +02:00
Satoru Takeuchi 1c40f6916b btrfs-progs: "device ready" accepts just one device
* actual result

  =======================================
  # ./btrfs device ready /dev/sdb foo
  #
  =======================================

* expecting result

  =======================================
  # ./btrfs device ready /dev/sdb foo
  btrfs device ready: too many arguments
  usage: btrfs device ready <device>

      Check device to see if it has all of its devices in cache for mounting

  #
  =======================================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-02 14:42:09 +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 2490de5da5 btrfs-progs: Introduce device delete by devid
This patch introduces new option <devid> for the command

  btrfs device delete <device_path|devid>[..]  <mnt>

In a user reported issue on a 3-disk-RAID1, one disk failed with its
SB unreadable. Now with this patch user will have a choice to delete
the device using devid.

The other method we could do, is to match the input device_path
to the available device_paths with in the kernel. But that won't
work in all the cases, like what if user provided mapper path
when the path within the kernel is a non-mapper path.

This patch depends on the below kernel patch for the new feature to work,
however it will fail-back to the old interface for the kernel without the
patch

  Btrfs: Introduce device delete by devid

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-14 14:11:33 +01:00
Satoru Takeuchi 1ff2823225 btrfs-progs: Fix device scan to interpret its argument properly
Fix the following bug.

  ================================
  # btrfs device scan -- /dev/sdb
  ERROR: not a block device: --
  ================================

It should work as follow.

  ================================
  # ./btrfs device scan -- /dev/sdb
  Scanning for Btrfs filesystems in '/dev/sdb'
  ================================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-14 13:42:47 +01:00
Yauhen Kharuzhy 3ee935e4dd btrfs-progs: Dont' stop scanning of devices at first failed device
When 'btrfs device scan' command is invoked, it scans all devices,
check them for btrfs superblock and add devices with btrfs to a list.

Next, each device from the list is passed to kernel where it is handled
in the btrfs_scan_one_device() function. This function can, for example,
return -EBUSY when device contains superblock matched to existing and
mounted filesystem (if this device was pulled out from RAID and
connected again after some time).

btrfs tool stops device scan if any device has been failed to add, so
other existing devices with (possibly) valid FS will never be reached.

Fix this by remove stopping at any failure in the btrfs_register_all_devices(),
just return error count. btrfs_scan_one_device() reports any kind of
error already.

Signed-off-by: Yauhen Kharuzhy <yauhen.kharuzhy@zavadatar.com>
[ initialize err to 0 ]
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-14 13:42:47 +01:00
Yauhen Kharuzhy da3ae9c69a btrfs-progs: fix broken 'device scan' arguments parsing
Commit 52179e4fea41e55f31c92cd033a0b53a5107b4f4 'btrfs-progs: unify argc
min/max checking' breaks 'btrfs device scan' command when no argument
was given. Fix this.

Signed-off-by: Yauhen Kharuzhy <yauhen.kharuzhy@zavadatar.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-14 13:42:47 +01:00
David Sterba 358807cc33 btrfs-progs: unify argc min/max checking
We don't want to modify argc.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-14 13:42:47 +01:00
David Sterba babe94e481 btrfs-progs: add getopt stubs where needed
Commands that do not take any options do not use getopt, which means the
standard option separator "--" does not work. Update all command
handlers that need it, argv needs to be referenced using the optind that
is correctly pointed after the separator.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-14 13:42:47 +01:00
David Sterba ac4ec4d4f4 btrfs-progs: check for negative return value from ioctl
Handle only negative values returned by ioctl syscalls, with exception
of the device remove. It returns positive values that are handled later.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-12 15:02:55 +01:00
David Sterba 633dc6f80f btrfs-progs: remove unnecessary errno temp variables
We can read errno directly if it's not clobbered by any intermediate
calls.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-12 15:02:55 +01:00
Zhao Lei 0ca4cd99a5 btrfs-progs: cleanup cmd_device_usage, simplify loop checks
1: Remove more_than_one variable, use iterators value instead
2: Remove "out" label, we use break instead.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
[ changelog update ]
Signed-off-by: David Sterba <dsterba@suse.com>
2015-11-16 14:23:45 +01:00
Zhao Lei f5d6833768 btrfs-progs: device: use warning/error for error message
Switch to common warning()/error() for cmds-device.c.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
[ minor tweaks ]
Signed-off-by: David Sterba <dsterba@suse.com>
2015-11-16 14:23:45 +01:00
Alexander Fougner 56480048e4 btrfs-progs: allow device deletion using 'missing' keyword again
Device deletion procedures ensures the device is a block device.
This patch introduces 'missing' as keyword again, correctly
passing it on to the kernel instead of complaining about
'missing' not being a block device.

Signed-off-by: Alexander Fougner <fougner89@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-11-16 14:23:44 +01:00
David Sterba 49e0f3e646 btrfs-progs: utils: rename helpinfo unit vairables
Signed-off-by: David Sterba <dsterba@suse.com>
2015-11-06 16:39:49 +01:00
Zhao Lei da34dbd149 btrfs-progs: Remove all btrfs_close_all_devices in sub-command
Since we have btrfs_close_all_devices() in btrfs's main entrance,
it is not necessary to call btrfs_close_all_devices() separately
in each sub-command.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-11-02 09:35:07 +01:00
Chandan Rajendra c11e36a29e Btrfs-progs: Do not force mixed block group creation unless '-M' option is specified
When creating small Btrfs filesystem instances (i.e. filesystem size <= 1GiB),
mkfs.btrfs fails if both sectorsize and nodesize are specified on the command
line and sectorsize != nodesize, since mixed block groups involves both data
and metadata blocks sharing the same block group. This is an incorrect behavior
when '-M' option isn't specified on the command line.

This commit makes optional the creation of mixed block groups i.e. Mixed block
groups are created only when -M option is specified on the command line.

Since we now allow small filesystem instances with sectorsize != nodesize to
be created, we can end up in the following situation,

[root@localhost ~]# mkfs.btrfs -f -n 65536 /dev/loop0
btrfs-progs v3.19-rc2-405-g976307c
See http://btrfs.wiki.kernel.org for more information.

Performing full device TRIM (512.00MiB) ...
Label:              (null)
UUID:               49fab72e-0c8b-466b-a3ca-d1bfe56475f0
Node size:          65536
Sector size:        4096
Filesystem size:    512.00MiB
Block group profiles:
  Data:             single            8.00MiB
  Metadata:         DUP              40.00MiB
  System:           DUP              12.00MiB
SSD detected:       no
Incompat features:  extref, skinny-metadata
Number of devices:  1
Devices:
   ID        SIZE  PATH
    1   512.00MiB  /dev/loop0
[root@localhost ~]# mount /dev/loop0 /mnt/
mount: mount /dev/loop0 on /mnt failed: No space left on device

The ENOSPC occurs during the creation of the UUID tree. This is because of
things like large metadata block size, DUP mode used for metadata and global
reservation consuming space. Also, large nodesize does not make sense on small
filesystems, hence this should not be an issue.

Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-11-02 09:35:04 +01:00
Anand Jain 89c0e3b706 btrfs-progs: device add: cleanup argument handling
This is needed by the patch which introduces new devid option for the
btrfs device delete.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-11-02 09:35:03 +01:00
Zhao Lei 078618d822 btrfs-progs: use btrfs_open_dir in open_path_or_dev_mnt
Use btrfs_open_dir() in open_path_or_dev_mnt() to make the function
return error when target is neither block device nor btrfs mount point.

Also add "verbose" argument to let function output common error
message instead of putting duplicated lines in caller.

Before patch:
  # ./btrfs device stats /mnt/tmp1
  ERROR: getting dev info for devstats failed: Inappropriate ioctl for device
  # ./btrfs replace start /dev/vdd /dev/vde /mnt/tmp1
  ERROR: ioctl(DEV_REPLACE_STATUS) failed on "/mnt/tmp1": Inappropriate ioctl for device

After patch:
  # ./btrfs device stats /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1
  # ./btrfs replace start /dev/vdd /dev/vde /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-11-02 09:35:01 +01:00
Anand Jain 54fdddfdc1 btrfs-progs: fix is_block_device() return checks
it was highlighted to me is_block_device(), returns
 1 if the file is a block device,
 < 0 in case of an error (eg: file not found)
 0 otherwise

This patch makes proper return checks at all the places
where is_block_device() is used. Thanks to Goffredo.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Suggested-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-10-02 17:54:29 +02:00
David Sterba fe2657a707 btrfs-progs: cleanup, mark more functions static
Reported by sparse.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-14 23:45:53 +02:00
David Sterba 8ede30c220 btrfs-progs: cleanup, make usage strings static
Reported by sparse.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-14 23:45:32 +02:00
Zhao Lei 4483673ba6 btrfs-progs: Use common unit parser for btrfs device command
Move to use get_unit_mode_from_arg() for cmds-device.c,
to make "btrfs device usage"'s unit argument same with other
tools.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-09-01 14:01:59 +02:00
Zhao Lei abe48ca860 btrfs-progs: use btrfs_open_dir for btrfs device command
We can use btrfs_open_dir() to check whether the target dir is
under btrfs mount point before openning, instead of checking it in kernel
through ioctl, and returning a  fuzzy error message.

Before patch:
  # (/mnt/tmp is not btrfs mountpoint)
  #
  # btrfs device add -f /dev/sda13 /mnt/tmp
  ERROR: error adding the device '/dev/sda13' - Inappropriate ioctl for device
  #

After patch:
  # btrfs device add -f /dev/sda13 /mnt/tmp
  ERROR: not btrfs filesystem: /mnt/tmp
  #

Similar fix for device remove and device usage.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
[renamed to btrfs_open_dir]
Signed-off-by: David Sterba <dsterba@suse.com>
2015-08-31 19:25:14 +02:00
Zhao Lei ec1fc69d39 btrfs-progs: close all fs_devices before exit in some commands
mkfs creates more than one fs_devices in fs_uuids.
1: one is for file system being created
2: others are created in test_dev_for_mkfs in order to check mount point
   test_dev_for_mkfs()-> ... -> btrfs_scan_one_device()

Current code only closes 1, and this patch also closes in case 2.

Similar problem exist in other tools, eg.::

 cmd-check.c: the function is:
 cmd_check()->check_mounted()-> ... -> btrfs_scan_one_device()
 ...

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-08-31 19:25:13 +02:00
David Sterba 25ff5e53e0 btrfs-progs: update help for device stats
Signed-off-by: David Sterba <dsterba@suse.com>
2015-08-31 19:25:12 +02:00
David Sterba c6cf9778e8 btrfs-progs: unify naming of command handlers
Use cmd_ + group + command schema.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-08-31 19:25:09 +02:00
Omar Sandoval f802f572b1 btrfs-progs: alias btrfs device delete to btrfs device remove
There's an awkward asymmetry between btrfs device add and btrfs device
delete. Resolve this by aliasing delete to remove.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-26 16:33:39 +02:00
David Sterba 6a039e5063 btrfs-progs: properly set up ioctl arguments
At some places we do not clear the whole ioctl structure and could
pass garbage to kernel. Zero the ioctl vol_args and use a helper for
copying the path.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-12 16:44:48 +02:00
David Sterba c848046eb9 btrfs-progs: print error within test_dev_for_mkfs
The error string buffer passed as an argument is of a fixed size, though
we could print up to PATH_MAX + something bytes. Print the error message
directly.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-11 00:46:30 +02:00
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