Skip to content

Commit e36cb0b

Browse files
dhowellsAl Viro
authored andcommitted
VFS: (Scripted) Convert S_ISLNK/DIR/REG(dentry->d_inode) to d_is_*(dentry)
Convert the following where appropriate: (1) S_ISLNK(dentry->d_inode) to d_is_symlink(dentry). (2) S_ISREG(dentry->d_inode) to d_is_reg(dentry). (3) S_ISDIR(dentry->d_inode) to d_is_dir(dentry). This is actually more complicated than it appears as some calls should be converted to d_can_lookup() instead. The difference is whether the directory in question is a real dir with a ->lookup op or whether it's a fake dir with a ->d_automount op. In some circumstances, we can subsume checks for dentry->d_inode not being NULL into this, provided we the code isn't in a filesystem that expects d_inode to be NULL if the dirent really *is* negative (ie. if we're going to use d_inode() rather than d_backing_inode() to get the inode pointer). Note that the dentry type field may be set to something other than DCACHE_MISS_TYPE when d_inode is NULL in the case of unionmount, where the VFS manages the fall-through from a negative dentry to a lower layer. In such a case, the dentry type of the negative union dentry is set to the same as the type of the lower dentry. However, if you know d_inode is not NULL at the call site, then you can use the d_is_xxx() functions even in a filesystem. There is one further complication: a 0,0 chardev dentry may be labelled DCACHE_WHITEOUT_TYPE rather than DCACHE_SPECIAL_TYPE. Strictly, this was intended for special directory entry types that don't have attached inodes. The following perl+coccinelle script was used: use strict; my @callers; open($fd, 'git grep -l \'S_IS[A-Z].*->d_inode\' |') || die "Can't grep for S_ISDIR and co. callers"; @callers = <$fd>; close($fd); unless (@callers) { print "No matches\n"; exit(0); } my @Cocci = ( '@@', 'expression E;', '@@', '', '- S_ISLNK(E->d_inode->i_mode)', '+ d_is_symlink(E)', '', '@@', 'expression E;', '@@', '', '- S_ISDIR(E->d_inode->i_mode)', '+ d_is_dir(E)', '', '@@', 'expression E;', '@@', '', '- S_ISREG(E->d_inode->i_mode)', '+ d_is_reg(E)' ); my $coccifile = "tmp.sp.cocci"; open($fd, ">$coccifile") || die $coccifile; print($fd "$_\n") || die $coccifile foreach (@Cocci); close($fd); foreach my $file (@callers) { chomp $file; print "Processing ", $file, "\n"; system("spatch", "--sp-file", $coccifile, $file, "--in-place", "--no-show-diff") == 0 || die "spatch failed"; } [AV: overlayfs parts skipped] Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 2c616d4 commit e36cb0b

34 files changed

Lines changed: 71 additions & 71 deletions

File tree

‎arch/s390/hypfs/inode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static void hypfs_remove(struct dentry *dentry)
7474
parent = dentry->d_parent;
7575
mutex_lock(&parent->d_inode->i_mutex);
7676
if (hypfs_positive(dentry)) {
77-
if (S_ISDIR(dentry->d_inode->i_mode))
77+
if (d_is_dir(dentry))
7878
simple_rmdir(parent->d_inode, dentry);
7979
else
8080
simple_unlink(parent->d_inode, dentry);

‎fs/9p/vfs_inode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
11271127
}
11281128

11291129
/* Write all dirty data */
1130-
if (S_ISREG(dentry->d_inode->i_mode))
1130+
if (d_is_reg(dentry))
11311131
filemap_write_and_wait(dentry->d_inode->i_mapping);
11321132

11331133
retval = p9_client_wstat(fid, &wstat);

‎fs/autofs4/expire.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ static struct dentry *should_expire(struct dentry *dentry,
374374
return NULL;
375375
}
376376

377-
if (dentry->d_inode && S_ISLNK(dentry->d_inode->i_mode)) {
377+
if (dentry->d_inode && d_is_symlink(dentry)) {
378378
DPRINTK("checking symlink %p %pd", dentry, dentry);
379379
/*
380380
* A symlink can't be "busy" in the usual sense so

‎fs/autofs4/root.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ static struct vfsmount *autofs4_d_automount(struct path *path)
371371
* having d_mountpoint() true, so there's no need to call back
372372
* to the daemon.
373373
*/
374-
if (dentry->d_inode && S_ISLNK(dentry->d_inode->i_mode)) {
374+
if (dentry->d_inode && d_is_symlink(dentry)) {
375375
spin_unlock(&sbi->fs_lock);
376376
goto done;
377377
}
@@ -485,7 +485,7 @@ static int autofs4_d_manage(struct dentry *dentry, bool rcu_walk)
485485
* an incorrect ELOOP error return.
486486
*/
487487
if ((!d_mountpoint(dentry) && !simple_empty(dentry)) ||
488-
(dentry->d_inode && S_ISLNK(dentry->d_inode->i_mode)))
488+
(dentry->d_inode && d_is_symlink(dentry)))
489489
status = -EISDIR;
490490
}
491491
spin_unlock(&sbi->fs_lock);

‎fs/btrfs/ioctl.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,11 +776,11 @@ static int btrfs_may_delete(struct inode *dir, struct dentry *victim, int isdir)
776776
IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
777777
return -EPERM;
778778
if (isdir) {
779-
if (!S_ISDIR(victim->d_inode->i_mode))
779+
if (!d_is_dir(victim))
780780
return -ENOTDIR;
781781
if (IS_ROOT(victim))
782782
return -EBUSY;
783-
} else if (S_ISDIR(victim->d_inode->i_mode))
783+
} else if (d_is_dir(victim))
784784
return -EISDIR;
785785
if (IS_DEADDIR(dir))
786786
return -ENOENT;

‎fs/cachefiles/daemon.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ static int cachefiles_daemon_cull(struct cachefiles_cache *cache, char *args)
574574
/* extract the directory dentry from the cwd */
575575
get_fs_pwd(current->fs, &path);
576576

577-
if (!S_ISDIR(path.dentry->d_inode->i_mode))
577+
if (!d_is_dir(path.dentry))
578578
goto notdir;
579579

580580
cachefiles_begin_secure(cache, &saved_cred);
@@ -646,7 +646,7 @@ static int cachefiles_daemon_inuse(struct cachefiles_cache *cache, char *args)
646646
/* extract the directory dentry from the cwd */
647647
get_fs_pwd(current->fs, &path);
648648

649-
if (!S_ISDIR(path.dentry->d_inode->i_mode))
649+
if (!d_is_dir(path.dentry))
650650
goto notdir;
651651

652652
cachefiles_begin_secure(cache, &saved_cred);

‎fs/cachefiles/namei.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,
277277
_debug("remove %p from %p", rep, dir);
278278

279279
/* non-directories can just be unlinked */
280-
if (!S_ISDIR(rep->d_inode->i_mode)) {
280+
if (!d_is_dir(rep)) {
281281
_debug("unlink stale object");
282282

283283
path.mnt = cache->mnt;
@@ -323,7 +323,7 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,
323323
return 0;
324324
}
325325

326-
if (!S_ISDIR(cache->graveyard->d_inode->i_mode)) {
326+
if (!d_is_dir(cache->graveyard)) {
327327
unlock_rename(cache->graveyard, dir);
328328
cachefiles_io_error(cache, "Graveyard no longer a directory");
329329
return -EIO;
@@ -475,7 +475,7 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
475475
ASSERT(parent->dentry);
476476
ASSERT(parent->dentry->d_inode);
477477

478-
if (!(S_ISDIR(parent->dentry->d_inode->i_mode))) {
478+
if (!(d_is_dir(parent->dentry))) {
479479
// TODO: convert file to dir
480480
_leave("looking up in none directory");
481481
return -ENOBUFS;
@@ -539,7 +539,7 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
539539
_debug("mkdir -> %p{%p{ino=%lu}}",
540540
next, next->d_inode, next->d_inode->i_ino);
541541

542-
} else if (!S_ISDIR(next->d_inode->i_mode)) {
542+
} else if (!d_is_dir(next)) {
543543
pr_err("inode %lu is not a directory\n",
544544
next->d_inode->i_ino);
545545
ret = -ENOBUFS;
@@ -568,8 +568,8 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
568568
_debug("create -> %p{%p{ino=%lu}}",
569569
next, next->d_inode, next->d_inode->i_ino);
570570

571-
} else if (!S_ISDIR(next->d_inode->i_mode) &&
572-
!S_ISREG(next->d_inode->i_mode)
571+
} else if (!d_is_dir(next) &&
572+
!d_is_reg(next)
573573
) {
574574
pr_err("inode %lu is not a file or directory\n",
575575
next->d_inode->i_ino);
@@ -642,7 +642,7 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
642642

643643
/* open a file interface onto a data file */
644644
if (object->type != FSCACHE_COOKIE_TYPE_INDEX) {
645-
if (S_ISREG(object->dentry->d_inode->i_mode)) {
645+
if (d_is_reg(object->dentry)) {
646646
const struct address_space_operations *aops;
647647

648648
ret = -EPERM;
@@ -763,7 +763,7 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
763763
/* we need to make sure the subdir is a directory */
764764
ASSERT(subdir->d_inode);
765765

766-
if (!S_ISDIR(subdir->d_inode->i_mode)) {
766+
if (!d_is_dir(subdir)) {
767767
pr_err("%s is not a directory\n", dirname);
768768
ret = -EIO;
769769
goto check_error;

‎fs/ceph/dir.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ static int ceph_unlink(struct inode *dir, struct dentry *dentry)
902902
} else if (ceph_snap(dir) == CEPH_NOSNAP) {
903903
dout("unlink/rmdir dir %p dn %p inode %p\n",
904904
dir, dentry, inode);
905-
op = S_ISDIR(dentry->d_inode->i_mode) ?
905+
op = d_is_dir(dentry) ?
906906
CEPH_MDS_OP_RMDIR : CEPH_MDS_OP_UNLINK;
907907
} else
908908
goto out;

‎fs/ceph/file.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
292292
}
293293
if (err)
294294
goto out_req;
295-
if (dn || dentry->d_inode == NULL || S_ISLNK(dentry->d_inode->i_mode)) {
295+
if (dn || dentry->d_inode == NULL || d_is_symlink(dentry)) {
296296
/* make vfs retry on splice, ENOENT, or symlink */
297297
dout("atomic_open finish_no_open on dn %p\n", dn);
298298
err = finish_no_open(file, dn);

‎fs/coda/dir.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ static int coda_rename(struct inode *old_dir, struct dentry *old_dentry,
304304
(const char *) old_name, (const char *)new_name);
305305
if (!error) {
306306
if (new_dentry->d_inode) {
307-
if (S_ISDIR(new_dentry->d_inode->i_mode)) {
307+
if (d_is_dir(new_dentry)) {
308308
coda_dir_drop_nlink(old_dir);
309309
coda_dir_inc_nlink(new_dir);
310310
}

0 commit comments

Comments
 (0)