Commit 3000855c authored by Kent Overstreet's avatar Kent Overstreet
Browse files

bcachefs: io_opts_to_rebalance_opts()



New helper to simplify bch2_bkey_set_needs_rebalance()

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 5fffe1a3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -357,7 +357,7 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
						k.k->p, bkey_start_pos(&insert->k)) ?:
			bch2_insert_snapshot_whiteouts(trans, m->btree_id,
						k.k->p, insert->k.p) ?:
			bch2_bkey_set_needs_rebalance(c, insert, &op->opts) ?:
			bch2_bkey_set_needs_rebalance(c, &op->opts, insert) ?:
			bch2_trans_update(trans, &iter, insert,
				BTREE_UPDATE_internal_snapshot_node) ?:
			bch2_trans_commit(trans, &op->res,
+16 −44
Original line number Diff line number Diff line
@@ -1478,55 +1478,27 @@ u64 bch2_bkey_sectors_need_rebalance(struct bch_fs *c, struct bkey_s_c k)
	return sectors;
}

int bch2_bkey_set_needs_rebalance(struct bch_fs *c, struct bkey_i *_k,
				  struct bch_io_opts *opts)
int bch2_bkey_set_needs_rebalance(struct bch_fs *c, struct bch_io_opts *opts,
				  struct bkey_i *_k)
{
	struct bkey_s k = bkey_i_to_s(_k);
	struct bch_extent_rebalance *r;
	unsigned target = opts->background_target;
	unsigned compression = opts->background_compression;
	bool needs_rebalance;

	if (!bkey_extent_is_direct_data(k.k))
	if (!bkey_extent_is_direct_data(&_k->k))
		return 0;

	/* get existing rebalance entry: */
	r = (struct bch_extent_rebalance *) bch2_bkey_rebalance_opts(k.s_c);
	if (r) {
		if (k.k->type == KEY_TYPE_reflink_v) {
			/*
			 * indirect extents: existing options take precedence,
			 * so that we don't move extents back and forth if
			 * they're referenced by different inodes with different
			 * options:
			 */
			if (r->background_target)
				target = r->background_target;
			if (r->background_compression)
				compression = r->background_compression;
		}
	struct bkey_s k = bkey_i_to_s(_k);
	struct bch_extent_rebalance *old =
		(struct bch_extent_rebalance *) bch2_bkey_rebalance_opts(k.s_c);

		r->background_target		= target;
		r->background_compression	= compression;
	if (k.k->type == KEY_TYPE_reflink_v ||
	    bch2_bkey_ptrs_need_rebalance(c, k.s_c, opts->background_target, opts->background_compression)) {
		if (!old) {
			old = bkey_val_end(k);
			k.k->u64s += sizeof(*old) / sizeof(u64);
		}

	needs_rebalance = bch2_bkey_ptrs_need_rebalance(c, k.s_c, target, compression);

	if (needs_rebalance && !r) {
		union bch_extent_entry *new = bkey_val_end(k);

		new->rebalance.type			= 1U << BCH_EXTENT_ENTRY_rebalance;
		new->rebalance.background_compression	= compression;
		new->rebalance.background_target	= target;
		new->rebalance.unused			= 0;
		k.k->u64s += extent_entry_u64s(new);
	} else if (!needs_rebalance && r && k.k->type != KEY_TYPE_reflink_v) {
		/*
		 * For indirect extents, don't delete the rebalance entry when
		 * we're finished so that we know we specifically moved it or
		 * compressed it to its current location/compression type
		 */
		extent_entry_drop(k, (union bch_extent_entry *) r);
		*old = io_opts_to_rebalance_opts(opts);
	} else {
		if (old)
			extent_entry_drop(k, (union bch_extent_entry *) old);
	}

	return 0;
+1 −2
Original line number Diff line number Diff line
@@ -715,8 +715,7 @@ unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *, struct bkey_s_c,
				       unsigned, unsigned);
u64 bch2_bkey_sectors_need_rebalance(struct bch_fs *, struct bkey_s_c);

int bch2_bkey_set_needs_rebalance(struct bch_fs *, struct bkey_i *,
				  struct bch_io_opts *);
int bch2_bkey_set_needs_rebalance(struct bch_fs *, struct bch_io_opts *, struct bkey_i *);

/* Generic extent code: */

+5 −0
Original line number Diff line number Diff line
@@ -215,6 +215,11 @@ struct bch_extent_rebalance {
#endif
};

/* subset of BCH_INODE_OPTS */
#define BCH_REBALANCE_OPTS()			\
	x(background_compression)		\
	x(background_target)

union bch_extent_entry {
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ||  __BITS_PER_LONG == 64
	unsigned long			type;
+1 −1
Original line number Diff line number Diff line
@@ -461,7 +461,7 @@ case LOGGED_OP_FINSERT_shift_extents:

		op->v.pos = cpu_to_le64(insert ? bkey_start_offset(&delete.k) : delete.k.p.offset);

		ret =   bch2_bkey_set_needs_rebalance(c, copy, &opts) ?:
		ret =   bch2_bkey_set_needs_rebalance(c, &opts, copy) ?:
			bch2_btree_insert_trans(trans, BTREE_ID_extents, &delete, 0) ?:
			bch2_btree_insert_trans(trans, BTREE_ID_extents, copy, 0) ?:
			bch2_logged_op_update(trans, &op->k_i) ?:
Loading