- bch2_btree_iter_unlock(&iter);
- }
-
- return 0;
-}
-
-/*
- * This moves only the meta-data off, leaving the data (if any) in place.
- * The data is moved off by bch_move_data_off_device, if desired, and
- * called first.
- *
- * Before calling this, allocation of buckets to the device must have
- * been disabled, as else we'll continue to write meta-data to the device
- * when new buckets are picked for meta-data writes.
- * In addition, the copying gc and allocator threads for the device
- * must have been stopped. The allocator thread is the only thread
- * that writes prio/gen information.
- *
- * Meta-data consists of:
- * - Btree nodes
- * - Prio/gen information
- * - Journal entries
- * - Superblock
- *
- * This has to move the btree nodes and the journal only:
- * - prio/gen information is not written once the allocator thread is stopped.
- * also, as the prio/gen information is per-device it is not moved.
- * - the superblock will be written by the caller once after everything
- * is stopped.
- *
- * Note that currently there is no way to stop btree node and journal
- * meta-data writes to a device without moving the meta-data because
- * once a bucket is open for a btree node, unless a replacement btree
- * node is allocated (and the tree updated), the bucket will continue
- * to be written with updates. Similarly for the journal (it gets
- * written until filled).
- *
- * This routine leaves the data (if any) in place. Whether the data
- * should be moved off is a decision independent of whether the meta
- * data should be moved off and stopped:
- *
- * - For device removal, both data and meta-data are moved off, in
- * that order.
- *
- * - However, for turning a device read-only without removing it, only
- * meta-data is moved off since that's the only way to prevent it
- * from being written. Data is left in the device, but no new data
- * is written.
- */
-
-int bch2_move_metadata_off_device(struct bch_dev *ca)
-{
- struct bch_fs *c = ca->fs;
- unsigned i;
- int ret = 0;
-
- BUG_ON(ca->mi.state == BCH_MEMBER_STATE_RW);
-
- if (!(bch2_dev_has_data(c, ca) &
- ((1 << BCH_DATA_JOURNAL)|
- (1 << BCH_DATA_BTREE))))
- return 0;
-
- mutex_lock(&c->replicas_gc_lock);
- bch2_replicas_gc_start(c,
- (1 << BCH_DATA_JOURNAL)|
- (1 << BCH_DATA_BTREE));