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);
35 unsigned encoded_extent_max;
41 static inline struct format_opts format_opts_default()
43 return (struct format_opts) {
44 .version = bcachefs_metadata_version_current,
45 .encoded_extent_max = 128,
52 u64 size; /* 512 byte sectors */
55 unsigned data_allowed;
65 static inline struct dev_opts dev_opts_default()
67 return (struct dev_opts) {
68 .data_allowed = ~0U << 2,
73 void bch2_pick_bucket_size(struct bch_opts, struct dev_opts *);
74 struct bch_sb *bch2_format(struct bch_opt_strs,
76 struct format_opts, struct dev_opts *, size_t);
78 void bch2_super_write(int, struct bch_sb *);
79 struct bch_sb *__bch2_super_read(int, u64);
81 void bch2_sb_print(struct bch_sb *, bool, unsigned, enum units);
83 /* ioctl interface: */
85 int bcachectl_open(void);
93 void bcache_fs_close(struct bchfs_handle);
94 struct bchfs_handle bcache_fs_open(const char *);
95 struct bchfs_handle bchu_fs_open_by_dev(const char *, unsigned *);
97 static inline void bchu_disk_add(struct bchfs_handle fs, char *dev)
99 struct bch_ioctl_disk i = { .dev = (unsigned long) dev, };
101 xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_ADD, &i);
104 static inline void bchu_disk_remove(struct bchfs_handle fs, unsigned dev_idx,
107 struct bch_ioctl_disk i = {
108 .flags = flags|BCH_BY_INDEX,
112 xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_REMOVE, &i);
115 static inline void bchu_disk_online(struct bchfs_handle fs, char *dev)
117 struct bch_ioctl_disk i = { .dev = (unsigned long) dev, };
119 xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_ONLINE, &i);
122 static inline void bchu_disk_offline(struct bchfs_handle fs, unsigned dev_idx,
125 struct bch_ioctl_disk i = {
126 .flags = flags|BCH_BY_INDEX,
130 xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_OFFLINE, &i);
133 static inline void bchu_disk_set_state(struct bchfs_handle fs, unsigned dev,
134 unsigned new_state, unsigned flags)
136 struct bch_ioctl_disk_set_state i = {
137 .flags = flags|BCH_BY_INDEX,
138 .new_state = new_state,
142 xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_SET_STATE, &i);
145 static inline struct bch_ioctl_fs_usage *bchu_fs_usage(struct bchfs_handle fs)
147 struct bch_ioctl_fs_usage *u = NULL;
148 size_t replica_entries_bytes = 4096;
151 u = xrealloc(u, sizeof(*u) + replica_entries_bytes);
152 u->replica_entries_bytes = replica_entries_bytes;
154 if (!ioctl(fs.ioctl_fd, BCH_IOCTL_FS_USAGE, u))
158 die("BCH_IOCTL_USAGE error: %m");
160 replica_entries_bytes *= 2;
164 static inline struct bch_ioctl_dev_usage bchu_dev_usage(struct bchfs_handle fs,
167 struct bch_ioctl_dev_usage i = { .dev = idx, .flags = BCH_BY_INDEX};
169 if (xioctl(fs.ioctl_fd, BCH_IOCTL_DEV_USAGE, &i))
170 die("BCH_IOCTL_DEV_USAGE error: %m");
174 static inline struct bch_sb *bchu_read_super(struct bchfs_handle fs, unsigned idx)
177 struct bch_sb *sb = NULL;
180 sb = xrealloc(sb, size);
181 struct bch_ioctl_read_super i = {
183 .sb = (unsigned long) sb,
187 i.flags |= BCH_READ_DEV|BCH_BY_INDEX;
191 if (!ioctl(fs.ioctl_fd, BCH_IOCTL_READ_SUPER, &i))
194 die("BCH_IOCTL_READ_SUPER error: %m");
199 static inline unsigned bchu_disk_get_idx(struct bchfs_handle fs, dev_t dev)
201 struct bch_ioctl_disk_get_idx i = { .dev = dev };
203 return xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_GET_IDX, &i);
206 static inline void bchu_disk_resize(struct bchfs_handle fs,
210 struct bch_ioctl_disk_resize i = {
211 .flags = BCH_BY_INDEX,
213 .nbuckets = nbuckets,
216 xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_RESIZE, &i);
219 static inline void bchu_disk_resize_journal(struct bchfs_handle fs,
223 struct bch_ioctl_disk_resize i = {
224 .flags = BCH_BY_INDEX,
226 .nbuckets = nbuckets,
229 xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_RESIZE_JOURNAL, &i);
232 int bchu_data(struct bchfs_handle, struct bch_ioctl_data);
240 typedef darray(struct dev_name) dev_names;
242 dev_names bchu_fs_get_devices(struct bchfs_handle);
244 #endif /* _LIBBCACHE_H */