2008-03-25 02:01:56 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 Oracle. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public
|
|
|
|
* License v2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 021110-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __BTRFS_VOLUMES_
|
|
|
|
#define __BTRFS_VOLUMES_
|
2008-04-04 03:29:03 +07:00
|
|
|
|
2008-04-10 03:28:12 +07:00
|
|
|
#include <linux/bio.h>
|
2011-01-05 17:07:28 +07:00
|
|
|
#include <linux/sort.h>
|
2013-01-29 13:04:50 +07:00
|
|
|
#include <linux/btrfs.h>
|
2008-06-12 03:50:36 +07:00
|
|
|
#include "async-thread.h"
|
2008-04-10 03:28:12 +07:00
|
|
|
|
2011-01-05 17:07:28 +07:00
|
|
|
#define BTRFS_STRIPE_LEN (64 * 1024)
|
|
|
|
|
2008-04-11 03:19:33 +07:00
|
|
|
struct buffer_head;
|
2009-04-21 02:50:09 +07:00
|
|
|
struct btrfs_pending_bios {
|
|
|
|
struct bio *head;
|
|
|
|
struct bio *tail;
|
|
|
|
};
|
|
|
|
|
2008-03-25 02:01:56 +07:00
|
|
|
struct btrfs_device {
|
|
|
|
struct list_head dev_list;
|
2008-04-22 20:22:07 +07:00
|
|
|
struct list_head dev_alloc_list;
|
2008-11-18 09:11:30 +07:00
|
|
|
struct btrfs_fs_devices *fs_devices;
|
2014-07-24 10:37:10 +07:00
|
|
|
|
2008-03-25 02:01:56 +07:00
|
|
|
struct btrfs_root *dev_root;
|
2009-04-21 02:50:09 +07:00
|
|
|
|
2014-07-24 10:37:10 +07:00
|
|
|
struct rcu_string *name;
|
|
|
|
|
|
|
|
u64 generation;
|
|
|
|
|
|
|
|
spinlock_t io_lock ____cacheline_aligned;
|
|
|
|
int running_pending;
|
2009-04-21 02:50:09 +07:00
|
|
|
/* regular prio bios */
|
|
|
|
struct btrfs_pending_bios pending_bios;
|
|
|
|
/* WRITE_SYNC bios */
|
|
|
|
struct btrfs_pending_bios pending_sync_bios;
|
|
|
|
|
2014-07-24 10:37:10 +07:00
|
|
|
struct block_device *bdev;
|
|
|
|
|
|
|
|
/* the mode sent to blkdev_get */
|
|
|
|
fmode_t mode;
|
|
|
|
|
2008-11-18 09:11:30 +07:00
|
|
|
int writeable;
|
2008-05-14 00:46:40 +07:00
|
|
|
int in_fs_metadata;
|
2010-12-14 02:56:23 +07:00
|
|
|
int missing;
|
2011-08-04 21:52:27 +07:00
|
|
|
int can_discard;
|
2012-11-06 00:29:28 +07:00
|
|
|
int is_tgtdev_for_dev_replace;
|
2008-04-22 20:22:07 +07:00
|
|
|
|
2008-03-25 02:01:56 +07:00
|
|
|
/* the internal btrfs device id */
|
|
|
|
u64 devid;
|
|
|
|
|
|
|
|
/* size of the device */
|
|
|
|
u64 total_bytes;
|
|
|
|
|
2009-04-27 18:29:03 +07:00
|
|
|
/* size of the disk */
|
|
|
|
u64 disk_total_bytes;
|
|
|
|
|
2008-03-25 02:01:56 +07:00
|
|
|
/* bytes used */
|
|
|
|
u64 bytes_used;
|
|
|
|
|
|
|
|
/* optimal io alignment for this device */
|
|
|
|
u32 io_align;
|
|
|
|
|
|
|
|
/* optimal io width for this device */
|
|
|
|
u32 io_width;
|
2013-10-31 11:27:33 +07:00
|
|
|
/* type and info about this device */
|
|
|
|
u64 type;
|
2008-03-25 02:01:56 +07:00
|
|
|
|
|
|
|
/* minimal io size for this device */
|
|
|
|
u32 sector_size;
|
|
|
|
|
|
|
|
/* physical drive uuid (or lvm uuid) */
|
2008-04-16 02:41:47 +07:00
|
|
|
u8 uuid[BTRFS_UUID_SIZE];
|
2008-06-12 03:50:36 +07:00
|
|
|
|
2013-10-31 11:27:33 +07:00
|
|
|
/* for sending down flush barriers */
|
|
|
|
int nobarriers;
|
|
|
|
struct bio *flush_bio;
|
|
|
|
struct completion flush_wait;
|
|
|
|
|
2011-03-08 20:14:00 +07:00
|
|
|
/* per-device scrub information */
|
Btrfs: rename the scrub context structure
The device replace procedure makes use of the scrub code. The scrub
code is the most efficient code to read the allocated data of a disk,
i.e. it reads sequentially in order to avoid disk head movements, it
skips unallocated blocks, it uses read ahead mechanisms, and it
contains all the code to detect and repair defects.
This commit is a first preparation step to adapt the scrub code to
be shareable for the device replace procedure.
The block device will be removed from the scrub context state
structure in a later step. It used to be the source block device.
The scrub code as it is used for the device replace procedure reads
the source data from whereever it is optimal. The source device might
even be gone (disconnected, for instance due to a hardware failure).
Or the drive can be so faulty so that the device replace procedure
tries to avoid access to the faulty source drive as much as possible,
and only if all other mirrors are damaged, as a last resort, the
source disk is accessed.
The modified scrub code operates as if it would handle the source
drive and thereby generates an exact copy of the source disk on the
target disk, even if the source disk is not present at all. Therefore
the block device pointer to the source disk is removed in a later
patch, and therefore the context structure is renamed (this is the
goal of the current patch) to reflect that no source block device
scope is there anymore.
Summary:
This first preparation step consists of a textual substitution of the
term "dev" to the term "ctx" whereever the scrub context is used.
Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2012-11-02 15:58:09 +07:00
|
|
|
struct scrub_ctx *scrub_device;
|
2011-03-08 20:14:00 +07:00
|
|
|
|
2014-02-28 09:46:19 +07:00
|
|
|
struct btrfs_work work;
|
2011-04-20 17:09:16 +07:00
|
|
|
struct rcu_head rcu;
|
|
|
|
struct work_struct rcu_work;
|
2011-05-23 19:30:00 +07:00
|
|
|
|
|
|
|
/* readahead state */
|
|
|
|
spinlock_t reada_lock;
|
|
|
|
atomic_t reada_in_flight;
|
|
|
|
u64 reada_next;
|
|
|
|
struct reada_zone *reada_curr_zone;
|
|
|
|
struct radix_tree_root reada_zones;
|
|
|
|
struct radix_tree_root reada_extents;
|
2011-11-19 03:07:51 +07:00
|
|
|
|
2012-05-25 21:06:08 +07:00
|
|
|
/* disk I/O failure stats. For detailed description refer to
|
|
|
|
* enum btrfs_dev_stat_values in ioctl.h */
|
2012-05-25 21:06:10 +07:00
|
|
|
int dev_stats_valid;
|
2012-05-25 21:06:08 +07:00
|
|
|
int dev_stats_dirty; /* counters need to be written to disk */
|
|
|
|
atomic_t dev_stat_values[BTRFS_DEV_STAT_VALUES_MAX];
|
2008-03-25 02:01:56 +07:00
|
|
|
};
|
|
|
|
|
2008-03-25 02:02:07 +07:00
|
|
|
struct btrfs_fs_devices {
|
|
|
|
u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
|
|
|
|
|
2009-04-03 03:46:06 +07:00
|
|
|
/* the device with this id has the most recent copy of the super */
|
2008-03-25 02:02:07 +07:00
|
|
|
u64 latest_devid;
|
|
|
|
u64 latest_trans;
|
|
|
|
u64 num_devices;
|
2008-05-14 03:03:06 +07:00
|
|
|
u64 open_devices;
|
2008-11-18 09:11:30 +07:00
|
|
|
u64 rw_devices;
|
2010-12-14 02:56:23 +07:00
|
|
|
u64 missing_devices;
|
2008-11-18 09:11:30 +07:00
|
|
|
u64 total_rw_bytes;
|
2011-08-04 21:52:27 +07:00
|
|
|
u64 num_can_discard;
|
2012-06-22 03:03:58 +07:00
|
|
|
u64 total_devices;
|
2008-03-25 02:02:07 +07:00
|
|
|
struct block_device *latest_bdev;
|
2009-06-11 02:17:02 +07:00
|
|
|
|
|
|
|
/* all of the devices in the FS, protected by a mutex
|
|
|
|
* so we can safely walk it to write out the supers without
|
2013-10-25 18:12:02 +07:00
|
|
|
* worrying about add/remove by the multi-device code.
|
|
|
|
* Scrubbing super can kick off supers writing by holding
|
|
|
|
* this mutex lock.
|
2009-06-11 02:17:02 +07:00
|
|
|
*/
|
|
|
|
struct mutex device_list_mutex;
|
2008-03-25 02:02:07 +07:00
|
|
|
struct list_head devices;
|
2008-04-22 20:22:07 +07:00
|
|
|
|
|
|
|
/* devices not currently being allocated */
|
|
|
|
struct list_head alloc_list;
|
2008-03-25 02:02:07 +07:00
|
|
|
struct list_head list;
|
2008-11-18 09:11:30 +07:00
|
|
|
|
|
|
|
struct btrfs_fs_devices *seed;
|
|
|
|
int seeding;
|
|
|
|
|
|
|
|
int opened;
|
2009-06-10 20:51:32 +07:00
|
|
|
|
|
|
|
/* set when we find or add a device that doesn't have the
|
|
|
|
* nonrot flag set
|
|
|
|
*/
|
|
|
|
int rotating;
|
2008-03-25 02:02:07 +07:00
|
|
|
};
|
|
|
|
|
2013-07-25 18:22:34 +07:00
|
|
|
#define BTRFS_BIO_INLINE_CSUM_SIZE 64
|
|
|
|
|
2013-05-18 05:30:14 +07:00
|
|
|
/*
|
|
|
|
* we need the mirror number and stripe index to be passed around
|
|
|
|
* the call chain while we are processing end_io (especially errors).
|
|
|
|
* Really, what we need is a btrfs_bio structure that has this info
|
|
|
|
* and is properly sized with its stripe array, but we're not there
|
|
|
|
* quite yet. We have our own btrfs bioset, and all of the bios
|
|
|
|
* we allocate are actually btrfs_io_bios. We'll cram as much of
|
|
|
|
* struct btrfs_bio as we can into this over time.
|
|
|
|
*/
|
2013-07-25 18:22:34 +07:00
|
|
|
typedef void (btrfs_io_bio_end_io_t) (struct btrfs_io_bio *bio, int err);
|
2013-05-18 05:30:14 +07:00
|
|
|
struct btrfs_io_bio {
|
|
|
|
unsigned long mirror_num;
|
|
|
|
unsigned long stripe_index;
|
2013-07-25 18:22:34 +07:00
|
|
|
u8 *csum;
|
|
|
|
u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE];
|
|
|
|
u8 *csum_allocated;
|
|
|
|
btrfs_io_bio_end_io_t *end_io;
|
2013-05-18 05:30:14 +07:00
|
|
|
struct bio bio;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct btrfs_io_bio *btrfs_io_bio(struct bio *bio)
|
|
|
|
{
|
|
|
|
return container_of(bio, struct btrfs_io_bio, bio);
|
|
|
|
}
|
|
|
|
|
2008-04-10 03:28:12 +07:00
|
|
|
struct btrfs_bio_stripe {
|
|
|
|
struct btrfs_device *dev;
|
|
|
|
u64 physical;
|
2011-03-24 17:24:26 +07:00
|
|
|
u64 length; /* only used for discard mappings */
|
2008-04-10 03:28:12 +07:00
|
|
|
};
|
|
|
|
|
2011-08-04 22:15:33 +07:00
|
|
|
struct btrfs_bio;
|
|
|
|
typedef void (btrfs_bio_end_io_t) (struct btrfs_bio *bio, int err);
|
|
|
|
|
2014-06-19 09:42:54 +07:00
|
|
|
#define BTRFS_BIO_ORIG_BIO_SUBMITTED 0x1
|
|
|
|
|
2011-08-04 22:15:33 +07:00
|
|
|
struct btrfs_bio {
|
2008-04-10 03:28:12 +07:00
|
|
|
atomic_t stripes_pending;
|
Btrfs: fix use-after-free in the finishing procedure of the device replace
During device replace test, we hit a null pointer deference (It was very easy
to reproduce it by running xfstests' btrfs/011 on the devices with the virtio
scsi driver). There were two bugs that caused this problem:
- We might allocate new chunks on the replaced device after we updated
the mapping tree. And we forgot to replace the source device in those
mapping of the new chunks.
- We might get the mapping information which including the source device
before the mapping information update. And then submit the bio which was
based on that mapping information after we freed the source device.
For the first bug, we can fix it by doing mapping tree update and source
device remove in the same context of the chunk mutex. The chunk mutex is
used to protect the allocable device list, the above method can avoid
the new chunk allocation, and after we remove the source device, all
the new chunks will be allocated on the new device. So it can fix
the first bug.
For the second bug, we need make sure all flighting bios are finished and
no new bios are produced during we are removing the source device. To fix
this problem, we introduced a global @bio_counter, we not only inc/dec
@bio_counter outsize of map_blocks, but also inc it before submitting bio
and dec @bio_counter when ending bios.
Since Raid56 is a little different and device replace dosen't support raid56
yet, it is not addressed in the patch and I add comments to make sure we will
fix it in the future.
Reported-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Josef Bacik <jbacik@fb.com>
2014-01-30 15:46:55 +07:00
|
|
|
struct btrfs_fs_info *fs_info;
|
2008-04-10 03:28:12 +07:00
|
|
|
bio_end_io_t *end_io;
|
2008-08-05 21:13:57 +07:00
|
|
|
struct bio *orig_bio;
|
2014-06-19 09:42:54 +07:00
|
|
|
unsigned long flags;
|
2008-04-10 03:28:12 +07:00
|
|
|
void *private;
|
2008-04-29 20:38:00 +07:00
|
|
|
atomic_t error;
|
|
|
|
int max_errors;
|
2008-04-10 03:28:12 +07:00
|
|
|
int num_stripes;
|
2011-08-04 22:15:33 +07:00
|
|
|
int mirror_num;
|
2008-04-10 03:28:12 +07:00
|
|
|
struct btrfs_bio_stripe stripes[];
|
|
|
|
};
|
|
|
|
|
2011-01-05 17:07:28 +07:00
|
|
|
struct btrfs_device_info {
|
|
|
|
struct btrfs_device *dev;
|
|
|
|
u64 dev_offset;
|
|
|
|
u64 max_avail;
|
btrfs: quasi-round-robin for chunk allocation
In a multi device setup, the chunk allocator currently always allocates
chunks on the devices in the same order. This leads to a very uneven
distribution, especially with RAID1 or RAID10 and an uneven number of
devices.
This patch always sorts the devices before allocating, and allocates the
stripes on the devices with the most available space, as long as there
is enough space available. In a low space situation, it first tries to
maximize striping.
The patch also simplifies the allocator and reduces the checks for
corner cases.
The simplification is done by several means. First, it defines the
properties of each RAID type upfront. These properties are used afterwards
instead of differentiating cases in several places.
Second, the old allocator defined a minimum stripe size for each block
group type, tried to find a large enough chunk, and if this fails just
allocates a smaller one. This is now done in one step. The largest possible
chunk (up to max_chunk_size) is searched and allocated.
Because we now have only one pass, the allocation of the map (struct
map_lookup) is moved down to the point where the number of stripes is
already known. This way we avoid reallocation of the map.
We still avoid allocating stripes that are not a multiple of STRIPE_SIZE.
2011-04-12 17:07:57 +07:00
|
|
|
u64 total_avail;
|
2011-01-05 17:07:28 +07:00
|
|
|
};
|
|
|
|
|
2012-11-21 21:18:10 +07:00
|
|
|
struct btrfs_raid_attr {
|
|
|
|
int sub_stripes; /* sub_stripes info for map */
|
|
|
|
int dev_stripes; /* stripes per dev */
|
|
|
|
int devs_max; /* max devs to use */
|
|
|
|
int devs_min; /* min devs needed */
|
|
|
|
int devs_increment; /* ndevs has to be a multiple of this */
|
|
|
|
int ncopies; /* how many copies to data has */
|
|
|
|
};
|
|
|
|
|
Btrfs: add initial tracepoint support for btrfs
Tracepoints can provide insight into why btrfs hits bugs and be greatly
helpful for debugging, e.g
dd-7822 [000] 2121.641088: btrfs_inode_request: root = 5(FS_TREE), gen = 4, ino = 256, blocks = 8, disk_i_size = 0, last_trans = 8, logged_trans = 0
dd-7822 [000] 2121.641100: btrfs_inode_new: root = 5(FS_TREE), gen = 8, ino = 257, blocks = 0, disk_i_size = 0, last_trans = 0, logged_trans = 0
btrfs-transacti-7804 [001] 2146.935420: btrfs_cow_block: root = 2(EXTENT_TREE), refs = 2, orig_buf = 29368320 (orig_level = 0), cow_buf = 29388800 (cow_level = 0)
btrfs-transacti-7804 [001] 2146.935473: btrfs_cow_block: root = 1(ROOT_TREE), refs = 2, orig_buf = 29364224 (orig_level = 0), cow_buf = 29392896 (cow_level = 0)
btrfs-transacti-7804 [001] 2146.972221: btrfs_transaction_commit: root = 1(ROOT_TREE), gen = 8
flush-btrfs-2-7821 [001] 2155.824210: btrfs_chunk_alloc: root = 3(CHUNK_TREE), offset = 1103101952, size = 1073741824, num_stripes = 1, sub_stripes = 0, type = DATA
flush-btrfs-2-7821 [001] 2155.824241: btrfs_cow_block: root = 2(EXTENT_TREE), refs = 2, orig_buf = 29388800 (orig_level = 0), cow_buf = 29396992 (cow_level = 0)
flush-btrfs-2-7821 [001] 2155.824255: btrfs_cow_block: root = 4(DEV_TREE), refs = 2, orig_buf = 29372416 (orig_level = 0), cow_buf = 29401088 (cow_level = 0)
flush-btrfs-2-7821 [000] 2155.824329: btrfs_cow_block: root = 3(CHUNK_TREE), refs = 2, orig_buf = 20971520 (orig_level = 0), cow_buf = 20975616 (cow_level = 0)
btrfs-endio-wri-7800 [001] 2155.898019: btrfs_cow_block: root = 5(FS_TREE), refs = 2, orig_buf = 29384704 (orig_level = 0), cow_buf = 29405184 (cow_level = 0)
btrfs-endio-wri-7800 [001] 2155.898043: btrfs_cow_block: root = 7(CSUM_TREE), refs = 2, orig_buf = 29376512 (orig_level = 0), cow_buf = 29409280 (cow_level = 0)
Here is what I have added:
1) ordere_extent:
btrfs_ordered_extent_add
btrfs_ordered_extent_remove
btrfs_ordered_extent_start
btrfs_ordered_extent_put
These provide critical information to understand how ordered_extents are
updated.
2) extent_map:
btrfs_get_extent
extent_map is used in both read and write cases, and it is useful for tracking
how btrfs specific IO is running.
3) writepage:
__extent_writepage
btrfs_writepage_end_io_hook
Pages are cirtical resourses and produce a lot of corner cases during writeback,
so it is valuable to know how page is written to disk.
4) inode:
btrfs_inode_new
btrfs_inode_request
btrfs_inode_evict
These can show where and when a inode is created, when a inode is evicted.
5) sync:
btrfs_sync_file
btrfs_sync_fs
These show sync arguments.
6) transaction:
btrfs_transaction_commit
In transaction based filesystem, it will be useful to know the generation and
who does commit.
7) back reference and cow:
btrfs_delayed_tree_ref
btrfs_delayed_data_ref
btrfs_delayed_ref_head
btrfs_cow_block
Btrfs natively supports back references, these tracepoints are helpful on
understanding btrfs's COW mechanism.
8) chunk:
btrfs_chunk_alloc
btrfs_chunk_free
Chunk is a link between physical offset and logical offset, and stands for space
infomation in btrfs, and these are helpful on tracing space things.
9) reserved_extent:
btrfs_reserved_extent_alloc
btrfs_reserved_extent_free
These can show how btrfs uses its space.
Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-03-24 18:18:59 +07:00
|
|
|
struct map_lookup {
|
|
|
|
u64 type;
|
|
|
|
int io_align;
|
|
|
|
int io_width;
|
|
|
|
int stripe_len;
|
|
|
|
int sector_size;
|
|
|
|
int num_stripes;
|
|
|
|
int sub_stripes;
|
|
|
|
struct btrfs_bio_stripe stripes[];
|
|
|
|
};
|
|
|
|
|
2011-03-08 20:14:00 +07:00
|
|
|
#define map_lookup_size(n) (sizeof(struct map_lookup) + \
|
|
|
|
(sizeof(struct btrfs_bio_stripe) * (n)))
|
|
|
|
|
2012-01-17 03:04:47 +07:00
|
|
|
/*
|
|
|
|
* Restriper's general type filter
|
|
|
|
*/
|
|
|
|
#define BTRFS_BALANCE_DATA (1ULL << 0)
|
|
|
|
#define BTRFS_BALANCE_SYSTEM (1ULL << 1)
|
|
|
|
#define BTRFS_BALANCE_METADATA (1ULL << 2)
|
|
|
|
|
|
|
|
#define BTRFS_BALANCE_TYPE_MASK (BTRFS_BALANCE_DATA | \
|
|
|
|
BTRFS_BALANCE_SYSTEM | \
|
|
|
|
BTRFS_BALANCE_METADATA)
|
2012-01-17 03:04:48 +07:00
|
|
|
|
|
|
|
#define BTRFS_BALANCE_FORCE (1ULL << 3)
|
2012-01-17 03:04:48 +07:00
|
|
|
#define BTRFS_BALANCE_RESUME (1ULL << 4)
|
2012-01-17 03:04:48 +07:00
|
|
|
|
2012-01-17 03:04:47 +07:00
|
|
|
/*
|
|
|
|
* Balance filters
|
|
|
|
*/
|
|
|
|
#define BTRFS_BALANCE_ARGS_PROFILES (1ULL << 0)
|
2012-01-17 03:04:47 +07:00
|
|
|
#define BTRFS_BALANCE_ARGS_USAGE (1ULL << 1)
|
2012-01-17 03:04:47 +07:00
|
|
|
#define BTRFS_BALANCE_ARGS_DEVID (1ULL << 2)
|
2012-01-17 03:04:48 +07:00
|
|
|
#define BTRFS_BALANCE_ARGS_DRANGE (1ULL << 3)
|
2012-01-17 03:04:48 +07:00
|
|
|
#define BTRFS_BALANCE_ARGS_VRANGE (1ULL << 4)
|
2014-05-07 22:37:51 +07:00
|
|
|
#define BTRFS_BALANCE_ARGS_LIMIT (1ULL << 5)
|
2012-01-17 03:04:47 +07:00
|
|
|
|
2012-01-17 03:04:48 +07:00
|
|
|
/*
|
|
|
|
* Profile changing flags. When SOFT is set we won't relocate chunk if
|
|
|
|
* it already has the target profile (even though it may be
|
|
|
|
* half-filled).
|
|
|
|
*/
|
2012-01-17 03:04:48 +07:00
|
|
|
#define BTRFS_BALANCE_ARGS_CONVERT (1ULL << 8)
|
2012-01-17 03:04:48 +07:00
|
|
|
#define BTRFS_BALANCE_ARGS_SOFT (1ULL << 9)
|
2012-01-17 03:04:48 +07:00
|
|
|
|
2012-01-17 03:04:47 +07:00
|
|
|
struct btrfs_balance_args;
|
2012-01-17 03:04:49 +07:00
|
|
|
struct btrfs_balance_progress;
|
2012-01-17 03:04:47 +07:00
|
|
|
struct btrfs_balance_control {
|
|
|
|
struct btrfs_fs_info *fs_info;
|
|
|
|
|
|
|
|
struct btrfs_balance_args data;
|
|
|
|
struct btrfs_balance_args meta;
|
|
|
|
struct btrfs_balance_args sys;
|
|
|
|
|
|
|
|
u64 flags;
|
2012-01-17 03:04:49 +07:00
|
|
|
|
|
|
|
struct btrfs_balance_progress stat;
|
2012-01-17 03:04:47 +07:00
|
|
|
};
|
|
|
|
|
btrfs: fix wrong free space information of btrfs
When we store data by raid profile in btrfs with two or more different size
disks, df command shows there is some free space in the filesystem, but the
user can not write any data in fact, df command shows the wrong free space
information of btrfs.
# mkfs.btrfs -d raid1 /dev/sda9 /dev/sda10
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 28.00KB
devid 1 size 5.01GB used 2.03GB path /dev/sda9
devid 2 size 10.00GB used 2.01GB path /dev/sda10
# btrfs device scan /dev/sda9 /dev/sda10
# mount /dev/sda9 /mnt
# dd if=/dev/zero of=tmpfile0 bs=4K count=9999999999
(fill the filesystem)
# sync
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 5.4G 62% /mnt
# btrfs-show
Label: none uuid: a95cd49e-6e33-45b8-8741-a36153ce4b64
Total devices 2 FS bytes used 3.99GB
devid 1 size 5.01GB used 5.01GB path /dev/sda9
devid 2 size 10.00GB used 4.99GB path /dev/sda10
It is because btrfs cannot allocate chunks when one of the pairing disks has
no space, the free space on the other disks can not be used for ever, and should
be subtracted from the total space, but btrfs doesn't subtract this space from
the total. It is strange to the user.
This patch fixes it by calcing the free space that can be used to allocate
chunks.
Implementation:
1. get all the devices free space, and align them by stripe length.
2. sort the devices by the free space.
3. check the free space of the devices,
3.1. if it is not zero, and then check the number of the devices that has
more free space than this device,
if the number of the devices is beyond the min stripe number, the free
space can be used, and add into total free space.
if the number of the devices is below the min stripe number, we can not
use the free space, the check ends.
3.2. if the free space is zero, check the next devices, goto 3.1
This implementation is just likely fake chunk allocation.
After appling this patch, df can show correct space information:
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda9 btrfs 17G 8.6G 0 100% /mnt
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2011-01-05 17:07:31 +07:00
|
|
|
int btrfs_account_dev_extents_size(struct btrfs_device *device, u64 start,
|
|
|
|
u64 end, u64 *length);
|
|
|
|
|
2011-08-04 22:15:33 +07:00
|
|
|
#define btrfs_bio_size(n) (sizeof(struct btrfs_bio) + \
|
2008-04-10 03:28:12 +07:00
|
|
|
(sizeof(struct btrfs_bio_stripe) * (n)))
|
|
|
|
|
2012-11-05 21:46:42 +07:00
|
|
|
int btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
|
2008-04-10 03:28:12 +07:00
|
|
|
u64 logical, u64 *length,
|
2011-08-04 22:15:33 +07:00
|
|
|
struct btrfs_bio **bbio_ret, int mirror_num);
|
2008-12-09 04:46:26 +07:00
|
|
|
int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree,
|
|
|
|
u64 chunk_start, u64 physical, u64 devid,
|
|
|
|
u64 **logical, int *naddrs, int *stripe_len);
|
2008-12-12 22:03:26 +07:00
|
|
|
int btrfs_read_sys_array(struct btrfs_root *root);
|
2008-03-25 02:01:56 +07:00
|
|
|
int btrfs_read_chunk_tree(struct btrfs_root *root);
|
|
|
|
int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
|
2008-11-18 09:11:30 +07:00
|
|
|
struct btrfs_root *extent_root, u64 type);
|
2008-03-25 02:01:56 +07:00
|
|
|
void btrfs_mapping_init(struct btrfs_mapping_tree *tree);
|
|
|
|
void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree);
|
2008-04-10 03:28:12 +07:00
|
|
|
int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
|
2008-06-12 03:50:36 +07:00
|
|
|
int mirror_num, int async_submit);
|
2008-03-25 02:02:07 +07:00
|
|
|
int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
|
2008-12-02 18:36:09 +07:00
|
|
|
fmode_t flags, void *holder);
|
|
|
|
int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
|
2008-03-25 02:02:07 +07:00
|
|
|
struct btrfs_fs_devices **fs_devices_ret);
|
|
|
|
int btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
|
2012-11-06 19:15:27 +07:00
|
|
|
void btrfs_close_extra_devices(struct btrfs_fs_info *fs_info,
|
|
|
|
struct btrfs_fs_devices *fs_devices, int step);
|
2012-11-05 20:42:30 +07:00
|
|
|
int btrfs_find_device_missing_or_by_path(struct btrfs_root *root,
|
|
|
|
char *device_path,
|
|
|
|
struct btrfs_device **device);
|
2013-08-23 17:20:17 +07:00
|
|
|
struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info,
|
|
|
|
const u64 *devid,
|
|
|
|
const u8 *uuid);
|
2008-05-07 22:43:44 +07:00
|
|
|
int btrfs_rm_device(struct btrfs_root *root, char *device_path);
|
2012-03-01 20:56:26 +07:00
|
|
|
void btrfs_cleanup_fs_uuids(void);
|
2012-11-05 20:59:07 +07:00
|
|
|
int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len);
|
2008-04-26 03:53:30 +07:00
|
|
|
int btrfs_grow_device(struct btrfs_trans_handle *trans,
|
|
|
|
struct btrfs_device *device, u64 new_size);
|
2012-11-05 23:03:39 +07:00
|
|
|
struct btrfs_device *btrfs_find_device(struct btrfs_fs_info *fs_info, u64 devid,
|
2008-11-18 09:11:30 +07:00
|
|
|
u8 *uuid, u8 *fsid);
|
2008-04-26 03:53:30 +07:00
|
|
|
int btrfs_shrink_device(struct btrfs_device *device, u64 new_size);
|
2008-04-29 02:29:42 +07:00
|
|
|
int btrfs_init_new_device(struct btrfs_root *root, char *path);
|
2012-11-05 23:33:06 +07:00
|
|
|
int btrfs_init_dev_replace_tgtdev(struct btrfs_root *root, char *device_path,
|
|
|
|
struct btrfs_device **device_out);
|
2012-01-17 03:04:47 +07:00
|
|
|
int btrfs_balance(struct btrfs_balance_control *bctl,
|
|
|
|
struct btrfs_ioctl_balance_args *bargs);
|
2012-06-23 01:24:13 +07:00
|
|
|
int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info);
|
2012-06-23 01:24:12 +07:00
|
|
|
int btrfs_recover_balance(struct btrfs_fs_info *fs_info);
|
2012-01-17 03:04:49 +07:00
|
|
|
int btrfs_pause_balance(struct btrfs_fs_info *fs_info);
|
2012-01-17 03:04:49 +07:00
|
|
|
int btrfs_cancel_balance(struct btrfs_fs_info *fs_info);
|
2013-08-15 22:11:19 +07:00
|
|
|
int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info);
|
2013-08-15 22:11:23 +07:00
|
|
|
int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info);
|
2008-11-18 09:11:30 +07:00
|
|
|
int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset);
|
2013-06-28 00:22:46 +07:00
|
|
|
int find_free_dev_extent(struct btrfs_trans_handle *trans,
|
|
|
|
struct btrfs_device *device, u64 num_bytes,
|
Btrfs: make balance code choose more wisely when relocating
Currently, we can panic the box if the first block group we go to move is of a
type where there is no space left to move those extents. For example, if we
fill the disk up with data, and then we try to balance and we have no room to
move the data nor room to allocate new chunks, we will panic. Change this by
checking to see if we have room to move this chunk around, and if not, return
-ENOSPC and move on to the next chunk. This will make sure we remove block
groups that are moveable, like if we have alot of empty metadata block groups,
and then that way we make room to be able to balance our data chunks as well.
Tested this with an fs that would panic on btrfs-vol -b normally, but no longer
panics with this patch.
V1->V2:
-actually search for a free extent on the device to make sure we can allocate a
chunk if need be.
-fix btrfs_shrink_device to make sure we actually try to relocate all the
chunks, and then if we can't return -ENOSPC so if we are doing a btrfs-vol -r
we don't remove the device with data still on it.
-check to make sure the block group we are going to relocate isn't the last one
in that particular space
-fix a bug in btrfs_shrink_device where we would change the device's size and
not fix it if we fail to do our relocate
Signed-off-by: Josef Bacik <jbacik@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-09-12 03:11:19 +07:00
|
|
|
u64 *start, u64 *max_avail);
|
2012-05-25 21:06:08 +07:00
|
|
|
void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index);
|
2012-05-25 21:06:09 +07:00
|
|
|
int btrfs_get_dev_stats(struct btrfs_root *root,
|
2012-06-22 19:30:39 +07:00
|
|
|
struct btrfs_ioctl_get_dev_stats *stats);
|
2013-05-15 14:48:19 +07:00
|
|
|
void btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
|
2012-05-25 21:06:10 +07:00
|
|
|
int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info);
|
|
|
|
int btrfs_run_dev_stats(struct btrfs_trans_handle *trans,
|
|
|
|
struct btrfs_fs_info *fs_info);
|
2012-11-05 23:33:06 +07:00
|
|
|
void btrfs_rm_dev_replace_srcdev(struct btrfs_fs_info *fs_info,
|
|
|
|
struct btrfs_device *srcdev);
|
|
|
|
void btrfs_destroy_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
|
|
|
|
struct btrfs_device *tgtdev);
|
|
|
|
void btrfs_init_dev_replace_tgtdev_for_resume(struct btrfs_fs_info *fs_info,
|
|
|
|
struct btrfs_device *tgtdev);
|
2012-11-05 21:50:14 +07:00
|
|
|
int btrfs_scratch_superblock(struct btrfs_device *device);
|
2013-01-30 06:40:14 +07:00
|
|
|
int btrfs_is_parity_mirror(struct btrfs_mapping_tree *map_tree,
|
|
|
|
u64 logical, u64 len, int mirror_num);
|
|
|
|
unsigned long btrfs_full_stripe_len(struct btrfs_root *root,
|
|
|
|
struct btrfs_mapping_tree *map_tree,
|
|
|
|
u64 logical);
|
2013-06-28 00:22:46 +07:00
|
|
|
int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans,
|
|
|
|
struct btrfs_root *extent_root,
|
|
|
|
u64 chunk_offset, u64 chunk_size);
|
2012-05-25 21:06:08 +07:00
|
|
|
static inline void btrfs_dev_stat_inc(struct btrfs_device *dev,
|
|
|
|
int index)
|
|
|
|
{
|
|
|
|
atomic_inc(dev->dev_stat_values + index);
|
|
|
|
dev->dev_stats_dirty = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int btrfs_dev_stat_read(struct btrfs_device *dev,
|
|
|
|
int index)
|
|
|
|
{
|
|
|
|
return atomic_read(dev->dev_stat_values + index);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int btrfs_dev_stat_read_and_reset(struct btrfs_device *dev,
|
|
|
|
int index)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = atomic_xchg(dev->dev_stat_values + index, 0);
|
|
|
|
dev->dev_stats_dirty = 1;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void btrfs_dev_stat_set(struct btrfs_device *dev,
|
|
|
|
int index, unsigned long val)
|
|
|
|
{
|
|
|
|
atomic_set(dev->dev_stat_values + index, val);
|
|
|
|
dev->dev_stats_dirty = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void btrfs_dev_stat_reset(struct btrfs_device *dev,
|
|
|
|
int index)
|
|
|
|
{
|
|
|
|
btrfs_dev_stat_set(dev, index, 0);
|
|
|
|
}
|
2008-03-25 02:01:56 +07:00
|
|
|
#endif
|