platform/upstream/btrfs-progs.git
11 years agobtrfs-progs: simplify ioctl name copy and null termination
Eric Sandeen [Fri, 25 Jan 2013 19:27:47 +0000 (13:27 -0600)]
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>
11 years agobtrfs-progs: fix name lengths in cmd_subvol_create
Eric Sandeen [Fri, 25 Jan 2013 19:27:46 +0000 (13:27 -0600)]
btrfs-progs: fix name lengths in cmd_subvol_create

cmd_subvol_create() calls either BTRFS_IOC_SUBVOL_CREATE
or BTRFS_IOC_SUBVOL_CREATE_V2 depending on whether or
not inherit is set.  However, these 2 ioctls have different
args structures with different length name[] members.

In the BTRFS_IOC_SUBVOL_CREATE case, the arg is
btrfs_ioctl_vol_args, with a BTRFS_PATH_NAME_MAX length
name, not a BTRFS_SUBVOL_NAME_MAX length name.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
11 years agobtrfs-progs: remove duplicate __setup_root
Eric Sandeen [Fri, 25 Jan 2013 00:18:57 +0000 (18:18 -0600)]
btrfs-progs: remove duplicate __setup_root

__setup_root() was present in find-root.c as well
as disk-io.c.  No need for the cut and paste, just
use the one in disk-io.c

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: fix mdresotre typo in function names
Eric Sandeen [Fri, 25 Jan 2013 00:18:53 +0000 (18:18 -0600)]
btrfs-progs: fix mdresotre typo in function names

"mdresotre" sounds like it might be French, but most
likely it's a misspelling of mdrestore.  Fix it.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: zero out inspect ioctl args
Eric Sandeen [Fri, 25 Jan 2013 00:18:51 +0000 (18:18 -0600)]
btrfs-progs: zero out inspect ioctl args

Mostly just to keep things like coverity happy about potentially
uninitialized structure members, since it doesn't grok the ioctl.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: don't use closed fd
Eric Sandeen [Fri, 25 Jan 2013 00:18:50 +0000 (18:18 -0600)]
btrfs-progs: don't use closed fd

In the case that btrfs scrub cancel is given a device name,
we close the file handle, and then pass it to check_mounted_where()
which eventually preads from that (now closed) fd.  Fix the logic
so that we close & re-open the discovered mountpoint properly.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: don't double-close prg_fd
Eric Sandeen [Fri, 25 Jan 2013 00:18:49 +0000 (18:18 -0600)]
btrfs-progs: don't double-close prg_fd

If scrub start discovers that scrub is already running,
we need to set prg_fd to -1 before goto out, or we'll
try to close it again in the error path.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: don't leak fds in logical resolve
Zach Brown [Thu, 24 Jan 2013 18:53:49 +0000 (10:53 -0800)]
btrfs-progs: don't leak fds in logical resolve

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: close fd in inode resolve
Zach Brown [Thu, 24 Jan 2013 18:45:00 +0000 (10:45 -0800)]
btrfs-progs: close fd in inode resolve

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: don't leak multi-bio in find_root()
Zach Brown [Thu, 24 Jan 2013 18:38:28 +0000 (10:38 -0800)]
btrfs-progs: don't leak multi-bio in find_root()

It wasn't freed if it didn't find metadata.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: don't leak inherit on errors
Zach Brown [Wed, 23 Jan 2013 23:18:14 +0000 (15:18 -0800)]
btrfs-progs: don't leak inherit on errors

A few paths returned errors before freeing their inherit allocation.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: close ioctl fd in find new
Zach Brown [Wed, 23 Jan 2013 23:15:09 +0000 (15:15 -0800)]
btrfs-progs: close ioctl fd in find new

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: don't leak fd in resize
Zach Brown [Wed, 23 Jan 2013 23:11:24 +0000 (15:11 -0800)]
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>
11 years agobtrfs-progs: free path before returning
Zach Brown [Wed, 23 Jan 2013 23:07:18 +0000 (15:07 -0800)]
btrfs-progs: free path before returning

One of the return statements in search_dir() didn't free everything it
was supposed to.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: close fd in qgroup show
Zach Brown [Wed, 23 Jan 2013 23:00:46 +0000 (15:00 -0800)]
btrfs-progs: close fd in qgroup show

It wasn't closed in the error path.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: free bits in check_extents()
Zach Brown [Wed, 23 Jan 2013 22:55:31 +0000 (14:55 -0800)]
btrfs-progs: free bits in check_extents()

As far as I can tell, nothing took the address of this.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: remove unused arguments
Zach Brown [Wed, 23 Jan 2013 22:54:35 +0000 (14:54 -0800)]
btrfs-progs: remove unused arguments

add_root_to_pending() took a bunch of arguments that it never used.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: scrub can leak fd 0
Zach Brown [Wed, 23 Jan 2013 22:41:03 +0000 (14:41 -0800)]
btrfs-progs: scrub can leak fd 0

< 0 is returned for errors opening the file, this code could leak fd 0.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: fix scrub socket leak
Zach Brown [Wed, 23 Jan 2013 22:36:03 +0000 (14:36 -0800)]
btrfs-progs: fix scrub socket leak

