64 bit fixes for debugging support.
Use bool type where appropriate.
Minor code cleanups.
Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
Signed-off-by: Josef 'Jeff' Sipek <jsipek@cs.sunysb.edu>
err = PTR_ERR(tmp_dentry);
goto out;
}
- /* don't dput here because of do-while condition eval order */
} while (tmp_dentry->d_inode != NULL); /* need negative dentry */
dput(tmp_dentry);
*/
if (!d_deleted(dentry) &&
(sbgen > fgen || dbstart(dentry) != fbstart(file))) {
- int orig_brid = /* save orig branch ID */
- UNIONFS_F(file)->saved_branch_ids[fbstart(file)];
+ /* save orig branch ID */
+ int orig_brid = UNIONFS_F(file)->saved_branch_ids[fbstart(file)];
/* First we throw out the existing files. */
cleanup_file(file);
* update the mnt counts of the old and new
* branches accordingly.
*/
- unionfs_mntget(dentry, bstart); /* new branch */
- unionfs_mntput(sb->s_root, /* orig branch */
+ unionfs_mntget(dentry, bstart);
+ unionfs_mntput(sb->s_root,
branch_id_to_idx(sb, orig_brid));
}
}
atomic_set(&UNIONFS_F(file)->generation,
- atomic_read(&UNIONFS_I(dentry->d_inode)->
- generation));
+ atomic_read(&UNIONFS_I(dentry->d_inode)->generation));
}
/* Copyup on the first write to a file on a readonly branch. */
*/
/* it's always useful to know what part of the code called us */
-#define PRINT_CALLER() \
- do { \
- if (!printed_caller) { \
- printk("PC:%s:%s:%d\n",fname,fxn,line); \
- printed_caller = 1; \
- } \
+#define PRINT_CALLER(fname, fxn, line) \
+ do { \
+ if (!printed_caller) { \
+ printk("PC:%s:%s:%d\n",(fname),(fxn),(line)); \
+ printed_caller = 1; \
+ } \
} while (0)
+#if BITS_PER_LONG == 32
+#define POISONED_PTR ((void*) 0x5a5a5a5a)
+#elif BITS_PER_LONG == 64
+#define POISONED_PTR ((void*) 0x5a5a5a5a5a5a5a5a)
+#else
+#error Unknown BITS_PER_LONG value
+#endif /* BITS_PER_LONG != known */
+
/*
* __unionfs_check_{inode,dentry,file} perform exhaustive sanity checking on
* the fan-out of various Unionfs objects. We check that no lower objects
istart = ibstart(inode);
iend = ibend(inode);
if (istart > iend) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" Ci0: inode=%p istart/end=%d:%d\n",
inode, istart, iend);
}
if ((istart == -1 && iend != -1) ||
(istart != -1 && iend == -1)) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" Ci1: inode=%p istart/end=%d:%d\n",
inode, istart, iend);
}
if (!S_ISDIR(inode->i_mode)) {
if (iend != istart) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" Ci2: inode=%p istart=%d iend=%d\n",
inode, istart, iend);
}
for (bindex = sbstart(sb); bindex < sbmax(sb); bindex++) {
if (!UNIONFS_I(inode)) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" Ci3: no inode_info %p\n", inode);
return;
}
if (!UNIONFS_I(inode)->lower_inodes) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" Ci4: no lower_inodes %p\n", inode);
return;
}
lower_inode = unionfs_lower_inode_idx(inode, bindex);
if (lower_inode) {
if (bindex < istart || bindex > iend) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" Ci5: inode/linode=%p:%p bindex=%d "
"istart/end=%d:%d\n", inode,
lower_inode, bindex, istart, iend);
- } else if ((int)lower_inode == 0x5a5a5a5a) {
+ } else if (lower_inode == POISONED_PTR) {
/* freed inode! */
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" Ci6: inode/linode=%p:%p bindex=%d "
"istart/end=%d:%d\n", inode,
lower_inode, bindex, istart, iend);
*/
if (!(S_ISDIR(inode->i_mode) &&
bindex > istart && bindex < iend)) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" Ci7: inode/linode=%p:%p "
"bindex=%d istart/end=%d:%d\n",
inode, lower_inode, bindex,
if ((dstart == -1 && dend != -1) ||
(dstart != -1 && dend == -1)) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" CD0: dentry=%p dstart/end=%d:%d\n",
dentry, dstart, dend);
}
lower_dentry = unionfs_lower_dentry_idx(dentry, bindex);
if (lower_dentry) {
if (bindex < dstart || bindex > dend) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" CD1: dentry/lower=%p:%p(%p) "
"bindex=%d dstart/end=%d:%d\n",
dentry, lower_dentry,
(lower_dentry ? lower_dentry->d_inode :
- (void *) 0xffffffff),
+ (void *) -1L),
bindex, dstart, dend);
}
} else { /* lower_dentry == NULL */
inode &&
!(inode && S_ISDIR(inode->i_mode) &&
bindex > dstart && bindex < dend)) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" CD2: dentry/lower=%p:%p(%p) "
"bindex=%d dstart/end=%d:%d\n",
dentry, lower_dentry,
(lower_dentry ?
lower_dentry->d_inode :
- (void *) 0xffffffff),
+ (void *) -1L),
bindex, dstart, dend);
}
}
lower_mnt = unionfs_lower_mnt_idx(dentry, bindex);
if (lower_mnt) {
if (bindex < dstart || bindex > dend) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" CM0: dentry/lmnt=%p:%p bindex=%d "
"dstart/end=%d:%d\n", dentry,
lower_mnt, bindex, dstart, dend);
if (inode &&
!(inode && S_ISDIR(inode->i_mode) &&
bindex > dstart && bindex < dend)) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" CM1: dentry/lmnt=%p:%p "
"bindex=%d dstart/end=%d:%d\n",
dentry, lower_mnt, bindex,
BUG_ON(istart > iend);
if ((istart == -1 && iend != -1) ||
(istart != -1 && iend == -1)) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" CI0: dentry/inode=%p:%p istart/end=%d:%d\n",
dentry, inode, istart, iend);
}
if (istart != dstart) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" CI1: dentry/inode=%p:%p istart=%d dstart=%d\n",
dentry, inode, istart, dstart);
}
if (iend != dend) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" CI2: dentry/inode=%p:%p iend=%d dend=%d\n",
dentry, inode, iend, dend);
}
if (!S_ISDIR(inode->i_mode)) {
if (dend != dstart) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" CI3: dentry/inode=%p:%p dstart=%d dend=%d\n",
dentry, inode, dstart, dend);
}
if (iend != istart) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" CI4: dentry/inode=%p:%p istart=%d iend=%d\n",
dentry, inode, istart, iend);
}
lower_inode = unionfs_lower_inode_idx(inode, bindex);
if (lower_inode) {
if (bindex < istart || bindex > iend) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" CI5: dentry/linode=%p:%p bindex=%d "
"istart/end=%d:%d\n", dentry,
lower_inode, bindex, istart, iend);
- } else if ((int)lower_inode == 0x5a5a5a5a) {
+ } else if (lower_inode == POISONED_PTR) {
/* freed inode! */
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" CI6: dentry/linode=%p:%p bindex=%d "
"istart/end=%d:%d\n", dentry,
lower_inode, bindex, istart, iend);
*/
if (!(S_ISDIR(inode->i_mode) &&
bindex > istart && bindex < iend)) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" CI7: dentry/linode=%p:%p "
"bindex=%d istart/end=%d:%d\n",
dentry, lower_inode, bindex,
lower_mnt = unionfs_lower_mnt_idx(dentry, bindex);
if (!((lower_inode && lower_dentry && lower_mnt) ||
(!lower_inode && !lower_dentry && !lower_mnt))) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" Cx: lmnt/ldentry/linode=%p:%p:%p "
"bindex=%d dstart/end=%d:%d\n",
lower_mnt, lower_dentry, lower_inode,
}
/* check if lower inode is newer than upper one (it shouldn't) */
if (is_newer_lower(dentry)) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
for (bindex=ibstart(inode); bindex <= ibend(inode); bindex++) {
lower_inode = unionfs_lower_inode_idx(inode, bindex);
if (!lower_inode)
if ((fstart == -1 && fend != -1) ||
(fstart != -1 && fend == -1)) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" CF0: file/dentry=%p:%p fstart/end=%d:%d\n",
file, dentry, fstart, fend);
}
if (fstart != dstart) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" CF1: file/dentry=%p:%p fstart=%d dstart=%d\n",
file, dentry, fstart, dstart);
}
if (fend != dend) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" CF2: file/dentry=%p:%p fend=%d dend=%d\n",
file, dentry, fend, dend);
}
inode = dentry->d_inode;
if (!S_ISDIR(inode->i_mode)) {
if (fend != fstart) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" CF3: file/inode=%p:%p fstart=%d fend=%d\n",
file, inode, fstart, fend);
}
if (dend != dstart) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" CF4: file/dentry=%p:%p dstart=%d dend=%d\n",
file, dentry, dstart, dend);
}
lower_file = unionfs_lower_file_idx(file, bindex);
if (lower_file) {
if (bindex < fstart || bindex > fend) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" CF5: file/lower=%p:%p bindex=%d "
"fstart/end=%d:%d\n",
file, lower_file, bindex, fstart, fend);
*/
if (!(S_ISDIR(inode->i_mode) &&
bindex > fstart && bindex < fend)) {
- PRINT_CALLER();
+ PRINT_CALLER(fname, fxn, line);
printk(" CF6: file/lower=%p:%p "
"bindex=%d fstart/end=%d:%d\n",
file, lower_file, bindex,
* Assume that dentry's info node is locked.
* Assume that parent(s) are all valid already, but
* the child may not yet be valid.
- * Returns 1 if valid, 0 otherwise.
+ * Returns true if valid, false otherwise.
*/
-static int __unionfs_d_revalidate_one(struct dentry *dentry,
+static bool __unionfs_d_revalidate_one(struct dentry *dentry,
struct nameidata *nd)
{
- int valid = 1; /* default is valid (1); invalid is 0. */
+ bool valid = true; /* default is valid */
struct dentry *lower_dentry;
int bindex, bstart, bend;
int sbgen, dgen;
interpose_flag);
if (result) {
if (IS_ERR(result)) {
- valid = 0;
+ valid = false;
goto out;
}
/*
if (positive && UNIONFS_I(dentry->d_inode)->stale) {
make_bad_inode(dentry->d_inode);
d_drop(dentry);
- valid = 0;
+ valid = false;
goto out;
}
goto out;
continue;
if (!lower_dentry->d_op->d_revalidate(lower_dentry,
&lowernd))
- valid = 0;
+ valid = false;
}
if (!dentry->d_inode)
- valid = 0;
+ valid = false;
if (valid) {
/*
* Determine if the lower inode objects have changed from below the unionfs
* inode. Return 1 if changed, 0 otherwise.
*/
-int is_newer_lower(const struct dentry *dentry)
+bool is_newer_lower(const struct dentry *dentry)
{
int bindex;
struct inode *inode;
/* ignore if we're called on semi-initialized dentries/inodes */
if (!dentry || !UNIONFS_D(dentry))
- return 0;
+ return false;
inode = dentry->d_inode;
if (!inode || !UNIONFS_I(inode) ||
ibstart(inode) < 0 || ibend(inode) < 0)
- return 0;
+ return false;
for (bindex = ibstart(inode); bindex <= ibend(inode); bindex++) {
lower_inode = unionfs_lower_inode_idx(inode, bindex);
"(bindex=%d, name=%s)\n", bindex,
dentry->d_name.name);
show_dinode_times(dentry);
- return 1; /* mtime changed! */
+ return true; /* mtime changed! */
}
if (timespec_compare(&inode->i_ctime,
&lower_inode->i_ctime) < 0) {
"(bindex=%d, name=%s)\n", bindex,
dentry->d_name.name);
show_dinode_times(dentry);
- return 1; /* ctime changed! */
+ return true; /* ctime changed! */
}
}
- return 0; /* default: lower is not newer */
+ return true; /* default: lower is not newer */
}
/*
* active mappings and force a ->readpage, let us know please
* (invalidate_inode_pages2 doesn't do the trick).
*/
-static inline void purge_inode_data(struct dentry *dentry)
+static inline void purge_inode_data(struct inode *inode)
{
/* remove all non-private mappings */
- unmap_mapping_range(dentry->d_inode->i_mapping, 0, 0, 0);
+ unmap_mapping_range(inode->i_mapping, 0, 0, 0);
- if (dentry->d_inode->i_data.nrpages)
- truncate_inode_pages(&dentry->d_inode->i_data, 0);
+ if (inode->i_data.nrpages)
+ truncate_inode_pages(&inode->i_data, 0);
}
/*
* authoritative than what's below, therefore we can safely overwrite the
* lower inode times and data.
*/
-int __unionfs_d_revalidate_chain(struct dentry *dentry, struct nameidata *nd,
- int willwrite)
+bool __unionfs_d_revalidate_chain(struct dentry *dentry, struct nameidata *nd,
+ bool willwrite)
{
- int valid = 0; /* default is invalid (0); valid is 1. */
+ bool valid = false; /* default is invalid */
struct dentry **chain = NULL; /* chain of dentries to reval */
int chain_len = 0;
struct dentry *dtmp;
dgen = 0;
atomic_set(&UNIONFS_D(dtmp)->generation, dgen);
}
- purge_inode_data(dtmp);
+ purge_inode_data(dtmp->d_inode);
}
while (sbgen != dgen) {
/* The root entry should always be valid */
atomic_set(&UNIONFS_D(dentry)->generation, dgen);
}
if (!willwrite)
- purge_inode_data(dentry);
+ purge_inode_data(dentry->d_inode);
}
valid = __unionfs_d_revalidate_one(dentry, nd);
unionfs_read_lock(dentry->d_sb);
unionfs_lock_dentry(dentry);
- err = __unionfs_d_revalidate_chain(dentry, nd, 0);
+ err = __unionfs_d_revalidate_chain(dentry, nd, false);
unionfs_unlock_dentry(dentry);
unionfs_check_dentry(dentry);
unionfs_lock_dentry(dentry);
unionfs_lock_dentry(dentry->d_parent);
- valid = __unionfs_d_revalidate_chain(dentry->d_parent, nd, 0);
+ valid = __unionfs_d_revalidate_chain(dentry->d_parent, nd, false);
unionfs_unlock_dentry(dentry->d_parent);
if (!valid) {
err = -ESTALE; /* same as what real_lookup does */
goto out;
}
- valid = __unionfs_d_revalidate_chain(dentry, nd, 0);
+ valid = __unionfs_d_revalidate_chain(dentry, nd, false);
/*
* It's only a bug if this dentry was not negative and couldn't be
* revalidated (shouldn't happen).
unionfs_read_lock(old_dentry->d_sb);
unionfs_double_lock_dentry(new_dentry, old_dentry);
- if (!__unionfs_d_revalidate_chain(old_dentry, NULL, 0)) {
+ if (!__unionfs_d_revalidate_chain(old_dentry, NULL, false)) {
err = -ESTALE;
goto out;
}
if (new_dentry->d_inode &&
- !__unionfs_d_revalidate_chain(new_dentry, NULL, 0)) {
+ !__unionfs_d_revalidate_chain(new_dentry, NULL, false)) {
err = -ESTALE;
goto out;
}
unionfs_lock_dentry(dentry);
if (dentry->d_inode &&
- !__unionfs_d_revalidate_chain(dentry, NULL, 0)) {
+ !__unionfs_d_revalidate_chain(dentry, NULL, false)) {
err = -ESTALE;
goto out;
}
unionfs_lock_dentry(dentry);
if (dentry->d_inode &&
- !__unionfs_d_revalidate_chain(dentry, NULL, 0)) {
+ !__unionfs_d_revalidate_chain(dentry, NULL, false)) {
err = -ESTALE;
goto out;
}
unionfs_lock_dentry(dentry);
if (dentry->d_inode &&
- !__unionfs_d_revalidate_chain(dentry, NULL, 0)) {
+ !__unionfs_d_revalidate_chain(dentry, NULL, false)) {
err = -ESTALE;
goto out;
}
unionfs_read_lock(dentry->d_sb);
unionfs_lock_dentry(dentry);
- if (!__unionfs_d_revalidate_chain(dentry, NULL, 0)) {
+ if (!__unionfs_d_revalidate_chain(dentry, NULL, false)) {
err = -ESTALE;
goto out;
}
unionfs_read_lock(dentry->d_sb);
unionfs_lock_dentry(dentry);
- if (!__unionfs_d_revalidate_chain(dentry, nd, 0))
+ if (!__unionfs_d_revalidate_chain(dentry, nd, false))
printk("unionfs: put_link failed to revalidate dentry\n");
unionfs_unlock_dentry(dentry);
unionfs_read_lock(dentry->d_sb);
unionfs_lock_dentry(dentry);
- if (!__unionfs_d_revalidate_chain(dentry, NULL, 0)) {
+ if (!__unionfs_d_revalidate_chain(dentry, NULL, false)) {
err = -ESTALE;
goto out;
}
unionfs_read_lock(old_dentry->d_sb);
unionfs_double_lock_dentry(old_dentry, new_dentry);
- if (!__unionfs_d_revalidate_chain(old_dentry, NULL, 0)) {
+ if (!__unionfs_d_revalidate_chain(old_dentry, NULL, false)) {
err = -ESTALE;
goto out;
}
if (!d_deleted(new_dentry) && new_dentry->d_inode &&
- !__unionfs_d_revalidate_chain(new_dentry, NULL, 0)) {
+ !__unionfs_d_revalidate_chain(new_dentry, NULL, false)) {
err = -ESTALE;
goto out;
}
struct inode *inode;
inode = unionfs_lower_inode(
old_dentry->d_inode);
- atomic_inc(&inode->i_count);
+ igrab(inode);
unionfs_set_lower_inode_idx(
new_dentry->d_inode,
dbstart(new_dentry), inode);
unionfs_read_lock(sb);
unionfs_lock_dentry(dentry);
- if (!__unionfs_d_revalidate_chain(dentry, NULL, 0)) {
+ if (!__unionfs_d_revalidate_chain(dentry, NULL, false)) {
err = -ESTALE;
goto out;
}
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);
err = -ENOMEM;
goto out_release;
}
+
/* allocate space for new pointers to lower inodes */
new_lower_inodes = kcalloc(new_branches,
sizeof(struct inode *), GFP_KERNEL);
extern int unionfs_unlink(struct inode *dir, struct dentry *dentry);
extern int unionfs_rmdir(struct inode *dir, struct dentry *dentry);
-extern int __unionfs_d_revalidate_chain(struct dentry *dentry,
- struct nameidata *nd, int willwrite);
-extern int is_newer_lower(const struct dentry *dentry);
+extern bool __unionfs_d_revalidate_chain(struct dentry *dentry,
+ struct nameidata *nd, bool willwrite);
+extern bool is_newer_lower(const struct dentry *dentry);
/* The values for unionfs_interpose's flag. */
#define INTERPOSE_DEFAULT 0
#else /* not CONFIG_UNION_FS_DEBUG */
/* we leave useful hooks for these check functions throughout the code */
-#define unionfs_check_inode(i)
-#define unionfs_check_dentry(d)
-#define unionfs_check_file(f)
-#define show_branch_counts(sb)
-#define show_inode_times(i)
-#define show_dinode_times(d)
-#define show_inode_counts(i)
+#define unionfs_check_inode(i) do { } while(0)
+#define unionfs_check_dentry(d) do { } while(0)
+#define unionfs_check_file(f) do { } while(0)
+#define show_branch_counts(sb) do { } while(0)
+#define show_inode_times(i) do { } while(0)
+#define show_dinode_times(d) do { } while(0)
+#define show_inode_counts(i) do { } while(0)
#endif /* not CONFIG_UNION_FS_DEBUG */
unionfs_read_lock(dentry->d_sb);
unionfs_lock_dentry(dentry);
- if (!__unionfs_d_revalidate_chain(dentry, NULL, 0)) {
+ if (!__unionfs_d_revalidate_chain(dentry, NULL, false)) {
err = -ESTALE;
goto out;
}
unionfs_read_lock(dentry->d_sb);
unionfs_lock_dentry(dentry);
- if (!__unionfs_d_revalidate_chain(dentry, NULL, 0)) {
+ if (!__unionfs_d_revalidate_chain(dentry, NULL, false)) {
err = -ESTALE;
goto out;
}
unionfs_read_lock(dentry->d_sb);
unionfs_lock_dentry(dentry);
- if (!__unionfs_d_revalidate_chain(dentry, NULL, 0)) {
+ if (!__unionfs_d_revalidate_chain(dentry, NULL, false)) {
err = -ESTALE;
goto out;
}
unionfs_read_lock(dentry->d_sb);
unionfs_lock_dentry(dentry);
- if (!__unionfs_d_revalidate_chain(dentry, NULL, 0)) {
+ if (!__unionfs_d_revalidate_chain(dentry, NULL, false)) {
err = -ESTALE;
goto out;
}
unionfs_read_lock(dentry->d_sb);
unionfs_lock_dentry(dentry);
- if (!__unionfs_d_revalidate_chain(dentry, NULL, 0)) {
+ if (!__unionfs_d_revalidate_chain(dentry, NULL, false)) {
err = -ESTALE;
goto out;
}
unionfs_read_lock(dentry->d_sb);
unionfs_lock_dentry(dentry);
- if (!__unionfs_d_revalidate_chain(dentry, NULL, 0)) {
+ if (!__unionfs_d_revalidate_chain(dentry, NULL, false)) {
err = -ESTALE;
goto out;
}
dest->i_ctime = src->i_ctime;
}
-#endif /* not _LINUX_FS_STACK_H */
+#endif /* _LINUX_FS_STACK_H */