valid = __unionfs_d_revalidate_chain(dentry->d_parent, nd);
unionfs_unlock_dentry(dentry->d_parent);
if (!valid) {
- err = -ENOENT; /* same as what real_lookup does */
+ err = -ESTALE; /* same as what real_lookup does */
goto out;
}
valid = __unionfs_d_revalidate_chain(dentry, nd);
struct path path_save;
struct dentry *ret;
+ /*
+ * lookup is the only special function which takes a dentry, yet we
+ * do NOT want to call __unionfs_d_revalidate_chain because by
+ * definition, we don't have a valid dentry here yet.
+ */
+
/* save the dentry & vfsmnt from namei */
if (nd) {
path_save.dentry = nd->dentry;
struct dentry *whiteout_dentry;
char *name = NULL;
- BUG_ON(!is_valid_dentry(new_dentry));
- BUG_ON(!is_valid_dentry(old_dentry));
-
unionfs_double_lock_dentry(new_dentry, old_dentry);
+ if (!__unionfs_d_revalidate_chain(old_dentry, NULL)) {
+ err = -ESTALE;
+ goto out;
+ }
+ if (new_dentry->d_inode &&
+ !__unionfs_d_revalidate_chain(new_dentry, NULL)) {
+ err = -ESTALE;
+ goto out;
+ }
+
hidden_new_dentry = unionfs_lower_dentry(new_dentry);
/*
int bindex = 0, bstart;
char *name = NULL;
- BUG_ON(!is_valid_dentry(dentry));
-
unionfs_lock_dentry(dentry);
+ if (dentry->d_inode &&
+ !__unionfs_d_revalidate_chain(dentry, NULL)) {
+ err = -ESTALE;
+ goto out;
+ }
+
/* We start out in the leftmost branch. */
bstart = dbstart(dentry);
int whiteout_unlinked = 0;
struct sioq_args args;
- BUG_ON(!is_valid_dentry(dentry));
-
unionfs_lock_dentry(dentry);
+
+ if (dentry->d_inode &&
+ !__unionfs_d_revalidate_chain(dentry, NULL)) {
+ err = -ESTALE;
+ goto out;
+ }
+
bstart = dbstart(dentry);
hidden_dentry = unionfs_lower_dentry(dentry);
char *name = NULL;
int whiteout_unlinked = 0;
- BUG_ON(!is_valid_dentry(dentry));
-
unionfs_lock_dentry(dentry);
+
+ if (dentry->d_inode &&
+ !__unionfs_d_revalidate_chain(dentry, NULL)) {
+ err = -ESTALE;
+ goto out;
+ }
+
bstart = dbstart(dentry);
hidden_dentry = unionfs_lower_dentry(dentry);
int err;
struct dentry *hidden_dentry;
- BUG_ON(!is_valid_dentry(dentry));
-
unionfs_lock_dentry(dentry);
+
+ if (!__unionfs_d_revalidate_chain(dentry, NULL)) {
+ err = -ESTALE;
+ goto out;
+ }
+
hidden_dentry = unionfs_lower_dentry(dentry);
if (!hidden_dentry->d_inode->i_op ||
int len = PAGE_SIZE, err;
mm_segment_t old_fs;
- BUG_ON(!is_valid_dentry(dentry));
+ unionfs_lock_dentry(dentry);
+
+ if (dentry->d_inode &&
+ !__unionfs_d_revalidate_chain(dentry, nd)) {
+ err = -ESTALE;
+ goto out;
+ }
/* This is freed by the put_link method assuming a successful call. */
buf = kmalloc(len, GFP_KERNEL);
err = 0;
out:
+ unionfs_unlock_dentry(dentry);
unionfs_check_dentry(dentry);
return ERR_PTR(err);
}
static void unionfs_put_link(struct dentry *dentry, struct nameidata *nd,
void *cookie)
{
+ unionfs_lock_dentry(dentry);
+ if (!__unionfs_d_revalidate_chain(dentry, nd))
+ printk("unionfs: put_link failed to revalidate dentry\n");
+ unionfs_unlock_dentry(dentry);
+
unionfs_check_dentry(dentry);
kfree(nd_get_link(nd));
}
int i;
int copyup = 0;
- BUG_ON(!is_valid_dentry(dentry));
-
unionfs_lock_dentry(dentry);
+
+ if (!__unionfs_d_revalidate_chain(dentry, NULL)) {
+ err = -ESTALE;
+ goto out;
+ }
+
bstart = dbstart(dentry);
bend = dbend(dentry);
inode = dentry->d_inode;
int err = 0;
struct dentry *wh_dentry;
- BUG_ON(!is_valid_dentry(old_dentry));
- BUG_ON(!is_valid_dentry(new_dentry));
-
unionfs_double_lock_dentry(old_dentry, new_dentry);
+ if (!__unionfs_d_revalidate_chain(old_dentry, NULL)) {
+ err = -ESTALE;
+ goto out;
+ }
+ if (!d_deleted(new_dentry) && new_dentry->d_inode &&
+ !__unionfs_d_revalidate_chain(new_dentry, NULL)) {
+ err = -ESTALE;
+ goto out;
+ }
+
if (!S_ISDIR(old_dentry->d_inode->i_mode))
err = unionfs_partial_lookup(old_dentry);
else
struct super_block *sb;
struct dentry *lower_dentry;
- BUG_ON(!is_valid_dentry(dentry));
unionfs_check_dentry(dentry);
+ unionfs_lock_dentry(dentry);
+
+ if (!__unionfs_d_revalidate_chain(dentry, NULL)) {
+ err = -ESTALE;
+ goto out;
+ }
sb = dentry->d_sb;
memset(&buf->f_fsid, 0, sizeof(__kernel_fsid_t));
memset(&buf->f_spare, 0, sizeof(buf->f_spare));
+out:
+ unionfs_unlock_dentry(dentry);
unionfs_check_dentry(dentry);
return err;
}
return is_robranch_idx(dentry, index);
}
-/*
- * Check if dentry is valid or not, as per our generation numbers.
- * @dentry: dentry to check.
- * Returns 1 (valid) or 0 (invalid/stale).
- */
-static inline int is_valid_dentry(struct dentry *dentry)
-{
- BUG_ON(!UNIONFS_D(dentry));
- BUG_ON(!UNIONFS_SB(dentry->d_sb));
- return (atomic_read(&UNIONFS_D(dentry)->generation) ==
- atomic_read(&UNIONFS_SB(dentry->d_sb)->generation));
-}
-
/* What do we use for whiteouts. */
#define UNIONFS_WHPFX ".wh."
#define UNIONFS_WHLEN 4
{
int err = 0;
- BUG_ON(!is_valid_dentry(dentry));
-
unionfs_check_dentry(dentry);
unionfs_lock_dentry(dentry);
+ if (!__unionfs_d_revalidate_chain(dentry, NULL)) {
+ err = -ESTALE;
+ goto out;
+ }
+
err = unionfs_unlink_whiteout(dir, dentry);
/* call d_drop so the system "forgets" about us */
if (!err) {
d_drop(dentry);
}
+out:
unionfs_unlock_dentry(dentry);
return err;
}
int err = 0;
struct unionfs_dir_state *namelist = NULL;
- BUG_ON(!is_valid_dentry(dentry));
-
unionfs_check_dentry(dentry);
unionfs_lock_dentry(dentry);
+ if (!__unionfs_d_revalidate_chain(dentry, NULL)) {
+ err = -ESTALE;
+ goto out;
+ }
+
/* check if this unionfs directory is empty or not */
err = check_empty(dentry, &namelist);
if (err)
struct dentry *hidden_dentry = NULL;
int err = -EOPNOTSUPP;
- BUG_ON(!is_valid_dentry(dentry));
-
unionfs_lock_dentry(dentry);
+ if (!__unionfs_d_revalidate_chain(dentry, NULL)) {
+ err = -ESTALE;
+ goto out;
+ }
+
hidden_dentry = unionfs_lower_dentry(dentry);
err = vfs_getxattr(hidden_dentry, (char*) name, value, size);
+out:
unionfs_unlock_dentry(dentry);
unionfs_check_dentry(dentry);
return err;
struct dentry *hidden_dentry = NULL;
int err = -EOPNOTSUPP;
- BUG_ON(!is_valid_dentry(dentry));
-
unionfs_lock_dentry(dentry);
+
+ if (!__unionfs_d_revalidate_chain(dentry, NULL)) {
+ err = -ESTALE;
+ goto out;
+ }
+
hidden_dentry = unionfs_lower_dentry(dentry);
err = vfs_setxattr(hidden_dentry, (char*) name, (void*) value,
size, flags);
+out:
unionfs_unlock_dentry(dentry);
unionfs_check_dentry(dentry);
return err;
struct dentry *hidden_dentry = NULL;
int err = -EOPNOTSUPP;
- BUG_ON(!is_valid_dentry(dentry));
-
unionfs_lock_dentry(dentry);
+
+ if (!__unionfs_d_revalidate_chain(dentry, NULL)) {
+ err = -ESTALE;
+ goto out;
+ }
+
hidden_dentry = unionfs_lower_dentry(dentry);
err = vfs_removexattr(hidden_dentry, (char*) name);
+out:
unionfs_unlock_dentry(dentry);
unionfs_check_dentry(dentry);
return err;
int err = -EOPNOTSUPP;
char *encoded_list = NULL;
- BUG_ON(!is_valid_dentry(dentry));
-
unionfs_lock_dentry(dentry);
+ if (!__unionfs_d_revalidate_chain(dentry, NULL)) {
+ err = -ESTALE;
+ goto out;
+ }
+
hidden_dentry = unionfs_lower_dentry(dentry);
encoded_list = list;
err = vfs_listxattr(hidden_dentry, encoded_list, size);
+out:
unionfs_unlock_dentry(dentry);
unionfs_check_dentry(dentry);
return err;