From 1b784de410df81daf78035490c1020d2fc1b9235 Mon Sep 17 00:00:00 2001 From: patiencew Date: Tue, 13 Nov 2007 06:24:04 +0000 Subject: [PATCH] cleaned up some git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@2060 29311d96-e01e-0410-9327-a35deaab8ce9 --- trunk/ceph/kernel/messenger.c | 39 +++++++++++------------- trunk/ceph/kernel/messenger.h | 4 ++- trunk/ceph/kernel/poll.c | 57 ++++++++--------------------------- trunk/ceph/kernel/poll.h | 15 +++------ 4 files changed, 38 insertions(+), 77 deletions(-) diff --git a/trunk/ceph/kernel/messenger.c b/trunk/ceph/kernel/messenger.c index e6b2331ffdb1f..2766efca5b64d 100644 --- a/trunk/ceph/kernel/messenger.c +++ b/trunk/ceph/kernel/messenger.c @@ -606,8 +606,6 @@ static void try_accept(struct work_struct *work) new_con->in_tag = CEPH_MSGR_TAG_READY; /* TBD: fill in part of peers address */ /* new_con->peeraddr = saddr; */ -/* TBD: may not use this.. */ - new_sd->sk->sk_user_data = con; prepare_write_accept_announce(msgr, con); @@ -628,7 +626,7 @@ struct ceph_connection *new_listener(struct ceph_messenger *msgr) memset(&saddr, 0, sizeof(saddr)); con = kmalloc(sizeof(struct ceph_connection), GFP_KERNEL); - if (con == NULL) return 0; + if (con == NULL) return NULL; memset(&con, 0, sizeof(con)); /* create listener connection */ @@ -650,35 +648,34 @@ struct ceph_connection *new_listener(struct ceph_messenger *msgr) static struct ceph_messenger *new_messenger(void) { struct ceph_messenger *msgr; - struct ceph_connection *con; - struct ceph_pollable *pfiles; + struct ceph_connection *listener; msgr = kmalloc(sizeof(struct ceph_messenger), GFP_KERNEL); - if (msgr == NULL) return 0; + if (msgr == NULL) + goto done; memset(&msgr, 0, sizeof(msgr)); spin_lock_init(&msgr->con_lock); - - pfiles = kmalloc(sizeof(struct ceph_poll_task), GFP_KERNEL); - if (pfiles == NULL) { - kfree(msgr); - return 0; - } + INIT_LIST_HEAD(&msgr->poll_list); /* create listener connection */ - con = new_listener(msgr); + listener = new_listener(msgr); + if (listener == NULL) + goto err; - /* start polling */ - msgr->poll_task = start_poll(); + list_add(&msgr->poll_list, &listener->poll_list); + /* start up poll thread */ + msgr->poll_task = kthread_run(start_poll, msgr, "ceph-poll"); + if (IS_ERR(msgr->poll_task)) + goto err; - /* add listener to pollable files - * TBD: maybe do this before start polling */ - pfiles->con = con; - pfiles->file = con->sock->file; - list_add(&pfiles->poll_list, &msgr->poll_task->pfiles->poll_list); /* add to poll list */ - +done: return msgr; +err: + kfree(msgr); + msgr = NULL; + goto done; } diff --git a/trunk/ceph/kernel/messenger.h b/trunk/ceph/kernel/messenger.h index 3f95b56abc07a..556e076f0c557 100644 --- a/trunk/ceph/kernel/messenger.h +++ b/trunk/ceph/kernel/messenger.h @@ -17,12 +17,13 @@ typedef void (*ceph_messenger_dispatch_t) (void *p, struct ceph_message *m); struct ceph_messenger { void *parent; ceph_messenger_dispatch_t dispatch; - struct ceph_poll_task *poll_task; + struct task_struct *poll_task; struct ceph_connection *listen_con; /* listening connection */ struct ceph_entity_addr addr; /* my address */ spinlock_t con_lock; struct list_head con_all; /* all connections */ struct list_head con_accepting; /* doing handshake, or */ + struct list_head poll_list; /* connections polling */ struct radix_tree_root con_open; /* established. see get_connection() */ }; @@ -55,6 +56,7 @@ struct ceph_connection { struct list_head list_all; /* msgr->con_all */ struct list_head list_bucket; /* msgr->con_open or con_accepting */ + struct list_head poll_list; /* msgr->poll_list */ struct ceph_entity_addr peer_addr; /* peer address */ enum ceph_connection_state state; diff --git a/trunk/ceph/kernel/poll.c b/trunk/ceph/kernel/poll.c index 0609a9926baad..b83b824268c30 100644 --- a/trunk/ceph/kernel/poll.c +++ b/trunk/ceph/kernel/poll.c @@ -16,14 +16,10 @@ static struct workqueue_struct *send_wq; /* send work queue */ /* TBD: probably remove pwait, but may play around with it some.. * null for now.. No timeout, timeout maybe ignored if O_NONBLOCK anyway.. */ -static int do_ceph_pollfd(struct file *file, poll_table *pwait) +static int do_ceph_poll(struct ceph_connection *con, poll_table *pwait) { int mask; - struct socket *sock = (struct socket *)file->private_data; - struct sock *sk = sock->sk; - /* may keep connection in poll list instead of using this field */ - struct ceph_connection *con = - (struct ceph_connection *)sk->sk_user_data; + struct file *file = con->sock->file; mask = file->f_op->poll(file, pwait); @@ -57,10 +53,10 @@ static int do_ceph_pollfd(struct file *file, poll_table *pwait) /* * Poll thread function, start after creating listener connection */ -static int ceph_poll(void *arg) +int start_polling(void *arg) { - struct ceph_pollable *pos, *next; - struct ceph_pollable *pollables = arg; + struct ceph_connection *pos, *next; + struct ceph_messenger *pollables = arg; printk(KERN_INFO "starting kernel poll thread\n"); @@ -75,14 +71,14 @@ static int ceph_poll(void *arg) * this will work better for a large number of file descriptors */ list_for_each_entry_safe(pos, next, &pollables->poll_list, poll_list) { - if (do_ceph_pollfd(pos->file, NULL)) { - spin_lock(&pos->plock); + if (do_ceph_poll(pos, NULL)) { + spin_lock(&pos->con_lock); /* remove file from poll_list */ list_del(&pos->poll_list); - spin_unlock(&pos->plock); + spin_unlock(&pos->con_lock); /* TBD: free list entry or reuse..Need reuse list */ /* double check not freeing out from undermyself*/ - kfree(pos); + /* kfree(pos); */ } } schedule_timeout(5*HZ); /* TBD: make configurable */ @@ -92,39 +88,10 @@ static int ceph_poll(void *arg) return(0); } -struct ceph_poll_task *start_poll() +void stop_polling(struct ceph_messenger *msgr) { - struct ceph_poll_task *ptsk; - struct ceph_pollable *pfiles; - - ptsk = kmalloc(sizeof(struct ceph_poll_task), GFP_KERNEL); - if (ptsk == NULL) { - return 0; - } - memset(&ptsk, 0, sizeof(ptsk)); - - pfiles = kmalloc(sizeof(struct ceph_poll_task), GFP_KERNEL); - if (pfiles == NULL) { - kfree(ptsk); - return 0; - } - memset(pfiles, 0, sizeof(pfiles)); - INIT_LIST_HEAD(&pfiles->poll_list); - - /* start up poll thread */ - ptsk->poll_task = kthread_run(ceph_poll, pfiles, "ceph-poll"); - if (IS_ERR(ptsk->poll_task)) { - /* cleanup */ - } - - return(ptsk); -} - -void stop_poll(struct ceph_poll_task *ptsk) -{ - kthread_stop(ptsk->poll_task); - wake_up_process(ptsk->poll_task); - /* Free up poll structures.. */ + kthread_stop(msgr->poll_task); + wake_up_process(msgr->poll_task); } /* diff --git a/trunk/ceph/kernel/poll.h b/trunk/ceph/kernel/poll.h index e185f3e9557f7..11653a53a8c9a 100644 --- a/trunk/ceph/kernel/poll.h +++ b/trunk/ceph/kernel/poll.h @@ -1,19 +1,14 @@ #ifndef __FS_CEPH_POLL_H #define __FS_CEPH_POLL_H -struct ceph_poll_task *start_poll(void); - -/* list of pollable files */ -struct ceph_pollable { - spinlock_t plock; - struct list_head poll_list; - struct file *file; - struct ceph_connection *con; -}; +int start_poll(void *); +/* + * May use, probably not.. + */ struct ceph_poll_task { struct task_struct *poll_task; - struct ceph_pollable *pfiles; + struct list_head poll_list; u64 timeout; }; -- 2.39.5