4 #include <linux/uuid.h>
7 #include "libbcachefs/bcachefs_format.h"
8 #include "libbcachefs/bcachefs_ioctl.h"
9 #include "libbcachefs/opts.h"
10 #include "libbcachefs/vstructs.h"
11 #include "tools-util.h"
17 char *by_id[bch2_opts_nr];
19 #define x(_name, ...) char *_name;
26 struct bch_opt_strs bch2_cmdline_opts_get(int *, char *[], unsigned);
27 struct bch_opts bch2_parse_opts(struct bch_opt_strs);
28 void bch2_opts_usage(unsigned);
34 unsigned encoded_extent_max;
40 static inline struct format_opts format_opts_default()
42 return (struct format_opts) {
43 .encoded_extent_max = 128,
50 u64 size; /* 512 byte sectors */
53 unsigned data_allowed;
63 static inline struct dev_opts dev_opts_default()
65 return (struct dev_opts) {
66 .data_allowed = ~0U << 2,
71 void bch2_pick_bucket_size(struct bch_opts, struct dev_opts *);
72 struct bch_sb *bch2_format(struct bch_opt_strs,
74 struct format_opts, struct dev_opts *, size_t);
76 void bch2_super_write(int, struct bch_sb *);
77 struct bch_sb *__bch2_super_read(int, u64);
79 void bch2_sb_print(struct bch_sb *, bool, unsigned, enum units);
81 /* ioctl interface: */
83 int bcachectl_open(void);
91 void bcache_fs_close(struct bchfs_handle);
92 struct bchfs_handle bcache_fs_open(const char *);
93 struct bchfs_handle bchu_fs_open_by_dev(const char *, unsigned *);
95 static inline void bchu_disk_add(struct bchfs_handle fs, char *dev)
97 struct bch_ioctl_disk i = { .dev = (unsigned long) dev, };
99 xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_ADD, &i);
102 static inline void bchu_disk_remove(struct bchfs_handle fs, unsigned dev_idx,
105 struct bch_ioctl_disk i = {
106 .flags = flags|BCH_BY_INDEX,
110 xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_REMOVE, &i);
113 static inline void bchu_disk_online(struct bchfs_handle fs, char *dev)
115 struct bch_ioctl_disk i = { .dev = (unsigned long) dev, };
117 xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_ONLINE, &i);
120 static inline void bchu_disk_offline(struct bchfs_handle fs, unsigned dev_idx,
123 struct bch_ioctl_disk i = {
124 .flags = flags|BCH_BY_INDEX,
128 xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_OFFLINE, &i);
131 static inline void bchu_disk_set_state(struct bchfs_handle fs, unsigned dev,
132 unsigned new_state, unsigned flags)
134 struct bch_ioctl_disk_set_state i = {
135 .flags = flags|BCH_BY_INDEX,
136 .new_state = new_state,
140 xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_SET_STATE, &i);
143 static inline struct bch_ioctl_fs_usage *bchu_fs_usage(struct bchfs_handle fs)
145 struct bch_ioctl_fs_usage *u = NULL;
146 size_t replica_entries_bytes = 4096;
149 u = xrealloc(u, sizeof(*u) + replica_entries_bytes);
150 u->replica_entries_bytes = replica_entries_bytes;
152 if (!ioctl(fs.ioctl_fd, BCH_IOCTL_FS_USAGE, u))
156 die("BCH_IOCTL_USAGE error: %m");
158 replica_entries_bytes *= 2;
162 static inline struct bch_ioctl_dev_usage bchu_dev_usage(struct bchfs_handle fs,
165 struct bch_ioctl_dev_usage i = { .dev = idx, .flags = BCH_BY_INDEX};
167 if (xioctl(fs.ioctl_fd, BCH_IOCTL_DEV_USAGE, &i))
168 die("BCH_IOCTL_DEV_USAGE error: %m");
172 static inline struct bch_sb *bchu_read_super(struct bchfs_handle fs, unsigned idx)
175 struct bch_sb *sb = NULL;
178 sb = xrealloc(sb, size);
179 struct bch_ioctl_read_super i = {
181 .sb = (unsigned long) sb,
185 i.flags |= BCH_READ_DEV|BCH_BY_INDEX;
189 if (!ioctl(fs.ioctl_fd, BCH_IOCTL_READ_SUPER, &i))
192 die("BCH_IOCTL_READ_SUPER error: %m");
197 static inline unsigned bchu_disk_get_idx(struct bchfs_handle fs, dev_t dev)
199 struct bch_ioctl_disk_get_idx i = { .dev = dev };
201 return xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_GET_IDX, &i);
204 static inline void bchu_disk_resize(struct bchfs_handle fs,
208 struct bch_ioctl_disk_resize i = {
209 .flags = BCH_BY_INDEX,
211 .nbuckets = nbuckets,
214 xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_RESIZE, &i);
217 int bchu_data(struct bchfs_handle, struct bch_ioctl_data);
225 typedef darray(struct dev_name) dev_names;
227 dev_names bchu_fs_get_devices(struct bchfs_handle);
229 #endif /* _LIBBCACHE_H */