Commit Graph

73 Commits (master)

Author SHA1 Message Date
David Sterba 1f5094bb5c btrfs-progs: add support for raid1c3 and raid1c4
Add support for 3- and 4- copy variants of RAID1. This adds resiliency
against 2 or resp. 3 devices lost or damaged.

$ ./mkfs.btrfs -m raid1c4 -d raid1c3 /dev/sd[abcd]

Label:              (null)
UUID:               f1f988ab-6750-4bc2-957b-98a4ebe98631
Node size:          16384
Sector size:        4096
Filesystem size:    8.00GiB
Block group profiles:
  Data:             RAID1C3         273.06MiB
  Metadata:         RAID1C4         204.75MiB
  System:           RAID1C4           8.00MiB
SSD detected:       no
Incompat features:  extref, skinny-metadata, raid1c34
Number of devices:  4
Devices:
   ID        SIZE  PATH
    1     2.00GiB  /dev/sda
    2     2.00GiB  /dev/sdb
    3     2.00GiB  /dev/sdc
    4     2.00GiB  /dev/sdd

Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-22 19:09:50 +01:00
Anand Jain dff3fb19d7 btrfs-progs: device scan: add new option to forget one or all scanned devices
This patch adds option --forget to 'device scan'

  $ btrfs device scan --forget [dev...]

to unregister the given device from kernel module. The device cannot be
part of a mounted filesystem, this will be reported as an error.

If no argument is given it will unregister all stale (device which are
not mounted) from the kernel.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
[ update changelog ]
Signed-off-by: David Sterba <dsterba@suse.com>
2019-03-01 13:40:21 +01:00
Misono Tomohiro 001e1b2178 btrfs-progs: ioctl/libbtrfsutil: add 3 definitions of new unprivileged ioctl
Copy and add 3 definitions of new unprivileged ioctls:

* BTRFS_IOC_GET_SUBVOL_INFO
* BTRFS_IOC_GET_SUBVOL_ROOTREF
* BTRFS_IOC_INO_LOOKUP_USER

from kernel definitions. They will be used to implement the version
of "btrfs subvolume list/show" that will not require root privileges.

Signed-off-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-10-31 18:24:14 +01:00
David Sterba 08a072c709 btrfs-progs: ioctl: fix compilation if ioctl.h is included standalone
Definition of NULL is missing if ioctl.h is included standalone or when
no other include pulls the definition.

Reported-by: Sergei Trofimovich <slyich@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-23 10:49:33 +01:00
David Sterba b2fbfc8cdd btrfs-progs: ioctl: fix build failure if BUILD_ASSERT is not defined
The build fails if ioctl.h is included without kerncompat.h which
defines BUILD_ASSERT, as reported. The proposed patches add kerncompat.h
but I don't want to pull that header via ioctl.h, so the fix will
provide an empty macro instead.

Reported-by: Eric Sandeen <sandeen@redhat.com>
Reported-by: Sergei Trofimovich <slyfox@gentoo.org>
Reported-by: Mikhail Pukhlikov <cynede@gentoo.org>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-25 14:28:36 +02:00
David Sterba 32a168684e btrfs-progs: ioctl: add 64bit compat for SEND
The ioctl value of SEND will be different on 32bit userspace and 64bit
kernel due to different pointer type width, that unfortunatelly made it
into the structure definition.

To maintain backward compatibility, we must do it in the 64bit->32bit
way, because we don't have the kernel side workardound like
SET_RECEIVED_SUBVOL has.  Changing value of SEND would then break
existing users of the raw ioctl.

The compatibility structure and ioctl should not be used, exists for
documentation, and testing.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-24 14:57:02 +02:00
David Sterba bbda9a2892 btrfs-progs: ioctl: add 32bit compat for SET_RECEIVED_SUBVOL
The ioctl value of SET_RECEIVED_SUBVOL will be different on 32bit
userspace and 64bit kernel. This is transparently handled on the kernel
side. We now define the same structure so we can verify the ioctl value.

The defined structure and ioctl should not be used. It is exists only
for testing purposes, documenting the mess and as a warning for the
future.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-24 14:56:40 +02:00
David Sterba 64b195d34f btrfs-progs: add build-time checks for size of ioctl structures
All structures that become part of ioctl definition must never change
size. Add the build time checks for that.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-10-05 12:39:01 +02:00
Hans van Kranenburg dcd25b7e0d btrfs-progs: use the correct struct for BTRFS_IOC_LOGICAL_INO
BTRFS_IOC_LOGICAL_INO takes a btrfs_ioctl_logical_ino_args as argument,
not a btrfs_ioctl_ino_path_args. The lines were probably copy/pasted
when the code was written.