If connection fails the socket is leaked when the status file is used
instead.  Close it to trivially cut down on fd use and to bring down the
noise in static code analysis.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: don't leak in set_extent_bits
Zach Brown [Wed, 23 Jan 2013 20:18:32 +0000 (12:18 -0800)]
btrfs-progs: don't leak in set_extent_bits

It looks possible to hit the search_again label without using the
prealloc.  A new prealloc is allocated, leaking the current one.

Every use of prealloc sets it to null so let's just allocate a new
prealloc when we don't already have one.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: fix overflow in btrfs_scan_one_dir()
Zach Brown [Wed, 23 Jan 2013 19:31:24 +0000 (11:31 -0800)]
btrfs-progs: fix overflow in btrfs_scan_one_dir()

btrfs_scan_one_dir() can overflow an arbitrarily small 256 byte buffer
with an arbitrarily slightly larger 1024 byte buffer as it remembers the
path of a dir to later descend.

Make these buffers the same size to stop the overflow and chose PATH_MAX
for that size so that it won't fail on legitimately bonkers paths.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: free path on read_chunk_tree error
Zach Brown [Tue, 22 Jan 2013 23:52:17 +0000 (15:52 -0800)]
btrfs-progs: free path on read_chunk_tree error

Path allocation failure already has its own return, remember to free the
path when the error label is taken.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: array indexes must be < ARRAY_SIZE()
Zach Brown [Tue, 22 Jan 2013 23:11:55 +0000 (15:11 -0800)]
btrfs-progs: array indexes must be < ARRAY_SIZE()

It looks like the usual kernel idiom of "< ARRAY_SIZE()" was
accidentally negated as ">" instead of ">=".

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: don't write memory after sb to disk
Zach Brown [Tue, 22 Jan 2013 23:03:46 +0000 (15:03 -0800)]
btrfs-progs: don't write memory after sb to disk

struct btrfs_super is about 3.5k but a few writing paths were writing it
out as the full 4k BTRFS_SUPER_INFO_SIZE, leaking a few hundred bytes
after the super_block onto disk.  In practice this meant the memory
after super_copy in struct btrfs_fs_info and whatever came after it in
the heap.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: impossible BUG_ON meant to test empty
Zach Brown [Tue, 22 Jan 2013 21:58:20 +0000 (13:58 -0800)]
btrfs-progs: impossible BUG_ON meant to test empty

old_left_nritems is unsigned so BUG_ON(old_left_nritems < 0) is
impossible.  Presumably the BUG_ON() meant to test that it wasn't 0 so
that btrfs_item_offset_nr() doesn't get a nr of -1.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: check for open failure, don't close
Zach Brown [Tue, 22 Jan 2013 21:48:04 +0000 (13:48 -0800)]
btrfs-progs: check for open failure, don't close

Check for failure by testing for a negative file descriptor, not a
descriptor of 0.  And if it failed we have nothing to close().

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: don't close(<0) in subvol create
Zach Brown [Tue, 22 Jan 2013 21:42:16 +0000 (13:42 -0800)]
btrfs-progs: don't close(<0) in subvol create

Don't try to close an fd immediately after discovering that opening it
failed.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: don't return -EBUSY from main()
Zach Brown [Tue, 22 Jan 2013 21:36:47 +0000 (13:36 -0800)]
btrfs-progs: don't return -EBUSY from main()

-EBUSY is platform dependent and is even less reliable when truncated to
a u8.  Just return 1 on error.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: don't close(-1)
Zach Brown [Tue, 22 Jan 2013 01:11:28 +0000 (17:11 -0800)]
btrfs-progs: don't close(-1)

When opening the fd fails just return instead of taking the shared error
path that tries to close() the fd.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: break after printing FREE_INO
Zach Brown [Tue, 22 Jan 2013 00:52:15 +0000 (16:52 -0800)]
btrfs-progs: break after printing FREE_INO

The free inode objectid would be printed as "FREE_INOQUOTA_TREE" because
of a missing break.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: don't free null path
Zach Brown [Tue, 22 Jan 2013 00:34:03 +0000 (16:34 -0800)]
btrfs-progs: don't free null path

btrfs_free_path() derefs the path before freeing it.  It can't be passed
a null pointer when allocation fails.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: remove dead code that checks null eb
Zach Brown [Tue, 22 Jan 2013 00:25:51 +0000 (16:25 -0800)]
btrfs-progs: remove dead code that checks null eb

'next' can never be non-null in the body of these loops.  It's
initialized to NULL and the loop is terminated the moment it is set.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: fix copy-n-paste error checking
Zach Brown [Fri, 18 Jan 2013 00:36:48 +0000 (16:36 -0800)]
btrfs-progs: fix copy-n-paste error checking

copy_one_inline() meant to test the return of pwrite() with ram_size.
Presumably the comparison with len was copied from the test earlier in
the function.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: remove unused info_fd
Zach Brown [Fri, 18 Jan 2013 00:32:41 +0000 (16:32 -0800)]
btrfs-progs: remove unused info_fd

finish_subvol() initializes and tests info_fd but it is never used.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: use ftw() unstead of system("du")
Zach Brown [Thu, 17 Jan 2013 23:23:10 +0000 (15:23 -0800)]
btrfs-progs: use ftw() unstead of system("du")

size_sourcedir() uses shockingly bad code to try and estimate the size
of the files and directories in a subtree.

- Its use of snprintf(), strcat(), and sscanf() with arbitrarily small
  on-stack buffers manages to overflow the stack a few times when given
  long file names.

  $ BIG=$(perl -e 'print "a" x 200')
  $ mkdir -p /tmp/$BIG/$BIG/$BIG/$BIG/$BIG
  $ mkfs.btrfs /tmp/img -r /tmp/$BIG/$BIG/$BIG/$BIG/$BIG
  *** stack smashing detected ***: mkfs.btrfs terminated

- It passes raw paths to system() allowing interpreting file names as
  shell control characters.

  $ mkfs.btrfs /tmp/img -r /tmp/spacey\ dir/
  du: cannot access `/tmp/spacey': No such file or directory
  du: cannot access `dir/': No such file or directory

- It redirects du output to "temp_file" in the current directory,
  allowing overwriting of files through symlinks.

  $ echo hi > target
  $ ln -s target temp_file
  $ mkfs.btrfs /tmp/img -r /tmp/somedir/
  $ cat target
  3 /tmp/somedir/

This fixes the worst problems while maintaining -r functionality by
tearing out the system() code and using ftw() to walk the source tree
and sum up st.st_size.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: more carefully check eb backrefs
Zach Brown [Thu, 17 Jan 2013 21:24:35 +0000 (13:24 -0800)]
btrfs-progs: more carefully check eb backrefs

check_owner_ref() could deref a null path node if btrfs_search_slot()
fails or simply doesn't find a tree tall enough to get to the parent of
the desired block.

This was flagged by static analysis warning that btrfs_search_slot()'s
return value wasn't being checked.

Signed-off-by: Zach Brown <zab@redhat.com>
Again: caught by static analysis.

11 years agobtrfs-progs: return error from commit_tree_roots()
Zach Brown [Thu, 17 Jan 2013 20:06:29 +0000 (12:06 -0800)]
btrfs-progs: return error from commit_tree_roots()

Errors cow-ing the root block are silently being dropped.  This is
just a step towards error handling because both the caller and calee
assert on errors.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agobtrfs-progs: treat super.magic as an le64
Zach Brown [Thu, 17 Jan 2013 19:54:47 +0000 (11:54 -0800)]
btrfs-progs: treat super.magic as an le64

The super block magic is a le64 whose value looks like an unterminated
string in memory.  The lack of null termination leads to clumsy use of
string functions and causes static analysis tools to warn that the
string will be unterminated.

So let's just treat it as the le64 that it is.  Endian wrappers are used
on the constant so that they're compiled into run-time constants.

Signed-off-by: Zach Brown <zab@redhat.com>
11 years agoBtrfs-progs: use btrfs_lookup_first_block_group when fixing accounting
Josef Bacik [Fri, 1 Feb 2013 17:00:32 +0000 (12:00 -0500)]
Btrfs-progs: use btrfs_lookup_first_block_group when fixing accounting

This was a bug from long time ago that never actually got fixed.  We start
with bytenr 0 when looping through all of the block groups, but
btrfs_lookup_block_group will bail out since it couldn't find a block group
with 0 as the bytenr.  Btrfs_lookup_first_block_group will be nice and
adjust the start up to the right value, so this way we reset all the block
groups properly and not screw up the users block group accounting.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
11 years agoBtrfs-progs: dont print uuid unless -u option is given
Anand Jain [Thu, 25 Oct 2012 08:00:31 +0000 (16:00 +0800)]
Btrfs-progs: dont print uuid unless -u option is given

unless it was intentional to include uuid when -s
option is (show snapshot only) given, we would need
this break statement.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
11 years agobtrfs-progs: btrfsck: Print which filesystem to be checked to stdout
Dieter Ries [Sun, 14 Oct 2012 15:17:19 +0000 (17:17 +0200)]
btrfs-progs: btrfsck: Print which filesystem to be checked to stdout

This patch makes btrfsck print the filesystem, which is to be checked,
to stdout, as well as the UUID of the corresponding partition.
This should be helpful when analyzing (copied and pasted) output of
btrfsck.

Signed-off-by: Dieter Ries <mail@dieterries.net>
11 years agobtrfs-progs: update man pages of subvol list
David Sterba [Fri, 1 Feb 2013 16:37:29 +0000 (17:37 +0100)]
btrfs-progs: update man pages of subvol list

- rename to match code where applicable
- add missing options
- unify the help strings in short and detailed sections
- fix a few typos

Signed-off-by: David Sterba <dsterba@suse.cz>
11 years agobtrfs-progs: add option c to show ogeneration
David Sterba [Fri, 1 Feb 2013 16:19:49 +0000 (17:19 +0100)]
btrfs-progs: add option c to show ogeneration

This will also pair the 'C' filter.

Signed-off-by: David Sterba <dsterba@suse.cz>
11 years agobtrfs-progs: add option g to show generation
David Sterba [Tue, 9 Oct 2012 16:27:53 +0000 (18:27 +0200)]
btrfs-progs: add option g to show generation

Add 'g' to pair the 'G' filter.

Signed-off-by: David Sterba <dsterba@suse.cz>
11 years agobtrfs-progs: upcase filter options
David Sterba [Tue, 9 Oct 2012 16:27:52 +0000 (18:27 +0200)]
btrfs-progs: upcase filter options

Rename filter options in 'subvol list' subcommand, that way we can
distinguish them from the options that just show some option in the
output and can have a matching uppercase filter.

Signed-off-by: David Sterba <dsterba@suse.cz>
11 years agoBtrfs-progs: add subvol flags to print
Anand Jain [Fri, 1 Feb 2013 07:56:32 +0000 (15:56 +0800)]
Btrfs-progs: add subvol flags to print

This patch adds the flags row which as of now will show if the
subvol/snapshot is readonly.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
11 years agoBtrfs-progs: Fix a small memory leak in managing the btrfs list filter
Anand Jain [Fri, 1 Feb 2013 07:56:31 +0000 (15:56 +0800)]
Btrfs-progs: Fix a small memory leak in managing the btrfs list filter

Signed-off-by: Anand Jain <anand.jain@oracle.com>
11 years agoBtrfs-progs: update btrfs_get_subvol to be inline with resolve_root ret changes
Anand Jain [Fri, 1 Feb 2013 07:56:30 +0000 (15:56 +0800)]
Btrfs-progs: update btrfs_get_subvol to be inline with resolve_root ret changes

Signed-off-by: Anand Jain <anand.jain@oracle.com>
11 years agoBtrfs-progs: filter the deleted subvolumes when listing snapshots
Wang Shilong [Fri, 1 Feb 2013 07:56:29 +0000 (15:56 +0800)]
Btrfs-progs: filter the deleted subvolumes when listing snapshots

btrfs snapshot list command will stop by the deleted subvolumes.

The problem may happen by two ways:
1. a subvolume deletion is not commited, that is ROOT_BACKREF has been deleted,
   but ROOT_ITEM still exists. The command will fail to fill the path of
   the deleted subvolumes because we can not get the parent fs/file tree.
2. a subvolume is possibly deleted when we fill the path, For example,
   Fs tree
     |->subv0
  |->subv1

   We may fill the path of subv1 firstly, after that, some user deletes subv1
   and subv0, and then we fill the path of subv0. The command will fail to
   fill the path of subv0 because we can not get path of subv0. And the command
   also will fail to make the full path of subv1 because we don't have the path
   of subv0.

Since these subvolumes have been deleted, we should filter them. This patch
fixed the above problem by this way.

For the 1st case, ->ref_tree of the deleted subvolumes are 0.
For the 2nd case, if we found the error number that ioctl() returns is ENOENT,
we will set ->ref_tree to 0.
And when we make the full path of the subvolumes, we will check ->ref_tree of
them and their parent. If someone's ->ref_tree or its parent's ->ref_tree is 0,
we will filter it.

Reported-by: Stefan Priebe <s.priebe@profihost.ag>
Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
11 years agoBtrfs-progs: add show subcommand to subvol cli
Anand Jain [Fri, 1 Feb 2013 07:56:28 +0000 (15:56 +0800)]
Btrfs-progs: add show subcommand to subvol cli

This adds show sub-command to the btrfs subvol cli
to display detailed inforamtion of the given subvol
or snapshot.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
11 years agoBtrfs-progs: make get_subvol_name non cmds-send specific
Anand Jain [Fri, 1 Feb 2013 07:56:27 +0000 (15:56 +0800)]
Btrfs-progs: make get_subvol_name non cmds-send specific

get_subvol_name can be used other than the just with in cmds-send.c
so this patch will make it possible with out changing the original
intentions.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
11 years agoBtrfs-progs: make printing subvol extensible to newer layouts
Anand Jain [Fri, 1 Feb 2013 07:56:26 +0000 (15:56 +0800)]
Btrfs-progs: make printing subvol extensible to newer layouts

Currently you can print subvol in a list or table format.
This patch will provide a way to extend this to other formats
like the upcoming raw format.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
11 years agoBtrfs-progs: put find_mount_root() in commands.h
Anand Jain [Fri, 1 Feb 2013 07:56:25 +0000 (15:56 +0800)]
Btrfs-progs: put find_mount_root() in commands.h

A useful function need to define it in a header file.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
11 years agoBtrfs-progs: add method to filter snapshots by parent uuid
Anand Jain [Fri, 1 Feb 2013 07:56:24 +0000 (15:56 +0800)]
Btrfs-progs: add method to filter snapshots by parent uuid

Signed-off-by: Anand Jain <anand.jain@oracle.com>
11 years agoBtrfs-progs: add function btrfs_get_subvol to get root_info of a subvol
Anand Jain [Fri, 1 Feb 2013 07:56:23 +0000 (15:56 +0800)]
Btrfs-progs: add function btrfs_get_subvol to get root_info of a subvol

We need a function which can get the root_info of a given
subvol. This is in preparation to add support for the show
sub-cli.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
11 years agoBtrfs-progs: move struct root_info to btrfs-list.h
Anand Jain [Fri, 1 Feb 2013 07:56:22 +0000 (15:56 +0800)]
Btrfs-progs: move struct root_info to btrfs-list.h

