Commit Graph

485 Commits (cfdd42686c7534cd54270aa382f8a28c61bf2c70)
 

Author SHA1 Message Date
Miao Xie cfdd42686c 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>
2012-07-03 16:27:46 -04:00
Jan Kara 1ee733a9ca 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>
2012-07-03 16:27:46 -04:00
Hubert Kario ff2b80b460 Fix segmentation fault when opening invalid file system
Signed-off-by: Hubert Kario <kario@wit.edu.pl>
2012-07-03 16:27:46 -04:00
Josef Bacik 3f388b9690 Btrfs-progs: make btrfs filesystem show <uuid> actually work
The btrfs filesystem show command is only actually searching for labels,
it's not searching for UUID's at all.  This patch fixes that problem.
Thanks,

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

Reviewed-by: Josef Bacik <josef@redhat.com>
2012-06-05 19:56:20 +01:00
Jim Meyering 47f029cc8b 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>
2012-06-05 19:56:20 +01:00
Jim Meyering 6fc24e4a70 mkfs: use strdup in place of strlen,malloc,strcpy sequence
* mkfs.c (traverse_directory): No semantic change.

Reviewed-by: Josef Bacik <josef@redhat.com>
2012-06-05 19:56:20 +01:00
Jim Meyering 0195702a09 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>
2012-06-05 19:56:20 +01:00
Josef Bacik eda76e4629 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>
2012-06-05 19:56:19 +01:00
Sergei Trofimovich 996722194f Makefile: use $(MAKE) instead of hardcoded 'make'
CC: Chris Mason <chris.mason@oracle.com>
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
2012-06-05 19:56:19 +01:00
Sergei Trofimovich b0a408ac63 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>
2012-06-05 19:56:19 +01:00
Wang Sheng-Hui f9ffe57844 btrfs-progs: cleanup: remove the redundant BTRFS_CSUM_TYPE_CRC32 macro definition in ctree.h
Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
2012-06-05 13:35:58 +01:00
Chris Mason 1957076ab4 Add incompat flag for big metadata blocks
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2012-03-28 12:05:27 -04:00
Chris Mason 19cf368342 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>
2012-03-26 16:17:08 -04:00
Chris Mason e22827e9bb 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>
2012-02-22 10:59:55 -05:00
Chris Mason 8f01235dd8 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>
2012-02-22 10:59:55 -05:00
Chris Mason 32eff71182 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>
2012-02-21 15:35:13 -05:00
Chris Mason af00db292e 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>
2012-02-21 14:37:21 -05:00
Chris Mason 62b7993154 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>
2012-02-10 13:28:50 -05:00
Chris Mason ae1822f73f 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>
2012-02-09 11:53:33 -05:00
Chris Mason 47b104b7f1 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>
2012-02-09 10:38:05 -05:00
Chris Mason 0bc5e18aac 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>
2012-02-09 09:29:19 -05:00
Chris Mason d01fcebeb5 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>
2012-02-08 23:11:49 -05:00
Chris Mason 3e5b13bfb5 Turn off some commands in Makefile
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2012-02-08 21:38:20 -05:00
Chris Mason f01d6a8cc8 Merge branch 'for-chris' of git://github.com/idryomov/btrfs-progs 2012-02-08 21:29:56 -05:00
Chris Mason 5fd54bc94b btrfsck: fix block group accounting during repair
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2012-02-08 21:29:13 -05:00
Ilya Dryomov 08b51bd731 Btrfs-progs: allow multi-line command group synopsis
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
2012-02-08 18:55:51 +02:00
Chris Mason 08e2cb625e btrfs-corrupt-block: add -E option to randomly corrupt the extent_root
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2012-02-07 11:34:15 -05:00
Chris Mason f5c4c4f3b7 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>
2012-02-07 10:58:32 -05:00
Chris Mason 34c0fea109 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>
2012-02-07 06:06:21 -05:00
Chris Mason 712c23e38e btrfsck: don't BUG on corrupted extent records 2012-02-06 08:53:43 -05:00
Chris Mason b7ad5a8456 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>
2012-02-06 05:08:06 -05:00
Chris Mason 6a4903c8ad btrfsck: print some progress
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2012-02-06 05:05:59 -05:00
Chris Mason e7580bb296 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>
2012-02-05 16:11:48 -05:00
Chris Mason 6cd813b6fc Merge branch 'restriper' of git://github.com/idryomov/btrfs-progs 2012-02-05 15:09:10 -05:00
Chris Mason f476657500 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>
2012-02-05 21:30:14 +02:00
Chris Mason e89c970f59 Merge branch 'restriper' of git://github.com/idryomov/btrfs-progs 2012-02-05 10:14:09 -05:00
Chris Mason 8358341fdc Merge branch 'parser' of git://github.com/idryomov/btrfs-progs 2012-02-05 10:14:01 -05:00
Ilya Dryomov 6ffdac5e77 Btrfs-progs: add restriper commands
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
2012-02-03 21:02:30 +02:00
Ilya Dryomov 888b7005ca Btrfs-progs: add 'balance' command group infrastructure
Add balance command group under both 'btrfs' and 'btrfs filesystem'.
Preserve the old 'btrfs filesystem balance <path>' behaviour.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
2012-02-03 21:02:30 +02:00
Ilya Dryomov 4f3a15d09a Btrfs-progs: add restriper headers
Add restriper headers and update print-tree.c

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

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

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
2012-02-03 21:00:17 +02:00
Ilya Dryomov a46e7ff22e 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>
2011-12-12 20:00:25 +02:00
Ilya Dryomov d5734e8837 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>
2011-12-12 20:00:25 +02:00
Arnd Hannemann fdb6c04023 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>
2011-12-01 11:33:21 -05:00
Chris Mason 6da41f2a74 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>
2011-11-21 10:27:17 -05:00
Chris Mason 13eced9a0c 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>
2011-11-05 14:58:41 -04:00