aboutsummaryrefslogtreecommitdiffstats
path: root/fs/eventpoll.c
diff options
context:
space:
mode:
authorTony Luck <tony.luck@intel.com>2005-10-20 13:41:44 -0400
committerTony Luck <tony.luck@intel.com>2005-10-20 13:41:44 -0400
commit9cec58dc138d6fcad9f447a19c8ff69f6540e667 (patch)
tree4fe1cca94fdba8b705c87615bee06d3346f687ce /fs/eventpoll.c
parent17e5ad6c0ce5a970e2830d0de8bdd60a2f077d38 (diff)
parentac9b9c667c2e1194e22ebe0a441ae1c37aaa9b90 (diff)
Update from upstream with manual merge of Yasunori Goto's
changes to swiotlb.c made in commit 281dd25cdc0d6903929b79183816d151ea626341 since this file has been moved from arch/ia64/lib/swiotlb.c to lib/swiotlb.c Signed-off-by: Tony Luck <tony.luck@intel.com>
Diffstat (limited to 'fs/eventpoll.c')
-rw-r--r--fs/eventpoll.c48
1 files changed, 26 insertions, 22 deletions
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 6ab1dd0ca90..4284cd31eba 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -101,6 +101,10 @@
101/* Maximum number of poll wake up nests we are allowing */ 101/* Maximum number of poll wake up nests we are allowing */
102#define EP_MAX_POLLWAKE_NESTS 4 102#define EP_MAX_POLLWAKE_NESTS 4
103 103
104/* Maximum msec timeout value storeable in a long int */
105#define EP_MAX_MSTIMEO min(1000ULL * MAX_SCHEDULE_TIMEOUT / HZ, (LONG_MAX - 999ULL) / HZ)
106
107
104struct epoll_filefd { 108struct epoll_filefd {
105 struct file *file; 109 struct file *file;
106 int fd; 110 int fd;
@@ -231,8 +235,9 @@ struct ep_pqueue {
231 235
232static void ep_poll_safewake_init(struct poll_safewake *psw); 236static void ep_poll_safewake_init(struct poll_safewake *psw);
233static void ep_poll_safewake(struct poll_safewake *psw, wait_queue_head_t *wq); 237static void ep_poll_safewake(struct poll_safewake *psw, wait_queue_head_t *wq);
234static int ep_getfd(int *efd, struct inode **einode, struct file **efile); 238static int ep_getfd(int *efd, struct inode **einode, struct file **efile,
235static int ep_file_init(struct file *file); 239 struct eventpoll *ep);
240static int ep_alloc(struct eventpoll **pep);
236static void ep_free(struct eventpoll *ep); 241static void ep_free(struct eventpoll *ep);
237static struct epitem *ep_find(struct eventpoll *ep, struct file *file, int fd); 242static struct epitem *ep_find(struct eventpoll *ep, struct file *file, int fd);
238static void ep_use_epitem(struct epitem *epi); 243static void ep_use_epitem(struct epitem *epi);
@@ -501,38 +506,37 @@ void eventpoll_release_file(struct file *file)
501asmlinkage long sys_epoll_create(int size) 506asmlinkage long sys_epoll_create(int size)
502{ 507{
503 int error, fd; 508 int error, fd;
509 struct eventpoll *ep;
504 struct inode *inode; 510 struct inode *inode;
505 struct file *file; 511 struct file *file;
506 512
507 DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_create(%d)\n", 513 DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_create(%d)\n",
508 current, size)); 514 current, size));
509 515
510 /* Sanity check on the size parameter */ 516 /*
517 * Sanity check on the size parameter, and create the internal data
518 * structure ( "struct eventpoll" ).
519 */
511 error = -EINVAL; 520 error = -EINVAL;
512 if (size <= 0) 521 if (size <= 0 || (error = ep_alloc(&ep)) != 0)
513 goto eexit_1; 522 goto eexit_1;
514 523
515 /* 524 /*
516 * Creates all the items needed to setup an eventpoll file. That is, 525 * Creates all the items needed to setup an eventpoll file. That is,
517 * a file structure, and inode and a free file descriptor. 526 * a file structure, and inode and a free file descriptor.
518 */ 527 */
519 error = ep_getfd(&fd, &inode, &file); 528 error = ep_getfd(&fd, &inode, &file, ep);
520 if (error)
521 goto eexit_1;
522
523 /* Setup the file internal data structure ( "struct eventpoll" ) */
524 error = ep_file_init(file);
525 if (error) 529 if (error)
526 goto eexit_2; 530 goto eexit_2;
527 531
528
529 DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_create(%d) = %d\n", 532 DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_create(%d) = %d\n",
530 current, size, fd)); 533 current, size, fd));
531 534
532 return fd; 535 return fd;
533 536
534eexit_2: 537eexit_2:
535 sys_close(fd); 538 ep_free(ep);
539 kfree(ep);
536eexit_1: 540eexit_1:
537 DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_create(%d) = %d\n", 541 DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_create(%d) = %d\n",
538 current, size, error)); 542 current, size, error));
@@ -706,7 +710,8 @@ eexit_1:
706/* 710/*
707 * Creates the file descriptor to be used by the epoll interface. 711 * Creates the file descriptor to be used by the epoll interface.
708 */ 712 */
709static int ep_getfd(int *efd, struct inode **einode, struct file **efile) 713static int ep_getfd(int *efd, struct inode **einode, struct file **efile,
714 struct eventpoll *ep)
710{ 715{
711 struct qstr this; 716 struct qstr this;
712 char name[32]; 717 char name[32];
@@ -756,7 +761,7 @@ static int ep_getfd(int *efd, struct inode **einode, struct file **efile)
756 file->f_op = &eventpoll_fops; 761 file->f_op = &eventpoll_fops;
757 file->f_mode = FMODE_READ; 762 file->f_mode = FMODE_READ;
758 file->f_version = 0; 763 file->f_version = 0;
759 file->private_data = NULL; 764 file->private_data = ep;
760 765
761 /* Install the new setup file into the allocated fd. */ 766 /* Install the new setup file into the allocated fd. */
762 fd_install(fd, file); 767 fd_install(fd, file);
@@ -777,14 +782,13 @@ eexit_1:
777} 782}
778 783
779 784
780static int ep_file_init(struct file *file) 785static int ep_alloc(struct eventpoll **pep)
781{ 786{
782 struct eventpoll *ep; 787 struct eventpoll *ep = kzalloc(sizeof(*ep), GFP_KERNEL);
783 788
784 if (!(ep = kmalloc(sizeof(struct eventpoll), GFP_KERNEL))) 789 if (!ep)
785 return -ENOMEM; 790 return -ENOMEM;
786 791
787 memset(ep, 0, sizeof(*ep));
788 rwlock_init(&ep->lock); 792 rwlock_init(&ep->lock);
789 init_rwsem(&ep->sem); 793 init_rwsem(&ep->sem);
790 init_waitqueue_head(&ep->wq); 794 init_waitqueue_head(&ep->wq);
@@ -792,9 +796,9 @@ static int ep_file_init(struct file *file)
792 INIT_LIST_HEAD(&ep->rdllist); 796 INIT_LIST_HEAD(&ep->rdllist);
793 ep->rbr = RB_ROOT; 797 ep->rbr = RB_ROOT;
794 798
795 file->private_data = ep; 799 *pep = ep;
796 800
797 DNPRINTK(3, (KERN_INFO "[%p] eventpoll: ep_file_init() ep=%p\n", 801 DNPRINTK(3, (KERN_INFO "[%p] eventpoll: ep_alloc() ep=%p\n",
798 current, ep)); 802 current, ep));
799 return 0; 803 return 0;
800} 804}
@@ -1506,8 +1510,8 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
1506 * and the overflow condition. The passed timeout is in milliseconds, 1510 * and the overflow condition. The passed timeout is in milliseconds,
1507 * that why (t * HZ) / 1000. 1511 * that why (t * HZ) / 1000.
1508 */ 1512 */
1509 jtimeout = timeout == -1 || timeout > (MAX_SCHEDULE_TIMEOUT - 1000) / HZ ? 1513 jtimeout = (timeout < 0 || timeout >= EP_MAX_MSTIMEO) ?
1510 MAX_SCHEDULE_TIMEOUT: (timeout * HZ + 999) / 1000; 1514 MAX_SCHEDULE_TIMEOUT : (timeout * HZ + 999) / 1000;
1511 1515
1512retry: 1516retry:
1513 write_lock_irqsave(&ep->lock, flags); 1517 write_lock_irqsave(&ep->lock, flags);