mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-12-08 00:00:12 +03:00
Update bcachefs sources to 62003adb7cbd bcachefs: Add v2 ioctls that return error strings
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
459060f763
commit
ca482e7fd8
@ -1 +1 @@
|
||||
d863521e4078ad402b9eb34f962ce8b713c3d9c8
|
||||
62003adb7cbd505b54495338a1289cc087633cf1
|
||||
|
||||
@ -551,9 +551,10 @@ static int cmd_device_resize(int argc, char *argv[])
|
||||
die("Shrinking not supported yet");
|
||||
|
||||
printf("resizing %s to %llu buckets\n", dev, nbuckets);
|
||||
int ret = bch2_dev_resize(c, resize, nbuckets);
|
||||
CLASS(printbuf, err)();
|
||||
int ret = bch2_dev_resize(c, resize, nbuckets, &err);
|
||||
if (ret)
|
||||
fprintf(stderr, "resize error: %s\n", bch2_err_str(ret));
|
||||
fprintf(stderr, "resize error: %s\n%s", bch2_err_str(ret), err.buf);
|
||||
|
||||
enumerated_ref_put(&resize->io_ref[READ], 0);
|
||||
bch2_fs_stop(c);
|
||||
|
||||
@ -681,10 +681,13 @@ static int image_update(const char *src_path, const char *dst_image,
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
ret = bch2_dev_add(c, dev_opts.path);
|
||||
bch_err_msg(c, ret, "adding metadata device");
|
||||
if (ret)
|
||||
CLASS(printbuf, err)();
|
||||
ret = bch2_dev_add(c, dev_opts.path, &err);
|
||||
if (ret) {
|
||||
bch_err(c, "error adding metadata device: %s\n%s",
|
||||
bch2_err_str(ret), err.buf);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
set_data_allowed_for_image_update(c);
|
||||
|
||||
@ -66,29 +66,33 @@ struct bch_ioctl_incremental {
|
||||
#define BCH_IOCTL_STOP _IO(0xbc, 3)
|
||||
#endif
|
||||
|
||||
#define BCH_IOCTL_DISK_ADD _IOW(0xbc, 4, struct bch_ioctl_disk)
|
||||
#define BCH_IOCTL_DISK_REMOVE _IOW(0xbc, 5, struct bch_ioctl_disk)
|
||||
#define BCH_IOCTL_DISK_ONLINE _IOW(0xbc, 6, struct bch_ioctl_disk)
|
||||
#define BCH_IOCTL_DISK_OFFLINE _IOW(0xbc, 7, struct bch_ioctl_disk)
|
||||
#define BCH_IOCTL_DISK_SET_STATE _IOW(0xbc, 8, struct bch_ioctl_disk_set_state)
|
||||
#define BCH_IOCTL_DISK_SET_STATE_v2 _IOW(0xbc, 22, struct bch_ioctl_disk_set_state_v2)
|
||||
#define BCH_IOCTL_DATA _IOW(0xbc, 10, struct bch_ioctl_data)
|
||||
#define BCH_IOCTL_FS_USAGE _IOWR(0xbc, 11, struct bch_ioctl_fs_usage)
|
||||
#define BCH_IOCTL_DEV_USAGE _IOWR(0xbc, 11, struct bch_ioctl_dev_usage)
|
||||
#define BCH_IOCTL_READ_SUPER _IOW(0xbc, 12, struct bch_ioctl_read_super)
|
||||
#define BCH_IOCTL_DISK_GET_IDX _IOW(0xbc, 13, struct bch_ioctl_disk_get_idx)
|
||||
#define BCH_IOCTL_DISK_RESIZE _IOW(0xbc, 14, struct bch_ioctl_disk_resize)
|
||||
#define BCH_IOCTL_DISK_RESIZE_JOURNAL _IOW(0xbc,15, struct bch_ioctl_disk_resize_journal)
|
||||
#define BCH_IOCTL_DISK_ADD _IOW(0xbc, 4, struct bch_ioctl_disk)
|
||||
#define BCH_IOCTL_DISK_ADD_v2 _IOW(0xbc, 23, struct bch_ioctl_disk_v2)
|
||||
#define BCH_IOCTL_DISK_REMOVE _IOW(0xbc, 5, struct bch_ioctl_disk)
|
||||
#define BCH_IOCTL_DISK_REMOVE_v2 _IOW(0xbc, 24, struct bch_ioctl_disk_v2)
|
||||
#define BCH_IOCTL_DISK_ONLINE _IOW(0xbc, 6, struct bch_ioctl_disk)
|
||||
#define BCH_IOCTL_DISK_ONLINE_v2 _IOW(0xbc, 25, struct bch_ioctl_disk_v2)
|
||||
#define BCH_IOCTL_DISK_OFFLINE _IOW(0xbc, 7, struct bch_ioctl_disk)
|
||||
#define BCH_IOCTL_DISK_OFFLINE_v2 _IOW(0xbc, 26, struct bch_ioctl_disk_v2)
|
||||
#define BCH_IOCTL_DISK_SET_STATE _IOW(0xbc, 8, struct bch_ioctl_disk_set_state)
|
||||
#define BCH_IOCTL_DISK_SET_STATE_v2 _IOW(0xbc, 22, struct bch_ioctl_disk_set_state_v2)
|
||||
#define BCH_IOCTL_DATA _IOW(0xbc, 10, struct bch_ioctl_data)
|
||||
#define BCH_IOCTL_FS_USAGE _IOWR(0xbc, 11, struct bch_ioctl_fs_usage)
|
||||
#define BCH_IOCTL_DEV_USAGE _IOWR(0xbc, 11, struct bch_ioctl_dev_usage)
|
||||
#define BCH_IOCTL_READ_SUPER _IOW(0xbc, 12, struct bch_ioctl_read_super)
|
||||
#define BCH_IOCTL_DISK_GET_IDX _IOW(0xbc, 13, struct bch_ioctl_disk_get_idx)
|
||||
#define BCH_IOCTL_DISK_RESIZE _IOW(0xbc, 14, struct bch_ioctl_disk_resize)
|
||||
#define BCH_IOCTL_DISK_RESIZE_JOURNAL _IOW(0xbc, 15, struct bch_ioctl_disk_resize_journal)
|
||||
|
||||
#define BCH_IOCTL_SUBVOLUME_CREATE _IOW(0xbc, 16, struct bch_ioctl_subvolume)
|
||||
#define BCH_IOCTL_SUBVOLUME_DESTROY _IOW(0xbc, 17, struct bch_ioctl_subvolume)
|
||||
#define BCH_IOCTL_SUBVOLUME_CREATE _IOW(0xbc, 16, struct bch_ioctl_subvolume)
|
||||
#define BCH_IOCTL_SUBVOLUME_DESTROY _IOW(0xbc, 17, struct bch_ioctl_subvolume)
|
||||
|
||||
#define BCH_IOCTL_DEV_USAGE_V2 _IOWR(0xbc, 18, struct bch_ioctl_dev_usage_v2)
|
||||
#define BCH_IOCTL_DEV_USAGE_V2 _IOWR(0xbc, 18, struct bch_ioctl_dev_usage_v2)
|
||||
|
||||
#define BCH_IOCTL_FSCK_OFFLINE _IOW(0xbc, 19, struct bch_ioctl_fsck_offline)
|
||||
#define BCH_IOCTL_FSCK_ONLINE _IOW(0xbc, 20, struct bch_ioctl_fsck_online)
|
||||
#define BCH_IOCTL_QUERY_ACCOUNTING _IOW(0xbc, 21, struct bch_ioctl_query_accounting)
|
||||
#define BCH_IOCTL_QUERY_COUNTERS _IOW(0xbc, 21, struct bch_ioctl_query_counters)
|
||||
#define BCH_IOCTL_FSCK_OFFLINE _IOW(0xbc, 19, struct bch_ioctl_fsck_offline)
|
||||
#define BCH_IOCTL_FSCK_ONLINE _IOW(0xbc, 20, struct bch_ioctl_fsck_online)
|
||||
#define BCH_IOCTL_QUERY_ACCOUNTING _IOW(0xbc, 21, struct bch_ioctl_query_accounting)
|
||||
#define BCH_IOCTL_QUERY_COUNTERS _IOW(0xbc, 21, struct bch_ioctl_query_counters)
|
||||
|
||||
/* ioctl below act on a particular file, not the filesystem as a whole: */
|
||||
|
||||
@ -111,13 +115,6 @@ struct bch_ioctl_query_uuid {
|
||||
__uuid_t uuid;
|
||||
};
|
||||
|
||||
#if 0
|
||||
struct bch_ioctl_start {
|
||||
__u32 flags;
|
||||
__u32 pad;
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* BCH_IOCTL_DISK_ADD: add a new device to an existing filesystem
|
||||
*
|
||||
@ -171,6 +168,13 @@ struct bch_ioctl_disk {
|
||||
__u64 dev;
|
||||
};
|
||||
|
||||
struct bch_ioctl_disk_v2 {
|
||||
__u32 flags;
|
||||
__u32 pad;
|
||||
__u64 dev;
|
||||
struct bch_ioctl_err_msg err;
|
||||
};
|
||||
|
||||
/*
|
||||
* BCH_IOCTL_DISK_SET_STATE: modify state of a member device of a filesystem
|
||||
*
|
||||
|
||||
@ -187,6 +187,18 @@ static long bch2_ioctl_stop(struct bch_fs *c)
|
||||
}
|
||||
#endif
|
||||
|
||||
static int copy_ioctl_err_msg(struct bch_ioctl_err_msg *dst, struct printbuf *src, int ret)
|
||||
{
|
||||
if (ret) {
|
||||
prt_printf(src, "error=%s", bch2_err_str(ret));
|
||||
ret = copy_to_user_errcode((void __user *)(ulong)dst->msg_ptr,
|
||||
src->buf,
|
||||
min(src->pos, dst->msg_len)) ?: ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long bch2_ioctl_disk_add(struct bch_fs *c, struct bch_ioctl_disk arg)
|
||||
{
|
||||
char *path;
|
||||
@ -203,13 +215,37 @@ static long bch2_ioctl_disk_add(struct bch_fs *c, struct bch_ioctl_disk arg)
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = bch2_dev_add(c, path);
|
||||
if (!IS_ERR(path))
|
||||
kfree(path);
|
||||
CLASS(printbuf, err)();
|
||||
ret = bch2_dev_add(c, path, &err);
|
||||
if (ret)
|
||||
bch_err(c, "%s", err.buf);
|
||||
|
||||
kfree(path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long bch2_ioctl_disk_add_v2(struct bch_fs *c, struct bch_ioctl_disk_v2 arg)
|
||||
{
|
||||
char *path = NULL;
|
||||
int ret;
|
||||
|
||||
if (!capable(CAP_SYS_ADMIN))
|
||||
return -EPERM;
|
||||
|
||||
if (arg.flags || arg.pad)
|
||||
return -EINVAL;
|
||||
|
||||
path = strndup_user((const char __user *)(unsigned long) arg.dev, PATH_MAX);
|
||||
ret = PTR_ERR_OR_ZERO(path);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
CLASS(printbuf, err)();
|
||||
ret = bch2_dev_add(c, path, &err);
|
||||
kfree(path);
|
||||
return copy_ioctl_err_msg(&arg.err, &err, ret);
|
||||
}
|
||||
|
||||
static long bch2_ioctl_disk_remove(struct bch_fs *c, struct bch_ioctl_disk arg)
|
||||
{
|
||||
if (!capable(CAP_SYS_ADMIN))
|
||||
@ -226,7 +262,32 @@ static long bch2_ioctl_disk_remove(struct bch_fs *c, struct bch_ioctl_disk arg)
|
||||
if (IS_ERR(ca))
|
||||
return PTR_ERR(ca);
|
||||
|
||||
return bch2_dev_remove(c, ca, arg.flags);
|
||||
CLASS(printbuf, err)();
|
||||
int ret = bch2_dev_remove(c, ca, arg.flags, &err);
|
||||
if (ret)
|
||||
bch_err(ca, "%s", err.buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long bch2_ioctl_disk_remove_v2(struct bch_fs *c, struct bch_ioctl_disk_v2 arg)
|
||||
{
|
||||
if (!capable(CAP_SYS_ADMIN))
|
||||
return -EPERM;
|
||||
|
||||
if ((arg.flags & ~(BCH_FORCE_IF_DATA_LOST|
|
||||
BCH_FORCE_IF_METADATA_LOST|
|
||||
BCH_FORCE_IF_DEGRADED|
|
||||
BCH_BY_INDEX)) ||
|
||||
arg.pad)
|
||||
return -EINVAL;
|
||||
|
||||
struct bch_dev *ca = bch2_device_lookup(c, arg.dev, arg.flags);
|
||||
if (IS_ERR(ca))
|
||||
return PTR_ERR(ca);
|
||||
|
||||
CLASS(printbuf, err)();
|
||||
int ret = bch2_dev_remove(c, ca, arg.flags, &err);
|
||||
return copy_ioctl_err_msg(&arg.err, &err, ret);
|
||||
}
|
||||
|
||||
static long bch2_ioctl_disk_online(struct bch_fs *c, struct bch_ioctl_disk arg)
|
||||
@ -245,11 +306,36 @@ static long bch2_ioctl_disk_online(struct bch_fs *c, struct bch_ioctl_disk arg)
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = bch2_dev_online(c, path);
|
||||
CLASS(printbuf, err)();
|
||||
ret = bch2_dev_online(c, path, &err);
|
||||
if (ret)
|
||||
bch_err(c, "%s", err.buf);
|
||||
kfree(path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long bch2_ioctl_disk_online_v2(struct bch_fs *c, struct bch_ioctl_disk_v2 arg)
|
||||
{
|
||||
char *path;
|
||||
int ret;
|
||||
|
||||
if (!capable(CAP_SYS_ADMIN))
|
||||
return -EPERM;
|
||||
|
||||
if (arg.flags || arg.pad)
|
||||
return -EINVAL;
|
||||
|
||||
path = strndup_user((const char __user *)(unsigned long) arg.dev, PATH_MAX);
|
||||
ret = PTR_ERR_OR_ZERO(path);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
CLASS(printbuf, err)();
|
||||
ret = bch2_dev_online(c, path, &err);
|
||||
kfree(path);
|
||||
return copy_ioctl_err_msg(&arg.err, &err, ret);
|
||||
}
|
||||
|
||||
static long bch2_ioctl_disk_offline(struct bch_fs *c, struct bch_ioctl_disk arg)
|
||||
{
|
||||
if (!capable(CAP_SYS_ADMIN))
|
||||
@ -266,7 +352,32 @@ static long bch2_ioctl_disk_offline(struct bch_fs *c, struct bch_ioctl_disk arg)
|
||||
if (IS_ERR(ca))
|
||||
return PTR_ERR(ca);
|
||||
|
||||
return bch2_dev_offline(c, ca, arg.flags);
|
||||
CLASS(printbuf, err)();
|
||||
int ret = bch2_dev_offline(c, ca, arg.flags, &err);
|
||||
if (ret)
|
||||
bch_err(ca, "%s", err.buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long bch2_ioctl_disk_offline_v2(struct bch_fs *c, struct bch_ioctl_disk_v2 arg)
|
||||
{
|
||||
if (!capable(CAP_SYS_ADMIN))
|
||||
return -EPERM;
|
||||
|
||||
if ((arg.flags & ~(BCH_FORCE_IF_DATA_LOST|
|
||||
BCH_FORCE_IF_METADATA_LOST|
|
||||
BCH_FORCE_IF_DEGRADED|
|
||||
BCH_BY_INDEX)) ||
|
||||
arg.pad)
|
||||
return -EINVAL;
|
||||
|
||||
CLASS(bch2_device_lookup, ca)(c, arg.dev, arg.flags);
|
||||
if (IS_ERR(ca))
|
||||
return PTR_ERR(ca);
|
||||
|
||||
CLASS(printbuf, err)();
|
||||
int ret = bch2_dev_offline(c, ca, arg.flags, &err);
|
||||
return copy_ioctl_err_msg(&arg.err, &err, ret);
|
||||
}
|
||||
|
||||
static long bch2_ioctl_disk_set_state(struct bch_fs *c,
|
||||
@ -296,6 +407,8 @@ static long bch2_ioctl_disk_set_state(struct bch_fs *c,
|
||||
static long bch2_ioctl_disk_set_state_v2(struct bch_fs *c,
|
||||
struct bch_ioctl_disk_set_state_v2 arg)
|
||||
{
|
||||
CLASS(printbuf, err)();
|
||||
|
||||
if (!capable(CAP_SYS_ADMIN))
|
||||
return -EPERM;
|
||||
|
||||
@ -308,21 +421,15 @@ static long bch2_ioctl_disk_set_state_v2(struct bch_fs *c,
|
||||
return -EINVAL;
|
||||
|
||||
CLASS(bch2_device_lookup, ca)(c, arg.dev, arg.flags);
|
||||
if (IS_ERR(ca))
|
||||
return PTR_ERR(ca);
|
||||
|
||||
CLASS(printbuf, err)();
|
||||
int ret = bch2_dev_set_state(c, ca, arg.new_state, arg.flags, &err);
|
||||
int ret = PTR_ERR_OR_ZERO(ca);
|
||||
if (ret) {
|
||||
if (err.pos > arg.err.msg_len)
|
||||
return -ERANGE;
|
||||
|
||||
prt_printf(&err, "\nerror=%s", bch2_err_str(ret));
|
||||
ret = copy_to_user_errcode((void __user *)(ulong)arg.err.msg_ptr,
|
||||
err.buf,
|
||||
err.pos) ?: ret;
|
||||
prt_printf(&err, "device %llu not found\n", arg.dev);
|
||||
goto err;
|
||||
}
|
||||
return ret;
|
||||
|
||||
ret = bch2_dev_set_state(c, ca, arg.new_state, arg.flags, &err);
|
||||
err:
|
||||
return copy_ioctl_err_msg(&arg.err, &err, ret);
|
||||
}
|
||||
|
||||
struct bch_data_ctx {
|
||||
@ -653,7 +760,11 @@ static long bch2_ioctl_disk_resize(struct bch_fs *c,
|
||||
if (IS_ERR(ca))
|
||||
return PTR_ERR(ca);
|
||||
|
||||
return bch2_dev_resize(c, ca, arg.nbuckets);
|
||||
CLASS(printbuf, err)();
|
||||
int ret = bch2_dev_resize(c, ca, arg.nbuckets, &err);
|
||||
if (ret)
|
||||
bch_err(ca, "%s", err.buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long bch2_ioctl_disk_resize_journal(struct bch_fs *c,
|
||||
@ -717,12 +828,20 @@ long bch2_fs_ioctl(struct bch_fs *c, unsigned cmd, void __user *arg)
|
||||
switch (cmd) {
|
||||
case BCH_IOCTL_DISK_ADD:
|
||||
BCH_IOCTL(disk_add, struct bch_ioctl_disk);
|
||||
case BCH_IOCTL_DISK_ADD_v2:
|
||||
BCH_IOCTL(disk_add_v2, struct bch_ioctl_disk_v2);
|
||||
case BCH_IOCTL_DISK_REMOVE:
|
||||
BCH_IOCTL(disk_remove, struct bch_ioctl_disk);
|
||||
case BCH_IOCTL_DISK_REMOVE_v2:
|
||||
BCH_IOCTL(disk_remove_v2, struct bch_ioctl_disk_v2);
|
||||
case BCH_IOCTL_DISK_ONLINE:
|
||||
BCH_IOCTL(disk_online, struct bch_ioctl_disk);
|
||||
case BCH_IOCTL_DISK_ONLINE_v2:
|
||||
BCH_IOCTL(disk_online_v2, struct bch_ioctl_disk_v2);
|
||||
case BCH_IOCTL_DISK_OFFLINE:
|
||||
BCH_IOCTL(disk_offline, struct bch_ioctl_disk);
|
||||
case BCH_IOCTL_DISK_OFFLINE_v2:
|
||||
BCH_IOCTL(disk_offline_v2, struct bch_ioctl_disk_v2);
|
||||
case BCH_IOCTL_DISK_SET_STATE:
|
||||
BCH_IOCTL(disk_set_state, struct bch_ioctl_disk_set_state);
|
||||
case BCH_IOCTL_DISK_SET_STATE_v2:
|
||||
|
||||
@ -222,6 +222,8 @@ static int journal_entry_add(struct bch_fs *c, struct bch_dev *ca,
|
||||
*/
|
||||
dup = *_i;
|
||||
if (dup) {
|
||||
BUG_ON(dup->j.seq != j->seq);
|
||||
|
||||
bool identical = bytes == vstruct_bytes(&dup->j) &&
|
||||
!memcmp(j, &dup->j, bytes);
|
||||
bool not_identical = !identical &&
|
||||
@ -252,6 +254,7 @@ static int journal_entry_add(struct bch_fs *c, struct bch_dev *ca,
|
||||
if (entry_ptr.csum_good && !identical)
|
||||
goto replace;
|
||||
|
||||
BUG_ON(dup->j.seq != j->seq);
|
||||
return ret;
|
||||
}
|
||||
replace:
|
||||
|
||||
@ -1750,19 +1750,20 @@ static int bch2_dev_alloc(struct bch_fs *c, unsigned dev_idx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __bch2_dev_attach_bdev(struct bch_dev *ca, struct bch_sb_handle *sb)
|
||||
static int __bch2_dev_attach_bdev(struct bch_dev *ca, struct bch_sb_handle *sb,
|
||||
struct printbuf *err)
|
||||
{
|
||||
unsigned ret;
|
||||
|
||||
if (bch2_dev_is_online(ca)) {
|
||||
bch_err(ca, "already have device online in slot %u",
|
||||
sb->sb->dev_idx);
|
||||
prt_printf(err, "already have device online in slot %u\n",
|
||||
sb->sb->dev_idx);
|
||||
return bch_err_throw(ca->fs, device_already_online);
|
||||
}
|
||||
|
||||
if (get_capacity(sb->bdev->bd_disk) <
|
||||
ca->mi.bucket_size * ca->mi.nbuckets) {
|
||||
bch_err(ca, "cannot online: device too small (capacity %llu filesystem size %llu nbuckets %llu)",
|
||||
prt_printf(err, "cannot online: device too small (capacity %llu filesystem size %llu nbuckets %llu)\n",
|
||||
get_capacity(sb->bdev->bd_disk),
|
||||
ca->mi.bucket_size * ca->mi.nbuckets,
|
||||
ca->mi.nbuckets);
|
||||
@ -1798,7 +1799,8 @@ static int __bch2_dev_attach_bdev(struct bch_dev *ca, struct bch_sb_handle *sb)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bch2_dev_attach_bdev(struct bch_fs *c, struct bch_sb_handle *sb)
|
||||
static int bch2_dev_attach_bdev(struct bch_fs *c, struct bch_sb_handle *sb,
|
||||
struct printbuf *err)
|
||||
{
|
||||
struct bch_dev *ca;
|
||||
int ret;
|
||||
@ -1813,7 +1815,7 @@ static int bch2_dev_attach_bdev(struct bch_fs *c, struct bch_sb_handle *sb)
|
||||
|
||||
ca = bch2_dev_locked(c, sb->sb->dev_idx);
|
||||
|
||||
ret = __bch2_dev_attach_bdev(ca, sb);
|
||||
ret = __bch2_dev_attach_bdev(ca, sb, err);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
@ -1949,7 +1951,8 @@ int bch2_dev_set_state(struct bch_fs *c, struct bch_dev *ca,
|
||||
|
||||
/* Device add/removal: */
|
||||
|
||||
int bch2_dev_remove(struct bch_fs *c, struct bch_dev *ca, int flags)
|
||||
int bch2_dev_remove(struct bch_fs *c, struct bch_dev *ca, int flags,
|
||||
struct printbuf *err)
|
||||
{
|
||||
unsigned dev_idx = ca->dev_idx, data;
|
||||
bool fast_device_removal = !bch2_request_incompat_feature(c,
|
||||
@ -1965,7 +1968,7 @@ int bch2_dev_remove(struct bch_fs *c, struct bch_dev *ca, int flags)
|
||||
bch2_dev_put(ca);
|
||||
|
||||
if (!bch2_dev_state_allowed(c, ca, BCH_MEMBER_STATE_failed, flags, NULL)) {
|
||||
bch_err(ca, "Cannot remove without losing data");
|
||||
prt_printf(err, "Cannot remove without losing data\n");
|
||||
ret = bch_err_throw(c, device_state_not_allowed);
|
||||
goto err;
|
||||
}
|
||||
@ -1985,16 +1988,17 @@ int bch2_dev_remove(struct bch_fs *c, struct bch_dev *ca, int flags)
|
||||
if (!data_type_is_empty(i) &&
|
||||
!data_type_is_hidden(i) &&
|
||||
usage.buckets[i]) {
|
||||
bch_err(ca, "Remove failed: still has data (%s, %llu buckets)",
|
||||
__bch2_data_types[i], usage.buckets[i]);
|
||||
prt_printf(err, "Remove failed: still has data (%s, %llu buckets)\n",
|
||||
__bch2_data_types[i], usage.buckets[i]);
|
||||
ret = -EBUSY;
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = bch2_dev_remove_alloc(c, ca);
|
||||
bch_err_msg(ca, ret, "bch2_dev_remove_alloc()");
|
||||
if (ret)
|
||||
if (ret) {
|
||||
prt_printf(err, "bch2_dev_remove_alloc() error: %s\n", bch2_err_str(ret));
|
||||
goto err;
|
||||
}
|
||||
|
||||
/*
|
||||
* We need to flush the entire journal to get rid of keys that reference
|
||||
@ -2007,25 +2011,28 @@ int bch2_dev_remove(struct bch_fs *c, struct bch_dev *ca, int flags)
|
||||
* calls, and could be cleaned up:
|
||||
*/
|
||||
ret = bch2_journal_flush_device_pins(&c->journal, ca->dev_idx);
|
||||
bch_err_msg(ca, ret, "bch2_journal_flush_device_pins()");
|
||||
if (ret)
|
||||
if (ret) {
|
||||
prt_printf(err, "bch2_journal_flush_device_pins() error: %s\n", bch2_err_str(ret));
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = bch2_journal_flush(&c->journal);
|
||||
bch_err_msg(ca, ret, "bch2_journal_flush()");
|
||||
if (ret)
|
||||
if (ret) {
|
||||
prt_printf(err, "bch2_journal_flush() error: %s\n", bch2_err_str(ret));
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = bch2_replicas_gc2(c);
|
||||
bch_err_msg(ca, ret, "bch2_replicas_gc2()");
|
||||
if (ret)
|
||||
if (ret) {
|
||||
prt_printf(err, "bch2_replicas_gc2() error: %s\n", bch2_err_str(ret));
|
||||
goto err;
|
||||
}
|
||||
|
||||
data = bch2_dev_has_data(c, ca);
|
||||
if (data) {
|
||||
CLASS(printbuf, data_has)();
|
||||
prt_bitflags(&data_has, __bch2_data_types, data);
|
||||
bch_err(ca, "Remove failed, still has data (%s)", data_has.buf);
|
||||
prt_str(err, "Remove failed, still has data (");
|
||||
prt_bitflags(err, __bch2_data_types, data);
|
||||
prt_str(err, ")\n");
|
||||
ret = -EBUSY;
|
||||
goto err;
|
||||
}
|
||||
@ -2070,7 +2077,7 @@ err:
|
||||
}
|
||||
|
||||
/* Add new device to running filesystem: */
|
||||
int bch2_dev_add(struct bch_fs *c, const char *path)
|
||||
int bch2_dev_add(struct bch_fs *c, const char *path, struct printbuf *err)
|
||||
{
|
||||
struct bch_opts opts = bch2_opts_empty();
|
||||
struct bch_sb_handle sb = {};
|
||||
@ -2079,9 +2086,10 @@ int bch2_dev_add(struct bch_fs *c, const char *path)
|
||||
int ret = 0;
|
||||
|
||||
ret = bch2_read_super(path, &opts, &sb);
|
||||
bch_err_msg(c, ret, "reading super");
|
||||
if (ret)
|
||||
if (ret) {
|
||||
prt_printf(err, "error reading superblock: %s\n", bch2_err_str(ret));
|
||||
goto err;
|
||||
}
|
||||
|
||||
struct bch_member dev_mi = bch2_sb_member_get(sb.sb, sb.sb->dev_idx);
|
||||
|
||||
@ -2102,7 +2110,7 @@ int bch2_dev_add(struct bch_fs *c, const char *path)
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
bch_err(c, "filesystem UUID already open");
|
||||
prt_printf(err, "cannot go multidevice: filesystem UUID already open\n");
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
@ -2117,7 +2125,7 @@ int bch2_dev_add(struct bch_fs *c, const char *path)
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = __bch2_dev_attach_bdev(ca, &sb);
|
||||
ret = __bch2_dev_attach_bdev(ca, &sb, err);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
@ -2126,16 +2134,17 @@ int bch2_dev_add(struct bch_fs *c, const char *path)
|
||||
SET_BCH_SB_MULTI_DEVICE(c->disk_sb.sb, true);
|
||||
|
||||
ret = bch2_sb_from_fs(c, ca);
|
||||
bch_err_msg(c, ret, "setting up new superblock");
|
||||
if (ret)
|
||||
if (ret) {
|
||||
prt_printf(err, "error setting up new superblock: %s\n", bch2_err_str(ret));
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (dynamic_fault("bcachefs:add:no_slot"))
|
||||
goto err;
|
||||
|
||||
ret = bch2_sb_member_alloc(c);
|
||||
if (ret < 0) {
|
||||
bch_err_msg(c, ret, "setting up new superblock");
|
||||
prt_printf(err, "error allocating superblock member slot: %s\n", bch2_err_str(ret));
|
||||
goto err;
|
||||
}
|
||||
unsigned dev_idx = ret;
|
||||
@ -2153,7 +2162,7 @@ int bch2_dev_add(struct bch_fs *c, const char *path)
|
||||
|
||||
if (BCH_MEMBER_GROUP(&dev_mi)) {
|
||||
ret = __bch2_dev_group_set(c, ca, label.buf);
|
||||
bch_err_msg(c, ret, "creating new label");
|
||||
prt_printf(err, "error creating new label: %s\n", bch2_err_str(ret));
|
||||
if (ret)
|
||||
goto err_late;
|
||||
}
|
||||
@ -2167,22 +2176,25 @@ int bch2_dev_add(struct bch_fs *c, const char *path)
|
||||
|
||||
if (test_bit(BCH_FS_started, &c->flags)) {
|
||||
ret = bch2_trans_mark_dev_sb(c, ca, BTREE_TRIGGER_transactional);
|
||||
bch_err_msg(ca, ret, "marking new superblock");
|
||||
if (ret)
|
||||
if (ret) {
|
||||
prt_printf(err, "error marking new superblock: %s\n", bch2_err_str(ret));
|
||||
goto err_late;
|
||||
}
|
||||
|
||||
ret = bch2_fs_freespace_init(c);
|
||||
bch_err_msg(ca, ret, "initializing free space");
|
||||
if (ret)
|
||||
if (ret) {
|
||||
prt_printf(err, "error initializing free space: %s\n", bch2_err_str(ret));
|
||||
goto err_late;
|
||||
}
|
||||
|
||||
if (ca->mi.state == BCH_MEMBER_STATE_rw)
|
||||
__bch2_dev_read_write(c, ca);
|
||||
|
||||
ret = bch2_dev_journal_alloc(ca, false);
|
||||
bch_err_msg(c, ret, "allocating journal");
|
||||
if (ret)
|
||||
if (ret) {
|
||||
prt_printf(err, "error allocating journal: %s\n", bch2_err_str(ret));
|
||||
goto err_late;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2215,7 +2227,7 @@ err_late:
|
||||
}
|
||||
|
||||
/* Hot add existing device to running filesystem: */
|
||||
int bch2_dev_online(struct bch_fs *c, const char *path)
|
||||
int bch2_dev_online(struct bch_fs *c, const char *path, struct printbuf *err)
|
||||
{
|
||||
struct bch_opts opts = bch2_opts_empty();
|
||||
struct bch_sb_handle sb = { NULL };
|
||||
@ -2226,42 +2238,48 @@ int bch2_dev_online(struct bch_fs *c, const char *path)
|
||||
guard(rwsem_write)(&c->state_lock);
|
||||
|
||||
ret = bch2_read_super(path, &opts, &sb);
|
||||
if (ret)
|
||||
if (ret) {
|
||||
prt_printf(err, "error reading superblock: %s\n", bch2_err_str(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
dev_idx = sb.sb->dev_idx;
|
||||
|
||||
ret = bch2_dev_in_fs(&c->disk_sb, &sb, &c->opts);
|
||||
bch_err_msg(c, ret, "bringing %s online", path);
|
||||
if (ret)
|
||||
if (ret) {
|
||||
prt_printf(err, "device not a member of fs: %s\n", bch2_err_str(ret));
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = bch2_dev_attach_bdev(c, &sb);
|
||||
ret = bch2_dev_attach_bdev(c, &sb, err);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
ca = bch2_dev_locked(c, dev_idx);
|
||||
|
||||
ret = bch2_trans_mark_dev_sb(c, ca, BTREE_TRIGGER_transactional);
|
||||
bch_err_msg(c, ret, "bringing %s online: error from bch2_trans_mark_dev_sb", path);
|
||||
if (ret)
|
||||
if (ret) {
|
||||
prt_printf(err, "bch2_trans_mark_dev_sb() error: %s\n", bch2_err_str(ret));
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (ca->mi.state == BCH_MEMBER_STATE_rw)
|
||||
__bch2_dev_read_write(c, ca);
|
||||
|
||||
if (!ca->mi.freespace_initialized) {
|
||||
ret = bch2_dev_freespace_init(c, ca, 0, ca->mi.nbuckets);
|
||||
bch_err_msg(ca, ret, "initializing free space");
|
||||
if (ret)
|
||||
if (ret) {
|
||||
prt_printf(err, "bch2_dev_freespace_init() error: %s\n", bch2_err_str(ret));
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ca->journal.nr) {
|
||||
ret = bch2_dev_journal_alloc(ca, false);
|
||||
bch_err_msg(ca, ret, "allocating journal");
|
||||
if (ret)
|
||||
if (ret) {
|
||||
prt_printf(err, "bch2_dev_journal_alloc() error: %s\n", bch2_err_str(ret));
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
scoped_guard(mutex, &c->sb_lock) {
|
||||
@ -2276,17 +2294,17 @@ err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int bch2_dev_offline(struct bch_fs *c, struct bch_dev *ca, int flags)
|
||||
int bch2_dev_offline(struct bch_fs *c, struct bch_dev *ca, int flags, struct printbuf *err)
|
||||
{
|
||||
guard(rwsem_write)(&c->state_lock);
|
||||
|
||||
if (!bch2_dev_is_online(ca)) {
|
||||
bch_err(ca, "Already offline");
|
||||
prt_printf(err, "Already offline\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!bch2_dev_state_allowed(c, ca, BCH_MEMBER_STATE_failed, flags, NULL)) {
|
||||
bch_err(ca, "Cannot offline required disk");
|
||||
prt_printf(err, "Cannot offline required disk\n");
|
||||
return bch_err_throw(c, device_state_not_allowed);
|
||||
}
|
||||
|
||||
@ -2306,7 +2324,7 @@ static int __bch2_dev_resize_alloc(struct bch_dev *ca, u64 old_nbuckets, u64 new
|
||||
bch2_dev_freespace_init(c, ca, old_nbuckets, new_nbuckets);
|
||||
}
|
||||
|
||||
int bch2_dev_resize(struct bch_fs *c, struct bch_dev *ca, u64 nbuckets)
|
||||
int bch2_dev_resize(struct bch_fs *c, struct bch_dev *ca, u64 nbuckets, struct printbuf *err)
|
||||
{
|
||||
u64 old_nbuckets;
|
||||
int ret = 0;
|
||||
@ -2315,31 +2333,36 @@ int bch2_dev_resize(struct bch_fs *c, struct bch_dev *ca, u64 nbuckets)
|
||||
old_nbuckets = ca->mi.nbuckets;
|
||||
|
||||
if (nbuckets < ca->mi.nbuckets) {
|
||||
bch_err(ca, "Cannot shrink yet");
|
||||
prt_printf(err, "Cannot shrink yet\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (nbuckets > BCH_MEMBER_NBUCKETS_MAX) {
|
||||
bch_err(ca, "New device size too big (%llu greater than max %u)",
|
||||
nbuckets, BCH_MEMBER_NBUCKETS_MAX);
|
||||
prt_printf(err, "New device size too big (%llu greater than max %u)\n",
|
||||
nbuckets, BCH_MEMBER_NBUCKETS_MAX);
|
||||
return bch_err_throw(c, device_size_too_big);
|
||||
}
|
||||
|
||||
if (bch2_dev_is_online(ca) &&
|
||||
get_capacity(ca->disk_sb.bdev->bd_disk) <
|
||||
ca->mi.bucket_size * nbuckets) {
|
||||
bch_err(ca, "New size larger than device");
|
||||
prt_printf(err, "New size %llu larger than device size %llu\n",
|
||||
ca->mi.bucket_size * nbuckets,
|
||||
get_capacity(ca->disk_sb.bdev->bd_disk));
|
||||
return bch_err_throw(c, device_size_too_small);
|
||||
}
|
||||
|
||||
ret = bch2_dev_buckets_resize(c, ca, nbuckets);
|
||||
bch_err_msg(ca, ret, "resizing buckets");
|
||||
if (ret)
|
||||
if (ret) {
|
||||
prt_printf(err, "bch2_dev_buckets_resize() error: %s\n", bch2_err_str(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = bch2_trans_mark_dev_sb(c, ca, BTREE_TRIGGER_transactional);
|
||||
if (ret)
|
||||
if (ret) {
|
||||
prt_printf(err, "bch2_trans_mark_dev_sb() error: %s\n", bch2_err_str(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
scoped_guard(mutex, &c->sb_lock) {
|
||||
struct bch_member *m = bch2_members_v2_get_mut(c->disk_sb.sb, ca->dev_idx);
|
||||
@ -2350,8 +2373,10 @@ int bch2_dev_resize(struct bch_fs *c, struct bch_dev *ca, u64 nbuckets)
|
||||
|
||||
if (ca->mi.freespace_initialized) {
|
||||
ret = __bch2_dev_resize_alloc(ca, old_nbuckets, nbuckets);
|
||||
if (ret)
|
||||
if (ret) {
|
||||
prt_printf(err, "__bch2_dev_resize_alloc() error: %s\n", bch2_err_str(ret));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
bch2_recalc_capacity(c);
|
||||
@ -2581,9 +2606,12 @@ struct bch_fs *bch2_fs_open(darray_const_str *devices,
|
||||
|
||||
scoped_guard(rwsem_write, &c->state_lock)
|
||||
darray_for_each(sbs, sb) {
|
||||
ret = bch2_dev_attach_bdev(c, sb);
|
||||
if (ret)
|
||||
CLASS(printbuf, err)();
|
||||
ret = bch2_dev_attach_bdev(c, sb, &err);
|
||||
if (ret) {
|
||||
bch_err(bch2_dev_locked(c, sb->sb->dev_idx), "%s", err.buf);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (!c->opts.nostart) {
|
||||
|
||||
@ -26,12 +26,11 @@ int bch2_dev_set_state(struct bch_fs *, struct bch_dev *,
|
||||
enum bch_member_state, int,
|
||||
struct printbuf *);
|
||||
|
||||
int bch2_dev_fail(struct bch_dev *, int);
|
||||
int bch2_dev_remove(struct bch_fs *, struct bch_dev *, int);
|
||||
int bch2_dev_add(struct bch_fs *, const char *);
|
||||
int bch2_dev_online(struct bch_fs *, const char *);
|
||||
int bch2_dev_offline(struct bch_fs *, struct bch_dev *, int);
|
||||
int bch2_dev_resize(struct bch_fs *, struct bch_dev *, u64);
|
||||
int bch2_dev_remove(struct bch_fs *, struct bch_dev *, int, struct printbuf *);
|
||||
int bch2_dev_add(struct bch_fs *, const char *, struct printbuf *);
|
||||
int bch2_dev_online(struct bch_fs *, const char *, struct printbuf *);
|
||||
int bch2_dev_offline(struct bch_fs *, struct bch_dev *, int, struct printbuf *);
|
||||
int bch2_dev_resize(struct bch_fs *, struct bch_dev *, u64, struct printbuf *);
|
||||
struct bch_dev *bch2_dev_lookup(struct bch_fs *, const char *);
|
||||
|
||||
bool bch2_fs_emergency_read_only(struct bch_fs *);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user