Whamcloud - gitweb
add per-thread debugging flags. Use then to control CDEBUG().
[fs/lustre-release.git] / lustre / mdd / mdd_dir.c
index c100b35..aef052a 100644 (file)
@@ -437,6 +437,12 @@ out_trans:
         return rc;
 }
 
+static inline void mdd_set_dead_obj(struct mdd_object *obj)
+{
+        if (obj)
+                obj->mod_flags |= DEAD_OBJ;
+}
+
 /* caller should take a lock before calling */
 int mdd_finish_unlink(const struct lu_env *env,
                       struct mdd_object *obj, struct md_attr *ma,
@@ -452,6 +458,7 @@ int mdd_finish_unlink(const struct lu_env *env,
                 if (__mdd_orphan_add(env, obj, th) == 0)
                         obj->mod_flags |= ORPHAN_OBJ;
 
+                mdd_set_dead_obj(obj);
                 if (obj->mod_count == 0)
                         rc = mdd_object_kill(env, obj, ma);
                 else
@@ -548,8 +555,12 @@ static int mdd_unlink(const struct lu_env *env, struct md_object *pobj,
          * Check -ENOENT early here because we need to get object type
          * to calculate credits before transaction start
          */
-        if (!lu_object_exists(&cobj->mo_lu))
+        if (!lu_object_exists(&cobj->mo_lu)) {
+                LU_OBJECT_DEBUG(D_ERROR, env, &cobj->mo_lu,
+                                "unlinking as `%s'", name);
                 RETURN(-ENOENT);
+        }
+
         LASSERTF(lu_object_exists(&cobj->mo_lu) > 0, "FID is "DFID"\n",
                  PFID(lu_object_fid(&cobj->mo_lu)));
 
@@ -571,8 +582,12 @@ static int mdd_unlink(const struct lu_env *env, struct md_object *pobj,
                 GOTO(cleanup, rc);
 
         is_dir = S_ISDIR(lu_object_attr(&cobj->mo_lu));
+
+        current->debugging1 |= 0x1; /* XXX enable lvar_enoent_debug
+                                     * debugging */
         rc = __mdd_index_delete(env, mdd_pobj, name, is_dir, handle,
                                 mdd_object_capa(env, mdd_pobj));
+        current->debugging1 &= ~0x1;
         if (rc)
                 GOTO(cleanup, rc);
 
@@ -654,10 +669,11 @@ static int mdd_name_insert(const struct lu_env *env, struct md_object *pobj,
 
         rc = __mdd_index_insert(env, mdd_obj, fid, name, is_dir,
                                 handle, BYPASS_CAPA);
-
-        la->la_ctime = la->la_atime = CURRENT_SECONDS;
-        la->la_valid = LA_ATIME | LA_CTIME;
-        rc = mdd_attr_set_internal_locked(env, mdd_obj, la, handle, 0);
+        if (rc == 0) {
+                la->la_ctime = la->la_atime = CURRENT_SECONDS;
+                la->la_valid = LA_ATIME | LA_CTIME;
+                rc = mdd_attr_set_internal_locked(env, mdd_obj, la, handle, 0);
+        }
         EXIT;
 out_unlock:
         mdd_pdo_write_unlock(env, mdd_obj, dlh);
@@ -906,7 +922,7 @@ __mdd_lookup(const struct lu_env *env, struct md_object *pobj,
 
         mdd_lprocfs_time_start(mdo2mdd(pobj), &start, LPROC_MDD_LOOKUP);
         if (mdd_is_dead_obj(mdd_obj))
-                RETURN(-ENOENT);
+                RETURN(-ESTALE);
 
         rc = lu_object_exists(mdd2lu_obj(mdd_obj));
         if (rc == 0)
@@ -995,8 +1011,8 @@ static int mdd_create_sanity_check(const struct lu_env *env,
                 RETURN(-ENOENT);
 
         /*
-         * In some cases this lookup is not needed - we know before that if name
-         * exists or not.
+         * In some cases this lookup is not needed - we know before if name
+         * exists or not because MDT performs lookup for it.
          */
         /* XXX disable that lookup temporary */
         if (0 && lookup) {
@@ -1032,8 +1048,12 @@ static int mdd_create_sanity_check(const struct lu_env *env,
         }
 
         switch (ma->ma_attr.la_mode & S_IFMT) {
+        case S_IFDIR: {
+                struct mdd_device *mdd = mdo2mdd(pobj);
+                if (la->la_nlink >= mdd->mdd_dt_conf.ddp_max_nlink)
+                        RETURN(-EMLINK);
+        }
         case S_IFREG:
-        case S_IFDIR:
         case S_IFLNK:
         case S_IFCHR:
         case S_IFBLK: