platform/upstream/btrfs-progs.git
12 years agoBtrfs-progs: fix several complie warning
Miao Xie [Fri, 10 Aug 2012 02:46:16 +0000 (10:46 +0800)]
Btrfs-progs: fix several complie warning

This patch fixed the following warning:
cmds-send.c:464:6: warning: ‘ret' may be used uninitialized in this function [-Wuninitialized]
crc32c.c:121:1: warning: control reaches end of non-void function [-Wreturn-type]
send-utils.c:69:11: warning: ‘comp' may be used uninitialized in this function [-Wuninitialized]
send-utils.c:126:6: warning: ‘comp' may be used uninitialized in this function [-Wuninitialized]
send-utils.c:99:22: warning: ‘entry' may be used uninitialized in this function [-Wuninitialized]
btrfs.c:261:2: warning: implicit declaration of function ‘crc32c_optimization_init' [-Wimplicit-function-declaration]
btrfs.c:105:2: warning: ‘cmd' may be used uninitialized in this function [-Wuninitialized]
restore.c:435:12: warning: ignoring return value of ‘ftruncate', declared with attribute warn_unused_result [-Wunused-result]

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
12 years agoBtrfs-progs: fix arguments check of qgroup limit
Tsutomu Itoh [Wed, 12 Sep 2012 04:30:19 +0000 (13:30 +0900)]
Btrfs-progs: fix arguments check of qgroup limit

Segmentation fault occurred in the following command.

 # btrfs qgroup limit
 Segmentation fault

So, we should check a minimum number of arguments.

Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
12 years agoBtrfs-progs: only enforce a maximum size if we specify one
Josef Bacik [Fri, 27 Jul 2012 12:37:55 +0000 (08:37 -0400)]
Btrfs-progs: only enforce a maximum size if we specify one

My patch

04609add88ef8428d725de6ef60f46a3ff0dbc8e

introduced a regression where if you mkfs'ed a group of disks with different
sizes it limited the disks to the size of the first one that is specified.
This was not the intent of my patch, I only want it to limit the size based
on the -b option, so I've reworked the code to pass in a max block count and
that fixes the issue.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
12 years agobtrfs-progs: fsck: understand the -s option
David Sterba [Tue, 17 Jul 2012 10:41:13 +0000 (12:41 +0200)]
btrfs-progs: fsck: understand the -s option

Short options have to be repeated at the getopt_long call.

Signed-off-by: David Sterba <dsterba@suse.cz>
12 years agobtrfs-progs: mkfs: create root directory with 755 permissions
David Sterba [Tue, 17 Jul 2012 10:18:10 +0000 (12:18 +0200)]
btrfs-progs: mkfs: create root directory with 755 permissions

That's what all other mkfs do and there's no reason for 0555.

Signed-off-by: David Sterba <dsterba@suse.cz>
12 years agobtrfs-progs: mkfs: rename nodiscard option to K
David Sterba [Tue, 17 Jul 2012 10:30:16 +0000 (12:30 +0200)]
btrfs-progs: mkfs: rename nodiscard option to K

The original patch named the option -T, mkfs.xfs uses -K let's keep it
same.

Signed-off-by: David Sterba <dsterba@suse.cz>
12 years agoBtrfs progs: quota groups support upstream/0.20.rc1 v0.20-rc1
Arne Jansen [Tue, 7 Aug 2012 10:37:54 +0000 (12:37 +0200)]
Btrfs progs: quota groups support

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
Signed-off-by: Arne Jansen <sensille@gmx.net>
12 years agoBtrfs-progs: replace find_mount_root from send code
Jan Schmidt [Mon, 20 Aug 2012 11:40:18 +0000 (13:40 +0200)]
Btrfs-progs: replace find_mount_root from send code

find_mount_root had the problem that it tried to conclude from a file system
path to a mount point, taking the fsid as an indicator. This only works if
no two subvolumes (sharing the same btrfs fsid) are mounted in the same
hierarchy.

Now instead, we're parsing /etc/mtab and look for the longest match.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
12 years agoAllow relative paths for btrfs send
Chris Mason [Thu, 9 Aug 2012 16:48:29 +0000 (12:48 -0400)]
Allow relative paths for btrfs send

The initial btrfs send code was easily confused by relative paths and by
anything that wasn't in the root of the FS.  This fixes it to take
relative paths.

Signed-off-by: Chris Mason <chris.mason@fusionio.com>
12 years agoUse intel hardware crc32c where available
Chris Mason [Wed, 25 Jul 2012 19:02:07 +0000 (15:02 -0400)]
Use intel hardware crc32c where available

Signed-off-by: Chris Mason <chris.mason@fusionio.com>
12 years agoSwitch to -O1 for optimizations to enable FORTIFY_SOURCE
Chris Mason [Tue, 24 Jul 2012 16:17:42 +0000 (12:17 -0400)]
Switch to -O1 for optimizations to enable FORTIFY_SOURCE

Signed-off-by: Chris Mason <chris.mason@fusionio.com>
12 years agoBtrfs-progs: add btrfs send/receive commands
Alexander Block [Wed, 25 Jul 2012 21:08:25 +0000 (23:08 +0200)]
Btrfs-progs: add btrfs send/receive commands

Add user space commands for btrfs send/receive.

Signed-off-by: Alexander Block <ablock84@googlemail.com>
Reviewed-by: David Sterba <dave@jikos.cz>
Reviewed-by: Arne Jansen <sensille@gmx.net>
Reviewed-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
Reviewed-by: Alex Lyakas <alex.bolshoy.btrfs@gmail.com>
12 years agoBtrfs-progs: update ioctl.h to support btrfs send ioctl
Alexander Block [Wed, 20 Jun 2012 16:44:04 +0000 (18:44 +0200)]
Btrfs-progs: update ioctl.h to support btrfs send ioctl

Add btrfs_ioctl_send_args and BTRFS_IOC_SEND to ioctl.h

Signed-off-by: Alexander Block <ablock84@googlemail.com>
12 years agoBtrfs-progs: update btrfs-progs for subvol uuid+times support
Alexander Block [Wed, 25 Jul 2012 16:01:24 +0000 (18:01 +0200)]
Btrfs-progs: update btrfs-progs for subvol uuid+times support

Update ctree.h and ioctl.h for the new uuid+times for subvolumes.

Signed-off-by: Alexander Block <ablock84@googlemail.com>
12 years agoBtrfs-progs: print inode transid and dir item data field in debug-tree
Alexander Block [Wed, 20 Jun 2012 16:43:23 +0000 (18:43 +0200)]
Btrfs-progs: print inode transid and dir item data field in debug-tree

Add printing of inode transid and dir item data field.

Signed-off-by: Alexander Block <ablock84@googlemail.com>
12 years agoBtrfs-progs: update ioctl.h to support clone range ioctl
Alexander Block [Wed, 20 Jun 2012 16:42:19 +0000 (18:42 +0200)]
Btrfs-progs: update ioctl.h to support clone range ioctl

Added missing btrfs_ioctl_clone_range_args and BTRFS_IOC_CLONE_RANGE
to ioctl.h

Signed-off-by: Alexander Block <ablock84@googlemail.com>
12 years agoBtrfs-progs: add BTRFS_IOC_SUBVOL_GET/SETFLAGS to ioctl.h
Alexander Block [Mon, 25 Jun 2012 23:13:31 +0000 (01:13 +0200)]
Btrfs-progs: add BTRFS_IOC_SUBVOL_GET/SETFLAGS to ioctl.h

Btrfs send/receive and btrfs props needs this ioctl. This patch
requires a recent kernel with the "Btrfs: use _IOR for
BTRFS_IOC_SUBVOL_GETFLAGS" patch applied.

Signed-off-by: Alexander Block <ablock84@googlemail.com>
12 years agobtrfs-progs: mkfs: add option to skip trim
David Sterba [Fri, 6 Jul 2012 14:11:10 +0000 (10:11 -0400)]
btrfs-progs: mkfs: add option to skip trim

Signed-off-by: Chris Mason <chris.mason@fusionio.com>
12 years agoBtrfs: fix off by one in null termination
Chris Mason [Thu, 5 Jul 2012 18:58:51 +0000 (14:58 -0400)]
Btrfs: fix off by one in null termination

A recent commit was null terminating the root listing
strings one byte too short.

Signed-off-by: Chris Mason <chris.mason@fusionio.com>
12 years agoMerge branch 'for-chris' of git://github.com/idryomov/btrfs-progs into 0.20
Chris Mason [Thu, 5 Jul 2012 15:35:42 +0000 (11:35 -0400)]
Merge branch 'for-chris' of git://github.com/idryomov/btrfs-progs into 0.20

12 years agoBtrfs-progs, btrfs-map-logical: Fix typo in usage
Miao Xie [Thu, 23 Feb 2012 07:51:09 +0000 (15:51 +0800)]
Btrfs-progs, btrfs-map-logical: Fix typo in usage

The right option is 'o' not 'c'. And this tool is used for the block devices
on which there is a btrfs file system, so change "mount_point" to "device".

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
12 years agoBtrfs-progs, btrfs-corrupt-block: fix the wrong usage
Miao Xie [Thu, 23 Feb 2012 07:52:05 +0000 (15:52 +0800)]
Btrfs-progs, btrfs-corrupt-block: fix the wrong usage

The old usage is a copy of btrfs-map-logical, it's wrong, fix it.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
12 years agoBtrfs-progs: Fix manual of btrfs command
Akira Fujita [Fri, 16 Dec 2011 08:46:48 +0000 (17:46 +0900)]
Btrfs-progs: Fix manual of btrfs command

Usage of balancing btrfs is "btrfs filesystem balance",
not "btrfs device balance". And remove unneeded
usage of "btrfs filesystem defrag".
Also fix some typos and over 80 columns.

Signed-off-by: Akira Fujita <a-fujita@rs.jp.nec.com>
12 years agobtrfs-progs: document --rootdir mkfs switch
Phillip Susi [Mon, 9 Jan 2012 15:18:56 +0000 (10:18 -0500)]
btrfs-progs: document --rootdir mkfs switch

Signed-off-by: Phillip Susi <psusi@cfl.rr.com>
12 years agobtrfs-progs: removed extraneous whitespace from mkfs man page
Phillip Susi [Mon, 9 Jan 2012 15:18:55 +0000 (10:18 -0500)]
btrfs-progs: removed extraneous whitespace from mkfs man page

There were extra spaces around some of the arguments in the man
page for mkfs.

Signed-off-by: Phillip Susi <psusi@cfl.rr.com>
12 years agoscrub_fs_info( ) file handle leaking
Goffredo Baroncelli [Tue, 5 Jun 2012 17:26:34 +0000 (19:26 +0200)]
scrub_fs_info( ) file handle leaking

The function scrub_fs_info( ) closes and reopen a file handle
passed as argument, when a caller uses the file handle even after the
call.
The function scrub_fs_info( ) is updated to remove the file handle
argument, and instead uses a private own file handle.
The callers are updated to not pass the argument.

12 years agobtrfs-progs: Update resize documentation
Shawn Bohrer [Sat, 26 May 2012 17:57:55 +0000 (12:57 -0500)]
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>
12 years agoFix "set-dafault" typo in cmds-subvolume.c
Chris Samuel [Fri, 11 May 2012 12:55:17 +0000 (22:55 +1000)]
Fix "set-dafault" typo in cmds-subvolume.c

Andrei Popa reported that there were two typos of default as dafault,
this patch fixes those two typos up.

Signed-off-by: Chris Samuel <chris@csamuel.org>
12 years agoman: fix btrfs man page formatting
Hubert Kario [Mon, 30 Apr 2012 23:54:08 +0000 (01:54 +0200)]
man: fix btrfs man page formatting

Signed-off-by: Hubert Kario <kario@wit.edu.pl>
12 years agobtrfs-progs: enforce block count on all devices in mkfs
Josef Bacik [Wed, 28 Mar 2012 18:20:52 +0000 (14:20 -0400)]
btrfs-progs: enforce block count on all devices in mkfs

I had a test that creates a 7gig raid1 device but it was ending up wonky
because the second device that gets added is the full size of the disk
instead of the limited size.  So enforce the limited size on all disks
passed in at mkfs time, otherwise our threshold calculations end up wonky
when doing chunk allocations.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
12 years agoBtrfs-progs: fix btrfsck's snapshot wrong "unresolved refs"
Miao Xie [Thu, 23 Feb 2012 07:52:58 +0000 (15:52 +0800)]
Btrfs-progs: fix btrfsck's snapshot wrong "unresolved refs"

If the fs/file tree is not the parent of the snapshot, it is reasonable
that we can not find the relative reference and back reference. But btrfsck
doesn't consider this case, and reports "unresolved refs" message, it's wrong,
fix it.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
12 years agomkfs: Handle creation of filesystem larger than the first device
Jan Kara [Fri, 10 Feb 2012 10:49:19 +0000 (11:49 +0100)]
mkfs: Handle creation of filesystem larger than the first device

On Wed 08-02-12 22:05:26, Phillip Susi wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 02/08/2012 06:20 PM, Jan Kara wrote:
> >   Thanks for your reply. I admit I was not sure what exactly size argument
> > should be. So after looking into the code for a while I figured it should
> > be a total size of the filesystem - or differently it should be size of
> > virtual block address space in the filesystem. Thus when filesystem has
> > more devices (or admin wants to add more devices later), it can be larger
> > than the first device. But I'm not really a btrfs developper so I might be
> > wrong and of course feel free to fix the issue as you deem fit.
>
> The size of the fs is the total size of the individual disks.  When you
> limit the size, you limit the size of a disk, not the whole fs.  IIRC,
> mkfs initializes the fs on the first disk, which is why it was using that
> size as the size of the whole fs, and then adds the other disks after (
> which then add their size to the total fs size ).
  OK, I missed that btrfs_add_to_fsid() increases total size of the
filesystem. So now I agree with you. New patch is attached. Thanks for your
review.

> It might be nice if
> mkfs could take sizes for each disk, but it only seems to take one size
> for the initial disk.
  Yes, but I don't see a realistic usecase so I don't think it's really
worth the work.

Honza
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR

>From e5f46872232520310c56327593c02ef6a7f5ea33 Mon Sep 17 00:00:00 2001
From: Jan Kara <jack@suse.cz>
Date: Fri, 10 Feb 2012 11:44:44 +0100
Subject: [PATCH] mkfs: Handle creation of filesystem larger than the first device

mkfs does not properly check requested size of the filesystem. Thus if the
requested size is larger than the first device, it happily creates larger
filesystem than a device it resides on which results in 'attemp to access
beyond end of device' messages from the kernel. So verify specified filesystem
size against the size of the first device.

CC: David Sterba <dsterba@suse.cz>
Signed-off-by: Jan Kara <jack@suse.cz>
12 years agoFix segmentation fault when opening invalid file system
Hubert Kario [Sun, 19 Feb 2012 20:11:46 +0000 (21:11 +0100)]
Fix segmentation fault when opening invalid file system

Signed-off-by: Hubert Kario <kario@wit.edu.pl>
12 years agoBtrfs-progs: make btrfs filesystem show <uuid> actually work
Josef Bacik [Wed, 25 Apr 2012 18:22:32 +0000 (14:22 -0400)]
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>
12 years agomkfs: avoid heap-buffer-read-underrun for zero-length "size" arg
Jim Meyering [Fri, 20 Apr 2012 19:27:26 +0000 (21:27 +0200)]
mkfs: avoid heap-buffer-read-underrun for zero-length "size" arg

* mkfs.c (parse_size): ./mkfs.btrfs -A '' would read and possibly
write the byte before beginning of strdup'd heap buffer.  All other
size-accepting options were similarly affected.

Reviewed-by: Josef Bacik <josef@redhat.com>
12 years agoavoid several strncpy-induced buffer overruns
Jim Meyering [Fri, 20 Apr 2012 19:27:25 +0000 (21:27 +0200)]
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>
12 years agorestore: don't corrupt stack for a zero-length command-line argument
Jim Meyering [Fri, 20 Apr 2012 19:27:24 +0000 (21:27 +0200)]
restore: don't corrupt stack for a zero-length command-line argument

Given a zero-length directory name, the trailing-slash removal
code would test dir_name[-1], and if it were found to be a slash,
would set it to '\0'.

Reviewed-by: Josef Bacik <josef@redhat.com>
12 years agomkfs: use strdup in place of strlen,malloc,strcpy sequence
Jim Meyering [Fri, 20 Apr 2012 19:27:23 +0000 (21:27 +0200)]
mkfs: use strdup in place of strlen,malloc,strcpy sequence

* mkfs.c (traverse_directory): No semantic change.

Reviewed-by: Josef Bacik <josef@redhat.com>
12 years agobtrfs_scan_one_dir: avoid use-after-free on error path
Jim Meyering [Wed, 11 Apr 2012 14:42:50 +0000 (16:42 +0200)]
btrfs_scan_one_dir: avoid use-after-free on error path

If we iterate the "goto again" loop, we've called "closedir(dirp)",
yet at the top of the loop, upon malloc failure we "goto fail",
where we test dirp and if non-NULL, call closedir(dirp) again.
* utils.c (btrfs_scan_one_dir): Clear "dirp" after closedir to avoid
use-after-free upon failed fullpath = malloc(...

Signed-off-by: Jim Meyering <meyering@redhat.com>
12 years agoBtrfs-progs: make btrfsck aware of free space inodes
Josef Bacik [Mon, 9 Apr 2012 19:22:13 +0000 (15:22 -0400)]
Btrfs-progs: make btrfsck aware of free space inodes

The new xfstests will run fsck against the volume to make sure we didn't
introduce any inconsistencies, which is nice except we will error out
immediately if we mount with inode_cache.  We need to make btrfsck skip the
special free space cache items and then just assume that we have a link for
the free space cache inode item.  This makes btrfsck pass with success on a
fs with inode cache items.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
12 years agoMakefile: use $(MAKE) instead of hardcoded 'make'
Sergei Trofimovich [Mon, 2 Apr 2012 13:10:02 +0000 (16:10 +0300)]
Makefile: use $(MAKE) instead of hardcoded 'make'

CC: Chris Mason <chris.mason@oracle.com>
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
12 years agoMakefile: use $(CC) as a compilers instead of $(CC)/gcc
Sergei Trofimovich [Mon, 2 Apr 2012 13:10:01 +0000 (16:10 +0300)]
Makefile: use $(CC) as a compilers instead of $(CC)/gcc

CC: Chris Mason <chris.mason@oracle.com>
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
12 years agobtrfs-progs: cleanup: remove the redundant BTRFS_CSUM_TYPE_CRC32 macro definition...
Wang Sheng-Hui [Mon, 5 Mar 2012 05:33:59 +0000 (13:33 +0800)]
btrfs-progs: cleanup: remove the redundant BTRFS_CSUM_TYPE_CRC32 macro definition in ctree.h

Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
12 years agoAdd incompat flag for big metadata blocks
Chris Mason [Wed, 28 Mar 2012 16:05:27 +0000 (12:05 -0400)]
Add incompat flag for big metadata blocks

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agomkfs: make -l and -n an alias for each other
Chris Mason [Mon, 26 Mar 2012 20:17:08 +0000 (16:17 -0400)]
mkfs: make -l and -n an alias for each other

We don't allow different leaf and node blocksizes, so
this just makes the two options mean the same thing

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs-progs: allow dup for data chunks in mixed mode
Ilya Dryomov [Tue, 13 Mar 2012 20:15:07 +0000 (22:15 +0200)]
Btrfs-progs: allow dup for data chunks in mixed mode

Before commit a46e7ff2 was merged it was possible to create dup for
data+metadata chunks (mixed mode) by giving -m raid1 -d raid1 -M to
mkfs.  a46e7ff2 purposefully disabled behind the scenes profile
upgrading/downgrading, so give users a chance to pick dup explicitly and
bail if dup for data is requested in normal mode.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs-progs: make print-tree.c aware of free space cache
Ilya Dryomov [Tue, 13 Mar 2012 16:36:56 +0000 (18:36 +0200)]
Btrfs-progs: make print-tree.c aware of free space cache

This adds proper formatting for free space and inode cache items in
btrfs-debug-tree output.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs-progs: bring 'subvol get-default' back in
Ilya Dryomov [Mon, 12 Mar 2012 17:17:39 +0000 (19:17 +0200)]
Btrfs-progs: bring 'subvol get-default' back in

Commit bab2c565 accidentally broke 'subvol get-default' command by
removing almost all of the underlying code.  Bring it back with some
fixes and improvements.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs-progs: refactor resolve_root() function a bit
Ilya Dryomov [Mon, 12 Mar 2012 17:17:39 +0000 (19:17 +0200)]
Btrfs-progs: refactor resolve_root() function a bit

Don't pass a pointer to root_id to resolve_root().  It's always the same as
ri->root_id, passing a pointer hints that root_id can somehow change which is
not true.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs-progs: nuke redundant zeroing in __list_subvol_search()
Ilya Dryomov [Mon, 12 Mar 2012 17:17:39 +0000 (19:17 +0200)]
Btrfs-progs: nuke redundant zeroing in __list_subvol_search()

There's no need to zero out things twice.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agobtrfsck: add early code to handle corrupted block groups
Chris Mason [Wed, 22 Feb 2012 02:20:54 +0000 (21:20 -0500)]
btrfsck: add early code to handle corrupted block groups

This is mostly disabled, but it is step one in handling
corrupted block groups in the extent allocation tree.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoScan /dev/md and device mapper devices last
Chris Mason [Tue, 21 Feb 2012 20:56:10 +0000 (15:56 -0500)]
Scan /dev/md and device mapper devices last

When we're using multipath or raid0, it is possible
that btrfs dev scan will find one of the component devices
instead of the proper virtual device the kernel creates.

We want to make sure the kernel scans the virtual devices last,
since it always remembers the last device it finds with a given fsid.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs: use /proc/partitions scanning for btrfs_scan_for_fsid
Chris Mason [Tue, 21 Feb 2012 20:33:20 +0000 (15:33 -0500)]
Btrfs: use /proc/partitions scanning for btrfs_scan_for_fsid

btrfs_scan_for_fsid is used by open_ctree and by mkfs when it is
checking for mounted devices.  It currently scans all of /dev,
which is rarely the right answer.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfsck: add the ability to prune corrupt extent allocation tree blocks
Chris Mason [Tue, 21 Feb 2012 19:37:21 +0000 (14:37 -0500)]
Btrfsck: add the ability to prune corrupt extent allocation tree blocks

When we discover bad blocks in the extent allocation tree, repair can
now discard them and recreate the references from the rest of the trees.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agobtrfsck: remove extents from the fsck reference tracker as they are freed
Chris Mason [Fri, 10 Feb 2012 18:28:50 +0000 (13:28 -0500)]
btrfsck: remove extents from the fsck reference tracker as they are freed

During btrfsck --repair, we make an index of extents that have incorrect
reference counts.  Once we've collect the whole index, we go through
and modify the extent allocation tree to reflect the correct results.

Changing the extent allocation tree may free blocks, and so it may
end up removing a block that had a missing reference structure.  The
fsck code may then circle back around and add the reference back.

The result is an extent that isn't actually used, but is recorded in the
extent allocation tree.

This commit adds a hook called as extents are freed.  The hook searches
the index of incorrect references and updates it to reflect the freeing
of the extent.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agobtrfsck: make sure we fix the block group accounting during repair
Chris Mason [Thu, 9 Feb 2012 16:53:33 +0000 (11:53 -0500)]
btrfsck: make sure we fix the block group accounting during repair

The block group accounting is fixed after we check the extent back
references.  This makes sure the accounting is fixed unless we
were not able to repair the backrefs.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agobtrfsck: add --init-csum-tree to replace the csum root with an empty one
Chris Mason [Thu, 9 Feb 2012 15:38:05 +0000 (10:38 -0500)]
btrfsck: add --init-csum-tree to replace the csum root with an empty one

This will effectively delete all of your crcs, but at least you'll
be able to mount the FS with nodatasum.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agobtrfsck: make sure to dirty all block groups as we fix accounting
Chris Mason [Thu, 9 Feb 2012 14:29:19 +0000 (09:29 -0500)]
btrfsck: make sure to dirty all block groups as we fix accounting

The code that corrects the count of bytes used in each block group
was only marking block groups dirty when they contained extents.  This
fixes things to dirty all the block groups, so any empty block groups
are written with their correct (zero) count.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoFix btrfs-convert, btrfs-restore and btrfs-find-root build
Chris Mason [Thu, 9 Feb 2012 03:26:26 +0000 (22:26 -0500)]
Fix btrfs-convert, btrfs-restore and btrfs-find-root build

Signed-off-by: Chris Mason <chris.mason@oracle.com>
fixit
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoTurn off some commands in Makefile
Chris Mason [Thu, 9 Feb 2012 02:38:20 +0000 (21:38 -0500)]
Turn off some commands in Makefile

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoMerge branch 'for-chris' of git://github.com/idryomov/btrfs-progs
Chris Mason [Thu, 9 Feb 2012 02:29:56 +0000 (21:29 -0500)]
Merge branch 'for-chris' of git://github.com/idryomov/btrfs-progs

12 years agobtrfsck: fix block group accounting during repair
Chris Mason [Thu, 9 Feb 2012 02:29:13 +0000 (21:29 -0500)]
btrfsck: fix block group accounting during repair

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoBtrfs-progs: allow multi-line command group synopsis
Ilya Dryomov [Wed, 8 Feb 2012 15:45:54 +0000 (17:45 +0200)]
Btrfs-progs: allow multi-line command group synopsis

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agobtrfs-corrupt-block: add -E option to randomly corrupt the extent_root
Chris Mason [Tue, 7 Feb 2012 13:36:38 +0000 (08:36 -0500)]
btrfs-corrupt-block: add -E option to randomly corrupt the extent_root

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agobtrfsck: add code to rebuild extent records
Chris Mason [Tue, 7 Feb 2012 10:13:24 +0000 (05:13 -0500)]
btrfsck: add code to rebuild extent records

This also includes a new --repair btrfsck option.  For now it can
only fix errors in the extent allocation tree.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agobtrfs-corrupt-block: add -e option to corrupt the extent record
Chris Mason [Mon, 6 Feb 2012 13:54:05 +0000 (08:54 -0500)]
btrfs-corrupt-block: add -e option to corrupt the extent record

This will zero out the extent allocation tree records for the extent.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agobtrfsck: don't BUG on corrupted extent records
Chris Mason [Mon, 6 Feb 2012 13:53:43 +0000 (08:53 -0500)]
btrfsck: don't BUG on corrupted extent records

12 years agoAllow extent_buffers to use more ram
Chris Mason [Mon, 6 Feb 2012 10:06:18 +0000 (05:06 -0500)]
Allow extent_buffers to use more ram

This changes free_some_buffers (called each time we allocate an extent
buffer) to allow a higher hard limit on the number of extent buffers
in use.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agobtrfsck: print some progress
Chris Mason [Mon, 6 Feb 2012 10:05:59 +0000 (05:05 -0500)]
btrfsck: print some progress
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoAdd open_ctree_fs_info for partial FS opens
Chris Mason [Sun, 5 Feb 2012 21:11:48 +0000 (16:11 -0500)]
Add open_ctree_fs_info for partial FS opens

fsck needs to be able to open a damaged FS, which means open_ctree needs
to be able to return a damaged FS.

This adds a new open_ctree_fs_info which can be used to open any and all
roots that are valid.  btrfs-debug-tree is changed to use it.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agoMerge branch 'restriper' of git://github.com/idryomov/btrfs-progs
Chris Mason [Sun, 5 Feb 2012 20:09:10 +0000 (15:09 -0500)]
Merge branch 'restriper' of git://github.com/idryomov/btrfs-progs

12 years agoBtrfs-progs: fall back to the v1 ioctl if the new balance ioctl fails
Chris Mason [Sun, 5 Feb 2012 15:42:02 +0000 (10:42 -0500)]
Btrfs-progs: fall back to the v1 ioctl if the new balance ioctl fails

This only falls back if the plain version of balance start is used.
Any args make us report the ioctl isn't supported.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoMerge branch 'restriper' of git://github.com/idryomov/btrfs-progs
Chris Mason [Sun, 5 Feb 2012 15:14:09 +0000 (10:14 -0500)]
Merge branch 'restriper' of git://github.com/idryomov/btrfs-progs

12 years agoMerge branch 'parser' of git://github.com/idryomov/btrfs-progs
Chris Mason [Sun, 5 Feb 2012 15:14:01 +0000 (10:14 -0500)]
Merge branch 'parser' of git://github.com/idryomov/btrfs-progs

12 years agoBtrfs-progs: add restriper commands
Ilya Dryomov [Fri, 3 Feb 2012 19:02:30 +0000 (21:02 +0200)]
Btrfs-progs: add restriper commands

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs-progs: add 'balance' command group infrastructure
Ilya Dryomov [Fri, 3 Feb 2012 19:02:30 +0000 (21:02 +0200)]
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>
12 years agoBtrfs-progs: add restriper headers
Ilya Dryomov [Fri, 3 Feb 2012 19:02:29 +0000 (21:02 +0200)]
Btrfs-progs: add restriper headers

Add restriper headers and update print-tree.c

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs-progs: switch all existing commands to a new parser
Ilya Dryomov [Fri, 3 Feb 2012 19:00:17 +0000 (21:00 +0200)]
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>
12 years agoBtrfs-progs: implement new subcommand parser
Ilya Dryomov [Fri, 3 Feb 2012 19:00:17 +0000 (21:00 +0200)]
Btrfs-progs: implement new subcommand parser

This completely replaces the existing subcommand infrastructure, which
is not flexible enough to accomodate our needs.  Instead of a global
command table we now have per-level tables and command group handlers,
which allows command-group-specific handling of options and subcommands.
The new parser exports a clear interface and gets out of the way - all
control over how matching is done is passed to commands and command
group handlers.

One side effect of this is that command implementors have to check the
number of arguments themselves - patch to fix up all existing commands
follows.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs-progs: rearrange files in the repo
Ilya Dryomov [Fri, 3 Feb 2012 19:00:17 +0000 (21:00 +0200)]
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>
12 years agoBtrfs-progs: change the way mkfs picks raid profiles
Ilya Dryomov [Mon, 12 Dec 2011 18:00:25 +0000 (20:00 +0200)]
Btrfs-progs: change the way mkfs picks raid profiles

Currently mkfs in response to

  mkfs.btrfs -d raid10 dev1 dev2

instead of telling "you can't do that" creates a SINGLE on two devices,
and only rebalance can transform it to raid0.  Generally, it never warns
users about decisions it makes and it's not at all obvious which profile
it picks when.

Fix this by checking the number of effective devices and reporting back
if the specified profile is impossible to create.  Do not create FS in
case invalid profile was given.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs-progs: fail gracefully on error from open_ctree()
Ilya Dryomov [Mon, 12 Dec 2011 18:00:25 +0000 (20:00 +0200)]
Btrfs-progs: fail gracefully on error from open_ctree()

Error checking block got moved mistakenly exposing us to a potential
segmentation fault.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
12 years agoBtrfs-progs: Relocate -lpthread in makefile
Arnd Hannemann [Thu, 1 Dec 2011 16:33:21 +0000 (11:33 -0500)]
Btrfs-progs: Relocate -lpthread in makefile

This patch fixes the following compile error when compiled with
gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3):

gcc -lpthread -g -O0 -o btrfs btrfs.o btrfs_cmds.o scrub.o \
ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o root-tree.o dir-item.o file-item.o inode-item.o inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o volumes.o utils.o btrfs-list.o btrfslabel.o  -luuid
scrub.o: In function `scrub_start':
/home/arnd/Projekte/kernel/btrfs-progs/scrub.c:1342: undefined reference to `pthread_create'
/home/arnd/Projekte/kernel/btrfs-progs/scrub.c:1360: undefined reference to `pthread_create'
/home/arnd/Projekte/kernel/btrfs-progs/scrub.c:1374: undefined reference to `pthread_join'
/home/arnd/Projekte/kernel/btrfs-progs/scrub.c:1430: undefined reference to `pthread_cancel'
/home/arnd/Projekte/kernel/btrfs-progs/scrub.c:1432: undefined reference to `pthread_join'
collect2: ld returned 1 exit status
make: *** [btrfs] Error 1

The gcc man page says: "[...] the placement of the -l option is significant." so lets include -lpthread together with the usual $(LIBS)

Signed-off-by: Arnd Hannemann <arnd@arndnet.de>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
12 years agobtrfs-progs: make sure btrfs-zero-log writes something
Chris Mason [Mon, 21 Nov 2011 15:27:17 +0000 (10:27 -0500)]
btrfs-progs: make sure btrfs-zero-log writes something

The close_ctree code does a check to see if the FS has
changed before it does any IO.  This forces the commit.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
13 years agoBtrfs: add the tree history log to btrfs-progs
Chris Mason [Sat, 5 Nov 2011 18:58:41 +0000 (14:58 -0400)]
Btrfs: add the tree history log to btrfs-progs

This also adds btrfs-debug-tree -R to print the history

Signed-off-by: Chris Mason <chris.mason@oracle.com>
13 years agoBtrfs: fix raid10 reading math
Chris Mason [Thu, 3 Nov 2011 16:17:49 +0000 (12:17 -0400)]
Btrfs: fix raid10 reading math

The btrfs-progs raid10 code has been silently reading the wrong
raid10 block forever.  We didn't notice because it was always fixed
up by the retry code.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
13 years agoBtrfs-progs: added ioctls and commands to resolve inodes and logical addrs
Jan Schmidt [Wed, 2 Nov 2011 15:42:30 +0000 (11:42 -0400)]
Btrfs-progs: added ioctls and commands to resolve inodes and logical addrs

two new commands that make use of the new path resolving functions
implemented for scrub, doing the resolving in-kernel. the result for both
commands is a list of files belonging to that inode / logical address.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
13 years agoBtrfs-progs: added resolve commands to man page
Jan Schmidt [Fri, 8 Jul 2011 10:25:11 +0000 (12:25 +0200)]
Btrfs-progs: added resolve commands to man page

Added "inspect-internal inode-resolve" and "inspect-internal
logical-resolve" to the btrfs(8) man page.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
13 years agoFix missing entries in listing of subvolumes
Li Zefan [Wed, 15 Dec 2010 03:33:33 +0000 (03:33 +0000)]
Fix missing entries in listing of subvolumes

Stephane Chazelas <stephane.chazelas@gmail.com> writes:
> I've got a btrfs FS with 84 subvolumes in it (some created with
> "btrfs sub create", some with "btrfs sub snap" of the other
> ones). There's no nesting of subvolumes at all (all direct children
> of the root subvolume).
>
> The "btrfs subvolume list" is only showing 80 subvolumes. The 4
> missing ones (1 original volume, 3 snapshots) do exist on disk and
> files in there have different st_devs from any other subvolume.
>
> I found
> http://thread.gmane.org/gmane.comp.file-systems.btrfs/8123/focus=8208
>
> which looks like the same issue, with Li Zefan saying he had a
> fix, but I couldn't find any mention that it was actually fixed.

Li Zefan <lizf@cn.fujitsu.com> replied:
> After that, I posted a patch to fix btrfs-progs, which Chris aggreed
> on:
>
> http://marc.info/?l=linux-btrfs&m=129238454714319&w=2

So this btrfs-progs patch should fix missing subvolumes in the output of
"subvolume list":

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
13 years agoBtrfs-progs: btrfs-list: split list_subvols
Chris Mason [Wed, 2 Nov 2011 15:22:09 +0000 (11:22 -0400)]
Btrfs-progs: btrfs-list: split list_subvols

split list_subvols to separate functions and allow printing only in the
containing function. lets us make use of those functions when resolving
logical addresses.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
13 years agoMerge branch 'recovery-beta' of git://git.kernel.org/pub/scm/linux/kernel/git/mason...
Chris Mason [Mon, 31 Oct 2011 18:05:03 +0000 (14:05 -0400)]
Merge branch 'recovery-beta' of git://git./linux/kernel/git/mason/btrfs-progs

13 years agobtrfs-progs: remove old debugging statement
Chris Mason [Fri, 28 Oct 2011 02:40:23 +0000 (22:40 -0400)]
btrfs-progs: remove old debugging statement

Signed-off-by: Chris Mason <chris.mason@oracle.com>
13 years agobtrfs-progs: add a utility to corrupt a single block
Chris Mason [Fri, 28 Oct 2011 02:02:19 +0000 (22:02 -0400)]
btrfs-progs: add a utility to corrupt a single block

13 years agobtrfs-debug-tree: add -r option to print only the roots
Chris Mason [Thu, 27 Oct 2011 21:42:26 +0000 (17:42 -0400)]
btrfs-debug-tree: add -r option to print only the roots
Signed-off-by: Chris Mason <chris.mason@oracle.com>
13 years agorestore: deal with holes and set i_size correctly
Chris Mason [Thu, 27 Oct 2011 20:25:12 +0000 (16:25 -0400)]
restore: deal with holes and set i_size correctly

This changes restore to set the i_size of the files it
copies out based on the size in the inode.  It also changes
it to skip over holes.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
13 years agobtrfs-progs: fixup is_mounted checks
Chris Mason [Thu, 27 Oct 2011 20:23:14 +0000 (16:23 -0400)]
btrfs-progs: fixup is_mounted checks

/proc/mounts contains device names that don't exist,
we end up erroring out because we're not able to stat
the device (that doesn't exist).

Fix this by allowing the mkfs when the target device doesn't exist.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
13 years agobtrfs-progs: add a recovery utility to pull files from damanged filesystems
Josef Bacik [Fri, 26 Aug 2011 13:51:36 +0000 (09:51 -0400)]
btrfs-progs: add a recovery utility to pull files from damanged filesystems

Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
13 years agoPrint the root generation in btrfs-debug-tree
Chris Mason [Wed, 15 Dec 2010 21:03:00 +0000 (16:03 -0500)]
Print the root generation in btrfs-debug-tree

Signed-off-by: Chris Mason <chris.mason@oracle.com>
13 years agoPrint the root generation in btrfs-debug-tree
Chris Mason [Wed, 15 Dec 2010 21:03:00 +0000 (16:03 -0500)]
Print the root generation in btrfs-debug-tree

Signed-off-by: Chris Mason <chris.mason@oracle.com>
13 years agoBtrfs-progs: make btrfs df report profiles for mixed block groups
Ilya Dryomov [Sat, 8 Oct 2011 21:09:19 +0000 (00:09 +0300)]
Btrfs-progs: make btrfs df report profiles for mixed block groups

Profiles other than SINGLE for mixed chunks might sound a bit strange,
but there is nothing in the filesystem that prevents a crazy user from
doing it.  So make "btrfs fi df" report them properly.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>