2013-06-27 05:42:39 +04:00
|
|
|
/*
|
|
|
|
* Author: Kent Overstreet <kmo@daterainc.com>
|
|
|
|
*
|
|
|
|
* GPLv2
|
|
|
|
*/
|
|
|
|
|
2010-10-08 18:04:49 +04:00
|
|
|
#ifndef _BCACHE_H
|
|
|
|
#define _BCACHE_H
|
|
|
|
|
2014-08-26 06:11:59 +04:00
|
|
|
#include <linux/bcache.h>
|
2014-11-06 06:38:27 +03:00
|
|
|
#include <dirent.h>
|
2011-08-01 06:29:22 +04:00
|
|
|
|
2014-09-12 02:55:39 +04:00
|
|
|
typedef __u8 u8;
|
|
|
|
typedef __u16 u16;
|
|
|
|
typedef __u32 u32;
|
|
|
|
typedef __u64 u64;
|
|
|
|
|
|
|
|
typedef __s8 s8;
|
|
|
|
typedef __s16 s16;
|
|
|
|
typedef __s32 s32;
|
|
|
|
typedef __s64 s64;
|
|
|
|
|
2013-03-09 17:58:57 +04:00
|
|
|
#define SB_START (SB_SECTOR * 512)
|
2014-11-25 02:53:35 +03:00
|
|
|
#define MAX_PATH 256
|
2014-12-16 05:10:25 +03:00
|
|
|
#define MAX_DEVS MAX_CACHES_PER_SET
|
2014-09-26 05:34:24 +04:00
|
|
|
|
2015-02-10 08:51:56 +03:00
|
|
|
#define min(x, y) ({ \
|
|
|
|
typeof(x) _min1 = (x); \
|
|
|
|
typeof(y) _min2 = (y); \
|
|
|
|
(void) (&_min1 == &_min2); \
|
|
|
|
_min1 < _min2 ? _min1 : _min2; })
|
|
|
|
|
2014-09-26 05:34:24 +04:00
|
|
|
#define max(x, y) ({ \
|
|
|
|
typeof(x) _max1 = (x); \
|
|
|
|
typeof(y) _max2 = (y); \
|
|
|
|
(void) (&_max1 == &_max2); \
|
|
|
|
_max1 > _max2 ? _max1 : _max2; })
|
|
|
|
|
2015-01-15 12:33:48 +03:00
|
|
|
#define __bkey_idx(_set, _offset) \
|
|
|
|
((_set)->_data + (_offset))
|
|
|
|
|
|
|
|
#define bkey_idx(_set, _offset) \
|
|
|
|
((typeof(&(_set)->start[0])) __bkey_idx((_set), (_offset)))
|
|
|
|
|
|
|
|
#define bkey_next(_k) \
|
|
|
|
((typeof(_k)) __bkey_idx(_k, (_k)->u64s))
|
|
|
|
|
|
|
|
#define __bset_bkey_last(_set) \
|
2015-01-22 10:11:47 +03:00
|
|
|
__bkey_idx((_set), (_set)->u64s)
|
2015-01-15 12:33:48 +03:00
|
|
|
|
|
|
|
#define bset_bkey_last(_set) \
|
2015-01-22 10:11:47 +03:00
|
|
|
bkey_idx((_set), (_set)->u64s)
|
2015-01-15 12:33:48 +03:00
|
|
|
|
2014-08-26 06:11:59 +04:00
|
|
|
extern const char * const cache_state[];
|
|
|
|
extern const char * const replacement_policies[];
|
|
|
|
extern const char * const csum_types[];
|
|
|
|
extern const char * const bdev_cache_mode[];
|
|
|
|
extern const char * const bdev_state[];
|
2015-01-28 00:45:02 +03:00
|
|
|
extern const char * const set_attr[];
|
|
|
|
extern const char * const cache_attrs[];
|
|
|
|
extern const char * const internal_attrs[];
|
2014-08-26 06:11:59 +04:00
|
|
|
|
|
|
|
ssize_t read_string_list(const char *, const char * const[]);
|
|
|
|
ssize_t read_string_list_or_die(const char *, const char * const[],
|
|
|
|
const char *);
|
|
|
|
void print_string_list(const char * const[], size_t);
|
|
|
|
|
|
|
|
uint64_t bch_checksum(unsigned, const void *, size_t);
|
|
|
|
|
2014-09-26 05:34:24 +04:00
|
|
|
uint64_t getblocks(int);
|
|
|
|
uint64_t hatoi(const char *);
|
|
|
|
unsigned hatoi_validate(const char *, const char *);
|
2015-01-21 09:18:35 +03:00
|
|
|
void write_backingdev_sb(int, unsigned, unsigned *, unsigned, uint64_t,
|
2015-01-22 10:11:47 +03:00
|
|
|
const char *, uuid_le, uuid_le);
|
2014-09-26 05:34:24 +04:00
|
|
|
int dev_open(const char *, bool);
|
2015-02-10 08:51:56 +03:00
|
|
|
void write_cache_sbs(int *, struct cache_sb *, unsigned,
|
|
|
|
unsigned *, int, unsigned);
|
2014-11-13 04:51:42 +03:00
|
|
|
void next_cache_device(struct cache_sb *, unsigned, int, unsigned, bool);
|
2014-09-26 05:34:24 +04:00
|
|
|
unsigned get_blocksize(const char *);
|
|
|
|
long strtoul_or_die(const char *, size_t, const char *);
|
|
|
|
|
|
|
|
void show_super_backingdev(struct cache_sb *, bool);
|
|
|
|
void show_super_cache(struct cache_sb *, bool);
|
|
|
|
|
2014-12-10 05:03:47 +03:00
|
|
|
enum sysfs_attr {SET_ATTR, CACHE_ATTR, INTERNAL_ATTR};
|
|
|
|
|
2015-01-28 00:45:02 +03:00
|
|
|
enum sysfs_attr sysfs_attr_type(const char *attr);
|
2014-12-10 05:03:47 +03:00
|
|
|
void sysfs_attr_list();
|
|
|
|
|
2014-11-19 01:14:13 +03:00
|
|
|
struct cache_sb *query_dev(char *, bool, bool, bool, char *dev_uuid);
|
2014-11-25 04:16:55 +03:00
|
|
|
char *list_cachesets(char *, bool);
|
2014-11-06 04:45:57 +03:00
|
|
|
char *parse_array_to_list(char *const *);
|
2014-11-25 04:16:55 +03:00
|
|
|
char *register_bcache(char *const *);
|
|
|
|
char *unregister_bcache(char *const *);
|
|
|
|
char *probe(char *, int);
|
2014-12-16 05:10:25 +03:00
|
|
|
char *read_stat_dir(DIR *, char *, char *, char *);
|
2014-11-25 04:16:55 +03:00
|
|
|
char *find_matching_uuid(char *, char *, const char*);
|
2015-01-15 03:36:49 +03:00
|
|
|
char *add_devices(char *const *);
|
2014-11-26 05:36:05 +03:00
|
|
|
char *remove_device(const char *, bool);
|
2014-12-16 05:10:25 +03:00
|
|
|
char *bcache_get_capacity(const char *, const char *, bool);
|
2015-01-13 01:57:41 +03:00
|
|
|
char *dev_name(const char *);
|
2015-01-15 03:36:49 +03:00
|
|
|
char *device_set_failed(const char *dev_uuid);
|
2014-10-16 06:00:40 +04:00
|
|
|
|
2014-08-26 06:11:59 +04:00
|
|
|
#define csum_set(i, type) \
|
|
|
|
({ \
|
|
|
|
void *start = ((void *) (i)) + sizeof(uint64_t); \
|
2015-01-15 12:33:48 +03:00
|
|
|
void *end = __bset_bkey_last(i); \
|
2014-08-26 06:11:59 +04:00
|
|
|
\
|
|
|
|
bch_checksum(type, start, end - start); \
|
|
|
|
})
|
2011-07-26 21:02:15 +04:00
|
|
|
|
2010-10-08 18:04:49 +04:00
|
|
|
#endif
|