summaryrefslogtreecommitdiffstats
path: root/src/kernel
diff options
context:
space:
mode:
authorFrederic Robra2019-11-06 20:23:47 +0100
committerFrederic Robra2019-11-06 20:23:47 +0100
commitec6c0ce8b1af8d9c36f4ec87cd384365cb2d9012 (patch)
treefd62ba871ee3383a6f139207977f92b103bb198e /src/kernel
parentadded comments (diff)
downloaddnbd3-ng-ec6c0ce8b1af8d9c36f4ec87cd384365cb2d9012.tar.gz
dnbd3-ng-ec6c0ce8b1af8d9c36f4ec87cd384365cb2d9012.tar.xz
dnbd3-ng-ec6c0ce8b1af8d9c36f4ec87cd384365cb2d9012.zip
removed bug when sending and at the same time socket closes down
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/core.c5
-rw-r--r--src/kernel/dnbd3.h1
-rw-r--r--src/kernel/mq.c2
-rw-r--r--src/kernel/net-txrx.c2
-rw-r--r--src/kernel/net.c9
5 files changed, 10 insertions, 9 deletions
diff --git a/src/kernel/core.c b/src/kernel/core.c
index 874980b..4ef7221 100644
--- a/src/kernel/core.c
+++ b/src/kernel/core.c
@@ -272,7 +272,6 @@ int dnbd3_add_device(struct dnbd3_device *dev, int minor)
if (err < 0) {
goto out_free_disk;
}
-
dev->minor = minor;
dev->disk = disk;
dev->tag_set.ops = &dnbd3_mq_ops;
@@ -286,9 +285,9 @@ int dnbd3_add_device(struct dnbd3_device *dev, int minor)
dev->tag_set.driver_data = dev;
err = blk_mq_alloc_tag_set(&dev->tag_set);
- if (err)
+ if (err) {
goto out_free_idr;
-
+ }
q = blk_mq_init_queue(&dev->tag_set);
if (IS_ERR(q)) {
err = PTR_ERR(q);
diff --git a/src/kernel/dnbd3.h b/src/kernel/dnbd3.h
index 437edec..f8d4bae 100644
--- a/src/kernel/dnbd3.h
+++ b/src/kernel/dnbd3.h
@@ -163,6 +163,7 @@ struct dnbd3_device {
* @dnbd3: the dnbd3 device this command belongs to
* @lock: mutex to lock the cmd
* @cookie: the cookie of the command, this is set by the socket when sending
+ * @index: the queue_num of the requests this command belongs to
* @requed: 'true' if the command is requed
*/
struct dnbd3_cmd {
diff --git a/src/kernel/mq.c b/src/kernel/mq.c
index 34a8a5b..5b480de 100644
--- a/src/kernel/mq.c
+++ b/src/kernel/mq.c
@@ -109,7 +109,7 @@ void dndb3_reque_busy_requests(struct dnbd3_sock *sock)
void dnbd3_requeue_cmd(struct dnbd3_cmd *cmd)
{
struct request *req = blk_mq_rq_from_pdu(cmd);
- if (!cmd->requed) {
+ if (!cmd->requed && blk_queued_rq(req)) {
cmd->requed = true;
blk_mq_requeue_request(req, true);
}
diff --git a/src/kernel/net-txrx.c b/src/kernel/net-txrx.c
index a0d75bb..4ca3fa5 100644
--- a/src/kernel/net-txrx.c
+++ b/src/kernel/net-txrx.c
@@ -122,7 +122,7 @@ int dnbd3_send_request(struct dnbd3_sock *sock, struct request *req,
switch (req_op(req)) {
case REQ_OP_READ:
- debug_sock(sock, "request operation read %p", req);
+// debug_sock(sock, "request operation read %p", req);
request.cmd = CMD_GET_BLOCK;
request.offset = blk_rq_pos(req) << 9; // * 512
request.size = blk_rq_bytes(req);
diff --git a/src/kernel/net.c b/src/kernel/net.c
index a837702..801c15c 100644
--- a/src/kernel/net.c
+++ b/src/kernel/net.c
@@ -81,10 +81,9 @@ static void dnbd3_timer(struct timer_list *arg)
}
/* start after 2 seconds */
- if (dev->timer_count % TIMER_INTERVAL_PROBE_NORMAL == 2) {
+ if (!busy && dev->timer_count % TIMER_INTERVAL_PROBE_NORMAL == 2) {
queue_work(dnbd3_wq, &dev->discovery_worker);
}
-
dev->timer_count++;
dev->timer.expires = jiffies + HZ;
add_timer(&dev->timer);
@@ -108,11 +107,9 @@ static void dnbd3_receive_worker(struct work_struct *work)
result = dnbd3_receive_cmd(sock, &reply);
if (result == -EAGAIN) {
continue;
-
} else if (result <= 0) {
error_sock(sock, "connection to server lost %d", result);
goto error;
-
}
switch (reply.cmd) {
@@ -162,6 +159,10 @@ static void dnbd3_receive_worker(struct work_struct *work)
error:
if (result == 0) {
info_sock(sock, "result is 0, socket seems to be down");
+ /* be sure nobody is sending on the socket */
+ while (unlikely(sock->pending)) {
+ msleep(50);
+ }
dnbd3_sock_release(sock);
break;
} else if (result < 0) {