Commit 15f1a633 authored by Sukadev Bhattiprolu's avatar Sukadev Bhattiprolu Committed by Linus Torvalds

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: default avatarSukadev Bhattiprolu <sukadev@us.ibm.com>
Signed-off-by: default avatarAlan Cox <alan@redhat.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 4a2b5fdd
...@@ -60,7 +60,7 @@ static void pty_close(struct tty_struct * tty, struct file * filp) ...@@ -60,7 +60,7 @@ static void pty_close(struct tty_struct * tty, struct file * filp)
set_bit(TTY_OTHER_CLOSED, &tty->flags); set_bit(TTY_OTHER_CLOSED, &tty->flags);
#ifdef CONFIG_UNIX98_PTYS #ifdef CONFIG_UNIX98_PTYS
if (tty->driver == ptm_driver) if (tty->driver == ptm_driver)
devpts_pty_kill(tty->index); devpts_pty_kill(tty->link);
#endif #endif
tty_vhangup(tty->link); tty_vhangup(tty->link);
} }
...@@ -453,9 +453,10 @@ static int pty_unix98_ioctl(struct tty_struct *tty, struct file *file, ...@@ -453,9 +453,10 @@ static int pty_unix98_ioctl(struct tty_struct *tty, struct file *file,
* This provides our locking. * This provides our locking.
*/ */
static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver, int idx) static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver,
struct inode *ptm_inode, int idx)
{ {
struct tty_struct *tty = devpts_get_tty(idx); struct tty_struct *tty = devpts_get_tty(ptm_inode, idx);
if (tty) if (tty)
tty = tty->link; tty = tty->link;
return tty; return tty;
...@@ -470,9 +471,10 @@ static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver, int idx) ...@@ -470,9 +471,10 @@ static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver, int idx)
* This provides our locking. * This provides our locking.
*/ */
static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver, int idx) static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver,
struct inode *pts_inode, int idx)
{ {
struct tty_struct *tty = devpts_get_tty(idx); struct tty_struct *tty = devpts_get_tty(pts_inode, idx);
/* Master must be open before slave */ /* Master must be open before slave */
if (!tty) if (!tty)
return ERR_PTR(-EIO); return ERR_PTR(-EIO);
...@@ -602,7 +604,7 @@ static int __ptmx_open(struct inode *inode, struct file *filp) ...@@ -602,7 +604,7 @@ static int __ptmx_open(struct inode *inode, struct file *filp)
nonseekable_open(inode, filp); nonseekable_open(inode, filp);
/* find a device that is not in use. */ /* find a device that is not in use. */
index = devpts_new_index(); index = devpts_new_index(inode);
if (index < 0) if (index < 0)
return index; return index;
...@@ -619,7 +621,7 @@ static int __ptmx_open(struct inode *inode, struct file *filp) ...@@ -619,7 +621,7 @@ static int __ptmx_open(struct inode *inode, struct file *filp)
filp->private_data = tty; filp->private_data = tty;
file_move(filp, &tty->tty_files); file_move(filp, &tty->tty_files);
retval = devpts_pty_new(tty->link); retval = devpts_pty_new(inode, tty->link);
if (retval) if (retval)
goto out1; goto out1;
...@@ -630,7 +632,7 @@ static int __ptmx_open(struct inode *inode, struct file *filp) ...@@ -630,7 +632,7 @@ static int __ptmx_open(struct inode *inode, struct file *filp)
tty_release_dev(filp); tty_release_dev(filp);
return retval; return retval;
out: out:
devpts_kill_index(index); devpts_kill_index(inode, index);
return retval; return retval;
} }
......
...@@ -1213,12 +1213,13 @@ static void tty_line_name(struct tty_driver *driver, int index, char *p) ...@@ -1213,12 +1213,13 @@ static void tty_line_name(struct tty_driver *driver, int index, char *p)
* be held until the 'fast-open' is also done. Will change once we * be held until the 'fast-open' is also done. Will change once we
* have refcounting in the driver and per driver locking * have refcounting in the driver and per driver locking
*/ */
struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver, int idx) struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver,
struct inode *inode, int idx)
{ {
struct tty_struct *tty; struct tty_struct *tty;
if (driver->ops->lookup) if (driver->ops->lookup)
return driver->ops->lookup(driver, idx); return driver->ops->lookup(driver, inode, idx);
tty = driver->ttys[idx]; tty = driver->ttys[idx];
return tty; return tty;
...@@ -1539,10 +1540,11 @@ void tty_release_dev(struct file *filp) ...@@ -1539,10 +1540,11 @@ void tty_release_dev(struct file *filp)
int devpts; int devpts;
int idx; int idx;
char buf[64]; char buf[64];
struct inode *inode;
inode = filp->f_path.dentry->d_inode;
tty = (struct tty_struct *)filp->private_data; tty = (struct tty_struct *)filp->private_data;
if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, if (tty_paranoia_check(tty, inode, "tty_release_dev"))
"tty_release_dev"))
return; return;
check_tty_count(tty, "tty_release_dev"); check_tty_count(tty, "tty_release_dev");
...@@ -1751,7 +1753,7 @@ void tty_release_dev(struct file *filp) ...@@ -1751,7 +1753,7 @@ void tty_release_dev(struct file *filp)
/* Make this pty number available for reallocation */ /* Make this pty number available for reallocation */
if (devpts) if (devpts)
devpts_kill_index(idx); devpts_kill_index(inode, idx);
} }
/** /**
...@@ -1836,7 +1838,7 @@ static int __tty_open(struct inode *inode, struct file *filp) ...@@ -1836,7 +1838,7 @@ static int __tty_open(struct inode *inode, struct file *filp)
got_driver: got_driver:
if (!tty) { if (!tty) {
/* check whether we're reopening an existing tty */ /* check whether we're reopening an existing tty */
tty = tty_driver_lookup_tty(driver, index); tty = tty_driver_lookup_tty(driver, inode, index);
if (IS_ERR(tty)) if (IS_ERR(tty))
return PTR_ERR(tty); return PTR_ERR(tty);
......
...@@ -177,7 +177,7 @@ static struct dentry *get_node(int num) ...@@ -177,7 +177,7 @@ static struct dentry *get_node(int num)
return lookup_one_len(s, root, sprintf(s, "%d", num)); return lookup_one_len(s, root, sprintf(s, "%d", num));
} }
int devpts_new_index(void) int devpts_new_index(struct inode *ptmx_inode)
{ {
int index; int index;
int ida_ret; int ida_ret;
...@@ -205,14 +205,14 @@ int devpts_new_index(void) ...@@ -205,14 +205,14 @@ int devpts_new_index(void)
return index; return index;
} }
void devpts_kill_index(int idx) void devpts_kill_index(struct inode *ptmx_inode, int idx)
{ {
mutex_lock(&allocated_ptys_lock); mutex_lock(&allocated_ptys_lock);
ida_remove(&allocated_ptys, idx); ida_remove(&allocated_ptys, idx);
mutex_unlock(&allocated_ptys_lock); mutex_unlock(&allocated_ptys_lock);
} }
int devpts_pty_new(struct tty_struct *tty) int devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty)
{ {
int number = tty->index; /* tty layer puts index from devpts_new_index() in here */ int number = tty->index; /* tty layer puts index from devpts_new_index() in here */
struct tty_driver *driver = tty->driver; struct tty_driver *driver = tty->driver;
...@@ -245,7 +245,7 @@ int devpts_pty_new(struct tty_struct *tty) ...@@ -245,7 +245,7 @@ int devpts_pty_new(struct tty_struct *tty)
return 0; return 0;
} }
struct tty_struct *devpts_get_tty(int number) struct tty_struct *devpts_get_tty(struct inode *pts_inode, int number)
{ {
struct dentry *dentry = get_node(number); struct dentry *dentry = get_node(number);
struct tty_struct *tty; struct tty_struct *tty;
...@@ -262,8 +262,9 @@ struct tty_struct *devpts_get_tty(int number) ...@@ -262,8 +262,9 @@ struct tty_struct *devpts_get_tty(int number)
return tty; return tty;
} }
void devpts_pty_kill(int number) void devpts_pty_kill(struct tty_struct *tty)
{ {
int number = tty->index;
struct dentry *dentry = get_node(number); struct dentry *dentry = get_node(number);
if (!IS_ERR(dentry)) { if (!IS_ERR(dentry)) {
......
...@@ -17,20 +17,31 @@ ...@@ -17,20 +17,31 @@
#ifdef CONFIG_UNIX98_PTYS #ifdef CONFIG_UNIX98_PTYS
int devpts_new_index(void); int devpts_new_index(struct inode *ptmx_inode);
void devpts_kill_index(int idx); void devpts_kill_index(struct inode *ptmx_inode, int idx);
int devpts_pty_new(struct tty_struct *tty); /* mknod in devpts */ /* mknod in devpts */
struct tty_struct *devpts_get_tty(int number); /* get tty structure */ int devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty);
void devpts_pty_kill(int number); /* unlink */ /* get tty structure */
struct tty_struct *devpts_get_tty(struct inode *pts_inode, int number);
/* unlink */
void devpts_pty_kill(struct tty_struct *tty);
#else #else
/* Dummy stubs in the no-pty case */ /* Dummy stubs in the no-pty case */
static inline int devpts_new_index(void) { return -EINVAL; } static inline int devpts_new_index(struct inode *ptmx_inode) { return -EINVAL; }
static inline void devpts_kill_index(int idx) { } static inline void devpts_kill_index(struct inode *ptmx_inode, int idx) { }
static inline int devpts_pty_new(struct tty_struct *tty) { return -EINVAL; } static inline int devpts_pty_new(struct inode *ptmx_inode,
static inline struct tty_struct *devpts_get_tty(int number) { return NULL; } struct tty_struct *tty)
static inline void devpts_pty_kill(int number) { } {
return -EINVAL;
}
static inline struct tty_struct *devpts_get_tty(struct inode *pts_inode,
int number)
{
return NULL;
}
static inline void devpts_pty_kill(struct tty_struct *tty) { }
#endif #endif
......
...@@ -225,7 +225,8 @@ struct tty_struct; ...@@ -225,7 +225,8 @@ struct tty_struct;
struct tty_driver; struct tty_driver;
struct tty_operations { struct tty_operations {
struct tty_struct * (*lookup)(struct tty_driver *driver, int idx); struct tty_struct * (*lookup)(struct tty_driver *driver,
struct inode *inode, int idx);
int (*install)(struct tty_driver *driver, struct tty_struct *tty); int (*install)(struct tty_driver *driver, struct tty_struct *tty);
void (*remove)(struct tty_driver *driver, struct tty_struct *tty); void (*remove)(struct tty_driver *driver, struct tty_struct *tty);
int (*open)(struct tty_struct * tty, struct file * filp); int (*open)(struct tty_struct * tty, struct file * filp);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment