Commit Graph

724 Commits (e7cce77a56bff57144954b8b21fa1e79f00f549e)
 

Author SHA1 Message Date
Eric Sandeen e7cce77a56 btrfs-progs: initialize save_ptr prior to strtok_r
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>
2013-02-27 14:40:09 +01:00
Eric Sandeen fb631862c9 btrfs-progs: fix fd leak in cmd_subvol_set_default
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>
2013-02-27 14:40:05 +01:00
Eric Sandeen 917609b8d6 btrfs-progs: Tidy up resolve_root
Whitespace fixes and fix a variable declaration after
code.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-02-27 14:40:02 +01:00
Eric Sandeen a9df6a1bde btrfs-progs: fix mem leak in resolve_root
If we exit with error we must free the allocated memory
to avoid a leak.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-02-27 14:39:59 +01:00
Eric Sandeen e54ba43cde btrfs-progs: close fd on cmd_subvol_get_default return
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>
2013-02-27 14:39:56 +01:00
Eric Sandeen 1b12f5c9f7 btrfs-progs: free allocated di_args in cmd_start_replace
We only freed this allocation in error paths, and leaked
a bit when it went out of scope normally.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-02-27 14:39:53 +01:00
Eric Sandeen 3d118fe6c4 btrfs-progs: provide positive errno to strerror in cmd_restore
check_mounted returns a negative errno, so it needs to be flipped
again before passing to strerror.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-02-27 14:39:48 +01:00
Eric Sandeen b5acfa282b btrfs-progs: don't call close on error fd
In the error case where fd < 0, close(fd) is the wrong
thing to do.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-02-27 14:39:45 +01:00
Eric Sandeen 2e23e290ca btrfs-progs: free memory before error exit in read_whole_eb
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>
2013-02-27 14:39:42 +01:00
Eric Sandeen d310e9cfff btrfs-progs: more scrub cancel error handling
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>
2013-02-27 14:39:39 +01:00
Eric Sandeen 5eaeb577b5 btrfs-progs: fix close of error fd in scrub cancel
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>
2013-02-27 14:39:37 +01:00
Eric Sandeen 67c631329a btrfs-progs: fix open error test in cmd_start_replace
open() returns a negative fd on failure, not 0.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-02-27 14:39:34 +01:00
Eric Sandeen bbf1919b00 btrfs-progs: avoid double-free in __btrfs_map_block
__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>
2013-02-27 14:39:31 +01:00
Eric Sandeen b808cb66aa btrfs-progs: btrfs_list_get_path_rootid error handling
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>
2013-02-27 14:39:27 +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 220e1ccd87 btrfs-progs: fix btrfs_get_subvol cut/paste error
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>
2013-02-27 14:39:15 +01:00
Jeff Liu efbbbc88cb btrfs-progs: move btrfslabel.[c|h] stuff to utils.[c|h]
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>
2013-02-26 19:27:22 +01:00
Jeff Liu 63a44771a4 btrfs-progs: refactor check_label()
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>
2013-02-26 19:24:14 +01:00
Jeff Liu c51b711fff Btrfs-progs: fix cmd_label_usage to reflect this change.
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>
2013-02-26 19:24:14 +01:00
Jeff Liu 3988e80702 Btrfs-progs: Fix set_label_unmounted() with label length validation
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>
2013-02-26 19:24:14 +01: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
Mark Fasheh 704a08cb8a btrfsprogs: btrfstune support for extended inode refs
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>
2013-02-21 14:30:23 -05:00
Liu Bo e5701088e2 Btrfs-progs: fix segmentation fault of 'btrfs-debug-tree -e'
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>
2013-02-19 11:42:03 +01:00
Eric Sandeen 2a2d8e1962 btrfs-progs: require mkfs -f force option to overwrite filesystem or partition table
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>
2013-02-19 11:15:31 +01:00
Mark Fasheh 3b85739dd6 btrfs-progs: Fix pointer math in __ino_to_path_fd
We are casting an array of u64 values into a char ** array so
when we dereference this array (as a char **) on a 32 bit system
we're then re-casting that back to a 32 bit value. This causes
problems when we try to print those strings.

