From 64fc348a616ce622ae3611835144699a2a84ed6d Mon Sep 17 00:00:00 2001 From: David Teigland Date: Jan 22 2016 18:00:02 +0000 Subject: sanlock: use io_destroy to clear outstanding aio When a lockspace thread attempts to clear outstanding aio ops, it was using io_getevents indefinitely to wait for completions. Now, it uses io_getevents to clear the ops for up to 2 minutes, after which it uses io_destroy to clear them. io_destroy may have the ability clear certain ops that will never have a completion. --- diff --git a/src/task.c b/src/task.c index 144f5f8..f3c10f8 100644 --- a/src/task.c +++ b/src/task.c @@ -68,7 +68,9 @@ void close_task_aio(struct task *task) struct timespec ts; struct io_event event; uint64_t last_warn; - int rv, i, used, warn; + uint64_t begin; + uint64_t now; + int rv, i, used, lvl; if (!task->use_aio) goto skip_aio; @@ -77,16 +79,19 @@ void close_task_aio(struct task *task) ts.tv_sec = DEFAULT_IO_TIMEOUT; last_warn = time(NULL); + begin = last_warn; /* wait for all outstanding aio to complete before destroying aio context, freeing iocb and buffers */ while (1) { - warn = 0; + now = time(NULL); - if (time(NULL) - last_warn >= DEFAULT_IO_TIMEOUT) { - last_warn = time(NULL); - warn = 1; + if (now - last_warn >= (DEFAULT_IO_TIMEOUT * 6)) { + last_warn = now; + lvl = LOG_ERR; + } else { + lvl = LOG_DEBUG; } used = 0; @@ -96,15 +101,16 @@ void close_task_aio(struct task *task) continue; used++; - if (!warn) - continue; - log_taske(task, "close_task_aio %d %p busy", + log_level(0, 0, task->name, lvl, "close_task_aio %d %p busy", i, &task->callbacks[i]); } if (!used) break; + if (now - begin >= 120) + break; + memset(&event, 0, sizeof(event)); rv = io_getevents(task->aio_ctx, 1, 1, &event, &ts); @@ -127,8 +133,15 @@ void close_task_aio(struct task *task) ev_aicb->buf = NULL; } } + + if (used) + log_taskd(task, "close_task_aio destroy %d incomplete ops", used); + io_destroy(task->aio_ctx); + if (used) + log_taske(task, "close_task_aio destroyed %d incomplete ops", used); + if (task->iobuf) free(task->iobuf);