diff options
author | Frederic Robra | 2019-09-04 15:24:44 +0200 |
---|---|---|
committer | Frederic Robra | 2019-09-04 15:24:44 +0200 |
commit | 220e8d7720138f9de10072ba4d9596afa138235b (patch) | |
tree | 1f7ebeabaf8a20499e46b6af0f549968fecf5577 /src | |
parent | prepared kernel module to have configurable number of connections (diff) | |
download | dnbd3-ng-220e8d7720138f9de10072ba4d9596afa138235b.tar.gz dnbd3-ng-220e8d7720138f9de10072ba4d9596afa138235b.tar.xz dnbd3-ng-220e8d7720138f9de10072ba4d9596afa138235b.zip |
removed initial server and removed replacement of alt servers
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/core.c | 11 | ||||
-rw-r--r-- | src/kernel/dnbd3.h | 3 | ||||
-rw-r--r-- | src/kernel/net.c | 58 | ||||
-rw-r--r-- | src/kernel/sysfs.c | 18 |
4 files changed, 22 insertions, 68 deletions
diff --git a/src/kernel/core.c b/src/kernel/core.c index 2f7ddcb..6e9ce2b 100644 --- a/src/kernel/core.c +++ b/src/kernel/core.c @@ -132,13 +132,9 @@ static int dnbd3_ioctl(struct block_device *bdev, fmode_t mode, result = -EINVAL; } else { mutex_lock(&dev->device_lock); - if (sizeof(msg->host) != sizeof(dev->initial_server.host)) { + if (sizeof(msg->host) != sizeof(dnbd3_host_t)) { warn_dev(dev, "odd size bug#1 triggered in ioctl"); } - memcpy(&dev->initial_server.host, &msg->host, - sizeof(msg->host)); - dev->initial_server.failures = 0; - dnbd3_set_rtt_unknown(&dev->initial_server) dev->imgname = imgname; dev->rid = msg->rid; dev->use_server_provided_alts = @@ -149,8 +145,9 @@ static int dnbd3_ioctl(struct block_device *bdev, fmode_t mode, */ memset(dev->alt_servers, 0, sizeof(dev->alt_servers[0]) * NUMBER_SERVERS); - memcpy(dev->alt_servers, &dev->initial_server, - sizeof(dev->alt_servers[0])); + + memcpy(&dev->alt_servers[0].host, &msg->host, + sizeof(msg->host)); if (old_msg || msg->number_connections == 0) { dev->number_connections = 4; diff --git a/src/kernel/dnbd3.h b/src/kernel/dnbd3.h index 6d8ceb2..e8eab9b 100644 --- a/src/kernel/dnbd3.h +++ b/src/kernel/dnbd3.h @@ -144,8 +144,7 @@ struct dnbd3_device { uint8_t number_connections; struct dnbd3_sock *socks; char *imgname; - struct dnbd3_server initial_server; - struct dnbd3_server alt_servers[NUMBER_SERVERS];//TODO just add server to list do not remove + struct dnbd3_server alt_servers[NUMBER_SERVERS]; int new_servers_num; dnbd3_server_entry_t new_servers[NUMBER_SERVERS]; bool update_available; diff --git a/src/kernel/net.c b/src/kernel/net.c index 061deb1..8f71b5a 100644 --- a/src/kernel/net.c +++ b/src/kernel/net.c @@ -291,32 +291,6 @@ static int dnbd3_compare_plan(const void *lhs, const void *rhs) return l - r; } -static void dnbd3_lock_all_socks(struct dnbd3_device *dev) -{ - int i; - for (i = 0; i < dev->number_connections; i++) { - mutex_lock(&dev->socks[i].tx_lock); - } -} - -static void dnbd3_unlock_all_socks(struct dnbd3_device *dev) -{ - int i; - for (i = 0; i < dev->number_connections; i++) { - mutex_unlock(&dev->socks[i].tx_lock); - } -} - -static void dnbd3_print_conenction_plan(struct dnbd3_device *dev, - struct dnbd3_server **plan) -{ - int i; - debug_dev(dev, "connection plan:"); - for (i = 0; i < dev->number_connections; i++) { - debug_server(dev, plan[i], "server %d with avg rtt %llu:", - i, plan[i]->avg_rtt); - } -} /** * dnbd3_adjust_connections - create a connection plan and connect @@ -361,9 +335,17 @@ static int dnbd3_adjust_connections(struct dnbd3_device *dev) { sort(plan, dev->number_connections, sizeof(struct dnbd3_server *), &dnbd3_compare_plan, NULL); - dnbd3_print_conenction_plan(dev, plan); - dnbd3_lock_all_socks(dev); + /* lock all mutex at once, so nothing can be send */ + debug_dev(dev, "connection plan:"); + for (i = 0; i < dev->number_connections; i++) { + debug_server(dev, plan[i], + "server %d with avg rtt %llu:", + i, plan[i]->avg_rtt); + + mutex_lock(&dev->socks[i].tx_lock); + } + alive = 0; for (i = 0; i < dev->number_connections; i++) { if (plan[i] != dev->socks[i].server || @@ -379,8 +361,9 @@ static int dnbd3_adjust_connections(struct dnbd3_device *dev) { } else { alive++; } + mutex_unlock(&dev->socks[i].tx_lock); } - dnbd3_unlock_all_socks(dev); + if (alive == 0) { return -EIO; } @@ -540,10 +523,8 @@ static void dnbd3_merge_new_server(struct dnbd3_device *dev, dnbd3_server_entry_t *new_server) { int i; - struct dnbd3_server *existing_server, *free_server, *failed_server; - existing_server = NULL; - free_server = NULL; - failed_server = NULL; + struct dnbd3_server *existing_server = NULL; + struct dnbd3_server *free_server = NULL; /* find servers in alternative servers */ for (i = 0; i < NUMBER_SERVERS; i++) { @@ -557,8 +538,6 @@ static void dnbd3_merge_new_server(struct dnbd3_device *dev, existing_server = &dev->alt_servers[i]; } else if (dev->alt_servers[i].host.type == 0) { free_server = &dev->alt_servers[i]; - } else if (dev->alt_servers[i].failures > 20) { - failed_server = &dev->alt_servers[i]; } } @@ -566,19 +545,16 @@ static void dnbd3_merge_new_server(struct dnbd3_device *dev, if (new_server->failures == 1) { /* remove is requested */ info_server(dev, new_server, "remove server is requested"); - // adjust connection will remove it later + /* adjust connection will remove it later */ existing_server->host.type = 0; dnbd3_set_rtt_unreachable(existing_server); } -// existing_server->failures = 0; // reset failure count return; } else if (free_server) { - //TODO disconnect the server if it is connected free_server->host = new_server->host; - } else if (failed_server) { - failed_server->host = new_server->host; - free_server = failed_server; } else { + warn_dev(dev, "reached the maximum of %d servers", + NUMBER_SERVERS); /* no server found to replace */ return; } diff --git a/src/kernel/sysfs.c b/src/kernel/sysfs.c index bd23845..a780a21 100644 --- a/src/kernel/sysfs.c +++ b/src/kernel/sysfs.c @@ -29,16 +29,6 @@ #define MIN(a,b) ((a) < (b) ? (a) : (b)) #endif -ssize_t show_initial_server_addr(char *buf, struct dnbd3_device *dev) -{ - if (dev->initial_server.host.type == HOST_IP4) - return MIN(snprintf(buf, PAGE_SIZE, "%pI4,%d\n", dev->initial_server.host.addr, (int)ntohs(dev->initial_server.host.port)), PAGE_SIZE); - else if (dev->initial_server.host.type == HOST_IP6) - return MIN(snprintf(buf, PAGE_SIZE, "%pI6,%d\n", dev->initial_server.host.addr, (int)ntohs(dev->initial_server.host.port)), PAGE_SIZE); - *buf = '\0'; - return 0; -} - ssize_t show_connected_servers(char *buf, struct dnbd3_device *dev) { int i, size = PAGE_SIZE, ret; @@ -136,13 +126,6 @@ ssize_t show_update_available(char *buf, struct dnbd3_device *dev) return MIN(snprintf(buf, PAGE_SIZE, "%d\n", dev->update_available), PAGE_SIZE); } -struct device_attr_t initial_server = -{ - .attr = {.name = "initial_server", .mode = 0444 }, - .show = show_initial_server_addr, - .store = NULL, -}; - struct device_attr_t connected_server = { .attr = {.name = "connected_server", .mode = 0444 }, @@ -200,7 +183,6 @@ ssize_t device_show(struct kobject *kobj, struct attribute *attr, char *buf) struct attribute *device_attrs[] = { - &initial_server.attr, &connected_server.attr, // &cur_server_rtt.attr, &alt_server_num.attr, |