Signed-off-by: Mark Fasheh <mfasheh@suse.de>
2013-02-19 11:15:30 +01:00
Tsutomu Itoh d065d63057 Btrfs-progs: check out if the swap device
Currently, the following commands succeed.

 # cat /proc/swaps
 Filename                                Type            Size    Used    Priority
 /dev/sda3                               partition       8388604 0       -1
 /dev/sdc8                               partition       9765884 0       -2
 # mkfs.btrfs /dev/sdc8

 WARNING! - Btrfs v0.20-rc1-165-g82ac345 IS EXPERIMENTAL
 WARNING! - see http://btrfs.wiki.kernel.org before using

 fs created label (null) on /dev/sdc8
         nodesize 4096 leafsize 4096 sectorsize 4096 size 9.31GB
 Btrfs v0.20-rc1-165-g82ac345
 # btrfs fi sh /dev/sdc8
 Label: none  uuid: fc0bdbd0-7eed-460f-b4e9-131273b66df2
         Total devices 1 FS bytes used 28.00KB
         devid    1 size 9.31GB used 989.62MB path /dev/sdc8

 Btrfs v0.20-rc1-165-g82ac345
 #

But we should check out the swap device. Fixed it.

Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Tested-by: David Sterba <dsterba@suse.cz>
2013-02-19 11:15:30 +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
Ilya Dryomov 7d4dc89f96 Btrfs-progs: make 0 a valid usage filter argument
This is a progs counterpart to a "Btrfs: allow for selecting only
completely empty chunks".  usage=0 now means "select only only
completely empty chunks and nothing else".

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
2013-02-13 11:53:23 +01:00
Mark Fasheh 66819df285 btrfs-progs: add send-test
send-test.c links against libbtrfs and uses the send functionality provided
to decode and print a send stream to the console.

Signed-off-by: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
2013-02-13 11:53:21 +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
Ian Kumlien e43cc46155 Btrfs-progs: add restore command to btrfs
Add 'btrfs restore' command which previously existed as a separate
utility btrfs-restore.

Signed-off-by: Ian Kumlien <pomac@demius.net>
Signed-off-by: David Sterba <dsterba@suse.cz>
2013-02-12 23:46:15 +01:00
Ian Kumlien 1b1e07190f Btrfs-progs: restore.c -> cmds-restore.c
The btrfs-restore functionality will be integrated in
btrs as "btrfs restore"

Signed-off-by: Ian Kumlien <pomac@demius.net>
2013-02-12 23:46:15 +01:00
David Sterba e31f6172aa btrfs-progs: build btrsfck to keep compatibility
The command 'btrfsck' is commonly used and we should build it by
default.

Signed-off-by: David Sterba <dsterba@suse.cz>
2013-02-12 23:46:12 +01:00
Ilya Dryomov d5d2046ae3 Btrfs-progs: add btrfsck name detection to btrfs
This patch adds a busybox-style name detection for the name "btrfsck" to
btrfs utility.  The idea is to maintain backwards compatibility by
linking btrfsck to btrfs and have btrfs invoke the check sub-command
when called through the btrfsck link.  This has been suggested on the
mailing list and approved by Dave and Chris.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
2013-02-12 22:55:28 +01:00
Ilya Dryomov 2f4e4e448f Btrfs-progs: move crc32c optimization init
Don't call crc32c_optimization_init() until we know that a command is
actually going to be invoked.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
2013-02-12 22:55:26 +01:00
Ian Kumlien 5956f752c6 Btrfs-progs: add btrfsck functionality to btrfs
This patch includes the functionality of btrfs, it's
found as "btrfs check".

Signed-off-by: Ian Kumlien <pomac@demius.net>
Signed-off-by: David Sterba <dsterba@suse.cz>
2013-02-12 19:09:47 +01:00
Ian Kumlien fac45410e9 Btrfs-progs: Rename btrfsck.c -> cmds-check.c
In preparation for merging btrfsck functionality in to btrfs.

