Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / md / dm-bio-prison-v1.h
blobd39706c484476a5b8c9eb24097ae1705a6d2e79d
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (C) 2011-2017 Red Hat, Inc.
5 * This file is released under the GPL.
6 */
8 #ifndef DM_BIO_PRISON_H
9 #define DM_BIO_PRISON_H
11 #include "persistent-data/dm-block-manager.h" /* FIXME: for dm_block_t */
12 #include "dm-thin-metadata.h" /* FIXME: for dm_thin_id */
14 #include <linux/bio.h>
15 #include <linux/rbtree.h>
17 /*----------------------------------------------------------------*/
20 * Sometimes we can't deal with a bio straight away. We put them in prison
21 * where they can't cause any mischief. Bios are put in a cell identified
22 * by a key, multiple bios can be in the same cell. When the cell is
23 * subsequently unlocked the bios become available.
25 struct dm_bio_prison;
28 * Keys define a range of blocks within either a virtual or physical
29 * device.
31 struct dm_cell_key {
32 int virtual;
33 dm_thin_id dev;
34 dm_block_t block_begin, block_end;
38 * The range of a key (block_end - block_begin) must not
39 * exceed BIO_PRISON_MAX_RANGE. Also the range must not
40 * cross a similarly sized boundary.
42 * Must be a power of 2.
44 #define BIO_PRISON_MAX_RANGE 1024
45 #define BIO_PRISON_MAX_RANGE_SHIFT 10
48 * Treat this as opaque, only in header so callers can manage allocation
49 * themselves.
51 struct dm_bio_prison_cell {
52 struct list_head user_list; /* for client use */
53 struct rb_node node;
55 struct dm_cell_key key;
56 struct bio *holder;
57 struct bio_list bios;
60 struct dm_bio_prison *dm_bio_prison_create(void);
61 void dm_bio_prison_destroy(struct dm_bio_prison *prison);
64 * These two functions just wrap a mempool. This is a transitory step:
65 * Eventually all bio prison clients should manage their own cell memory.
67 * Like mempool_alloc(), dm_bio_prison_alloc_cell() can only fail if called
68 * in interrupt context or passed GFP_NOWAIT.
70 struct dm_bio_prison_cell *dm_bio_prison_alloc_cell(struct dm_bio_prison *prison,
71 gfp_t gfp);
72 void dm_bio_prison_free_cell(struct dm_bio_prison *prison,
73 struct dm_bio_prison_cell *cell);
76 * Returns false if key is beyond BIO_PRISON_MAX_RANGE or spans a boundary.
78 bool dm_cell_key_has_valid_range(struct dm_cell_key *key);
81 * An atomic op that combines retrieving or creating a cell, and adding a
82 * bio to it.
84 * Returns 1 if the cell was already held, 0 if @inmate is the new holder.
86 int dm_bio_detain(struct dm_bio_prison *prison,
87 struct dm_cell_key *key,
88 struct bio *inmate,
89 struct dm_bio_prison_cell *cell_prealloc,
90 struct dm_bio_prison_cell **cell_result);
92 void dm_cell_release(struct dm_bio_prison *prison,
93 struct dm_bio_prison_cell *cell,
94 struct bio_list *bios);
95 void dm_cell_release_no_holder(struct dm_bio_prison *prison,
96 struct dm_bio_prison_cell *cell,
97 struct bio_list *inmates);
98 void dm_cell_error(struct dm_bio_prison *prison,
99 struct dm_bio_prison_cell *cell, blk_status_t error);
102 * Visits the cell and then releases. Guarantees no new inmates are
103 * inserted between the visit and release.
105 void dm_cell_visit_release(struct dm_bio_prison *prison,
106 void (*visit_fn)(void *, struct dm_bio_prison_cell *),
107 void *context, struct dm_bio_prison_cell *cell);
109 /*----------------------------------------------------------------*/
112 * We use the deferred set to keep track of pending reads to shared blocks.
113 * We do this to ensure the new mapping caused by a write isn't performed
114 * until these prior reads have completed. Otherwise the insertion of the
115 * new mapping could free the old block that the read bios are mapped to.
118 struct dm_deferred_set;
119 struct dm_deferred_entry;
121 struct dm_deferred_set *dm_deferred_set_create(void);
122 void dm_deferred_set_destroy(struct dm_deferred_set *ds);
124 struct dm_deferred_entry *dm_deferred_entry_inc(struct dm_deferred_set *ds);
125 void dm_deferred_entry_dec(struct dm_deferred_entry *entry, struct list_head *head);
126 int dm_deferred_set_add_work(struct dm_deferred_set *ds, struct list_head *work);
128 /*----------------------------------------------------------------*/
130 #endif