diff options
author | Frederic Robra | 2019-07-14 20:04:45 +0200 |
---|---|---|
committer | Frederic Robra | 2019-07-14 20:04:45 +0200 |
commit | 23e585f4af267808c2ed0c69430207d7d7716a5b (patch) | |
tree | e89fb196ce9fd45e256acf5477d436dbc090cbb1 /src/kernel/core.c | |
parent | splitted receiver (diff) | |
download | dnbd3-ng-23e585f4af267808c2ed0c69430207d7d7716a5b.tar.gz dnbd3-ng-23e585f4af267808c2ed0c69430207d7d7716a5b.tar.xz dnbd3-ng-23e585f4af267808c2ed0c69430207d7d7716a5b.zip |
device now errors if connection get closed
Diffstat (limited to 'src/kernel/core.c')
-rw-r--r-- | src/kernel/core.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/kernel/core.c b/src/kernel/core.c index 8f02900..4704b0d 100644 --- a/src/kernel/core.c +++ b/src/kernel/core.c @@ -77,8 +77,10 @@ static int dnbd3_handle_cmd(struct dnbd3_cmd *cmd, int index) { struct request *req = blk_mq_rq_from_pdu(cmd); struct dnbd3_device *dev = cmd->dnbd3; - struct dnbd3_sock *sock; + struct dnbd3_sock *sock = NULL; int ret = -1; + int i; + int sock_alive = 0; printk(KERN_DEBUG "dnbd3: handle request at position %lu and size %d, device %i\n", blk_rq_pos(req), blk_rq_bytes(req), dev->minor); @@ -89,11 +91,24 @@ static int dnbd3_handle_cmd(struct dnbd3_cmd *cmd, int index) // return -EINVAL; // } - sock = &dev->socks[index]; - if (!sock->sock) { + for (i = 0; i < NUMBER_CONNECTIONS; i++) { + if (dev->socks[i].sock && dev->socks[i].server) { + if (index == sock_alive) { + sock = &dev->socks[index]; + } + sock_alive++; + } + } + + if (!sock) { printk(KERN_INFO "dnbd3: index is %d but no socket was found\n", index); dev_err_ratelimited(disk_to_dev(dev->disk), "attempted send on invalid socket\n"); - blk_mq_start_request(req); + if (sock_alive > 0) { + blk_mq_update_nr_hw_queues(&dev->tag_set, sock_alive); + blk_mq_start_request(req); + return -EINVAL; + } + blk_mq_end_request(req, BLK_STS_IOERR); return -EINVAL; } @@ -188,6 +203,7 @@ static enum blk_eh_timer_return dnbd3_xmit_timeout(struct request *req, bool res dev_err_ratelimited(disk_to_dev(dev->disk), "connection timed out\n"); cmd->status = BLK_STS_IOERR; blk_mq_complete_request(req); + blk_mq_end_request(req, BLK_STS_TIMEOUT); return BLK_EH_DONE; } @@ -292,6 +308,8 @@ static int dnbd3_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd kfree(dev->imgname); dev->imgname = NULL; } + dev->rid = 0; + dev->reported_size = 0; break; case IOCTL_SWITCH: @@ -506,6 +524,10 @@ static void dnbd3_dev_remove(struct dnbd3_device *dnbd3) dnbd3_net_disconnect(dnbd3); disk->private_data = NULL; put_disk(disk); + if (dnbd3->imgname) { + kfree(dnbd3->imgname); + dnbd3->imgname = NULL; + } } mutex_destroy(&dnbd3->device_lock); } |