aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSukadev Bhattiprolu <sukadev@us.ibm.com>2008-10-13 05:42:59 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-10-13 12:51:43 -0400
commit15f1a6338ddd4e69fff965d4b3a0e1bfb7a13d9c (patch)
tree301eea94cb514dc12b5070fc4b3ab33d3aab4322
parent4a2b5fddd53b80efcb3266ee36e23b8de28e761a (diff)
Add an instance parameter devpts interfaces
Pass-in 'inode' or 'tty' parameter to devpts interfaces. With multiple devpts instances, these parameters will be used in subsequent patches to identify the instance of devpts mounted. The parameters also help simplify devpts implementation. Changelog[v3]: - minor changes due to merge with ttydev updates - rename parameters to emphasize they are ptmx or pts inodes - pass-in tty_struct * to devpts_pty_kill() (this will help cleanup the get_node() call in a subsequent patch) Signed-off-by: Sukadev Bhattiprolu <sukadev@us.ibm.com> Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/char/pty.c18
-rw-r--r--drivers/char/tty_io.c14
-rw-r--r--fs/devpts/inode.c11
-rw-r--r--include/linux/devpts_fs.h31
-rw-r--r--include/linux/tty_driver.h3
5 files changed, 47 insertions, 30 deletions
diff --git a/drivers/char/pty.c b/drivers/char/pty.c
index c5a192dd00db..a391badef52a 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -60,7 +60,7 @@ static void pty_close(struct tty_struct * tty, struct file * filp)
60 set_bit(TTY_OTHER_CLOSED, &tty->flags); 60 set_bit(TTY_OTHER_CLOSED, &tty->flags);
61#ifdef CONFIG_UNIX98_PTYS 61#ifdef CONFIG_UNIX98_PTYS
62 if (tty->driver == ptm_driver) 62 if (tty->driver == ptm_driver)
63 devpts_pty_kill(tty->index); 63 devpts_pty_kill(tty->link);
64#endif 64#endif
65 tty_vhangup(tty->link); 65 tty_vhangup(tty->link);
66 } 66 }
@@ -453,9 +453,10 @@ static int pty_unix98_ioctl(struct tty_struct *tty, struct file *file,
453 * This provides our locking. 453 * This provides our locking.
454 */ 454 */
455 455
456static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver, int idx) 456static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver,
457 struct inode *ptm_inode, int idx)
457{ 458{
458 struct tty_struct *tty = devpts_get_tty(idx); 459 struct tty_struct *tty = devpts_get_tty(ptm_inode, idx);
459 if (tty) 460 if (tty)
460 tty = tty->link; 461 tty = tty->link;
461 return tty; 462 return tty;
@@ -470,9 +471,10 @@ static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver, int idx)
470 * This provides our locking. 471 * This provides our locking.
471 */ 472 */
472 473
473static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver, int idx) 474static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver,
475 struct inode *pts_inode, int idx)
474{ 476{
475 struct tty_struct *tty = devpts_get_tty(idx); 477 struct tty_struct *tty = devpts_get_tty(pts_inode, idx);
476 /* Master must be open before slave */ 478 /* Master must be open before slave */
477 if (!tty) 479 if (!tty)
478 return ERR_PTR(-EIO); 480 return ERR_PTR(-EIO);
@@ -602,7 +604,7 @@ static int __ptmx_open(struct inode *inode, struct file *filp)
602 nonseekable_open(inode, filp); 604 nonseekable_open(inode, filp);
603 605
604 /* find a device that is not in use. */ 606 /* find a device that is not in use. */
605 index = devpts_new_index(); 607 index = devpts_new_index(inode);
606 if (index < 0) 608 if (index < 0)
607 return index; 609 return index;
608 610
@@ -619,7 +621,7 @@ static int __ptmx_open(struct inode *inode, struct file *filp)
619 filp->private_data = tty; 621 filp->private_data = tty;
620 file_move(filp, &tty->tty_files); 622 file_move(filp, &tty->tty_files);
621 623
622 retval = devpts_pty_new(tty->link); 624 retval = devpts_pty_new(inode, tty->link);
623 if (retval) 625 if (retval)
624 goto out1; 626 goto out1;
625 627
@@ -630,7 +632,7 @@ out1:
630 tty_release_dev(filp); 632 tty_release_dev(filp);
631 return retval; 633 return retval;
632out: 634out:
633 devpts_kill_index(index); 635 devpts_kill_index(inode, index);
634 return retval; 636 return retval;
635} 637}
636 638
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 36098ee8fe65..959083961024 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -1213,12 +1213,13 @@ static void tty_line_name(struct tty_driver *driver, int index, char *p)
1213 * be held until the 'fast-open' is also done. Will change once we 1213 * be held until the 'fast-open' is also done. Will change once we
1214 * have refcounting in the driver and per driver locking 1214 * have refcounting in the driver and per driver locking
1215 */ 1215 */
1216struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver, int idx) 1216struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver,
1217 struct inode *inode, int idx)
1217{ 1218{
1218 struct tty_struct *tty; 1219 struct tty_struct *tty;
1219 1220
1220 if (driver->ops->lookup) 1221 if (driver->ops->lookup)
1221 return driver->ops->lookup(driver, idx); 1222 return driver->ops->lookup(driver, inode, idx);
1222 1223
1223 tty = driver->ttys[idx]; 1224 tty = driver->ttys[idx];
1224 return tty; 1225 return tty;
@@ -1539,10 +1540,11 @@ void tty_release_dev(struct file *filp)
1539 int devpts; 1540 int devpts;
1540 int idx; 1541 int idx;
1541 char buf[64]; 1542 char buf[64];
1543 struct inode *inode;
1542 1544
1545 inode = filp->f_path.dentry->d_inode;
1543 tty = (struct tty_struct *)filp->private_data; 1546 tty = (struct tty_struct *)filp->private_data;
1544 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, 1547 if (tty_paranoia_check(tty, inode, "tty_release_dev"))
1545 "tty_release_dev"))
1546 return; 1548 return;
1547 1549
1548 check_tty_count(tty, "tty_release_dev"); 1550 check_tty_count(tty, "tty_release_dev");
@@ -1751,7 +1753,7 @@ void tty_release_dev(struct file *filp)
1751 1753
1752 /* Make this pty number available for reallocation */ 1754 /* Make this pty number available for reallocation */
1753 if (devpts) 1755 if (devpts)
1754 devpts_kill_index(idx); 1756 devpts_kill_index(inode, idx);
1755} 1757}
1756 1758
1757/** 1759/**
@@ -1836,7 +1838,7 @@ retry_open:
1836got_driver: 1838got_driver:
1837 if (!tty) { 1839 if (!tty) {
1838 /* check whether we're reopening an existing tty */ 1840 /* check whether we're reopening an existing tty */
1839 tty = tty_driver_lookup_tty(driver, index); 1841 tty = tty_driver_lookup_tty(driver, inode, index);
1840 1842
1841 if (IS_ERR(tty)) 1843 if (IS_ERR(tty))
1842 return PTR_ERR(tty); 1844 return PTR_ERR(tty);
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index 488eb424f662..638db9b769ac 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -177,7 +177,7 @@ static struct dentry *get_node(int num)
177 return lookup_one_len(s, root, sprintf(s, "%d", num)); 177 return lookup_one_len(s, root, sprintf(s, "%d", num));
178} 178}
179 179
180int devpts_new_index(void) 180int devpts_new_index(struct inode *ptmx_inode)
181{ 181{
182 int index; 182 int index;
183 int ida_ret; 183 int ida_ret;
@@ -205,14 +205,14 @@ retry:
205 return index; 205 return index;
206} 206}
207 207
208void devpts_kill_index(int idx) 208void devpts_kill_index(struct inode *ptmx_inode, int idx)
209{ 209{
210 mutex_lock(&allocated_ptys_lock); 210 mutex_lock(&allocated_ptys_lock);
211 ida_remove(&allocated_ptys, idx); 211 ida_remove(&allocated_ptys, idx);
212 mutex_unlock(&allocated_ptys_lock); 212 mutex_unlock(&allocated_ptys_lock);
213} 213}
214 214
215int devpts_pty_new(struct tty_struct *tty) 215int devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty)
216{ 216{
217 int number = tty->index; /* tty layer puts index from devpts_new_index() in here */ 217 int number = tty->index; /* tty layer puts index from devpts_new_index() in here */
218 struct tty_driver *driver = tty->driver; 218 struct tty_driver *driver = tty->driver;
@@ -245,7 +245,7 @@ int devpts_pty_new(struct tty_struct *tty)
245 return 0; 245 return 0;
246} 246}
247 247
248struct tty_struct *devpts_get_tty(int number) 248struct tty_struct *devpts_get_tty(struct inode *pts_inode, int number)
249{ 249{
250 struct dentry *dentry = get_node(number); 250 struct dentry *dentry = get_node(number);
251 struct tty_struct *tty; 251 struct tty_struct *tty;
@@ -262,8 +262,9 @@ struct tty_struct *devpts_get_tty(int number)
262 return tty; 262 return tty;
263} 263}
264 264
265void devpts_pty_kill(int number) 265void devpts_pty_kill(struct tty_struct *tty)
266{ 266{
267 int number = tty->index;
267 struct dentry *dentry = get_node(number); 268 struct dentry *dentry = get_node(number);
268 269
269 if (!IS_ERR(dentry)) { 270 if (!IS_ERR(dentry)) {
diff --git a/include/linux/devpts_fs.h b/include/linux/devpts_fs.h
index 154769cad3f3..5ce0e5fd712e 100644
--- a/include/linux/devpts_fs.h
+++ b/include/linux/devpts_fs.h
@@ -17,20 +17,31 @@
17 17
18#ifdef CONFIG_UNIX98_PTYS 18#ifdef CONFIG_UNIX98_PTYS
19 19
20int devpts_new_index(void); 20int devpts_new_index(struct inode *ptmx_inode);
21void devpts_kill_index(int idx); 21void devpts_kill_index(struct inode *ptmx_inode, int idx);
22int devpts_pty_new(struct tty_struct *tty); /* mknod in devpts */ 22/* mknod in devpts */
23struct tty_struct *devpts_get_tty(int number); /* get tty structure */ 23int devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty);
24void devpts_pty_kill(int number); /* unlink */ 24/* get tty structure */
25struct tty_struct *devpts_get_tty(struct inode *pts_inode, int number);
26/* unlink */
27void devpts_pty_kill(struct tty_struct *tty);
25 28
26#else 29#else
27 30
28/* Dummy stubs in the no-pty case */ 31/* Dummy stubs in the no-pty case */
29static inline int devpts_new_index(void) { return -EINVAL; } 32static inline int devpts_new_index(struct inode *ptmx_inode) { return -EINVAL; }
30static inline void devpts_kill_index(int idx) { } 33static inline void devpts_kill_index(struct inode *ptmx_inode, int idx) { }
31static inline int devpts_pty_new(struct tty_struct *tty) { return -EINVAL; } 34static inline int devpts_pty_new(struct inode *ptmx_inode,
32static inline struct tty_struct *devpts_get_tty(int number) { return NULL; } 35 struct tty_struct *tty)
33static inline void devpts_pty_kill(int number) { } 36{
37 return -EINVAL;
38}
39static inline struct tty_struct *devpts_get_tty(struct inode *pts_inode,
40 int number)
41{
42 return NULL;
43}
44static inline void devpts_pty_kill(struct tty_struct *tty) { }
34 45
35#endif 46#endif
36 47
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
index 005d06ad46a6..78416b901589 100644
--- a/include/linux/tty_driver.h
+++ b/include/linux/tty_driver.h
@@ -225,7 +225,8 @@ struct tty_struct;
225struct tty_driver; 225struct tty_driver;
226 226
227struct tty_operations { 227struct tty_operations {
228 struct tty_struct * (*lookup)(struct tty_driver *driver, int idx); 228 struct tty_struct * (*lookup)(struct tty_driver *driver,
229 struct inode *inode, int idx);
229 int (*install)(struct tty_driver *driver, struct tty_struct *tty); 230 int (*install)(struct tty_driver *driver, struct tty_struct *tty);
230 void (*remove)(struct tty_driver *driver, struct tty_struct *tty); 231 void (*remove)(struct tty_driver *driver, struct tty_struct *tty);
231 int (*open)(struct tty_struct * tty, struct file * filp); 232 int (*open)(struct tty_struct * tty, struct file * filp);