Skip to content

Commit e371d46

Browse files
committed
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: merge fchmod() and fchmodat() guts, kill ancient broken kludge xfs: fix misspelled S_IS...() xfs: get rid of open-coded S_ISREG(), etc. vfs: document locking requirements for d_move, __d_move and d_materialise_unique omfs: fix (mode & S_IFDIR) abuse btrfs: S_ISREG(mode) is not mode & S_IFREG... ima: fmode_t misspelled as mode_t... pci-label.c: size_t misspelled as mode_t jffs2: S_ISLNK(mode & S_IFMT) is pointless snd_msnd ->mode is fmode_t, not mode_t v9fs_iop_get_acl: get rid of unused variable vfs: dont chain pipe/anon/socket on superblock s_inodes list Documentation: Exporting: update description of d_splice_alias fs: add missing unlock in default_llseek()
2 parents b0189cd + e57712e commit e371d46

File tree

25 files changed

+133
-120
lines changed

25 files changed

+133
-120
lines changed

Documentation/filesystems/nfs/Exporting

+8-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,14 @@ For a filesystem to be exportable it must:
9292
1/ provide the filehandle fragment routines described below.
9393
2/ make sure that d_splice_alias is used rather than d_add
9494
when ->lookup finds an inode for a given parent and name.
95-
Typically the ->lookup routine will end with a:
95+
96+
If inode is NULL, d_splice_alias(inode, dentry) is eqivalent to
97+
98+
d_add(dentry, inode), NULL
99+
100+
Similarly, d_splice_alias(ERR_PTR(err), dentry) = ERR_PTR(err)
101+
102+
Typically the ->lookup routine will simply end with a:
96103

97104
return d_splice_alias(inode, dentry);
98105
}

drivers/pci/pci-label.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ enum smbios_attr_enum {
5555
SMBIOS_ATTR_INSTANCE_SHOW,
5656
};
5757

