Skip to content

Commit 8a004d2

Browse files
committed
Fix: sbd-md: properly destroy io-context
1 parent 986798e commit 8a004d2

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/sbd-md.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ close_device(struct sbd_context *st)
9292
if (!st) {
9393
return;
9494
}
95+
if (st->ioctx) {
96+
io_destroy(st->ioctx);
97+
}
9598
if (st->devfd >= 0) {
9699
close(st->devfd);
97100
}

tests/sbd-testbed.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ typedef int (*orig_close_f_type)(int fd);
6363
typedef FILE *(*orig_fopen_f_type)(const char *pathname, const char *mode);
6464
typedef int (*orig_fclose_f_type)(FILE *fp);
6565
typedef int (*orig_io_setup_f_type)(int nr_events, io_context_t *ctx_idp);
66+
typedef int (*orig_io_destroy_f_type)(io_context_t ctx_id);
6667
typedef int (*orig_io_submit_f_type)(io_context_t ctx_id, long nr, struct iocb *ios[]);
6768
typedef int (*orig_io_getevents_f_type)(io_context_t ctx_id, long min_nr, long nr,
6869
struct io_event *events, struct timespec *timeout);
@@ -93,6 +94,7 @@ static orig_close_f_type orig_close = NULL;
9394
static orig_fopen_f_type orig_fopen = NULL;
9495
static orig_fclose_f_type orig_fclose = NULL;
9596
static orig_io_setup_f_type orig_io_setup = NULL;
97+
static orig_io_destroy_f_type orig_io_destroy = NULL;
9698
static orig_io_submit_f_type orig_io_submit = NULL;
9799
static orig_io_getevents_f_type orig_io_getevents = NULL;
98100
static orig_io_cancel_f_type orig_io_cancel = NULL;
@@ -158,6 +160,7 @@ init (void)
158160
exit(1);
159161
}
160162
orig_io_setup = (orig_io_setup_f_type)dlsym_fatal(handle,"io_setup");
163+
orig_io_destroy = (orig_io_destroy_f_type)dlsym_fatal(handle,"io_destroy");
161164
orig_io_submit = (orig_io_submit_f_type)dlsym_fatal(handle,"io_submit");
162165
orig_io_getevents = (orig_io_getevents_f_type)dlsym_fatal(handle,"io_getevents");
163166
orig_io_cancel = (orig_io_cancel_f_type)dlsym_fatal(handle,"io_cancel");
@@ -625,6 +628,19 @@ int io_setup(int nr_events, io_context_t *ctx_idp)
625628
return 0;
626629
}
627630

631+
int io_destroy(io_context_t ctx_id)
632+
{
633+
init();
634+
635+
if (!translate_aio) {
636+
return orig_io_destroy(ctx_id);
637+
}
638+
639+
if (ctx_id != &our_io_context) {
640+
return EINVAL;
641+
}
642+
return 0;
643+
}
628644

629645
int io_submit(io_context_t ctx_id, long nr, struct iocb *ios[])
630646
{

0 commit comments

Comments
 (0)