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

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6:
[PATCH] get stack footprint of pathname resolution back to relative sanity
[PATCH] double iput() on failure exit in hugetlb
[PATCH] double dput() on failure exit in tiny-shmem
[PATCH] fix up new filp allocators
[PATCH] check for null vfsmount in dentry_open()
[PATCH] reiserfs: eliminate private use of struct file in xattr
[PATCH] sanitize hppfs
hppfs pass vfsmount to dentry_open()
[PATCH] restore export of do_kern_mount()

+303 -367
+8 -10
fs/anon_inodes.c
··· 81 81 82 82 if (IS_ERR(anon_inode_inode)) 83 83 return -ENODEV; 84 - file = get_empty_filp(); 85 - if (!file) 86 - return -ENFILE; 87 84 88 85 error = get_unused_fd(); 89 86 if (error < 0) 90 - goto err_put_filp; 87 + return error; 91 88 fd = error; 92 89 93 90 /* ··· 111 114 dentry->d_flags &= ~DCACHE_UNHASHED; 112 115 d_instantiate(dentry, anon_inode_inode); 113 116 114 - file->f_path.mnt = mntget(anon_inode_mnt); 115 - file->f_path.dentry = dentry; 117 + error = -ENFILE; 118 + file = alloc_file(anon_inode_mnt, dentry, 119 + FMODE_READ | FMODE_WRITE, fops); 120 + if (!file) 121 + goto err_dput; 116 122 file->f_mapping = anon_inode_inode->i_mapping; 117 123 118 124 file->f_pos = 0; 119 125 file->f_flags = O_RDWR; 120 - file->f_op = fops; 121 - file->f_mode = FMODE_READ | FMODE_WRITE; 122 126 file->f_version = 0; 123 127 file->private_data = priv; 124 128 ··· 130 132 *pfile = file; 131 133 return 0; 132 134 135 + err_dput: 136 + dput(dentry); 133 137 err_put_unused_fd: 134 138 put_unused_fd(fd); 135 - err_put_filp: 136 - put_filp(file); 137 139 return error; 138 140 } 139 141 EXPORT_SYMBOL_GPL(anon_inode_getfd);
+6
fs/file_table.c
··· 83 83 /* Find an unused file structure and return a pointer to it. 84 84 * Returns NULL, if there are no more free file structures or 85 85 * we run out of memory. 86 + * 87 + * Be very careful using this. You are responsible for 88 + * getting write access to any mount that you might assign 89 + * to this filp, if it is opened for write. If this is not 90 + * done, you will imbalance int the mount's writer count 91 + * and a warning at __fput() time. 86 92 */ 87 93 struct file *get_empty_filp(void) 88 94 {
+202 -235
fs/hppfs/hppfs_kern.c
··· 1 1 /* 2 - * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) 2 + * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) 3 3 * Licensed under the GPL 4 4 */ 5 5 6 - #include <linux/fs.h> 7 - #include <linux/file.h> 8 - #include <linux/module.h> 9 - #include <linux/init.h> 10 - #include <linux/slab.h> 11 - #include <linux/list.h> 12 - #include <linux/kernel.h> 13 6 #include <linux/ctype.h> 14 7 #include <linux/dcache.h> 8 + #include <linux/file.h> 9 + #include <linux/fs.h> 10 + #include <linux/init.h> 11 + #include <linux/kernel.h> 12 + #include <linux/list.h> 13 + #include <linux/module.h> 14 + #include <linux/mount.h> 15 + #include <linux/slab.h> 15 16 #include <linux/statfs.h> 17 + #include <linux/types.h> 16 18 #include <asm/uaccess.h> 17 - #include <asm/fcntl.h> 18 19 #include "os.h" 19 20 20 - static int init_inode(struct inode *inode, struct dentry *dentry); 21 + static struct inode *get_inode(struct super_block *, struct dentry *); 21 22 22 23 struct hppfs_data { 23 24 struct list_head list; ··· 52 51 int i; 53 52 54 53 sb = dentry->d_sb; 55 - if((sb->s_op != &hppfs_sbops) || (dentry->d_parent != sb->s_root)) 56 - return(0); 54 + if ((sb->s_op != &hppfs_sbops) || (dentry->d_parent != sb->s_root)) 55 + return 0; 57 56 58 - for(i = 0; i < dentry->d_name.len; i++){ 59 - if(!isdigit(dentry->d_name.name[i])) 60 - return(0); 57 + for (i = 0; i < dentry->d_name.len; i++) { 58 + if (!isdigit(dentry->d_name.name[i])) 59 + return 0; 61 60 } 62 - return(1); 61 + return 1; 63 62 } 64 63 65 64 static char *dentry_name(struct dentry *dentry, int extra) ··· 71 70 72 71 len = 0; 73 72 parent = dentry; 74 - while(parent->d_parent != parent){ 75 - if(is_pid(parent)) 73 + while (parent->d_parent != parent) { 74 + if (is_pid(parent)) 76 75 len += strlen("pid") + 1; 77 76 else len += parent->d_name.len + 1; 78 77 parent = parent->d_parent; ··· 81 80 root = "proc"; 82 81 len += strlen(root); 83 82 name = kmalloc(len + extra + 1, GFP_KERNEL); 84 - if(name == NULL) return(NULL); 83 + if (name == NULL) 84 + return NULL; 85 85 86 86 name[len] = '\0'; 87 87 parent = dentry; 88 - while(parent->d_parent != parent){ 89 - if(is_pid(parent)){ 88 + while (parent->d_parent != parent) { 89 + if (is_pid(parent)) { 90 90 seg_name = "pid"; 91 91 seg_len = strlen("pid"); 92 92 } ··· 102 100 parent = parent->d_parent; 103 101 } 104 102 strncpy(name, root, strlen(root)); 105 - return(name); 103 + return name; 106 104 } 107 - 108 - struct dentry_operations hppfs_dentry_ops = { 109 - }; 110 105 111 106 static int file_removed(struct dentry *dentry, const char *file) 112 107 { ··· 111 112 int extra, fd; 112 113 113 114 extra = 0; 114 - if(file != NULL) extra += strlen(file) + 1; 115 + if (file != NULL) 116 + extra += strlen(file) + 1; 115 117 116 118 host_file = dentry_name(dentry, extra + strlen("/remove")); 117 - if(host_file == NULL){ 118 - printk("file_removed : allocation failed\n"); 119 - return(-ENOMEM); 119 + if (host_file == NULL) { 120 + printk(KERN_ERR "file_removed : allocation failed\n"); 121 + return -ENOMEM; 120 122 } 121 123 122 - if(file != NULL){ 124 + if (file != NULL) { 123 125 strcat(host_file, "/"); 124 126 strcat(host_file, file); 125 127 } ··· 128 128 129 129 fd = os_open_file(host_file, of_read(OPENFLAGS()), 0); 130 130 kfree(host_file); 131 - if(fd > 0){ 131 + if (fd > 0) { 132 132 os_close_file(fd); 133 - return(1); 133 + return 1; 134 134 } 135 - return(0); 136 - } 137 - 138 - static void hppfs_read_inode(struct inode *ino) 139 - { 140 - struct inode *proc_ino; 141 - 142 - if(HPPFS_I(ino)->proc_dentry == NULL) 143 - return; 144 - 145 - proc_ino = HPPFS_I(ino)->proc_dentry->d_inode; 146 - ino->i_uid = proc_ino->i_uid; 147 - ino->i_gid = proc_ino->i_gid; 148 - ino->i_atime = proc_ino->i_atime; 149 - ino->i_mtime = proc_ino->i_mtime; 150 - ino->i_ctime = proc_ino->i_ctime; 151 - ino->i_ino = proc_ino->i_ino; 152 - ino->i_mode = proc_ino->i_mode; 153 - ino->i_nlink = proc_ino->i_nlink; 154 - ino->i_size = proc_ino->i_size; 155 - ino->i_blocks = proc_ino->i_blocks; 156 - } 157 - 158 - static struct inode *hppfs_iget(struct super_block *sb) 159 - { 160 - struct inode *inode; 161 - 162 - inode = iget_locked(sb, 0); 163 - if (!inode) 164 - return ERR_PTR(-ENOMEM); 165 - if (inode->i_state & I_NEW) { 166 - hppfs_read_inode(inode); 167 - unlock_new_inode(inode); 168 - } 169 - return inode; 135 + return 0; 170 136 } 171 137 172 138 static struct dentry *hppfs_lookup(struct inode *ino, struct dentry *dentry, ··· 143 177 int err, deleted; 144 178 145 179 deleted = file_removed(dentry, NULL); 146 - if(deleted < 0) 147 - return(ERR_PTR(deleted)); 148 - else if(deleted) 149 - return(ERR_PTR(-ENOENT)); 180 + if (deleted < 0) 181 + return ERR_PTR(deleted); 182 + else if (deleted) 183 + return ERR_PTR(-ENOENT); 150 184 151 185 err = -ENOMEM; 152 186 parent = HPPFS_I(ino)->proc_dentry; 153 187 mutex_lock(&parent->d_inode->i_mutex); 154 188 proc_dentry = d_lookup(parent, &dentry->d_name); 155 - if(proc_dentry == NULL){ 189 + if (proc_dentry == NULL) { 156 190 proc_dentry = d_alloc(parent, &dentry->d_name); 157 - if(proc_dentry == NULL){ 191 + if (proc_dentry == NULL) { 158 192 mutex_unlock(&parent->d_inode->i_mutex); 159 193 goto out; 160 194 } 161 195 new = (*parent->d_inode->i_op->lookup)(parent->d_inode, 162 196 proc_dentry, NULL); 163 - if(new){ 197 + if (new) { 164 198 dput(proc_dentry); 165 199 proc_dentry = new; 166 200 } 167 201 } 168 202 mutex_unlock(&parent->d_inode->i_mutex); 169 203 170 - if(IS_ERR(proc_dentry)) 171 - return(proc_dentry); 204 + if (IS_ERR(proc_dentry)) 205 + return proc_dentry; 172 206 173 - inode = hppfs_iget(ino->i_sb); 174 - if (IS_ERR(inode)) { 175 - err = PTR_ERR(inode); 207 + err = -ENOMEM; 208 + inode = get_inode(ino->i_sb, proc_dentry); 209 + if (!inode) 176 210 goto out_dput; 177 - } 178 - 179 - err = init_inode(inode, proc_dentry); 180 - if(err) 181 - goto out_put; 182 - 183 - hppfs_read_inode(inode); 184 211 185 212 d_add(dentry, inode); 186 - dentry->d_op = &hppfs_dentry_ops; 187 - return(NULL); 213 + return NULL; 188 214 189 - out_put: 190 - iput(inode); 191 215 out_dput: 192 216 dput(proc_dentry); 193 217 out: 194 - return(ERR_PTR(err)); 218 + return ERR_PTR(err); 195 219 } 196 220 197 221 static const struct inode_operations hppfs_file_iops = { ··· 195 239 196 240 read = file->f_path.dentry->d_inode->i_fop->read; 197 241 198 - if(!is_user) 242 + if (!is_user) 199 243 set_fs(KERNEL_DS); 200 244 201 245 n = (*read)(file, buf, count, &file->f_pos); 202 246 203 - if(!is_user) 247 + if (!is_user) 204 248 set_fs(USER_DS); 205 249 206 - if(ppos) *ppos = file->f_pos; 250 + if (ppos) 251 + *ppos = file->f_pos; 207 252 return n; 208 253 } 209 254 ··· 216 259 217 260 n = -ENOMEM; 218 261 new_buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 219 - if(new_buf == NULL){ 220 - printk("hppfs_read_file : kmalloc failed\n"); 262 + if (new_buf == NULL) { 263 + printk(KERN_ERR "hppfs_read_file : kmalloc failed\n"); 221 264 goto out; 222 265 } 223 266 n = 0; 224 - while(count > 0){ 267 + while (count > 0) { 225 268 cur = min_t(ssize_t, count, PAGE_SIZE); 226 269 err = os_read_file(fd, new_buf, cur); 227 - if(err < 0){ 228 - printk("hppfs_read : read failed, errno = %d\n", 229 - err); 270 + if (err < 0) { 271 + printk(KERN_ERR "hppfs_read : read failed, " 272 + "errno = %d\n", err); 230 273 n = err; 231 274 goto out_free; 232 - } 233 - else if(err == 0) 275 + } else if (err == 0) 234 276 break; 235 277 236 - if(copy_to_user(buf, new_buf, err)){ 278 + if (copy_to_user(buf, new_buf, err)) { 237 279 n = -EFAULT; 238 280 goto out_free; 239 281 } ··· 253 297 loff_t off; 254 298 int err; 255 299 256 - if(hppfs->contents != NULL){ 257 - if(*ppos >= hppfs->len) return(0); 300 + if (hppfs->contents != NULL) { 301 + if (*ppos >= hppfs->len) 302 + return 0; 258 303 259 304 data = hppfs->contents; 260 305 off = *ppos; 261 - while(off >= sizeof(data->contents)){ 306 + while (off >= sizeof(data->contents)) { 262 307 data = list_entry(data->list.next, struct hppfs_data, 263 308 list); 264 309 off -= sizeof(data->contents); 265 310 } 266 311 267 - if(off + count > hppfs->len) 312 + if (off + count > hppfs->len) 268 313 count = hppfs->len - off; 269 314 copy_to_user(buf, &data->contents[off], count); 270 315 *ppos += count; 271 - } 272 - else if(hppfs->host_fd != -1){ 316 + } else if (hppfs->host_fd != -1) { 273 317 err = os_seek_file(hppfs->host_fd, *ppos); 274 - if(err){ 275 - printk("hppfs_read : seek failed, errno = %d\n", err); 276 - return(err); 318 + if (err) { 319 + printk(KERN_ERR "hppfs_read : seek failed, " 320 + "errno = %d\n", err); 321 + return err; 277 322 } 278 323 count = hppfs_read_file(hppfs->host_fd, buf, count); 279 - if(count > 0) 324 + if (count > 0) 280 325 *ppos += count; 281 326 } 282 327 else count = read_proc(hppfs->proc_file, buf, count, ppos, 1); 283 328 284 - return(count); 329 + return count; 285 330 } 286 331 287 332 static ssize_t hppfs_write(struct file *file, const char __user *buf, size_t len, ··· 299 342 err = (*write)(proc_file, buf, len, &proc_file->f_pos); 300 343 file->f_pos = proc_file->f_pos; 301 344 302 - return(err); 345 + return err; 303 346 } 304 347 305 348 static int open_host_sock(char *host_file, int *filter_out) ··· 311 354 strcpy(end, "/rw"); 312 355 *filter_out = 1; 313 356 fd = os_connect_socket(host_file); 314 - if(fd > 0) 315 - return(fd); 357 + if (fd > 0) 358 + return fd; 316 359 317 360 strcpy(end, "/r"); 318 361 *filter_out = 0; 319 362 fd = os_connect_socket(host_file); 320 - return(fd); 363 + return fd; 321 364 } 322 365 323 366 static void free_contents(struct hppfs_data *head) ··· 325 368 struct hppfs_data *data; 326 369 struct list_head *ele, *next; 327 370 328 - if(head == NULL) return; 371 + if (head == NULL) 372 + return; 329 373 330 - list_for_each_safe(ele, next, &head->list){ 374 + list_for_each_safe(ele, next, &head->list) { 331 375 data = list_entry(ele, struct hppfs_data, list); 332 376 kfree(data); 333 377 } ··· 345 387 346 388 err = -ENOMEM; 347 389 data = kmalloc(sizeof(*data), GFP_KERNEL); 348 - if(data == NULL){ 349 - printk("hppfs_get_data : head allocation failed\n"); 390 + if (data == NULL) { 391 + printk(KERN_ERR "hppfs_get_data : head allocation failed\n"); 350 392 goto failed; 351 393 } 352 394 ··· 355 397 head = data; 356 398 *size_out = 0; 357 399 358 - if(filter){ 359 - while((n = read_proc(proc_file, data->contents, 400 + if (filter) { 401 + while ((n = read_proc(proc_file, data->contents, 360 402 sizeof(data->contents), NULL, 0)) > 0) 361 403 os_write_file(fd, data->contents, n); 362 404 err = os_shutdown_socket(fd, 0, 1); 363 - if(err){ 364 - printk("hppfs_get_data : failed to shut down " 405 + if (err) { 406 + printk(KERN_ERR "hppfs_get_data : failed to shut down " 365 407 "socket\n"); 366 408 goto failed_free; 367 409 } 368 410 } 369 - while(1){ 411 + while (1) { 370 412 n = os_read_file(fd, data->contents, sizeof(data->contents)); 371 - if(n < 0){ 413 + if (n < 0) { 372 414 err = n; 373 - printk("hppfs_get_data : read failed, errno = %d\n", 374 - err); 415 + printk(KERN_ERR "hppfs_get_data : read failed, " 416 + "errno = %d\n", err); 375 417 goto failed_free; 376 - } 377 - else if(n == 0) 418 + } else if (n == 0) 378 419 break; 379 420 380 421 *size_out += n; 381 422 382 - if(n < sizeof(data->contents)) 423 + if (n < sizeof(data->contents)) 383 424 break; 384 425 385 426 new = kmalloc(sizeof(*data), GFP_KERNEL); 386 - if(new == 0){ 387 - printk("hppfs_get_data : data allocation failed\n"); 427 + if (new == 0) { 428 + printk(KERN_ERR "hppfs_get_data : data allocation " 429 + "failed\n"); 388 430 err = -ENOMEM; 389 431 goto failed_free; 390 432 } ··· 393 435 list_add(&new->list, &data->list); 394 436 data = new; 395 437 } 396 - return(head); 438 + return head; 397 439 398 440 failed_free: 399 441 free_contents(head); 400 442 failed: 401 - return(ERR_PTR(err)); 443 + return ERR_PTR(err); 402 444 } 403 445 404 446 static struct hppfs_private *hppfs_data(void) ··· 406 448 struct hppfs_private *data; 407 449 408 450 data = kmalloc(sizeof(*data), GFP_KERNEL); 409 - if(data == NULL) 410 - return(data); 451 + if (data == NULL) 452 + return data; 411 453 412 454 *data = ((struct hppfs_private ) { .host_fd = -1, 413 455 .len = -1, 414 456 .contents = NULL } ); 415 - return(data); 457 + return data; 416 458 } 417 459 418 460 static int file_mode(int fmode) 419 461 { 420 - if(fmode == (FMODE_READ | FMODE_WRITE)) 421 - return(O_RDWR); 422 - if(fmode == FMODE_READ) 423 - return(O_RDONLY); 424 - if(fmode == FMODE_WRITE) 425 - return(O_WRONLY); 426 - return(0); 462 + if (fmode == (FMODE_READ | FMODE_WRITE)) 463 + return O_RDWR; 464 + if (fmode == FMODE_READ) 465 + return O_RDONLY; 466 + if (fmode == FMODE_WRITE) 467 + return O_WRONLY; 468 + return 0; 427 469 } 428 470 429 471 static int hppfs_open(struct inode *inode, struct file *file) 430 472 { 431 473 struct hppfs_private *data; 432 474 struct dentry *proc_dentry; 475 + struct vfsmount *proc_mnt; 433 476 char *host_file; 434 477 int err, fd, type, filter; 435 478 436 479 err = -ENOMEM; 437 480 data = hppfs_data(); 438 - if(data == NULL) 481 + if (data == NULL) 439 482 goto out; 440 483 441 484 host_file = dentry_name(file->f_path.dentry, strlen("/rw")); 442 - if(host_file == NULL) 485 + if (host_file == NULL) 443 486 goto out_free2; 444 487 445 488 proc_dentry = HPPFS_I(inode)->proc_dentry; 489 + proc_mnt = inode->i_sb->s_fs_info; 446 490 447 491 /* XXX This isn't closed anywhere */ 448 - data->proc_file = dentry_open(dget(proc_dentry), NULL, 492 + data->proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt), 449 493 file_mode(file->f_mode)); 450 494 err = PTR_ERR(data->proc_file); 451 - if(IS_ERR(data->proc_file)) 495 + if (IS_ERR(data->proc_file)) 452 496 goto out_free1; 453 497 454 498 type = os_file_type(host_file); 455 - if(type == OS_TYPE_FILE){ 499 + if (type == OS_TYPE_FILE) { 456 500 fd = os_open_file(host_file, of_read(OPENFLAGS()), 0); 457 - if(fd >= 0) 501 + if (fd >= 0) 458 502 data->host_fd = fd; 459 - else printk("hppfs_open : failed to open '%s', errno = %d\n", 460 - host_file, -fd); 503 + else 504 + printk(KERN_ERR "hppfs_open : failed to open '%s', " 505 + "errno = %d\n", host_file, -fd); 461 506 462 507 data->contents = NULL; 463 - } 464 - else if(type == OS_TYPE_DIR){ 508 + } else if (type == OS_TYPE_DIR) { 465 509 fd = open_host_sock(host_file, &filter); 466 - if(fd > 0){ 510 + if (fd > 0) { 467 511 data->contents = hppfs_get_data(fd, filter, 468 512 data->proc_file, 469 513 file, &data->len); 470 - if(!IS_ERR(data->contents)) 514 + if (!IS_ERR(data->contents)) 471 515 data->host_fd = fd; 472 - } 473 - else printk("hppfs_open : failed to open a socket in " 474 - "'%s', errno = %d\n", host_file, -fd); 516 + } else 517 + printk(KERN_ERR "hppfs_open : failed to open a socket " 518 + "in '%s', errno = %d\n", host_file, -fd); 475 519 } 476 520 kfree(host_file); 477 521 478 522 file->private_data = data; 479 - return(0); 523 + return 0; 480 524 481 525 out_free1: 482 526 kfree(host_file); ··· 486 526 free_contents(data->contents); 487 527 kfree(data); 488 528 out: 489 - return(err); 529 + return err; 490 530 } 491 531 492 532 static int hppfs_dir_open(struct inode *inode, struct file *file) 493 533 { 494 534 struct hppfs_private *data; 495 535 struct dentry *proc_dentry; 536 + struct vfsmount *proc_mnt; 496 537 int err; 497 538 498 539 err = -ENOMEM; 499 540 data = hppfs_data(); 500 - if(data == NULL) 541 + if (data == NULL) 501 542 goto out; 502 543 503 544 proc_dentry = HPPFS_I(inode)->proc_dentry; 504 - data->proc_file = dentry_open(dget(proc_dentry), NULL, 545 + proc_mnt = inode->i_sb->s_fs_info; 546 + data->proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt), 505 547 file_mode(file->f_mode)); 506 548 err = PTR_ERR(data->proc_file); 507 - if(IS_ERR(data->proc_file)) 549 + if (IS_ERR(data->proc_file)) 508 550 goto out_free; 509 551 510 552 file->private_data = data; 511 - return(0); 553 + return 0; 512 554 513 555 out_free: 514 556 kfree(data); 515 557 out: 516 - return(err); 558 + return err; 517 559 } 518 560 519 561 static loff_t hppfs_llseek(struct file *file, loff_t off, int where) ··· 526 564 loff_t ret; 527 565 528 566 llseek = proc_file->f_path.dentry->d_inode->i_fop->llseek; 529 - if(llseek != NULL){ 567 + if (llseek != NULL) { 530 568 ret = (*llseek)(proc_file, off, where); 531 - if(ret < 0) 532 - return(ret); 569 + if (ret < 0) 570 + return ret; 533 571 } 534 572 535 - return(default_llseek(file, off, where)); 573 + return default_llseek(file, off, where); 536 574 } 537 575 538 576 static const struct file_operations hppfs_file_fops = { ··· 554 592 { 555 593 struct hppfs_dirent *dirent = d; 556 594 557 - if(file_removed(dirent->dentry, name)) 558 - return(0); 595 + if (file_removed(dirent->dentry, name)) 596 + return 0; 559 597 560 - return((*dirent->filldir)(dirent->vfs_dirent, name, size, offset, 561 - inode, type)); 598 + return (*dirent->filldir)(dirent->vfs_dirent, name, size, offset, 599 + inode, type); 562 600 } 563 601 564 602 static int hppfs_readdir(struct file *file, void *ent, filldir_t filldir) ··· 569 607 struct hppfs_dirent dirent = ((struct hppfs_dirent) 570 608 { .vfs_dirent = ent, 571 609 .filldir = filldir, 572 - .dentry = file->f_path.dentry } ); 610 + .dentry = file->f_path.dentry 611 + }); 573 612 int err; 574 613 575 614 readdir = proc_file->f_path.dentry->d_inode->i_fop->readdir; ··· 579 616 err = (*readdir)(proc_file, &dirent, hppfs_filldir); 580 617 file->f_pos = proc_file->f_pos; 581 618 582 - return(err); 619 + return err; 583 620 } 584 621 585 622 static int hppfs_fsync(struct file *file, struct dentry *dentry, int datasync) 586 623 { 587 - return(0); 624 + return 0; 588 625 } 589 626 590 627 static const struct file_operations hppfs_dir_fops = { ··· 602 639 sf->f_files = 0; 603 640 sf->f_ffree = 0; 604 641 sf->f_type = HPPFS_SUPER_MAGIC; 605 - return(0); 642 + return 0; 606 643 } 607 644 608 645 static struct inode *hppfs_alloc_inode(struct super_block *sb) ··· 610 647 struct hppfs_inode_info *hi; 611 648 612 649 hi = kmalloc(sizeof(*hi), GFP_KERNEL); 613 - if(hi == NULL) 614 - return(NULL); 650 + if (!hi) 651 + return NULL; 615 652 616 - *hi = ((struct hppfs_inode_info) { .proc_dentry = NULL }); 653 + hi->proc_dentry = NULL; 617 654 inode_init_once(&hi->vfs_inode); 618 - return(&hi->vfs_inode); 655 + return &hi->vfs_inode; 619 656 } 620 657 621 658 void hppfs_delete_inode(struct inode *ino) ··· 628 665 kfree(HPPFS_I(inode)); 629 666 } 630 667 668 + static void hppfs_put_super(struct super_block *sb) 669 + { 670 + mntput(sb->s_fs_info); 671 + } 672 + 631 673 static const struct super_operations hppfs_sbops = { 632 674 .alloc_inode = hppfs_alloc_inode, 633 675 .destroy_inode = hppfs_destroy_inode, 634 676 .delete_inode = hppfs_delete_inode, 635 677 .statfs = hppfs_statfs, 678 + .put_super = hppfs_put_super, 636 679 }; 637 680 638 - static int hppfs_readlink(struct dentry *dentry, char __user *buffer, int buflen) 681 + static int hppfs_readlink(struct dentry *dentry, char __user *buffer, 682 + int buflen) 639 683 { 640 684 struct file *proc_file; 641 685 struct dentry *proc_dentry; 686 + struct vfsmount *proc_mnt; 642 687 int ret; 643 688 644 689 proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry; 645 - proc_file = dentry_open(dget(proc_dentry), NULL, O_RDONLY); 690 + proc_mnt = dentry->d_sb->s_fs_info; 691 + 692 + proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt), O_RDONLY); 646 693 if (IS_ERR(proc_file)) 647 694 return PTR_ERR(proc_file); 648 695 ··· 667 694 { 668 695 struct file *proc_file; 669 696 struct dentry *proc_dentry; 697 + struct vfsmount *proc_mnt; 670 698 void *ret; 671 699 672 700 proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry; 673 - proc_file = dentry_open(dget(proc_dentry), NULL, O_RDONLY); 701 + proc_mnt = dentry->d_sb->s_fs_info; 702 + 703 + proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt), O_RDONLY); 674 704 if (IS_ERR(proc_file)) 675 705 return proc_file; 676 706 ··· 693 717 .follow_link = hppfs_follow_link, 694 718 }; 695 719 696 - static int init_inode(struct inode *inode, struct dentry *dentry) 720 + static struct inode *get_inode(struct super_block *sb, struct dentry *dentry) 697 721 { 698 - if(S_ISDIR(dentry->d_inode->i_mode)){ 722 + struct inode *proc_ino = dentry->d_inode; 723 + struct inode *inode = new_inode(sb); 724 + 725 + if (!inode) 726 + return ERR_PTR(-ENOMEM); 727 + 728 + if (S_ISDIR(dentry->d_inode->i_mode)) { 699 729 inode->i_op = &hppfs_dir_iops; 700 730 inode->i_fop = &hppfs_dir_fops; 701 - } 702 - else if(S_ISLNK(dentry->d_inode->i_mode)){ 731 + } else if (S_ISLNK(dentry->d_inode->i_mode)) { 703 732 inode->i_op = &hppfs_link_iops; 704 733 inode->i_fop = &hppfs_file_fops; 705 - } 706 - else { 734 + } else { 707 735 inode->i_op = &hppfs_file_iops; 708 736 inode->i_fop = &hppfs_file_fops; 709 737 } 710 738 711 739 HPPFS_I(inode)->proc_dentry = dentry; 712 740 713 - return(0); 741 + inode->i_uid = proc_ino->i_uid; 742 + inode->i_gid = proc_ino->i_gid; 743 + inode->i_atime = proc_ino->i_atime; 744 + inode->i_mtime = proc_ino->i_mtime; 745 + inode->i_ctime = proc_ino->i_ctime; 746 + inode->i_ino = proc_ino->i_ino; 747 + inode->i_mode = proc_ino->i_mode; 748 + inode->i_nlink = proc_ino->i_nlink; 749 + inode->i_size = proc_ino->i_size; 750 + inode->i_blocks = proc_ino->i_blocks; 751 + 752 + return 0; 714 753 } 715 754 716 755 static int hppfs_fill_super(struct super_block *sb, void *d, int silent) 717 756 { 718 757 struct inode *root_inode; 719 - struct file_system_type *procfs; 720 - struct super_block *proc_sb; 721 - int err; 758 + struct vfsmount *proc_mnt; 759 + int err = -ENOENT; 722 760 723 - err = -ENOENT; 724 - procfs = get_fs_type("proc"); 725 - if(procfs == NULL) 761 + proc_mnt = do_kern_mount("proc", 0, "proc", NULL); 762 + if (IS_ERR(proc_mnt)) 726 763 goto out; 727 - 728 - if(list_empty(&procfs->fs_supers)) 729 - goto out; 730 - 731 - proc_sb = list_entry(procfs->fs_supers.next, struct super_block, 732 - s_instances); 733 764 734 765 sb->s_blocksize = 1024; 735 766 sb->s_blocksize_bits = 10; 736 767 sb->s_magic = HPPFS_SUPER_MAGIC; 737 768 sb->s_op = &hppfs_sbops; 738 - 739 - root_inode = hppfs_iget(sb); 740 - if (IS_ERR(root_inode)) { 741 - err = PTR_ERR(root_inode); 742 - goto out; 743 - } 744 - 745 - err = init_inode(root_inode, proc_sb->s_root); 746 - if(err) 747 - goto out_put; 769 + sb->s_fs_info = proc_mnt; 748 770 749 771 err = -ENOMEM; 772 + root_inode = get_inode(sb, proc_mnt->mnt_sb->s_root); 773 + if (!root_inode) 774 + goto out_mntput; 775 + 750 776 sb->s_root = d_alloc_root(root_inode); 751 - if(sb->s_root == NULL) 752 - goto out_put; 777 + if (!sb->s_root) 778 + goto out_iput; 753 779 754 - hppfs_read_inode(root_inode); 780 + return 0; 755 781 756 - return(0); 757 - 758 - out_put: 782 + out_iput: 759 783 iput(root_inode); 784 + out_mntput: 785 + mntput(proc_mnt); 760 786 out: 761 787 return(err); 762 788 } ··· 780 802 781 803 static int __init init_hppfs(void) 782 804 { 783 - return(register_filesystem(&hppfs_type)); 805 + return register_filesystem(&hppfs_type); 784 806 } 785 807 786 808 static void __exit exit_hppfs(void) ··· 791 813 module_init(init_hppfs) 792 814 module_exit(exit_hppfs) 793 815 MODULE_LICENSE("GPL"); 794 - 795 - /* 796 - * Overrides for Emacs so that we follow Linus's tabbing style. 797 - * Emacs will notice this stuff at the end of the file and automatically 798 - * adjust the settings for this buffer only. This must remain at the end 799 - * of the file. 800 - * --------------------------------------------------------------------------- 801 - * Local variables: 802 - * c-file-style: "linux" 803 - * End: 804 - */
+1 -1
fs/hugetlbfs/inode.c
··· 954 954 FMODE_WRITE | FMODE_READ, 955 955 &hugetlbfs_file_operations); 956 956 if (!file) 957 - goto out_inode; 957 + goto out_dentry; /* inode is already attached */ 958 958 959 959 return file; 960 960
+32 -31
fs/namei.c
··· 106 106 * any extra contention... 107 107 */ 108 108 109 - static int link_path_walk(const char *name, struct nameidata *nd); 109 + static int __link_path_walk(const char *name, struct nameidata *nd); 110 110 111 111 /* In order to reduce some races, while at the same time doing additional 112 112 * checking and hopefully speeding things up, we copy filenames to the ··· 561 561 path_get(&fs->root); 562 562 read_unlock(&fs->lock); 563 563 return 1; 564 + } 565 + 566 + /* 567 + * Wrapper to retry pathname resolution whenever the underlying 568 + * file system returns an ESTALE. 569 + * 570 + * Retry the whole path once, forcing real lookup requests 571 + * instead of relying on the dcache. 572 + */ 573 + static __always_inline int link_path_walk(const char *name, struct nameidata *nd) 574 + { 575 + struct path save = nd->path; 576 + int result; 577 + 578 + /* make sure the stuff we saved doesn't go away */ 579 + dget(save.dentry); 580 + mntget(save.mnt); 581 + 582 + result = __link_path_walk(name, nd); 583 + if (result == -ESTALE) { 584 + /* nd->path had been dropped */ 585 + nd->path = save; 586 + dget(nd->path.dentry); 587 + mntget(nd->path.mnt); 588 + nd->flags |= LOOKUP_REVAL; 589 + result = __link_path_walk(name, nd); 590 + } 591 + 592 + path_put(&save); 593 + 594 + return result; 564 595 } 565 596 566 597 static __always_inline int __vfs_follow_link(struct nameidata *nd, const char *link) ··· 1049 1018 path_put(&nd->path); 1050 1019 return_err: 1051 1020 return err; 1052 - } 1053 - 1054 - /* 1055 - * Wrapper to retry pathname resolution whenever the underlying 1056 - * file system returns an ESTALE. 1057 - * 1058 - * Retry the whole path once, forcing real lookup requests 1059 - * instead of relying on the dcache. 1060 - */ 1061 - static int link_path_walk(const char *name, struct nameidata *nd) 1062 - { 1063 - struct nameidata save = *nd; 1064 - int result; 1065 - 1066 - /* make sure the stuff we saved doesn't go away */ 1067 - dget(save.path.dentry); 1068 - mntget(save.path.mnt); 1069 - 1070 - result = __link_path_walk(name, nd); 1071 - if (result == -ESTALE) { 1072 - *nd = save; 1073 - dget(nd->path.dentry); 1074 - mntget(nd->path.mnt); 1075 - nd->flags |= LOOKUP_REVAL; 1076 - result = __link_path_walk(name, nd); 1077 - } 1078 - 1079 - path_put(&save.path); 1080 - 1081 - return result; 1082 1021 } 1083 1022 1084 1023 static int path_walk(const char *name, struct nameidata *nd)
+12
fs/open.c
··· 903 903 int error; 904 904 struct file *f; 905 905 906 + /* 907 + * We must always pass in a valid mount pointer. Historically 908 + * callers got away with not passing it, but we must enforce this at 909 + * the earliest possible point now to avoid strange problems deep in the 910 + * filesystem stack. 911 + */ 912 + if (!mnt) { 913 + printk(KERN_WARNING "%s called with NULL vfsmount\n", __func__); 914 + dump_stack(); 915 + return ERR_PTR(-EINVAL); 916 + } 917 + 906 918 error = -ENFILE; 907 919 f = get_empty_filp(); 908 920 if (f == NULL) {
+9 -10
fs/pipe.c
··· 957 957 struct dentry *dentry; 958 958 struct qstr name = { .name = "" }; 959 959 960 - f = get_empty_filp(); 961 - if (!f) 962 - return ERR_PTR(-ENFILE); 963 960 err = -ENFILE; 964 961 inode = get_pipe_inode(); 965 962 if (!inode) 966 - goto err_file; 963 + goto err; 967 964 968 965 err = -ENOMEM; 969 966 dentry = d_alloc(pipe_mnt->mnt_sb->s_root, &name); ··· 975 978 */ 976 979 dentry->d_flags &= ~DCACHE_UNHASHED; 977 980 d_instantiate(dentry, inode); 978 - f->f_path.mnt = mntget(pipe_mnt); 979 - f->f_path.dentry = dentry; 981 + 982 + err = -ENFILE; 983 + f = alloc_file(pipe_mnt, dentry, FMODE_WRITE, &write_pipe_fops); 984 + if (!f) 985 + goto err_dentry; 980 986 f->f_mapping = inode->i_mapping; 981 987 982 988 f->f_flags = O_WRONLY; 983 - f->f_op = &write_pipe_fops; 984 - f->f_mode = FMODE_WRITE; 985 989 f->f_version = 0; 986 990 987 991 return f; 988 992 993 + err_dentry: 994 + dput(dentry); 989 995 err_inode: 990 996 free_pipe_info(inode); 991 997 iput(inode); 992 - err_file: 993 - put_filp(f); 998 + err: 994 999 return ERR_PTR(err); 995 1000 } 996 1001
+30 -80
fs/reiserfs/xattr.c
··· 191 191 dput(xadir); 192 192 if (err) 193 193 xafile = ERR_PTR(err); 194 - return xafile; 195 - } 196 - 197 - /* Opens a file pointer to the attribute associated with inode */ 198 - static struct file *open_xa_file(const struct inode *inode, const char *name, 199 - int flags) 200 - { 201 - struct dentry *xafile; 202 - struct file *fp; 203 - 204 - xafile = get_xa_file_dentry(inode, name, flags); 205 - if (IS_ERR(xafile)) 206 - return ERR_PTR(PTR_ERR(xafile)); 207 194 else if (!xafile->d_inode) { 208 195 dput(xafile); 209 - return ERR_PTR(-ENODATA); 196 + xafile = ERR_PTR(-ENODATA); 210 197 } 211 - 212 - fp = dentry_open(xafile, NULL, O_RDWR); 213 - /* dentry_open dputs the dentry if it fails */ 214 - 215 - return fp; 198 + return xafile; 216 199 } 217 200 218 201 /* ··· 211 228 * we're called with i_mutex held, so there are no worries about the directory 212 229 * changing underneath us. 213 230 */ 214 - static int __xattr_readdir(struct file *filp, void *dirent, filldir_t filldir) 231 + static int __xattr_readdir(struct inode *inode, void *dirent, filldir_t filldir) 215 232 { 216 - struct inode *inode = filp->f_path.dentry->d_inode; 217 233 struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */ 218 234 INITIALIZE_PATH(path_to_entry); 219 235 struct buffer_head *bh; ··· 356 374 * 357 375 */ 358 376 static 359 - int xattr_readdir(struct file *file, filldir_t filler, void *buf) 377 + int xattr_readdir(struct inode *inode, filldir_t filler, void *buf) 360 378 { 361 - struct inode *inode = file->f_path.dentry->d_inode; 362 - int res = -ENOTDIR; 363 - if (!file->f_op || !file->f_op->readdir) 364 - goto out; 379 + int res = -ENOENT; 365 380 mutex_lock_nested(&inode->i_mutex, I_MUTEX_XATTR); 366 - // down(&inode->i_zombie); 367 - res = -ENOENT; 368 381 if (!IS_DEADDIR(inode)) { 369 382 lock_kernel(); 370 - res = __xattr_readdir(file, buf, filler); 383 + res = __xattr_readdir(inode, buf, filler); 371 384 unlock_kernel(); 372 385 } 373 - // up(&inode->i_zombie); 374 386 mutex_unlock(&inode->i_mutex); 375 - out: 376 387 return res; 377 388 } 378 389 ··· 417 442 size_t buffer_size, int flags) 418 443 { 419 444 int err = 0; 420 - struct file *fp; 445 + struct dentry *dentry; 421 446 struct page *page; 422 447 char *data; 423 448 struct address_space *mapping; ··· 435 460 xahash = xattr_hash(buffer, buffer_size); 436 461 437 462 open_file: 438 - fp = open_xa_file(inode, name, flags); 439 - if (IS_ERR(fp)) { 440 - err = PTR_ERR(fp); 463 + dentry = get_xa_file_dentry(inode, name, flags); 464 + if (IS_ERR(dentry)) { 465 + err = PTR_ERR(dentry); 441 466 goto out; 442 467 } 443 468 444 - xinode = fp->f_path.dentry->d_inode; 469 + xinode = dentry->d_inode; 445 470 REISERFS_I(inode)->i_flags |= i_has_xattr_dir; 446 471 447 472 /* we need to copy it off.. */ 448 473 if (xinode->i_nlink > 1) { 449 - fput(fp); 474 + dput(dentry); 450 475 err = reiserfs_xattr_del(inode, name); 451 476 if (err < 0) 452 477 goto out; ··· 460 485 newattrs.ia_size = buffer_size; 461 486 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME; 462 487 mutex_lock_nested(&xinode->i_mutex, I_MUTEX_XATTR); 463 - err = notify_change(fp->f_path.dentry, &newattrs); 488 + err = notify_change(dentry, &newattrs); 464 489 if (err) 465 490 goto out_filp; 466 491 ··· 493 518 rxh->h_hash = cpu_to_le32(xahash); 494 519 } 495 520 496 - err = reiserfs_prepare_write(fp, page, page_offset, 521 + err = reiserfs_prepare_write(NULL, page, page_offset, 497 522 page_offset + chunk + skip); 498 523 if (!err) { 499 524 if (buffer) 500 525 memcpy(data + skip, buffer + buffer_pos, chunk); 501 - err = 502 - reiserfs_commit_write(fp, page, page_offset, 503 - page_offset + chunk + 504 - skip); 526 + err = reiserfs_commit_write(NULL, page, page_offset, 527 + page_offset + chunk + 528 + skip); 505 529 } 506 530 unlock_page(page); 507 531 reiserfs_put_page(page); ··· 522 548 523 549 out_filp: 524 550 mutex_unlock(&xinode->i_mutex); 525 - fput(fp); 551 + dput(dentry); 526 552 527 553 out: 528 554 return err; ··· 536 562 size_t buffer_size) 537 563 { 538 564 ssize_t err = 0; 539 - struct file *fp; 565 + struct dentry *dentry; 540 566 size_t isize; 541 567 size_t file_pos = 0; 542 568 size_t buffer_pos = 0; ··· 552 578 if (get_inode_sd_version(inode) == STAT_DATA_V1) 553 579 return -EOPNOTSUPP; 554 580 555 - fp = open_xa_file(inode, name, FL_READONLY); 556 - if (IS_ERR(fp)) { 557 - err = PTR_ERR(fp); 581 + dentry = get_xa_file_dentry(inode, name, FL_READONLY); 582 + if (IS_ERR(dentry)) { 583 + err = PTR_ERR(dentry); 558 584 goto out; 559 585 } 560 586 561 - xinode = fp->f_path.dentry->d_inode; 587 + xinode = dentry->d_inode; 562 588 isize = xinode->i_size; 563 589 REISERFS_I(inode)->i_flags |= i_has_xattr_dir; 564 590 ··· 626 652 } 627 653 628 654 out_dput: 629 - fput(fp); 655 + dput(dentry); 630 656 631 657 out: 632 658 return err; ··· 716 742 /* This is called w/ inode->i_mutex downed */ 717 743 int reiserfs_delete_xattrs(struct inode *inode) 718 744 { 719 - struct file *fp; 720 745 struct dentry *dir, *root; 721 746 int err = 0; 722 747 ··· 736 763 return 0; 737 764 } 738 765 739 - fp = dentry_open(dir, NULL, O_RDWR); 740 - if (IS_ERR(fp)) { 741 - err = PTR_ERR(fp); 742 - /* dentry_open dputs the dentry if it fails */ 743 - goto out; 744 - } 745 - 746 766 lock_kernel(); 747 - err = xattr_readdir(fp, reiserfs_delete_xattrs_filler, dir); 767 + err = xattr_readdir(dir->d_inode, reiserfs_delete_xattrs_filler, dir); 748 768 if (err) { 749 769 unlock_kernel(); 750 770 goto out_dir; ··· 757 791 unlock_kernel(); 758 792 759 793 out_dir: 760 - fput(fp); 794 + dput(dir); 761 795 762 796 out: 763 797 if (!err) ··· 799 833 800 834 int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs) 801 835 { 802 - struct file *fp; 803 836 struct dentry *dir; 804 837 int err = 0; 805 838 struct reiserfs_chown_buf buf; ··· 822 857 goto out; 823 858 } 824 859 825 - fp = dentry_open(dir, NULL, O_RDWR); 826 - if (IS_ERR(fp)) { 827 - err = PTR_ERR(fp); 828 - /* dentry_open dputs the dentry if it fails */ 829 - goto out; 830 - } 831 - 832 860 lock_kernel(); 833 861 834 862 attrs->ia_valid &= (ATTR_UID | ATTR_GID | ATTR_CTIME); ··· 829 871 buf.attrs = attrs; 830 872 buf.inode = inode; 831 873 832 - err = xattr_readdir(fp, reiserfs_chown_xattrs_filler, &buf); 874 + err = xattr_readdir(dir->d_inode, reiserfs_chown_xattrs_filler, &buf); 833 875 if (err) { 834 876 unlock_kernel(); 835 877 goto out_dir; ··· 839 881 unlock_kernel(); 840 882 841 883 out_dir: 842 - fput(fp); 884 + dput(dir); 843 885 844 886 out: 845 887 attrs->ia_valid = ia_valid; ··· 987 1029 */ 988 1030 ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size) 989 1031 { 990 - struct file *fp; 991 1032 struct dentry *dir; 992 1033 int err = 0; 993 1034 struct reiserfs_listxattr_buf buf; ··· 1009 1052 goto out; 1010 1053 } 1011 1054 1012 - fp = dentry_open(dir, NULL, O_RDWR); 1013 - if (IS_ERR(fp)) { 1014 - err = PTR_ERR(fp); 1015 - /* dentry_open dputs the dentry if it fails */ 1016 - goto out; 1017 - } 1018 - 1019 1055 buf.r_buf = buffer; 1020 1056 buf.r_size = buffer ? size : 0; 1021 1057 buf.r_pos = 0; ··· 1016 1066 1017 1067 REISERFS_I(dentry->d_inode)->i_flags |= i_has_xattr_dir; 1018 1068 1019 - err = xattr_readdir(fp, reiserfs_listxattr_filler, &buf); 1069 + err = xattr_readdir(dir->d_inode, reiserfs_listxattr_filler, &buf); 1020 1070 if (err) 1021 1071 goto out_dir; 1022 1072 ··· 1026 1076 err = buf.r_pos; 1027 1077 1028 1078 out_dir: 1029 - fput(fp); 1079 + dput(dir); 1030 1080 1031 1081 out: 1032 1082 reiserfs_read_unlock_xattr_i(dentry->d_inode);
+1
fs/super.c
··· 945 945 put_filesystem(type); 946 946 return mnt; 947 947 } 948 + EXPORT_SYMBOL_GPL(do_kern_mount); 948 949 949 950 struct vfsmount *kern_mount_data(struct file_system_type *type, void *data) 950 951 {
+2
mm/tiny-shmem.c
··· 88 88 89 89 close_file: 90 90 put_filp(file); 91 + return ERR_PTR(error); 92 + 91 93 put_dentry: 92 94 dput(dentry); 93 95 put_memory: