summaryrefslogtreecommitdiffstats
path: root/src/kernel
diff options
context:
space:
mode:
authorFrederic Robra2019-07-09 12:12:55 +0200
committerFrederic Robra2019-07-09 12:12:55 +0200
commit04ba582cf57deacb07884b2d26ef60a591087dd3 (patch)
tree81c10e3fb3b04aeed85a3644998419cc37e52775 /src/kernel
parentadded first draft for keepalive and discovery (diff)
downloaddnbd3-ng-04ba582cf57deacb07884b2d26ef60a591087dd3.tar.gz
dnbd3-ng-04ba582cf57deacb07884b2d26ef60a591087dd3.tar.xz
dnbd3-ng-04ba582cf57deacb07884b2d26ef60a591087dd3.zip
added worker for keepalive and discovery
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/core.c7
-rw-r--r--src/kernel/dnbd3.h4
-rw-r--r--src/kernel/net.c16
3 files changed, 18 insertions, 9 deletions
diff --git a/src/kernel/core.c b/src/kernel/core.c
index 48f809b..1b0aa46 100644
--- a/src/kernel/core.c
+++ b/src/kernel/core.c
@@ -54,6 +54,8 @@
#define DNBD3_CMD_REQUEUED 1
+
+struct workqueue_struct *dnbd3_wq;
DEFINE_IDR(dnbd3_index_idr);
DEFINE_MUTEX(dnbd3_index_mutex);
@@ -426,6 +428,8 @@ static int __init dnbd3_init(void)
int i;
printk(KERN_DEBUG "dnbd3: starting kernel module\n");
+ dnbd3_wq = alloc_workqueue("kdnbd3", WQ_MEM_RECLAIM | WQ_FREEZABLE, 1);
+
if (max_devs < 0) {
printk(KERN_ERR "dnbd3: max_devs must be >= 0\n");
return -EINVAL;
@@ -483,6 +487,7 @@ static void dnbd3_dev_remove(struct dnbd3_device *dnbd3)
disk->private_data = NULL;
put_disk(disk);
}
+ mutex_destroy(&dnbd3->device_lock);
}
static void dnbd3_put(struct dnbd3_device *dnbd3)
@@ -516,6 +521,8 @@ static void __exit dnbd3_exit(void)
kfree(device);
+ destroy_workqueue(dnbd3_wq);
+
printk(KERN_INFO "dnbd3: stopped kernel module\n");
}
diff --git a/src/kernel/dnbd3.h b/src/kernel/dnbd3.h
index 57f26f6..0e39dfb 100644
--- a/src/kernel/dnbd3.h
+++ b/src/kernel/dnbd3.h
@@ -33,6 +33,9 @@
#define NUMBER_CONNECTIONS 4
+
+extern struct workqueue_struct *dnbd3_wq;
+
typedef struct dnbd3_server {
dnbd3_host_t host;
uint64_t rtts[4]; // Last four round trip time measurements in microsecond
@@ -90,7 +93,6 @@ typedef struct dnbd3_device {
struct work_struct discovery; // if in irq and need to send request
struct timer_list discovery_timer;
-
// process
// struct task_struct * thread_send;
// struct task_struct * thread_receive;
diff --git a/src/kernel/net.c b/src/kernel/net.c
index f44925f..921f0d3 100644
--- a/src/kernel/net.c
+++ b/src/kernel/net.c
@@ -31,8 +31,8 @@
#define dnbd3_req_op(req) req_op(req)
#define dnbd3_sock_create(af,type,proto,sock) sock_create_kern(&init_net, (af) == HOST_IP4 ? AF_INET : AF_INET6, type, proto, sock)
-#define KEEPALIVE_TIMER (TIMER_INTERVAL_KEEPALIVE_PACKET * (jiffies + HZ))
-#define DISCOVERY_TIMER (TIMER_INTERVAL_PROBE_NORMAL * (jiffies + HZ))
+#define KEEPALIVE_TIMER (jiffies + (HZ * TIMER_INTERVAL_KEEPALIVE_PACKET))
+#define DISCOVERY_TIMER (jiffies + (HZ * TIMER_INTERVAL_PROBE_NORMAL))
#define init_msghdr(h) do { \
h.msg_name = NULL; \
@@ -43,6 +43,7 @@
} while (0)
+
static void printHost(struct dnbd3_host_t *host, char *msg)
{
if (host->type == HOST_IP4) {
@@ -239,8 +240,8 @@ error:
void dnbd3_keepalive(struct timer_list *arg)
{
struct dnbd3_sock *sock = container_of(arg, struct dnbd3_sock, keepalive_timer);
- printk(KERN_DEBUG "dnbd3: schedule keepalive\n");
// schedule_work(&sock->keepalive);
+ queue_work(dnbd3_wq, &sock->keepalive);
sock->keepalive_timer.expires = KEEPALIVE_TIMER;
add_timer(&sock->keepalive_timer);
}
@@ -249,6 +250,7 @@ static void keepalive(struct work_struct *work)
{
struct dnbd3_sock *sock = container_of(work, struct dnbd3_sock, keepalive);
struct request *req;
+ printk(KERN_DEBUG "dnbd3: starting keepalive worker\n");
mutex_lock(&sock->lock);
req = kmalloc(sizeof(struct request), GFP_ATOMIC );
// send keepalive
@@ -266,8 +268,7 @@ static void keepalive(struct work_struct *work)
void dnbd3_discovery(struct timer_list *arg)
{
struct dnbd3_device *dev = container_of(arg, struct dnbd3_device, discovery_timer);
- printk(KERN_DEBUG "dnbd3: schedule discovery\n");
-// schedule_work(&dev->discovery);
+ queue_work(dnbd3_wq, &dev->discovery);
dev->discovery_timer.expires = DISCOVERY_TIMER;
add_timer(&dev->discovery_timer);
}
@@ -277,12 +278,13 @@ static void discovery(struct work_struct *work)
struct dnbd3_device *dev = container_of(work, struct dnbd3_device, discovery);
dnbd3_sock *sock = &dev->socks[0]; // we use the first sock for discovery
struct request *req;
+ printk(KERN_DEBUG "dnbd3: starting discovery worker\n");
mutex_lock(&sock->lock);
req = kmalloc(sizeof(struct request), GFP_ATOMIC );
// send keepalive
if (req) {
dnbd3_cmd_to_priv(req, CMD_GET_SERVERS);
- dnbd3_send_request(NULL, sock, req); // we do not need the device for keepalive
+ dnbd3_send_request(dev, sock, req); // we do not need the device for keepalive
kfree(req);
} else {
printk(KERN_WARNING "dnbd3: could not create get servers request\n");
@@ -468,7 +470,6 @@ static int dnbd3_socket_disconnect(dnbd3_device *dev, dnbd3_sock *sock)
// clear heartbeat timer
del_timer_sync(&sock->keepalive_timer);
-// destroy_workqueue(&sock->keepalive);
if (sock->sock) {
kernel_sock_shutdown(sock->sock, SHUT_RDWR);
@@ -490,7 +491,6 @@ int dnbd3_net_disconnect(struct dnbd3_device *dev)
int i;
int result;
del_timer_sync(&dev->discovery_timer);
-// destroy_workqueue(&dev->discovery);
for (i = 0; i < NUMBER_CONNECTIONS; i++) {
if (dev->socks[i].sock) {
if (dnbd3_socket_disconnect(dev, &dev->socks[i])) {