mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-23 00:00:02 +03:00
Change open_for_format to the block io api
Upcoming patch will add device benchmarking at format time, which needs the bio API. Signed-off-by: Hunter Shaffer <huntershaffer182456@gmail.com>
This commit is contained in:
parent
b2ffa12074
commit
9f98746bfc
@ -113,7 +113,9 @@ int cmd_device_add(int argc, char *argv[])
|
|||||||
|
|
||||||
struct bchfs_handle fs = bcache_fs_open(fs_path);
|
struct bchfs_handle fs = bcache_fs_open(fs_path);
|
||||||
|
|
||||||
dev_opts.fd = open_for_format(dev_opts.path, force);
|
int ret = open_for_format(&dev_opts, force);
|
||||||
|
if (ret)
|
||||||
|
die("Error opening %s: %s", dev_opts.path, strerror(-ret));
|
||||||
|
|
||||||
struct bch_opt_strs fs_opt_strs;
|
struct bch_opt_strs fs_opt_strs;
|
||||||
memset(&fs_opt_strs, 0, sizeof(fs_opt_strs));
|
memset(&fs_opt_strs, 0, sizeof(fs_opt_strs));
|
||||||
@ -130,8 +132,8 @@ int cmd_device_add(int argc, char *argv[])
|
|||||||
format_opts,
|
format_opts,
|
||||||
&dev_opts, 1);
|
&dev_opts, 1);
|
||||||
free(sb);
|
free(sb);
|
||||||
fsync(dev_opts.fd);
|
fsync(dev_opts.bdev->bd_buffered_fd);
|
||||||
close(dev_opts.fd);
|
close(dev_opts.bdev->bd_buffered_fd);
|
||||||
|
|
||||||
bchu_disk_add(fs, dev_opts.path);
|
bchu_disk_add(fs, dev_opts.path);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -230,8 +230,11 @@ int cmd_format(int argc, char *argv[])
|
|||||||
initialize = false;
|
initialize = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
darray_for_each(devices, dev)
|
darray_for_each(devices, dev) {
|
||||||
dev->fd = open_for_format(dev->path, force);
|
int ret = open_for_format(dev, force);
|
||||||
|
if (ret)
|
||||||
|
die("Error opening %s: %s", dev_opts.path, strerror(-ret));
|
||||||
|
}
|
||||||
|
|
||||||
struct bch_sb *sb =
|
struct bch_sb *sb =
|
||||||
bch2_format(fs_opt_strs,
|
bch2_format(fs_opt_strs,
|
||||||
|
@ -669,9 +669,9 @@ static int migrate_fs(const char *fs_path,
|
|||||||
struct dev_opts dev = dev_opts_default();
|
struct dev_opts dev = dev_opts_default();
|
||||||
|
|
||||||
dev.path = dev_t_to_path(stat.st_dev);
|
dev.path = dev_t_to_path(stat.st_dev);
|
||||||
dev.fd = xopen(dev.path, O_RDWR);
|
dev.bdev = blkdev_get_by_path(dev.path, BLK_OPEN_READ|BLK_OPEN_WRITE, &dev, NULL);
|
||||||
|
|
||||||
opt_set(fs_opts, block_size, get_blocksize(dev.fd));
|
opt_set(fs_opts, block_size, get_blocksize(dev.bdev->bd_buffered_fd));
|
||||||
|
|
||||||
char *file_path = mprintf("%s/bcachefs", fs_path);
|
char *file_path = mprintf("%s/bcachefs", fs_path);
|
||||||
printf("Creating new filesystem on %s in space reserved at %s\n",
|
printf("Creating new filesystem on %s in space reserved at %s\n",
|
||||||
@ -682,7 +682,7 @@ static int migrate_fs(const char *fs_path,
|
|||||||
u64 bcachefs_inum;
|
u64 bcachefs_inum;
|
||||||
ranges extents = reserve_new_fs_space(file_path,
|
ranges extents = reserve_new_fs_space(file_path,
|
||||||
fs_opts.block_size >> 9,
|
fs_opts.block_size >> 9,
|
||||||
get_size(dev.fd) / 5,
|
get_size(dev.bdev->bd_buffered_fd) / 5,
|
||||||
&bcachefs_inum, stat.st_dev, force);
|
&bcachefs_inum, stat.st_dev, force);
|
||||||
|
|
||||||
find_superblock_space(extents, format_opts, &dev);
|
find_superblock_space(extents, format_opts, &dev);
|
||||||
|
@ -67,7 +67,7 @@ static u64 min_size(unsigned bucket_size)
|
|||||||
void bch2_pick_bucket_size(struct bch_opts opts, struct dev_opts *dev)
|
void bch2_pick_bucket_size(struct bch_opts opts, struct dev_opts *dev)
|
||||||
{
|
{
|
||||||
if (!dev->size)
|
if (!dev->size)
|
||||||
dev->size = get_size(dev->fd);
|
dev->size = get_size(dev->bdev->bd_buffered_fd);
|
||||||
|
|
||||||
if (!dev->bucket_size) {
|
if (!dev->bucket_size) {
|
||||||
if (dev->size < min_size(opts.block_size))
|
if (dev->size < min_size(opts.block_size))
|
||||||
@ -154,8 +154,7 @@ struct bch_sb *bch2_format(struct bch_opt_strs fs_opt_strs,
|
|||||||
unsigned opt_id;
|
unsigned opt_id;
|
||||||
|
|
||||||
for (i = devs; i < devs + nr_devs; i++)
|
for (i = devs; i < devs + nr_devs; i++)
|
||||||
max_dev_block_size = max(max_dev_block_size,
|
max_dev_block_size = max(max_dev_block_size, get_blocksize(i->bdev->bd_buffered_fd));
|
||||||
get_blocksize(i->fd));
|
|
||||||
|
|
||||||
/* calculate block size: */
|
/* calculate block size: */
|
||||||
if (!opt_defined(fs_opts, block_size)) {
|
if (!opt_defined(fs_opts, block_size)) {
|
||||||
@ -312,12 +311,12 @@ struct bch_sb *bch2_format(struct bch_opt_strs fs_opt_strs,
|
|||||||
/* Zero start of disk */
|
/* Zero start of disk */
|
||||||
static const char zeroes[BCH_SB_SECTOR << 9];
|
static const char zeroes[BCH_SB_SECTOR << 9];
|
||||||
|
|
||||||
xpwrite(i->fd, zeroes, BCH_SB_SECTOR << 9, 0,
|
xpwrite(i->bdev->bd_buffered_fd, zeroes, BCH_SB_SECTOR << 9, 0,
|
||||||
"zeroing start of disk");
|
"zeroing start of disk");
|
||||||
}
|
}
|
||||||
|
|
||||||
bch2_super_write(i->fd, sb.sb);
|
bch2_super_write(i->bdev->bd_buffered_fd, sb.sb);
|
||||||
close(i->fd);
|
close(i->bdev->bd_buffered_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.sb;
|
return sb.sb;
|
||||||
|
@ -52,7 +52,7 @@ static inline struct format_opts format_opts_default()
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct dev_opts {
|
struct dev_opts {
|
||||||
int fd;
|
struct block_device *bdev;
|
||||||
char *path;
|
char *path;
|
||||||
u64 size; /* bytes*/
|
u64 size; /* bytes*/
|
||||||
u64 bucket_size; /* bytes */
|
u64 bucket_size; /* bytes */
|
||||||
|
23
tools-util.c
23
tools-util.c
@ -17,6 +17,7 @@
|
|||||||
#include <blkid.h>
|
#include <blkid.h>
|
||||||
#include <uuid/uuid.h>
|
#include <uuid/uuid.h>
|
||||||
|
|
||||||
|
#include "libbcachefs.h"
|
||||||
#include "libbcachefs/bcachefs_ioctl.h"
|
#include "libbcachefs/bcachefs_ioctl.h"
|
||||||
#include "linux/sort.h"
|
#include "linux/sort.h"
|
||||||
#include "tools-util.h"
|
#include "tools-util.h"
|
||||||
@ -212,22 +213,24 @@ unsigned get_blocksize(int fd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Open a block device, do magic blkid stuff to probe for existing filesystems: */
|
/* Open a block device, do magic blkid stuff to probe for existing filesystems: */
|
||||||
int open_for_format(const char *dev, bool force)
|
int open_for_format(struct dev_opts *dev, bool force)
|
||||||
{
|
{
|
||||||
blkid_probe pr;
|
blkid_probe pr;
|
||||||
const char *fs_type = NULL, *fs_label = NULL;
|
const char *fs_type = NULL, *fs_label = NULL;
|
||||||
size_t fs_type_len, fs_label_len;
|
size_t fs_type_len, fs_label_len;
|
||||||
|
|
||||||
int fd = open(dev, O_RDWR|O_EXCL);
|
dev->bdev = blkdev_get_by_path(dev->path, BLK_OPEN_READ|BLK_OPEN_WRITE|BLK_OPEN_EXCL,
|
||||||
if (fd < 0)
|
dev, NULL);
|
||||||
die("Error opening device to format %s: %m", dev);
|
int ret = PTR_ERR_OR_ZERO(dev->bdev);
|
||||||
|
if (ret < 0)
|
||||||
|
die("Error opening device to format %s: %s", dev->path, strerror(-ret));
|
||||||
|
|
||||||
if (force)
|
if (force)
|
||||||
return fd;
|
return 0;
|
||||||
|
|
||||||
if (!(pr = blkid_new_probe()))
|
if (!(pr = blkid_new_probe()))
|
||||||
die("blkid error 1");
|
die("blkid error 1");
|
||||||
if (blkid_probe_set_device(pr, fd, 0, 0))
|
if (blkid_probe_set_device(pr, dev->bdev->bd_buffered_fd, 0, 0))
|
||||||
die("blkid error 2");
|
die("blkid error 2");
|
||||||
if (blkid_probe_enable_partitions(pr, true))
|
if (blkid_probe_enable_partitions(pr, true))
|
||||||
die("blkid error 3");
|
die("blkid error 3");
|
||||||
@ -240,19 +243,19 @@ int open_for_format(const char *dev, bool force)
|
|||||||
if (fs_type) {
|
if (fs_type) {
|
||||||
if (fs_label)
|
if (fs_label)
|
||||||
printf("%s contains a %s filesystem labelled '%s'\n",
|
printf("%s contains a %s filesystem labelled '%s'\n",
|
||||||
dev, fs_type, fs_label);
|
dev->path, fs_type, fs_label);
|
||||||
else
|
else
|
||||||
printf("%s contains a %s filesystem\n",
|
printf("%s contains a %s filesystem\n",
|
||||||
dev, fs_type);
|
dev->path, fs_type);
|
||||||
fputs("Proceed anyway?", stdout);
|
fputs("Proceed anyway?", stdout);
|
||||||
if (!ask_yn())
|
if (!ask_yn())
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
while (blkid_do_probe(pr) == 0)
|
while (blkid_do_probe(pr) == 0)
|
||||||
blkid_do_wipe(pr, 0);
|
blkid_do_wipe(pr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
blkid_free_probe(pr);
|
blkid_free_probe(pr);
|
||||||
return fd;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ask_yn(void)
|
bool ask_yn(void)
|
||||||
|
@ -64,7 +64,8 @@ ssize_t read_string_list_or_die(const char *, const char * const[],
|
|||||||
|
|
||||||
u64 get_size(int);
|
u64 get_size(int);
|
||||||
unsigned get_blocksize(int);
|
unsigned get_blocksize(int);
|
||||||
int open_for_format(const char *, bool);
|
struct dev_opts;
|
||||||
|
int open_for_format(struct dev_opts *, bool);
|
||||||
|
|
||||||
bool ask_yn(void);
|
bool ask_yn(void);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user