Static mkfs.btrfs can be used to "bootstrap" a system from a live CD
which does not provide mkfs.btrfs.
The executable produced is named mkfs.btrfs.static and built by invoking
the "static" make rule.
Signed-off-by: Antoine Sirinelli <antoine@monte-stello.com>
Allocate fs_info::super_copy dynamically of full BTRFS_SUPER_INFO_SIZE
and use it directly for saving superblock to disk.
This fixes incorrect superblock checksum after mkfs.
Signed-off-by: David Sterba <dsterba@suse.cz>
consolidate error handling to ensure that peer_fd
is closed on error paths. Add a couple comments
to the error handling after the thread is complete.
Note that scrub_progress_cycle returns negative
errnos on any error.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Today wrong cmdlines give odd results:
# ./btrfs-vol /dev/sdb1
Unable to open device (null)
# ./btrfs-vol -a /dev/sdb1
usage: btrfs-vol [options] mount_point ...
Make it a bit more informative:
# ./btrfs-vol /dev/sdb1
No command specified
usage: btrfs-vol [options] mount_point ...
# ./btrfs-vol -a /dev/sdb1
No mountpoint specified
usage: btrfs-vol [options] mount_point ...
(even though it's deprecated ...)
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
The two sigint handlers issue ioctls to clean up, but if
they fail, noone would know. I'm not sure there is
any other error handling to be done at this point, but a
notification seems wise.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
It seems highly unlikely that posix_fadvise could fail,
and even if it does, it was only advisory. Still, if
it does, we could issue a notice to the user.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
cmd_subvol_create() currently returns without freeing resources
in almost every error case. Switch to a goto arrangement
so all cleanup can be done in one place.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
cmd_snapshot() currently returns without freeing resources
in almost every error case. Switch to a goto arrangement
so all cleanup can be done in one place.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Segmentation fault occurred in the following command.
# btrfs check /dev/sdc7
No valid Btrfs found on /dev/sdc7
Segmentation fault (core dumped)
Fix it.
Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
If we fail to execute the command:
btrfs qgroup show <mnt>
It will output the follow messages:
ERROR: can't perform the search - Inappropriate ioctl for device
ERROR: can't list qgroups
The error is outputed twice, this is wrong, fix it.
Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Linking 'btrfs' and other binaries against the dynamic library makes it
tedious to use directly from the git repo. This is useful for testing
various fixes, but now it'd need to also set LD_LIBRARY_PATH or install
the library to a known path.
Add a target for static library and use it for linking, the dynamic
library is to be used by external users.
Signed-off-by: David Sterba <dsterba@suse.cz>
External software wanting to use the functionality provided by the btrfs
send ioctl has a hard time doing so without replicating tons of work. Of
particular interest are functions like btrfs_read_and_process_send_stream()
and subvol_uuid_search(). As that functionality requires a bit more than
just send-stream.c and send-utils.c we have to pull in some other parts of
the progs package.
This patch adds code to the Makefile and headers to create a library,
libbtrfs which the btrfs command now links to.
Signed-off-by: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
The coverity runs had a false positive complaining that
save_ptr is uninitialized in the call to strtok_r.
Turns out that under the covers glibc was doing enough
to confuse the checker about what was being called.
Just to keep the noise down, do a harmless initialization,
with a comment as to why.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Rearrange cmd_subvol_set_default() slightly so we
don't have to close the fd on an error return.
While we're at it, fix whitespace & remove magic
return values.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Without this we leak the fd when we return from the
function.
Also, remove the senseless random return values.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Free the memory allocated to "multi" before the error
exit in read_whole_eb(). Set it to NULL after we free
it in the loop to avoid any potential double-free.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
If we request scrub cancel on an unmounted or
non-btrfs device, we still get a "scrub canceled"
success message:
# btrfs scrub cancel /dev/loop1
scrub cancelled
# blkid /dev/loop1
/dev/loop1: UUID="7f586941-1d5e-4ba7-9caa-b35934849957" TYPE="xfs"
Fix this so that if check_mounted_where returns 0
we don't report success.
While we're at it, use perror to report the reason for an open
failure, if we get one.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
If we retry opening the mountpoint and fail, we'll call
close on a filehandle w/ value -1. Rearrange so the
retry uses the same open and same error handling.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
__btrfs_map_block() can possibly do the goto again: loop after
having allocated & freed the "multi" pointer. There are then
a couple error conditions where it will attempt to again kfree
the now non-NULL multi pointer. So before retrying, reset
multi to NULL after we free it.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
btrfs_list_get_path_rootid() tries to return a negative
number on error, but it's a u64 function. Callers which test
for a return < 0 will never see an error.
Change the function to fill in the rootid via a pointer,
and then return a simple int as error.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
in btrfs_get_subvol(), there is a cut and paste error:
if (ri->full_path)
the_ri->full_path = strdup(ri->full_path);
else
the_ri->name = NULL;
It should be setting the_ri->full_path to NULL here.
Do it in a function instead of the cpoy & paste to avoid future
errors.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Clean btrfslabel.[c|h] out of the source tree and move those related
functions to utils.[c|h].
CC: Gene Czarcinski <gene@czarc.net>
Signed-off-by: Jie Liu <jeff.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Refactor check_label().
- Make it be static at first, this is a preparation step since we'll remove
btrfslabel.[c|h] and move those functions from there to utils.[c|h], we can
do pre-checking against the input label string with it.
- Fix the label length check up from BTRFS_LABEL_SIZE to BTRFS_LABEL_SIZE - 1.
- Kill the check of label contains an invalid character, see below commits for detail:
79e0e445fc
btrfs-progs: kill check for /'s in labels.
Signed-off-by: Jie Liu <jeff.liu@oracle.com>
CC: David Sterba <dsterba@suse.cz>
CC: Gene Czarcinski <gene@czarc.net>
Fix the command usage of "btrfs filesystem label" to reflect this change. i.e. so that
we can get/set the label of a mounted filesystem against the mountpoint.
Signed-off-by: Jie Liu <jeff.liu@oracle.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Currently, we keeping silent if the label length is exceeding BTRFS_LABEL_SIZE - 1, and just
truncating the characters beyond that.
This patch make it return error and exit in this situation.
Signed-off-by: Jie Liu <jeff.liu@oracle.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
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>
This patch adds an option to btrfstune, '-r' which will enable the extended
inode refs flag on the provided btrfs superblock. We don't have a disable
option at the moment as that would require far more work.
Signed-off-by: Mark Fasheh <mfasheh@suse.de>
Due to some historical reasons, we remove 'printing leaf' part, which'd
lead to 'Segmentation fault' of btrfs-debug-tree -e, this patch adds it
back.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
The core of this is shamelessly stolen from xfsprogs.
Use blkid to detect an existing filesystem or partition
table on any of the target devices. If something is found,
require the '-f' option to overwrite it, hopefully avoiding
disaster due to mistyped devicenames, etc.
# mkfs.btrfs /dev/sda1
WARNING! - Btrfs v0.20-rc1-59-gd00279c-dirty IS EXPERIMENTAL
WARNING! - see http://btrfs.wiki.kernel.org before using
/dev/sda1 appears to contain an existing filesystem (xfs).
Use the -f option to force overwrite.
#
This does introduce a requirement on libblkid.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>