diff --git a/lib/nvme/nvme_cuse.c b/lib/nvme/nvme_cuse.c index 5c808202f2..4d55072740 100644 --- a/lib/nvme/nvme_cuse.c +++ b/lib/nvme/nvme_cuse.c @@ -623,6 +623,10 @@ cuse_thread(void *arg) const char *dev_info_argv[] = { devname_arg }; struct cuse_info ci; int multithreaded; + int rc; + struct fuse_buf buf = { .mem = NULL }; + struct pollfd fds; + int timeout_msecs = 500; spdk_unaffinitize_thread(); @@ -646,7 +650,22 @@ cuse_thread(void *arg) } SPDK_NOTICELOG("fuse session for device %s created\n", cuse_device->dev_name); - fuse_session_loop(cuse_device->session); + + /* Receive and process fuse requests */ + fds.fd = fuse_session_fd(cuse_device->session); + fds.events = POLLIN; + while (!fuse_session_exited(cuse_device->session)) { + rc = poll(&fds, 1, timeout_msecs); + if (rc <= 0) { + continue; + } + rc = fuse_session_receive_buf(cuse_device->session, &buf); + if (rc > 0) { + fuse_session_process_buf(cuse_device->session, &buf); + } + } + free(buf.mem); + fuse_session_reset(cuse_device->session); end: cuse_lowlevel_teardown(cuse_device->session); @@ -691,14 +710,12 @@ cuse_nvme_ctrlr_stop(struct cuse_device *ctrlr_device) TAILQ_FOREACH_SAFE(ns_device, &ctrlr_device->ns_devices, tailq, tmp) { fuse_session_exit(ns_device->session); - pthread_kill(ns_device->tid, SIGHUP); pthread_join(ns_device->tid, NULL); TAILQ_REMOVE(&ctrlr_device->ns_devices, ns_device, tailq); free(ns_device); } fuse_session_exit(ctrlr_device->session); - pthread_kill(ctrlr_device->tid, SIGHUP); pthread_join(ctrlr_device->tid, NULL); TAILQ_REMOVE(&g_ctrlr_ctx_head, ctrlr_device, tailq); free(ctrlr_device); diff --git a/test/nvme/spdk_nvme_cli_cuse.sh b/test/nvme/spdk_nvme_cli_cuse.sh index f75d5076ec..5a6ba5d098 100755 --- a/test/nvme/spdk_nvme_cli_cuse.sh +++ b/test/nvme/spdk_nvme_cli_cuse.sh @@ -23,6 +23,10 @@ $rpc_py bdev_nvme_cuse_register -n Nvme0 -p spdk/nvme0 sleep 5 +if [ ! -c /dev/spdk/nvme0 ]; then + return 1 +fi + $rpc_py bdev_get_bdevs $rpc_py bdev_nvme_get_controllers @@ -43,6 +47,31 @@ for ctrlr in $(ls /dev/spdk/nvme?); do ${NVME_CMD} reset $ctrlr done +if [ ! -c /dev/spdk/nvme0 ]; then + return 1 +fi + +$rpc_py bdev_nvme_cuse_unregister -n Nvme0 +sleep 1 +if [ -c /dev/spdk/nvme0 ]; then + return 1 +fi + +$rpc_py bdev_nvme_cuse_register -n Nvme0 -p spdk/nvme1 +sleep 1 + +if [ ! -c /dev/spdk/nvme1 ]; then + return 1 +fi + +$rpc_py bdev_nvme_cuse_unregister -n Nvme0 +sleep 1 +if [ -c /dev/spdk/nvme1 ]; then + return 1 +fi + +$rpc_py bdev_nvme_detach_controller Nvme0 + trap - SIGINT SIGTERM EXIT kill $spdk_tgt_pid