aboutsummaryrefslogtreecommitdiffstats
path: root/fs/devpts
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-04-16 18:16:07 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-04-18 16:43:02 -0400
commit67245ff332064c01b760afa7a384ccda024bfd24 (patch)
treebf77d422b16306ba9fdcf2f7e1f340a409f8a0f6 /fs/devpts
parent2e572599139d27db3aaf540b0d34f0a4f58dfca1 (diff)
devpts: clean up interface to pty drivers
This gets rid of the horrible notion of having that struct inode *ptmx_inode be the linchpin of the interface between the pty code and devpts. By de-emphasizing the ptmx inode, a lot of things actually get cleaner, and we will have a much saner way forward. In particular, this will allow us to associate with any particular devpts instance at open-time, and not be artificially tied to one particular ptmx inode. The patch itself is actually fairly straightforward, and apart from some locking and return path cleanups it's pretty mechanical: - the interfaces that devpts exposes all take "struct pts_fs_info *" instead of "struct inode *ptmx_inode" now. NOTE! The "struct pts_fs_info" thing is a completely opaque structure as far as the pty driver is concerned: it's still declared entirely internally to devpts. So the pty code can't actually access it in any way, just pass it as a "cookie" to the devpts code. - the "look up the pts fs info" is now a single clear operation, that also does the reference count increment on the pts superblock. So "devpts_add/del_ref()" is gone, and replaced by a "lookup and get ref" operation (devpts_get_ref(inode)), along with a "put ref" op (devpts_put_ref()). - the pty master "tty->driver_data" field now contains the pts_fs_info, not the ptmx inode. - because we don't care about the ptmx inode any more as some kind of base index, the ref counting can now drop the inode games - it just gets the ref on the superblock. - the pts_fs_info now has a back-pointer to the super_block. That's so that we can easily look up the information we actually need. Although quite often, the pts fs info was actually all we wanted, and not having to look it up based on some magical inode makes things more straightforward. In particular, now that "devpts_get_ref(inode)" operation should really be the *only* place we need to look up what devpts instance we're associated with, and we do it exactly once, at ptmx_open() time. The other side of this is that one ptmx node could now be associated with multiple different devpts instances - you could have a single /dev/ptmx node, and then have multiple mount namespaces with their own instances of devpts mounted on /dev/pts/. And that's all perfectly sane in a model where we just look up the pts instance at open time. This will eventually allow us to get rid of our odd single-vs-multiple pts instance model, but this patch in itself changes no semantics, only an internal binding model. Cc: Eric Biederman <ebiederm@xmission.com> Cc: Peter Anvin <hpa@zytor.com> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Peter Hurley <peter@hurleysoftware.com> Cc: Serge Hallyn <serge.hallyn@ubuntu.com> Cc: Willy Tarreau <w@1wt.eu> Cc: Aurelien Jarno <aurelien@aurel32.net> Cc: Alan Cox <gnomes@lxorguk.ukuu.org.uk> Cc: Jann Horn <jann@thejh.net> Cc: Greg KH <greg@kroah.com> Cc: Jiri Slaby <jslaby@suse.com> Cc: Florian Weimer <fw@deneb.enyo.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/devpts')
-rw-r--r--fs/devpts/inode.c49
1 files changed, 24 insertions, 25 deletions
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index 655f21f99160..0af8e7d70d27 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -128,6 +128,7 @@ static const match_table_t tokens = {
128struct pts_fs_info { 128struct pts_fs_info {
129 struct ida allocated_ptys; 129 struct ida allocated_ptys;
130 struct pts_mount_opts mount_opts; 130 struct pts_mount_opts mount_opts;
131 struct super_block *sb;
131 struct dentry *ptmx_dentry; 132 struct dentry *ptmx_dentry;
132}; 133};
133 134
@@ -358,7 +359,7 @@ static const struct super_operations devpts_sops = {
358 .show_options = devpts_show_options, 359 .show_options = devpts_show_options,
359}; 360};
360 361
361static void *new_pts_fs_info(void) 362static void *new_pts_fs_info(struct super_block *sb)
362{ 363{
363 struct pts_fs_info *fsi; 364 struct pts_fs_info *fsi;
364 365
@@ -369,6 +370,7 @@ static void *new_pts_fs_info(void)
369 ida_init(&fsi->allocated_ptys); 370 ida_init(&fsi->allocated_ptys);
370 fsi->mount_opts.mode = DEVPTS_DEFAULT_MODE; 371 fsi->mount_opts.mode = DEVPTS_DEFAULT_MODE;
371 fsi->mount_opts.ptmxmode = DEVPTS_DEFAULT_PTMX_MODE; 372 fsi->mount_opts.ptmxmode = DEVPTS_DEFAULT_PTMX_MODE;
373 fsi->sb = sb;
372 374
373 return fsi; 375 return fsi;
374} 376}
@@ -384,7 +386,7 @@ devpts_fill_super(struct super_block *s, void *data, int silent)
384 s->s_op = &devpts_sops; 386 s->s_op = &devpts_sops;
385 s->s_time_gran = 1; 387 s->s_time_gran = 1;
386 388
387 s->s_fs_info = new_pts_fs_info(); 389 s->s_fs_info = new_pts_fs_info(s);
388 if (!s->s_fs_info) 390 if (!s->s_fs_info)
389 goto fail; 391 goto fail;
390 392
@@ -524,17 +526,14 @@ static struct file_system_type devpts_fs_type = {
524 * to the System V naming convention 526 * to the System V naming convention
525 */ 527 */
526 528
527int devpts_new_index(struct inode *ptmx_inode) 529int devpts_new_index(struct pts_fs_info *fsi)
528{ 530{
529 struct super_block *sb = pts_sb_from_inode(ptmx_inode);
530 struct pts_fs_info *fsi;
531 int index; 531 int index;
532 int ida_ret; 532 int ida_ret;
533 533
534 if (!sb) 534 if (!fsi)
535 return -ENODEV; 535 return -ENODEV;
536 536
537 fsi = DEVPTS_SB(sb);
538retry: 537retry:
539 if (!ida_pre_get(&fsi->allocated_ptys, GFP_KERNEL)) 538 if (!ida_pre_get(&fsi->allocated_ptys, GFP_KERNEL))
540 return -ENOMEM; 539 return -ENOMEM;
@@ -564,11 +563,8 @@ retry:
564 return index; 563 return index;
565} 564}
566 565
567void devpts_kill_index(struct inode *ptmx_inode, int idx) 566void devpts_kill_index(struct pts_fs_info *fsi, int idx)
568{ 567{
569 struct super_block *sb = pts_sb_from_inode(ptmx_inode);
570 struct pts_fs_info *fsi = DEVPTS_SB(sb);
571
572 mutex_lock(&allocated_ptys_lock); 568 mutex_lock(&allocated_ptys_lock);
573 ida_remove(&fsi->allocated_ptys, idx); 569 ida_remove(&fsi->allocated_ptys, idx);
574 pty_count--; 570 pty_count--;
@@ -578,21 +574,25 @@ void devpts_kill_index(struct inode *ptmx_inode, int idx)
578/* 574/*
579 * pty code needs to hold extra references in case of last /dev/tty close 575 * pty code needs to hold extra references in case of last /dev/tty close
580 */ 576 */
581 577struct pts_fs_info *devpts_get_ref(struct inode *ptmx_inode, struct file *file)
582void devpts_add_ref(struct inode *ptmx_inode)
583{ 578{
584 struct super_block *sb = pts_sb_from_inode(ptmx_inode); 579 struct super_block *sb;
580 struct pts_fs_info *fsi;
581
582 sb = pts_sb_from_inode(ptmx_inode);
583 if (!sb)
584 return NULL;
585 fsi = DEVPTS_SB(sb);
586 if (!fsi)
587 return NULL;
585 588
586 atomic_inc(&sb->s_active); 589 atomic_inc(&sb->s_active);
587 ihold(ptmx_inode); 590 return fsi;
588} 591}
589 592
590void devpts_del_ref(struct inode *ptmx_inode) 593void devpts_put_ref(struct pts_fs_info *fsi)
591{ 594{
592 struct super_block *sb = pts_sb_from_inode(ptmx_inode); 595 deactivate_super(fsi->sb);
593
594 iput(ptmx_inode);
595 deactivate_super(sb);
596} 596}
597 597
598/** 598/**
@@ -604,22 +604,21 @@ void devpts_del_ref(struct inode *ptmx_inode)
604 * 604 *
605 * The created inode is returned. Remove it from /dev/pts/ by devpts_pty_kill. 605 * The created inode is returned. Remove it from /dev/pts/ by devpts_pty_kill.
606 */ 606 */
607struct inode *devpts_pty_new(struct inode *ptmx_inode, dev_t device, int index, 607struct inode *devpts_pty_new(struct pts_fs_info *fsi, dev_t device, int index,
608 void *priv) 608 void *priv)
609{ 609{
610 struct dentry *dentry; 610 struct dentry *dentry;
611 struct super_block *sb = pts_sb_from_inode(ptmx_inode); 611 struct super_block *sb;
612 struct inode *inode; 612 struct inode *inode;
613 struct dentry *root; 613 struct dentry *root;
614 struct pts_fs_info *fsi;
615 struct pts_mount_opts *opts; 614 struct pts_mount_opts *opts;
616 char s[12]; 615 char s[12];
617 616
618 if (!sb) 617 if (!fsi)
619 return ERR_PTR(-ENODEV); 618 return ERR_PTR(-ENODEV);
620 619
620 sb = fsi->sb;
621 root = sb->s_root; 621 root = sb->s_root;
622 fsi = DEVPTS_SB(sb);
623 opts = &fsi->mount_opts; 622 opts = &fsi->mount_opts;
624 623
625 inode = new_inode(sb); 624 inode = new_inode(sb);