Since btrfs_ioctl_logical_ino_args and btrfs_ioctl_ino_path_args have
the same size, the actual IOCTL definition here does not change.

But, it makes the code less confusing for the reader.

Signed-off-by: Hans van Kranenburg <hans.van.kranenburg@mendix.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-04 14:12:38 +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
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
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
David Sterba 40db5cd7ff btrfs-progs: extend balance args to take min/max usage filter
Add the overlapping usage and [usage_min, usage_max] members to the
balance args. The min/max values are interpreted iff the corresponding
flag BTRFS_BALANCE_ARGS_USAGE_RANGE is set.

The minimum boundary is inclusive, maximum is exclusive:
* usage_min <= chunk_usage < usage_max

Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-12 15:01:04 +01:00
Gabríel Arthúr Pétursson 0826a8ddb9 btrfs-progs: balance: add stripes filter
Add new balance filter 'stripes=<range>' to process only chunks that are
spread accross given number of chunks.

The range minimum and maximum are inclusive.

Signed-off-by: Gabríel Arthúr Pétursson <gabriel@system.is>
[ reworked a bit to use the range helpers, dropped the single value
  for stripes ]
Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-12 15:01:04 +01:00
David Sterba 45e9bf8098 btrfs-progs: extend balance args to take min/max limit filter
Add the overlapping limit and [limit_min, limit_max] members to the
balance args. The min/max values are interpreted iff the corresponding
flag BTRFS_BALANCE_ARGS_LIMIT_RANGE is set.

The minimum and maximum are inclusive.

Note that the values are only 32bit, but this should be enough for the
foreseeable future.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-12 15:01:03 +01:00
David Sterba 250a58f34d btrfs-progs: add missing includes to header files
Add includes that let the header files compile or add explicit include
of kerncompat if the uXX types are used.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-10 02:52:21 +02:00
David Sterba 1d46539284 btrfs-progs: ioctl.h: add btrfs_ioctl_feature_flags struct
Copied from uapi/linux/btrfs.h.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-03 19:36:36 +02:00
David Sterba 5910645a0e btrfs-progs: ioctl.h: update btrfs_ioctl_fs_info_args
Copied from uapi/linux/btrfs.h.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-03 19:35:54 +02:00
David Sterba 3e35646453 btrfs-progs: ioctl.h: update type annotations
Add the __user annotations to pointers in structures.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-03 19:33:44 +02:00
David Sterba b648021e06 btrfs-progs: ioctl.h: add send flag mask
Copied from uapi/linux/btrfs.h.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-03 19:33:44 +02:00
David Sterba 5adf707028 btrfs-progs: ioctl.h: add EXTENT_SAME ioctl and structures
Copied from uapi/linux/btrfs.h.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-03 19:33:43 +02:00
David Sterba 493f979c15 btrfs-progs: ioctl.h: copy commented version of balance structures
Copied from uapi/linux/btrfs.h, no-op change.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-03 16:40:34 +02:00
David Sterba ddd8003d94 btrfs-progs: ioctl.h: copy commented version of scrub_progress structure
Copied from uapi/linux/btrfs.h, no-op change.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-03 16:38:43 +02:00
David Sterba 9a6eb1f5ea btrfs-progs: ioctl.h: reorder to match kernel uapi header
This is a no-op change, move the code that also exists in the
uapi/linux/btrfs.h header.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-03 16:35:51 +02:00
David Sterba 07ce7005fc btrfs-progs: unify header file inclusion protections
There are missing ifdefs or defines with very generic names.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-01-21 17:49:26 +01:00
David Sterba 8ef9ac8cda btrfs-progs: basic support for TREE_SEARCH_V2 ioctl
Add the interface and helper that checks if the v2 ioctl is supported.

Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-10 15:01:20 +01:00
Eryu Guan b5e1ca5a49 btrfs-progs: add new dev replace result
A new dev replace result was introduced by kernel commit

Btrfs: return failure if btrfs_dev_replace_finishing() failed

Make the userspace know about the new result too.

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-25 18:50:58 +01:00
Eryu Guan 39893bb15e btrfs-progs: only report internal dev replace result if there's a result
If BTRFS_IOC_DEV_REPLACE ioctl failed, args.result usually won't be
updated by the ioctl.

And the arg has been initialized with 0, the result is always 0, which
is BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR, and the resulting error
message looks confusing:

ERROR: ioctl(DEV_REPLACE_START) failed on "/mnt/btrfs": No such file or directory, no error

