Skip to content

Commit 53325c6

Browse files
author
Rafal Stefanowski
committed
Multiple fixes
- update cache IO channels after device detach/attach - fix management queue refcount - fix IO channels double free - handle spdk_thread_send_msg() errors - do not allow using OCF core as base bdev for another OCF core - remove redundant checks - remove cluttering logs Change-Id: I34f2aceb434d5752c787ae6071cce3930bc44575 Signed-off-by: Rafal Stefanowski <rafal.stefanowski@huawei.com>
1 parent a06263a commit 53325c6

File tree

8 files changed

+253
-88
lines changed

8 files changed

+253
-88
lines changed

module/bdev/ocf/ctx.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ vbdev_ocf_ctx_cleaner_init(ocf_cleaner_t c)
342342
}
343343

344344
priv->mngt_queue = vbdev_ocf_cache->cache_mngt_q;
345+
ocf_queue_get(priv->mngt_queue);
345346

346347
ocf_cleaner_set_cmpl(c, cleaner_cmpl);
347348
ocf_cleaner_set_priv(c, priv);

module/bdev/ocf/vbdev_ocf.c

Lines changed: 52 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ static void
209209
_cache_stop_cb(ocf_cache_t cache, void *cb_arg, int error)
210210
{
211211
struct vbdev_ocf_mngt_ctx *mngt_ctx = cb_arg;
212-
ocf_queue_t cache_mngt_q = ((struct vbdev_ocf_cache *)ocf_cache_get_priv(cache))->cache_mngt_q;
213212

214213
SPDK_DEBUGLOG(vbdev_ocf, "OCF cache '%s': finishing stop of OCF cache\n",
215214
ocf_cache_get_name(cache));
@@ -225,11 +224,8 @@ _cache_stop_cb(ocf_cache_t cache, void *cb_arg, int error)
225224
if (!error || !mngt_ctx) {
226225
if (vbdev_ocf_cache_is_base_attached(cache)) {
227226
vbdev_ocf_cache_base_detach(cache);
228-
} else {
229-
/* If device was not attached to cache, then
230-
* cache stop won't put its management queue. */
231-
ocf_queue_put(cache_mngt_q);
232227
}
228+
vbdev_ocf_cache_mngt_queue_put(cache);
233229
vbdev_ocf_cache_destroy(cache);
234230
}
235231

@@ -293,7 +289,6 @@ _cache_stop_core_unregister_cb(void *cb_arg, int error)
293289
ocf_core_get_name(core), spdk_strerror(-error));
294290
}
295291

296-
ocf_mngt_cache_put(cache);
297292
vbdev_ocf_core_destroy(core_ctx);
298293

