summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFrederic Robra2019-11-14 15:18:32 +0100
committerFrederic Robra2019-11-14 15:18:32 +0100
commitfff87d1c3e19c0a24a3b0d4cff3e9a8f6f140e34 (patch)
tree54de680b694fb5a8b7ea02821f95d1fe8e530127 /src
parentbug when sending and release at the same time (diff)
downloaddnbd3-ng-fff87d1c3e19c0a24a3b0d4cff3e9a8f6f140e34.tar.gz
dnbd3-ng-fff87d1c3e19c0a24a3b0d4cff3e9a8f6f140e34.tar.xz
dnbd3-ng-fff87d1c3e19c0a24a3b0d4cff3e9a8f6f140e34.zip
added check for rid and discovery now takes bigger test block
Diffstat (limited to 'src')
-rw-r--r--src/clientconfig.h2
-rw-r--r--src/kernel/core.c15
-rw-r--r--src/kernel/net-txrx.c84
-rw-r--r--src/kernel/net.c53
4 files changed, 84 insertions, 70 deletions
diff --git a/src/clientconfig.h b/src/clientconfig.h
index ab1cff8..77252a4 100644
--- a/src/clientconfig.h
+++ b/src/clientconfig.h
@@ -14,6 +14,8 @@
#define RTT_UNKNOWN (RTT_UNREACHABLE / 2)
// This must be a power of two:
#define RTT_BLOCK_SIZE 4096
+// Size of the RTT test block 256k
+#define RTT_TEST_BLOCK_SIZE 262144
#define STARTUP_MODE_DURATION 30
// Interval of several repeating tasks (in seconds)
diff --git a/src/kernel/core.c b/src/kernel/core.c
index 7e05505..ef41158 100644
--- a/src/kernel/core.c
+++ b/src/kernel/core.c
@@ -277,12 +277,21 @@ int dnbd3_add_device(struct dnbd3_device *dev, int minor)
dev->tag_set.ops = &dnbd3_mq_ops;
/* this can be changed later with blk_mq_update_nr_hw_queues() */
dev->tag_set.nr_hw_queues = 1;
- dev->tag_set.timeout = 5 * HZ;
+ dev->tag_set.timeout = 10 * HZ;
dev->tag_set.queue_depth = 128;
dev->tag_set.numa_node = NUMA_NO_NODE;
dev->tag_set.cmd_size = sizeof(struct dnbd3_cmd);
- dev->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_SG_MERGE |
- BLK_MQ_F_BLOCKING;
+ /*
+ * nbd has this flags set (ther is no documentation)
+ * BLK_MQ_F_SHOULD_MERGE: Reverse check our software queue for entries
+ * that we could potentially merge with
+ * BLK_MQ_F_SG_MERGE: If SG merging is disabled, each bio vector is
+ * a segment.
+ * BLK_MQ_F_BLOCKING: Wait for rcu if blocking, else wait for rcu in
+ * each queue.
+ */
+ dev->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_SG_MERGE;
+// | BLK_MQ_F_BLOCKING;
dev->tag_set.driver_data = dev;
err = blk_mq_alloc_tag_set(&dev->tag_set);
diff --git a/src/kernel/net-txrx.c b/src/kernel/net-txrx.c
index 3a9b057..82f7408 100644
--- a/src/kernel/net-txrx.c
+++ b/src/kernel/net-txrx.c
@@ -45,7 +45,7 @@
#define dnbd3_test_block_to_req(req) \
do { \
(req)->cmd_flags = REQ_OP_READ; \
- (req)->__data_len = RTT_BLOCK_SIZE; \
+ (req)->__data_len = RTT_TEST_BLOCK_SIZE; \
(req)->__sector = 0; \
} while (0)
@@ -270,38 +270,38 @@ int dnbd3_receive_cmd(struct dnbd3_sock *sock, dnbd3_reply_t *reply)
return result;
}
-static int dnbd3_clear_socket(struct dnbd3_sock *sock, dnbd3_reply_t *reply,
- int remaining)
-{
- int result = 0;
- char *buf;
- struct kvec iov;
- struct msghdr msg;
- dnbd3_init_msghdr(msg);
- warn_sock(sock, "clearing socket %d bytes", remaining);
- buf = kmalloc(RTT_BLOCK_SIZE, GFP_KERNEL);
- if (!buf) {
- error_sock(sock, "kmalloc failed");
- return -EIO;
- }
- iov.iov_base = buf;
- iov.iov_len = RTT_BLOCK_SIZE;
- while (remaining > 0) {
- result = kernel_recvmsg(sock->sock, &msg, &iov, 1, iov.iov_len,
- msg.msg_flags);
- if (result <= 0) {
- goto error;
- }
- remaining -= result;
- }
-
- debug_sock(sock, "cleared socket");
-error:
- if (buf) {
- kfree(buf);
- }
- return result;
-}
+//static int dnbd3_clear_socket(struct dnbd3_sock *sock, dnbd3_reply_t *reply,
+// int remaining)
+//{
+// int result = 0;
+// char *buf;
+// struct kvec iov;
+// struct msghdr msg;
+// dnbd3_init_msghdr(msg);
+// warn_sock(sock, "clearing socket %d bytes", remaining);
+// buf = kmalloc(RTT_BLOCK_SIZE, GFP_KERNEL);
+// if (!buf) {
+// error_sock(sock, "kmalloc failed");
+// return -EIO;
+// }
+// iov.iov_base = buf;
+// iov.iov_len = RTT_BLOCK_SIZE;
+// while (remaining > 0) {
+// result = kernel_recvmsg(sock->sock, &msg, &iov, 1, iov.iov_len,
+// msg.msg_flags);
+// if (result <= 0) {
+// goto error;
+// }
+// remaining -= result;
+// }
+//
+// debug_sock(sock, "cleared socket");
+//error:
+// if (buf) {
+// kfree(buf);
+// }
+// return result;
+//}
/**
* dnbd3_receive_cmd_get_block_mq - receive a block for mq
@@ -351,7 +351,7 @@ int dnbd3_receive_cmd_get_block_mq(struct dnbd3_sock *sock,
dnbd3_requeue_cmd(cmd);
mutex_unlock(&cmd->lock);
}
- dnbd3_clear_socket(sock, reply, remaining);
+// dnbd3_clear_socket(sock, reply, remaining);
return -EIO;
}
cmd = blk_mq_rq_to_pdu(req);
@@ -361,7 +361,7 @@ int dnbd3_receive_cmd_get_block_mq(struct dnbd3_sock *sock,
error_sock(sock, "double reply on req %p, cookie %u, handle cookie %u",
req, cmd->cookie, cookie);
mutex_unlock(&cmd->lock);
- dnbd3_clear_socket(sock, reply, remaining);
+// dnbd3_clear_socket(sock, reply, remaining);
return -EIO;
}
@@ -382,7 +382,7 @@ int dnbd3_receive_cmd_get_block_mq(struct dnbd3_sock *sock,
dnbd3_requeue_cmd(cmd);
mutex_unlock(&cmd->lock);
if (result >= 0) {
- dnbd3_clear_socket(sock, reply, remaining);
+// dnbd3_clear_socket(sock, reply, remaining);
return -EIO;
} else {
return result;
@@ -425,7 +425,7 @@ int dnbd3_receive_cmd_get_block_test(struct dnbd3_sock *sock,
iov.iov_len = reply->size;
result = kernel_recvmsg(sock->sock, &msg, &iov, 1, reply->size,
msg.msg_flags);
- if (result != RTT_BLOCK_SIZE) {
+ if (result != RTT_TEST_BLOCK_SIZE) {
error_sock(sock, "receive test block failed");
goto error;
}
@@ -589,18 +589,20 @@ int dnbd3_receive_cmd_select_image(struct dnbd3_sock *sock,
return -EIO;
}
- //TODO compare RID
-
name = serializer_get_string(&payload_buffer);
rid = serializer_get_uint16(&payload_buffer);
- if (dev->rid != rid && strcmp(name, dev->imgname) != 0) {
+ if (dev->rid == 0) {
+ dev->rid = rid;
+ }
+
+ if (dev->rid != rid || strcmp(name, dev->imgname) != 0) {
error_sock(sock, "server offers image '%s', requested '%s'",
name, dev->imgname);
return -EIO;
}
reported_size = serializer_get_uint64(&payload_buffer);
- if (!dev->reported_size) {
+ if (dev->reported_size == 0) {
if (reported_size < 4096) {
error_sock(sock, "reported size by server is < 4096");
return -EIO;
diff --git a/src/kernel/net.c b/src/kernel/net.c
index 838aafb..e8c7cad 100644
--- a/src/kernel/net.c
+++ b/src/kernel/net.c
@@ -237,30 +237,31 @@ static struct dnbd3_server **dnbd3_sort_server(struct dnbd3_device *dev) {
return sorted_servers;
}
-/**
- * dnbd3_compare_servers - comparator for the connecion plan
- * @lhs: left hand sign
- * @rhs: right hand sign
- */
-static int dnbd3_compare_plan(const void *lhs, const void *rhs)
-{
- uint64_t l, r;
- struct dnbd3_server *lhs_server = *((struct dnbd3_server **) lhs);
- struct dnbd3_server *rhs_server = *((struct dnbd3_server **) rhs);
- uint8_t *l_addr = lhs_server->host.addr;
- uint8_t *r_addr = rhs_server->host.addr;
- l = l_addr[0] + l_addr[1] + l_addr[2] + l_addr[3] + l_addr[4] +
- l_addr[5] + l_addr[6] + l_addr[7] + l_addr[8] +
- l_addr[9] + l_addr[10] + l_addr[11] + l_addr[12] +
- l_addr[13] + l_addr[14] + l_addr[15] +
- lhs_server->host.port;
- r = r_addr[0] + r_addr[1] + r_addr[2] + r_addr[3] + r_addr[4] +
- r_addr[5] + r_addr[6] + r_addr[7] + r_addr[8] +
- r_addr[9] + r_addr[10] + r_addr[11] + r_addr[12] +
- r_addr[13] + r_addr[14] + r_addr[15] +
- rhs_server->host.port;
- return l - r;
-}
+// Not used right now, plan is sorted by the rating
+///**
+// * dnbd3_compare_servers - comparator for the connecion plan
+// * @lhs: left hand sign
+// * @rhs: right hand sign
+// */
+//static int dnbd3_compare_plan(const void *lhs, const void *rhs)
+//{
+// uint64_t l, r;
+// struct dnbd3_server *lhs_server = *((struct dnbd3_server **) lhs);
+// struct dnbd3_server *rhs_server = *((struct dnbd3_server **) rhs);
+// uint8_t *l_addr = lhs_server->host.addr;
+// uint8_t *r_addr = rhs_server->host.addr;
+// l = l_addr[0] + l_addr[1] + l_addr[2] + l_addr[3] + l_addr[4] +
+// l_addr[5] + l_addr[6] + l_addr[7] + l_addr[8] +
+// l_addr[9] + l_addr[10] + l_addr[11] + l_addr[12] +
+// l_addr[13] + l_addr[14] + l_addr[15] +
+// lhs_server->host.port;
+// r = r_addr[0] + r_addr[1] + r_addr[2] + r_addr[3] + r_addr[4] +
+// r_addr[5] + r_addr[6] + r_addr[7] + r_addr[8] +
+// r_addr[9] + r_addr[10] + r_addr[11] + r_addr[12] +
+// r_addr[13] + r_addr[14] + r_addr[15] +
+// rhs_server->host.port;
+// return l - r;
+//}
/**
@@ -305,7 +306,7 @@ static int dnbd3_adjust_connections(struct dnbd3_device *dev) {
kfree(servers);
sort(plan, dev->number_connections, sizeof(struct dnbd3_server *),
- &dnbd3_compare_plan, NULL);
+ &dnbd3_compare_servers, NULL);
/* lock all mutex at once, so nothing can be send */
debug_dev(dev, "connection plan:");
@@ -450,7 +451,7 @@ static int dnbd3_meassure_rtt(struct dnbd3_device *dev,
}
result = dnbd3_receive_cmd(&sock, &reply);
if (reply.magic != dnbd3_packet_magic|| reply.cmd != CMD_GET_BLOCK
- || reply.size != RTT_BLOCK_SIZE) {
+ || reply.size != RTT_TEST_BLOCK_SIZE) {
error_sock(&sock, "receive header cmd test block failed in rtt measurement");
result = -EIO;
goto error;