2018-04-04 01:16:55 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2008-03-25 03:01:56 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 Oracle. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2018-04-04 01:16:55 +08:00
|
|
|
#ifndef BTRFS_VOLUMES_H
|
|
|
|
#define BTRFS_VOLUMES_H
|
2008-04-04 04:29:03 +08:00
|
|
|
|
2008-04-10 04:28:12 +08:00
|
|
|
#include <linux/bio.h>
|
2011-01-05 18:07:28 +08:00
|
|
|
#include <linux/sort.h>
|
2013-01-29 14:04:50 +08:00
|
|
|
#include <linux/btrfs.h>
|
2008-06-12 04:50:36 +08:00
|
|
|
#include "async-thread.h"
|
2008-04-10 04:28:12 +08:00
|
|
|
|
2018-07-03 17:10:05 +08:00
|
|
|
#define BTRFS_MAX_DATA_CHUNK_SIZE (10ULL * SZ_1G)
|
|
|
|
|
2014-09-03 21:35:43 +08:00
|
|
|
extern struct mutex uuid_mutex;
|
|
|
|
|
2015-12-15 00:42:10 +08:00
|
|
|
#define BTRFS_STRIPE_LEN SZ_64K
|
2011-01-05 18:07:28 +08:00
|
|
|
|
2008-04-11 04:19:33 +08:00
|
|
|
struct buffer_head;
|
2009-04-21 03:50:09 +08:00
|
|
|
struct btrfs_pending_bios {
|
|
|
|
struct bio *head;
|
|
|
|
struct bio *tail;
|
|
|
|
};
|
|
|
|
|
2019-06-03 17:05:03 +08:00
|
|
|
struct btrfs_io_geometry {
|
|
|
|
/* remaining bytes before crossing a stripe */
|
|
|
|
u64 len;
|
|
|
|
/* offset of logical address in chunk */
|
|
|
|
u64 offset;
|
|
|
|
/* length of single IO stripe */
|
|
|
|
u64 stripe_len;
|
|
|
|
/* number of stripe where address falls */
|
|
|
|
u64 stripe_nr;
|
|
|
|
/* offset of address in stripe */
|
|
|
|
u64 stripe_offset;
|
|
|
|
/* offset of raid56 stripe into the chunk */
|
|
|
|
u64 raid56_stripe_offset;
|
|
|
|
};
|
|
|
|
|
2014-09-03 21:35:38 +08:00
|
|
|
/*
|
|
|
|
* Use sequence counter to get consistent device stat data on
|
|
|
|
* 32-bit processors.
|
|
|
|
*/
|
|
|
|
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
|
|
|
|
#include <linux/seqlock.h>
|
|
|
|
#define __BTRFS_NEED_DEVICE_DATA_ORDERED
|
|
|
|
#define btrfs_device_data_ordered_init(device) \
|
|
|
|
seqcount_init(&device->data_seqcount)
|
|
|
|
#else
|
|
|
|
#define btrfs_device_data_ordered_init(device) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
2017-12-04 12:54:52 +08:00
|
|
|
#define BTRFS_DEV_STATE_WRITEABLE (0)
|
2017-12-04 12:54:53 +08:00
|
|
|
#define BTRFS_DEV_STATE_IN_FS_METADATA (1)
|
2017-12-04 12:54:54 +08:00
|
|
|
#define BTRFS_DEV_STATE_MISSING (2)
|
2017-12-04 12:54:55 +08:00
|
|
|
#define BTRFS_DEV_STATE_REPLACE_TGT (3)
|
2017-12-04 12:54:56 +08:00
|
|
|
#define BTRFS_DEV_STATE_FLUSH_SENT (4)
|
2024-06-11 20:26:44 +08:00
|
|
|
#define BTRFS_DEV_STATE_NO_READA (5)
|
2017-12-04 12:54:52 +08:00
|
|
|
|
2008-03-25 03:01:56 +08:00
|
|
|
struct btrfs_device {
|
2019-05-09 23:11:11 +08:00
|
|
|
struct list_head dev_list; /* device_list_mutex */
|
|
|
|
struct list_head dev_alloc_list; /* chunk mutex */
|
2019-03-25 20:31:22 +08:00
|
|
|
struct list_head post_commit_list; /* chunk mutex */
|
2008-11-18 10:11:30 +08:00
|
|
|
struct btrfs_fs_devices *fs_devices;
|
2016-06-23 06:54:56 +08:00
|
|
|
struct btrfs_fs_info *fs_info;
|
2009-04-21 03:50:09 +08:00
|
|
|
|
2014-07-24 11:37:10 +08:00
|
|
|
struct rcu_string *name;
|
|
|
|
|
|
|
|
u64 generation;
|
|
|
|
|
|
|
|
spinlock_t io_lock ____cacheline_aligned;
|
|
|
|
int running_pending;
|
2009-04-21 03:50:09 +08:00
|
|
|
/* regular prio bios */
|
|
|
|
struct btrfs_pending_bios pending_bios;
|
2016-11-01 21:40:10 +08:00
|
|
|
/* sync bios */
|
2009-04-21 03:50:09 +08:00
|
|
|
struct btrfs_pending_bios pending_sync_bios;
|
|
|
|
|
2014-07-24 11:37:10 +08:00
|
|
|
struct block_device *bdev;
|
|
|
|
|
|
|
|
/* the mode sent to blkdev_get */
|
|
|
|
fmode_t mode;
|
|
|
|
|
2017-12-04 12:54:52 +08:00
|
|
|
unsigned long dev_state;
|
2017-08-23 14:45:59 +08:00
|
|
|
blk_status_t last_flush_error;
|
2008-04-22 21:22:07 +08:00
|
|
|
|
2014-09-03 21:35:38 +08:00
|
|
|
#ifdef __BTRFS_NEED_DEVICE_DATA_ORDERED
|
|
|
|
seqcount_t data_seqcount;
|
|
|
|
#endif
|
|
|
|
|
2008-03-25 03:01:56 +08:00
|
|
|
/* the internal btrfs device id */
|
|
|
|
u64 devid;
|
|
|
|
|
2014-07-24 11:37:12 +08:00
|
|
|
/* size of the device in memory */
|
2008-03-25 03:01:56 +08:00
|
|
|
u64 total_bytes;
|
|
|
|
|
2014-07-24 11:37:12 +08:00
|
|
|
/* size of the device on disk */
|
2009-04-27 19:29:03 +08:00
|
|
|
u64 disk_total_bytes;
|
|
|
|
|
2008-03-25 03:01:56 +08: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 12:27:33 +08:00
|
|
|
/* type and info about this device */
|
|
|
|
u64 type;
|
2008-03-25 03:01:56 +08:00
|
|
|
|
|
|
|
/* minimal io size for this device */
|
|
|
|
u32 sector_size;
|
|
|
|
|
|
|
|
/* physical drive uuid (or lvm uuid) */
|
2008-04-16 03:41:47 +08:00
|
|
|
u8 uuid[BTRFS_UUID_SIZE];
|
2008-06-12 04:50:36 +08:00
|
|
|
|
2014-09-03 21:35:33 +08:00
|
|
|
/*
|
|
|
|
* size of the device on the current transaction
|
|
|
|
*
|
|
|
|
* This variant is update when committing the transaction,
|
2019-03-25 20:31:22 +08:00
|
|
|
* and protected by chunk mutex
|
2014-09-03 21:35:33 +08:00
|
|
|
*/
|
|
|
|
u64 commit_total_bytes;
|
|
|
|
|
2014-09-03 21:35:34 +08:00
|
|
|
/* bytes used on the current transaction */
|
|
|
|
u64 commit_bytes_used;
|
2014-09-03 21:35:33 +08:00
|
|
|
|
2013-10-31 12:27:33 +08:00
|
|
|
/* for sending down flush barriers */
|
|
|
|
struct bio *flush_bio;
|
|
|
|
struct completion flush_wait;
|
|
|
|
|
2011-03-08 21:14:00 +08:00
|
|
|
/* per-device scrub information */
|
2018-01-03 16:08:30 +08:00
|
|
|
struct scrub_ctx *scrub_ctx;
|
2011-03-08 21:14:00 +08:00
|
|
|
|
2014-02-28 10:46:19 +08:00
|
|
|
struct btrfs_work work;
|
2011-05-23 20:30:00 +08:00
|
|
|
|
|
|
|
/* readahead state */
|
|
|
|
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 04:07:51 +08:00
|
|
|
|
2012-05-25 22:06:08 +08:00
|
|
|
/* disk I/O failure stats. For detailed description refer to
|
|
|
|
* enum btrfs_dev_stat_values in ioctl.h */
|
2012-05-25 22:06:10 +08:00
|
|
|
int dev_stats_valid;
|
2014-07-24 11:37:11 +08:00
|
|
|
|
|
|
|
/* Counter to record the change of device stats */
|
|
|
|
atomic_t dev_stats_ccnt;
|
2012-05-25 22:06:08 +08:00
|
|
|
atomic_t dev_stat_values[BTRFS_DEV_STAT_VALUES_MAX];
|
2019-03-27 20:24:12 +08:00
|
|
|
|
|
|
|
struct extent_io_tree alloc_state;
|
2008-03-25 03:01:56 +08:00
|
|
|
};
|
|
|
|
|
2014-09-03 21:35:38 +08:00
|
|
|
/*
|
|
|
|
* If we read those variants at the context of their own lock, we needn't
|
|
|
|
* use the following helpers, reading them directly is safe.
|
|
|
|
*/
|
|
|
|
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
|
|
|
|
#define BTRFS_DEVICE_GETSET_FUNCS(name) \
|
|
|
|
static inline u64 \
|
|
|
|
btrfs_device_get_##name(const struct btrfs_device *dev) \
|
|
|
|
{ \
|
|
|
|
u64 size; \
|
|
|
|
unsigned int seq; \
|
|
|
|
\
|
|
|
|
do { \
|
|
|
|
seq = read_seqcount_begin(&dev->data_seqcount); \
|
|
|
|
size = dev->name; \
|
|
|
|
} while (read_seqcount_retry(&dev->data_seqcount, seq)); \
|
|
|
|
return size; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static inline void \
|
|
|
|
btrfs_device_set_##name(struct btrfs_device *dev, u64 size) \
|
|
|
|
{ \
|
|
|
|
preempt_disable(); \
|
|
|
|
write_seqcount_begin(&dev->data_seqcount); \
|
|
|
|
dev->name = size; \
|
|
|
|
write_seqcount_end(&dev->data_seqcount); \
|
|
|
|
preempt_enable(); \
|
|
|
|
}
|
|
|
|
#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
|
|
|
|
#define BTRFS_DEVICE_GETSET_FUNCS(name) \
|
|
|
|
static inline u64 \
|
|
|
|
btrfs_device_get_##name(const struct btrfs_device *dev) \
|
|
|
|
{ \
|
|
|
|
u64 size; \
|
|
|
|
\
|
|
|
|
preempt_disable(); \
|
|
|
|
size = dev->name; \
|
|
|
|
preempt_enable(); \
|
|
|
|
return size; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static inline void \
|
|
|
|
btrfs_device_set_##name(struct btrfs_device *dev, u64 size) \
|
|
|
|
{ \
|
|
|
|
preempt_disable(); \
|
|
|
|
dev->name = size; \
|
|
|
|
preempt_enable(); \
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define BTRFS_DEVICE_GETSET_FUNCS(name) \
|
|
|
|
static inline u64 \
|
|
|
|
btrfs_device_get_##name(const struct btrfs_device *dev) \
|
|
|
|
{ \
|
|
|
|
return dev->name; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static inline void \
|
|
|
|
btrfs_device_set_##name(struct btrfs_device *dev, u64 size) \
|
|
|
|
{ \
|
|
|
|
dev->name = size; \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
BTRFS_DEVICE_GETSET_FUNCS(total_bytes);
|
|
|
|
BTRFS_DEVICE_GETSET_FUNCS(disk_total_bytes);
|
|
|
|
BTRFS_DEVICE_GETSET_FUNCS(bytes_used);
|
|
|
|
|
2008-03-25 03:02:07 +08:00
|
|
|
struct btrfs_fs_devices {
|
|
|
|
u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
|
2018-10-30 22:43:23 +08:00
|
|
|
u8 metadata_uuid[BTRFS_FSID_SIZE];
|
2018-10-30 22:43:26 +08:00
|
|
|
bool fsid_change;
|
2018-04-12 10:29:25 +08:00
|
|
|
struct list_head fs_list;
|
2008-03-25 03:02:07 +08:00
|
|
|
|
|
|
|
u64 num_devices;
|
2008-05-14 04:03:06 +08:00
|
|
|
u64 open_devices;
|
2008-11-18 10:11:30 +08:00
|
|
|
u64 rw_devices;
|
2010-12-14 03:56:23 +08:00
|
|
|
u64 missing_devices;
|
2008-11-18 10:11:30 +08:00
|
|
|
u64 total_rw_bytes;
|
2012-06-22 04:03:58 +08:00
|
|
|
u64 total_devices;
|
2018-10-30 22:43:26 +08:00
|
|
|
|
|
|
|
/* Highest generation number of seen devices */
|
|
|
|
u64 latest_generation;
|
|
|
|
|
2008-03-25 03:02:07 +08:00
|
|
|
struct block_device *latest_bdev;
|
2009-06-11 03:17:02 +08: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 19:12:02 +08: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 03:17:02 +08:00
|
|
|
*/
|
|
|
|
struct mutex device_list_mutex;
|
2019-05-09 23:11:11 +08:00
|
|
|
|
|
|
|
/* List of all devices, protected by device_list_mutex */
|
2008-03-25 03:02:07 +08:00
|
|
|
struct list_head devices;
|
2008-04-22 21:22:07 +08:00
|
|
|
|
2019-05-09 23:11:11 +08:00
|
|
|
/*
|
|
|
|
* Devices which can satisfy space allocation. Protected by
|
|
|
|
* chunk_mutex
|
|
|
|
*/
|
2008-04-22 21:22:07 +08:00
|
|
|
struct list_head alloc_list;
|
2008-11-18 10:11:30 +08:00
|
|
|
|
|
|
|
struct btrfs_fs_devices *seed;
|
|
|
|
int seeding;
|
|
|
|
|
|
|
|
int opened;
|
2009-06-10 21:51:32 +08:00
|
|
|
|
|
|
|
/* set when we find or add a device that doesn't have the
|
|
|
|
* nonrot flag set
|
|
|
|
*/
|
|
|
|
int rotating;
|
2015-03-10 06:38:29 +08:00
|
|
|
|
2015-03-10 06:38:31 +08:00
|
|
|
struct btrfs_fs_info *fs_info;
|
2015-03-10 06:38:29 +08:00
|
|
|
/* sysfs kobjects */
|
2015-08-14 18:32:50 +08:00
|
|
|
struct kobject fsid_kobj;
|
2015-03-10 06:38:29 +08:00
|
|
|
struct kobject *device_dir_kobj;
|
|
|
|
struct completion kobj_unregister;
|
2008-03-25 03:02:07 +08:00
|
|
|
};
|
|
|
|
|
2013-07-25 19:22:34 +08:00
|
|
|
#define BTRFS_BIO_INLINE_CSUM_SIZE 64
|
|
|
|
|
2019-03-08 14:20:03 +08:00
|
|
|
#define BTRFS_MAX_DEVS(info) ((BTRFS_MAX_ITEM_SIZE(info) \
|
|
|
|
- sizeof(struct btrfs_chunk)) \
|
|
|
|
/ sizeof(struct btrfs_stripe) + 1)
|
|
|
|
|
|
|
|
#define BTRFS_MAX_DEVS_SYS_CHUNK ((BTRFS_SYSTEM_CHUNK_ARRAY_SIZE \
|
|
|
|
- 2 * sizeof(struct btrfs_disk_key) \
|
|
|
|
- 2 * sizeof(struct btrfs_chunk)) \
|
|
|
|
/ sizeof(struct btrfs_stripe) + 1)
|
|
|
|
|
2013-05-18 06:30:14 +08: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.
|
|
|
|
*/
|
|
|
|
struct btrfs_io_bio {
|
2014-09-12 18:43:56 +08:00
|
|
|
unsigned int mirror_num;
|
|
|
|
unsigned int stripe_index;
|
|
|
|
u64 logical;
|
2013-07-25 19:22:34 +08:00
|
|
|
u8 *csum;
|
|
|
|
u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE];
|
2017-05-16 06:33:27 +08:00
|
|
|
struct bvec_iter iter;
|
2017-06-12 23:29:36 +08:00
|
|
|
/*
|
|
|
|
* This member must come last, bio_alloc_bioset will allocate enough
|
|
|
|
* bytes for entire btrfs_io_bio but relies on bio being last.
|
|
|
|
*/
|
2013-05-18 06:30:14 +08: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);
|
|
|
|
}
|
|
|
|
|
2018-11-23 00:16:49 +08:00
|
|
|
static inline void btrfs_io_bio_free_csum(struct btrfs_io_bio *io_bio)
|
|
|
|
{
|
|
|
|
if (io_bio->csum != io_bio->csum_inline) {
|
|
|
|
kfree(io_bio->csum);
|
|
|
|
io_bio->csum = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-10 04:28:12 +08:00
|
|
|
struct btrfs_bio_stripe {
|
|
|
|
struct btrfs_device *dev;
|
|
|
|
u64 physical;
|
2011-03-24 18:24:26 +08:00
|
|
|
u64 length; /* only used for discard mappings */
|
2008-04-10 04:28:12 +08:00
|
|
|
};
|
|
|
|
|
2011-08-04 23:15:33 +08:00
|
|
|
struct btrfs_bio {
|
2017-03-03 16:55:10 +08:00
|
|
|
refcount_t refs;
|
2008-04-10 04:28:12 +08: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 16:46:55 +08:00
|
|
|
struct btrfs_fs_info *fs_info;
|
2015-01-20 15:11:43 +08:00
|
|
|
u64 map_type; /* get from map_lookup->type */
|
2008-04-10 04:28:12 +08:00
|
|
|
bio_end_io_t *end_io;
|
2008-08-05 22:13:57 +08:00
|
|
|
struct bio *orig_bio;
|
2008-04-10 04:28:12 +08:00
|
|
|
void *private;
|
2008-04-29 21:38:00 +08:00
|
|
|
atomic_t error;
|
|
|
|
int max_errors;
|
2008-04-10 04:28:12 +08:00
|
|
|
int num_stripes;
|
2011-08-04 23:15:33 +08:00
|
|
|
int mirror_num;
|
2014-11-14 16:06:25 +08:00
|
|
|
int num_tgtdevs;
|
|
|
|
int *tgtdev_map;
|
2015-01-20 15:11:33 +08:00
|
|
|
/*
|
|
|
|
* logical block numbers for the start of each stripe
|
|
|
|
* The last one or two are p/q. These are sorted,
|
|
|
|
* so raid_map[0] is the start of our full stripe
|
|
|
|
*/
|
|
|
|
u64 *raid_map;
|
2008-04-10 04:28:12 +08:00
|
|
|
struct btrfs_bio_stripe stripes[];
|
|
|
|
};
|
|
|
|
|
2011-01-05 18:07:28 +08: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 18:07:57 +08:00
|
|
|
u64 total_avail;
|
2011-01-05 18:07:28 +08:00
|
|
|
};
|
|
|
|
|
2012-11-21 22:18:10 +08:00
|
|
|
struct btrfs_raid_attr {
|
2019-05-17 17:43:36 +08:00
|
|
|
u8 sub_stripes; /* sub_stripes info for map */
|
|
|
|
u8 dev_stripes; /* stripes per dev */
|
|
|
|
u8 devs_max; /* max devs to use */
|
|
|
|
u8 devs_min; /* min devs needed */
|
|
|
|
u8 tolerated_failures; /* max tolerated fail devs */
|
|
|
|
u8 devs_increment; /* ndevs has to be a multiple of this */
|
|
|
|
u8 ncopies; /* how many copies to data has */
|
|
|
|
u8 nparity; /* number of stripes worth of bytes to store
|
2018-10-05 05:24:42 +08:00
|
|
|
* parity information */
|
2019-05-17 17:43:36 +08:00
|
|
|
u8 mindev_error; /* error code if min devs requisite is unmet */
|
2018-04-25 19:01:42 +08:00
|
|
|
const char raid_name[8]; /* name of the raid */
|
2018-04-25 19:01:43 +08:00
|
|
|
u64 bg_flag; /* block group flag of the raid */
|
2012-11-21 22:18:10 +08:00
|
|
|
};
|
|
|
|
|
2015-09-15 21:08:06 +08:00
|
|
|
extern const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES];
|
|
|
|
|
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 19:18:59 +08:00
|
|
|
struct map_lookup {
|
|
|
|
u64 type;
|
|
|
|
int io_align;
|
|
|
|
int io_width;
|
2016-04-27 08:53:31 +08:00
|
|
|
u64 stripe_len;
|
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 19:18:59 +08:00
|
|
|
int num_stripes;
|
|
|
|
int sub_stripes;
|
2018-08-01 10:37:19 +08:00
|
|
|
int verified_stripes; /* For mount time dev extent verification */
|
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 19:18:59 +08:00
|
|
|
struct btrfs_bio_stripe stripes[];
|
|
|
|
};
|
|
|
|
|
2011-03-08 21:14:00 +08:00
|
|
|
#define map_lookup_size(n) (sizeof(struct map_lookup) + \
|
|
|
|
(sizeof(struct btrfs_bio_stripe) * (n)))
|
|
|
|
|
2012-01-17 04:04:47 +08:00
|
|
|
struct btrfs_balance_args;
|
2012-01-17 04:04:49 +08:00
|
|
|
struct btrfs_balance_progress;
|
2012-01-17 04:04:47 +08:00
|
|
|
struct btrfs_balance_control {
|
|
|
|
struct btrfs_balance_args data;
|
|
|
|
struct btrfs_balance_args meta;
|
|
|
|
struct btrfs_balance_args sys;
|
|
|
|
|
|
|
|
u64 flags;
|
2012-01-17 04:04:49 +08:00
|
|
|
|
|
|
|
struct btrfs_balance_progress stat;
|
2012-01-17 04:04:47 +08:00
|
|
|
};
|
|
|
|
|
2016-10-27 15:27:36 +08:00
|
|
|
enum btrfs_map_op {
|
|
|
|
BTRFS_MAP_READ,
|
|
|
|
BTRFS_MAP_WRITE,
|
|
|
|
BTRFS_MAP_DISCARD,
|
|
|
|
BTRFS_MAP_GET_READ_MIRRORS,
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline enum btrfs_map_op btrfs_op(struct bio *bio)
|
|
|
|
{
|
|
|
|
switch (bio_op(bio)) {
|
|
|
|
case REQ_OP_DISCARD:
|
|
|
|
return BTRFS_MAP_DISCARD;
|
|
|
|
case REQ_OP_WRITE:
|
|
|
|
return BTRFS_MAP_WRITE;
|
|
|
|
default:
|
|
|
|
WARN_ON_ONCE(1);
|
2019-01-23 16:48:28 +08:00
|
|
|
/* fall through */
|
2016-10-27 15:27:36 +08:00
|
|
|
case REQ_OP_READ:
|
|
|
|
return BTRFS_MAP_READ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:11:34 +08:00
|
|
|
void btrfs_get_bbio(struct btrfs_bio *bbio);
|
|
|
|
void btrfs_put_bbio(struct btrfs_bio *bbio);
|
2016-10-27 15:27:36 +08:00
|
|
|
int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
|
2008-04-10 04:28:12 +08:00
|
|
|
u64 logical, u64 *length,
|
2011-08-04 23:15:33 +08:00
|
|
|
struct btrfs_bio **bbio_ret, int mirror_num);
|
2016-10-27 15:27:36 +08:00
|
|
|
int btrfs_map_sblock(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
|
2014-10-23 14:42:50 +08:00
|
|
|
u64 logical, u64 *length,
|
2017-03-28 20:45:22 +08:00
|
|
|
struct btrfs_bio **bbio_ret);
|
2019-06-03 17:05:03 +08:00
|
|
|
int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
|
2019-06-03 17:05:05 +08:00
|
|
|
u64 logical, u64 len, struct btrfs_io_geometry *io_geom);
|
2018-05-04 15:53:05 +08:00
|
|
|
int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start,
|
|
|
|
u64 physical, u64 **logical, int *naddrs, int *stripe_len);
|
2016-06-22 09:16:51 +08:00
|
|
|
int btrfs_read_sys_array(struct btrfs_fs_info *fs_info);
|
2016-06-21 22:40:19 +08:00
|
|
|
int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info);
|
2018-06-20 20:49:06 +08:00
|
|
|
int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, u64 type);
|
2019-05-17 17:43:17 +08:00
|
|
|
void btrfs_mapping_tree_free(struct extent_map_tree *tree);
|
2017-08-23 14:45:59 +08:00
|
|
|
blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
|
|
|
|
int mirror_num, int async_submit);
|
2008-03-25 03:02:07 +08:00
|
|
|
int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
|
2008-12-02 19:36:09 +08:00
|
|
|
fmode_t flags, void *holder);
|
2018-07-12 14:23:16 +08:00
|
|
|
struct btrfs_device *btrfs_scan_one_device(const char *path,
|
|
|
|
fmode_t flags, void *holder);
|
2019-01-04 13:31:54 +08:00
|
|
|
int btrfs_forget_devices(const char *path);
|
2008-03-25 03:02:07 +08:00
|
|
|
int btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
|
2018-02-27 12:41:59 +08:00
|
|
|
void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step);
|
2018-07-21 00:37:50 +08:00
|
|
|
void btrfs_assign_next_active_device(struct btrfs_device *device,
|
|
|
|
struct btrfs_device *this_dev);
|
2018-09-03 17:46:14 +08:00
|
|
|
struct btrfs_device *btrfs_find_device_by_devspec(struct btrfs_fs_info *fs_info,
|
|
|
|
u64 devid,
|
|
|
|
const char *devpath);
|
2013-08-23 18:20:17 +08:00
|
|
|
struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info,
|
|
|
|
const u64 *devid,
|
|
|
|
const u8 *uuid);
|
2018-03-20 22:47:33 +08:00
|
|
|
void btrfs_free_device(struct btrfs_device *device);
|
2016-06-23 06:54:24 +08:00
|
|
|
int btrfs_rm_device(struct btrfs_fs_info *fs_info,
|
2017-02-15 00:55:53 +08:00
|
|
|
const char *device_path, u64 devid);
|
2018-02-20 00:24:15 +08:00
|
|
|
void __exit btrfs_cleanup_fs_uuids(void);
|
2012-11-05 21:59:07 +08:00
|
|
|
int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len);
|
2008-04-26 04:53:30 +08:00
|
|
|
int btrfs_grow_device(struct btrfs_trans_handle *trans,
|
|
|
|
struct btrfs_device *device, u64 new_size);
|
2019-01-17 23:32:31 +08:00
|
|
|
struct btrfs_device *btrfs_find_device(struct btrfs_fs_devices *fs_devices,
|
2019-01-19 14:48:55 +08:00
|
|
|
u64 devid, u8 *uuid, u8 *fsid, bool seed);
|
2008-04-26 04:53:30 +08:00
|
|
|
int btrfs_shrink_device(struct btrfs_device *device, u64 new_size);
|
2017-02-15 00:55:53 +08:00
|
|
|
int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *path);
|
2018-05-07 23:44:03 +08:00
|
|
|
int btrfs_balance(struct btrfs_fs_info *fs_info,
|
|
|
|
struct btrfs_balance_control *bctl,
|
2012-01-17 04:04:47 +08:00
|
|
|
struct btrfs_ioctl_balance_args *bargs);
|
2018-11-20 16:12:55 +08:00
|
|
|
void btrfs_describe_block_groups(u64 flags, char *buf, u32 size_buf);
|
2012-06-23 02:24:13 +08:00
|
|
|
int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info);
|
2012-06-23 02:24:12 +08:00
|
|
|
int btrfs_recover_balance(struct btrfs_fs_info *fs_info);
|
2012-01-17 04:04:49 +08:00
|
|
|
int btrfs_pause_balance(struct btrfs_fs_info *fs_info);
|
2012-01-17 04:04:49 +08:00
|
|
|
int btrfs_cancel_balance(struct btrfs_fs_info *fs_info);
|
2013-08-15 23:11:19 +08:00
|
|
|
int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info);
|
2013-08-15 23:11:23 +08:00
|
|
|
int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info);
|
2016-06-23 06:54:24 +08:00
|
|
|
int btrfs_chunk_readonly(struct btrfs_fs_info *fs_info, u64 chunk_offset);
|
2019-03-27 20:24:14 +08:00
|
|
|
int find_free_dev_extent(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 04:11:19 +08:00
|
|
|
u64 *start, u64 *max_avail);
|
2012-05-25 22:06:08 +08:00
|
|
|
void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index);
|
2016-06-23 06:54:24 +08:00
|
|
|
int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
|
2012-06-22 20:30:39 +08:00
|
|
|
struct btrfs_ioctl_get_dev_stats *stats);
|
2013-05-15 15:48:19 +08:00
|
|
|
void btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
|
2012-05-25 22:06:10 +08:00
|
|
|
int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info);
|
2019-03-20 23:50:38 +08:00
|
|
|
int btrfs_run_dev_stats(struct btrfs_trans_handle *trans);
|
2018-07-21 00:37:48 +08:00
|
|
|
void btrfs_rm_dev_replace_remove_srcdev(struct btrfs_device *srcdev);
|
2019-03-20 23:34:54 +08:00
|
|
|
void btrfs_rm_dev_replace_free_srcdev(struct btrfs_device *srcdev);
|
2018-07-21 00:37:51 +08:00
|
|
|
void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev);
|
2017-02-15 00:55:53 +08:00
|
|
|
void btrfs_scratch_superblocks(struct block_device *bdev, const char *device_path);
|
2017-03-15 04:33:55 +08:00
|
|
|
int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info,
|
2017-07-19 15:48:42 +08:00
|
|
|
u64 logical, u64 len);
|
2016-06-23 06:54:24 +08:00
|
|
|
unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
|
2013-01-30 07:40:14 +08:00
|
|
|
u64 logical);
|
2013-06-28 01:22:46 +08:00
|
|
|
int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans,
|
2018-07-21 00:37:53 +08:00
|
|
|
u64 chunk_offset, u64 chunk_size);
|
|
|
|
int btrfs_remove_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset);
|
2018-05-17 07:34:31 +08:00
|
|
|
struct extent_map *btrfs_get_chunk_map(struct btrfs_fs_info *fs_info,
|
|
|
|
u64 logical, u64 length);
|
2014-07-24 11:37:11 +08:00
|
|
|
|
2012-05-25 22:06:08 +08:00
|
|
|
static inline void btrfs_dev_stat_inc(struct btrfs_device *dev,
|
|
|
|
int index)
|
|
|
|
{
|
|
|
|
atomic_inc(dev->dev_stat_values + index);
|
2017-10-24 18:47:37 +08:00
|
|
|
/*
|
|
|
|
* This memory barrier orders stores updating statistics before stores
|
|
|
|
* updating dev_stats_ccnt.
|
|
|
|
*
|
|
|
|
* It pairs with smp_rmb() in btrfs_run_dev_stats().
|
|
|
|
*/
|
2014-07-24 11:37:11 +08:00
|
|
|
smp_mb__before_atomic();
|
|
|
|
atomic_inc(&dev->dev_stats_ccnt);
|
2012-05-25 22:06:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2017-10-20 23:10:58 +08:00
|
|
|
/*
|
|
|
|
* atomic_xchg implies a full memory barriers as per atomic_t.txt:
|
|
|
|
* - RMW operations that have a return value are fully ordered;
|
|
|
|
*
|
|
|
|
* This implicit memory barriers is paired with the smp_rmb in
|
|
|
|
* btrfs_run_dev_stats
|
|
|
|
*/
|
2014-07-24 11:37:11 +08:00
|
|
|
atomic_inc(&dev->dev_stats_ccnt);
|
2012-05-25 22:06:08 +08:00
|
|
|
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);
|
2017-10-24 18:47:37 +08:00
|
|
|
/*
|
|
|
|
* This memory barrier orders stores updating statistics before stores
|
|
|
|
* updating dev_stats_ccnt.
|
|
|
|
*
|
|
|
|
* It pairs with smp_rmb() in btrfs_run_dev_stats().
|
|
|
|
*/
|
2014-07-24 11:37:11 +08:00
|
|
|
smp_mb__before_atomic();
|
|
|
|
atomic_inc(&dev->dev_stats_ccnt);
|
2012-05-25 22:06:08 +08:00
|
|
|
}
|
|
|
|
|
2018-01-30 18:20:45 +08:00
|
|
|
/*
|
|
|
|
* Convert block group flags (BTRFS_BLOCK_GROUP_*) to btrfs_raid_types, which
|
|
|
|
* can be used as index to access btrfs_raid_array[].
|
|
|
|
*/
|
|
|
|
static inline enum btrfs_raid_types btrfs_bg_flags_to_raid_index(u64 flags)
|
|
|
|
{
|
|
|
|
if (flags & BTRFS_BLOCK_GROUP_RAID10)
|
|
|
|
return BTRFS_RAID_RAID10;
|
|
|
|
else if (flags & BTRFS_BLOCK_GROUP_RAID1)
|
|
|
|
return BTRFS_RAID_RAID1;
|
|
|
|
else if (flags & BTRFS_BLOCK_GROUP_DUP)
|
|
|
|
return BTRFS_RAID_DUP;
|
|
|
|
else if (flags & BTRFS_BLOCK_GROUP_RAID0)
|
|
|
|
return BTRFS_RAID_RAID0;
|
|
|
|
else if (flags & BTRFS_BLOCK_GROUP_RAID5)
|
|
|
|
return BTRFS_RAID_RAID5;
|
|
|
|
else if (flags & BTRFS_BLOCK_GROUP_RAID6)
|
|
|
|
return BTRFS_RAID_RAID6;
|
|
|
|
|
|
|
|
return BTRFS_RAID_SINGLE; /* BTRFS_BLOCK_GROUP_SINGLE */
|
|
|
|
}
|
|
|
|
|
2019-03-25 20:31:22 +08:00
|
|
|
void btrfs_commit_device_sizes(struct btrfs_transaction *trans);
|
Btrfs: fix race between fs trimming and block group remove/allocation
Our fs trim operation, which is completely transactionless (doesn't start
or joins an existing transaction) consists of visiting all block groups
and then for each one to iterate its free space entries and perform a
discard operation against the space range represented by the free space
entries. However before performing a discard, the corresponding free space
entry is removed from the free space rbtree, and when the discard completes
it is added back to the free space rbtree.
If a block group remove operation happens while the discard is ongoing (or
before it starts and after a free space entry is hidden), we end up not
waiting for the discard to complete, remove the extent map that maps
logical address to physical addresses and the corresponding chunk metadata
from the the chunk and device trees. After that and before the discard
completes, the current running transaction can finish and a new one start,
allowing for new block groups that map to the same physical addresses to
be allocated and written to.
So fix this by keeping the extent map in memory until the discard completes
so that the same physical addresses aren't reused before it completes.
If the physical locations that are under a discard operation end up being
used for a new metadata block group for example, and dirty metadata extents
are written before the discard finishes (the VM might call writepages() of
our btree inode's i_mapping for example, or an fsync log commit happens) we
end up overwriting metadata with zeroes, which leads to errors from fsck
like the following:
checking extents
Check tree block failed, want=833912832, have=0
Check tree block failed, want=833912832, have=0
Check tree block failed, want=833912832, have=0
Check tree block failed, want=833912832, have=0
Check tree block failed, want=833912832, have=0
read block failed check_tree_block
owner ref check failed [833912832 16384]
Errors found in extent allocation tree or chunk allocation
checking free space cache
checking fs roots
Check tree block failed, want=833912832, have=0
Check tree block failed, want=833912832, have=0
Check tree block failed, want=833912832, have=0
Check tree block failed, want=833912832, have=0
Check tree block failed, want=833912832, have=0
read block failed check_tree_block
root 5 root dir 256 error
root 5 inode 260 errors 2001, no inode item, link count wrong
unresolved ref dir 256 index 0 namelen 8 name foobar_3 filetype 1 errors 6, no dir index, no inode ref
root 5 inode 262 errors 2001, no inode item, link count wrong
unresolved ref dir 256 index 0 namelen 8 name foobar_5 filetype 1 errors 6, no dir index, no inode ref
root 5 inode 263 errors 2001, no inode item, link count wrong
(...)
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
2014-11-28 05:14:15 +08:00
|
|
|
|
2015-03-10 06:38:30 +08:00
|
|
|
struct list_head *btrfs_get_fs_uuids(void);
|
2015-03-10 06:38:31 +08:00
|
|
|
void btrfs_set_fs_info_ptr(struct btrfs_fs_info *fs_info);
|
|
|
|
void btrfs_reset_fs_info_ptr(struct btrfs_fs_info *fs_info);
|
2017-12-18 17:08:59 +08:00
|
|
|
bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info,
|
|
|
|
struct btrfs_device *failing_dev);
|
btrfs: Introduce a function to check if all chunks a OK for degraded rw mount
Introduce a new function, btrfs_check_rw_degradable(), to check if all
chunks in btrfs is OK for degraded rw mount.
It provides the new basis for accurate btrfs mount/remount and even
runtime degraded mount check other than old one-size-fit-all method.
Btrfs currently uses num_tolerated_disk_barrier_failures to do global
check for tolerated missing device.
Although the one-size-fit-all solution is quite safe, it's too strict
if data and metadata has different duplication level.
For example, if one use Single data and RAID1 metadata for 2 disks, it
means any missing device will make the fs unable to be degraded
mounted.
But in fact, some times all single chunks may be in the existing
device and in that case, we should allow it to be rw degraded mounted.
Such case can be easily reproduced using the following script:
# mkfs.btrfs -f -m raid1 -d sing /dev/sdb /dev/sdc
# wipefs -f /dev/sdc
# mount /dev/sdb -o degraded,rw
If using btrfs-debug-tree to check /dev/sdb, one should find that the
data chunk is only in sdb, so in fact it should allow degraded mount.
This patchset will introduce a new per-chunk degradable check for
btrfs, allow above case to succeed, and it's quite small anyway.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.com>
[ copied text from cover letter with more details about the problem being
solved ]
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-09 09:34:36 +08:00
|
|
|
|
2018-07-14 02:46:30 +08:00
|
|
|
int btrfs_bg_type_to_factor(u64 flags);
|
2019-05-17 17:43:41 +08:00
|
|
|
const char *btrfs_bg_type_to_raid_name(u64 flags);
|
2018-08-01 10:37:19 +08:00
|
|
|
int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info);
|
2018-07-14 02:46:30 +08:00
|
|
|
|
2008-03-25 03:01:56 +08:00
|
|
|
#endif
|