As we would add more ways to list and manage the subvols
and snapshots, its better if we have struct root_info
defined in the header file.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
11 years agoBtrfs-progs: add parent uuid for snapshots
Anand Jain [Fri, 1 Feb 2013 07:56:21 +0000 (15:56 +0800)]
Btrfs-progs: add parent uuid for snapshots

Signed-off-by: Anand Jain <anand.jain@oracle.com>
11 years agoBtrfs-progs: move printing subvol list outside of btrfs_list_subvols
Anand Jain [Fri, 1 Feb 2013 07:56:20 +0000 (15:56 +0800)]
Btrfs-progs: move printing subvol list outside of btrfs_list_subvols

To improve the code reuse its better to have btrfs_list_subvols
just return list of subvols witout printing

Signed-off-by: Anand Jain <anand.jain@oracle.com>
11 years agoBtrfs-progs: List all subvolumes by default
Lukas Czerner [Tue, 11 Dec 2012 14:25:00 +0000 (15:25 +0100)]
Btrfs-progs: List all subvolumes by default

Commit a1e89891eb6af5381539d9875b85c196150171b6 changed subvolume list
command so that we list only subvolumes under the specified directory.
However this is confusing and unnecessary obstacle, because one usually
want to see all subvolumes in the file system. It was introduced with
the notion the full_path may be invalid which is not exactly true as the
full_path is always relative to the root subvolume which makes perfect
sense.

Simply making option '-a' default is not enough since it introduces the
relative/absolute path distinction effectively obfuscating the subvolume
nesting.

This commit returns the subvolume list command behaviour before commit
a1e89891eb6af5381539d9875b85c196150171b6 where we list all subvolumes in
the filesystem with path naming from root subovolume. IMO this is the
best default as it is well understood and gives all the important
information about file system subvolumes including subvolume nesting
without the need to parse additional information.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
11 years agoBtrfs-progs: add '-o' option into subvolume list command
Lukas Czerner [Tue, 11 Dec 2012 14:24:59 +0000 (15:24 +0100)]
Btrfs-progs: add '-o' option into subvolume list command

This commit introduces new option '-o' to list only subvolumes under the
specified path. This does not change subvolume list  behaviour. It has
been default in the past and it is even with this commit.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
11 years agoBtrfs-progs: move path modification to filters
Lukas Czerner [Tue, 11 Dec 2012 14:24:58 +0000 (15:24 +0100)]
Btrfs-progs: move path modification to filters

Commit 8e8e019e910f20947fea7eff5da40753639d8870 introduces -a option
which will list all subvolumes with distinguishing between relative and
absolute by prepending absolute patch with "<FS_TREE>".

This commit moves the path modification to a filter code rather than
doing so in path construction in resolve_root(). This gives us more
flexibility in formatting path output.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
11 years agoBtrfs-progs: Complete the help information of btrfs send/receive
Chen Yang [Fri, 18 Jan 2013 06:52:12 +0000 (14:52 +0800)]
Btrfs-progs: Complete the help information of btrfs send/receive

When typing command "btrfs send --help" or "btrfs receive --help",
the help information of the commands is incomplete, which only
shows a short usage.

This patch helps to display the complete infomation of the commands.

Signed-off-by: Cheng Yang <chenyang.fnst@cn.fujitsu.com>
11 years agoUpdate the man page with the new prefixes.
Goffredo Baroncelli [Mon, 29 Oct 2012 17:53:20 +0000 (18:53 +0100)]
Update the man page with the new prefixes.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
11 years agobtrfs-progs: mkfs support for extended inode refs
Mark Fasheh [Thu, 7 Jun 2012 23:00:56 +0000 (16:00 -0700)]
btrfs-progs: mkfs support for extended inode refs

This patch turns on the BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF superblock flag
when creating a new file system in mkfs, enabling extended inode refs.

Signed-off-by: Mark Fasheh <mfasheh@suse.de>
11 years agobtrfs-progs: add extended inode ref support to btrfsck
Mark Fasheh [Thu, 7 Jun 2012 23:00:55 +0000 (16:00 -0700)]
btrfs-progs: add extended inode ref support to btrfsck

Add a function, process_inode_extref() to be called from process_one_leaf()
when an item type of BTRFS_INODE_EXTREF_KEY is encountered.

Similarly to process_inode_ref(), process_inode_extref() walks an extref and
adds an inode_backref structure for each reference found within.

I modified fsck's inode_backref to get a type field (ref_type) which helps
us internally track the exact type of backrefs found.  Of course this field
could be overwritten in case of disk corruption (duplicate refs) but
duplicate refs themselves are tracked by btrfsck so that should not be an
issue as btrfsck is written today.

Signed-off-by: Mark Fasheh <mfasheh@suse.de>
11 years agobtrfs-progs: Basic support for extended inode refs
Mark Fasheh [Thu, 7 Jun 2012 23:00:54 +0000 (16:00 -0700)]
btrfs-progs: Basic support for extended inode refs

This patch syncs the extended inode ref definitions from kernels ctree.h and
adds support in btrfs-debug-tree for visualizing the state of extended refs
on disk.

Signed-off-by: Mark Fasheh <mfasheh@suse.de>
11 years agoBtrfs-prog/send: fix wrong dump_fd check in cmd_send_start()
Chen Yang [Thu, 31 Jan 2013 08:21:24 +0000 (16:21 +0800)]
Btrfs-prog/send: fix wrong dump_fd check in cmd_send_start()