Signed-off-by: Ian Kumlien <pomac@demius.net>
2013-02-12 16:36:47 +01:00
Ian Kumlien 93f06520b8 Btrfs-progs: -U_FORTIFY_SOURCE before -D
My builds are cluttered with:
<command-line>:0:0: warning: "_FORTIFY_SOURCE" redefined [enabled by
default]

Which makes it hard to tell if something breaks or not.

Signed-off-by: Ian Kumlien <pomac@demius.net>
2013-02-12 15:22:57 +01:00
Ian Kumlien 6e0ade1767 Btrfs-progs: add static compile target
Sometimes, when you least expect it, a static binary is what you need to
rescue your data... Or just get a good enough handle on things to make
it work again ;)

"make static" is a gift to you, dear user with filesystem problems!

Anyway, on a more serious note, changed the cflags and ldflags so that
we create a smaller binary, 1.1MB stripped on my 64 bit system
(2.7MB with debug data)

Signed-off-by: Ian Kumlien <pomac@demius.net>
2013-02-12 15:22:55 +01:00
Wang Sheng-Hui 50e3ff573c btrfs-progs: code cleanup for root-tree.c/btrfs_del_root
Remove the redundant if check on the condition ret > 0.
Leave BUG_ON check here.

Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
2013-02-07 01:19:50 +01:00
Josef Bacik 8a46573c2a Btrfs-progs: return an error if we can't find an fs root
Instead of doing a BUG_ON() if we fail to find the last fs root just return
an error so the callers can deal with it how they like.  Also we need to
actually return an error if we can't find the latest root so that the error
handling works.  With this btrfsck was able to deal with a file system that
was missing a root item but still had extents that referred back to the
root.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
2013-02-07 01:19:50 +01:00
Josef Bacik 8795e785ce Btrfs-progs: fix double free of extent buffer
Noticed this while looking for an segfault related to our eb cache in
btrfsck.  We free the eb in out: so we don't need this extra free.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
2013-02-07 01:19:50 +01:00
Josef Bacik 6cba7b1b46 Btrfs-progs: handle errors reading fs roots
A user had a problem where btrfsck would bail out because it was finding
extents for a snapshot that had been deleted but not entirely cleaned up.
We can handle this case fine, we just need to report an error properly.
This patch allowed btrfsck to continue and eventually fix his file system.
Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
2013-02-07 01:19:49 +01:00
Eric Sandeen 5e7b9d2156 btrfs-progs: remove unused bit-radix.[ch] files
fd53de4d Drop bit-radix.[ch] files
removed the files from the Makefile, but not the files themselves.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-02-07 01:19:49 +01:00
Eric Sandeen a8cb2d03dd Btrfs-progs print more informative error when we fail to open a device
print more informative error when we fail to open a device

If open() fails, we should let the user know why it failed.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Gene Czarcinski <gene@czarc.net>
2013-02-06 23:09:02 +01:00
Chris Mason 82ac34581e Merge branch 'cov-fixes-v1-integration-20130201' of http://git.zabbo.net/cgit/btrfs-progs into merged 2013-02-06 12:51:58 -05:00
Chris Mason 7b1c567c84 Merge branch 'for-chris' of git://repo.or.cz/btrfs-progs-unstable/devel into raid56
Conflicts:
	ctree.h

Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-02-06 12:42:24 -05:00
Eric Sandeen 2986545ccd btrfs-progs: initialize pipefd[] for error path
Several goto out; paths will end up doing i.e.

        if (pipefd[0])
                close(pipefd[0]);

but we get there with uninitialized values in many cases.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-02-05 16:09:41 -08:00
Eric Sandeen 899ba61fa6 btrfs-progs: fix overflows of ioctl name args
3 places where we copy pathnames into ioctl arguments
were not limited to the destination name size, and
could overflow.  Use the new strncpy_null() macro
to make this safe.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-02-05 16:09:41 -08: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