aboutsummaryrefslogtreecommitdiffstats
path: root/fs/devpts
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-04-25 23:04:08 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-04-26 18:47:32 -0400
commit8ead9dd54716d1e05e129959f702fcc1786f82b4 (patch)
treea31bb92dab97a482390b515e91fd29e80b3a3004 /fs/devpts
parentbcc981e9ed84c678533299d7eff17d2c81e4d5de (diff)
devpts: more pty driver interface cleanups
This is more prep-work for the upcoming pty changes. Still just code cleanup with no actual semantic changes. This removes a bunch pointless complexity by just having the slave pty side remember the dentry associated with the devpts slave rather than the inode. That allows us to remove all the "look up the dentry" code for when we want to remove it again. Together with moving the tty pointer from "inode->i_private" to "dentry->d_fsdata" and getting rid of pointless inode locking, this removes about 30 lines of code. Not only is the end result smaller, it's simpler and easier to understand. The old code, for example, depended on the d_find_alias() to not just find the dentry, but also to check that it is still hashed, which in turn validated the tty pointer in the inode. That is a _very_ roundabout way to say "invalidate the cached tty pointer when the dentry is removed". The new code just does dentry->d_fsdata = NULL; in devpts_pty_kill() instead, invalidating the tty pointer rather more directly and obviously. Don't do something complex and subtle when the obvious straightforward approach will do. The rest of the patch (ie apart from code deletion and the above tty pointer clearing) is just switching the calling convention to pass the dentry or file pointer around instead of the inode. 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.c53
1 files changed, 12 insertions, 41 deletions
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index 0af8e7d70d27..0b2954d7172d 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -604,8 +604,7 @@ void devpts_put_ref(struct pts_fs_info *fsi)
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 pts_fs_info *fsi, dev_t device, int index, 607struct dentry *devpts_pty_new(struct pts_fs_info *fsi, int index, void *priv)
608 void *priv)
609{ 608{
610 struct dentry *dentry; 609 struct dentry *dentry;
611 struct super_block *sb; 610 struct super_block *sb;
@@ -629,25 +628,21 @@ struct inode *devpts_pty_new(struct pts_fs_info *fsi, dev_t device, int index,
629 inode->i_uid = opts->setuid ? opts->uid : current_fsuid(); 628 inode->i_uid = opts->setuid ? opts->uid : current_fsuid();
630 inode->i_gid = opts->setgid ? opts->gid : current_fsgid(); 629 inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
631 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; 630 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
632 init_special_inode(inode, S_IFCHR|opts->mode, device); 631 init_special_inode(inode, S_IFCHR|opts->mode, MKDEV(UNIX98_PTY_SLAVE_MAJOR, index));
633 inode->i_private = priv;
634 632
635 sprintf(s, "%d", index); 633 sprintf(s, "%d", index);
636 634
637 inode_lock(d_inode(root));
638
639 dentry = d_alloc_name(root, s); 635 dentry = d_alloc_name(root, s);
640 if (dentry) { 636 if (dentry) {
637 dentry->d_fsdata = priv;
641 d_add(dentry, inode); 638 d_add(dentry, inode);
642 fsnotify_create(d_inode(root), dentry); 639 fsnotify_create(d_inode(root), dentry);
643 } else { 640 } else {
644 iput(inode); 641 iput(inode);
645 inode = ERR_PTR(-ENOMEM); 642 dentry = ERR_PTR(-ENOMEM);
646 } 643 }
647 644
648 inode_unlock(d_inode(root)); 645 return dentry;
649
650 return inode;
651} 646}
652 647
653/** 648/**
@@ -656,24 +651,10 @@ struct inode *devpts_pty_new(struct pts_fs_info *fsi, dev_t device, int index,
656 * 651 *
657 * Returns whatever was passed as priv in devpts_pty_new for a given inode. 652 * Returns whatever was passed as priv in devpts_pty_new for a given inode.
658 */ 653 */
659void *devpts_get_priv(struct inode *pts_inode) 654void *devpts_get_priv(struct dentry *dentry)
660{ 655{
661 struct dentry *dentry; 656 WARN_ON_ONCE(dentry->d_sb->s_magic != DEVPTS_SUPER_MAGIC);
662 void *priv = NULL; 657 return dentry->d_fsdata;
663
664 BUG_ON(pts_inode->i_rdev == MKDEV(TTYAUX_MAJOR, PTMX_MINOR));
665
666 /* Ensure dentry has not been deleted by devpts_pty_kill() */
667 dentry = d_find_alias(pts_inode);
668 if (!dentry)
669 return NULL;
670
671 if (pts_inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC)
672 priv = pts_inode->i_private;
673
674 dput(dentry);
675
676 return priv;
677} 658}
678 659
679/** 660/**
@@ -682,24 +663,14 @@ void *devpts_get_priv(struct inode *pts_inode)
682 * 663 *
683 * This is an inverse operation of devpts_pty_new. 664 * This is an inverse operation of devpts_pty_new.
684 */ 665 */
685void devpts_pty_kill(struct inode *inode) 666void devpts_pty_kill(struct dentry *dentry)
686{ 667{
687 struct super_block *sb = pts_sb_from_inode(inode); 668 WARN_ON_ONCE(dentry->d_sb->s_magic != DEVPTS_SUPER_MAGIC);
688 struct dentry *root = sb->s_root;
689 struct dentry *dentry;
690 669
691 BUG_ON(inode->i_rdev == MKDEV(TTYAUX_MAJOR, PTMX_MINOR)); 670 dentry->d_fsdata = NULL;
692 671 drop_nlink(dentry->d_inode);
693 inode_lock(d_inode(root));
694
695 dentry = d_find_alias(inode);
696
697 drop_nlink(inode);
698 d_delete(dentry); 672 d_delete(dentry);
699 dput(dentry); /* d_alloc_name() in devpts_pty_new() */ 673 dput(dentry); /* d_alloc_name() in devpts_pty_new() */
700 dput(dentry); /* d_find_alias above */
701
702 inode_unlock(d_inode(root));
703} 674}
704 675
705static int __init init_devpts_fs(void) 676static int __init init_devpts_fs(void)