But in case there's an internal result returned in future, don't drop
the result completely, instead print dev replace result message only
if the result is updated by a failed ioctl call.

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-11-03 18:35:30 +01:00
David Sterba 266c81a910 btrfs-progs: balance filter: add limit of processed chunks
Add more control to the balance behaviour.

Usage filter may not be finegrained enough and can lead to moving too
many chunks at once. Another example use is in connection with
drange+devid or vrange filters that allow to work with a specific chunk
or even with a chunk on a given device.

The limit filter applies last, the value of 0 means no limiting.

CC: Ilya Dryomov <idryomov@gmail.com>
CC: Hugo Mills <hugo@carfax.org.uk>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-08-22 14:55:26 +02:00
Gui Hecheng 2873ae9bd8 btrfs-progs: correct prompt of minimal num of devs for raid56
For btrfs,
Raid5 can't go below 2 devs, not 3;
Raid6 can't go below 3 devs, not 4.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-04-11 19:47:30 +02:00
Arvin Schnell 12b727a486 Btrfs-progs: use the correct integer type for ioctl
Signed-off-by: Arvin Schnell <aschnell@suse.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
2014-03-21 06:23:33 -07:00
David Disseldorp 1484081f61 ioctl: add note regarding CLONE_RANGE(len=0) behaviour
A BTRFS_IOC_CLONE_RANGE request with a src_length value of zero has the
effect of cloning all data from src_offset through to end-of-file.

Document this behaviour in the header file for those who (like me)
incorrectly assume that no data is cloned in such a case.

Signed-off-by: David Disseldorp <ddiss@suse.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
2014-03-21 06:23:10 -07:00
Anand Jain 257a71cb24 btrfs-progs: sync-up with newly introduced ioctl number
for now the manual sync up of new ioctls introduced in the btrfs
kernel. For which there wasn't any btrfs-progs patch.
however we might have better idea for the long run.

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:24 -08:00
David Sterba 4b7656f3bf btrfs-progs: add options to set commit mode after subvol delete
Subvolume deletion does not do a full transaction commit. This can lead
to an unexpected result when the system crashes between deletion and
commit, the subvolume directory will appear again. Add options to request
filesystem sync after each deleted subvolume or after the last one.

If the command with --commit option finishes succesfully, the
subvolume(s) deletion status is safely stored on the media.

Userspace approach is more flexible than in-kernel. Related discussions:
http://www.spinics.net/lists/linux-btrfs/msg22088.html
http://www.spinics.net/lists/linux-btrfs/msg27240.html

CC: Alex Lyakas <alex.btrfs@zadarastorage.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
2014-01-31 08:22:20 -08:00
Wang Shilong 1425caef05 Btrfs-progs: fix typo in btrfs_err_str()
Raid5 and raid6 at least need three and foure devices respectively,
fix it.

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:42 -04:00
Jan Schmidt eda2178b99 Btrfs-progs: added "btrfs quota rescan" -w switch (wait)
With -w one can wait for a rescan operation to finish. It can be used when
starting a rescan operation or later to wait for the currently running
rescan operation to finish. Waiting is interruptible.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-09-03 19:40:50 +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
Stefan Behrens 6315410f25 Btrfs-progs: add send option for using new end-cmd semantic
This commit adds a command line option to enable sending streams
which make use of the new end-cmd semantic if multiple snapshots are
sent back-to-back. The goal is to use the <end cmd> as an indication
to stop reading the input stream. So far, the receiver could only
use EOF to recognize the end.

If the new command line option '-e' is set, this commit requires a
kernel which is able to support the new flags in the send ioctl. New
bits in the flags of the send ioctl will be set which cause EINVAL
on old kernels. However, if the option '-e' is not set, it works
with old and new kernels without any errors or any changed behavior.

This used to be the encoding (with 2 snapshots in this example):
<stream header> + <sequence of commands> + <end cmd> +
<stream header> + <sequence of commands> + <end cmd> + EOF

The new format (if the two new flags are used) is this one:
<stream header> + <sequence of commands> +
                  <sequence of commands> + <end cmd>

Note that the currently existing receivers treat <end cmd> only as
an indication that a new <stream header> is following. This means,
you can just skip the sequence <end cmd> <stream header> without
loosing compatibility. As long as an EOF is following, the currently
existing receivers handle the new format (if the two new flags are
used) exactly as the old one.

Also note that the kernel interface was changed in a way that is
backward compatible to old btrfs-progs tools. You set one or two bits
in the flags field of the ioctl to enable the new behavior. Old tools
set these flags to zero, thus getting exactly the same as they got
with older kernels. And this is exactly what happens if the new '-e'
option is not set, the new bits in the flags are not set and thus
old kernels and new kernels are both supported.

