diff options
author | David Howells <dhowells@redhat.com> | 2015-01-29 07:02:35 -0500 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2015-02-22 11:38:41 -0500 |
commit | e36cb0b89ce20b4f8786a57e8a6bc8476f577650 (patch) | |
tree | 68adea9f719915013dfd85e9b5872b5bc00b1c70 /fs/cachefiles | |
parent | 2c616d4d88de1dc5b1545eefdc2e291eeb9f2e9d (diff) |
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>
Diffstat (limited to 'fs/cachefiles')
-rw-r--r-- | fs/cachefiles/daemon.c | 4 | ||||
-rw-r--r-- | fs/cachefiles/namei.c | 16 |
2 files changed, 10 insertions, 10 deletions
diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c index ce1b115dcc28..d92840209863 100644 --- a/fs/cachefiles/daemon.c +++ b/fs/cachefiles/daemon.c | |||
@@ -574,7 +574,7 @@ static int cachefiles_daemon_cull(struct cachefiles_cache *cache, char *args) | |||
574 | /* extract the directory dentry from the cwd */ | 574 | /* extract the directory dentry from the cwd */ |
575 | get_fs_pwd(current->fs, &path); | 575 | get_fs_pwd(current->fs, &path); |
576 | 576 | ||
577 | if (!S_ISDIR(path.dentry->d_inode->i_mode)) | 577 | if (!d_is_dir(path.dentry)) |
578 | goto notdir; | 578 | goto notdir; |
579 | 579 | ||
580 | cachefiles_begin_secure(cache, &saved_cred); | 580 | cachefiles_begin_secure(cache, &saved_cred); |
@@ -646,7 +646,7 @@ static int cachefiles_daemon_inuse(struct cachefiles_cache *cache, char *args) | |||
646 | /* extract the directory dentry from the cwd */ | 646 | /* extract the directory dentry from the cwd */ |
647 | get_fs_pwd(current->fs, &path); | 647 | get_fs_pwd(current->fs, &path); |
648 | 648 | ||
649 | if (!S_ISDIR(path.dentry->d_inode->i_mode)) | 649 | if (!d_is_dir(path.dentry)) |
650 | goto notdir; | 650 | goto notdir; |
651 | 651 | ||
652 | cachefiles_begin_secure(cache, &saved_cred); | 652 | cachefiles_begin_secure(cache, &saved_cred); |
diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c index 7f8e83f9d74e..d750e8cc0ab6 100644 --- a/fs/cachefiles/namei.c +++ b/fs/cachefiles/namei.c | |||
@@ -277,7 +277,7 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache, | |||
277 | _debug("remove %p from %p", rep, dir); | 277 | _debug("remove %p from %p", rep, dir); |
278 | 278 | ||
279 | /* non-directories can just be unlinked */ | 279 | /* non-directories can just be unlinked */ |
280 | if (!S_ISDIR(rep->d_inode->i_mode)) { | 280 | if (!d_is_dir(rep)) { |
281 | _debug("unlink stale object"); | 281 | _debug("unlink stale object"); |
282 | 282 | ||
283 | path.mnt = cache->mnt; | 283 | path.mnt = cache->mnt; |
@@ -323,7 +323,7 @@ try_again: | |||
323 | return 0; | 323 | return 0; |
324 | } | 324 | } |
325 | 325 | ||
326 | if (!S_ISDIR(cache->graveyard->d_inode->i_mode)) { | 326 | if (!d_is_dir(cache->graveyard)) { |
327 | unlock_rename(cache->graveyard, dir); | 327 | unlock_rename(cache->graveyard, dir); |
328 | cachefiles_io_error(cache, "Graveyard no longer a directory"); | 328 | cachefiles_io_error(cache, "Graveyard no longer a directory"); |
329 | return -EIO; | 329 | return -EIO; |
@@ -475,7 +475,7 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent, | |||
475 | ASSERT(parent->dentry); | 475 | ASSERT(parent->dentry); |
476 | ASSERT(parent->dentry->d_inode); | 476 | ASSERT(parent->dentry->d_inode); |
477 | 477 | ||
478 | if (!(S_ISDIR(parent->dentry->d_inode->i_mode))) { | 478 | if (!(d_is_dir(parent->dentry))) { |
479 | // TODO: convert file to dir | 479 | // TODO: convert file to dir |
480 | _leave("looking up in none directory"); | 480 | _leave("looking up in none directory"); |
481 | return -ENOBUFS; | 481 | return -ENOBUFS; |
@@ -539,7 +539,7 @@ lookup_again: | |||
539 | _debug("mkdir -> %p{%p{ino=%lu}}", | 539 | _debug("mkdir -> %p{%p{ino=%lu}}", |
540 | next, next->d_inode, next->d_inode->i_ino); | 540 | next, next->d_inode, next->d_inode->i_ino); |
541 | 541 | ||
542 | } else if (!S_ISDIR(next->d_inode->i_mode)) { | 542 | } else if (!d_is_dir(next)) { |
543 | pr_err("inode %lu is not a directory\n", | 543 | pr_err("inode %lu is not a directory\n", |
544 | next->d_inode->i_ino); | 544 | next->d_inode->i_ino); |
545 | ret = -ENOBUFS; | 545 | ret = -ENOBUFS; |
@@ -568,8 +568,8 @@ lookup_again: | |||
568 | _debug("create -> %p{%p{ino=%lu}}", | 568 | _debug("create -> %p{%p{ino=%lu}}", |
569 | next, next->d_inode, next->d_inode->i_ino); | 569 | next, next->d_inode, next->d_inode->i_ino); |
570 | 570 | ||
571 | } else if (!S_ISDIR(next->d_inode->i_mode) && | 571 | } else if (!d_is_dir(next) && |
572 | !S_ISREG(next->d_inode->i_mode) | 572 | !d_is_reg(next) |
573 | ) { | 573 | ) { |
574 | pr_err("inode %lu is not a file or directory\n", | 574 | pr_err("inode %lu is not a file or directory\n", |
575 | next->d_inode->i_ino); | 575 | next->d_inode->i_ino); |
@@ -642,7 +642,7 @@ lookup_again: | |||
642 | 642 | ||
643 | /* open a file interface onto a data file */ | 643 | /* open a file interface onto a data file */ |
644 | if (object->type != FSCACHE_COOKIE_TYPE_INDEX) { | 644 | if (object->type != FSCACHE_COOKIE_TYPE_INDEX) { |
645 | if (S_ISREG(object->dentry->d_inode->i_mode)) { | 645 | if (d_is_reg(object->dentry)) { |
646 | const struct address_space_operations *aops; | 646 | const struct address_space_operations *aops; |
647 | 647 | ||
648 | ret = -EPERM; | 648 | ret = -EPERM; |
@@ -763,7 +763,7 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache, | |||
763 | /* we need to make sure the subdir is a directory */ | 763 | /* we need to make sure the subdir is a directory */ |
764 | ASSERT(subdir->d_inode); | 764 | ASSERT(subdir->d_inode); |
765 | 765 | ||
766 | if (!S_ISDIR(subdir->d_inode->i_mode)) { | 766 | if (!d_is_dir(subdir)) { |
767 | pr_err("%s is not a directory\n", dirname); | 767 | pr_err("%s is not a directory\n", dirname); |
768 | ret = -EIO; | 768 | ret = -EIO; |
769 | goto check_error; | 769 | goto check_error; |