fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / fs / namei.c
index b9d0804..9714ca5 100644 (file)
@@ -34,7 +34,9 @@
 #include <linux/namei.h>
 #include <linux/proc_fs.h>
 #include <linux/vserver/inode.h>
-#include <linux/vserver/debug.h>
+#include <linux/vs_base.h>
+#include <linux/vs_tag.h>
+#include <linux/vs_cowbl.h>
 #include <asm/namei.h>
 #include <asm/uaccess.h>
 
@@ -228,9 +230,9 @@ int generic_permission(struct inode *inode, int mask,
        return -EACCES;
 }
 
-static inline int vx_barrier(struct inode *inode)
+static inline int dx_barrier(struct inode *inode)
 {
-       if (IS_BARRIER(inode) && !vx_check(0, VX_ADMIN|VX_WATCH)) {
+       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN)) {
                vxwprintk(1, "xid=%d did hit the barrier.",
                        vx_current_xid());
                return 1;
@@ -238,17 +240,17 @@ static inline int vx_barrier(struct inode *inode)
        return 0;
 }
 
-static inline int xid_permission(struct inode *inode, int mask, struct nameidata *nd)
+static inline int dx_permission(struct inode *inode, int mask, struct nameidata *nd)
 {
-       if (vx_barrier(inode))
+       if (dx_barrier(inode))
                return -EACCES;
-       if (inode->i_xid == 0)
+       if (inode->i_tag == 0)
                return 0;
-       if (vx_check(inode->i_xid, VX_ADMIN|VX_WATCH|VX_IDENT))
+       if (dx_check(inode->i_tag, DX_ADMIN|DX_WATCH|DX_IDENT))
                return 0;
 
        vxwprintk(1, "xid=%d denied access to %p[#%d,%lu] »%s«.",
-               vx_current_xid(), inode, inode->i_xid, inode->i_ino,
+               vx_current_xid(), inode, inode->i_tag, inode->i_ino,
                vxd_cond_path(nd));
        return -EACCES;
 }
@@ -270,21 +272,23 @@ int permission(struct inode *inode, int mask, struct nameidata *nd)
                /*
                 * Nobody gets write access to an immutable file.
                 */
-               if (IS_IMMUTABLE(inode))
+               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
                        return -EACCES;
        }
 
 
        /*
         * MAY_EXEC on regular files requires special handling: We override
-        * filesystem execute permissions if the mode bits aren't set.
+        * filesystem execute permissions if the mode bits aren't set or
+        * the fs is mounted with the "noexec" flag.
         */
-       if ((mask & MAY_EXEC) && S_ISREG(mode) && !(mode & S_IXUGO))
+       if ((mask & MAY_EXEC) && S_ISREG(mode) && (!(mode & S_IXUGO) ||
+                       (nd && nd->mnt && (nd->mnt->mnt_flags & MNT_NOEXEC))))
                return -EACCES;
 
        /* Ordinary permission routines do not understand MAY_APPEND. */
        submask = mask & ~MAY_APPEND;
-       if ((retval = xid_permission(inode, mask, nd)))
+       if ((retval = dx_permission(inode, mask, nd)))
                return retval;
        if (inode->i_op && inode->i_op->permission)
                retval = inode->i_op->permission(inode, submask, nd);
@@ -325,7 +329,7 @@ int vfs_permission(struct nameidata *nd, int mask)
  */
 int file_permission(struct file *file, int mask)
 {
-       return permission(file->f_dentry->d_inode, mask, NULL);
+       return permission(file->f_path.dentry->d_inode, mask, NULL);
 }
 
 /*
@@ -361,7 +365,7 @@ int get_write_access(struct inode * inode)
 
 int deny_write_access(struct file * file)
 {
-       struct inode *inode = file->f_dentry->d_inode;
+       struct inode *inode = file->f_path.dentry->d_inode;
 
        spin_lock(&inode->i_lock);
        if (atomic_read(&inode->i_writecount) > 0) {
@@ -396,13 +400,14 @@ void path_release_on_umount(struct nameidata *nd)
  */
 void release_open_intent(struct nameidata *nd)
 {
-       if (nd->intent.open.file->f_dentry == NULL)
+       if (nd->intent.open.file->f_path.dentry == NULL)
                put_filp(nd->intent.open.file);
        else
                fput(nd->intent.open.file);
 }
 
