2 * Author: Kent Overstreet <kmo@daterainc.com>
13 #define __packed __attribute__((__packed__))
15 #include "bcache-ondisk.h"
16 #include "bcache-ioctl.h"
28 #define SB_START (SB_SECTOR * 512)
30 #define MAX_DEVS MAX_CACHES_PER_SET
32 #define min(x, y) ({ \
33 typeof(x) _min1 = (x); \
34 typeof(y) _min2 = (y); \
35 (void) (&_min1 == &_min2); \
36 _min1 < _min2 ? _min1 : _min2; })
38 #define max(x, y) ({ \
39 typeof(x) _max1 = (x); \
40 typeof(y) _max2 = (y); \
41 (void) (&_max1 == &_max2); \
42 _max1 > _max2 ? _max1 : _max2; })
44 #define __bkey_idx(_set, _offset) \
45 ((_set)->_data + (_offset))
47 #define bkey_idx(_set, _offset) \
48 ((typeof(&(_set)->start[0])) __bkey_idx((_set), (_offset)))
50 #define bkey_next(_k) \
51 ((typeof(_k)) __bkey_idx(_k, (_k)->u64s))
53 #define __bset_bkey_last(_set) \
54 __bkey_idx((_set), (_set)->u64s)
56 #define bset_bkey_last(_set) \
57 bkey_idx((_set), (_set)->u64s)
59 extern const char * const cache_state[];
60 extern const char * const replacement_policies[];
61 extern const char * const csum_types[];
62 extern const char * const compression_types[];
63 extern const char * const error_actions[];
64 extern const char * const bdev_cache_mode[];
65 extern const char * const bdev_state[];
66 extern const char * const set_attr[];
67 extern const char * const cache_attrs[];
68 extern const char * const internal_attrs[];
70 ssize_t read_string_list(const char *, const char * const[]);
71 ssize_t read_string_list_or_die(const char *, const char * const[],
73 void print_string_list(const char * const[], size_t);
75 uint64_t bch_checksum(unsigned, const void *, size_t);
77 uint64_t getblocks(int);
78 uint64_t hatoi(const char *);
79 unsigned hatoi_validate(const char *, const char *);
80 int dev_open(const char *);
81 unsigned get_blocksize(const char *, int);
82 long strtoul_or_die(const char *, size_t, const char *);
84 void show_super_backingdev(struct cache_sb *, bool);
85 void show_super_cache(struct cache_sb *, bool);
87 enum sysfs_attr {SET_ATTR, CACHE_ATTR, INTERNAL_ATTR};
89 enum sysfs_attr sysfs_attr_type(const char *attr);
90 void sysfs_attr_list();
92 struct cache_sb *query_dev(char *, bool, bool, bool, char *dev_uuid);
93 char *parse_array_to_list(char *const *);
94 char *register_bcache(char *const *);
95 char *find_matching_uuid(char *, char *, const char*);
96 char *dev_name(const char *);
98 int bcachectl_open(void);
99 unsigned nr_args(char * const *);
101 #define csum_set(i, type) \
103 void *start = ((void *) (i)) + sizeof(uint64_t); \
104 void *end = __bset_bkey_last(i); \
106 bch_checksum(type, start, end - start); \
109 #define die(arg, ...) \
111 fprintf(stderr, arg "\n", ##__VA_ARGS__); \
112 exit(EXIT_FAILURE); \