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

Pull vfs fixes from Al Viro:
"atomic_open-related fixes (Miklos' series, with EEXIST-related parts
replaced with fix in fs/namei.c:atomic_open() instead of messing with
the instances) + race fix in autofs + leak on failure exit in 9p"

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
9p: don't forget to destroy inode cache if fscache registration fails
atomic_open: take care of EEXIST in no-open case with O_CREAT|O_EXCL in fs/namei.c
vfs: don't set FILE_CREATED before calling ->atomic_open()
nfs: set FILE_CREATED
gfs2: set FILE_CREATED
cifs: fix filp leak in cifs_atomic_open()
vfs: improve i_op->atomic_open() documentation
autofs4: close the races around autofs4_notify_daemon()

+62 -43
+7 -7
Documentation/filesystems/vfs.txt
··· 359 359 ssize_t (*listxattr) (struct dentry *, char *, size_t); 360 360 int (*removexattr) (struct dentry *, const char *); 361 361 void (*update_time)(struct inode *, struct timespec *, int); 362 - int (*atomic_open)(struct inode *, struct dentry *, 362 + int (*atomic_open)(struct inode *, struct dentry *, struct file *, 363 + unsigned open_flag, umode_t create_mode, int *opened); 363 364 int (*tmpfile) (struct inode *, struct dentry *, umode_t); 364 - } ____cacheline_aligned; 365 - struct file *, unsigned open_flag, 366 - umode_t create_mode, int *opened); 367 365 }; 368 366 369 367 Again, all methods are called without any locks being held, unless ··· 468 470 method the filesystem can look up, possibly create and open the file in 469 471 one atomic operation. If it cannot perform this (e.g. the file type 470 472 turned out to be wrong) it may signal this by returning 1 instead of 471 - usual 0 or -ve . This method is only called if the last 472 - component is negative or needs lookup. Cached positive dentries are 473 - still handled by f_op->open(). 473 + usual 0 or -ve . This method is only called if the last component is 474 + negative or needs lookup. Cached positive dentries are still handled by 475 + f_op->open(). If the file was created, the FILE_CREATED flag should be 476 + set in "opened". In case of O_EXCL the method must only succeed if the 477 + file didn't exist and hence FILE_CREATED shall always be set on success. 474 478 475 479 tmpfile: called in the end of O_TMPFILE open(). Optional, equivalent to 476 480 atomically creating, opening and unlinking a file in given directory.
+4 -3
fs/9p/v9fs.c
··· 603 603 if (ret < 0) 604 604 return ret; 605 605 #ifdef CONFIG_9P_FSCACHE 606 - return fscache_register_netfs(&v9fs_cache_netfs); 607 - #else 608 - return ret; 606 + ret = fscache_register_netfs(&v9fs_cache_netfs); 607 + if (ret < 0) 608 + v9fs_destroy_inode_cache(); 609 609 #endif 610 + return ret; 610 611 } 611 612 612 613 static void v9fs_cache_unregister(void)
+1 -7
fs/9p/vfs_inode_dotl.c
··· 267 267 } 268 268 269 269 /* Only creates */ 270 - if (!(flags & O_CREAT)) 270 + if (!(flags & O_CREAT) || dentry->d_inode) 271 271 return finish_no_open(file, res); 272 - else if (dentry->d_inode) { 273 - if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) 274 - return -EEXIST; 275 - else 276 - return finish_no_open(file, res); 277 - } 278 272 279 273 v9ses = v9fs_inode2v9ses(dir); 280 274
+3 -10
fs/autofs4/waitq.c
··· 109 109 110 110 pkt.hdr.proto_version = sbi->version; 111 111 pkt.hdr.type = type; 112 - mutex_lock(&sbi->wq_mutex); 113 112 114 - /* Check if we have become catatonic */ 115 - if (sbi->catatonic) { 116 - mutex_unlock(&sbi->wq_mutex); 117 - return; 118 - } 119 113 switch (type) { 120 114 /* Kernel protocol v4 missing and expire packets */ 121 115 case autofs_ptype_missing: ··· 421 427 wq->tgid = current->tgid; 422 428 wq->status = -EINTR; /* Status return if interrupted */ 423 429 wq->wait_ctr = 2; 424 - mutex_unlock(&sbi->wq_mutex); 425 430 426 431 if (sbi->version < 5) { 427 432 if (notify == NFY_MOUNT) ··· 442 449 (unsigned long) wq->wait_queue_token, wq->name.len, 443 450 wq->name.name, notify); 444 451 445 - /* autofs4_notify_daemon() may block */ 452 + /* autofs4_notify_daemon() may block; it will unlock ->wq_mutex */ 446 453 autofs4_notify_daemon(sbi, wq, type); 447 454 } else { 448 455 wq->wait_ctr++; 449 - mutex_unlock(&sbi->wq_mutex); 450 - kfree(qstr.name); 451 456 DPRINTK("existing wait id = 0x%08lx, name = %.*s, nfy=%d", 452 457 (unsigned long) wq->wait_queue_token, wq->name.len, 453 458 wq->name.name, notify); 459 + mutex_unlock(&sbi->wq_mutex); 460 + kfree(qstr.name); 454 461 } 455 462 456 463 /*
+1
fs/cifs/dir.c
··· 500 500 if (server->ops->close) 501 501 server->ops->close(xid, tcon, &fid); 502 502 cifs_del_pending_open(&open); 503 + fput(file); 503 504 rc = -ENOMEM; 504 505 } 505 506
+3 -1
fs/gfs2/inode.c
··· 694 694 695 695 mark_inode_dirty(inode); 696 696 d_instantiate(dentry, inode); 697 - if (file) 697 + if (file) { 698 + *opened |= FILE_CREATED; 698 699 error = finish_open(file, dentry, gfs2_open_common, opened); 700 + } 699 701 gfs2_glock_dq_uninit(ghs); 700 702 gfs2_glock_dq_uninit(ghs + 1); 701 703 return error;
+22 -12
fs/namei.c
··· 2656 2656 int acc_mode; 2657 2657 int create_error = 0; 2658 2658 struct dentry *const DENTRY_NOT_SET = (void *) -1UL; 2659 + bool excl; 2659 2660 2660 2661 BUG_ON(dentry->d_inode); 2661 2662 ··· 2670 2669 if ((open_flag & O_CREAT) && !IS_POSIXACL(dir)) 2671 2670 mode &= ~current_umask(); 2672 2671 2673 - if ((open_flag & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT)) { 2672 + excl = (open_flag & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT); 2673 + if (excl) 2674 2674 open_flag &= ~O_TRUNC; 2675 - *opened |= FILE_CREATED; 2676 - } 2677 2675 2678 2676 /* 2679 2677 * Checking write permission is tricky, bacuse we don't know if we are ··· 2725 2725 goto out; 2726 2726 } 2727 2727 2728 - acc_mode = op->acc_mode; 2729 - if (*opened & FILE_CREATED) { 2730 - fsnotify_create(dir, dentry); 2731 - acc_mode = MAY_OPEN; 2732 - } 2733 - 2734 2728 if (error) { /* returned 1, that is */ 2735 2729 if (WARN_ON(file->f_path.dentry == DENTRY_NOT_SET)) { 2736 2730 error = -EIO; ··· 2734 2740 dput(dentry); 2735 2741 dentry = file->f_path.dentry; 2736 2742 } 2737 - if (create_error && dentry->d_inode == NULL) { 2738 - error = create_error; 2739 - goto out; 2743 + if (*opened & FILE_CREATED) 2744 + fsnotify_create(dir, dentry); 2745 + if (!dentry->d_inode) { 2746 + WARN_ON(*opened & FILE_CREATED); 2747 + if (create_error) { 2748 + error = create_error; 2749 + goto out; 2750 + } 2751 + } else { 2752 + if (excl && !(*opened & FILE_CREATED)) { 2753 + error = -EEXIST; 2754 + goto out; 2755 + } 2740 2756 } 2741 2757 goto looked_up; 2742 2758 } ··· 2755 2751 * We didn't have the inode before the open, so check open permission 2756 2752 * here. 2757 2753 */ 2754 + acc_mode = op->acc_mode; 2755 + if (*opened & FILE_CREATED) { 2756 + WARN_ON(!(open_flag & O_CREAT)); 2757 + fsnotify_create(dir, dentry); 2758 + acc_mode = MAY_OPEN; 2759 + } 2758 2760 error = may_open(&file->f_path, acc_mode, open_flag); 2759 2761 if (error) 2760 2762 fput(file);
+3
fs/nfs/dir.c
··· 1392 1392 { 1393 1393 int err; 1394 1394 1395 + if ((open_flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) 1396 + *opened |= FILE_CREATED; 1397 + 1395 1398 err = finish_open(file, dentry, do_open, opened); 1396 1399 if (err) 1397 1400 goto out;
+18 -3
fs/open.c
··· 744 744 745 745 /** 746 746 * finish_open - finish opening a file 747 - * @od: opaque open data 747 + * @file: file pointer 748 748 * @dentry: pointer to dentry 749 749 * @open: open callback 750 + * @opened: state of open 750 751 * 751 752 * This can be used to finish opening a file passed to i_op->atomic_open(). 752 753 * 753 754 * If the open callback is set to NULL, then the standard f_op->open() 754 755 * filesystem callback is substituted. 756 + * 757 + * NB: the dentry reference is _not_ consumed. If, for example, the dentry is 758 + * the return value of d_splice_alias(), then the caller needs to perform dput() 759 + * on it after finish_open(). 760 + * 761 + * On successful return @file is a fully instantiated open file. After this, if 762 + * an error occurs in ->atomic_open(), it needs to clean up with fput(). 763 + * 764 + * Returns zero on success or -errno if the open failed. 755 765 */ 756 766 int finish_open(struct file *file, struct dentry *dentry, 757 767 int (*open)(struct inode *, struct file *), ··· 782 772 /** 783 773 * finish_no_open - finish ->atomic_open() without opening the file 784 774 * 785 - * @od: opaque open data 775 + * @file: file pointer 786 776 * @dentry: dentry or NULL (as returned from ->lookup()) 787 777 * 788 778 * This can be used to set the result of a successful lookup in ->atomic_open(). 789 - * The filesystem's atomic_open() method shall return NULL after calling this. 779 + * 780 + * NB: unlike finish_open() this function does consume the dentry reference and 781 + * the caller need not dput() it. 782 + * 783 + * Returns "1" which must be the return value of ->atomic_open() after having 784 + * called this function. 790 785 */ 791 786 int finish_no_open(struct file *file, struct dentry *dentry) 792 787 {