Skip to content

Commit 15f1a63

Browse files
Sukadev Bhattiprolutorvalds
authored andcommitted
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>
1 parent 4a2b5fd commit 15f1a63

5 files changed

Lines changed: 47 additions & 30 deletions

File tree

‎drivers/char/pty.c‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static void pty_close(struct tty_struct * tty, struct file * filp)
6060
set_bit(TTY_OTHER_CLOSED, &tty->flags);
6161
#ifdef CONFIG_UNIX98_PTYS
6262
if (tty->driver == ptm_driver)
63-
devpts_pty_kill(tty->index);
63+
devpts_pty_kill(tty->link);
6464
#endif
6565
tty_vhangup(tty->link);
6666
}
@@ -453,9 +453,10 @@ static int pty_unix98_ioctl(struct tty_struct *tty, struct file *file,
453453
* This provides our locking.
454454
*/
455455

456-
static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver, int idx)
456+
static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver,
457+
struct inode *ptm_inode, int idx)
457458
{
458-
struct tty_struct *tty = devpts_get_tty(idx);
459+
struct tty_struct *tty = devpts_get_tty(ptm_inode, idx);
459460
if (tty)
460461
tty = tty->link;
461462
return tty;
@@ -470,9 +471,10 @@ static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver, int idx)
470471
* This provides our locking.
471472
*/
472473

473-
static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver, int idx)
474+
static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver,
475+
struct inode *pts_inode, int idx)
474476
{
475-
struct tty_struct *tty = devpts_get_tty(idx);
477+
struct tty_struct *tty = devpts_get_tty(pts_inode, idx);
476478
/* Master must be open before slave */
477479
if (!tty)
478480
return ERR_PTR(-EIO);
@@ -602,7 +604,7 @@ static int __ptmx_open(struct inode *inode, struct file *filp)
602604
nonseekable_open(inode, filp);
603605

604606
/* find a device that is not in use. */
605-
index = devpts_new_index();
607+
index = devpts_new_index(inode);
606608
if (index < 0)
607609
return index;
608610

@@ -619,7 +621,7 @@ static int __ptmx_open(struct inode *inode, struct file *filp)
619621
filp->private_data = tty;
620622
file_move(filp, &tty->tty_files);
621623

622-
retval = devpts_pty_new(tty->link);
624+
retval = devpts_pty_new(inode, tty->link);
623625
if (retval)
624626
goto out1;
625627

@@ -630,7 +632,7 @@ static int __ptmx_open(struct inode *inode, struct file *filp)
630632
tty_release_dev(filp);
631633
return retval;
632634
out:
633-
devpts_kill_index(index);
635+
devpts_kill_index(inode, index);
634636
return retval;
635637
}
636638

‎drivers/char/tty_io.c‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,12 +1213,13 @@ static void tty_line_name(struct tty_driver *driver, int index, char *p)
12131213
* be held until the 'fast-open' is also done. Will change once we
12141214
* have refcounting in the driver and per driver locking
12151215
*/
1216-
struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver, int idx)
1216+
struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver,
1217+
struct inode *inode, int idx)
12171218
{
12181219
struct tty_struct *tty;
12191220

12201221
if (driver->ops->lookup)
1221-
return driver->ops->lookup(driver, idx);
1222+
return driver->ops->lookup(driver, inode, idx);
12221223

12231224
tty = driver->ttys[idx];
12241225
return tty;
@@ -1539,10 +1540,11 @@ void tty_release_dev(struct file *filp)
15391540
int devpts;
15401541
int idx;
15411542
char buf[64];
1543+
struct inode *inode;
15421544

1545+
inode = filp->f_path.dentry->d_inode;
15431546
tty = (struct tty_struct *)filp->private_data;
1544-
if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode,
1545-
"tty_release_dev"))
1547+
if (tty_paranoia_check(tty, inode, "tty_release_dev"))
15461548
return;
15471549

15481550
check_tty_count(tty, "tty_release_dev");
@@ -1751,7 +1753,7 @@ void tty_release_dev(struct file *filp)
17511753

17521754
/* Make this pty number available for reallocation */
17531755
if (devpts)
1754-
devpts_kill_index(idx);
1756+
devpts_kill_index(inode, idx);
17551757
}
17561758