In cmd_send_start(), there is a check to make sure dump_fd is not a tty
before parsing command options. So if we use the option "-f file",
it doesn't work for the dump_fd has not been created. So fix it.

Signed-off-by: Cheng Yang <chenyang.fnst@cn.fujitsu.com>
11 years agoBtrfs-progs: man btrfs: subcommands must be grouped together
Anand Jain [Thu, 31 Jan 2013 05:35:31 +0000 (13:35 +0800)]
Btrfs-progs: man btrfs: subcommands must be grouped together

Signed-off-by: Anand Jain <anand.jain@oracle.com>
11 years agobtrfs-progs: fix parallel build
David Sterba [Wed, 30 Jan 2013 18:02:21 +0000 (19:02 +0100)]
btrfs-progs: fix parallel build

Parallel build may fail due to late creation of version.h, fix the rule name
that does not match the filename.

Signed-off-by: David Sterba <dsterba@suse.cz>
Reviewed-by: Eri Sandeen <sandeen@redhat.com>
11 years agobtrfs-progs: fix mkfs.btrfs -r option
Eric Sandeen [Tue, 29 Jan 2013 20:32:28 +0000 (14:32 -0600)]
btrfs-progs: fix mkfs.btrfs -r option

Commit 605e806166847872bb91831b397d58f95027975a broke the
mkfs.btrfs -r option, because it calls make_btrfs
without ever setting dev_block_count, in the -r case,
so we tell it to make a filesystem of size 0.

Then we wander into ENOSPC land and segfault.

As a quick one-line-fix, just set the dev_block_count
to the size of the destination image file.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
11 years agoBtrfs-progs: add support for device replace procedure
Stefan Behrens [Mon, 7 May 2012 12:00:20 +0000 (14:00 +0200)]
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>
11 years agoBtrfs-progs: add command to get/reset device stats via ioctl
Stefan Behrens [Tue, 15 May 2012 09:30:39 +0000 (11:30 +0200)]
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>
11 years agoBtrfs-progs: make two utility functions globally available
Stefan Behrens [Tue, 15 May 2012 10:05:44 +0000 (12:05 +0200)]
Btrfs-progs: make two utility functions globally available

Two convenient utility functions that have so far been local to scrub are
moved to utils.c.
They will be used in the device stats code in a following commit.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
11 years agoBtrfs-progs: move open_file_or_dir() to utils.c
Anand Jain [Mon, 28 Jan 2013 05:22:30 +0000 (13:22 +0800)]
Btrfs-progs: move open_file_or_dir() to utils.c

The definition of the function open_file_or_dir() is moved from common.c
to utils.c in order to be able to share some common code between scrub
and the device stats in the following step. That common code uses
open_file_or_dir(). Since open_file_or_dir() makes use of the function
dirfd(3), the required XOPEN version was raised from 6 to 7.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Original-Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
11 years agobtrfs-progs: fix build warnings in btrfslabel.c
David Sterba [Mon, 28 Jan 2013 18:29:32 +0000 (19:29 +0100)]
btrfs-progs: fix build warnings in btrfslabel.c

Signed-off-by: David Sterba <dsterba@suse.cz>
11 years agobtrfs-progs: fix unaligned accesses v2
Ben Peddell [Sun, 27 Jan 2013 05:45:43 +0000 (15:45 +1000)]
btrfs-progs: fix unaligned accesses v2

gcc optimizes out the memcpy calls at -O2 and -Os.

Replacing memcpy with memmove does't work - gcc treats memmove
the same way it treats memcpy.

This patch brings in {get|put}_unaligned_le{16|32|64} (using the
packed struct method), and uses them in the failing get/set calls.

On architectures where unaligned accesses are cheap, these unaligned
macros should be optimized out by the compiler.

Signed-off-by: Ben Peddell <klightspeed@killerwolves.net>
11 years agoBtrfs-progs: Fix trival compiler error in cmds-qgroup.c
Gene Czarcinski [Sat, 26 Jan 2013 18:10:33 +0000 (13:10 -0500)]
Btrfs-progs: Fix trival compiler error in cmds-qgroup.c

The compiler does not realize that usage() never returns.
Initializing the variable keeps it quiet.

Signed-off-by: Gene Czarcinski <gene@czarc.net>
11 years agobtrfs-progs: update options in find-root.c
Wang Sheng-Hui [Sun, 18 Nov 2012 02:13:20 +0000 (10:13 +0800)]
btrfs-progs: update options in find-root.c

Remove the useless option "-v" and add the option "-o" in
the description of usage.

Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
11 years agobtrfs-progs pretty/quiet build
Eric Sandeen [Thu, 24 Jan 2013 23:32:52 +0000 (17:32 -0600)]
btrfs-progs pretty/quiet build

A quieter build makes warnings more obvious.

This could probably be improved, but just to see
if people like this or if they hate it.  :)

make V=1 overrides it and gets you the full
glory again.

    [CC]     ctree.o
    [CC]     disk-io.o
    [CC]     radix-tree.o
    [CC]     extent-tree.o
    ...

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
11 years agobtrfs-progs: kill check for /'s in labels
Josef Bacik [Thu, 22 Jan 2009 19:25:44 +0000 (14:25 -0500)]
btrfs-progs: kill check for /'s in labels

