diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/client.c | 7 | ||||
-rw-r--r-- | src/kernel/dnbd3.h | 6 | ||||
-rw-r--r-- | src/kernel/net.c | 16 | ||||
-rw-r--r-- | src/kernel/sysfs.c | 20 | ||||
-rw-r--r-- | src/kernel/utils.c | 13 | ||||
-rw-r--r-- | src/kernel/utils.h | 4 |
6 files changed, 41 insertions, 25 deletions
diff --git a/src/client/client.c b/src/client/client.c index 37f0558..40542ba 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -43,13 +43,14 @@ static int openDevices[MAX_DEVS]; -static const char *optString = "f:h:i:r:d:a:cs:HV?k"; +static const char *optString = "f:h:i:r:d:n:a:cs:HV?k"; static const struct option longOpts[] = { { "file", required_argument, NULL, 'f' }, { "host", required_argument, NULL, 'h' }, { "image", required_argument, NULL, 'i' }, { "rid", required_argument, NULL, 'r' }, { "device", required_argument, NULL, 'd' }, + { "connections", required_argument, NULL, 'n'}, { "ahead", required_argument, NULL, 'a' }, { "close", no_argument, NULL, 'c' }, { "switch", required_argument, NULL, 's' }, @@ -231,6 +232,9 @@ int main(int argc, char *argv[]) dev = strdup( optarg ); printf( "Device is %s\n", dev ); break; + case 'n': + msg.number_connections = (uint8_t) atoi( optarg ); + break; case 'a': msg.read_ahead_kb = atoi( optarg ); break; @@ -652,6 +656,7 @@ static void dnbd3_print_help(char *argv_0) printf( "-i or --image \t\t Image name of exported image.\n" ); printf( "-r or --rid \t\t Release-ID of exported image (default 0, latest).\n" ); printf( "-d or --device \t\t DNBD3 device name.\n" ); + printf( "-n or --connections \t The number of parallel connections\n"); printf( "-a or --ahead \t\t Read ahead in KByte (default %i).\n", DEFAULT_READ_AHEAD_KB ); printf( "-c or --close \t\t Disconnect and close device.\n" ); printf( "-s or --switch \t\t Switch dnbd3-server on device (DEBUG).\n" ); diff --git a/src/kernel/dnbd3.h b/src/kernel/dnbd3.h index e8eab9b..848acdd 100644 --- a/src/kernel/dnbd3.h +++ b/src/kernel/dnbd3.h @@ -64,7 +64,7 @@ extern struct workqueue_struct *dnbd3_wq; struct dnbd3_server { dnbd3_host_t host; uint64_t rtts[4]; - uint64_t avg_rtt; + uint64_t rating; uint16_t protocol_version; uint16_t failures; }; @@ -182,14 +182,14 @@ struct dnbd3_cmd { #define dnbd3_set_rtt_unreachable(server) \ (server)->rtts[0] = (server)->rtts[1] = (server)->rtts[2] \ - = (server)->rtts[3] = (server)->avg_rtt = \ + = (server)->rtts[3] = (server)->rating = \ RTT_UNREACHABLE; #define dnbd3_set_rtt_unknown(server) \ (server)->rtts[0] = (server)->rtts[1] = (server)->rtts[2] \ = (server)->rtts[3] = 0;\ - (server)->avg_rtt = RTT_UNKNOWN; + (server)->rating = RTT_UNKNOWN; /** diff --git a/src/kernel/net.c b/src/kernel/net.c index 8f71b5a..0cedb4c 100644 --- a/src/kernel/net.c +++ b/src/kernel/net.c @@ -204,9 +204,9 @@ static int dnbd3_compare_servers(const void *lhs, const void *rhs) { struct dnbd3_server *lhs_server = *((struct dnbd3_server **) lhs); struct dnbd3_server *rhs_server = *((struct dnbd3_server **) rhs); - l = lhs_server->host.type != 0 ? lhs_server->avg_rtt + l = lhs_server->host.type != 0 ? lhs_server->rating : RTT_UNREACHABLE * 2; - r = rhs_server->host.type != 0 ? rhs_server->avg_rtt + r = rhs_server->host.type != 0 ? rhs_server->rating : RTT_UNREACHABLE * 2; return l - r; } @@ -317,9 +317,9 @@ static int dnbd3_adjust_connections(struct dnbd3_device *dev) { j = 1; for (i = 1; i < dev->number_connections; i++) { if (servers[j]->host.type != 0 && - servers[j]->avg_rtt < RTT_UNKNOWN) { - if (RTT_FACTOR(plan[i - 1]->avg_rtt) > - servers[j]->avg_rtt) { + servers[j]->rating < RTT_UNKNOWN) { + if (RTT_FACTOR(plan[i - 1]->rating) > + servers[j]->rating) { plan[i] = servers[j]; j++; } else { @@ -341,7 +341,7 @@ static int dnbd3_adjust_connections(struct dnbd3_device *dev) { for (i = 0; i < dev->number_connections; i++) { debug_server(dev, plan[i], "server %d with avg rtt %llu:", - i, plan[i]->avg_rtt); + i, plan[i]->rating); mutex_lock(&dev->socks[i].tx_lock); } @@ -497,10 +497,10 @@ static int dnbd3_meassure_rtt(struct dnbd3_device *dev, error: sock.server->rtts[dev->discovery_count % 4] = rtt; - sock.server->avg_rtt = dnbd3_average_rtt(sock.server); + sock.server->rating = dnbd3_rating(sock.server); debug_sock(&sock, "meassured rrt: %llu; avg_rtt: %llu", rtt, - sock.server->avg_rtt); + sock.server->rating); if (result <= 0) { server->failures++; } diff --git a/src/kernel/sysfs.c b/src/kernel/sysfs.c index a780a21..4d5a87d 100644 --- a/src/kernel/sysfs.c +++ b/src/kernel/sysfs.c @@ -35,18 +35,20 @@ ssize_t show_connected_servers(char *buf, struct dnbd3_device *dev) for (i = 0; i < dev->number_connections; ++i) { if (dev->socks[i].sock) { if (dev->socks[i].server->host.type == HOST_IP4) { - ret = MIN(snprintf(buf, size, "%pI4,%d,%llu,%d\n", + ret = MIN(snprintf(buf, size, "%pI4,%d,%llu,%llu,%d\n", dev->socks[i].server->host.addr, (int)ntohs(dev->socks[i].server->host.port), - dev->socks[i].server->avg_rtt, + dndb3_average_rtt(dev->socks[i].server), + dev->socks[i].server->rating, (int)dev->socks[i].server->failures) , size); } else { - ret = MIN(snprintf(buf, size, "%pI6,%d,%llu,%d\n", + ret = MIN(snprintf(buf, size, "%pI6,%d,%llu,%llu,%d\n", dev->socks[i].server->host.addr, (int)ntohs(dev->socks[i].server->host.port), - dev->socks[i].server->avg_rtt, + dndb3_average_rtt(dev->socks[i].server), + dev->socks[i].server->rating, (int)dev->socks[i].server->failures) , size); @@ -84,17 +86,19 @@ ssize_t show_alt_servers(char *buf, struct dnbd3_device *dev) int i, size = PAGE_SIZE, ret; for (i = 0; i < NUMBER_SERVERS; ++i) { if (dev->alt_servers[i].host.type == HOST_IP4) { - ret = MIN(snprintf(buf, size, "%pI4,%d,%llu,%d\n", + ret = MIN(snprintf(buf, size, "%pI4,%d,%llu,%llu,%d\n", dev->alt_servers[i].host.addr, (int)ntohs(dev->alt_servers[i].host.port), - dev->alt_servers[i].avg_rtt, + dndb3_average_rtt(&dev->alt_servers[i]), + dev->alt_servers[i].rating, (int)dev->alt_servers[i].failures) , size); } else if (dev->alt_servers[i].host.type == HOST_IP6) { - ret = MIN(snprintf(buf, size, "%pI6,%d,%llu,%d\n", + ret = MIN(snprintf(buf, size, "%pI6,%d,,%llu%llu,%d\n", dev->alt_servers[i].host.addr, (int)ntohs(dev->alt_servers[i].host.port), - dev->alt_servers[i].avg_rtt, + dndb3_average_rtt(&dev->alt_servers[i]), + dev->alt_servers[i].rating, (int)dev->alt_servers[i].failures) , size); } else { diff --git a/src/kernel/utils.c b/src/kernel/utils.c index 164d51a..f6a01d4 100644 --- a/src/kernel/utils.c +++ b/src/kernel/utils.c @@ -43,7 +43,7 @@ void inet_ntoa(struct in_addr addr, char *str) sprintf(str, "%d.%d.%d.%d", ptr[0] & 0xff, ptr[1] & 0xff, ptr[2] & 0xff, ptr[3] & 0xff); } -uint64_t dnbd3_average_rtt(struct dnbd3_server *server) +uint64_t dndb3_average_rtt(struct dnbd3_server *server) { int i, j = 0; uint64_t avg = 0; @@ -54,8 +54,13 @@ uint64_t dnbd3_average_rtt(struct dnbd3_server *server) if (avg == 0) { return RTT_UNKNOWN; } else { - avg = avg / j; - avg += server->failures * avg / 10; - return avg; + return avg / j; } } + +uint64_t dnbd3_rating(struct dnbd3_server *server) +{ + uint64_t avg = dndb3_average_rtt(server); + avg += server->failures * avg / 10; + return avg; +} diff --git a/src/kernel/utils.h b/src/kernel/utils.h index d7eb87f..052e69f 100644 --- a/src/kernel/utils.h +++ b/src/kernel/utils.h @@ -34,6 +34,8 @@ void inet_ntoa(struct in_addr addr, char *str); * dnbd3_average_rtt - calculate the average rtt * @server: the server to calculate the average rtt */ -uint64_t dnbd3_average_rtt(struct dnbd3_server *server); +uint64_t dndb3_average_rtt(struct dnbd3_server *server); + +uint64_t dnbd3_rating(struct dnbd3_server *server); #endif /* UTILS_H_ */ |