@@ -1345,6 +1345,17 @@ static void nbd_clear_sock_ioctl(struct nbd_device *nbd,
sock_shutdown(nbd);
__invalidate_device(bdev, true);
nbd_bdev_reset(bdev);
+
+ /*
+ * When calling the ioctl(), fget() will be called on this
+ * fd, and nbd_release() is only called when the fd's refcount
+ * drops to zero. With this we can make sure that the
+ * nbd_release() won't be called before the ioctl() finished.
+ *
+ * So there won't have the double lock issue if it will
+ * call the nbd_config_put() here for the "config_lock", which
+ * has already been held by nbd_ioctl().
+ */
if (test_and_clear_bit(NBD_RT_HAS_CONFIG_REF,
&nbd->config->runtime_flags))
nbd_config_put(nbd);