aboutsummaryrefslogtreecommitdiffstats
path: root/fs/devpts
diff options
context:
space:
mode:
authorKonstantin Khlebnikov <khlebnikov@openvz.org>2012-01-05 04:06:02 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2012-01-24 17:00:41 -0500
commita4834c102f4a46808630cad1a545cb0706b3b0a2 (patch)
tree683971bcb7796e1649b4bd9b15619d700aa9e0da /fs/devpts
parent593a27c4b212e2afdf772a1f8dcb894e91bda0fa (diff)
tty: move pty count limiting into devpts
Let's move this stuff to the better place, where we can account pty right in tty-indexes managing code. Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'fs/devpts')
-rw-r--r--fs/devpts/inode.c53
1 files changed, 52 insertions, 1 deletions
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index c4e2a58a2e82..c2c7317d5687 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -36,7 +36,52 @@
36#define DEVPTS_DEFAULT_PTMX_MODE 0000 36#define DEVPTS_DEFAULT_PTMX_MODE 0000
37#define PTMX_MINOR 2 37#define PTMX_MINOR 2
38 38
39extern int pty_limit; /* Config limit on Unix98 ptys */ 39/*
40 * sysctl support for setting limits on the number of Unix98 ptys allocated.
41 * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
42 */
43static int pty_limit = NR_UNIX98_PTY_DEFAULT;
44static int pty_limit_min;
45static int pty_limit_max = NR_UNIX98_PTY_MAX;
46static int pty_count;
47
48static struct ctl_table pty_table[] = {
49 {
50 .procname = "max",
51 .maxlen = sizeof(int),
52 .mode = 0644,
53 .data = &pty_limit,
54 .proc_handler = proc_dointvec_minmax,
55 .extra1 = &pty_limit_min,
56 .extra2 = &pty_limit_max,
57 }, {
58 .procname = "nr",
59 .maxlen = sizeof(int),
60 .mode = 0444,
61 .data = &pty_count,
62 .proc_handler = proc_dointvec,
63 },
64 {}
65};
66
67static struct ctl_table pty_kern_table[] = {
68 {
69 .procname = "pty",
70 .mode = 0555,
71 .child = pty_table,
72 },
73 {}
74};
75
76static struct ctl_table pty_root_table[] = {
77 {
78 .procname = "kernel",
79 .mode = 0555,
80 .child = pty_kern_table,
81 },
82 {}
83};
84
40static DEFINE_MUTEX(allocated_ptys_lock); 85static DEFINE_MUTEX(allocated_ptys_lock);
41 86
42static struct vfsmount *devpts_mnt; 87static struct vfsmount *devpts_mnt;
@@ -451,6 +496,7 @@ retry:
451 mutex_unlock(&allocated_ptys_lock); 496 mutex_unlock(&allocated_ptys_lock);
452 return -EIO; 497 return -EIO;
453 } 498 }
499 pty_count++;
454 mutex_unlock(&allocated_ptys_lock); 500 mutex_unlock(&allocated_ptys_lock);
455 return index; 501 return index;
456} 502}
@@ -462,6 +508,7 @@ void devpts_kill_index(struct inode *ptmx_inode, int idx)
462 508
463 mutex_lock(&allocated_ptys_lock); 509 mutex_lock(&allocated_ptys_lock);
464 ida_remove(&fsi->allocated_ptys, idx); 510 ida_remove(&fsi->allocated_ptys, idx);
511 pty_count--;
465 mutex_unlock(&allocated_ptys_lock); 512 mutex_unlock(&allocated_ptys_lock);
466} 513}
467 514
@@ -558,11 +605,15 @@ void devpts_pty_kill(struct tty_struct *tty)
558static int __init init_devpts_fs(void) 605static int __init init_devpts_fs(void)
559{ 606{
560 int err = register_filesystem(&devpts_fs_type); 607 int err = register_filesystem(&devpts_fs_type);
608 struct ctl_table_header *table;
609
561 if (!err) { 610 if (!err) {
611 table = register_sysctl_table(pty_root_table);
562 devpts_mnt = kern_mount(&devpts_fs_type); 612 devpts_mnt = kern_mount(&devpts_fs_type);
563 if (IS_ERR(devpts_mnt)) { 613 if (IS_ERR(devpts_mnt)) {
564 err = PTR_ERR(devpts_mnt); 614 err = PTR_ERR(devpts_mnt);
565 unregister_filesystem(&devpts_fs_type); 615 unregister_filesystem(&devpts_fs_type);
616 unregister_sysctl_table(table);
566 } 617 }
567 } 618 }
568 return err; 619 return err;