]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs.h
Fix some makefile misspellings
[bcachefs-tools-debian] / libbcachefs.h
index dc5098339eb22bdb1eeddd0c70faa15e0d4d4390..7cdbf69622548aa9f88bf982a65756a6673c8ef0 100644 (file)
@@ -6,29 +6,36 @@
 
 #include "libbcachefs/bcachefs_format.h"
 #include "libbcachefs/bcachefs_ioctl.h"
-#include "tools-util.h"
+#include "libbcachefs/opts.h"
 #include "libbcachefs/vstructs.h"
+#include "tools-util.h"
 
-struct format_opts {
-       char            *label;
-       uuid_le         uuid;
-
-       unsigned        on_error_action;
+/* option parsing */
 
-       unsigned        block_size;
-       unsigned        btree_node_size;
-       unsigned        encoded_extent_max;
+#define SUPERBLOCK_SIZE_DEFAULT                2048    /* 1 MB */
 
-       unsigned        meta_replicas;
-       unsigned        data_replicas;
-
-       unsigned        meta_replicas_required;
-       unsigned        data_replicas_required;
+struct bch_opt_strs {
+union {
+       char                    *by_id[bch2_opts_nr];
+struct {
+#define x(_name, ...)  char    *_name;
+       BCH_OPTS()
+#undef x
+};
+};
+};
 
-       unsigned        meta_csum_type;
-       unsigned        data_csum_type;
-       unsigned        compression_type;
+void bch2_opt_strs_free(struct bch_opt_strs *);
+struct bch_opt_strs bch2_cmdline_opts_get(int *, char *[], unsigned);
+struct bch_opts bch2_parse_opts(struct bch_opt_strs);
+void bch2_opts_usage(unsigned);
 
+struct format_opts {
+       char            *label;
+       uuid_le         uuid;
+       unsigned        version;
+       unsigned        superblock_size;
+       unsigned        encoded_extent_max;
        bool            encrypted;
        char            *passphrase;
 };
@@ -36,14 +43,9 @@ struct format_opts {
 static inline struct format_opts format_opts_default()
 {
        return (struct format_opts) {
-               .on_error_action        = BCH_ON_ERROR_RO,
+               .version                = bcachefs_metadata_version_current,
+               .superblock_size        = SUPERBLOCK_SIZE_DEFAULT,
                .encoded_extent_max     = 128,
-               .meta_csum_type         = BCH_CSUM_OPT_CRC32C,
-               .data_csum_type         = BCH_CSUM_OPT_CRC32C,
-               .meta_replicas          = 1,
-               .data_replicas          = 1,
-               .meta_replicas_required = 1,
-               .data_replicas_required = 1,
        };
 }
 
@@ -52,8 +54,9 @@ struct dev_opts {
        char            *path;
        u64             size; /* 512 byte sectors */
        unsigned        bucket_size;
-       unsigned        tier;
+       const char      *group;
        unsigned        data_allowed;
+       unsigned        durability;
        bool            discard;
 
        u64             nbuckets;
@@ -66,11 +69,14 @@ static inline struct dev_opts dev_opts_default()
 {
        return (struct dev_opts) {
                .data_allowed           = ~0U << 2,
+               .durability             = 1,
        };
 }
 
-void bch2_pick_bucket_size(struct format_opts, struct dev_opts *);
-struct bch_sb *bch2_format(struct format_opts, struct dev_opts *, size_t);
+void bch2_pick_bucket_size(struct bch_opts, struct dev_opts *);
+struct bch_sb *bch2_format(struct bch_opt_strs,
+                          struct bch_opts,
+                          struct format_opts, struct dev_opts *, size_t);
 
 void bch2_super_write(int, struct bch_sb *);
 struct bch_sb *__bch2_super_read(int, u64);
@@ -89,48 +95,86 @@ struct bchfs_handle {
 
 void bcache_fs_close(struct bchfs_handle);
 struct bchfs_handle bcache_fs_open(const char *);
+struct bchfs_handle bchu_fs_open_by_dev(const char *, int *);
+int bchu_dev_path_to_idx(struct bchfs_handle, const char *);
 
 static inline void bchu_disk_add(struct bchfs_handle fs, char *dev)
 {
-       struct bch_ioctl_disk i = { .dev = (__u64) dev, };
+       struct bch_ioctl_disk i = { .dev = (unsigned long) dev, };
 
        xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_ADD, &i);
 }
 
-static inline void bchu_disk_set_state(struct bchfs_handle fs, const char *dev,
+static inline void bchu_disk_remove(struct bchfs_handle fs, unsigned dev_idx,
+                                   unsigned flags)
+{
+       struct bch_ioctl_disk i = {
+               .flags  = flags|BCH_BY_INDEX,
+               .dev    = dev_idx,
+       };
+
+       xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_REMOVE, &i);
+}
+
+static inline void bchu_disk_online(struct bchfs_handle fs, char *dev)
+{
+       struct bch_ioctl_disk i = { .dev = (unsigned long) dev, };
+
+       xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_ONLINE, &i);
+}
+
+static inline void bchu_disk_offline(struct bchfs_handle fs, unsigned dev_idx,
+                                    unsigned flags)
+{
+       struct bch_ioctl_disk i = {
+               .flags  = flags|BCH_BY_INDEX,
+               .dev    = dev_idx,
+       };
+
+       xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_OFFLINE, &i);
+}
+
+static inline void bchu_disk_set_state(struct bchfs_handle fs, unsigned dev,
                                       unsigned new_state, unsigned flags)
 {
        struct bch_ioctl_disk_set_state i = {
-               .flags          = flags,
+               .flags          = flags|BCH_BY_INDEX,
                .new_state      = new_state,
+               .dev            = dev,
        };
 
-       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)
+static inline struct bch_ioctl_fs_usage *bchu_fs_usage(struct bchfs_handle fs)
 {
-       struct bch_ioctl_usage *u = NULL;
-       unsigned nr_devices = 4;
+       struct bch_ioctl_fs_usage *u = NULL;
+       size_t replica_entries_bytes = 4096;
 
        while (1) {
-               u = xrealloc(u, sizeof(*u) + sizeof(u->devs[0]) * nr_devices);
-               u->nr_devices = nr_devices;
+               u = xrealloc(u, sizeof(*u) + replica_entries_bytes);
+               u->replica_entries_bytes = replica_entries_bytes;
 
-               if (!ioctl(fs.ioctl_fd, BCH_IOCTL_USAGE, u))
+               if (!ioctl(fs.ioctl_fd, BCH_IOCTL_FS_USAGE, u))
                        return u;
 
-               if (errno != ENOSPC)
+               if (errno != ERANGE)
                        die("BCH_IOCTL_USAGE error: %m");
-               nr_devices *= 2;
+
+               replica_entries_bytes *= 2;
        }
 }
 
+static inline struct bch_ioctl_dev_usage bchu_dev_usage(struct bchfs_handle fs,
+                                                       unsigned idx)
+{
+       struct bch_ioctl_dev_usage i = { .dev = idx, .flags = BCH_BY_INDEX};
+
+       if (xioctl(fs.ioctl_fd, BCH_IOCTL_DEV_USAGE, &i))
+               die("BCH_IOCTL_DEV_USAGE error: %m");
+       return i;
+}
+
 static inline struct bch_sb *bchu_read_super(struct bchfs_handle fs, unsigned idx)
 {
        size_t size = 4096;
@@ -140,7 +184,7 @@ static inline struct bch_sb *bchu_read_super(struct bchfs_handle fs, unsigned id
                sb = xrealloc(sb, size);
                struct bch_ioctl_read_super i = {
                        .size   = size,
-                       .sb     = (u64) sb,
+                       .sb     = (unsigned long) sb,
                };
 
                if (idx != -1) {
@@ -176,4 +220,29 @@ static inline void bchu_disk_resize(struct bchfs_handle fs,
        xioctl(fs.ioctl_fd, BCH_IOCTL_DISK_RESIZE, &i);
 }
 
+static inline void bchu_disk_resize_journal(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_JOURNAL, &i);
+}
+
+int bchu_data(struct bchfs_handle, struct bch_ioctl_data);
+
+struct dev_name {
+       unsigned        idx;
+       char            *dev;
+       char            *label;
+       uuid_le         uuid;
+};
+typedef darray(struct dev_name) dev_names;
+
+dev_names bchu_fs_get_devices(struct bchfs_handle);
+
 #endif /* _LIBBCACHE_H */