-static inline struct dentry *do_revalidate(struct dentry *dentry, struct nameidata *nd)
+static inline struct dentry *
+do_revalidate(struct dentry *dentry, struct nameidata *nd)
 {
        int status = dentry->d_op->d_revalidate(dentry, nd);
        if (unlikely(status <= 0)) {
@@ -460,7 +465,7 @@ static int exec_permission_lite(struct inode *inode,
 {
        umode_t mode = inode->i_mode;
 
-       if (vx_barrier(inode))
+       if (dx_barrier(inode))
                return -EACCES;
        if (inode->i_op && inode->i_op->permission)
                return -EAGAIN;
@@ -549,18 +554,20 @@ static int __emul_lookup_dentry(const char *, struct nameidata *);
 static __always_inline int
 walk_init_root(const char *name, struct nameidata *nd)
 {
-       read_lock(&current->fs->lock);
-       if (current->fs->altroot && !(nd->flags & LOOKUP_NOALT)) {
-               nd->mnt = mntget(current->fs->altrootmnt);
-               nd->dentry = dget(current->fs->altroot);
-               read_unlock(&current->fs->lock);
+       struct fs_struct *fs = current->fs;
+
+       read_lock(&fs->lock);
+       if (fs->altroot && !(nd->flags & LOOKUP_NOALT)) {
+               nd->mnt = mntget(fs->altrootmnt);
+               nd->dentry = dget(fs->altroot);
+               read_unlock(&fs->lock);
                if (__emul_lookup_dentry(name,nd))
                        return 0;
-               read_lock(&current->fs->lock);
+               read_lock(&fs->lock);
        }
-       nd->mnt = mntget(current->fs->rootmnt);
-       nd->dentry = dget(current->fs->root);
-       read_unlock(&current->fs->lock);
+       nd->mnt = mntget(fs->rootmnt);
+       nd->dentry = dget(fs->root);
+       read_unlock(&fs->lock);
        return 1;
 }
 
@@ -599,11 +606,6 @@ fail:
        return PTR_ERR(link);
 }
 
-struct path {
-       struct vfsmount *mnt;
-       struct dentry *dentry;
-};
-
 static inline void dput_path(struct path *path, struct nameidata *nd)
 {
        dput(path->dentry);
@@ -755,18 +757,20 @@ int follow_down(struct vfsmount **mnt, struct dentry **dentry)
 
 static __always_inline void follow_dotdot(struct nameidata *nd)
 {
+       struct fs_struct *fs = current->fs;
+
        while(1) {
                struct vfsmount *parent;
                struct dentry *old = nd->dentry;
 
-                read_lock(&current->fs->lock);
-               if (nd->dentry == current->fs->root &&
-                   nd->mnt == current->fs->rootmnt) {
-                        read_unlock(&current->fs->lock);
+                read_lock(&fs->lock);
+               if (nd->dentry == fs->root &&
+                   nd->mnt == fs->rootmnt) {
+                        read_unlock(&fs->lock);
                        /* for sane '/' avoid follow_mount() */
                        return;
                }
-                read_unlock(&current->fs->lock);
+                read_unlock(&fs->lock);
                spin_lock(&dcache_lock);
                if (nd->dentry != nd->mnt->mnt_root) {
                        nd->dentry = dget(nd->dentry->d_parent);
@@ -797,7 +801,7 @@ static __always_inline void follow_dotdot(struct nameidata *nd)
  *  It _is_ time-critical.
  */
 static int do_lookup(struct nameidata *nd, struct qstr *name,
-                    struct path *path, int atomic)
+                    struct path *path)
 {
        struct vfsmount *mnt = nd->mnt;
        struct dentry *dentry = __d_lookup(nd->dentry, name);
@@ -807,41 +811,36 @@ static int do_lookup(struct nameidata *nd, struct qstr *name,
                goto need_lookup;
        if (dentry->d_op && dentry->d_op->d_revalidate)
                goto need_revalidate;
-done:
        inode = dentry->d_inode;
        if (!inode)
-               goto no_inode;
-       if (!vx_check(inode->i_xid, VX_WATCH|VX_ADMIN|VX_HOSTID|VX_IDENT))
-               goto hidden;
+               goto done;
        if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
                struct proc_dir_entry *de = PDE(inode);
 
                if (de && !vx_hide_check(0, de->vx_flags))
                        goto hidden;
        }
-no_inode:
+       if (!dx_check(inode->i_tag, DX_WATCH|DX_ADMIN|DX_HOSTID|DX_IDENT))
+               goto hidden;
+done:
        path->mnt = mnt;
        path->dentry = dentry;
        __follow_mount(path);
        return 0;
 hidden:
        vxwprintk(1, "xid=%d did lookup hidden %p[#%d,%lu] »%s«.",
-               vx_current_xid(), inode, inode->i_xid, inode->i_ino,
+               vx_current_xid(), inode, inode->i_tag, inode->i_ino,
                vxd_path(dentry, mnt));
        dput(dentry);
        return -ENOENT;
 
 need_lookup:
-       if (atomic)
-               return -EWOULDBLOCKIO;
        dentry = real_lookup(nd->dentry, name, nd);
        if (IS_ERR(dentry))
                goto fail;
        goto done;
 
 need_revalidate:
-       if (atomic)
-               return -EWOULDBLOCKIO;
        dentry = do_revalidate(dentry, nd);
        if (!dentry)
                goto need_lookup;
@@ -865,11 +864,9 @@ static fastcall int __link_path_walk(const char * name, struct nameidata *nd)
 {
        struct path next;
        struct inode *inode;
-       int err, atomic;
+       int err;
        unsigned int lookup_flags = nd->flags;
-
-       atomic = (lookup_flags & LOOKUP_ATOMIC);
-
+       
        while (*name=='/')
                name++;
        if (!*name)
@@ -938,7 +935,7 @@ static fastcall int __link_path_walk(const char * name, struct nameidata *nd)
                                break;
                }
                /* This does the actual lookups.. */
-               err = do_lookup(nd, &this, &next, atomic);
+               err = do_lookup(nd, &this, &next);
                if (err)
                        break;
 
@@ -993,7 +990,7 @@ last_component:
                        if (err < 0)
                                break;
                }
-               err = do_lookup(nd, &this, &next, atomic);
+               err = do_lookup(nd, &this, &next);
                if (err)
                        break;
                inode = next.dentry->d_inode;
@@ -1099,15 +1096,17 @@ static int __emul_lookup_dentry(const char *name, struct nameidata *nd)
                struct vfsmount *old_mnt = nd->mnt;
                struct qstr last = nd->last;
                int last_type = nd->last_type;
+               struct fs_struct *fs = current->fs;
+
                /*
-                * NAME was not found in alternate root or it's a directory.  Try to find
-                * it in the normal root:
+                * NAME was not found in alternate root or it's a directory.
+                * Try to find it in the normal root:
                 */
                nd->last_type = LAST_ROOT;
-               read_lock(&current->fs->lock);
-               nd->mnt = mntget(current->fs->rootmnt);
-               nd->dentry = dget(current->fs->root);
-               read_unlock(&current->fs->lock);
+               read_lock(&fs->lock);
+               nd->mnt = mntget(fs->rootmnt);
+               nd->dentry = dget(fs->root);
+               read_unlock(&fs->lock);
                if (path_walk(name, nd) == 0) {
                        if (nd->dentry->d_inode) {
                                dput(old_dentry);
@@ -1131,6 +1130,7 @@ void set_fs_altroot(void)
        struct vfsmount *mnt = NULL, *oldmnt;
        struct dentry *dentry = NULL, *olddentry;
        int err;
+       struct fs_struct *fs = current->fs;
 
        if (!emul)
                goto set_it;
@@ -1140,12 +1140,12 @@ void set_fs_altroot(void)
                dentry = nd.dentry;
        }
 set_it:
-       write_lock(&current->fs->lock);
-       oldmnt = current->fs->altrootmnt;
-       olddentry = current->fs->altroot;
-       current->fs->altrootmnt = mnt;
-       current->fs->altroot = dentry;
-       write_unlock(&current->fs->lock);
+       write_lock(&fs->lock);
+       oldmnt = fs->altrootmnt;
+       olddentry = fs->altroot;
+       fs->altrootmnt = mnt;
+       fs->altroot = dentry;
+       write_unlock(&fs->lock);
        if (olddentry) {
                dput(olddentry);
                mntput(oldmnt);
@@ -1159,29 +1159,30 @@ static int fastcall do_path_lookup(int dfd, const char *name,
        int retval = 0;
        int fput_needed;
        struct file *file;
+       struct fs_struct *fs = current->fs;
 
        nd->last_type = LAST_ROOT; /* if there are only slashes... */
        nd->flags = flags;
        nd->depth = 0;
 
        if (*name=='/') {
-               read_lock(&current->fs->lock);
-               if (current->fs->altroot && !(nd->flags & LOOKUP_NOALT)) {
-                       nd->mnt = mntget(current->fs->altrootmnt);
-                       nd->dentry = dget(current->fs->altroot);
-                       read_unlock(&current->fs->lock);
+               read_lock(&fs->lock);
+               if (fs->altroot && !(nd->flags & LOOKUP_NOALT)) {
+                       nd->mnt = mntget(fs->altrootmnt);
+                       nd->dentry = dget(fs->altroot);
+                       read_unlock(&fs->lock);
                        if (__emul_lookup_dentry(name,nd))
                                goto out; /* found in altroot */
-                       read_lock(&current->fs->lock);
+                       read_lock(&fs->lock);
                }
-               nd->mnt = mntget(current->fs->rootmnt);
-               nd->dentry = dget(current->fs->root);
-               read_unlock(&current->fs->lock);
+               nd->mnt = mntget(fs->rootmnt);
+               nd->dentry = dget(fs->root);
+               read_unlock(&fs->lock);
        } else if (dfd == AT_FDCWD) {
-               read_lock(&current->fs->lock);
-               nd->mnt = mntget(current->fs->pwdmnt);
-               nd->dentry = dget(current->fs->pwd);
-               read_unlock(&current->fs->lock);
+               read_lock(&fs->lock);
+               nd->mnt = mntget(fs->pwdmnt);
+               nd->dentry = dget(fs->pwd);
+               read_unlock(&fs->lock);
        } else {
                struct dentry *dentry;
 
@@ -1190,7 +1191,7 @@ static int fastcall do_path_lookup(int dfd, const char *name,
                if (!file)
                        goto out_fail;
 
-               dentry = file->f_dentry;
+               dentry = file->f_path.dentry;
 
                retval = -ENOTDIR;
                if (!S_ISDIR(dentry->d_inode->i_mode))
@@ -1200,7 +1201,7 @@ static int fastcall do_path_lookup(int dfd, const char *name,
                if (retval)
                        goto fput_fail;
 
-               nd->mnt = mntget(file->f_vfsmnt);
+               nd->mnt = mntget(file->f_path.mnt);
                nd->dentry = dget(dentry);
 
                fput_light(file, fput_needed);
@@ -1496,8 +1497,6 @@ static inline int lookup_flags(unsigned int f)
        
        if (f & O_DIRECTORY)
                retval |= LOOKUP_DIRECTORY;
-       if (f & O_ATOMICLOOKUP)
-               retval |= LOOKUP_ATOMIC;
 
        return retval;
 }
@@ -1583,6 +1582,14 @@ int may_open(struct nameidata *nd, int acc_mode, int flag)
        if (S_ISDIR(inode->i_mode) && (flag & FMODE_WRITE))
                return -EISDIR;
 
+#ifdef CONFIG_VSERVER_COWBL
+       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
+               if (IS_COW_LINK(inode))
+                       return -EMLINK;
+               inode->i_flags &= ~(S_IUNLINK|S_IMMUTABLE);
+               mark_inode_dirty(inode);
+       }
+#endif
        error = vfs_permission(nd, acc_mode);
        if (error)
                return error;
@@ -1648,6 +1655,24 @@ int may_open(struct nameidata *nd, int acc_mode, int flag)
        return 0;
 }
 
+static int open_namei_create(struct nameidata *nd, struct path *path,
+                               int flag, int mode)
+{
+       int error;
+       struct dentry *dir = nd->dentry;
+
+       if (!IS_POSIXACL(dir->d_inode))
+               mode &= ~current->fs->umask;
+       error = vfs_create(dir->d_inode, path->dentry, mode, nd);
+       mutex_unlock(&dir->d_inode->i_mutex);
+       dput(nd->dentry);
+       nd->dentry = path->dentry;
+       if (error)
+               return error;
+       /* Don't check for write permission, don't truncate */
+       return may_open(nd, 0, flag & ~O_TRUNC);
+}
+
 /*
  *     open_namei()
  *
@@ -1670,6 +1695,11 @@ int open_namei(int dfd, const char *pathname, int flag,
        struct dentry *dir;
        int count = 0;
 
+#ifdef CONFIG_VSERVER_COWBL
+       int rflag = flag;
+       int rmode = mode;
+restart:
+#endif
        acc_mode = ACC_MODE(flag);
 
        /* O_TRUNC implies we need access checks for write permissions */
@@ -1729,18 +1759,10 @@ do_last:
 
        /* Negative dentry, just create the file */
        if (!path.dentry->d_inode) {
-               if (!IS_POSIXACL(dir->d_inode))
-                       mode &= ~current->fs->umask;
-               error = vfs_create(dir->d_inode, path.dentry, mode, nd);
-               mutex_unlock(&dir->d_inode->i_mutex);
-               dput(nd->dentry);
-               nd->dentry = path.dentry;
+               error = open_namei_create(nd, &path, flag, mode);
                if (error)
                        goto exit;
-               /* Don't check for write permission, don't truncate */
-               acc_mode = 0;
-               flag &= ~O_TRUNC;
-               goto ok;
+               return 0;
        }
 
        /*
@@ -1771,6 +1793,22 @@ do_last:
                goto exit;
 ok:
        error = may_open(nd, acc_mode, flag);
+#ifdef CONFIG_VSERVER_COWBL
+       if (error == -EMLINK) {
+               struct dentry *dentry;
+               dentry = cow_break_link(pathname);
+               if (IS_ERR(dentry)) {
+                       error = PTR_ERR(dentry);
+                       goto exit;
+               }
+               dput(dentry);
+               release_open_intent(nd);
+               path_release(nd);
+               flag = rflag;
+               mode = rmode;
+               goto restart;
+       }
+#endif
        if (error)
                goto exit;
        return 0;
@@ -1990,31 +2028,32 @@ asmlinkage long sys_mkdirat(int dfd, const char __user *pathname, int mode)
 {
        int error = 0;
        char * tmp;
+       struct dentry *dentry;
+       struct nameidata nd;
 
        tmp = getname(pathname);
        error = PTR_ERR(tmp);
-       if (!IS_ERR(tmp)) {
-               struct dentry *dentry;
-               struct nameidata nd;
+       if (IS_ERR(tmp))
+               goto out_err;
 
-               error = do_path_lookup(dfd, tmp, LOOKUP_PARENT, &nd);
-               if (error)
-                       goto out;
-               dentry = lookup_create(&nd, 1);
-               error = PTR_ERR(dentry);
-               if (!IS_ERR(dentry)) {
-                       if (!IS_POSIXACL(nd.dentry->d_inode))
-                               mode &= ~current->fs->umask;
-                       error = vfs_mkdir(nd.dentry->d_inode, dentry,
-                               mode, &nd);
-                       dput(dentry);
-               }
-               mutex_unlock(&nd.dentry->d_inode->i_mutex);
-               path_release(&nd);
-out:
-               putname(tmp);
-       }
+       error = do_path_lookup(dfd, tmp, LOOKUP_PARENT, &nd);
+       if (error)
+               goto out;
+       dentry = lookup_create(&nd, 1);
+       error = PTR_ERR(dentry);
+       if (IS_ERR(dentry))
+               goto out_unlock;
 
+       if (!IS_POSIXACL(nd.dentry->d_inode))
+               mode &= ~current->fs->umask;
+       error = vfs_mkdir(nd.dentry->d_inode, dentry, mode, &nd);
+       dput(dentry);
+out_unlock:
+       mutex_unlock(&nd.dentry->d_inode->i_mutex);
+       path_release(&nd);
+out:
+       putname(tmp);
+out_err:
        return error;
 }
 
@@ -2041,8 +2080,7 @@ asmlinkage long sys_mkdir(const char __user *pathname, int mode)
 void dentry_unhash(struct dentry *dentry)
 {
        dget(dentry);
-       if (atomic_read(&dentry->d_count))
-               shrink_dcache_parent(dentry);
+       shrink_dcache_parent(dentry);
        spin_lock(&dcache_lock);
        spin_lock(&dentry->d_lock);
        if (atomic_read(&dentry->d_count) == 2)
@@ -2114,10 +2152,11 @@ static long do_rmdir(int dfd, const char __user *pathname)
        mutex_lock_nested(&nd.dentry->d_inode->i_mutex, I_MUTEX_PARENT);
        dentry = lookup_hash(&nd);
        error = PTR_ERR(dentry);
-       if (!IS_ERR(dentry)) {
-               error = vfs_rmdir(nd.dentry->d_inode, dentry, &nd);
-               dput(dentry);
-       }
+       if (IS_ERR(dentry))
+               goto exit2;
+       error = vfs_rmdir(nd.dentry->d_inode, dentry, &nd);
+       dput(dentry);
+exit2:
        mutex_unlock(&nd.dentry->d_inode->i_mutex);
 exit1:
        path_release(&nd);
@@ -2259,31 +2298,33 @@ asmlinkage long sys_symlinkat(const char __user *oldname,
        int error = 0;
        char * from;
        char * to;
+       struct dentry *dentry;
+       struct nameidata nd;
 
        from = getname(oldname);
        if(IS_ERR(from))
                return PTR_ERR(from);
        to = getname(newname);
        error = PTR_ERR(to);
-       if (!IS_ERR(to)) {
-               struct dentry *dentry;
-               struct nameidata nd;
+       if (IS_ERR(to))
+               goto out_putname;
 
-               error = do_path_lookup(newdfd, to, LOOKUP_PARENT, &nd);
-               if (error)
-                       goto out;
-               dentry = lookup_create(&nd, 0);
-               error = PTR_ERR(dentry);
-               if (!IS_ERR(dentry)) {
-                       error = vfs_symlink(nd.dentry->d_inode, dentry,
-                               from, S_IALLUGO, &nd);
-                       dput(dentry);
-               }
-               mutex_unlock(&nd.dentry->d_inode->i_mutex);
-               path_release(&nd);
+       error = do_path_lookup(newdfd, to, LOOKUP_PARENT, &nd);
+       if (error)
+               goto out;
+       dentry = lookup_create(&nd, 0);
+       error = PTR_ERR(dentry);
+       if (IS_ERR(dentry))
+               goto out_unlock;
+
+       error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO, &nd);
+       dput(dentry);
+out_unlock:
+       mutex_unlock(&nd.dentry->d_inode->i_mutex);
+       path_release(&nd);
 out:
-               putname(to);
-       }
+       putname(to);
+out_putname:
        putname(from);
        return error;
 }
@@ -2370,11 +2411,11 @@ asmlinkage long sys_linkat(int olddfd, const char __user *oldname,
                goto out_release;
        new_dentry = lookup_create(&nd, 0);
        error = PTR_ERR(new_dentry);
-       if (!IS_ERR(new_dentry)) {
-               error = vfs_link(old_nd.dentry, nd.dentry->d_inode,
-                       new_dentry, &nd);
-               dput(new_dentry);
-       }
+       if (IS_ERR(new_dentry))
+               goto out_unlock;
+       error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry, &nd);
+       dput(new_dentry);
+out_unlock:
        mutex_unlock(&nd.dentry->d_inode->i_mutex);
 out_release:
        path_release(&nd);
@@ -2461,7 +2502,8 @@ static int vfs_rename_dir(struct inode *old_dir, struct dentry *old_dentry,
                dput(new_dentry);
        }
        if (!error)
-               d_move(old_dentry,new_dentry);
+               if (!(old_dir->i_sb->s_type->fs_flags & FS_RENAME_DOES_D_MOVE))
+                       d_move(old_dentry,new_dentry);
        return error;
 }
 
@@ -2484,8 +2526,7 @@ static int vfs_rename_other(struct inode *old_dir, struct dentry *old_dentry,
        else
                error = old_dir->i_op->rename(old_dir, old_dentry, new_dir, new_dentry);
        if (!error) {
-               /* The following d_move() should become unconditional */
-               if (!(old_dir->i_sb->s_type->fs_flags & FS_ODD_RENAME))
+               if (!(old_dir->i_sb->s_type->fs_flags & FS_RENAME_DOES_D_MOVE))
                        d_move(old_dentry, new_dentry);
        }
        if (target)
@@ -2685,6 +2726,129 @@ int vfs_follow_link(struct nameidata *nd, const char *link)
        return __vfs_follow_link(nd, link);
 }
 
+
+#ifdef CONFIG_VSERVER_COWBL
+
+#include <linux/file.h>
+
+struct dentry *cow_break_link(const char *pathname)
+{
+       int ret, mode, pathlen;
+       struct nameidata old_nd, dir_nd;
+       struct dentry *old_dentry, *new_dentry;
+       struct dentry *res = ERR_PTR(-EMLINK);
+       struct vfsmount *old_mnt, *new_mnt;
+       struct file *old_file;
+       struct file *new_file;
+       char *to, *path, pad='\251';
+       loff_t size;
+
+       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
+       path = kmalloc(PATH_MAX, GFP_KERNEL);
+
+       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
+       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
+       old_dentry = old_nd.dentry;
+       old_mnt = old_nd.mnt;
+       mode = old_dentry->d_inode->i_mode;
+
+       to = d_path(old_dentry, old_mnt, path, PATH_MAX-2);
+       pathlen = strlen(to);
+       vxdprintk(VXD_CBIT(misc, 2), "old path »%s«", to);
+
+       to[pathlen+1] = 0;
+retry:
+       to[pathlen] = pad--;
+       if (pad <= '\240')
+               goto out_rel_old;
+
+       vxdprintk(VXD_CBIT(misc, 1), "temp copy »%s«", to);
+       ret = path_lookup(to,
+               LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE, &dir_nd);
+
+       /* this puppy downs the inode sem */
+       new_dentry = lookup_create(&dir_nd, 0);
+       vxdprintk(VXD_CBIT(misc, 2),
+               "lookup_create(new): %p", new_dentry);
+       if (!new_dentry) {
+               path_release(&dir_nd);
+               goto retry;
+       }
+
+       ret = vfs_create(dir_nd.dentry->d_inode, new_dentry, mode, &dir_nd);
+       vxdprintk(VXD_CBIT(misc, 2),
+               "vfs_create(new): %d", ret);
+       if (ret == -EEXIST) {
+               mutex_unlock(&dir_nd.dentry->d_inode->i_mutex);
+               dput(new_dentry);
+               path_release(&dir_nd);
+               goto retry;
+       }
+       else if (ret < 0) {
+               res = ERR_PTR(ret);
+               goto out_rel_both;
+       }
+
+       new_mnt = dir_nd.mnt;
+
+       dget(old_dentry);
+       mntget(old_mnt);
+       /* this one cleans up the dentry in case of failure */
+       old_file = dentry_open(old_dentry, old_mnt, O_RDONLY);
+       vxdprintk(VXD_CBIT(misc, 2),
+               "dentry_open(old): %p", old_file);
+       if (!old_file)
+               goto out_rel_both;
+
+       dget(new_dentry);
+       mntget(new_mnt);
+       /* this one cleans up the dentry in case of failure */
+       new_file = dentry_open(new_dentry, new_mnt, O_WRONLY);
+       vxdprintk(VXD_CBIT(misc, 2),
+               "dentry_open(new): %p", new_file);
+       if (!new_file)
+               goto out_fput_old;
+
+       size = i_size_read(old_file->f_dentry->d_inode);
+       ret = vfs_sendfile(new_file, old_file, NULL, size, 0);
+       vxdprintk(VXD_CBIT(misc, 2), "vfs_sendfile: %d", ret);
+
+       if (ret < 0)
+               goto out_fput_both;
+
+       ret = vfs_rename(dir_nd.dentry->d_inode, new_dentry,
+               old_nd.dentry->d_parent->d_inode, old_dentry);
+       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
+       if (!ret) {
+               res = new_dentry;
+               dget(new_dentry);
+       }
+
+out_fput_both:
+       vxdprintk(VXD_CBIT(misc, 3),
+               "fput(new_file=%p[#%d])", new_file,
+               atomic_read(&new_file->f_count));
+       fput(new_file);
+
+out_fput_old:
+       vxdprintk(VXD_CBIT(misc, 3),
+               "fput(old_file=%p[#%d])", old_file,
+               atomic_read(&old_file->f_count));
+       fput(old_file);
+
+out_rel_both:
+       mutex_unlock(&dir_nd.dentry->d_inode->i_mutex);
+       dput(new_dentry);
+
+       path_release(&dir_nd);
+out_rel_old:
+       path_release(&old_nd);
+       kfree(path);
+       return res;
+}
+
+#endif
+
 /* get the link contents into pagecache */
 static char *page_getlink(struct dentry * dentry, struct page **ppage)
 {