| 1 |
diff -ru /tmp/linux/linux/fs/namei.c linux/fs/namei.c |
| 2 |
--- /tmp/linux/linux/fs/namei.c Fri Sep 22 23:21:18 2000 |
| 3 |
+++ linux/fs/namei.c Thu Nov 2 10:23:25 2000 |
| 4 |
@@ -99,6 +99,9 @@ |
| 5 |
* XEmacs seems to be relying on it... |
| 6 |
*/ |
| 7 |
|
| 8 |
+/* lookup function for "virtual" files */ |
| 9 |
+struct dentry *(*lookup_virtual)(struct nameidata *, struct dentry *); |
| 10 |
+ |
| 11 |
/* In order to reduce some races, while at the same time doing additional |
| 12 |
* checking and hopefully speeding things up, we copy filenames to the |
| 13 |
* kernel data space before using them.. |
| 14 |
@@ -261,9 +264,10 @@ |
| 15 |
* make sure that nobody added the entry to the dcache in the meantime.. |
| 16 |
* SMP-safe |
| 17 |
*/ |
| 18 |
-static struct dentry * real_lookup(struct dentry * parent, struct qstr * name, int flags) |
| 19 |
+static struct dentry * real_lookup(struct nameidata * nd, struct qstr * name, int flags) |
| 20 |
{ |
| 21 |
struct dentry * result; |
| 22 |
+ struct dentry *parent = nd->dentry; |
| 23 |
struct inode *dir = parent->d_inode; |
| 24 |
|
| 25 |
down(&dir->i_sem); |
| 26 |
@@ -282,12 +286,24 @@ |
| 27 |
lock_kernel(); |
| 28 |
result = dir->i_op->lookup(dir, dentry); |
| 29 |
unlock_kernel(); |
| 30 |
- if (result) |
| 31 |
+ if (result) { |
| 32 |
dput(dentry); |
| 33 |
- else |
| 34 |
+ up(&dir->i_sem); |
| 35 |
+ } |
| 36 |
+ else { |
| 37 |
+ up(&dir->i_sem); |
| 38 |
result = dentry; |
| 39 |
- } |
| 40 |
- up(&dir->i_sem); |
| 41 |
+ /* |
| 42 |
+ * If the dentry is negative it might |
| 43 |
+ * refer to a 'virtual' file |
| 44 |
+ */ |
| 45 |
+ if (lookup_virtual && !dentry->d_inode) |
| 46 |
+ lookup_virtual(nd, dentry); |
| 47 |
+ } |
| 48 |
+ } |
| 49 |
+ else |
| 50 |
+ up(&dir->i_sem); |
| 51 |
+ |
| 52 |
return result; |
| 53 |
} |
| 54 |
|
| 55 |
@@ -490,7 +506,7 @@ |
| 56 |
/* This does the actual lookups.. */ |
| 57 |
dentry = cached_lookup(nd->dentry, &this, LOOKUP_CONTINUE); |
| 58 |
if (!dentry) { |
| 59 |
- dentry = real_lookup(nd->dentry, &this, LOOKUP_CONTINUE); |
| 60 |
+ dentry = real_lookup(nd, &this, LOOKUP_CONTINUE); |
| 61 |
err = PTR_ERR(dentry); |
| 62 |
if (IS_ERR(dentry)) |
| 63 |
break; |
| 64 |
@@ -553,7 +569,7 @@ |
| 65 |
} |
| 66 |
dentry = cached_lookup(nd->dentry, &this, 0); |
| 67 |
if (!dentry) { |
| 68 |
- dentry = real_lookup(nd->dentry, &this, 0); |
| 69 |
+ dentry = real_lookup(nd, &this, 0); |
| 70 |
err = PTR_ERR(dentry); |
| 71 |
if (IS_ERR(dentry)) |
| 72 |
break; |
| 73 |
diff -ru /tmp/linux/linux/fs/super.c linux/fs/super.c |
| 74 |
--- /tmp/linux/linux/fs/super.c Mon Oct 16 21:57:59 2000 |
| 75 |
+++ linux/fs/super.c Thu Nov 2 10:23:25 2000 |
| 76 |
@@ -47,7 +47,7 @@ |
| 77 |
* unmounting a filesystem and re-mounting it (or something |
| 78 |
* else). |
| 79 |
*/ |
| 80 |
-static DECLARE_MUTEX(mount_sem); |
| 81 |
+DECLARE_MUTEX(mount_sem); |
| 82 |
|
| 83 |
extern void wait_for_keypress(void); |
| 84 |
|
| 85 |
@@ -303,9 +303,10 @@ |
| 86 |
* support for such beasts we'll have to change prototype. |
| 87 |
*/ |
| 88 |
|
| 89 |
-static struct vfsmount *add_vfsmnt(struct nameidata *nd, |
| 90 |
- struct dentry *root, |
| 91 |
- const char *dev_name) |
| 92 |
+struct vfsmount *add_vfsmnt(struct nameidata *nd, |
| 93 |
+ struct dentry *root, |
| 94 |
+ const char *dev_name, |
| 95 |
+ struct mount_operations *mnt_op) |
| 96 |
{ |
| 97 |
struct vfsmount *mnt; |
| 98 |
struct super_block *sb = root->d_inode->i_sb; |
| 99 |
@@ -330,6 +331,7 @@ |
| 100 |
mnt->mnt_owner = current->uid; |
| 101 |
atomic_set(&mnt->mnt_count,1); |
| 102 |
mnt->mnt_sb = sb; |
| 103 |
+ mnt->mnt_op = mnt_op; |
| 104 |
|
| 105 |
spin_lock(&dcache_lock); |
| 106 |
if (nd && !IS_ROOT(nd->dentry) && d_unhashed(nd->dentry)) |
| 107 |
@@ -417,6 +419,8 @@ |
| 108 |
list_del(&mnt->mnt_child); |
| 109 |
spin_unlock(&dcache_lock); |
| 110 |
/* Now we can work safely */ |
| 111 |
+ if(mnt->mnt_op && mnt->mnt_op->release) |
| 112 |
+ mnt->mnt_op->release(mnt); |
| 113 |
if (mnt->mnt_parent != mnt) |
| 114 |
mntput(mnt->mnt_parent); |
| 115 |
|
| 116 |
@@ -979,7 +983,7 @@ |
| 117 |
put_unnamed_dev(dev); |
| 118 |
return ERR_PTR(-EINVAL); |
| 119 |
} |
| 120 |
- mnt = add_vfsmnt(NULL, sb->s_root, NULL); |
| 121 |
+ mnt = add_vfsmnt(NULL, sb->s_root, NULL, NULL); |
| 122 |
if (!mnt) { |
| 123 |
kill_super(sb, 0); |
| 124 |
return ERR_PTR(-ENOMEM); |
| 125 |
@@ -1010,7 +1014,23 @@ |
| 126 |
return 0; |
| 127 |
} |
| 128 |
|
| 129 |
-static int do_umount(struct vfsmount *mnt, int umount_root, int flags) |
| 130 |
+static void try_umount_children(struct vfsmount *mnt) |
| 131 |
+{ |
| 132 |
+ struct list_head *next, *curr; |
| 133 |
+ struct vfsmount *child; |
| 134 |
+ |
| 135 |
+ /* The mount list is protected by mount_sem */ |
| 136 |
+ curr = mnt->mnt_mounts.next; |
| 137 |
+ while(curr != &mnt->mnt_mounts) { |
| 138 |
+ next = curr->next; |
| 139 |
+ child = list_entry(curr, struct vfsmount, mnt_child); |
| 140 |
+ if(child->mnt_op && child->mnt_op->umount) |
| 141 |
+ child->mnt_op->umount(child); |
| 142 |
+ curr = next; |
| 143 |
+ } |
| 144 |
+} |
| 145 |
+ |
| 146 |
+int do_umount(struct vfsmount *mnt, int umount_root, int flags) |
| 147 |
{ |
| 148 |
struct super_block * sb = mnt->mnt_sb; |
| 149 |
|
| 150 |
@@ -1036,6 +1056,9 @@ |
| 151 |
return retval; |
| 152 |
} |
| 153 |
|
| 154 |
+ /* umount any automatic mounts */ |
| 155 |
+ try_umount_children(mnt); |
| 156 |
+ |
| 157 |
spin_lock(&dcache_lock); |
| 158 |
if (atomic_read(&mnt->mnt_count) > 2) { |
| 159 |
spin_unlock(&dcache_lock); |
| 160 |
@@ -1213,7 +1236,7 @@ |
| 161 |
down(&new_nd.dentry->d_inode->i_zombie); |
| 162 |
if (IS_DEADDIR(new_nd.dentry->d_inode)) |
| 163 |
err = -ENOENT; |
| 164 |
- else if (add_vfsmnt(&new_nd, old_nd.dentry, old_nd.mnt->mnt_devname)) |
| 165 |
+ else if (add_vfsmnt(&new_nd, old_nd.dentry, old_nd.mnt->mnt_devname, NULL)) |
| 166 |
err = 0; |
| 167 |
up(&new_nd.dentry->d_inode->i_zombie); |
| 168 |
up(&mount_sem); |
| 169 |
@@ -1398,7 +1421,7 @@ |
| 170 |
down(&nd.dentry->d_inode->i_zombie); |
| 171 |
if (!IS_DEADDIR(nd.dentry->d_inode)) { |
| 172 |
retval = -ENOMEM; |
| 173 |
- mnt = add_vfsmnt(&nd, sb->s_root, dev_name); |
| 174 |
+ mnt = add_vfsmnt(&nd, sb->s_root, dev_name, NULL); |
| 175 |
} |
| 176 |
up(&nd.dentry->d_inode->i_zombie); |
| 177 |
if (!mnt) |
| 178 |
@@ -1603,10 +1626,10 @@ |
| 179 |
devfs_mk_symlink (NULL, "root", DEVFS_FL_DEFAULT, |
| 180 |
path + 5 + path_start, NULL, NULL); |
| 181 |
memcpy (path + path_start, "/dev/", 5); |
| 182 |
- vfsmnt = add_vfsmnt(NULL, sb->s_root, path + path_start); |
| 183 |
+ vfsmnt = add_vfsmnt(NULL, sb->s_root, path + path_start, NULL); |
| 184 |
} |
| 185 |
else |
| 186 |
- vfsmnt = add_vfsmnt(NULL, sb->s_root, "/dev/root"); |
| 187 |
+ vfsmnt = add_vfsmnt(NULL, sb->s_root, "/dev/root", NULL); |
| 188 |
/* FIXME: if something will try to umount us right now... */ |
| 189 |
if (vfsmnt) { |
| 190 |
set_fs_root(current->fs, vfsmnt, sb->s_root); |
| 191 |
diff -ru /tmp/linux/linux/include/linux/fs.h linux/include/linux/fs.h |
| 192 |
--- /tmp/linux/linux/include/linux/fs.h Tue Oct 31 20:18:05 2000 |
| 193 |
+++ linux/include/linux/fs.h Thu Nov 2 10:23:25 2000 |
| 194 |
@@ -849,6 +849,10 @@ |
| 195 |
extern void kern_umount(struct vfsmount *); |
| 196 |
extern int may_umount(struct vfsmount *); |
| 197 |
extern long do_mount(char *, char *, char *, unsigned long, void *); |
| 198 |
+extern struct vfsmount *add_vfsmnt(struct nameidata *nd, struct dentry *root, |
| 199 |
+ const char *dev_name, |
| 200 |
+ struct mount_operations *mnt_op); |
| 201 |
+extern int do_umount(struct vfsmount *mnt, int umount_root, int flags); |
| 202 |
|
| 203 |
|
| 204 |
extern int vfs_statfs(struct super_block *, struct statfs *); |
| 205 |
@@ -1124,6 +1128,9 @@ |
| 206 |
|
| 207 |
/* needed for stackable file system support */ |
| 208 |
extern loff_t default_llseek(struct file *file, loff_t offset, int origin); |
| 209 |
+ |
| 210 |
+/* lookup function for "virtual" files */ |
| 211 |
+extern struct dentry *(*lookup_virtual)(struct nameidata *, struct dentry *); |
| 212 |
|
| 213 |
extern int __user_walk(const char *, unsigned, struct nameidata *); |
| 214 |
extern int path_init(const char *, unsigned, struct nameidata *); |
| 215 |
diff -ru /tmp/linux/linux/include/linux/mount.h linux/include/linux/mount.h |
| 216 |
--- /tmp/linux/linux/include/linux/mount.h Sun Sep 17 18:51:57 2000 |
| 217 |
+++ linux/include/linux/mount.h Thu Nov 2 10:23:25 2000 |
| 218 |
@@ -14,6 +14,8 @@ |
| 219 |
|
| 220 |
#define MNT_VISIBLE 1 |
| 221 |
|
| 222 |
+extern struct semaphore mount_sem; |
| 223 |
+ |
| 224 |
struct vfsmount |
| 225 |
{ |
| 226 |
struct dentry *mnt_mountpoint; /* dentry of mountpoint */ |
| 227 |
@@ -30,6 +32,20 @@ |
| 228 |
char *mnt_devname; /* Name of device e.g. /dev/dsk/hda1 */ |
| 229 |
struct list_head mnt_list; |
| 230 |
uid_t mnt_owner; |
| 231 |
+ struct mount_operations *mnt_op; /* Operations on vfsmount */ |
| 232 |
+}; |
| 233 |
+ |
| 234 |
+/* |
| 235 |
+ * Mount operations: |
| 236 |
+ * release(node) - called when this node has been umounted |
| 237 |
+ * umount(node) - called when the parent is being umounted |
| 238 |
+ * |
| 239 |
+ * mount_sem is held in all |
| 240 |
+ */ |
| 241 |
+ |
| 242 |
+struct mount_operations { |
| 243 |
+ void (*release) (struct vfsmount *); |
| 244 |
+ void (*umount) (struct vfsmount *); |
| 245 |
}; |
| 246 |
|
| 247 |
static inline struct vfsmount *mntget(struct vfsmount *mnt) |
| 248 |
diff -ru /tmp/linux/linux/kernel/ksyms.c linux/kernel/ksyms.c |
| 249 |
--- /tmp/linux/linux/kernel/ksyms.c Mon Oct 30 19:50:27 2000 |
| 250 |
+++ linux/kernel/ksyms.c Thu Nov 2 10:23:25 2000 |
| 251 |
@@ -270,6 +270,9 @@ |
| 252 |
EXPORT_SYMBOL(filemap_sync); |
| 253 |
EXPORT_SYMBOL(lock_page); |
| 254 |
|
| 255 |
+/* lookup function for "virtual" files */ |
| 256 |
+EXPORT_SYMBOL(lookup_virtual); |
| 257 |
+ |
| 258 |
/* device registration */ |
| 259 |
EXPORT_SYMBOL(register_chrdev); |
| 260 |
EXPORT_SYMBOL(unregister_chrdev); |
| 261 |
@@ -322,6 +325,9 @@ |
| 262 |
EXPORT_SYMBOL(kern_mount); |
| 263 |
EXPORT_SYMBOL(kern_umount); |
| 264 |
EXPORT_SYMBOL(may_umount); |
| 265 |
+EXPORT_SYMBOL(add_vfsmnt); |
| 266 |
+EXPORT_SYMBOL(do_umount); |
| 267 |
+EXPORT_SYMBOL(mount_sem); |
| 268 |
|
| 269 |
/* executable format registration */ |
| 270 |
EXPORT_SYMBOL(register_binfmt); |