diff options
| author | Davide Libenzi <davidel@xmailserver.org> | 2007-05-11 01:23:23 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-05-11 11:29:37 -0400 |
| commit | 7699acd1341c63fdbcfc56994fb2989ec59d2a43 (patch) | |
| tree | ccb434eca7111edc906a96a59b299fdba6d47f12 | |
| parent | cea69241870e55638156a026814551d6c575fd7f (diff) | |
epoll cleanups: epoll remove static pre-declarations and akpm-ize the code
Re-arrange epoll code to avoid static functions pre-declarations, and apply
akpm-filter on it.
Signed-off-by: Davide Libenzi <davidel@xmailserver.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
| -rw-r--r-- | fs/eventpoll.c | 1034 |
1 files changed, 486 insertions, 548 deletions
diff --git a/fs/eventpoll.c b/fs/eventpoll.c index e224abfd9197..1aad34ea61a4 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c | |||
| @@ -41,7 +41,6 @@ | |||
| 41 | #include <asm/atomic.h> | 41 | #include <asm/atomic.h> |
| 42 | #include <asm/semaphore.h> | 42 | #include <asm/semaphore.h> |
| 43 | 43 | ||
| 44 | |||
| 45 | /* | 44 | /* |
| 46 | * LOCKING: | 45 | * LOCKING: |
| 47 | * There are three level of locking required by epoll : | 46 | * There are three level of locking required by epoll : |
| @@ -74,7 +73,6 @@ | |||
| 74 | * a greater scalability. | 73 | * a greater scalability. |
| 75 | */ | 74 | */ |
| 76 | 75 | ||
| 77 | |||
| 78 | #define DEBUG_EPOLL 0 | 76 | #define DEBUG_EPOLL 0 |
| 79 | 77 | ||
| 80 | #if DEBUG_EPOLL > 0 | 78 | #if DEBUG_EPOLL > 0 |
| @@ -104,7 +102,6 @@ | |||
| 104 | 102 | ||
| 105 | #define EP_MAX_EVENTS (INT_MAX / sizeof(struct epoll_event)) | 103 | #define EP_MAX_EVENTS (INT_MAX / sizeof(struct epoll_event)) |
| 106 | 104 | ||
| 107 | |||
| 108 | struct epoll_filefd { | 105 | struct epoll_filefd { |
| 109 | struct file *file; | 106 | struct file *file; |
| 110 | int fd; | 107 | int fd; |
| @@ -222,36 +219,6 @@ struct ep_pqueue { | |||
| 222 | struct epitem *epi; | 219 | struct epitem *epi; |
| 223 | }; | 220 | }; |
| 224 | 221 | ||
| 225 | |||
| 226 | |||
| 227 | static void ep_poll_safewake_init(struct poll_safewake *psw); | ||
| 228 | static void ep_poll_safewake(struct poll_safewake *psw, wait_queue_head_t *wq); | ||
| 229 | static int ep_alloc(struct eventpoll **pep); | ||
| 230 | static void ep_free(struct eventpoll *ep); | ||
| 231 | static struct epitem *ep_find(struct eventpoll *ep, struct file *file, int fd); | ||
| 232 | static void ep_use_epitem(struct epitem *epi); | ||
| 233 | static void ep_release_epitem(struct epitem *epi); | ||
| 234 | static void ep_ptable_queue_proc(struct file *file, wait_queue_head_t *whead, | ||
| 235 | poll_table *pt); | ||
| 236 | static void ep_rbtree_insert(struct eventpoll *ep, struct epitem *epi); | ||
| 237 | static int ep_insert(struct eventpoll *ep, struct epoll_event *event, | ||
| 238 | struct file *tfile, int fd); | ||
| 239 | static int ep_modify(struct eventpoll *ep, struct epitem *epi, | ||
| 240 | struct epoll_event *event); | ||
| 241 | static void ep_unregister_pollwait(struct eventpoll *ep, struct epitem *epi); | ||
| 242 | static int ep_unlink(struct eventpoll *ep, struct epitem *epi); | ||
| 243 | static int ep_remove(struct eventpoll *ep, struct epitem *epi); | ||
| 244 | static int ep_poll_callback(wait_queue_t *wait, unsigned mode, int sync, void *key); | ||
| 245 | static int ep_eventpoll_close(struct inode *inode, struct file *file); | ||
| 246 | static unsigned int ep_eventpoll_poll(struct file *file, poll_table *wait); | ||
| 247 | static int ep_send_events(struct eventpoll *ep, struct list_head *txlist, | ||
| 248 | struct epoll_event __user *events, int maxevents); | ||
| 249 | static int ep_events_transfer(struct eventpoll *ep, | ||
| 250 | struct epoll_event __user *events, | ||
| 251 | int maxevents); | ||
| 252 | static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events, | ||
| 253 | int maxevents, long timeout); | ||
| 254 | |||
| 255 | /* | 222 | /* |
| 256 | * This semaphore is used to serialize ep_free() and eventpoll_release_file(). | 223 | * This semaphore is used to serialize ep_free() and eventpoll_release_file(). |
| 257 | */ | 224 | */ |
| @@ -266,19 +233,6 @@ static struct kmem_cache *epi_cache __read_mostly; | |||
| 266 | /* Slab cache used to allocate "struct eppoll_entry" */ | 233 | /* Slab cache used to allocate "struct eppoll_entry" */ |
| 267 | static struct kmem_cache *pwq_cache __read_mostly; | 234 | static struct kmem_cache *pwq_cache __read_mostly; |
| 268 | 235 | ||
| 269 | /* File callbacks that implement the eventpoll file behaviour */ | ||
| 270 | static const struct file_operations eventpoll_fops = { | ||
| 271 | .release = ep_eventpoll_close, | ||
| 272 | .poll = ep_eventpoll_poll | ||
| 273 | }; | ||
| 274 | |||
| 275 | |||
| 276 | |||
| 277 | /* Fast test to see if the file is an evenpoll file */ | ||
| 278 | static inline int is_file_epoll(struct file *f) | ||
| 279 | { | ||
| 280 | return f->f_op == &eventpoll_fops; | ||
| 281 | } | ||
| 282 | 236 | ||
| 283 | /* Setup the structure that is used as key for the rb-tree */ | 237 | /* Setup the structure that is used as key for the rb-tree */ |
| 284 | static inline void ep_set_ffd(struct epoll_filefd *ffd, | 238 | static inline void ep_set_ffd(struct epoll_filefd *ffd, |
| @@ -347,7 +301,6 @@ static void ep_poll_safewake_init(struct poll_safewake *psw) | |||
| 347 | spin_lock_init(&psw->lock); | 301 | spin_lock_init(&psw->lock); |
| 348 | } | 302 | } |
| 349 | 303 | ||
| 350 | |||
| 351 | /* | 304 | /* |
| 352 | * Perform a safe wake up of the poll wait list. The problem is that | 305 | * Perform a safe wake up of the poll wait list. The problem is that |
| 353 | * with the new callback'd wake up system, it is possible that the | 306 | * with the new callback'd wake up system, it is possible that the |
| @@ -402,325 +355,145 @@ static void ep_poll_safewake(struct poll_safewake *psw, wait_queue_head_t *wq) | |||
| 402 | spin_unlock_irqrestore(&psw->lock, flags); | 355 | spin_unlock_irqrestore(&psw->lock, flags); |
| 403 | } | 356 | } |
| 404 | 357 | ||
| 405 | |||
| 406 | /* | 358 | /* |
| 407 | * This is called from eventpoll_release() to unlink files from the eventpoll | 359 | * This function unregister poll callbacks from the associated file descriptor. |
| 408 | * interface. We need to have this facility to cleanup correctly files that are | 360 | * Since this must be called without holding "ep->lock" the atomic exchange trick |
| 409 | * closed without being removed from the eventpoll interface. | 361 | * will protect us from multiple unregister. |
| 410 | */ | 362 | */ |
| 411 | void eventpoll_release_file(struct file *file) | 363 | static void ep_unregister_pollwait(struct eventpoll *ep, struct epitem *epi) |
| 412 | { | 364 | { |
| 413 | struct list_head *lsthead = &file->f_ep_links; | 365 | int nwait; |
| 414 | struct eventpoll *ep; | 366 | struct list_head *lsthead = &epi->pwqlist; |
| 415 | struct epitem *epi; | 367 | struct eppoll_entry *pwq; |
| 416 | 368 | ||
| 417 | /* | 369 | /* This is called without locks, so we need the atomic exchange */ |
| 418 | * We don't want to get "file->f_ep_lock" because it is not | 370 | nwait = xchg(&epi->nwait, 0); |
| 419 | * necessary. It is not necessary because we're in the "struct file" | ||
| 420 | * cleanup path, and this means that noone is using this file anymore. | ||
| 421 | * The only hit might come from ep_free() but by holding the semaphore | ||
| 422 | * will correctly serialize the operation. We do need to acquire | ||
| 423 | * "ep->sem" after "epmutex" because ep_remove() requires it when called | ||
| 424 | * from anywhere but ep_free(). | ||
| 425 | */ | ||
| 426 | mutex_lock(&epmutex); | ||
| 427 | 371 | ||
| 428 | while (!list_empty(lsthead)) { | 372 | if (nwait) { |
| 429 | epi = list_first_entry(lsthead, struct epitem, fllink); | 373 | while (!list_empty(lsthead)) { |
| 374 | pwq = list_first_entry(lsthead, struct eppoll_entry, llink); | ||
| 430 | 375 | ||
| 431 | ep = epi->ep; | 376 | list_del_init(&pwq->llink); |
| 432 | list_del_init(&epi->fllink); | 377 | remove_wait_queue(pwq->whead, &pwq->wait); |
| 433 | down_write(&ep->sem); | 378 | kmem_cache_free(pwq_cache, pwq); |
| 434 | ep_remove(ep, epi); | 379 | } |
| 435 | up_write(&ep->sem); | ||
| 436 | } | 380 | } |
| 437 | |||
| 438 | mutex_unlock(&epmutex); | ||
| 439 | } | 381 | } |
| 440 | 382 | ||
| 441 | |||
| 442 | /* | 383 | /* |
| 443 | * It opens an eventpoll file descriptor by suggesting a storage of "size" | 384 | * Unlink the "struct epitem" from all places it might have been hooked up. |
| 444 | * file descriptors. The size parameter is just an hint about how to size | 385 | * This function must be called with write IRQ lock on "ep->lock". |
| 445 | * data structures. It won't prevent the user to store more than "size" | ||
| 446 | * file descriptors inside the epoll interface. It is the kernel part of | ||
| 447 | * the userspace epoll_create(2). | ||
| 448 | */ | 386 | */ |
| 449 | asmlinkage long sys_epoll_create(int size) | 387 | static int ep_unlink(struct eventpoll *ep, struct epitem *epi) |
| 450 | { | 388 | { |
| 451 | int error, fd = -1; | 389 | int error; |
| 452 | struct eventpoll *ep; | ||
| 453 | struct inode *inode; | ||
| 454 | struct file *file; | ||
| 455 | |||
| 456 | DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_create(%d)\n", | ||
| 457 | current, size)); | ||
| 458 | |||
| 459 | /* | ||
| 460 | * Sanity check on the size parameter, and create the internal data | ||
| 461 | * structure ( "struct eventpoll" ). | ||
| 462 | */ | ||
| 463 | error = -EINVAL; | ||
| 464 | if (size <= 0 || (error = ep_alloc(&ep)) != 0) | ||
| 465 | goto eexit_1; | ||
| 466 | 390 | ||