58-
static mode_t
58+
static size_t
5959
find_smbios_instance_string(struct pci_dev *pdev, char *buf,
6060
enum smbios_attr_enum attribute)
6161
{

fs/anon_inodes.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ EXPORT_SYMBOL_GPL(anon_inode_getfd);
187187
*/
188188
static struct inode *anon_inode_mkinode(void)
189189
{
190-
struct inode *inode = new_inode(anon_inode_mnt->mnt_sb);
190+
struct inode *inode = new_inode_pseudo(anon_inode_mnt->mnt_sb);
191191

192192
if (!inode)
193193
return ERR_PTR(-ENOMEM);

fs/btrfs/inode.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -4467,7 +4467,7 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
44674467
inode->i_generation = BTRFS_I(inode)->generation;
44684468
btrfs_set_inode_space_info(root, inode);
44694469

4470-
if (mode & S_IFDIR)
4470+
if (S_ISDIR(mode))
44714471
owner = 0;
44724472
else
44734473
owner = 1;
@@ -4512,7 +4512,7 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
45124512

45134513
btrfs_inherit_iflags(inode, dir);
45144514

4515-
if ((mode & S_IFREG)) {
4515+
if (S_ISREG(mode)) {
45164516
if (btrfs_test_opt(root, NODATASUM))
45174517
BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM;
45184518
if (btrfs_test_opt(root, NODATACOW) ||

fs/dcache.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -2138,8 +2138,9 @@ static void dentry_unlock_parents_for_move(struct dentry *dentry,
21382138
* @target: new dentry
21392139
*
21402140
* Update the dcache to reflect the move of a file name. Negative
2141-
* dcache entries should not be moved in this way. Caller hold
2142-
* rename_lock.
2141+
* dcache entries should not be moved in this way. Caller must hold
2142+
* rename_lock, the i_mutex of the source and target directories,
2143+
* and the sb->s_vfs_rename_mutex if they differ. See lock_rename().
21432144
*/
21442145
static void __d_move(struct dentry * dentry, struct dentry * target)
21452146
{
@@ -2202,7 +2203,8 @@ static void __d_move(struct dentry * dentry, struct dentry * target)
22022203
* @target: new dentry
22032204
*
22042205
* Update the dcache to reflect the move of a file name. Negative
2205-
* dcache entries should not be moved in this way.
2206+
* dcache entries should not be moved in this way. See the locking
2207+
* requirements for __d_move.
22062208
*/
22072209
void d_move(struct dentry *dentry, struct dentry *target)
22082210
{
@@ -2320,7 +2322,8 @@ static void __d_materialise_dentry(struct dentry *dentry, struct dentry *anon)
23202322
* @inode: inode to bind to the dentry, to which aliases may be attached
23212323
*
23222324
* Introduces an dentry into the tree, substituting an extant disconnected
2323-
* root directory alias in its place if there is one
2325+
* root directory alias in its place if there is one. Caller must hold the
2326+
* i_mutex of the parent directory.
23242327
*/
23252328
struct dentry *d_materialise_unique(struct dentry *dentry, struct inode *inode)
23262329
{

fs/inode.c

+30-9
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,11 @@ EXPORT_SYMBOL_GPL(inode_sb_list_add);
361361

362362
static inline void inode_sb_list_del(struct inode *inode)
363363
{
364-
spin_lock(&inode_sb_list_lock);
365-
list_del_init(&inode->i_sb_list);
366-
spin_unlock(&inode_sb_list_lock);
364+
if (!list_empty(&inode->i_sb_list)) {
365+
spin_lock(&inode_sb_list_lock);
366+
list_del_init(&inode->i_sb_list);
367+
spin_unlock(&inode_sb_list_lock);
368+
}
367369
}
368370

369371
static unsigned long hash(struct super_block *sb, unsigned long hashval)
@@ -795,6 +797,29 @@ unsigned int get_next_ino(void)
795797
}
796798
EXPORT_SYMBOL(get_next_ino);
797799

800+
/**
801+
* new_inode_pseudo - obtain an inode
802+
* @sb: superblock
803+
*
804+
* Allocates a new inode for given superblock.
805+
* Inode wont be chained in superblock s_inodes list
806+
* This means :
807+
* - fs can't be unmount
808+
* - quotas, fsnotify, writeback can't work
809+
*/
810+
struct inode *new_inode_pseudo(struct super_block *sb)
811+
{
812+
struct inode *inode = alloc_inode(sb);
813+
814+
if (inode) {
815+
spin_lock(&inode->i_lock);
816+
inode->i_state = 0;
817+
spin_unlock(&inode->i_lock);
818+
INIT_LIST_HEAD(&inode->i_sb_list);
819+
}
820+
return inode;
821+
}
822+
798823
/**
799824
* new_inode - obtain an inode
800825
* @sb: superblock
@@ -813,13 +838,9 @@ struct inode *new_inode(struct super_block *sb)
813838

814839
spin_lock_prefetch(&inode_sb_list_lock);
815840

816-
inode = alloc_inode(sb);
817-
if (inode) {
818-
spin_lock(&inode->i_lock);
819-
inode->i_state = 0;
820-
spin_unlock(&inode->i_lock);
841+
inode = new_inode_pseudo(sb);
842+
if (inode)
821843
inode_sb_list_add(inode);
822-
}
823844
return inode;
824845
}
825846
EXPORT_SYMBOL(new_inode);

fs/jffs2/fs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
8080
ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
8181
if (ret) {
8282
jffs2_free_raw_inode(ri);
83-
if (S_ISLNK(inode->i_mode & S_IFMT))
83+
if (S_ISLNK(inode->i_mode))
8484
kfree(mdata);
8585
return ret;
8686
}

fs/omfs/dir.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ int omfs_make_empty(struct inode *inode, struct super_block *sb)
9393

9494
memset(bh->b_data, 0, sizeof(struct omfs_inode));
9595

96-
if (inode->i_mode & S_IFDIR) {
96+
if (S_ISDIR(inode->i_mode)) {
9797
memset(&bh->b_data[OMFS_DIR_START], 0xff,
9898
sbi->s_sys_blocksize - OMFS_DIR_START);
9999
} else

fs/open.c

+28-50
Original file line numberDiff line numberDiff line change
@@ -446,74 +446,52 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
446446
return error;
447447
}
448448

449-
SYSCALL_DEFINE2(fchmod, unsigned int, fd, mode_t, mode)
449+
static int chmod_common(struct path *path, umode_t mode)
450450
{
451-
struct inode * inode;
452-
struct dentry * dentry;
453-
struct file * file;
454-
int err = -EBADF;
451+
struct inode *inode = path->dentry->d_inode;
455452
struct iattr newattrs;
453+
int error;
456454

457-
file = fget(fd);
458-
if (!file)
459-
goto out;
460-
461-
dentry = file->f_path.dentry;
462-
inode = dentry->d_inode;
463-
464-
audit_inode(NULL, dentry);
465-
466-
err = mnt_want_write_file(file);
467-
if (err)
468-
goto out_putf;
455+
error = mnt_want_write(path->mnt);
456+
if (error)
457+
return error;
469458
mutex_lock(&inode->i_mutex);
470-
err = security_path_chmod(dentry, file->f_vfsmnt, mode);
471-
if (err)
459+
error = security_path_chmod(path->dentry, path->mnt, mode);
460+
if (error)
472461
goto out_unlock;
473-
if (mode == (mode_t) -1)
474-
mode = inode->i_mode;
475462
newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
476463
newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
477-
err = notify_change(dentry, &newattrs);
464+
error = notify_change(path->dentry, &newattrs);
478465
out_unlock:
479466
mutex_unlock(&inode->i_mutex);
480-
mnt_drop_write(file->f_path.mnt);
481-
out_putf:
482-
fput(file);
483-
out:
467+
mnt_drop_write(path->mnt);
468+
return error;
469+
}
470+
471+
SYSCALL_DEFINE2(fchmod, unsigned int, fd, mode_t, mode)
472+
{
473+
struct file * file;
474+
int err = -EBADF;
475+
476+
file = fget(fd);
477+
if (file) {
478+
audit_inode(NULL, file->f_path.dentry);
479+
err = chmod_common(&file->f_path, mode);
480+
fput(file);
481+
}
484482
return err;
485483
}
486484

487485
SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, mode_t, mode)
488486
{
489487
struct path path;
490-
struct inode *inode;
491488
int error;
492-
struct iattr newattrs;
493489

494490
error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
495-
if (error)
496-
goto out;
497-
inode = path.dentry->d_inode;
498-
499-
error = mnt_want_write(path.mnt);
500-
if (error)
501-
goto dput_and_out;
502-
mutex_lock(&inode->i_mutex);
503-
error = security_path_chmod(path.dentry, path.mnt, mode);
504-
if (error)
505-
goto out_unlock;
506-
if (mode == (mode_t) -1)
507-
mode = inode->i_mode;
508-
newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
509-
newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
510-
error = notify_change(path.dentry, &newattrs);
511-
out_unlock:
512-
mutex_unlock(&inode->i_mutex);
513-
mnt_drop_write(path.mnt);
514-
dput_and_out:
515-
path_put(&path);
516-
out:
491+
if (!error) {
492+
error = chmod_common(&path, mode);
493+
path_put(&path);
494+
}
517495
return error;
518496
}
519497

fs/pipe.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ static const struct dentry_operations pipefs_dentry_operations = {
948948

949949
static struct inode * get_pipe_inode(void)
950950
{
951-
struct inode *inode = new_inode(pipe_mnt->mnt_sb);
951+
struct inode *inode = new_inode_pseudo(pipe_mnt->mnt_sb);
952952
struct pipe_inode_info *pipe;
953953

954954
if (!inode)

fs/read_write.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,21 @@ loff_t default_llseek(struct file *file, loff_t offset, int origin)
166166
* long as offset isn't at the end of the file then the
167167
* offset is data.
168168
*/
169-
if (offset >= inode->i_size)
170-
return -ENXIO;
169+
if (offset >= inode->i_size) {
170+
retval = -ENXIO;
171+
goto out;
172+
}
171173
break;
172174
case SEEK_HOLE:
173175
/*
174176
* There is a virtual hole at the end of the file, so
175177
* as long as offset isn't i_size or larger, return
176178
* i_size.
177179
*/
178-
if (offset >= inode->i_size)
179-
return -ENXIO;
180+
if (offset >= inode->i_size) {
181+
retval = -ENXIO;
182+
goto out;
183+
}
180184
offset = inode->i_size;
181185
break;
182186
}

fs/xfs/linux-2.6/xfs_ioctl.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ xfs_open_by_handle(
265265
return PTR_ERR(filp);
266266
}
267267

268-
if (inode->i_mode & S_IFREG) {
268+
if (S_ISREG(inode->i_mode)) {
269269
filp->f_flags |= O_NOATIME;
270270
filp->f_mode |= FMODE_NOCMTIME;
271271
}
@@ -850,14 +850,14 @@ xfs_set_diflags(
850850
di_flags |= XFS_DIFLAG_NODEFRAG;
851851
if (xflags & XFS_XFLAG_FILESTREAM)
852852
di_flags |= XFS_DIFLAG_FILESTREAM;
853-
if ((ip->i_d.di_mode & S_IFMT) == S_IFDIR) {
853+
if (S_ISDIR(ip->i_d.di_mode)) {
854854
if (xflags & XFS_XFLAG_RTINHERIT)
855855
di_flags |= XFS_DIFLAG_RTINHERIT;
856856
if (xflags & XFS_XFLAG_NOSYMLINKS)
857857
di_flags |= XFS_DIFLAG_NOSYMLINKS;
858858
if (xflags & XFS_XFLAG_EXTSZINHERIT)
859859
di_flags |= XFS_DIFLAG_EXTSZINHERIT;
860-
} else if ((ip->i_d.di_mode & S_IFMT) == S_IFREG) {
860+
} else if (S_ISREG(ip->i_d.di_mode)) {
861861
if (xflags & XFS_XFLAG_REALTIME)
862862
di_flags |= XFS_DIFLAG_REALTIME;
863863
if (xflags & XFS_XFLAG_EXTSIZE)

fs/xfs/xfs_bmap.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ xfs_bmap_add_attrfork_local(
414414

415415
if (ip->i_df.if_bytes <= XFS_IFORK_DSIZE(ip))
416416
return 0;
417-
if ((ip->i_d.di_mode & S_IFMT) == S_IFDIR) {
417+
if (S_ISDIR(ip->i_d.di_mode)) {
418418
mp = ip->i_mount;
419419
memset(&dargs, 0, sizeof(dargs));
420420
dargs.dp = ip;
@@ -3344,8 +3344,7 @@ xfs_bmap_local_to_extents(
33443344
* We don't want to deal with the case of keeping inode data inline yet.
33453345
* So sending the data fork of a regular inode is invalid.
33463346
*/
3347-
ASSERT(!((ip->i_d.di_mode & S_IFMT) == S_IFREG &&
3348-
whichfork == XFS_DATA_FORK));
3347+
ASSERT(!(S_ISREG(ip->i_d.di_mode) && whichfork == XFS_DATA_FORK));
33493348
ifp = XFS_IFORK_PTR(ip, whichfork);
33503349
ASSERT(XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_LOCAL);
33513350
flags = 0;
@@ -4052,7 +4051,7 @@ xfs_bmap_one_block(
40524051

40534052
#ifndef DEBUG
40544053
if (whichfork == XFS_DATA_FORK) {
4055-
return ((ip->i_d.di_mode & S_IFMT) == S_IFREG) ?
4054+
return S_ISREG(ip->i_d.di_mode) ?
40564055
(ip->i_size == ip->i_mount->m_sb.sb_blocksize) :
40574056
(ip->i_d.di_size == ip->i_mount->m_sb.sb_blocksize);
40584057
}

0 commit comments

Comments
 (0)