for (bindex = bstart; bindex <= bend; bindex++) {
lower_dentry = unionfs_lower_dentry_idx(dentry, bindex);
- if (!lower_dentry) {
+ if (unlikely(!lower_dentry)) {
unionfs_set_lower_inode_idx(inode, bindex, NULL);
continue;
}
/* Initialize the lower inode to the new lower inode. */
- if (!lower_dentry->d_inode)
+ if (unlikely(!lower_dentry->d_inode))
continue;
unionfs_set_lower_inode_idx(inode, bindex,
lower_inode = unionfs_lower_inode(inode);
/* Use different set of inode ops for symlinks & directories */
- if (S_ISLNK(lower_inode->i_mode))
+ if (unlikely(S_ISLNK(lower_inode->i_mode)))
inode->i_op = &unionfs_symlink_iops;
else if (S_ISDIR(lower_inode->i_mode))
inode->i_op = &unionfs_dir_iops;
inode->i_fop = &unionfs_dir_fops;
/* properly initialize special inodes */
- if (S_ISBLK(lower_inode->i_mode) || S_ISCHR(lower_inode->i_mode) ||
- S_ISFIFO(lower_inode->i_mode) || S_ISSOCK(lower_inode->i_mode))
+ if (unlikely(S_ISBLK(lower_inode->i_mode) ||
+ S_ISCHR(lower_inode->i_mode) ||
+ S_ISFIFO(lower_inode->i_mode) ||
+ S_ISSOCK(lower_inode->i_mode)))
init_special_inode(inode, lower_inode->i_mode,
lower_inode->i_rdev);
UNIONFS_I(inode)->lower_inodes =
kcalloc(sbmax(sb), sizeof(struct inode *), GFP_KERNEL);
- if (!UNIONFS_I(inode)->lower_inodes) {
+ if (unlikely(!UNIONFS_I(inode)->lower_inodes)) {
err = -ENOMEM;
goto out;
}
} else {
/* get unique inode number for unionfs */
inode = iget(sb, iunique(sb, UNIONFS_ROOT_INO));
- if (!inode) {
+ if (unlikely(!inode)) {
err = -EACCES;
goto out;
}
break;
case INTERPOSE_LOOKUP:
spliced = d_splice_alias(inode, dentry);
- if (IS_ERR(spliced))
+ if (unlikely(IS_ERR(spliced)))
err = PTR_ERR(spliced);
else if (spliced && spliced != dentry) {
/*
goto out;
out_spliced:
- if (!err)
+ if (likely(!err))
return spliced;
out:
return ERR_PTR(err);
bend = dbend(dentry);
for (bindex = bstart; bindex <= bend; bindex++) {
lower_dentry = unionfs_lower_dentry_idx(dentry, bindex);
- if (!lower_dentry)
+ if (unlikely(!lower_dentry))
continue;
- if (!lower_dentry->d_inode)
+ if (unlikely(!lower_dentry->d_inode))
continue;
- if (unionfs_lower_inode_idx(inode, bindex))
+ if (unlikely(unionfs_lower_inode_idx(inode, bindex)))
continue;
unionfs_set_lower_inode_idx(inode, bindex,
igrab(lower_dentry->d_inode));
int check_branch(struct nameidata *nd)
{
/* XXX: remove in ODF code -- stacking unions allowed there */
- if (!strcmp(nd->dentry->d_sb->s_type->name, "unionfs"))
+ if (unlikely(!strcmp(nd->dentry->d_sb->s_type->name, "unionfs")))
return -EINVAL;
- if (!nd->dentry->d_inode)
+ if (unlikely(!nd->dentry->d_inode))
return -ENOENT;
- if (!S_ISDIR(nd->dentry->d_inode->i_mode))
+ if (unlikely(!S_ISDIR(nd->dentry->d_inode->i_mode)))
return -ENOTDIR;
return 0;
}
while ((dent != dent2) && (dent->d_parent != dent))
dent = dent->d_parent;
- if (dent == dent2)
+ if (unlikely(dent == dent2))
return 1;
dent = dent2;
*/
int __parse_branch_mode(const char *name)
{
- if (!name)
+ if (unlikely(!name))
return 0;
if (!strcmp(name, "ro"))
return MAY_READ;
struct dentry *dent1;
struct dentry *dent2;
- if (options[0] == '\0') {
+ if (unlikely(options[0] == '\0')) {
printk(KERN_WARNING "unionfs: no branches specified\n");
err = -EINVAL;
goto out;
/* allocate space for underlying pointers to lower dentry */
UNIONFS_SB(sb)->data =
kcalloc(branches, sizeof(struct unionfs_data), GFP_KERNEL);
- if (!UNIONFS_SB(sb)->data) {
+ if (unlikely(!UNIONFS_SB(sb)->data)) {
err = -ENOMEM;
goto out;
}
lower_root_info->lower_paths =
kcalloc(branches, sizeof(struct path), GFP_KERNEL);
- if (!lower_root_info->lower_paths) {
+ if (unlikely(!lower_root_info->lower_paths)) {
err = -ENOMEM;
goto out;
}
if (!name)
continue;
- if (!*name) { /* bad use of ':' (extra colons) */
+ if (unlikely(!*name)) { /* bad use of ':' (extra colons)) */
err = -EINVAL;
goto out;
}
*mode++ = '\0';
perms = parse_branch_mode(mode);
- if (!bindex && !(perms & MAY_WRITE)) {
+ if (unlikely(!bindex && !(perms & MAY_WRITE))) {
err = -EINVAL;
goto out;
}
err = path_lookup(name, LOOKUP_FOLLOW, &nd);
- if (err) {
+ if (unlikely(err)) {
printk(KERN_WARNING "unionfs: error accessing "
"lower directory '%s' (error %d)\n",
name, err);
goto out;
}
- if ((err = check_branch(&nd))) {
+ if (unlikely((err = check_branch(&nd)))) {
printk(KERN_WARNING "unionfs: lower directory "
"'%s' is not a valid branch\n", name);
path_release(&nd);
bindex++;
}
- if (branches == 0) {
+ if (unlikely(branches == 0)) {
printk(KERN_WARNING "unionfs: no branches specified\n");
err = -EINVAL;
goto out;
dent1 = lower_root_info->lower_paths[i].dentry;
for (j = i + 1; j < branches; j++) {
dent2 = lower_root_info->lower_paths[j].dentry;
- if (is_branch_overlap(dent1, dent2)) {
+ if (unlikely(is_branch_overlap(dent1, dent2))) {
printk(KERN_WARNING "unionfs: branches %d and "
"%d overlap\n", i, j);
err = -EINVAL;
}
out:
- if (err) {
+ if (unlikely(err)) {
for (i = 0; i < branches; i++)
if (lower_root_info->lower_paths[i].dentry) {
dput(lower_root_info->lower_paths[i].dentry);
err = -ENOMEM;
lower_root_info =
kzalloc(sizeof(struct unionfs_dentry_info), GFP_KERNEL);
- if (!lower_root_info)
+ if (unlikely(!lower_root_info))
goto out_error;
lower_root_info->bstart = -1;
lower_root_info->bend = -1;
char *endptr;
int intval;
- if (!optname || !*optname)
+ if (unlikely(!optname || !*optname))
continue;
optarg = strchr(optname, '=');
* All of our options take an argument now. Insert ones that
* don't, above this check.
*/
- if (!optarg) {
+ if (unlikely(!optarg)) {
printk("unionfs: %s requires an argument.\n", optname);
err = -EINVAL;
goto out_error;
}
if (!strcmp("dirs", optname)) {
- if (++dirsfound > 1) {
+ if (unlikely(++dirsfound > 1)) {
printk(KERN_WARNING
"unionfs: multiple dirs specified\n");
err = -EINVAL;
goto out_error;
}
err = parse_dirs_option(sb, lower_root_info, optarg);
- if (err)
+ if (unlikely(err))
goto out_error;
continue;
}
/* All of these options require an integer argument. */
intval = simple_strtoul(optarg, &endptr, 0);
- if (*endptr) {
+ if (unlikely(*endptr)) {
printk(KERN_WARNING
"unionfs: invalid %s option '%s'\n",
optname, optarg);
"unionfs: unrecognized option '%s'\n", optname);
goto out_error;
}
- if (dirsfound != 1) {
+ if (unlikely(dirsfound != 1)) {
printk(KERN_WARNING "unionfs: dirs option required\n");
err = -EINVAL;
goto out_error;
{
struct dentry *ret = NULL;
- if (sb) {
+ if (likely(sb)) {
static const struct qstr name = {.name = "/",.len = 1 };
ret = d_alloc(NULL, &name);
- if (ret) {
+ if (likely(ret)) {
ret->d_op = &unionfs_dops;
ret->d_sb = sb;
ret->d_parent = ret;
struct unionfs_dentry_info *lower_root_info = NULL;
int bindex, bstart, bend;
- if (!raw_data) {
+ if (unlikely(!raw_data)) {
printk(KERN_WARNING
"unionfs: read_super: missing data argument\n");
err = -EINVAL;
/* Allocate superblock private data */
sb->s_fs_info = kzalloc(sizeof(struct unionfs_sb_info), GFP_KERNEL);
- if (!UNIONFS_SB(sb)) {
+ if (unlikely(!UNIONFS_SB(sb))) {
printk(KERN_WARNING "unionfs: read_super: out of memory\n");
err = -ENOMEM;
goto out;
UNIONFS_SB(sb)->high_branch_id = -1; /* -1 == invalid branch ID */
lower_root_info = unionfs_parse_options(sb, raw_data);
- if (IS_ERR(lower_root_info)) {
+ if (unlikely(IS_ERR(lower_root_info))) {
printk(KERN_WARNING
"unionfs: read_super: error while parsing options "
"(err = %ld)\n", PTR_ERR(lower_root_info));
lower_root_info = NULL;
goto out_free;
}
- if (lower_root_info->bstart == -1) {
+ if (unlikely(lower_root_info->bstart == -1)) {
err = -ENOENT;
goto out_free;
}
/* See comment next to the definition of unionfs_d_alloc_root */
sb->s_root = unionfs_d_alloc_root(sb);
- if (!sb->s_root) {
+ if (unlikely(!sb->s_root)) {
err = -ENOMEM;
goto out_dput;
}
/* link the upper and lower dentries */
sb->s_root->d_fsdata = NULL;
- if ((err = new_dentry_private_data(sb->s_root)))
+ if (unlikely((err = new_dentry_private_data(sb->s_root))))
goto out_freedpd;
/* Set the lower dentries for s_root */
*/
err = PTR_ERR(unionfs_interpose(sb->s_root, sb, 0));
unionfs_unlock_dentry(sb->s_root);
- if (!err)
+ if (likely(!err))
goto out;
/* else fall through */
printk("Registering unionfs " UNIONFS_VERSION "\n");
- if ((err = unionfs_init_filldir_cache()))
+ if (unlikely((err = unionfs_init_filldir_cache())))
goto out;
- if ((err = unionfs_init_inode_cache()))
+ if (unlikely((err = unionfs_init_inode_cache())))
goto out;
- if ((err = unionfs_init_dentry_cache()))
+ if (unlikely((err = unionfs_init_dentry_cache())))
goto out;
- if ((err = init_sioq()))
+ if (unlikely((err = init_sioq())))
goto out;
err = register_filesystem(&unionfs_fs_type);
out:
- if (err) {
+ if (unlikely(err)) {
stop_sioq();
unionfs_destroy_filldir_cache();
unionfs_destroy_inode_cache();
size = sbmax(inode->i_sb) * sizeof(struct inode *);
info->lower_inodes = kzalloc(size, GFP_KERNEL);
- if (!info->lower_inodes) {
+ if (unlikely(!info->lower_inodes)) {
printk(KERN_ERR "unionfs: no kernel memory when allocating "
"lower-pointer array!\n");
BUG();
int leaks = 0;
spd = UNIONFS_SB(sb);
- if (!spd)
+ if (unlikely(!spd))
return;
bstart = sbstart(sb);
/* Make sure we have no leaks of branchget/branchput. */
for (bindex = bstart; bindex <= bend; bindex++)
- if (branch_count(sb, bindex) != 0) {
+ if (unlikely(branch_count(sb, bindex) != 0)) {
printk("unionfs: branch %d has %d references left!\n",
bindex, branch_count(sb, bindex));
leaks = 1;
unionfs_read_lock(sb);
unionfs_lock_dentry(dentry);
- if (!__unionfs_d_revalidate_chain(dentry, NULL, false)) {
+ if (unlikely(!__unionfs_d_revalidate_chain(dentry, NULL, false))) {
err = -ESTALE;
goto out;
}
struct nameidata nd;
/* by now, optarg contains the branch name */
- if (!*optarg) {
+ if (unlikely(!*optarg)) {
printk("unionfs: no branch specified for mode change.\n");
goto out;
}
- if (!modename) {
+ if (unlikely(!modename)) {
printk("unionfs: branch \"%s\" requires a mode.\n", optarg);
goto out;
}
*modename++ = '\0';
perms = __parse_branch_mode(modename);
- if (perms == 0) {
+ if (unlikely(perms == 0)) {
printk("unionfs: invalid mode \"%s\" for \"%s\".\n",
modename, optarg);
goto out;
* uniqueness.
*/
err = path_lookup(optarg, LOOKUP_FOLLOW, &nd);
- if (err) {
+ if (unlikely(err)) {
printk(KERN_WARNING "unionfs: error accessing "
"lower directory \"%s\" (error %d)\n",
optarg, err);
nd.dentry == new_lower_paths[idx].dentry)
break;
path_release(&nd); /* no longer needed */
- if (idx == cur_branches) {
+ if (unlikely(idx == cur_branches)) {
err = -ENOENT; /* err may have been reset above */
printk(KERN_WARNING "unionfs: branch \"%s\" "
"not found\n", optarg);
* uniqueness.
*/
err = path_lookup(optarg, LOOKUP_FOLLOW, &nd);
- if (err) {
+ if (unlikely(err)) {
printk(KERN_WARNING "unionfs: error accessing "
"lower directory \"%s\" (error %d)\n",
optarg, err);
nd.dentry == new_lower_paths[idx].dentry)
break;
path_release(&nd); /* no longer needed */
- if (idx == cur_branches) {
+ if (unlikely(idx == cur_branches)) {
printk(KERN_WARNING "unionfs: branch \"%s\" "
"not found\n", optarg);
err = -ENOENT;
goto out;
}
/* check if there are any open files on the branch to be deleted */
- if (atomic_read(&new_data[idx].open_files) > 0) {
+ if (unlikely(atomic_read(&new_data[idx].open_files) > 0)) {
err = -EBUSY;
goto out;
}
* uniqueness.
*/
err = path_lookup(optarg, LOOKUP_FOLLOW, &nd);
- if (err) {
+ if (unlikely(err)) {
printk(KERN_WARNING "unionfs: error accessing "
"lower directory \"%s\" (error %d)\n",
optarg, err);
nd.dentry == new_lower_paths[idx].dentry)
break;
path_release(&nd); /* no longer needed */
- if (idx == cur_branches) {
+ if (unlikely(idx == cur_branches)) {
printk(KERN_WARNING "unionfs: branch \"%s\" "
"not found\n", optarg);
err = -ENOENT;
*modename++ = '\0';
perms = parse_branch_mode(modename);
- if (!new_branch || !*new_branch) {
+ if (unlikely(!new_branch || !*new_branch)) {
printk(KERN_WARNING "unionfs: null new branch\n");
err = -EINVAL;
goto out;
}
err = path_lookup(new_branch, LOOKUP_FOLLOW, &nd);
- if (err) {
+ if (unlikely(err)) {
printk(KERN_WARNING "unionfs: error accessing "
"lower directory \"%s\" (error %d)\n",
new_branch, err);
* because this code base doesn't support stacking unionfs: the ODF
* code base supports that correctly.
*/
- if ((err = check_branch(&nd))) {
+ if (unlikely((err = check_branch(&nd)))) {
printk(KERN_WARNING "unionfs: lower directory "
"\"%s\" is not a valid branch\n", optarg);
path_release(&nd);
* need to check if any other flags may have been passed (none are
* allowed/supported as of now).
*/
- if ((*flags & ~(MS_RDONLY | MS_SILENT)) != 0) {
+ if (unlikely((*flags & ~(MS_RDONLY | MS_SILENT)) != 0)) {
printk(KERN_WARNING
"unionfs: remount flags 0x%x unsupported\n", *flags);
err = -EINVAL;
* the union to a "ro" or "rw" and the VFS took care of it. So
* nothing to do and we're done.
*/
- if (!options || options[0] == '\0')
+ if (unlikely(!options || options[0] == '\0'))
goto out_error;
/*
* strsep modifies the string and we need it later.
*/
optionstmp = tmp_to_free = kstrdup(options, GFP_KERNEL);
- if (!optionstmp) {
+ if (unlikely(!optionstmp)) {
err = -ENOMEM;
goto out_free;
}
while ((optname = strsep(&optionstmp, ",")) != NULL) {
char *optarg;
- if (!optname || !*optname)
+ if (unlikely(!optname || !*optname))
continue;
optarg = strchr(optname, '=');
}
kfree(tmp_to_free);
/* after all changes, will we have at least one branch left? */
- if ((new_branches + add_branches - del_branches) < 1) {
+ if (unlikely((new_branches + add_branches - del_branches) < 1)) {
printk(KERN_WARNING
"unionfs: no branches left after remount\n");
err = -EINVAL;
/* allocate space for new pointers to lower dentry */
tmp_data = kcalloc(max_branches,
sizeof(struct unionfs_data), GFP_KERNEL);
- if (!tmp_data) {
+ if (unlikely(!tmp_data)) {
err = -ENOMEM;
goto out_free;
}
/* allocate space for new pointers to lower paths */
tmp_lower_paths = kcalloc(max_branches,
sizeof(struct path), GFP_KERNEL);
- if (!tmp_lower_paths) {
+ if (unlikely(!tmp_lower_paths)) {
err = -ENOMEM;
goto out_free;
}
while ((optname = strsep(&options, ",")) != NULL) {
char *optarg;
- if (!optname || !*optname)
+ if (unlikely(!optname || !*optname))
continue;
/*
* At this stage optname holds a comma-delimited option, but
* that don't above this check.) So at this stage optname
* contains the CMD part and optarg contains the ARG part.
*/
- if (!optarg || !*optarg) {
+ if (unlikely(!optarg || !*optarg)) {
printk("unionfs: all remount options require "
"an argument (%s).\n", optname);
err = -EINVAL;
tmp_data,
tmp_lower_paths,
&new_high_branch_id);
- if (err)
+ if (unlikely(err))
goto out_release;
new_branches++;
- if (new_branches > UNIONFS_MAX_BRANCHES) {
+ if (unlikely(new_branches > UNIONFS_MAX_BRANCHES)) {
printk("unionfs: command exceeds "
"%d branches\n", UNIONFS_MAX_BRANCHES);
err = -E2BIG;
err = do_remount_del_option(optarg, new_branches,
tmp_data,
tmp_lower_paths);
- if (err)
+ if (unlikely(err))
goto out_release;
new_branches--;
continue;
err = do_remount_mode_option(optarg, new_branches,
tmp_data,
tmp_lower_paths);
- if (err)
+ if (unlikely(err))
goto out_release;
continue;
}
* actually process the ro/rw remount options, we have to
* return 0 from this function.
*/
- if (!strcmp("dirs", optname)) {
+ if (unlikely(!strcmp("dirs", optname))) {
printk(KERN_WARNING
"unionfs: remount ignoring option \"%s\".\n",
optname);
* have to be re-read.
*******************************************************************/
- if (!(tmp_data[0].branchperms & MAY_WRITE)) {
+ if (unlikely(!(tmp_data[0].branchperms & MAY_WRITE))) {
printk("unionfs: leftmost branch cannot be read-only "
"(use \"remount,ro\" to create a read-only union)\n");
err = -EINVAL;
/* (re)allocate space for new pointers to lower dentry */
size = new_branches * sizeof(struct unionfs_data);
new_data = krealloc(tmp_data, size, GFP_KERNEL);
- if (!new_data) {
+ if (unlikely(!new_data)) {
err = -ENOMEM;
goto out_release;
}
/* allocate space for new pointers to lower paths */
size = new_branches * sizeof(struct path);
new_lower_paths = krealloc(tmp_lower_paths, size, GFP_KERNEL);
- if (!new_lower_paths) {
+ if (unlikely(!new_lower_paths)) {
err = -ENOMEM;
goto out_release;
}
/* allocate space for new pointers to lower inodes */
new_lower_inodes = kcalloc(new_branches,
sizeof(struct inode *), GFP_KERNEL);
- if (!new_lower_inodes) {
+ if (unlikely(!new_lower_inodes)) {
err = -ENOMEM;
goto out_release;
}
i = atomic_inc_return(&UNIONFS_SB(sb)->generation);
atomic_set(&UNIONFS_D(sb->s_root)->generation, i);
atomic_set(&UNIONFS_I(sb->s_root->d_inode)->generation, i);
- if (!(*flags & MS_SILENT))
+ if (likely(!(*flags & MS_SILENT)))
printk("unionfs: new generation number %d\n", i);
/* finally, update the root dentry's times */
unionfs_copy_attr_times(sb->s_root->d_inode);
*/
out_release:
/* no need to cleanup/release anything in tmp_data */
- if (tmp_lower_paths)
+ if (likely(tmp_lower_paths))
for (i=0; i<new_branches; i++)
pathput(&tmp_lower_paths[i]);
out_free:
*/
bstart = ibstart(inode);
bend = ibend(inode);
- if (bstart >= 0) {
+ if (likely(bstart >= 0)) {
for (bindex = bstart; bindex <= bend; bindex++) {
lower_inode = unionfs_lower_inode_idx(inode, bindex);
- if (!lower_inode)
+ if (unlikely(!lower_inode))
continue;
iput(lower_inode);
}
struct unionfs_inode_info *i;
i = kmem_cache_alloc(unionfs_inode_cachep, GFP_KERNEL);
- if (!i)
+ if (unlikely(!i))
return NULL;
/* memset everything up to the inode to 0 */
kmem_cache_create("unionfs_inode_cache",
sizeof(struct unionfs_inode_info), 0,
SLAB_RECLAIM_ACCOUNT, init_once);
- if (!unionfs_inode_cachep)
+ if (unlikely(!unionfs_inode_cachep))
err = -ENOMEM;
return err;
}
/* unionfs inode cache destructor */
void unionfs_destroy_inode_cache(void)
{
- if (unionfs_inode_cachep)
+ if (likely(unionfs_inode_cachep))
kmem_cache_destroy(unionfs_inode_cachep);
}
struct vfsmount *lower_mnt;
int bindex, bstart, bend;
- if (!(flags & MNT_FORCE))
+ if (likely(!(flags & MNT_FORCE)))
/*
* we are not being MNT_FORCE'd, therefore we should emulate
* old behavior
unionfs_lock_dentry(sb->s_root);
tmp_page = (char*) __get_free_page(GFP_KERNEL);
- if (!tmp_page) {
+ if (unlikely(!tmp_page)) {
ret = -ENOMEM;
goto out;
}
path = d_path(unionfs_lower_dentry_idx(sb->s_root, bindex),
unionfs_lower_mnt_idx(sb->s_root, bindex),
tmp_page, PAGE_SIZE);
- if (IS_ERR(path)) {
+ if (unlikely(IS_ERR(path))) {
ret = PTR_ERR(path);
goto out;
}