Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] kill altroot

long overdue...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro 7f2da1e7 8bb79224

+5 -466
+2 -87
fs/namei.c
··· 31 31 #include <linux/file.h> 32 32 #include <linux/fcntl.h> 33 33 #include <linux/device_cgroup.h> 34 - #include <asm/namei.h> 35 34 #include <asm/uaccess.h> 36 35 37 36 #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE]) ··· 561 562 return result; 562 563 } 563 564 564 - static int __emul_lookup_dentry(const char *, struct nameidata *); 565 - 566 565 /* SMP-safe */ 567 - static __always_inline int 566 + static __always_inline void 568 567 walk_init_root(const char *name, struct nameidata *nd) 569 568 { 570 569 struct fs_struct *fs = current->fs; 571 570 572 571 read_lock(&fs->lock); 573 - if (fs->altroot.dentry && !(nd->flags & LOOKUP_NOALT)) { 574 - nd->path = fs->altroot; 575 - path_get(&fs->altroot); 576 - read_unlock(&fs->lock); 577 - if (__emul_lookup_dentry(name,nd)) 578 - return 0; 579 - read_lock(&fs->lock); 580 - } 581 572 nd->path = fs->root; 582 573 path_get(&fs->root); 583 574 read_unlock(&fs->lock); 584 - return 1; 585 575 } 586 576 587 577 /* ··· 611 623 612 624 if (*link == '/') { 613 625 path_put(&nd->path); 614 - if (!walk_init_root(link, nd)) 615 - /* weird __emul_prefix() stuff did it */ 616 - goto out; 626 + walk_init_root(link, nd); 617 627 } 618 628 res = link_path_walk(link, nd); 619 - out: 620 629 if (nd->depth || res || nd->last_type!=LAST_NORM) 621 630 return res; 622 631 /* ··· 1062 1077 return link_path_walk(name, nd); 1063 1078 } 1064 1079 1065 - /* 1066 - * SMP-safe: Returns 1 and nd will have valid dentry and mnt, if 1067 - * everything is done. Returns 0 and drops input nd, if lookup failed; 1068 - */ 1069 - static int __emul_lookup_dentry(const char *name, struct nameidata *nd) 1070 - { 1071 - if (path_walk(name, nd)) 1072 - return 0; /* something went wrong... */ 1073 - 1074 - if (!nd->path.dentry->d_inode || 1075 - S_ISDIR(nd->path.dentry->d_inode->i_mode)) { 1076 - struct path old_path = nd->path; 1077 - struct qstr last = nd->last; 1078 - int last_type = nd->last_type; 1079 - struct fs_struct *fs = current->fs; 1080 - 1081 - /* 1082 - * NAME was not found in alternate root or it's a directory. 1083 - * Try to find it in the normal root: 1084 - */ 1085 - nd->last_type = LAST_ROOT; 1086 - read_lock(&fs->lock); 1087 - nd->path = fs->root; 1088 - path_get(&fs->root); 1089 - read_unlock(&fs->lock); 1090 - if (path_walk(name, nd) == 0) { 1091 - if (nd->path.dentry->d_inode) { 1092 - path_put(&old_path); 1093 - return 1; 1094 - } 1095 - path_put(&nd->path); 1096 - } 1097 - nd->path = old_path; 1098 - nd->last = last; 1099 - nd->last_type = last_type; 1100 - } 1101 - return 1; 1102 - } 1103 - 1104 - void set_fs_altroot(void) 1105 - { 1106 - char *emul = __emul_prefix(); 1107 - struct nameidata nd; 1108 - struct path path = {}, old_path; 1109 - int err; 1110 - struct fs_struct *fs = current->fs; 1111 - 1112 - if (!emul) 1113 - goto set_it; 1114 - err = path_lookup(emul, LOOKUP_FOLLOW|LOOKUP_DIRECTORY|LOOKUP_NOALT, &nd); 1115 - if (!err) 1116 - path = nd.path; 1117 - set_it: 1118 - write_lock(&fs->lock); 1119 - old_path = fs->altroot; 1120 - fs->altroot = path; 1121 - write_unlock(&fs->lock); 1122 - if (old_path.dentry) 1123 - path_put(&old_path); 1124 - } 1125 - 1126 1080 /* Returns 0 and nd will be valid on success; Retuns error, otherwise. */ 1127 1081 static int do_path_lookup(int dfd, const char *name, 1128 1082 unsigned int flags, struct nameidata *nd) ··· 1077 1153 1078 1154 if (*name=='/') { 1079 1155 read_lock(&fs->lock); 1080 - if (fs->altroot.dentry && !(nd->flags & LOOKUP_NOALT)) { 1081 - nd->path = fs->altroot; 1082 - path_get(&fs->altroot); 1083 - read_unlock(&fs->lock); 1084 - if (__emul_lookup_dentry(name,nd)) 1085 - goto out; /* found in altroot */ 1086 - read_lock(&fs->lock); 1087 - } 1088 1156 nd->path = fs->root; 1089 1157 path_get(&fs->root); 1090 1158 read_unlock(&fs->lock); ··· 1110 1194 } 1111 1195 1112 1196 retval = path_walk(name, nd); 1113 - out: 1114 1197 if (unlikely(!retval && !audit_dummy_context() && nd->path.dentry && 1115 1198 nd->path.dentry->d_inode)) 1116 1199 audit_inode(name, nd->path.dentry);
+1 -7
fs/namespace.c
··· 1972 1972 struct fs_struct *fs) 1973 1973 { 1974 1974 struct mnt_namespace *new_ns; 1975 - struct vfsmount *rootmnt = NULL, *pwdmnt = NULL, *altrootmnt = NULL; 1975 + struct vfsmount *rootmnt = NULL, *pwdmnt = NULL; 1976 1976 struct vfsmount *p, *q; 1977 1977 1978 1978 new_ns = kmalloc(sizeof(struct mnt_namespace), GFP_KERNEL); ··· 2015 2015 pwdmnt = p; 2016 2016 fs->pwd.mnt = mntget(q); 2017 2017 } 2018 - if (p == fs->altroot.mnt) { 2019 - altrootmnt = p; 2020 - fs->altroot.mnt = mntget(q); 2021 - } 2022 2018 } 2023 2019 p = next_mnt(p, mnt_ns->root); 2024 2020 q = next_mnt(q, new_ns->root); ··· 2025 2029 mntput(rootmnt); 2026 2030 if (pwdmnt) 2027 2031 mntput(pwdmnt); 2028 - if (altrootmnt) 2029 - mntput(altrootmnt); 2030 2032 2031 2033 return new_ns; 2032 2034 }
+1 -2
fs/open.c
··· 548 548 struct nameidata nd; 549 549 int error; 550 550 551 - error = __user_walk(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY | LOOKUP_NOALT, &nd); 551 + error = __user_walk(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &nd); 552 552 if (error) 553 553 goto out; 554 554 ··· 561 561 goto dput_and_out; 562 562 563 563 set_fs_root(current->fs, &nd.path); 564 - set_fs_altroot(); 565 564 error = 0; 566 565 dput_and_out: 567 566 path_put(&nd.path);
-17
include/asm-alpha/namei.h
··· 1 - /* $Id: namei.h,v 1.1 1996/12/13 14:48:21 jj Exp $ 2 - * linux/include/asm-alpha/namei.h 3 - * 4 - * Included from linux/fs/namei.c 5 - */ 6 - 7 - #ifndef __ALPHA_NAMEI_H 8 - #define __ALPHA_NAMEI_H 9 - 10 - /* This dummy routine maybe changed to something useful 11 - * for /usr/gnemul/ emulation stuff. 12 - * Look at asm-sparc/namei.h for details. 13 - */ 14 - 15 - #define __emul_prefix() NULL 16 - 17 - #endif /* __ALPHA_NAMEI_H */
-25
include/asm-arm/namei.h
··· 1 - /* 2 - * linux/include/asm-arm/namei.h 3 - * 4 - * Routines to handle famous /usr/gnemul 5 - * Derived from the Sparc version of this file 6 - * 7 - * Included from linux/fs/namei.c 8 - */ 9 - 10 - #ifndef __ASMARM_NAMEI_H 11 - #define __ASMARM_NAMEI_H 12 - 13 - #define ARM_BSD_EMUL "usr/gnemul/bsd/" 14 - 15 - static inline char *__emul_prefix(void) 16 - { 17 - switch (current->personality) { 18 - case PER_BSD: 19 - return ARM_BSD_EMUL; 20 - default: 21 - return NULL; 22 - } 23 - } 24 - 25 - #endif /* __ASMARM_NAMEI_H */
-7
include/asm-avr32/namei.h
··· 1 - #ifndef __ASM_AVR32_NAMEI_H 2 - #define __ASM_AVR32_NAMEI_H 3 - 4 - /* This dummy routine may be changed to something useful */ 5 - #define __emul_prefix() NULL 6 - 7 - #endif /* __ASM_AVR32_NAMEI_H */
-19
include/asm-blackfin/namei.h
··· 1 - /* 2 - * linux/include/asm/namei.h 3 - * 4 - * Included from linux/fs/namei.c 5 - * 6 - * Changes made by Lineo Inc. May 2001 7 - */ 8 - 9 - #ifndef __BFIN_NAMEI_H 10 - #define __BFIN_NAMEI_H 11 - 12 - /* This dummy routine maybe changed to something useful 13 - * for /usr/gnemul/ emulation stuff. 14 - * Look at asm-sparc/namei.h for details. 15 - */ 16 - 17 - #define __emul_prefix() NULL 18 - 19 - #endif
-17
include/asm-cris/namei.h
··· 1 - /* $Id: namei.h,v 1.1 2000/07/10 16:32:31 bjornw Exp $ 2 - * linux/include/asm-cris/namei.h 3 - * 4 - * Included from linux/fs/namei.c 5 - */ 6 - 7 - #ifndef __CRIS_NAMEI_H 8 - #define __CRIS_NAMEI_H 9 - 10 - /* used to find file-system prefixes for doing emulations 11 - * see for example asm-sparc/namei.h 12 - * we don't use it... 13 - */ 14 - 15 - #define __emul_prefix() NULL 16 - 17 - #endif /* __CRIS_NAMEI_H */
-18
include/asm-frv/namei.h
··· 1 - /* 2 - * include/asm-frv/namei.h 3 - * 4 - * Included from linux/fs/namei.c 5 - */ 6 - 7 - #ifndef __ASM_NAMEI_H 8 - #define __ASM_NAMEI_H 9 - 10 - /* This dummy routine maybe changed to something useful 11 - * for /usr/gnemul/ emulation stuff. 12 - * Look at asm-sparc/namei.h for details. 13 - */ 14 - 15 - #define __emul_prefix() NULL 16 - 17 - #endif 18 -
-17
include/asm-h8300/namei.h
··· 1 - /* 2 - * linux/include/asm-h8300/namei.h 3 - * 4 - * Included from linux/fs/namei.c 5 - */ 6 - 7 - #ifndef __H8300_NAMEI_H 8 - #define __H8300_NAMEI_H 9 - 10 - /* This dummy routine maybe changed to something useful 11 - * for /usr/gnemul/ emulation stuff. 12 - * Look at asm-sparc/namei.h for details. 13 - */ 14 - 15 - #define __emul_prefix() NULL 16 - 17 - #endif
-25
include/asm-ia64/namei.h
··· 1 - #ifndef _ASM_IA64_NAMEI_H 2 - #define _ASM_IA64_NAMEI_H 3 - 4 - /* 5 - * Modified 1998, 1999, 2001 6 - * David Mosberger-Tang <davidm@hpl.hp.com>, Hewlett-Packard Co 7 - */ 8 - 9 - #include <asm/ptrace.h> 10 - #include <asm/system.h> 11 - 12 - #define EMUL_PREFIX_LINUX_IA32 "/emul/ia32-linux/" 13 - 14 - static inline char * 15 - __emul_prefix (void) 16 - { 17 - switch (current->personality) { 18 - case PER_LINUX32: 19 - return EMUL_PREFIX_LINUX_IA32; 20 - default: 21 - return NULL; 22 - } 23 - } 24 - 25 - #endif /* _ASM_IA64_NAMEI_H */
-17
include/asm-m32r/namei.h
··· 1 - #ifndef _ASM_M32R_NAMEI_H 2 - #define _ASM_M32R_NAMEI_H 3 - 4 - /* 5 - * linux/include/asm-m32r/namei.h 6 - * 7 - * Included from linux/fs/namei.c 8 - */ 9 - 10 - /* This dummy routine maybe changed to something useful 11 - * for /usr/gnemul/ emulation stuff. 12 - * Look at asm-sparc/namei.h for details. 13 - */ 14 - 15 - #define __emul_prefix() NULL 16 - 17 - #endif /* _ASM_M32R_NAMEI_H */
-17
include/asm-m68k/namei.h
··· 1 - /* 2 - * linux/include/asm-m68k/namei.h 3 - * 4 - * Included from linux/fs/namei.c 5 - */ 6 - 7 - #ifndef __M68K_NAMEI_H 8 - #define __M68K_NAMEI_H 9 - 10 - /* This dummy routine maybe changed to something useful 11 - * for /usr/gnemul/ emulation stuff. 12 - * Look at asm-sparc/namei.h for details. 13 - */ 14 - 15 - #define __emul_prefix() NULL 16 - 17 - #endif
-1
include/asm-m68knommu/namei.h
··· 1 - #include <asm-m68k/namei.h>
-11
include/asm-mips/namei.h
··· 1 - #ifndef _ASM_NAMEI_H 2 - #define _ASM_NAMEI_H 3 - 4 - /* 5 - * This dummy routine maybe changed to something useful 6 - * for /usr/gnemul/ emulation stuff. 7 - */ 8 - 9 - #define __emul_prefix() NULL 10 - 11 - #endif /* _ASM_NAMEI_H */
-22
include/asm-mn10300/namei.h
··· 1 - /* Emulation stuff 2 - * 3 - * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. 4 - * Written by David Howells (dhowells@redhat.com) 5 - * 6 - * This program is free software; you can redistribute it and/or 7 - * modify it under the terms of the GNU General Public Licence 8 - * as published by the Free Software Foundation; either version 9 - * 2 of the Licence, or (at your option) any later version. 10 - */ 11 - 12 - #ifndef _ASM_NAMEI_H 13 - #define _ASM_NAMEI_H 14 - 15 - /* This dummy routine maybe changed to something useful 16 - * for /usr/gnemul/ emulation stuff. 17 - * Look at asm-sparc/namei.h for details. 18 - */ 19 - 20 - #define __emul_prefix() NULL 21 - 22 - #endif /* _ASM_NAMEI_H */
-17
include/asm-parisc/namei.h
··· 1 - /* $Id: namei.h,v 1.1 1996/12/13 14:48:21 jj Exp $ 2 - * linux/include/asm-parisc/namei.h 3 - * 4 - * Included from linux/fs/namei.c 5 - */ 6 - 7 - #ifndef __PARISC_NAMEI_H 8 - #define __PARISC_NAMEI_H 9 - 10 - /* This dummy routine maybe changed to something useful 11 - * for /usr/gnemul/ emulation stuff. 12 - * Look at asm-sparc/namei.h for details. 13 - */ 14 - 15 - #define __emul_prefix() NULL 16 - 17 - #endif /* __PARISC_NAMEI_H */
-20
include/asm-powerpc/namei.h
··· 1 - #ifndef _ASM_POWERPC_NAMEI_H 2 - #define _ASM_POWERPC_NAMEI_H 3 - 4 - #ifdef __KERNEL__ 5 - 6 - /* 7 - * Adapted from include/asm-alpha/namei.h 8 - * 9 - * Included from fs/namei.c 10 - */ 11 - 12 - /* This dummy routine maybe changed to something useful 13 - * for /usr/gnemul/ emulation stuff. 14 - * Look at asm-sparc/namei.h for details. 15 - */ 16 - 17 - #define __emul_prefix() NULL 18 - 19 - #endif /* __KERNEL__ */ 20 - #endif /* _ASM_POWERPC_NAMEI_H */
-21
include/asm-s390/namei.h
··· 1 - /* 2 - * include/asm-s390/namei.h 3 - * 4 - * S390 version 5 - * 6 - * Derived from "include/asm-i386/namei.h" 7 - * 8 - * Included from linux/fs/namei.c 9 - */ 10 - 11 - #ifndef __S390_NAMEI_H 12 - #define __S390_NAMEI_H 13 - 14 - /* This dummy routine maybe changed to something useful 15 - * for /usr/gnemul/ emulation stuff. 16 - * Look at asm-sparc/namei.h for details. 17 - */ 18 - 19 - #define __emul_prefix() NULL 20 - 21 - #endif /* __S390_NAMEI_H */
-17
include/asm-sh/namei.h
··· 1 - /* $Id: namei.h,v 1.3 2000/07/04 06:24:49 gniibe Exp $ 2 - * linux/include/asm-sh/namei.h 3 - * 4 - * Included from linux/fs/namei.c 5 - */ 6 - 7 - #ifndef __ASM_SH_NAMEI_H 8 - #define __ASM_SH_NAMEI_H 9 - 10 - /* This dummy routine maybe changed to something useful 11 - * for /usr/gnemul/ emulation stuff. 12 - * Look at asm-sparc/namei.h for details. 13 - */ 14 - 15 - #define __emul_prefix() NULL 16 - 17 - #endif /* __ASM_SH_NAMEI_H */
-8
include/asm-sparc/namei.h
··· 1 - #ifndef ___ASM_SPARC_NAMEI_H 2 - #define ___ASM_SPARC_NAMEI_H 3 - #if defined(__sparc__) && defined(__arch64__) 4 - #include <asm-sparc/namei_64.h> 5 - #else 6 - #include <asm-sparc/namei_32.h> 7 - #endif 8 - #endif
-1
include/asm-sparc64/namei.h
··· 1 - #include <asm-sparc/namei.h>
-6
include/asm-um/namei.h
··· 1 - #ifndef __UM_NAMEI_H 2 - #define __UM_NAMEI_H 3 - 4 - #include "asm/arch/namei.h" 5 - 6 - #endif
-17
include/asm-v850/namei.h
··· 1 - /* 2 - * linux/include/asm-v850/namei.h 3 - * 4 - * Included from linux/fs/namei.c 5 - */ 6 - 7 - #ifndef __V850_NAMEI_H__ 8 - #define __V850_NAMEI_H__ 9 - 10 - /* This dummy routine maybe changed to something useful 11 - * for /usr/gnemul/ emulation stuff. 12 - * Look at asm-sparc/namei.h for details. 13 - */ 14 - 15 - #define __emul_prefix() NULL 16 - 17 - #endif /* __V850_NAMEI_H__ */
-11
include/asm-x86/namei.h
··· 1 - #ifndef _ASM_X86_NAMEI_H 2 - #define _ASM_X86_NAMEI_H 3 - 4 - /* This dummy routine maybe changed to something useful 5 - * for /usr/gnemul/ emulation stuff. 6 - * Look at asm-sparc/namei.h for details. 7 - */ 8 - 9 - #define __emul_prefix() NULL 10 - 11 - #endif /* _ASM_X86_NAMEI_H */
-26
include/asm-xtensa/namei.h
··· 1 - /* 2 - * include/asm-xtensa/namei.h 3 - * 4 - * Included from linux/fs/namei.c 5 - * 6 - * This file is subject to the terms and conditions of the GNU General Public 7 - * License. See the file "COPYING" in the main directory of this archive 8 - * for more details. 9 - * 10 - * Copyright (C) 2001 - 2005 Tensilica Inc. 11 - */ 12 - 13 - #ifndef _XTENSA_NAMEI_H 14 - #define _XTENSA_NAMEI_H 15 - 16 - #ifdef __KERNEL__ 17 - 18 - /* This dummy routine maybe changed to something useful 19 - * for /usr/gnemul/ emulation stuff. 20 - * Look at asm-sparc/namei.h for details. 21 - */ 22 - 23 - #define __emul_prefix() NULL 24 - 25 - #endif /* __KERNEL__ */ 26 - #endif /* _XTENSA_NAMEI_H */
+1 -2
include/linux/fs_struct.h
··· 7 7 atomic_t count; 8 8 rwlock_t lock; 9 9 int umask; 10 - struct path root, pwd, altroot; 10 + struct path root, pwd; 11 11 }; 12 12 13 13 #define INIT_FS { \ ··· 19 19 extern struct kmem_cache *fs_cachep; 20 20 21 21 extern void exit_fs(struct task_struct *); 22 - extern void set_fs_altroot(void); 23 22 extern void set_fs_root(struct fs_struct *, struct path *); 24 23 extern void set_fs_pwd(struct fs_struct *, struct path *); 25 24 extern struct fs_struct *copy_fs_struct(struct fs_struct *);
-1
include/linux/namei.h
··· 47 47 #define LOOKUP_DIRECTORY 2 48 48 #define LOOKUP_CONTINUE 4 49 49 #define LOOKUP_PARENT 16 50 - #define LOOKUP_NOALT 32 51 50 #define LOOKUP_REVAL 64 52 51 /* 53 52 * Intent data
-1
kernel/exec_domain.c
··· 168 168 current->personality = personality; 169 169 oep = current_thread_info()->exec_domain; 170 170 current_thread_info()->exec_domain = ep; 171 - set_fs_altroot(); 172 171 173 172 module_put(oep->module); 174 173 return 0;
-2
kernel/exit.c
··· 565 565 if (atomic_dec_and_test(&fs->count)) { 566 566 path_put(&fs->root); 567 567 path_put(&fs->pwd); 568 - if (fs->altroot.dentry) 569 - path_put(&fs->altroot); 570 568 kmem_cache_free(fs_cachep, fs); 571 569 } 572 570 }
-7
kernel/fork.c
··· 657 657 path_get(&old->root); 658 658 fs->pwd = old->pwd; 659 659 path_get(&old->pwd); 660 - if (old->altroot.dentry) { 661 - fs->altroot = old->altroot; 662 - path_get(&old->altroot); 663 - } else { 664 - fs->altroot.mnt = NULL; 665 - fs->altroot.dentry = NULL; 666 - } 667 660 read_unlock(&old->lock); 668 661 } 669 662 return fs;