btrfs-progs: libbtrfs: use own copy of ctree.h, extent_io.h, send.h and extent-cache.h
Let libbtrfs use own copy of the exported header files to avoid potential breakage when syncing with kernel headers and also to remove declarations that are not used by userspace. The send.h is frozen to support protocol v1. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
c6dbd1d337
commit
bb7db09e46
6
Makefile
6
Makefile
|
@ -212,10 +212,10 @@ libbtrfs_objects = \
|
|||
libbtrfs/send-utils.o \
|
||||
crypto/crc32c.o
|
||||
|
||||
libbtrfs_headers = libbtrfs/send-stream.h libbtrfs/send-utils.h kernel-shared/send.h kernel-lib/rbtree.h \
|
||||
libbtrfs_headers = libbtrfs/send-stream.h libbtrfs/send-utils.h libbtrfs/send.h kernel-lib/rbtree.h \
|
||||
kernel-lib/list.h kernel-lib/rbtree_types.h kerncompat.h \
|
||||
common/extent-cache.h kernel-shared/extent_io.h ioctl.h \
|
||||
kernel-shared/ctree.h version.h
|
||||
libbtrfs/extent-cache.h libbtrfs/extent_io.h ioctl.h \
|
||||
libbtrfs/ctree.h version.h
|
||||
libbtrfsutil_major := $(shell sed -rn 's/^\#define BTRFS_UTIL_VERSION_MAJOR ([0-9])+$$/\1/p' libbtrfsutil/btrfsutil.h)
|
||||
libbtrfsutil_minor := $(shell sed -rn 's/^\#define BTRFS_UTIL_VERSION_MINOR ([0-9])+$$/\1/p' libbtrfsutil/btrfsutil.h)
|
||||
libbtrfsutil_patch := $(shell sed -rn 's/^\#define BTRFS_UTIL_VERSION_PATCH ([0-9])+$$/\1/p' libbtrfsutil/btrfsutil.h)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
* 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_EXTENT_CACHE_H__
|
||||
#define __BTRFS_EXTENT_CACHE_H__
|
||||
|
||||
#if BTRFS_FLAT_INCLUDES
|
||||
#include "kerncompat.h"
|
||||
#include "kernel-lib/rbtree.h"
|
||||
#else
|
||||
#include <btrfs/kerncompat.h>
|
||||
#include <btrfs/rbtree.h>
|
||||
#endif /* BTRFS_FLAT_INCLUDES */
|
||||
|
||||
struct cache_tree {
|
||||
struct rb_root root;
|
||||
};
|
||||
|
||||
struct cache_extent {
|
||||
struct rb_node rb_node;
|
||||
u64 objectid;
|
||||
u64 start;
|
||||
u64 size;
|
||||
};
|
||||
|
||||
void cache_tree_init(struct cache_tree *tree);
|
||||
|
||||
struct cache_extent *first_cache_extent(struct cache_tree *tree);
|
||||
struct cache_extent *last_cache_extent(struct cache_tree *tree);
|
||||
struct cache_extent *prev_cache_extent(struct cache_extent *pe);
|
||||
struct cache_extent *next_cache_extent(struct cache_extent *pe);
|
||||
|
||||
/*
|
||||
* Find a cache_extent which covers start.
|
||||
*
|
||||
* If not found, return next cache_extent if possible.
|
||||
*/
|
||||
struct cache_extent *search_cache_extent(struct cache_tree *tree, u64 start);
|
||||
|
||||
/*
|
||||
* Find a cache_extent which restrictly covers start.
|
||||
*
|
||||
* If not found, return NULL.
|
||||
*/
|
||||
struct cache_extent *lookup_cache_extent(struct cache_tree *tree,
|
||||
u64 start, u64 size);
|
||||
|
||||
/*
|
||||
* Add an non-overlap extent into cache tree
|
||||
*
|
||||
* If [start, start+size) overlap with existing one, it will return -EEXIST.
|
||||
*/
|
||||
int add_cache_extent(struct cache_tree *tree, u64 start, u64 size);
|
||||
|
||||
/*
|
||||
* Same with add_cache_extent, but with cache_extent strcut.
|
||||
*/
|
||||
int insert_cache_extent(struct cache_tree *tree, struct cache_extent *pe);
|
||||
void remove_cache_extent(struct cache_tree *tree, struct cache_extent *pe);
|
||||
|
||||
static inline int cache_tree_empty(struct cache_tree *tree)
|
||||
{
|
||||
return RB_EMPTY_ROOT(&tree->root);
|
||||
}
|
||||
|
||||
typedef void (*free_cache_extent)(struct cache_extent *pe);
|
||||
|
||||
void cache_tree_free_extents(struct cache_tree *tree,
|
||||
free_cache_extent free_func);
|
||||
|
||||
#define FREE_EXTENT_CACHE_BASED_TREE(name, free_func) \
|
||||
static void free_##name##_tree(struct cache_tree *tree) \
|
||||
{ \
|
||||
cache_tree_free_extents(tree, free_func); \
|
||||
}
|
||||
|
||||
void free_extent_cache_tree(struct cache_tree *tree);
|
||||
|
||||
/*
|
||||
* Search a cache_extent with same objectid, and covers start.
|
||||
*
|
||||
* If not found, return next if possible.
|
||||
*/
|
||||
struct cache_extent *search_cache_extent2(struct cache_tree *tree,
|
||||
u64 objectid, u64 start);
|
||||
/*
|
||||
* Search a cache_extent with same objectid, and covers the range
|
||||
* [start, start + size)
|
||||
*
|
||||
* If not found, return next cache_extent if possible.
|
||||
*/
|
||||
struct cache_extent *lookup_cache_extent2(struct cache_tree *tree,
|
||||
u64 objectid, u64 start, u64 size);
|
||||
int insert_cache_extent2(struct cache_tree *tree, struct cache_extent *pe);
|
||||
|
||||
/*
|
||||
* Insert a cache_extent range [start, start + size).
|
||||
*
|
||||
* This function may merge with existing cache_extent.
|
||||
* NOTE: caller must ensure the inserted range won't cover with any existing
|
||||
* range.
|
||||
*/
|
||||
int add_merge_cache_extent(struct cache_tree *tree, u64 start, u64 size);
|
||||
#endif
|
|
@ -0,0 +1,177 @@
|
|||
/*
|
||||
* 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_EXTENT_IO_H__
|
||||
#define __BTRFS_EXTENT_IO_H__
|
||||
|
||||
#if BTRFS_FLAT_INCLUDES
|
||||
#include "kerncompat.h"
|
||||
#include "libbtrfs/extent-cache.h"
|
||||
#include "kernel-lib/list.h"
|
||||
#else
|
||||
#include <btrfs/kerncompat.h>
|
||||
#include <btrfs/extent-cache.h>
|
||||
#include <btrfs/list.h>
|
||||
#endif /* BTRFS_FLAT_INCLUDES */
|
||||
|
||||
#define EXTENT_DIRTY (1U << 0)
|
||||
#define EXTENT_WRITEBACK (1U << 1)
|
||||
#define EXTENT_UPTODATE (1U << 2)
|
||||
#define EXTENT_LOCKED (1U << 3)
|
||||
#define EXTENT_NEW (1U << 4)
|
||||
#define EXTENT_DELALLOC (1U << 5)
|
||||
#define EXTENT_DEFRAG (1U << 6)
|
||||
#define EXTENT_DEFRAG_DONE (1U << 7)
|
||||
#define EXTENT_BUFFER_FILLED (1U << 8)
|
||||
#define EXTENT_CSUM (1U << 9)
|
||||
#define EXTENT_BAD_TRANSID (1U << 10)
|
||||
#define EXTENT_BUFFER_DUMMY (1U << 11)
|
||||
#define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
|
||||
|
||||
#define BLOCK_GROUP_DATA (1U << 1)
|
||||
#define BLOCK_GROUP_METADATA (1U << 2)
|
||||
#define BLOCK_GROUP_SYSTEM (1U << 4)
|
||||
|
||||
/*
|
||||
* The extent buffer bitmap operations are done with byte granularity instead of
|
||||
* word granularity for two reasons:
|
||||
* 1. The bitmaps must be little-endian on disk.
|
||||
* 2. Bitmap items are not guaranteed to be aligned to a word and therefore a
|
||||
* single word in a bitmap may straddle two pages in the extent buffer.
|
||||
*/
|
||||
#define BIT_BYTE(nr) ((nr) / BITS_PER_BYTE)
|
||||
#define BYTE_MASK ((1 << BITS_PER_BYTE) - 1)
|
||||
#define BITMAP_FIRST_BYTE_MASK(start) \
|
||||
((BYTE_MASK << ((start) & (BITS_PER_BYTE - 1))) & BYTE_MASK)
|
||||
#define BITMAP_LAST_BYTE_MASK(nbits) \
|
||||
(BYTE_MASK >> (-(nbits) & (BITS_PER_BYTE - 1)))
|
||||
|
||||
static inline int le_test_bit(int nr, const u8 *addr)
|
||||
{
|
||||
return 1U & (addr[BIT_BYTE(nr)] >> (nr & (BITS_PER_BYTE-1)));
|
||||
}
|
||||
|
||||
struct btrfs_fs_info;
|
||||
|
||||
struct extent_io_tree {
|
||||
struct cache_tree state;
|
||||
struct cache_tree cache;
|
||||
struct list_head lru;
|
||||
u64 cache_size;
|
||||
u64 max_cache_size;
|
||||
};
|
||||
|
||||
struct extent_state {
|
||||
struct cache_extent cache_node;
|
||||
u64 start;
|
||||
u64 end;
|
||||
int refs;
|
||||
unsigned long state;
|
||||
u64 xprivate;
|
||||
};
|
||||
|
||||
struct extent_buffer {
|
||||
struct cache_extent cache_node;
|
||||
u64 start;
|
||||
struct list_head lru;
|
||||
struct list_head recow;
|
||||
u32 len;
|
||||
int refs;
|
||||
u32 flags;
|
||||
struct btrfs_fs_info *fs_info;
|
||||
char data[] __attribute__((aligned(8)));
|
||||
};
|
||||
|
||||
static inline void extent_buffer_get(struct extent_buffer *eb)
|
||||
{
|
||||
eb->refs++;
|
||||
}
|
||||
|
||||
void extent_io_tree_init(struct extent_io_tree *tree);
|
||||
void extent_io_tree_init_cache_max(struct extent_io_tree *tree,
|
||||
u64 max_cache_size);
|
||||
void extent_io_tree_cleanup(struct extent_io_tree *tree);
|
||||
int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, int bits);
|
||||
int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, int bits);
|
||||
int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
|
||||
u64 *start_ret, u64 *end_ret, int bits);
|
||||
int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
||||
int bits, int filled);
|
||||
int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end);
|
||||
int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end);
|
||||
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_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;
|
||||
}
|
||||
|
||||
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);
|
||||
struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree,
|
||||
u64 bytenr, u32 blocksize);
|
||||
struct extent_buffer *find_first_extent_buffer(struct extent_io_tree *tree,
|
||||
u64 start);
|
||||
struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
|
||||
u64 bytenr, u32 blocksize);
|
||||
struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src);
|
||||
struct extent_buffer *alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
|
||||
u64 bytenr, u32 blocksize);
|
||||
void free_extent_buffer(struct extent_buffer *eb);
|
||||
void free_extent_buffer_nocache(struct extent_buffer *eb);
|
||||
int memcmp_extent_buffer(const struct extent_buffer *eb, const void *ptrv,
|
||||
unsigned long start, unsigned long len);
|
||||
void read_extent_buffer(const 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);
|
||||
int extent_buffer_test_bit(struct extent_buffer *eb, unsigned long start,
|
||||
unsigned long nr);
|
||||
int set_extent_buffer_dirty(struct extent_buffer *eb);
|
||||
int clear_extent_buffer_dirty(struct extent_buffer *eb);
|
||||
int read_data_from_disk(struct btrfs_fs_info *info, void *buf, u64 logical,
|
||||
u64 *len, int mirror);
|
||||
int write_data_to_disk(struct btrfs_fs_info *info, void *buf, u64 offset,
|
||||
u64 bytes, int mirror);
|
||||
void extent_buffer_bitmap_clear(struct extent_buffer *eb, unsigned long start,
|
||||
unsigned long pos, unsigned long len);
|
||||
void extent_buffer_bitmap_set(struct extent_buffer *eb, unsigned long start,
|
||||
unsigned long pos, unsigned long len);
|
||||
|
||||
#endif
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include "kernel-shared/send.h"
|
||||
#include "libbtrfs/send.h"
|
||||
#include "libbtrfs/send-stream.h"
|
||||
#include "crypto/crc32c.h"
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "kernel-shared/ctree.h"
|
||||
#include "libbtrfs/ctree.h"
|
||||
#include "libbtrfs/send-utils.h"
|
||||
#include "ioctl.h"
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#if BTRFS_FLAT_INCLUDES
|
||||
#include "kerncompat.h"
|
||||
#include "kernel-shared/ctree.h"
|
||||
#include "libbtrfs/ctree.h"
|
||||
#include "kernel-lib/rbtree.h"
|
||||
#else
|
||||
#include <btrfs/kerncompat.h>
|
||||
|
|
|
@ -0,0 +1,147 @@
|
|||
/*
|
||||
* Copyright (C) 2012 Alexander Block. All rights reserved.
|
||||
* Copyright (C) 2012 STRATO. 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_SEND_H__
|
||||
#define __BTRFS_SEND_H__
|
||||
|
||||
#if BTRFS_FLAT_INCLUDES
|
||||
#include "libbtrfs/ctree.h"
|
||||
#else
|
||||
#include <btrfs/ctree.h>
|
||||
#endif /* BTRFS_FLAT_INCLUDES */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define BTRFS_SEND_STREAM_MAGIC "btrfs-stream"
|
||||
#define BTRFS_SEND_STREAM_VERSION 1
|
||||
|
||||
#define BTRFS_SEND_BUF_SIZE (64 * 1024)
|
||||
#define BTRFS_SEND_READ_SIZE (1024 * 48)
|
||||
|
||||
enum btrfs_tlv_type {
|
||||
BTRFS_TLV_U8,
|
||||
BTRFS_TLV_U16,
|
||||
BTRFS_TLV_U32,
|
||||
BTRFS_TLV_U64,
|
||||
BTRFS_TLV_BINARY,
|
||||
BTRFS_TLV_STRING,
|
||||
BTRFS_TLV_UUID,
|
||||
BTRFS_TLV_TIMESPEC,
|
||||
};
|
||||
|
||||
struct btrfs_stream_header {
|
||||
char magic[sizeof(BTRFS_SEND_STREAM_MAGIC)];
|
||||
__le32 version;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct btrfs_cmd_header {
|
||||
/* len excluding the header */
|
||||
__le32 len;
|
||||
__le16 cmd;
|
||||
/* crc including the header with zero crc field */
|
||||
__le32 crc;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct btrfs_tlv_header {
|
||||
__le16 tlv_type;
|
||||
/* len excluding the header */
|
||||
__le16 tlv_len;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
/* commands */
|
||||
enum btrfs_send_cmd {
|
||||
BTRFS_SEND_C_UNSPEC,
|
||||
|
||||
BTRFS_SEND_C_SUBVOL,
|
||||
BTRFS_SEND_C_SNAPSHOT,
|
||||
|
||||
BTRFS_SEND_C_MKFILE,
|
||||
BTRFS_SEND_C_MKDIR,
|
||||
BTRFS_SEND_C_MKNOD,
|
||||
BTRFS_SEND_C_MKFIFO,
|
||||
BTRFS_SEND_C_MKSOCK,
|
||||
BTRFS_SEND_C_SYMLINK,
|
||||
|
||||
BTRFS_SEND_C_RENAME,
|
||||
BTRFS_SEND_C_LINK,
|
||||
BTRFS_SEND_C_UNLINK,
|
||||
BTRFS_SEND_C_RMDIR,
|
||||
|
||||
BTRFS_SEND_C_SET_XATTR,
|
||||
BTRFS_SEND_C_REMOVE_XATTR,
|
||||
|
||||
BTRFS_SEND_C_WRITE,
|
||||
BTRFS_SEND_C_CLONE,
|
||||
|
||||
BTRFS_SEND_C_TRUNCATE,
|
||||
BTRFS_SEND_C_CHMOD,
|
||||
BTRFS_SEND_C_CHOWN,
|
||||
BTRFS_SEND_C_UTIMES,
|
||||
|
||||
BTRFS_SEND_C_END,
|
||||
BTRFS_SEND_C_UPDATE_EXTENT,
|
||||
__BTRFS_SEND_C_MAX,
|
||||
};
|
||||
#define BTRFS_SEND_C_MAX (__BTRFS_SEND_C_MAX - 1)
|
||||
|
||||
/* attributes in send stream */
|
||||
enum {
|
||||
BTRFS_SEND_A_UNSPEC,
|
||||
|
||||
BTRFS_SEND_A_UUID,
|
||||
BTRFS_SEND_A_CTRANSID,
|
||||
|
||||
BTRFS_SEND_A_INO,
|
||||
BTRFS_SEND_A_SIZE,
|
||||
BTRFS_SEND_A_MODE,
|
||||
BTRFS_SEND_A_UID,
|
||||
BTRFS_SEND_A_GID,
|
||||
BTRFS_SEND_A_RDEV,
|
||||
BTRFS_SEND_A_CTIME,
|
||||
BTRFS_SEND_A_MTIME,
|
||||
BTRFS_SEND_A_ATIME,
|
||||
BTRFS_SEND_A_OTIME,
|
||||
|
||||
BTRFS_SEND_A_XATTR_NAME,
|
||||
BTRFS_SEND_A_XATTR_DATA,
|
||||
|
||||
BTRFS_SEND_A_PATH,
|
||||
BTRFS_SEND_A_PATH_TO,
|
||||
BTRFS_SEND_A_PATH_LINK,
|
||||
|
||||
BTRFS_SEND_A_FILE_OFFSET,
|
||||
BTRFS_SEND_A_DATA,
|
||||
|
||||
BTRFS_SEND_A_CLONE_UUID,
|
||||
BTRFS_SEND_A_CLONE_CTRANSID,
|
||||
BTRFS_SEND_A_CLONE_PATH,
|
||||
BTRFS_SEND_A_CLONE_OFFSET,
|
||||
BTRFS_SEND_A_CLONE_LEN,
|
||||
|
||||
__BTRFS_SEND_A_MAX,
|
||||
};
|
||||
#define BTRFS_SEND_A_MAX (__BTRFS_SEND_A_MAX - 1)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue