Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / fs / xfs / xfs_rename.c
index cb13f9a..1f14876 100644 (file)
@@ -1,60 +1,45 @@
 /*
- * Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
+ * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
+ * All Rights Reserved.
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
  * published by the Free Software Foundation.
  *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc., 59
- * Temple Place - Suite 330, Boston MA 02111-1307, USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
-
 #include "xfs.h"
-#include "xfs_macros.h"
+#include "xfs_fs.h"
 #include "xfs_types.h"
-#include "xfs_inum.h"
 #include "xfs_log.h"
+#include "xfs_inum.h"
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_dir.h"
 #include "xfs_dir2.h"
 #include "xfs_dmapi.h"
 #include "xfs_mount.h"
+#include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dir_sf.h"
 #include "xfs_dir2_sf.h"
+#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
-#include "xfs_inode_item.h"
 #include "xfs_inode.h"
+#include "xfs_inode_item.h"
 #include "xfs_bmap.h"
 #include "xfs_error.h"
 #include "xfs_quota.h"
 #include "xfs_refcache.h"
 #include "xfs_utils.h"
 #include "xfs_trans_space.h"
-#include "xfs_da_btree.h"
 #include "xfs_dir_leaf.h"
 
 
@@ -234,9 +219,6 @@ xfs_lock_for_rename(
        return 0;
 }
 
-
-int rename_which_error_return = 0;
-
 /*
  * xfs_rename
  */
@@ -261,7 +243,6 @@ xfs_rename(
        xfs_inode_t     *inodes[4];
        int             target_ip_dropped = 0;  /* dropped target_ip link? */
        vnode_t         *src_dir_vp;
-       bhv_desc_t      *target_dir_bdp;
        int             spaceres;
        int             target_link_zero = 0;
        int             num_inodes;
@@ -278,14 +259,12 @@ xfs_rename(
         * Find the XFS behavior descriptor for the target directory
         * vnode since it was not handed to us.
         */
-       target_dir_bdp = vn_bhv_lookup_unlocked(VN_BHV_HEAD(target_dir_vp),
-                                               &xfs_vnodeops);
-       if (target_dir_bdp == NULL) {
+       target_dp = xfs_vtoi(target_dir_vp);
+       if (target_dp == NULL) {
                return XFS_ERROR(EXDEV);
        }
 
        src_dp = XFS_BHVTOI(src_dir_bdp);
-       target_dp = XFS_BHVTOI(target_dir_bdp);
        mp = src_dp->i_mount;
 
        if (DM_EVENT_ENABLED(src_dir_vp->v_vfsp, src_dp, DM_EVENT_RENAME) ||
@@ -316,7 +295,6 @@ xfs_rename(
                        &num_inodes);
 
        if (error) {
-               rename_which_error_return = __LINE__;
                /*
                 * We have nothing locked, no inode references, and
                 * no transaction, so just get out.
@@ -332,13 +310,24 @@ xfs_rename(
                 */
                if (target_ip == NULL && (src_dp != target_dp) &&
                    target_dp->i_d.di_nlink >= XFS_MAXLINK) {
-                       rename_which_error_return = __LINE__;
                        error = XFS_ERROR(EMLINK);
                        xfs_rename_unlock4(inodes, XFS_ILOCK_SHARED);
                        goto rele_return;
                }
        }
 
+       /*
+        * If we are using project inheritance, we only allow renames
+        * into our tree when the project IDs are the same; else the
+        * tree quota mechanism would be circumvented.
+        */
+       if (unlikely((target_dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
+                    (target_dp->i_d.di_projid != src_ip->i_d.di_projid))) {
+               error = XFS_ERROR(EXDEV);
+               xfs_rename_unlock4(inodes, XFS_ILOCK_SHARED);
+               goto rele_return;
+       }
+
        new_parent = (src_dp != target_dp);
        src_is_directory = ((src_ip->i_d.di_mode & S_IFMT) == S_IFDIR);
 
@@ -359,7 +348,6 @@ xfs_rename(
                                XFS_TRANS_PERM_LOG_RES, XFS_RENAME_LOG_COUNT);
        }
        if (error) {
-               rename_which_error_return = __LINE__;
                xfs_trans_cancel(tp, 0);
                goto rele_return;
        }
@@ -369,7 +357,6 @@ xfs_rename(
         */
        if ((error = XFS_QM_DQVOPRENAME(mp, inodes))) {
                xfs_trans_cancel(tp, cancel_flags);
-               rename_which_error_return = __LINE__;
                goto rele_return;
        }
 
@@ -413,7 +400,6 @@ xfs_rename(
                if (spaceres == 0 &&
                    (error = XFS_DIR_CANENTER(mp, tp, target_dp, target_name,
                                target_namelen))) {
-                       rename_which_error_return = __LINE__;
                        goto error_return;
                }
                /*
@@ -425,11 +411,9 @@ xfs_rename(
                                           target_namelen, src_ip->i_ino,
                                           &first_block, &free_list, spaceres);
                if (error == ENOSPC) {
-                       rename_which_error_return = __LINE__;
                        goto error_return;
                }
                if (error) {
-                       rename_which_error_return = __LINE__;
                        goto abort_return;
                }
                xfs_ichgtime(target_dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
@@ -437,7 +421,6 @@ xfs_rename(
                if (new_parent && src_is_directory) {
                        error = xfs_bumplink(tp, target_dp);
                        if (error) {
-                               rename_which_error_return = __LINE__;
                                goto abort_return;
                        }
                }
@@ -455,7 +438,6 @@ xfs_rename(
                        if (!(XFS_DIR_ISEMPTY(target_ip->i_mount, target_ip)) ||
                            (target_ip->i_d.di_nlink > 2)) {
                                error = XFS_ERROR(EEXIST);
-                               rename_which_error_return = __LINE__;
                                goto error_return;
                        }
                }
@@ -473,7 +455,6 @@ xfs_rename(
                        target_namelen, src_ip->i_ino, &first_block,
                        &free_list, spaceres);
                if (error) {
-                       rename_which_error_return = __LINE__;
                        goto abort_return;
                }
                xfs_ichgtime(target_dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
@@ -484,7 +465,6 @@ xfs_rename(
                 */
                error = xfs_droplink(tp, target_ip);
                if (error) {
-                       rename_which_error_return = __LINE__;
                        goto abort_return;
                }
                target_ip_dropped = 1;
@@ -495,7 +475,6 @@ xfs_rename(
                         */
                        error = xfs_droplink(tp, target_ip);
                        if (error) {
-                               rename_which_error_return = __LINE__;
                                goto abort_return;
                        }
                }
@@ -519,7 +498,6 @@ xfs_rename(
                                        &free_list, spaceres);
                ASSERT(error != EEXIST);
                if (error) {
-                       rename_which_error_return = __LINE__;
                        goto abort_return;
                }
                xfs_ichgtime(src_ip, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
@@ -550,7 +528,6 @@ xfs_rename(
                 */
                error = xfs_droplink(tp, src_dp);
                if (error) {
-                       rename_which_error_return = __LINE__;
                        goto abort_return;
                }
        }
@@ -558,7 +535,6 @@ xfs_rename(
        error = XFS_DIR_REMOVENAME(mp, tp, src_dp, src_name, src_namelen,
                        src_ip->i_ino, &first_block, &free_list, spaceres);
        if (error) {
-               rename_which_error_return = __LINE__;
                goto abort_return;
        }
        xfs_ichgtime(src_dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
@@ -638,8 +614,6 @@ xfs_rename(
                IRELE(target_ip);
        }
 
-       FSC_NOTIFY_NAME_CHANGED(XFS_ITOV(src_ip));
-
        IRELE(src_ip);
 
        /* Fall through to std_return with error = 0 or errno from