diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/sysfs.c | 80 |
1 files changed, 61 insertions, 19 deletions
diff --git a/src/kernel/sysfs.c b/src/kernel/sysfs.c index b5e180b..2c319e3 100644 --- a/src/kernel/sysfs.c +++ b/src/kernel/sysfs.c @@ -2,6 +2,7 @@ * This file is part of the Distributed Network Block Device 3 * * Copyright(c) 2011-2012 Johann Latocha <johann@latocha.de> + * Copyright(c) 2019 Frederic Robra <frederic@robra.org> * * This file may be licensed under the terms of of the * GNU General Public License Version 2 (the ``GPL''). @@ -28,17 +29,51 @@ #define MIN(a,b) ((a) < (b) ? (a) : (b)) #endif -//ssize_t show_cur_server_addr(char *buf, dnbd3_device_t *dev) -//{ -// if (dev->cur_server.host.type == HOST_IP4) -// return MIN(snprintf(buf, PAGE_SIZE, "%pI4,%d\n", dev->cur_server.host.addr, (int)ntohs(dev->cur_server.host.port)), PAGE_SIZE); -// else if (dev->cur_server.host.type == HOST_IP6) -// return MIN(snprintf(buf, PAGE_SIZE, "%pI6,%d\n", dev->cur_server.host.addr, (int)ntohs(dev->cur_server.host.port)), PAGE_SIZE); -// *buf = '\0'; -// return 0; -//} -// -//ssize_t show_cur_server_rtt(char *buf, dnbd3_device_t *dev) +ssize_t show_initial_server_addr(char *buf, 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, dnbd3_device *dev) +{ + int i, size = PAGE_SIZE, ret; + for (i = 0; i < 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", + dev->socks[i].server->host.addr, + (int)ntohs(dev->socks[i].server->host.port), + (unsigned long long)((dev->socks[i].server->rtts[0] + dev->socks[i].server->rtts[1] + dev->socks[i].server->rtts[2] + dev->socks[i].server->rtts[3]) / 4), + (int)dev->socks[i].server->failures) + , size); + + } else { + ret = MIN(snprintf(buf, size, "%pI6,%d,%llu,%d\n", + dev->socks[i].server->host.addr, + (int)ntohs(dev->socks[i].server->host.port), + (unsigned long long)((dev->socks[i].server->rtts[0] + dev->socks[i].server->rtts[1] + dev->socks[i].server->rtts[2] + dev->socks[i].server->rtts[3]) / 4), + (int)dev->socks[i].server->failures) + , size); + + } + size -= ret; + buf += ret; + if (size <= 0) { + size = 0; + break; + } + } + + } + return PAGE_SIZE - size; +} + +//ssize_t show_cur_server_rtt(char *buf, dnbd3_devic *dev) //{ // return MIN(snprintf(buf, PAGE_SIZE, "%llu\n", (unsigned long long)dev->cur_rtt), PAGE_SIZE); //} @@ -101,13 +136,19 @@ ssize_t show_update_available(char *buf, dnbd3_device *dev) return MIN(snprintf(buf, PAGE_SIZE, "%d\n", dev->update_available), PAGE_SIZE); } -//device_attr_t cur_server_addr = -//{ -// .attr = {.name = "cur_server_addr", .mode = 0444 }, -// .show = show_cur_server_addr, -// .store = NULL, -//}; -// +device_attr_t initial_server = +{ + .attr = {.name = "initial_server", .mode = 0444 }, + .show = show_initial_server_addr, + .store = NULL, +}; + +device_attr_t connected_server = +{ + .attr = {.name = "connected_server", .mode = 0444 }, + .show = show_connected_servers, + .store = NULL, +}; //device_attr_t cur_server_rtt = //{ // .attr = {.name = "cur_server_rtt", .mode = 0444 }, @@ -159,7 +200,8 @@ ssize_t device_show(struct kobject *kobj, struct attribute *attr, char *buf) struct attribute *device_attrs[] = { -// &cur_server_addr.attr, + &initial_server.attr, + &connected_server.attr, // &cur_server_rtt.attr, &alt_server_num.attr, &alt_servers.attr, |