2 * Author: Kent Overstreet <kmo@daterainc.com>
10 #include <linux/bcache.h>
23 #define SB_START (SB_SECTOR * 512)
25 #define MAX_DEVS MAX_CACHES_PER_SET
27 #define max(x, y) ({ \
28 typeof(x) _max1 = (x); \
29 typeof(y) _max2 = (y); \
30 (void) (&_max1 == &_max2); \
31 _max1 > _max2 ? _max1 : _max2; })
33 extern const char * const cache_state[];
34 extern const char * const replacement_policies[];
35 extern const char * const csum_types[];
36 extern const char * const bdev_cache_mode[];
37 extern const char * const bdev_state[];
39 ssize_t read_string_list(const char *, const char * const[]);
40 ssize_t read_string_list_or_die(const char *, const char * const[],
42 void print_string_list(const char * const[], size_t);
44 uint64_t bch_checksum(unsigned, const void *, size_t);
46 uint64_t getblocks(int);
47 uint64_t hatoi(const char *);
48 unsigned hatoi_validate(const char *, const char *);
49 void write_backingdev_sb(int, unsigned, unsigned *, bool, uint64_t,
50 const char *, uuid_le);
51 int dev_open(const char *, bool);
52 void write_cache_sbs(int *, struct cache_sb *, unsigned, unsigned *, int);
53 void next_cache_device(struct cache_sb *, unsigned, int, unsigned, bool);
54 unsigned get_blocksize(const char *);
55 long strtoul_or_die(const char *, size_t, const char *);
57 void show_super_backingdev(struct cache_sb *, bool);
58 void show_super_cache(struct cache_sb *, bool);
60 enum sysfs_attr {SET_ATTR, CACHE_ATTR, INTERNAL_ATTR};
62 static const char *set_attrs[] = {
64 "btree_scan_ratelimit",
65 "bucket_reserve_percent",
66 "cache_reserve_percent",
68 "congested_read_threshold_us",
69 "congested_write_threshold_us",
72 "foreground_target_percent",
76 "sector_reserve_percent",
81 static const char *cache_attrs[] = {
82 "cache_replacement_policy",
89 static const char *internal_attrs[] = {
90 "btree_shrinker_disabled",
92 "foreground_write_rate",
98 enum sysfs_attr sysfs_attr_type(char *attr);
99 void sysfs_attr_list();
101 struct cache_sb *query_dev(char *, bool, bool, bool, char *dev_uuid);
102 char *list_cachesets(char *, bool);
103 char *parse_array_to_list(char *const *);
104 char *register_bcache(char *const *);
105 char *unregister_bcache(char *const *);
106 char *probe(char *, int);
107 char *read_stat_dir(DIR *, char *, char *, char *);
108 char *find_matching_uuid(char *, char *, const char*);
109 char *add_devices(char *const *, char *);
110 char *remove_device(const char *, bool);
111 char *bcache_get_capacity(const char *, const char *, bool);
113 #define csum_set(i, type) \
115 void *start = ((void *) (i)) + sizeof(uint64_t); \
116 void *end = bset_bkey_last(i); \
118 bch_checksum(type, start, end - start); \