17571759
/**
@@ -1836,7 +1838,7 @@ static int __tty_open(struct inode *inode, struct file *filp)
18361838
got_driver:
18371839
if (!tty) {
18381840
/* 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);
18401842

18411843
if (IS_ERR(tty))
18421844
return PTR_ERR(tty);

‎fs/devpts/inode.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static struct dentry *get_node(int num)
177177
return lookup_one_len(s, root, sprintf(s, "%d", num));
178178
}
179179

180-
int devpts_new_index(void)
180+
int devpts_new_index(struct inode *ptmx_inode)
181181
{
182182
int index;
183183
int ida_ret;
@@ -205,14 +205,14 @@ int devpts_new_index(void)
205205
return index;
206206
}
207207

208-
void devpts_kill_index(int idx)
208+
void devpts_kill_index(struct inode *ptmx_inode, int idx)
209209
{
210210
mutex_lock(&allocated_ptys_lock);
211211
ida_remove(&allocated_ptys, idx);
212212
mutex_unlock(&allocated_ptys_lock);
213213
}
214214

215-
int devpts_pty_new(struct tty_struct *tty)
215+
int devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty)
216216
{
217217
int number = tty->index; /* tty layer puts index from devpts_new_index() in here */
218218
struct tty_driver *driver = tty->driver;
@@ -245,7 +245,7 @@ int devpts_pty_new(struct tty_struct *tty)
245245
return 0;
246246
}
247247

248-
struct tty_struct *devpts_get_tty(int number)
248+
struct tty_struct *devpts_get_tty(struct inode *pts_inode, int number)
249249
{
250250
struct dentry *dentry = get_node(number);
251251
struct tty_struct *tty;
@@ -262,8 +262,9 @@ struct tty_struct *devpts_get_tty(int number)
262262
return tty;
263263
}
264264

265-
void devpts_pty_kill(int number)
265+
void devpts_pty_kill(struct tty_struct *tty)
266266
{
267+
int number = tty->index;
267268
struct dentry *dentry = get_node(number);
268269

269270
if (!IS_ERR(dentry)) {

‎include/linux/devpts_fs.h‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,31 @@
1717

1818
#ifdef CONFIG_UNIX98_PTYS
1919

20-
int devpts_new_index(void);
21-
void devpts_kill_index(int idx);
22-
int devpts_pty_new(struct tty_struct *tty); /* mknod in devpts */
23-
struct tty_struct *devpts_get_tty(int number); /* get tty structure */
24-
void devpts_pty_kill(int number); /* unlink */
20+
int devpts_new_index(struct inode *ptmx_inode);
21+
void devpts_kill_index(struct inode *ptmx_inode, int idx);
22+
/* mknod in devpts */
23+
int devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty);
24+
/* get tty structure */
25+
struct tty_struct *devpts_get_tty(struct inode *pts_inode, int number);
26+
/* unlink */
27+
void devpts_pty_kill(struct tty_struct *tty);
2528

2629
#else
2730

2831
/* Dummy stubs in the no-pty case */
29-
static inline int devpts_new_index(void) { return -EINVAL; }
30-
static inline void devpts_kill_index(int idx) { }
31-
static inline int devpts_pty_new(struct tty_struct *tty) { return -EINVAL; }
32-
static inline struct tty_struct *devpts_get_tty(int number) { return NULL; }
33-
static inline void devpts_pty_kill(int number) { }
32+
static inline int devpts_new_index(struct inode *ptmx_inode) { return -EINVAL; }
33+
static inline void devpts_kill_index(struct inode *ptmx_inode, int idx) { }
34+
static inline int devpts_pty_new(struct inode *ptmx_inode,
35+
struct tty_struct *tty)
36+
{
37+
return -EINVAL;
38+
}
39+
static inline struct tty_struct *devpts_get_tty(struct inode *pts_inode,
40+
int number)
41+
{
42+
return NULL;
43+
}
44+
static inline void devpts_pty_kill(struct tty_struct *tty) { }
3445

3546
#endif
3647

‎include/linux/tty_driver.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ struct tty_struct;
225225
struct tty_driver;
226226

227227
struct 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);
229230
int (*install)(struct tty_driver *driver, struct tty_struct *tty);
230231
void (*remove)(struct tty_driver *driver, struct tty_struct *tty);
231232
int (*open)(struct tty_struct * tty, struct file * filp);

0 commit comments

Comments
 (0)