Skip to content

Commit e6ee8c0

Browse files
Kiyoshi Uedakergon
authored andcommitted
dm: enable request based option
This patch enables request-based dm. o Request-based dm and bio-based dm coexist, since there are some target drivers which are more fitting to bio-based dm. Also, there are other bio-based devices in the kernel (e.g. md, loop). Since bio-based device can't receive struct request, there are some limitations on device stacking between bio-based and request-based. type of underlying device bio-based request-based ---------------------------------------------- bio-based OK OK request-based -- OK The device type is recognized by the queue flag in the kernel, so dm follows that. o The type of a dm device is decided at the first table binding time. Once the type of a dm device is decided, the type can't be changed. o Mempool allocations are deferred to at the table loading time, since mempools for request-based dm are different from those for bio-based dm and needed mempool type is fixed by the type of table. o Currently, request-based dm supports only tables that have a single target. To support multiple targets, we need to support request splitting or prevent bio/request from spanning multiple targets. The former needs lots of changes in the block layer, and the latter needs that all target drivers support merge() function. Both will take a time. Signed-off-by: Kiyoshi Ueda <k-ueda@ct.jp.nec.com> Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com>
1 parent cec47e3 commit e6ee8c0

4 files changed

Lines changed: 285 additions & 26 deletions

File tree

‎drivers/md/dm-ioctl.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,12 @@ static int populate_table(struct dm_table *table,
10501050
next = spec->next;
10511051
}
10521052

1053+
r = dm_table_set_type(table);
1054+
if (r) {
1055+
DMWARN("unable to set table type");
1056+
return r;
1057+
}
1058+
10531059
return dm_table_complete(table);
10541060
}
10551061

@@ -1095,6 +1101,13 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
10951101
goto out;
10961102
}
10971103

1104+
r = dm_table_alloc_md_mempools(t);
1105+
if (r) {
1106+
DMWARN("unable to allocate mempools for this table");
1107+
dm_table_destroy(t);
1108+
goto out;
1109+
}
1110+
10981111
down_write(&_hash_lock);
10991112
hc = dm_get_mdptr(md);
11001113
if (!hc || hc->md != md) {

‎drivers/md/dm-table.c‎

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
struct dm_table {
4242
struct mapped_device *md;
4343
atomic_t holders;
44+
unsigned type;
4445

4546
/* btree table */
4647
unsigned int depth;
@@ -65,6 +66,8 @@ struct dm_table {
6566
/* events get handed up using this callback */
6667
void (*event_fn)(void *);
6768
void *event_context;
69+
70+
struct dm_md_mempools *mempools;
6871
};
6972

7073
/*
@@ -258,6 +261,8 @@ void dm_table_destroy(struct dm_table *t)
258261
if (t->devices.next != &t->devices)
259262
free_devices(&t->devices);
260263

264+
dm_free_md_mempools(t->mempools);
265+
261266
kfree(t);
262267
}
263268

@@ -764,6 +769,99 @@ int dm_table_add_target(struct dm_table *t, const char *type,
764769
return r;
765770
}
766771

772+
int dm_table_set_type(struct dm_table *t)
773+
{
774+
unsigned i;
775+
unsigned bio_based = 0, request_based = 0;
776+
struct dm_target *tgt;
777+
struct dm_dev_internal *dd;
778+
struct list_head *devices;
779+
780+
for (i = 0; i < t->num_targets; i++) {
781+
tgt = t->targets + i;
782+
if (dm_target_request_based(tgt))
783+
request_based = 1;
784+
else
785+
bio_based = 1;
786+
787+
if (bio_based && request_based) {
788+
DMWARN("Inconsistent table: different target types"
789+
" can't be mixed up");
790+
return -EINVAL;
791+
}
792+
}
793+
794+
if (bio_based) {
795+
/* We must use this table as bio-based */
796+
t->type = DM_TYPE_BIO_BASED;
797+
return 0;
798+
}
799+
800+
BUG_ON(!request_based); /* No targets in this table */
801+
802+
/* Non-request-stackable devices can't be used for request-based dm */
803+
devices = dm_table_get_devices(t);
804+
list_for_each_entry(dd, devices, list) {
805+
if (!blk_queue_stackable(bdev_get_queue(dd->dm_dev.bdev))) {
806+
DMWARN("table load rejected: including"
807+
" non-request-stackable devices");
808+
return -EINVAL;
809+
}
810+
}
811+
812+
/*
813+
* Request-based dm supports only tables that have a single target now.
814+
* To support multiple targets, request splitting support is needed,
815+
* and that needs lots of changes in the block-layer.
816+
* (e.g. request completion process for partial completion.)
817+
*/
818+
if (t->num_targets > 1) {
819+
DMWARN("Request-based dm doesn't support multiple targets yet");
820+
return -EINVAL;
821+
}
822+
823+
t->type = DM_TYPE_REQUEST_BASED;
824+
825+
return 0;
826+
}
827+
828+
unsigned dm_table_get_type(struct dm_table *t)
829+
{
830+
return t->type;
831+
}
832+
833+
bool dm_table_request_based(struct dm_table *t)
834+
{
835+
return dm_table_get_type(t) == DM_TYPE_REQUEST_BASED;
836+
}
837+
838+
int dm_table_alloc_md_mempools(struct dm_table *t)
839+
{
840+
unsigned type = dm_table_get_type(t);
841+
842+
if (unlikely(type == DM_TYPE_NONE)) {
843+
DMWARN("no table type is set, can't allocate mempools");
844+
return -EINVAL;
845+
}
846+
847+
t->mempools = dm_alloc_md_mempools(type);
848+
if (!t->mempools)
849+
return -ENOMEM;
850+
851+
return 0;
852+
}
853+
854+
void dm_table_free_md_mempools(struct dm_table *t)
855+
{
856+
dm_free_md_mempools(t->mempools);
857+
t->mempools = NULL;
858+
}
859+
860+
struct dm_md_mempools *dm_table_get_md_mempools(struct dm_table *t)
861+
{
862+
return t->mempools;
863+
}
864+
767865
static int setup_indexes(struct dm_table *t)
768866
{
769867
int i;
@@ -985,6 +1083,19 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
9851083
queue_flag_set_unlocked(QUEUE_FLAG_CLUSTER, q);
9861084

9871085
dm_table_set_integrity(t);
1086+
1087+
/*
1088+
* QUEUE_FLAG_STACKABLE must be set after all queue settings are
1089+
* visible to other CPUs because, once the flag is set, incoming bios
1090+
* are processed by request-based dm, which refers to the queue
1091+
* settings.
1092+
* Until the flag set, bios are passed to bio-based dm and queued to
1093+
* md->deferred where queue settings are not needed yet.
1094+
* Those bios are passed to request-based dm at the resume time.
1095+
*/
1096+
smp_mb();
1097+
if (dm_table_request_based(t))
1098+
queue_flag_set_unlocked(QUEUE_FLAG_STACKABLE, q);
9881099
}
9891100

9901101
unsigned int dm_table_get_num_targets(struct dm_table *t)

0 commit comments

Comments
 (0)