299294
if (ocf_cache_get_core_count(cache) == ocf_cache_get_core_inactive_count(cache)) {
@@ -307,7 +302,6 @@ static int
307302
_cache_stop_core_visitor(ocf_core_t core, void *cb_arg)
308303
{
309304
struct vbdev_ocf_mngt_ctx *mngt_ctx = cb_arg;
310-
ocf_cache_t cache = ocf_core_get_cache(core);
311305
struct vbdev_ocf_core *core_ctx = ocf_core_get_priv(core);
312306
int rc = 0;
313307

@@ -316,13 +310,11 @@ _cache_stop_core_visitor(ocf_core_t core, void *cb_arg)
316310
if (!core_ctx) {
317311
/* Skip this core. If there is no context, it means that this core
318312
* was added from metadata during cache load and it's just an empty shell. */
319-
ocf_mngt_cache_put(cache);
320313
return 0;
321314
}
322315

323316
/* If core is detached it's already unregistered, so just free its data and exit. */
324317
if (!vbdev_ocf_core_is_base_attached(core_ctx)) {
325-
ocf_mngt_cache_put(cache);
326318
vbdev_ocf_core_destroy(core_ctx);
327319
return 0;
328320
}
@@ -332,7 +324,6 @@ _cache_stop_core_visitor(ocf_core_t core, void *cb_arg)
332324
if ((rc = vbdev_ocf_core_unregister(core_ctx, _cache_stop_core_unregister_cb, core))) {
333325
SPDK_ERRLOG("OCF core '%s': failed to start unregistering OCF vbdev: %s\n",
334326
ocf_core_get_name(core), spdk_strerror(-rc));
335-
ocf_mngt_cache_put(cache);
336327
return rc;
337328
}
338329

@@ -342,18 +333,10 @@ _cache_stop_core_visitor(ocf_core_t core, void *cb_arg)
342333
static int
343334
_module_fini_cache_visitor(ocf_cache_t cache, void *cb_arg)
344335
{
345-
int i, rc = 0;
336+
int rc;
346337

347338
SPDK_DEBUGLOG(vbdev_ocf, "OCF cache '%s': module stop visit\n", ocf_cache_get_name(cache));
348339

349-
/* Increment cache refcount to not destroy cache structs before destroying all cores. */
350-
for (i = ocf_cache_get_core_count(cache); i > 0; i--) {
351-
if ((rc = ocf_mngt_cache_get(cache))) {
352-
SPDK_ERRLOG("OCF cache '%s': failed to increment refcount: %s\n",
353-
ocf_cache_get_name(cache), spdk_strerror(-rc));
354-
}
355-
}
356-
357340
if (!ocf_cache_get_core_count(cache) ||
358341
ocf_cache_get_core_count(cache) == ocf_cache_get_core_inactive_count(cache)) {
359342
/* If there are no cores or all of them are detached,
@@ -439,6 +422,12 @@ _examine_config_core_visitor(ocf_core_t core, void *cb_arg)
439422
SPDK_NOTICELOG("OCF core '%s': base bdev '%s' found\n",
440423
ocf_core_get_name(core), bdev_name);
441424

425+
if (!strcmp(spdk_bdev_get_product_name(spdk_bdev_get_by_name(bdev_name)), "OCF_disk")) {
426+
SPDK_ERRLOG("OCF core '%s': base bdev '%s' is already an OCF core\n",
427+
ocf_core_get_name(core), bdev_name);
428+
return -ENOTSUP;
429+
}
430+
442431
assert(!vbdev_ocf_core_is_base_attached(core_ctx));
443432

444433
if ((rc = vbdev_ocf_core_base_attach(core_ctx, bdev_name))) {
@@ -506,11 +495,20 @@ vbdev_ocf_module_examine_config(struct spdk_bdev *bdev)
506495
SPDK_NOTICELOG("OCF core '%s': base bdev '%s' found\n",
507496
vbdev_ocf_core_get_name(core_ctx), bdev_name);
508497

498+
if (!strcmp(spdk_bdev_get_product_name(bdev), "OCF_disk")) {
499+
SPDK_ERRLOG("OCF core '%s': base bdev '%s' is already an OCF core\n",
500+
vbdev_ocf_core_get_name(core_ctx), bdev_name);
501+
spdk_bdev_module_examine_done(&ocf_if);
502+
return;
503+
}
504+
509505
assert(!vbdev_ocf_core_is_base_attached(core_ctx));
510506

511507
if ((rc = vbdev_ocf_core_base_attach(core_ctx, bdev_name))) {
512508
SPDK_ERRLOG("OCF core '%s': failed to attach base bdev '%s': %s\n",
513509
vbdev_ocf_core_get_name(core_ctx), bdev_name, spdk_strerror(-rc));
510+
spdk_bdev_module_examine_done(&ocf_if);
511+
return;
514512
}
515513

516514
spdk_bdev_module_examine_done(&ocf_if);
@@ -627,7 +625,13 @@ _cache_attach_examine_attach_cb(ocf_cache_t cache, void *cb_arg, int error)
627625
} else {
628626
SPDK_NOTICELOG("OCF cache '%s': device attached\n", ocf_cache_get_name(cache));
629627

630-
vbdev_ocf_core_add_from_waitlist(cache);
628+
/* Update cache IO channel after new device attach. */
629+
if ((error = vbdev_ocf_core_create_cache_channel(cache))) {
630+
SPDK_ERRLOG("OCF cache '%s': failed to create channel for newly attached cache: %s\n",
631+
ocf_cache_get_name(cache), spdk_strerror(-error));
632+
} else {
633+
vbdev_ocf_core_add_from_waitlist(cache);
634+
}
631635
}
632636

633637
spdk_bdev_module_examine_done(&ocf_if);
@@ -843,9 +847,6 @@ _vbdev_ocf_submit_io_cb(ocf_io_t io, void *priv1, void *priv2, int error)
843847
{
844848
struct spdk_bdev_io *bdev_io = priv1;
845849

846-
SPDK_DEBUGLOG(vbdev_ocf, "OCF vbdev '%s': finishing submit of IO request\n",
847-
spdk_bdev_get_name(bdev_io->bdev));
848-
849850
ocf_io_put(io);
850851

851852
if (error == -OCF_ERR_NO_MEM) {
@@ -870,13 +871,8 @@ vbdev_ocf_submit_io(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io, ui
870871
struct vbdev_ocf_core_io_channel_ctx *ch_ctx = spdk_io_channel_get_ctx(ch);
871872
ocf_io_t io = NULL;
872873

873-
// impossible to be true ?
874-
if (!core) {
875-
SPDK_ERRLOG("OCF vbdev '%s': failed to submit IO - no OCF core device\n",
876-
spdk_bdev_get_name(bdev_io->bdev));
877-
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
878-
return;
879-
}
874+
/* OCF core should be added before vbdev register and removed after vbdev unregister. */
875+
assert(core);
880876

881877
io = ocf_volume_new_io(ocf_core_get_front_volume(core), ch_ctx->queue,
882878
offset, len, dir, 0, flags);
@@ -917,9 +913,6 @@ vbdev_ocf_fn_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bde
917913
uint64_t offset = bdev_io->u.bdev.offset_blocks * bdev_io->bdev->blocklen;
918914
uint32_t len = bdev_io->u.bdev.num_blocks * bdev_io->bdev->blocklen;
919915

920-
SPDK_DEBUGLOG(vbdev_ocf, "OCF vbdev '%s': initiating submit of IO request\n",
921-
spdk_bdev_get_name(bdev_io->bdev));
922-
923916
switch (bdev_io->type) {
924917
case SPDK_BDEV_IO_TYPE_READ:
925918
// align buffer for write as well ? (comment in old vbdev_ocf.c)
@@ -948,9 +941,6 @@ vbdev_ocf_fn_io_type_supported(void *ctx, enum spdk_bdev_io_type io_type)
948941
ocf_core_t core = ctx;
949942
struct vbdev_ocf_core *core_ctx = ocf_core_get_priv(core);
950943

951-
SPDK_DEBUGLOG(vbdev_ocf, "OCF vbdev '%s': checking if IO type '%s' is supported\n",
952-
spdk_bdev_get_name(&core_ctx->ocf_vbdev), spdk_bdev_get_io_type_name(io_type));
953-
954944
switch (io_type) {
955945
case SPDK_BDEV_IO_TYPE_READ:
956946
case SPDK_BDEV_IO_TYPE_WRITE:
@@ -994,7 +984,6 @@ _cache_start_rpc_err_cb(ocf_cache_t cache, void *cb_arg, int error)
994984

995985
vbdev_ocf_cache_destroy(cache);
996986
ocf_mngt_cache_unlock(cache); // use in error path only ?
997-
//ocf_mngt_cache_put(cache); // no need ? (check refcnt)
998987
}
999988

1000989
static void
@@ -1018,7 +1007,7 @@ _cache_start_rpc_attach_cb(ocf_cache_t cache, void *cb_arg, int error)
10181007
}
10191008

10201009
vbdev_ocf_cache_base_detach(cache);
1021-
ocf_queue_put(((struct vbdev_ocf_cache *)ocf_cache_get_priv(cache))->cache_mngt_q); // needed ?
1010+
vbdev_ocf_cache_mngt_queue_put(cache);
10221011
ocf_mngt_cache_stop(cache, _cache_start_rpc_err_cb, NULL);
10231012
} else {
10241013
SPDK_NOTICELOG("OCF cache '%s': started\n", ocf_cache_get_name(cache));
@@ -1110,7 +1099,7 @@ vbdev_ocf_cache_start(const char *cache_name, const char *base_name,
11101099
err_volume:
11111100
vbdev_ocf_cache_base_detach(cache);
11121101
err_base:
1113-
ocf_queue_put(((struct vbdev_ocf_cache *)ocf_cache_get_priv(cache))->cache_mngt_q);
1102+
vbdev_ocf_cache_mngt_queue_put(cache);
11141103
err_queue:
11151104
ocf_mngt_cache_stop(cache, _cache_start_rpc_err_cb, NULL);
11161105
err_create:
@@ -1124,7 +1113,7 @@ vbdev_ocf_cache_stop(const char *cache_name, vbdev_ocf_rpc_mngt_cb rpc_cb_fn, vo
11241113
{
11251114
ocf_cache_t cache;
11261115
struct vbdev_ocf_mngt_ctx *mngt_ctx;
1127-
int i, rc;
1116+
int rc;
11281117

11291118
SPDK_DEBUGLOG(vbdev_ocf, "OCF cache '%s': initiating stop\n", cache_name);
11301119

@@ -1145,18 +1134,6 @@ vbdev_ocf_cache_stop(const char *cache_name, vbdev_ocf_rpc_mngt_cb rpc_cb_fn, vo
11451134
mngt_ctx->rpc_cb_arg = rpc_cb_arg;
11461135
mngt_ctx->cache = cache;
11471136

1148-
/* Increment cache refcount to not destroy cache structs before destroying all cores. */
1149-
for (i = ocf_cache_get_core_count(cache); i > 0; i--) {
1150-
if ((rc = ocf_mngt_cache_get(cache))) {
1151-
SPDK_ERRLOG("OCF cache '%s': failed to increment refcount (OCF error: %d)\n",
1152-
ocf_cache_get_name(cache), rc);
1153-
for (i = ocf_cache_get_core_count(cache) - i; i > 0; i--) {
1154-
ocf_mngt_cache_put(cache);
1155-
}
1156-
goto err_get;
1157-
}
1158-
}
1159-
11601137
if (!ocf_cache_get_core_count(cache) ||
11611138
ocf_cache_get_core_count(cache) == ocf_cache_get_core_inactive_count(cache)) {
11621139
/* If there are no cores or all of them are detached,
@@ -1167,14 +1144,12 @@ vbdev_ocf_cache_stop(const char *cache_name, vbdev_ocf_rpc_mngt_cb rpc_cb_fn, vo
11671144
if ((rc = ocf_core_visit(cache, _cache_stop_core_visitor, mngt_ctx, false))) {
11681145
SPDK_ERRLOG("OCF cache '%s': failed to iterate over core bdevs: %s\n",
11691146
ocf_cache_get_name(cache), spdk_strerror(-rc));
1170-
// ocf_mngt_cache_put() ? how many times ?
11711147
goto err_visit;
11721148
}
11731149

11741150
return;
11751151

11761152
err_visit:
1177-
err_get:
11781153
free(mngt_ctx);
11791154
err_alloc:
11801155
ocf_mngt_cache_put(cache);
@@ -1195,12 +1170,16 @@ _cache_detach_rpc_detach_cb(ocf_cache_t cache, void *cb_arg, int error)
11951170
ocf_cache_get_name(cache), error);
11961171
} else {
11971172
vbdev_ocf_cache_base_detach(cache);
1173+
1174+
/* Update cache IO channel after device detach. */
1175+
if ((error = vbdev_ocf_core_destroy_cache_channel(cache))) {
1176+
SPDK_ERRLOG("OCF cache '%s': failed to destroy channel for detached cache: %s\n",
1177+
ocf_cache_get_name(cache), spdk_strerror(-error));
1178+
}
1179+
11981180
SPDK_NOTICELOG("OCF cache '%s': device detached\n", ocf_cache_get_name(cache));
11991181
}
12001182

1201-
/* Increment queue refcount to prevent destroying management queue after cache device detach. */
1202-
ocf_queue_get(((struct vbdev_ocf_cache *)ocf_cache_get_priv(cache))->cache_mngt_q);
1203-
12041183
mngt_ctx->rpc_cb_fn(ocf_cache_get_name(cache), mngt_ctx->rpc_cb_arg, error);
12051184
ocf_mngt_cache_unlock(cache);
12061185
ocf_mngt_cache_put(cache);
@@ -1319,7 +1298,13 @@ _cache_attach_rpc_attach_cb(ocf_cache_t cache, void *cb_arg, int error)
13191298
} else {
13201299
SPDK_NOTICELOG("OCF cache '%s': device attached\n", ocf_cache_get_name(cache));
13211300

1322-
vbdev_ocf_core_add_from_waitlist(cache);
1301+
/* Update cache IO channel after new device attach. */
1302+
if ((error = vbdev_ocf_core_create_cache_channel(cache))) {
1303+
SPDK_ERRLOG("OCF cache '%s': failed to create channel for newly attached cache: %s\n",
1304+
ocf_cache_get_name(cache), spdk_strerror(-error));
1305+
} else {
1306+
vbdev_ocf_core_add_from_waitlist(cache);
1307+
}
13231308
}
13241309

13251310
mngt_ctx->rpc_cb_fn(ocf_cache_get_name(cache), mngt_ctx->rpc_cb_arg, error);
@@ -1543,7 +1528,13 @@ vbdev_ocf_core_add(const char *core_name, const char *base_name, const char *cac
15431528
}
15441529
SPDK_ERRLOG("OCF core '%s': failed to attach base bdev '%s': %s\n",
15451530
core_name, base_name, spdk_strerror(-rc));
1546-
goto err_base;
1531+
goto err_no_base;
1532+
}
1533+
1534+
if (!strcmp(spdk_bdev_get_product_name(spdk_bdev_get_by_name(base_name)), "OCF_disk")) {
1535+
SPDK_ERRLOG("OCF core '%s': base bdev '%s' is already an OCF core\n", core_name, base_name);
1536+
rc = -ENOTSUP;
1537+
goto err_ocf_base;
15471538
}
15481539

15491540
/* Second, check if OCF cache for this core is already started. */
@@ -1603,8 +1594,9 @@ vbdev_ocf_core_add(const char *core_name, const char *base_name, const char *cac
16031594
err_alloc:
16041595
err_bsize:
16051596
ocf_mngt_cache_put(cache);
1597+
err_ocf_base:
16061598
vbdev_ocf_core_base_detach(core_ctx);
1607-
err_base:
1599+
err_no_base:
16081600
vbdev_ocf_core_destroy(core_ctx);
16091601
err_create:
16101602
err_exist:

0 commit comments

Comments
 (0)