Commit Graph

662 Commits (065fa46f5de017d6a01263623442b31f44e41cd2)
 

Author SHA1 Message Date
Zach Brown 065fa46f5d 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>
2013-02-05 16:09:40 -08:00
Zach Brown bf4196b408 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>
2013-02-05 16:09:40 -08:00
Zach Brown ceb538f178 btrfs-progs: close ioctl fd in find new
Signed-off-by: Zach Brown <zab@redhat.com>
2013-02-05 16:09:40 -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
Zach Brown 4e381d4169 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>
2013-02-05 16:09:40 -08:00
Zach Brown 7b3f63be2c btrfs-progs: close fd in qgroup show
It wasn't closed in the error path.

Signed-off-by: Zach Brown <zab@redhat.com>
2013-02-05 16:09:40 -08:00
Zach Brown 6ea327567f 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>
2013-02-05 16:09:40 -08:00
Zach Brown e37d9aa8e1 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>
2013-02-05 16:09:40 -08:00
Zach Brown f4dc05bf76 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>
2013-02-05 16:09:40 -08:00
Zach Brown cb4c601a4e 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>
2013-02-05 16:09:40 -08:00
Zach Brown 09fac3824d 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>
2013-02-05 16:09:40 -08:00
Zach Brown de763395fb 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>
2013-02-05 16:09:39 -08:00
Zach Brown 506fb87fe4 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>
2013-02-05 16:09:39 -08:00
Zach Brown aaf682ac2e 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>
2013-02-05 16:09:39 -08:00
Zach Brown 7d365c5a87 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>
2013-02-05 16:09:39 -08:00
Zach Brown fd732dd81a 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>
2013-02-05 16:09:39 -08:00
Zach Brown 7c9f323a7c 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>
2013-02-05 16:09:39 -08:00
Zach Brown 201238df26 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>
2013-02-05 16:09:39 -08:00
Zach Brown 31802d9e75 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>
2013-02-05 16:09:39 -08:00
Zach Brown ac59571f59 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>
2013-02-05 16:09:39 -08:00
Zach Brown da3a185f44 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>
2013-02-05 16:09:39 -08:00
Zach Brown 4b76e34093 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>
2013-02-05 16:09:39 -08:00
Zach Brown 5fc2413e64 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>
2013-02-05 16:09:39 -08:00
Zach Brown ba4791fde3 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>
2013-02-05 16:09:38 -08:00
Zach Brown d86394da23 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>
2013-02-05 16:09:38 -08:00
Zach Brown 9e4ad99099 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>
2013-02-05 16:09:38 -08:00
Zach Brown 968efc6f98 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.
2013-02-05 16:09:38 -08:00
Zach Brown ea0ac9416f 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>
2013-02-05 16:09:38 -08:00
Zach Brown 52162700bb 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>
2013-02-05 16:09:32 -08:00
Josef Bacik 2161e1b6f3 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>
2013-02-01 17:56:42 +01:00
Anand Jain aebc64f01e 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>
2013-02-01 17:42:14 +01:00
Dieter Ries 629dfb8fa8 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>
2013-02-01 17:38:35 +01:00
David Sterba 641e688375 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>
2013-02-01 17:37:29 +01:00
David Sterba 58cc1ef8df btrfs-progs: add option c to show ogeneration
This will also pair the 'C' filter.

Signed-off-by: David Sterba <dsterba@suse.cz>
2013-02-01 17:19:49 +01:00
David Sterba f7fef0d242 btrfs-progs: add option g to show generation
Add 'g' to pair the 'G' filter.

Signed-off-by: David Sterba <dsterba@suse.cz>
2013-02-01 17:08:57 +01:00
David Sterba bd82f40c73 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>
2013-02-01 17:02:27 +01:00
Anand Jain d9a085ba83 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>
2013-02-01 16:55:06 +01:00
Anand Jain 28909327c3 Btrfs-progs: Fix a small memory leak in managing the btrfs list filter
Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-02-01 16:55:06 +01:00
Anand Jain 11825e7a29 Btrfs-progs: update btrfs_get_subvol to be inline with resolve_root ret changes
Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-02-01 16:55:06 +01:00
Wang Shilong 64edc851da 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>
2013-02-01 16:55:06 +01:00
Anand Jain 437eea9664 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>
2013-02-01 16:55:06 +01:00
Anand Jain 16ef0a0c3c 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>
2013-02-01 16:55:05 +01:00
Anand Jain e260954a9e 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>
2013-02-01 16:55:05 +01:00
Anand Jain 64f9c40759 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>
2013-02-01 16:55:05 +01:00
Anand Jain d985294b02 Btrfs-progs: add method to filter snapshots by parent uuid
Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-02-01 16:55:05 +01:00
Anand Jain 2d2c9cef4b 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>
2013-02-01 16:55:05 +01:00
Anand Jain 1999aae995 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>
2013-02-01 16:55:04 +01:00
Anand Jain 89c899ed47 Btrfs-progs: add parent uuid for snapshots
Signed-off-by: Anand Jain <anand.jain@oracle.com>
2013-02-01 16:55:04 +01:00
Anand Jain 93b3fd3879 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>
2013-02-01 16:55:04 +01:00
Lukas Czerner 8c2b1be428 Btrfs-progs: List all subvolumes by default
Commit a1e89891eb 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
a1e89891eb 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>
2013-02-01 16:55:03 +01:00