This patch kills a check in mkfs's label stuff which doesn't allow labels that
have /'s in them.  This causes problems for Anaconda which try to label volumes
with their mountpoints.  Thanks,

Signed-off-by: Josef Bacik <jbacik@redhat.com>
11 years agoBtrfs-progs: we need to have the string null terminated
Anand Jain [Thu, 24 Jan 2013 10:05:14 +0000 (18:05 +0800)]
Btrfs-progs: we need to have the string null terminated

Bug:
-------------
btrfs subvolume list / -a
ID 258 gen 4226 top level 384 path media/smbshare
::
btrfs subvolume list /home -a
ID 258 gen 4226 top level 5 path <FS_TREE>/__active/media/smbshare4.snap

In the first command's output, this path is printed correctly, however
in the second output it has "4.snap" appended, similar to the names of
the snapshots I made 22 hours ago.
------------

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reported-by: Brendan Hide <brendan@swiftspirit.co.za>
11 years agoBtrfs-prog/send: fix wrong best-parent assignment in, find_good_parent()
Chen Yang [Thu, 24 Jan 2013 11:53:40 +0000 (19:53 +0800)]
Btrfs-prog/send: fix wrong best-parent assignment in, find_good_parent()

We use find_good_parent() to look for a suit snapshot in the clone source
snapshots as the parent, not the source subvolume of the snapshot which
is about to be sent. fix it

Reviewed-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
Signed-off-by: Cheng Yang <chenyang.fnst@cn.fujitsu.com>
11 years agobtrfs-progs: Add btrfs-show-super
Stefan Behrens [Fri, 2 Nov 2012 14:05:30 +0000 (15:05 +0100)]
btrfs-progs: Add btrfs-show-super

Just a small program to print the fields of a super block.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
11 years agoBtrfs-progs: add btrfs device ready command
Josef Bacik [Sat, 19 Jan 2013 18:06:20 +0000 (13:06 -0500)]
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>
11 years agoBtrfs-progs: detect if the disk we are formatting is a ssd
Josef Bacik [Sat, 19 Jan 2013 18:06:21 +0000 (13:06 -0500)]
Btrfs-progs: detect if the disk we are formatting is a ssd

Patch rebased because of changes in mkfs.c but otherwise the same
as created by Josef Bacik

SSD's do not gain anything by having metadata DUP turned on.  The underlying
file system that is a part of all SSD's could easily map duplicate metadat
blocks into the same erase block which effectively eliminates the benefit of
duplicating the metadata on disk.  So detect if we are formatting a single
SSD drive and if we are do not use DUP.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: Gene Czarcinski <gene@czarc.net>
11 years agobtrfs-progs: Use sysconf instead of getpagesize
Eric Sandeen [Sat, 19 Jan 2013 18:06:17 +0000 (13:06 -0500)]
btrfs-progs: Use sysconf instead of getpagesize

Rawhide is getting cranky with posix compliance, and a few
things have stopped building.

getpagesize() is now only available -with- __USE_XOPEN_EXTENDED
or __USE_BSD, and NOT __USE_XOPEN2K.

_GNU_SOURCE must define __USE_XOPEN2K because getpagesize()
has gone away for mkfs.  I gave up and used sysconf.

Also, something used to pull in stat that no longer does, so
things like S_ISREG weren't getting defined.

The following fixes things for me.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
11 years agobtrfs-progs: fix build, manpage compression command
Christian Hesse [Tue, 22 Jan 2013 20:51:19 +0000 (15:51 -0500)]
btrfs-progs: fix build, manpage compression command

man pages for btrfs-progs are compressed by gzip by default. In Makefile the
variable GZIP is use, this evaluates to 'gzip gzip' on my system. From man
gzip:

> The environment variable GZIP can hold a set of default options for gzip.
> These options are interpreted first and can be overwritten by explicit
> command line parameters.

So using any other variable name fixes this. Patch is attached.

Signed-off-by: Christian Hesse <list@eworm.de>
Signed-off-by: Gene Czarcinski <gene@czarc.net>
11 years agoBtrfs-progs: Fix typo in balance start usage; filetrs -> filters.
Andreas Fischer [Mon, 21 Jan 2013 19:19:03 +0000 (19:19 +0000)]
Btrfs-progs: Fix typo in balance start usage; filetrs -> filters.

Fix typo in "btrfs balance start" usage documentation: 'filetrs' should have
been 'filters'.

Signed-off-by: Andreas Fischer <info@andreasfischer.net>
11 years agoBtrfs-progs: fix an off-by-one in write_dev_supers()
Stefan Behrens [Wed, 31 Oct 2012 16:56:56 +0000 (17:56 +0100)]
Btrfs-progs: fix an off-by-one in write_dev_supers()

Fix an off-by-one in write_dev_supers().

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
11 years agoBtrfs-progs: bugfix for subvolume parent determination in btrfs send
Jan Schmidt [Tue, 6 Nov 2012 20:47:08 +0000 (21:47 +0100)]
Btrfs-progs: bugfix for subvolume parent determination in btrfs send

