Whamcloud - gitweb
LU-4017 quota: add project inherit attributes
[fs/lustre-release.git] / lustre / mdd / mdd_dir.c
index 4c20548..07fe079 100644 (file)
@@ -49,8 +49,8 @@ static const char dot[] = ".";
 static const char dotdot[] = "..";
 
 static struct lu_name lname_dotdot = {
-        (char *) dotdot,
-        sizeof(dotdot) - 1
+       .ln_name        = (char *) dotdot,
+       .ln_namelen     = sizeof(dotdot) - 1,
 };
 
 static inline int
@@ -1241,12 +1241,6 @@ static int mdd_declare_link(const struct lu_env *env,
        if (rc != 0)
                return rc;
 
-       if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_MORE_NLINK)) {
-               rc = mdo_declare_ref_add(env, c, handle);
-               if (rc != 0)
-                       return rc;
-       }
-
        la->la_valid = LA_CTIME | LA_MTIME;
        rc = mdo_declare_attr_set(env, p, la, handle);
        if (rc != 0)
@@ -1291,6 +1285,15 @@ static int mdd_link(const struct lu_env *env, struct md_object *tgt_obj,
        if (rc != 0)
                RETURN(rc);
 
+       /*
+        * If we are using project inheritance, we only allow hard link
+        * creation in our tree when the project IDs are the same;
+        * otherwise the tree quota mechanism could be circumvented.
+        */
+       if ((tattr->la_flags & LUSTRE_PROJINHERIT_FL) &&
+           (tattr->la_projid != cattr->la_projid))
+               RETURN(-EXDEV);
+
         handle = mdd_trans_create(env, mdd);
         if (IS_ERR(handle))
                 GOTO(out_pending, rc = PTR_ERR(handle));
@@ -1329,12 +1332,6 @@ static int mdd_link(const struct lu_env *env, struct md_object *tgt_obj,
                        GOTO(out_unlock, rc);
        }
 
-       if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_MORE_NLINK)) {
-               rc = mdo_ref_add(env, mdd_sobj, handle);
-               if (rc != 0)
-                       GOTO(out_unlock, rc);
-       }
-
        *tfid = *mdo2fid(mdd_sobj);
        if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING3))
                tfid->f_oid = cfs_fail_val;
@@ -1954,6 +1951,16 @@ static int mdd_create_sanity_check(const struct lu_env *env,
                }
        }
 
+       /* Inherit project ID from parent directory */
+       if (pattr->la_flags & LUSTRE_PROJINHERIT_FL) {
+               cattr->la_projid = pattr->la_projid;
+               if (S_ISDIR(cattr->la_mode)) {
+                       cattr->la_flags |= LUSTRE_PROJINHERIT_FL;
+                       cattr->la_valid |= LA_FLAGS;
+               }
+               cattr->la_valid |= LA_PROJID;
+       }
+
        rc = mdd_name_check(m, lname);
        if (rc < 0)
                RETURN(rc);
@@ -2593,6 +2600,17 @@ static int mdd_rename_sanity_check(const struct lu_env *env,
         * before mdd_rename and enable MDS_PERM_BYPASS. */
        LASSERT(sobj);
 
+       /*
+        * If we are using project inheritance, we only allow renames
+        * into our tree when the project IDs are the same; otherwise
+        * tree quota mechanism would be circumvented.
+        */
+       if (((tpattr->la_flags & LUSTRE_PROJINHERIT_FL) &&
+           tpattr->la_projid != cattr->la_projid) ||
+           ((pattr->la_flags & LUSTRE_PROJINHERIT_FL) &&
+           (pattr->la_projid != tpattr->la_projid)))
+               RETURN(-EXDEV);
+
        rc = mdd_may_delete(env, src_pobj, pattr, sobj, cattr, NULL, 1, 0);
        if (rc)
                RETURN(rc);