2008-01-04 15:36:26 +00: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.
|
|
|
|
*/
|
|
|
|
|
2015-01-21 16:49:26 +00:00
|
|
|
#ifndef __BTRFS_EXTENT_IO_H__
|
|
|
|
#define __BTRFS_EXTENT_IO_H__
|
2013-01-07 22:24:35 +00:00
|
|
|
|
|
|
|
#if BTRFS_FLAT_INCLUDES
|
2008-01-04 15:36:26 +00:00
|
|
|
#include "kerncompat.h"
|
|
|
|
#include "extent-cache.h"
|
|
|
|
#include "list.h"
|
2013-01-07 22:24:35 +00:00
|
|
|
#else
|
|
|
|
#include <btrfs/kerncompat.h>
|
|
|
|
#include <btrfs/extent-cache.h>
|
|
|
|
#include <btrfs/list.h>
|
|
|
|
#endif /* BTRFS_FLAT_INCLUDES */
|
2008-01-04 15:36:26 +00:00
|
|
|
|
|
|
|
#define EXTENT_DIRTY 1
|
|
|
|
#define EXTENT_WRITEBACK (1 << 1)
|
|
|
|
#define EXTENT_UPTODATE (1 << 2)
|
|
|
|
#define EXTENT_LOCKED (1 << 3)
|
|
|
|
#define EXTENT_NEW (1 << 4)
|
|
|
|
#define EXTENT_DELALLOC (1 << 5)
|
|
|
|
#define EXTENT_DEFRAG (1 << 6)
|
|
|
|
#define EXTENT_DEFRAG_DONE (1 << 7)
|
|
|
|
#define EXTENT_BUFFER_FILLED (1 << 8)
|
|
|
|
#define EXTENT_CSUM (1 << 9)
|
2013-10-01 13:00:19 +00:00
|
|
|
#define EXTENT_BAD_TRANSID (1 << 10)
|
2014-10-10 20:57:07 +00:00
|
|
|
#define EXTENT_BUFFER_DUMMY (1 << 11)
|
2008-01-04 15:36:26 +00:00
|
|
|
#define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
|
|
|
|
|
2013-07-03 13:25:17 +00:00
|
|
|
#define BLOCK_GROUP_DATA EXTENT_WRITEBACK
|
|
|
|
#define BLOCK_GROUP_METADATA EXTENT_UPTODATE
|
|
|
|
#define BLOCK_GROUP_SYSTEM EXTENT_NEW
|
|
|
|
|
|
|
|
#define BLOCK_GROUP_DIRTY EXTENT_DIRTY
|
|
|
|
|
2013-04-04 13:57:50 +00:00
|
|
|
struct btrfs_fs_info;
|
|
|
|
|
2008-03-04 16:16:54 +00:00
|
|
|
struct extent_io_tree {
|
2008-01-04 15:36:26 +00:00
|
|
|
struct cache_tree state;
|
|
|
|
struct cache_tree cache;
|
|
|
|
struct list_head lru;
|
|
|
|
u64 cache_size;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct extent_state {
|
|
|
|
struct cache_extent cache_node;
|
|
|
|
u64 start;
|
|
|
|
u64 end;
|
|
|
|
int refs;
|
|
|
|
unsigned long state;
|
2013-01-30 22:50:26 +00:00
|
|
|
u64 xprivate;
|
2008-01-04 15:36:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct extent_buffer {
|
|
|
|
struct cache_extent cache_node;
|
|
|
|
u64 start;
|
|
|
|
u64 dev_bytenr;
|
|
|
|
u32 len;
|
2008-03-04 16:16:54 +00:00
|
|
|
struct extent_io_tree *tree;
|
2008-01-04 15:36:26 +00:00
|
|
|
struct list_head lru;
|
2013-10-01 13:00:19 +00:00
|
|
|
struct list_head recow;
|
2008-01-04 15:36:26 +00:00
|
|
|
int refs;
|
|
|
|
int flags;
|
|
|
|
int fd;
|
|
|
|
char data[];
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void extent_buffer_get(struct extent_buffer *eb)
|
|
|
|
{
|
|
|
|
eb->refs++;
|
|
|
|
}
|
|
|
|
|
2008-03-04 16:16:54 +00:00
|
|
|
void extent_io_tree_init(struct extent_io_tree *tree);
|
|
|
|
void extent_io_tree_cleanup(struct extent_io_tree *tree);
|
|
|
|
int set_extent_bits(struct extent_io_tree *tree, u64 start,
|
2008-01-04 15:36:26 +00:00
|
|
|
u64 end, int bits, gfp_t mask);
|
2008-03-04 16:16:54 +00:00
|
|
|
int clear_extent_bits(struct extent_io_tree *tree, u64 start,
|
2008-01-04 15:36:26 +00:00
|
|
|
u64 end, int bits, gfp_t mask);
|
2008-03-04 16:16:54 +00:00
|
|
|
int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
|
2008-01-04 15:36:26 +00:00
|
|
|
u64 *start_ret, u64 *end_ret, int bits);
|
2008-03-04 16:16:54 +00:00
|
|
|
int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
2008-01-04 15:36:26 +00:00
|
|
|
int bits, int filled);
|
2008-03-04 16:16:54 +00:00
|
|
|
int set_extent_dirty(struct extent_io_tree *tree, u64 start,
|
2008-01-04 15:36:26 +00:00
|
|
|
u64 end, gfp_t mask);
|
2008-03-04 16:16:54 +00:00
|
|
|
int clear_extent_dirty(struct extent_io_tree *tree, u64 start,
|
2008-01-04 15:36:26 +00:00
|
|
|
u64 end, gfp_t mask);
|
2015-01-27 03:12:43 +00:00
|
|
|
static inline int set_extent_buffer_uptodate(struct extent_buffer *eb)
|
|
|
|
{
|
|
|
|
eb->flags |= EXTENT_UPTODATE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int clear_extent_buffer_uptodate(struct extent_io_tree *tree,
|
|
|
|
struct extent_buffer *eb)
|
|
|
|
{
|
|
|
|
eb->flags &= ~EXTENT_UPTODATE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int extent_buffer_uptodate(struct extent_buffer *eb)
|
|
|
|
{
|
|
|
|
if (!eb || IS_ERR(eb))
|
|
|
|
return 0;
|
|
|
|
if (eb->flags & EXTENT_UPTODATE)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-30 22:50:26 +00:00
|
|
|
int set_state_private(struct extent_io_tree *tree, u64 start, u64 xprivate);
|
|
|
|
int get_state_private(struct extent_io_tree *tree, u64 start, u64 *xprivate);
|
2008-03-04 16:16:54 +00:00
|
|
|
struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree,
|
2008-01-04 15:36:26 +00:00
|
|
|
u64 bytenr, u32 blocksize);
|
2008-03-04 16:16:54 +00:00
|
|
|
struct extent_buffer *find_first_extent_buffer(struct extent_io_tree *tree,
|
2008-01-04 15:36:26 +00:00
|
|
|
u64 start);
|
2008-03-04 16:16:54 +00:00
|
|
|
struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
|
2008-01-04 15:36:26 +00:00
|
|
|
u64 bytenr, u32 blocksize);
|
2014-10-10 20:57:07 +00:00
|
|
|
struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src);
|
2008-01-04 15:36:26 +00:00
|
|
|
void free_extent_buffer(struct extent_buffer *eb);
|
2009-07-11 17:12:37 +00:00
|
|
|
int read_extent_from_disk(struct extent_buffer *eb,
|
|
|
|
unsigned long offset, unsigned long len);
|
2008-01-04 15:36:26 +00:00
|
|
|
int write_extent_to_disk(struct extent_buffer *eb);
|
|
|
|
int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv,
|
|
|
|
unsigned long start, unsigned long len);
|
|
|
|
void read_extent_buffer(struct extent_buffer *eb, void *dst,
|
|
|
|
unsigned long start, unsigned long len);
|
|
|
|
void write_extent_buffer(struct extent_buffer *eb, const void *src,
|
|
|
|
unsigned long start, unsigned long len);
|
|
|
|
void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,
|
|
|
|
unsigned long dst_offset, unsigned long src_offset,
|
|
|
|
unsigned long len);
|
|
|
|
void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
|
|
|
|
unsigned long src_offset, unsigned long len);
|
|
|
|
void memset_extent_buffer(struct extent_buffer *eb, char c,
|
|
|
|
unsigned long start, unsigned long len);
|
2015-09-30 03:51:45 +00:00
|
|
|
int extent_buffer_test_bit(struct extent_buffer *eb, unsigned long start,
|
|
|
|
unsigned long nr);
|
2008-01-04 15:36:26 +00:00
|
|
|
int set_extent_buffer_dirty(struct extent_buffer *eb);
|
|
|
|
int clear_extent_buffer_dirty(struct extent_buffer *eb);
|
2013-04-04 13:57:50 +00:00
|
|
|
int read_data_from_disk(struct btrfs_fs_info *info, void *buf, u64 offset,
|
|
|
|
u64 bytes, int mirror);
|
Btrfs-progs: enhance btrfs-image to restore image onto multiple disks
This adds a 'btrfs-image -m' option, which let us restore an image that
is built from a btrfs of multiple disks onto several disks altogether.
This aims to address the following case,
$ mkfs.btrfs -m raid0 sda sdb
$ btrfs-image sda image.file
$ btrfs-image -r image.file sdc
---------
so we can only restore metadata onto sdc, and another thing is we can
only mount sdc with degraded mode as we don't provide informations of
another disk. And, it's built as RAID0 and we have only one disk,
so after mount sdc we'll get into readonly mode.
This is just annoying for people(like me) who're trying to restore image
but turn to find they cannot make it work.
So this'll make your life easier, just tap
$ btrfs-image -m image.file sdc sdd
---------
then you get everything about metadata done, the same offset with that of
the originals(of course, you need offer enough disk size, at least the disk
size of the original disks).
Besides, this also works with raid5 and raid6 metadata image.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-06-22 05:32:45 +00:00
|
|
|
int write_data_to_disk(struct btrfs_fs_info *info, void *buf, u64 offset,
|
|
|
|
u64 bytes, int mirror);
|
2008-01-04 15:36:26 +00:00
|
|
|
#endif
|