* Code for moving data off a device.
*/
-#include "bcache.h"
+#include "bcachefs.h"
#include "btree_update.h"
#include "buckets.h"
#include "extents.h"
const struct bch_extent_ptr *ptr;
int ret;
- if (bch_disk_reservation_get(c, &res, k.k->size, 0))
+ if (bch2_disk_reservation_get(c, &res, k.k->size, 0))
return -ENOSPC;
extent_for_each_ptr(bkey_s_c_to_extent(k), ptr)
found:
/* XXX: we need to be doing something with the disk reservation */
- ret = bch_data_move(c, ctxt, &c->migration_write_point, k, ptr);
+ ret = bch2_data_move(c, ctxt, &c->migration_write_point, k, ptr);
if (ret)
- bch_disk_reservation_put(c, &res);
+ bch2_disk_reservation_put(c, &res);
return ret;
}
* land in the same device even if there are others available.
*/
-int bch_move_data_off_device(struct bch_dev *ca)
+int bch2_move_data_off_device(struct bch_dev *ca)
{
struct moving_context ctxt;
struct bch_fs *c = ca->fs;
if (!ca->mi.has_data)
return 0;
- bch_move_ctxt_init(&ctxt, NULL, SECTORS_IN_FLIGHT_PER_DEVICE);
+ bch2_move_ctxt_init(&ctxt, NULL, SECTORS_IN_FLIGHT_PER_DEVICE);
ctxt.avoid = ca;
/*
atomic_set(&ctxt.error_count, 0);
atomic_set(&ctxt.error_flags, 0);
- bch_btree_iter_init(&iter, c, BTREE_ID_EXTENTS, POS_MIN);
+ bch2_btree_iter_init(&iter, c, BTREE_ID_EXTENTS, POS_MIN);
- while (!bch_move_ctxt_wait(&ctxt) &&
- (k = bch_btree_iter_peek(&iter)).k &&
+ while (!bch2_move_ctxt_wait(&ctxt) &&
+ (k = bch2_btree_iter_peek(&iter)).k &&
!(ret = btree_iter_err(k))) {
if (!bkey_extent_is_data(k.k) ||
- !bch_extent_has_device(bkey_s_c_to_extent(k),
+ !bch2_extent_has_device(bkey_s_c_to_extent(k),
ca->dev_idx))
goto next;
ret = issue_migration_move(ca, &ctxt, k);
if (ret == -ENOMEM) {
- bch_btree_iter_unlock(&iter);
+ bch2_btree_iter_unlock(&iter);
/*
* memory allocation failure, wait for some IO
* to finish
*/
- bch_move_ctxt_wait_for_io(&ctxt);
+ bch2_move_ctxt_wait_for_io(&ctxt);
continue;
}
if (ret == -ENOSPC)
seen_key_count++;
next:
- bch_btree_iter_advance_pos(&iter);
- bch_btree_iter_cond_resched(&iter);
+ bch2_btree_iter_advance_pos(&iter);
+ bch2_btree_iter_cond_resched(&iter);
}
- bch_btree_iter_unlock(&iter);
- bch_move_ctxt_exit(&ctxt);
+ bch2_btree_iter_unlock(&iter);
+ bch2_move_ctxt_exit(&ctxt);
if (ret)
return ret;
}
mutex_lock(&c->sb_lock);
- mi = bch_sb_get_members(c->disk_sb);
+ mi = bch2_sb_get_members(c->disk_sb);
SET_BCH_MEMBER_HAS_DATA(&mi->members[ca->dev_idx], false);
- bch_write_super(c);
+ bch2_write_super(c);
mutex_unlock(&c->sb_lock);
return 0;
* This walks the btree, and for any node on the relevant device it moves the
* node elsewhere.
*/
-static int bch_move_btree_off(struct bch_dev *ca, enum btree_id id)
+static int bch2_move_btree_off(struct bch_dev *ca, enum btree_id id)
{
struct bch_fs *c = ca->fs;
struct btree_iter iter;
for_each_btree_node(&iter, c, id, POS_MIN, 0, b) {
struct bkey_s_c_extent e = bkey_i_to_s_c_extent(&b->key);
retry:
- if (!bch_extent_has_device(e, ca->dev_idx))
+ if (!bch2_extent_has_device(e, ca->dev_idx))
continue;
- ret = bch_btree_node_rewrite(&iter, b, &cl);
+ ret = bch2_btree_node_rewrite(&iter, b, &cl);
if (ret == -EINTR || ret == -ENOSPC) {
/*
* Drop locks to upgrade locks or wait on
* reserve: after retaking, recheck in case we
* raced.
*/
- bch_btree_iter_unlock(&iter);
+ bch2_btree_iter_unlock(&iter);
closure_sync(&cl);
- b = bch_btree_iter_peek_node(&iter);
+ b = bch2_btree_iter_peek_node(&iter);
goto retry;
}
if (ret) {
- bch_btree_iter_unlock(&iter);
+ bch2_btree_iter_unlock(&iter);
return ret;
}
- bch_btree_iter_set_locks_want(&iter, 0);
+ bch2_btree_iter_set_locks_want(&iter, 0);
}
- ret = bch_btree_iter_unlock(&iter);
+ ret = bch2_btree_iter_unlock(&iter);
if (ret)
return ret; /* btree IO error */
- if (IS_ENABLED(CONFIG_BCACHE_DEBUG)) {
+ if (IS_ENABLED(CONFIG_BCACHEFS_DEBUG)) {
for_each_btree_node(&iter, c, id, POS_MIN, 0, b) {
struct bkey_s_c_extent e = bkey_i_to_s_c_extent(&b->key);
- BUG_ON(bch_extent_has_device(e, ca->dev_idx));
+ BUG_ON(bch2_extent_has_device(e, ca->dev_idx));
}
- bch_btree_iter_unlock(&iter);
+ bch2_btree_iter_unlock(&iter);
}
return 0;
* is written.
*/
-int bch_move_metadata_off_device(struct bch_dev *ca)
+int bch2_move_metadata_off_device(struct bch_dev *ca)
{
struct bch_fs *c = ca->fs;
struct bch_sb_field_members *mi;
/* 1st, Move the btree nodes off the device */
for (i = 0; i < BTREE_ID_NR; i++) {
- ret = bch_move_btree_off(ca, i);
+ ret = bch2_move_btree_off(ca, i);
if (ret)
return ret;
}
/* 2nd. Move the journal off the device */
- ret = bch_journal_move(ca);
+ ret = bch2_journal_move(ca);
if (ret)
return ret;
mutex_lock(&c->sb_lock);
- mi = bch_sb_get_members(c->disk_sb);
+ mi = bch2_sb_get_members(c->disk_sb);
SET_BCH_MEMBER_HAS_METADATA(&mi->members[ca->dev_idx], false);
- bch_write_super(c);
+ bch2_write_super(c);
mutex_unlock(&c->sb_lock);
return 0;
* migrate the data off the device.
*/
-static int bch_flag_key_bad(struct btree_iter *iter,
+static int bch2_flag_key_bad(struct btree_iter *iter,
struct bch_dev *ca,
struct bkey_s_c_extent orig)
{
extent_for_each_ptr_backwards(e, ptr)
if (ptr->dev == ca->dev_idx)
- bch_extent_drop_ptr(e, ptr);
+ bch2_extent_drop_ptr(e, ptr);
/*
- * If the new extent no longer has any pointers, bch_extent_normalize()
+ * If the new extent no longer has any pointers, bch2_extent_normalize()
* will do the appropriate thing with it (turning it into a
* KEY_TYPE_ERROR key, or just a discard if it was a cached extent)
*/
- bch_extent_normalize(c, e.s);
+ bch2_extent_normalize(c, e.s);
- return bch_btree_insert_at(c, NULL, NULL, NULL,
+ return bch2_btree_insert_at(c, NULL, NULL, NULL,
BTREE_INSERT_ATOMIC,
BTREE_INSERT_ENTRY(iter, &tmp.key));
}
* that we've already tried to move the data MAX_DATA_OFF_ITER times and
* are not likely to succeed if we try again.
*/
-int bch_flag_data_bad(struct bch_dev *ca)
+int bch2_flag_data_bad(struct bch_dev *ca)
{
int ret = 0;
struct bkey_s_c k;
struct bkey_s_c_extent e;
struct btree_iter iter;
- bch_btree_iter_init(&iter, ca->fs, BTREE_ID_EXTENTS, POS_MIN);
+ bch2_btree_iter_init(&iter, ca->fs, BTREE_ID_EXTENTS, POS_MIN);
- while ((k = bch_btree_iter_peek(&iter)).k &&
+ while ((k = bch2_btree_iter_peek(&iter)).k &&
!(ret = btree_iter_err(k))) {
if (!bkey_extent_is_data(k.k))
goto advance;
e = bkey_s_c_to_extent(k);
- if (!bch_extent_has_device(e, ca->dev_idx))
+ if (!bch2_extent_has_device(e, ca->dev_idx))
goto advance;
- ret = bch_flag_key_bad(&iter, ca, e);
+ ret = bch2_flag_key_bad(&iter, ca, e);
/*
* don't want to leave ret == -EINTR, since if we raced and
*/
continue;
advance:
- bch_btree_iter_advance_pos(&iter);
+ bch2_btree_iter_advance_pos(&iter);
}
- bch_btree_iter_unlock(&iter);
+ bch2_btree_iter_unlock(&iter);
return ret;
}