diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2017-12-28 01:01:16 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2017-12-28 02:55:08 -0500 |
commit | aca9f96dcce97be69437248c119a1b83b3a3ed90 (patch) | |
tree | 5d8ef32acf816e1134db09662c3a3cc4c8a46837 /libbcachefs.h | |
parent | 9d2dfea54b4b4471b28f71d9e9e8b5760268bf22 (diff) |
Resizing
Diffstat (limited to 'libbcachefs.h')
-rw-r--r-- | libbcachefs.h | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/libbcachefs.h b/libbcachefs.h index 836cb7a9..97f4b2d8 100644 --- a/libbcachefs.h +++ b/libbcachefs.h @@ -5,6 +5,7 @@ #include <stdbool.h> #include "libbcachefs/bcachefs_format.h" +#include "libbcachefs/bcachefs_ioctl.h" #include "tools-util.h" #include "libbcachefs/vstructs.h" @@ -76,4 +77,103 @@ struct bch_sb *__bch2_super_read(int, u64); void bch2_super_print(struct bch_sb *, int); +/* ioctl interface: */ + +int bcachectl_open(void); + +struct bchfs_handle { + uuid_le uuid; + int ioctl_fd; + int sysfs_fd; +}; + +void bcache_fs_close(struct bchfs_handle); +struct bchfs_handle bcache_fs_open(const char *); + +static inline void bchu_disk_add(struct bchfs_handle fs, char *dev) +{ + struct bch_ioctl_disk i = { .dev = (__u64) dev, }; + + xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_ADD, &i); +} + +static inline void bchu_disk_set_state(struct bchfs_handle fs, const char *dev, + unsigned new_state, unsigned flags) +{ + struct bch_ioctl_disk_set_state i = { + .flags = flags, + .new_state = new_state, + }; + + if (!kstrtoull(dev, 10, &i.dev)) + i.flags |= BCH_BY_INDEX; + else + i.dev = (u64) dev; + + xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_SET_STATE, &i); +} + +static inline struct bch_ioctl_usage *bchu_usage(struct bchfs_handle fs) +{ + struct bch_ioctl_usage *u = NULL; + unsigned nr_devices = 4; + + while (1) { + u = xrealloc(u, sizeof(*u) + sizeof(u->devs[0]) * nr_devices); + u->nr_devices = nr_devices; + + if (!ioctl(fs.ioctl_fd, BCH_IOCTL_USAGE, u)) + return u; + + if (errno != ENOSPC) + die("BCH_IOCTL_USAGE error: %m"); + nr_devices *= 2; + } +} + +static inline struct bch_sb *bchu_read_super(struct bchfs_handle fs, unsigned idx) +{ + size_t size = 4096; + struct bch_sb *sb = NULL; + + while (1) { + sb = xrealloc(sb, size); + struct bch_ioctl_read_super i = { + .size = size, + .sb = (u64) sb, + }; + + if (idx != -1) { + i.flags |= BCH_READ_DEV|BCH_BY_INDEX; + i.dev = idx; + } + + if (!ioctl(fs.ioctl_fd, BCH_IOCTL_READ_SUPER, &i)) + return sb; + if (errno != ERANGE) + die("BCH_IOCTL_READ_SUPER error: %m"); + size *= 2; + } +} + +static inline unsigned bchu_disk_get_idx(struct bchfs_handle fs, dev_t dev) +{ + struct bch_ioctl_disk_get_idx i = { .dev = dev }; + + return xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_GET_IDX, &i); +} + +static inline void bchu_disk_resize(struct bchfs_handle fs, + unsigned idx, + u64 nbuckets) +{ + struct bch_ioctl_disk_resize i = { + .flags = BCH_BY_INDEX, + .dev = idx, + .nbuckets = nbuckets, + }; + + xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_RESIZE, &i); +} + #endif /* _LIBBCACHE_H */ |