From fd4c68d75b5e06868c8dfd1b1078694460a1ad41 Mon Sep 17 00:00:00 2001 From: Frederic Robra Date: Wed, 17 Jul 2019 17:13:17 +0200 Subject: added some comments and macros --- src/kernel/dnbd3.h | 73 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 13 deletions(-) (limited to 'src/kernel/dnbd3.h') diff --git a/src/kernel/dnbd3.h b/src/kernel/dnbd3.h index c9f9fab..72294b0 100644 --- a/src/kernel/dnbd3.h +++ b/src/kernel/dnbd3.h @@ -30,8 +30,16 @@ #include "types.h" #include "serialize.h" +/** + * the number of parallel connections + */ +#define NUMBER_CONNECTIONS 4 // power of 2 + +/** + * limit to which the other connected servers are only allowed to be that worser then the best rtt + */ +#define RTT_THRESOULD_LIMIT(best_rtt) ((best_rtt) * 10) -#define NUMBER_CONNECTIONS 2 // power of 2 #define DEBUG @@ -56,7 +64,14 @@ struct dnbd3_server { * @sock_nr: nr of this socket * @device: the dnbd3_device this socket belongs to * @server: the server this socket is connected to, 'NULL' if not connected - * + * @tx_lock: mutex to lock when sending + * @sock: the socket, 'NULL' if not connected + * @panic: 'true' if it is not possible to send or receive + * @cookie: is incremented for every send, used to find the mq request in the receiver + * @keepalive_worker: worker to send a keepalive package + * @receive_worker: worker to handle the incoming packages + * @pending: the pending request which is going to be send + * @receive_command: the last command the receiver got */ struct dnbd3_sock { uint8_t sock_nr; @@ -66,7 +81,7 @@ struct dnbd3_sock { struct mutex tx_lock; struct socket *sock; - bool panic;//, discover, panic_count; + bool panic; uint32_t cookie; struct work_struct keepalive_worker; @@ -76,6 +91,30 @@ struct dnbd3_sock { uint16_t receive_command; }; +/** + * struct dnbd3_device - defining a dnbd3 device + * @minor: minor number of this device + * @tag_set: the blk mq tag set + * @list: list of previous and next dnbd3_device + * @disk: the gendisk + * @kobj: the kobject + * @device_lock: mutex to lock when device changes + * @socks: array of dnbd3_sock to connect to + * @imgname: the connected image name + * @initial_server: the server which was configured with ioctl, will not be overriden + * @alt_servers: array of alternative servers + * @new_servers_num: number of new alternative servers that are waiting to be copied to above array + * @new_servers: pending new alternative servers + * @update_available: 'true' if the rid has changes + * @use_server_provided_alts: 'true' if the alt_servers array is upated by the alternatives provided by the server + * @rid: the revision ID? TODO + * @reported_size: the size of the image + * @panic_worker: worker to handle panics and to connect if all connections are down + * @discovery_worker: worker to update the alt_servers, make rtt meassurement and reconnect to better servers + * @discovery_count: counter for the discovery worker + * @timer: timer to start the appropriate workers + * @timer_count: counter for the timer + */ struct dnbd3_device { int minor; struct blk_mq_tag_set tag_set; @@ -109,6 +148,14 @@ struct dnbd3_device { }; +/** + * struct dnbd3_cmd - defines a mq cmd for dnbd3 + * @dnbd3: the dnbd3 device this command belongs to + * @lock: mutex to lock the cmd + * @cookie: the cookie of the command, this is set by the socket when sending + * @status: the status of the command + * @requed: 'true' if the command is requed + */ struct dnbd3_cmd { struct dnbd3_device *dnbd3; struct mutex lock; @@ -118,7 +165,7 @@ struct dnbd3_cmd { }; -#define _print_sock(level, sock, fmt, ...) \ +#define __print_sock(level, sock, fmt, ...) \ do { \ if ((sock)->server->host.type == HOST_IP4) { \ printk(level "dnbd%d/%d %pI4:%d: " fmt "\n", (sock)->device->minor, (sock)->sock_nr, (sock)->server->host.addr, (sock)->server->host.port, ## __VA_ARGS__); \ @@ -127,7 +174,7 @@ struct dnbd3_cmd { } \ } while (0) -#define _print_server(level, dev, server, fmt, ...) \ +#define __print_server(level, dev, server, fmt, ...) \ do { \ if ((server)->host.type == HOST_IP4) { \ printk(level "dnbd%d: " fmt " %pI4:%d\n", (dev)->minor, ## __VA_ARGS__, (server)->host.addr, (server)->host.port); \ @@ -146,10 +193,10 @@ struct dnbd3_cmd { printk(KERN_DEBUG "dnbd%d: " fmt "\n", (dev)->minor, ## __VA_ARGS__) #define debug_sock(sock, fmt, ...) \ - _print_sock(KERN_DEBUG, sock, fmt, ## __VA_ARGS__) + __print_sock(KERN_DEBUG, sock, fmt, ## __VA_ARGS__) #define debug_server(dev, server, fmt, ...) \ - _print_server(KERN_DEBUG, dev, server, fmt, ## __VA_ARGS__) + __print_server(KERN_DEBUG, dev, server, fmt, ## __VA_ARGS__) #else @@ -170,10 +217,10 @@ struct dnbd3_cmd { printk(KERN_INFO "dnbd%d: " fmt "\n", (dev)->minor, ## __VA_ARGS__) #define info_sock(sock, fmt, ...) \ - _print_sock(KERN_INFO, sock, fmt, ## __VA_ARGS__) + __print_sock(KERN_INFO, sock, fmt, ## __VA_ARGS__) #define info_server(dev, server, fmt, ...) \ - _print_server(KERN_INFO, dev, server, fmt, ## __VA_ARGS__) + __print_server(KERN_INFO, dev, server, fmt, ## __VA_ARGS__) #define warn(fmt, ...) \ @@ -183,10 +230,10 @@ struct dnbd3_cmd { printk(KERN_WARNING "dnbd%d: " fmt "\n", (dev)->minor, ## __VA_ARGS__) #define warn_sock(sock, fmt, ...) \ - _print_sock(KERN_WARNING, sock, fmt, ## __VA_ARGS__) + __print_sock(KERN_WARNING, sock, fmt, ## __VA_ARGS__) #define warn_server(dev, server, fmt, ...) \ - _print_server(KERN_WARNING, dev, server, fmt, ## __VA_ARGS__) + __print_server(KERN_WARNING, dev, server, fmt, ## __VA_ARGS__) #define error(fmt, ...) \ @@ -196,9 +243,9 @@ struct dnbd3_cmd { printk(KERN_ERR "dnbd%d: " fmt "\n", (dev)->minor, ## __VA_ARGS__) #define error_sock(sock, fmt, ...) \ - _print_sock(KERN_ERR, sock, fmt, ## __VA_ARGS__) + __print_sock(KERN_ERR, sock, fmt, ## __VA_ARGS__) #define error_server(dev, server, fmt, ...) \ - _print_server(KERN_ERR, dev, server, fmt, ## __VA_ARGS__) + __print_server(KERN_ERR, dev, server, fmt, ## __VA_ARGS__) #endif /* DNBD_H_ */ -- cgit v1.2.3-55-g7522