So what is the benefit of this change? The goal is to be able to use
a single stream (one TCP connection) to multiplex a request/response
handshake plus Btrfs send streams, all in the same stream. In this
case you cannot evaluate an EOF condition as an end of the Btrfs send
stream. You need something else, and the <end cmd> is just perfect
for this purpose.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-08-09 14:32:29 +02:00
Jan Schmidt 14e028c26b Btrfs-progs: fixup: add flags to struct btrfs_ioctl_quota_rescan_args
The patch set previously sent was sent together with the kernel part, but
was not updated as I added some reserved bytes to the ioctl struct for
future compatibility. This fixes struct btrfs_ioctl_quota_rescan_args.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-05-10 10:55:22 -04:00
Jan Schmidt e9217541db Btrfs-progs: quota rescan
This adds the quota rescan command to be used if qgroup tracking should get
out of sync. Can also be used to query the status of a running rescan
operation.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
2013-04-23 18:56:27 +02:00
Jeff Liu 619dc61cae Btrfs-progs: Change the label of a mounted file system
With this new ioctl(2), we can set/change the label for a mounted file system.
It still does normal process for an umounted file system.

Signed-off-by: Jie Liu <jeff.liu@oracle.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-02-26 19:23:32 +01:00
Arvin Schnell 0c38ff3ca4 btrfs-progs: make libbtrfs usable from C++
Please find attached a patch to make the new libbtrfs usable from
C++ (at least for the parts snapper will likely need).

Signed-off-by: Arvin Schnell <aschnell@suse.de>
Signed-off-by: Mark Fasheh <mfasheh@suse.de>
2013-02-19 11:15:30 +01:00
Mark Fasheh fac5b559a7 btrfs-progs: Add support for BTRFS_SEND_FLAG_NO_FILE_DATA
The flag and command are synced from kernel to user. Also, this patch adds a
callback for the BTRFS_SEND_C_UPDATE_EXTENT in struct btrfs_send_ops.
read_and_process_cmd() is updated to decode BTRFS_SEND_C_UPDATE_EXTENT and
send the values through the right callback. I did not add a callback
definition to cmds-receive.c as that code never uses
BTRFS_SEND_FLAG_NO_FILE_DATA.

Signed-off-by: Mark Fasheh <mfasheh@suse.de>
2013-02-12 23:46:15 +01:00
Stefan Behrens 7e08a9116d Btrfs-progs: add support for device replace procedure
This is the user mode part of the device replace patch series.

The command group "btrfs replace" is added with three commands:
- btrfs replace start srcdev|srcdevid targetdev [-Bfr] mount_point
- btrfs replace status mount_point [-1]
- btrfs replace cancel mount_point

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
2013-01-31 13:47:26 +01:00
Stefan Behrens 5b8826ddfd Btrfs-progs: add command to get/reset device stats via ioctl
"btrfs device stats" is used to retrieve and print the device stats.
"btrfs device stats -z" is used to atomically retrieve, reset and
print the stats.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
2013-01-31 13:47:17 +01:00
Josef Bacik ce814a9378 Btrfs-progs: add btrfs device ready command
This command will be used by things like dracut that wish to know very
simply if all of the devices have been added to the kernel cache yet for the
device to be fully mounted.  This keeps initrd's from constantly having to
try to mount the file system until it succeeds every time a device is added
to the system.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: Gene Czarcinski <gene@czarc.net>
2013-01-23 19:41:27 +01:00
Arne Jansen 89fe5b5f66 Btrfs progs: quota groups support
Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
Signed-off-by: Arne Jansen <sensille@gmx.net>
2012-09-04 11:15:49 +02:00
Alexander Block a55616ee6c Btrfs-progs: update ioctl.h to support btrfs send ioctl
Add btrfs_ioctl_send_args and BTRFS_IOC_SEND to ioctl.h

Signed-off-by: Alexander Block <ablock84@googlemail.com>
2012-07-26 14:51:27 -04:00
Alexander Block 84b9586a89 Btrfs-progs: update btrfs-progs for subvol uuid+times support
Update ctree.h and ioctl.h for the new uuid+times for subvolumes.

Signed-off-by: Alexander Block <ablock84@googlemail.com>
2012-07-26 14:51:17 -04:00
Alexander Block 9cc8f76129 Btrfs-progs: update ioctl.h to support clone range ioctl
Added missing btrfs_ioctl_clone_range_args and BTRFS_IOC_CLONE_RANGE
to ioctl.h

Signed-off-by: Alexander Block <ablock84@googlemail.com>
2012-07-26 14:51:16 -04:00