[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 063/104] virtiofsd: Kill threads when queues are stopped
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[PATCH 063/104] virtiofsd: Kill threads when queues are stopped |
Date: |
Thu, 12 Dec 2019 16:38:23 +0000 |
From: "Dr. David Alan Gilbert" <address@hidden>
Kill the threads we've started when the queues get stopped.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
tools/virtiofsd/fuse_virtio.c | 37 +++++++++++++++++++++++++++++++----
1 file changed, 33 insertions(+), 4 deletions(-)
diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
index 3c778b6296..2f11fee46d 100644
--- a/tools/virtiofsd/fuse_virtio.c
+++ b/tools/virtiofsd/fuse_virtio.c
@@ -41,6 +41,7 @@ struct fv_QueueInfo {
/* Our queue index, corresponds to array position */
int qidx;
int kick_fd;
+ int kill_fd; /* For killing the thread */
/* The element for the command currently being processed */
VuVirtqElement *qe;
@@ -410,14 +411,17 @@ static void *fv_queue_thread(void *opaque)
fuse_log(FUSE_LOG_INFO, "%s: Start for queue %d kick_fd %d\n", __func__,
qi->qidx, qi->kick_fd);
while (1) {
- struct pollfd pf[1];
+ struct pollfd pf[2];
pf[0].fd = qi->kick_fd;
pf[0].events = POLLIN;
pf[0].revents = 0;
+ pf[1].fd = qi->kill_fd;
+ pf[1].events = POLLIN;
+ pf[1].revents = 0;
fuse_log(FUSE_LOG_DEBUG, "%s: Waiting for Queue %d event\n", __func__,
qi->qidx);
- int poll_res = ppoll(pf, 1, NULL, NULL);
+ int poll_res = ppoll(pf, 2, NULL, NULL);
if (poll_res == -1) {
if (errno == EINTR) {
@@ -428,12 +432,23 @@ static void *fv_queue_thread(void *opaque)
fuse_log(FUSE_LOG_ERR, "fv_queue_thread ppoll: %m\n");
break;
}
- assert(poll_res == 1);
+ assert(poll_res >= 1);
if (pf[0].revents & (POLLERR | POLLHUP | POLLNVAL)) {
fuse_log(FUSE_LOG_ERR, "%s: Unexpected poll revents %x Queue %d\n",
__func__, pf[0].revents, qi->qidx);
break;
}
+ if (pf[1].revents & (POLLERR | POLLHUP | POLLNVAL)) {
+ fuse_log(FUSE_LOG_ERR,
+ "%s: Unexpected poll revents %x Queue %d killfd\n",
+ __func__, pf[1].revents, qi->qidx);
+ break;
+ }
+ if (pf[1].revents) {
+ fuse_log(FUSE_LOG_INFO, "%s: kill event on queue %d - quitting\n",
+ __func__, qi->qidx);
+ break;
+ }
assert(pf[0].revents & POLLIN);
fuse_log(FUSE_LOG_DEBUG, "%s: Got queue event on Queue %d\n", __func__,
qi->qidx);
@@ -631,15 +646,29 @@ static void fv_queue_set_started(VuDev *dev, int qidx,
bool started)
}
ourqi = vud->qi[qidx];
ourqi->kick_fd = dev->vq[qidx].kick_fd;
+
+ ourqi->kill_fd = eventfd(0, EFD_CLOEXEC | EFD_SEMAPHORE);
+ assert(ourqi->kill_fd != -1);
if (pthread_create(&ourqi->thread, NULL, fv_queue_thread, ourqi)) {
fuse_log(FUSE_LOG_ERR, "%s: Failed to create thread for queue
%d\n",
__func__, qidx);
assert(0);
}
} else {
- /* TODO: Kill the thread */
+ int ret;
assert(qidx < vud->nqueues);
ourqi = vud->qi[qidx];
+
+ /* Kill the thread */
+ if (eventfd_write(ourqi->kill_fd, 1)) {
+ fuse_log(FUSE_LOG_ERR, "Eventfd_read for queue: %m\n");
+ }
+ ret = pthread_join(ourqi->thread, NULL);
+ if (ret) {
+ fuse_log(FUSE_LOG_ERR, "%s: Failed to join thread idx %d err %d\n",
+ __func__, qidx, ret);
+ }
+ close(ourqi->kill_fd);
ourqi->kick_fd = -1;
}
}
--
2.23.0
- [PATCH 053/104] virtiofsd: Drop CAP_FSETID if client asked for it, (continued)
- [PATCH 053/104] virtiofsd: Drop CAP_FSETID if client asked for it, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 054/104] virtiofsd: set maximum RLIMIT_NOFILE limit, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 057/104] virtiofsd: add --syslog command-line option, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 055/104] virtiofsd: fix libfuse information leaks, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 056/104] virtiofsd: add security guide document, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 059/104] virtiofsd: Add ID to the log with FUSE_LOG_DEBUG level, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 060/104] virtiofsd: Add timestamp to the log with FUSE_LOG_DEBUG level, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 058/104] virtiofsd: print log only when priority is high enough, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 061/104] virtiofsd: Handle reinit, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 062/104] virtiofsd: Handle hard reboot, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 063/104] virtiofsd: Kill threads when queues are stopped,
Dr. David Alan Gilbert (git) <=
- [PATCH 064/104] vhost-user: Print unexpected slave message types, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 065/104] contrib/libvhost-user: Protect slave fd with mutex, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 066/104] virtiofsd: passthrough_ll: add renameat2 support, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 067/104] virtiofsd: passthrough_ll: disable readdirplus on cache=never, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 068/104] virtiofsd: passthrough_ll: control readdirplus, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 069/104] virtiofsd: rename unref_inode() to unref_inode_lolocked(), Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 070/104] virtiofsd: fail when parent inode isn't known in lo_do_lookup(), Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 072/104] virtiofsd: passthrough_ll: fix refcounting on remove/rename, Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 071/104] virtiofsd: extract root inode init into setup_root(), Dr. David Alan Gilbert (git), 2019/12/12
- [PATCH 073/104] virtiofsd: passthrough_ll: clean up cache related options, Dr. David Alan Gilbert (git), 2019/12/12