]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs.h
cmd_migrate: Fix fsck invocation
[bcachefs-tools-debian] / libbcachefs.h
index ab4f0cd67fa079306a89c71cc34f059d55c8308c..b189a208115f63266f1bfeba6ac47ca43fc05c45 100644 (file)
@@ -32,7 +32,7 @@ void bch2_opts_usage(unsigned);
 
 struct format_opts {
        char            *label;
-       uuid_le         uuid;
+       __uuid_t        uuid;
        unsigned        version;
        unsigned        superblock_size;
        bool            encrypted;
@@ -41,14 +41,18 @@ struct format_opts {
 
 static inline struct format_opts format_opts_default()
 {
+       unsigned version = !access(   "/sys/module/bcachefs/parameters/version", R_OK)
+           ? read_file_u64(AT_FDCWD, "/sys/module/bcachefs/parameters/version")
+           : bcachefs_metadata_version_current;
+
        return (struct format_opts) {
-               .version                = bcachefs_metadata_version_current,
+               .version                = version,
                .superblock_size        = SUPERBLOCK_SIZE_DEFAULT,
        };
 }
 
 struct dev_opts {
-       int             fd;
+       struct block_device *bdev;
        char            *path;
        u64             size;           /* bytes*/
        u64             bucket_size;    /* bytes */
@@ -71,7 +75,9 @@ static inline struct dev_opts dev_opts_default()
        };
 }
 
-void bch2_pick_bucket_size(struct bch_opts, struct dev_opts *);
+u64 bch2_pick_bucket_size(struct bch_opts, struct dev_opts *);
+void bch2_check_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);
@@ -79,16 +85,14 @@ struct bch_sb *bch2_format(struct bch_opt_strs,
 void bch2_super_write(int, struct bch_sb *);
 struct bch_sb *__bch2_super_read(int, u64);
 
-void bch2_sb_print(struct bch_sb *, bool, unsigned, enum units);
-
 /* ioctl interface: */
 
 int bcachectl_open(void);
 
 struct bchfs_handle {
-       uuid_le uuid;
-       int     ioctl_fd;
-       int     sysfs_fd;
+       __uuid_t        uuid;
+       int             ioctl_fd;
+       int             sysfs_fd;
 };
 
 void bcache_fs_close(struct bchfs_handle);
@@ -163,14 +167,30 @@ static inline struct bch_ioctl_fs_usage *bchu_fs_usage(struct bchfs_handle fs)
        }
 }
 
-static inline struct bch_ioctl_dev_usage bchu_dev_usage(struct bchfs_handle fs,
-                                                       unsigned idx)
+static inline struct bch_ioctl_dev_usage_v2 *bchu_dev_usage(struct bchfs_handle fs,
+                                                           unsigned idx)
 {
-       struct bch_ioctl_dev_usage i = { .dev = idx, .flags = BCH_BY_INDEX};
+       struct bch_ioctl_dev_usage_v2 *u = xcalloc(sizeof(*u) + sizeof(u->d[0]) * BCH_DATA_NR, 1);
+
+       u->dev                  = idx;
+       u->flags                = BCH_BY_INDEX;
+       u->nr_data_types        = BCH_DATA_NR;
+
+       if (!ioctl(fs.ioctl_fd, BCH_IOCTL_DEV_USAGE_V2, u))
+               return u;
 
-       if (xioctl(fs.ioctl_fd, BCH_IOCTL_DEV_USAGE, &i))
-               die("BCH_IOCTL_DEV_USAGE error: %m");
-       return i;
+       struct bch_ioctl_dev_usage u_v1 = { .dev = idx, .flags = BCH_BY_INDEX};
+       xioctl(fs.ioctl_fd, BCH_IOCTL_DEV_USAGE, &u_v1);
+
+       u->state        = u_v1.state;
+       u->nr_data_types = ARRAY_SIZE(u_v1.d);
+       u->bucket_size  = u_v1.bucket_size;
+       u->nr_buckets   = u_v1.nr_buckets;
+
+       for (unsigned i = 0; i < ARRAY_SIZE(u_v1.d); i++)
+               u->d[i] = u_v1.d[i];
+
+       return u;
 }
 
 static inline struct bch_sb *bchu_read_super(struct bchfs_handle fs, unsigned idx)
@@ -237,9 +257,10 @@ struct dev_name {
        unsigned        idx;
        char            *dev;
        char            *label;
-       uuid_le         uuid;
+       uuid_t          uuid;
+       unsigned        durability;
 };
-typedef darray(struct dev_name) dev_names;
+typedef DARRAY(struct dev_name) dev_names;
 
 dev_names bchu_fs_get_devices(struct bchfs_handle);