Commit Graph

41 Commits (91bc44bd073020c27487b22ccf53a37d593d331e)

Author SHA1 Message Date
Gui Hecheng d9d9704510 btrfs-progs: fix improper error prompt for defragment
The error msg:
	"ERROR: defrag range ioctl not supported in this kernel,
	 please try without any options."
should only show up when failing to do a range defraging,
not upon non-range defraging.

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-01-31 08:22:13 -08:00
David Sterba 37cd29521a btrfs-progs: call endmntent in btrfs_scan_kernel
btrfs_scan_kernel() does a getmntent() but never releases the
filedescriptor it gets back from that.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=64711

Reported-by: Arjan van de Ven <arjan@linux.intel.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
2014-01-31 08:22:07 -08:00
Anand Jain 1ecefced86 btrfs-progs: define BTRFS_UUID_UNPARSE_SIZE for uuid unparse buf size
we use 37 as the allocation size to hold the uuid_unparse, here
it defines BTRFS_UUID_UNPARSE_SIZE for the same.

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:03 -08:00
Filipe David Borba Manana 457b1286dd Btrfs-progs: let get_label return the label instead of printing it
get_label prints the label at the moment. Change this so that
the label is returned and printing is done by the caller.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
2014-01-31 08:22:02 -08:00
Anand Jain a156b967ed btrfs-progs: make filesystem show by label work
with design revamp around filesystem show the fsid filter
by label wasn't planned. but apparently that seemed to be
necessary. this patch will fix it.

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:21:58 -08:00
Chris Mason 5aff090a39 btrfs filesystem show: skip duplicate fsids
If a given filesystem is mounted more than once, btrfs fi show will
print dups.  This adds a quick and dirty hash table of fsids it
has already printed and makes sure we don't print any fsid more than
once.

Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-11-18 14:27:21 -05:00
Eric Sandeen b68477aee1 btrfs-progs: check for fstat failure in cmd_defrag
Resolves-Coverity-CID: 1125924
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-11-07 16:10:41 -05:00
Eric Sandeen 7e29db9e49 btrfs-progs: pass positive errno to strerror in cmd_df()
get_df returns a negative error number, but then
we pass it to strerror, which wants a positive value...

Resolves-Coverity-CID: 1125929
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-11-07 16:10:41 -05:00
Eric Sandeen 09aa5d3601 btrfs-progs: btrfs_scan_kernel(): fd==0 is not an error
The error return from open is -1, so test that, not 0,
for success/failure.

Resolves-Coverity-CID: 1125931
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-11-07 16:10:41 -05:00
Eric Sandeen 667c121184 btrfs-progs: fix error returns in get_df()
get_df returns -ERRNO, or maybe (+)errno, or even 0 in
the case where we inexplicably got 0 total_spaces from
the BTRFS_IOC_SPACE_INFO.

Consistently return a negative error number, and return
-ENOENT rather than 0 for total_spaces == 0, so that the
caller will know that **sargs_ret hasn't been set up.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-11-07 16:10:40 -05:00
Anand Jain d33b2a4842 btrfs-progs: filesystem show of specified mounted disk should work
Originally, thinking was user will use mount point if the disk
is mounted. But thats not really true, actually user don't
(or shouldn't) care to check if disk mounted, so whether disk
is mounted/unmounted when disk path is specified it should work.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-10-24 05:57:44 -04:00
Anand Jain dde4b92141 btrfs-progs: use BTRFS_SCAN_LBLKID as default scan in filesystem show
btrfs progs has to scan for the btrfs disks for two main reasons,
 one to register them with the btrfs kernel (under btrfs dev scan)
 2nd to report btrfs disks to the user (under btrfs fi show)
 (there few more minor reasons like check_mounted etc..).

 To facilitate the scan, in total we have the following methods
 to scan for the btrfs

 BTRFS_SCAN_PROC
  which uses the /proc/partitions to look for the disks, when
  scanning it does it twice first would look for non dm- paths
  and in the 2nd scan it would pick only dm- paths.

 BTRFS_SCAN_DEV
  which scans all the block dev under /dev as they appear during
  scanning.

 BTRFS_SCAN_LBLKID
  this uses the library functions provided  by the lblkid to get
  only disks which contains the btrfs SB.

 The better method to use would be BTRFS_SCAN_LBLKID for the obvious
 reasons we don't have to reinvent that feature with in btrfs-progs.

 For the btrfs fi show - This patch will..
   - make BTRFS_SCAN_LBLKID as the default scan option

   (BTRFS_SCAN_DEV is accessible under the option --all-devices and
   BTRFS_SCAN_PROC won't be used by btrfs fi show any more)

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 6c2c30ce03 btrfs-progs: use kernel for mounted disk for show
As of now btrfs filesystem show reads directly from
disks. So sometimes output can be stale, mainly when
user wants to cross verify their operation like,
label or device delete or add... etc. so this
patch will read from the kernel ioctl if it finds
that disk is mounted.

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
Frank Holton c2c5e53bf7 btrfs-progs: Add recursive defrag using -r option
Add an option to defrag all files in a directory recursively.

Signed-off-by: Frank Holton <fholton@gmail.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
Anand Jain 23c47a132f btrfs-progs: move out print in cmd_df to another function
This is a prepatory work for the btrfs fi show command
fixes. So that we have a function get_df to get the fs sizes

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 4e466c8b44 btrfs-progs: add list_sort and use it to sort devices by id
The devices in 'btrfs filesystem show' are now sorted by the device id,
currently the order was undefined.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-10-16 08:22:26 -04:00
Wang Shilong c0a7cbf03c Btrfs-progs: fix magic return value in cmds-filesystem.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
Qu Wenruo 3ca706a6ee btrfs-progs: Update the usage strings of some cmds
Update the usage strings of some cmds to keep the them consistent with
the source.

Also some minor changes are done to fit the man page syntax.

Signed-off-by: Qu Wenruo <quwenruo@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:37 +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 7d1478b91a btrfs-progs: label option in btrfs filesystem show is not coded
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
Zach Brown 876e3f9380 btrfs-progs: per-thread, per-call pretty buffer
We don't need callers to manage string storage for each pretty_sizes()
call.  We can use a macro to have per-thread and per-call static storage
so that pretty_sizes() can be used as many times as needed in printf()
arguments without requiring a bunch of supporting variables.

This lets us have a natural interface at the cost of requiring __thread
and TLS from gcc and a small amount of static storage.  This seems
better than the current code or doing something with illegible format
specifier macros.

Signed-off-by: Zach Brown <zab@redhat.com>
Acked-by: Wang Shilong <wangs.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:33 +02:00
Liu Bo 617769147f Btrfs-progs: record errno for ioctl DEFRAG_RANGE
In order to sparse exact error message, we need to record errno here.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
2013-04-23 18:56:27 +02:00
Anand Jain e9393c220f btrfs-progs: defrag return zero on success
Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-03-18 19:42:29 +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 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
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
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 4cce2094b1 btrfs-progs: don't leak fd in resize
Argument validation failed to close the fd that was opened.  So check
the arguments before opening anything.

Signed-off-by: Zach Brown <zab@redhat.com>
2013-02-05 16:09:40 -08:00
David Woodhouse 4d48b96b28 Add basic RAID[56] support
David Woodhouse originally contributed this code, and Chris Mason
changed it around to reflect the current design goals for raid56.

The original code expected all metadata and data writes to be full
stripes.  This meant metadata block size == stripe size, and had a few
other restrictions.

This version allows metadata blocks smaller than the stripe size.  It
implements both raid5 and raid6, although it does not have code to
rebuild from parity if one of the drives is missing or incorrect.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-02-01 14:22:07 -05:00
Goffredo Baroncelli 8f76aee6bc Move parse_size() to utils.[hc]
Move the function from cmds-filesystem.c and mkfs.c to utils.c

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
2013-01-17 18:27:54 +01:00
Zhi Yong Wu f38a139a96 btrfs-progs: Fix up memory leakage
Some code pathes forget to free memory on exit.

Changelog from v1:
  Fix the variable is used uncorrectly. [Ram Pai]

Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2012-10-04 16:26:34 -04:00
Zhi Yong Wu 4a39f7d5d1 btrfs-progs: Close file descriptor on exit
Need to close fd on exit.

Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2012-10-04 16:26:34 -04:00
Shawn Bohrer 6cb6eeb11d btrfs-progs: Update resize documentation
The btrfs filesystem resize command defaults to only resizing the
filesystem for devid 1, and must have a devid passed in to resize the
filesystem for the other devices in the filesystem.

Additionally the documentation lacked information on how to actually
resize the underlying partition so this provides a little more detail.

Signed-off-by: Shawn Bohrer <shawn.bohrer@gmail.com>
2012-07-03 16:27:46 -04:00
Josef Bacik 3f388b9690 Btrfs-progs: make btrfs filesystem show <uuid> actually work
The btrfs filesystem show command is only actually searching for labels,
it's not searching for UUID's at all.  This patch fixes that problem.
Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
2012-07-03 16:27:46 -04:00
Jim Meyering 54e345b5c2 avoid several strncpy-induced buffer overruns
* restore.c (main): Ensure strncpy-copied dir_name is NUL-terminated.
* btrfsctl.c (main): Likewise, for a command-line argument.
* utils.c (multiple functions): Likewise.
* btrfs-list.c (add_root): Likewise.
* btrfslabel.c (change_label_unmounted): Likewise.
* cmds-device.c (cmd_add_dev, cmd_rm_dev, cmd_scan_dev): Likewise.
* cmds-filesystem.c (cmd_resize): Likewise.
* cmds-subvolume.c (cmd_subvol_create, cmd_subvol_delete, cmd_snapshot):
Likewise.

Reviewed-by: Josef Bacik <josef@redhat.com>
2012-06-05 19:56:20 +01:00
Ilya Dryomov 08b51bd731 Btrfs-progs: allow multi-line command group synopsis
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
2012-02-08 18:55:51 +02:00
Ilya Dryomov 888b7005ca Btrfs-progs: add 'balance' command group infrastructure
Add balance command group under both 'btrfs' and 'btrfs filesystem'.
Preserve the old 'btrfs filesystem balance <path>' behaviour.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
2012-02-03 21:02:30 +02:00
Ilya Dryomov d675085a67 Btrfs-progs: switch all existing commands to a new parser
The new infrastructure offloads checking number of arguments passed to a
command to individual command handlers.  Fix them up accordingly.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
2012-02-03 21:00:17 +02:00
Ilya Dryomov 4f26833193 Btrfs-progs: rearrange files in the repo
Separate every command group into its own file (cmds_<group>.c) and
rearrange includes.  Remove btrfs_cmds.c.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
2012-02-03 21:00:17 +02:00