We missed to add the default subvolume, because it has no ROOT_BACKREF_ITEM.
This made get_parent always fail for direct decendants of the default
subvolume, resulting in lots of full streams where incremental streams were
requested.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
Reviewed-by: Alexander Block <ablock84@googlemail.com>
11 years agoBtrfs-progs: correcting misnamed parameter options for btrfs send
Jan Schmidt [Tue, 6 Nov 2012 20:47:07 +0000 (21:47 +0100)]
Btrfs-progs: correcting misnamed parameter options for btrfs send

Unfortunately, the command line options for btrfs send were misnamed. The
-i option should not be used to give "clone sources", we'll be using -c
instead.

Compatibily note: -i option was broken anyway, which makes it less critical
renaming it. For potential users of the old option style, we emit a fatal
warning if the -i option is used.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
11 years agobtrfs-progs: initialize data before send ioctl
Arvin Schnell [Sun, 20 Jan 2013 21:04:18 +0000 (16:04 -0500)]
btrfs-progs: initialize data before send ioctl

Likely not strictly needed but I noticed valgrind complaining about
uninitialised memory in the ioctl call.

Signed-off-by: Arvin Schnell <aschnell@suse.de>
11 years agoBtrfs-progs: check the relation of two group by real level numbers
Wang Shilong [Sun, 20 Jan 2013 21:04:16 +0000 (16:04 -0500)]
Btrfs-progs: check the relation of two group by real level numbers

Comparing qgroupid is not good way to check the relationship of two groups,
the right way is to compare the real level numbers.

Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Gene Czarcinski <gene@czarc.net>
11 years agoBtrfs-progs: clean up reduplicate parse_qgroupid() and replace atoi with strtoull
Wang Shilong [Sun, 20 Jan 2013 21:04:15 +0000 (16:04 -0500)]
Btrfs-progs: clean up reduplicate parse_qgroupid() and replace atoi with strtoull

1. parse_qgroupid() is implemented twice, clean up the reduplicate code.
2. atoi() can not detect errors, so use strtoull() instead of it.

Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Gene Czarcinski <gene@czarc.net>
11 years agoBtrfs-progs: fix arg parsing for btrfs qgroup limit commands
Wang Shilong [Sun, 20 Jan 2013 21:04:14 +0000 (16:04 -0500)]
Btrfs-progs: fix arg parsing for btrfs qgroup limit commands

We can use this command in two ways.
1. btrfs qgroup limit size qgroupid path
2. btrfs qgroup limit size path

Before applying this patch, we differentiate them by check the parsing result
of the second argument. It is not so good because it may make some mistakes,
For example:
  btrfs qgroup limit 1M 123456
  ^ It is a subvolume name.

In fact, we can differentiate them just by the number of arguments, so fix it
by this way.

Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Gene Czarcinski <gene@czarc.net>
11 years agoBtrfs-progs: correct btrfs receive usage string
Ulrik [Sun, 20 Jan 2013 21:04:08 +0000 (16:04 -0500)]
Btrfs-progs: correct btrfs receive usage string

Fix the usage string to specify the correct '-f' option for input file,
not '-i'.

Signed-off-by: Ulrik Sverdrup <ulrik.sverdrup@gmail.com>
Signed-off-by: Gene Czarcinski <gene@czarc.net>
11 years agoBtrfs-progs: fix resolving of loop devices
Nirbheek Chauhan [Sun, 20 Jan 2013 21:04:07 +0000 (16:04 -0500)]
Btrfs-progs: fix resolving of loop devices

The LOOP_GET_STATUS ioctl truncates filenames to 64 characters. We should get
the backing file for a given loop device from /sys/. This is how losetup does it
as well.

Signed-off-by: Nirbheek Chauhan <nirbheek.chauhan@collabora.co.uk>
Signed-off-by: Gene Czarcinski <gene@czarc.net>
Tested-By: Hector Oron <hector.oron@collabora.co.uk>
11 years agobtrfs-progs: Handle errors returned from open_ctree
Danny Kukawka [Mon, 21 Jan 2013 15:57:25 +0000 (16:57 +0100)]
btrfs-progs: Handle errors returned from open_ctree

Signed-off-by: Danny Kukawka <danny.kukawka@bisect.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
11 years agobtrfs-progs: add malloc check in transaction.h/btrfs_start_transaction
Wang Sheng-Hui [Thu, 16 Aug 2012 12:15:56 +0000 (20:15 +0800)]
btrfs-progs: add malloc check in transaction.h/btrfs_start_transaction

For malloc may fail, we should check it before assign
values to the struct btrfs_trans_handle *h.

Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
11 years agoBtrfs-progs: bugfix for scrubbing single devices
Arne Jansen [Tue, 29 Nov 2011 07:40:28 +0000 (08:40 +0100)]
Btrfs-progs: bugfix for scrubbing single devices

Scrub can be invoked to scrub only a single device of a (mounted) filesystem.
The code determines whether the given path is a mountpoint of a filesystem
by issueing a btrfs-specific ioctl to it. Only in case of EINVAL it assumed
it may be a device, all other errnos just caused it fail, but some devices
(correctly) return ENOTTY. This patch adds this to the error check.

Signed-off-by: Arne Jansen <sensille@gmx.net>