Whamcloud - gitweb
LU-3474 mdd: mdd_links_read() to return linkea_init() errors
[fs/lustre-release.git] / lustre / mdd / mdd_dir.c
index c28c068..6ac8aed 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Intel Corporation.
+ * Copyright (c) 2011, 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -554,60 +554,6 @@ static int __mdd_index_delete(const struct lu_env *env, struct mdd_object *pobj,
         RETURN(rc);
 }
 
-int mdd_declare_llog_record(const struct lu_env *env, struct mdd_device *mdd,
-                            int reclen, struct thandle *handle)
-{
-        int rc;
-
-        /* XXX: this is a temporary solution to declare llog changes
-         *      will be fixed in 2.3 with new llog implementation */
-
-        LASSERT(mdd->mdd_capa);
-
-        /* XXX: Since we use the 'mdd_capa' as fake llog object here, we
-         *      have to set the parameter 'size' as INT_MAX or 0 to inform
-         *      OSD that this record write is for a llog write or catalog
-         *      header update, and osd declare function will reserve less
-         *      credits for optimization purpose.
-         *
-         *      Reserve 6 blocks for a llog write, since the llog file is
-         *      usually small, reserve 2 blocks for catalog header update,
-         *      because we know for sure that catalog header is already
-         *      allocated.
-         *
-         *      This hack should be removed in 2.3.
-         */
-
-        /* record itself */
-        rc = dt_declare_record_write(env, mdd->mdd_capa,
-                                     DECLARE_LLOG_WRITE, 0, handle);
-        if (rc)
-                return rc;
-
-        /* header will be updated as well */
-        rc = dt_declare_record_write(env, mdd->mdd_capa,
-                                     DECLARE_LLOG_WRITE, 0, handle);
-        if (rc)
-                return rc;
-
-        /* also we should be able to create new plain log */
-        rc = dt_declare_create(env, mdd->mdd_capa, NULL, NULL, NULL, handle);
-        if (rc)
-                return rc;
-
-        /* new record referencing new plain llog */
-        rc = dt_declare_record_write(env, mdd->mdd_capa,
-                                     DECLARE_LLOG_WRITE, 0, handle);
-        if (rc)
-                return rc;
-
-        /* catalog's header will be updated as well */
-        rc = dt_declare_record_write(env, mdd->mdd_capa,
-                                     DECLARE_LLOG_REWRITE, 0, handle);
-
-        return rc;
-}
-
 int mdd_declare_changelog_store(const struct lu_env *env,
                                struct mdd_device *mdd,
                                const struct lu_name *fname,
@@ -930,6 +876,9 @@ static int __mdd_links_add(const struct lu_env *env,
                linkea_add_buf(ldata, lname, tfid);
        }
 
+       if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_MORE2))
+               linkea_add_buf(ldata, lname, pfid);
+
        return linkea_add_buf(ldata, lname, pfid);
 }
 
@@ -973,14 +922,17 @@ static int mdd_linkea_prepare(const struct lu_env *env,
 
        LASSERT(oldpfid != NULL || newpfid != NULL);
 
-       if (mdd_obj->mod_flags & DEAD_OBJ)
+       if (mdd_obj->mod_flags & DEAD_OBJ) {
+               /* Prevent linkea to be updated which is NOT necessary. */
+               ldata->ld_reclen = 0;
                /* No more links, don't bother */
                RETURN(0);
+       }
 
        if (oldpfid != NULL) {
                rc = __mdd_links_del(env, mdd_obj, ldata, oldlname, oldpfid);
                if (rc) {
-                       if ((check == 0) ||
+                       if ((check == 1) ||
                            (rc != -ENODATA && rc != -ENOENT))
                                RETURN(rc);
                        /* No changes done. */
@@ -994,8 +946,6 @@ static int mdd_linkea_prepare(const struct lu_env *env,
                 * old link */
                rc2 = __mdd_links_add(env, mdd_obj, ldata, newlname, newpfid,
                                      first, check);
-               if (rc2 == -EEXIST)
-                       rc2 = 0;
        }
 
        rc = rc != 0 ? rc : rc2;
@@ -1027,7 +977,7 @@ int mdd_links_rename(const struct lu_env *env,
                        GOTO(out, rc);
        }
 
-       if (ldata->ld_lee != NULL)
+       if (ldata->ld_reclen != 0)
                rc = mdd_links_write(env, mdd_obj, ldata, handle);
        EXIT;
 out:
@@ -1035,7 +985,7 @@ out:
                rc = rc2;
        if (rc) {
                int error = 1;
-               if (rc == -EOVERFLOW || rc == -ENOENT)
+               if (rc == -EOVERFLOW || rc == -ENOSPC)
                        error = 0;
                if (oldpfid == NULL)
                        CDEBUG(error ? D_ERROR : D_OTHER,
@@ -1098,7 +1048,7 @@ int mdd_links_read(const struct lu_env *env, struct mdd_object *mdd_obj,
        /* First try a small buf */
        LASSERT(env != NULL);
        ldata->ld_buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_link_buf,
-                                              CFS_PAGE_SIZE);
+                                              PAGE_CACHE_SIZE);
        if (ldata->ld_buf->lb_buf == NULL)
                return -ENOMEM;
 
@@ -1123,8 +1073,7 @@ int mdd_links_read(const struct lu_env *env, struct mdd_object *mdd_obj,
        if (rc < 0)
                return rc;
 
-       linkea_init(ldata);
-       return 0;
+       return linkea_init(ldata);
 }
 
 /** Read the link EA into a temp buffer.
@@ -1162,7 +1111,7 @@ int mdd_declare_links_add(const struct lu_env *env, struct mdd_object *mdd_obj,
                ea_len = ldata->ld_leh->leh_len;
                linkea = ldata->ld_buf->lb_buf;
        } else {
-               ea_len = 4096;
+               ea_len = DEFAULT_LINKEA_SIZE;
                linkea = NULL;
        }
 
@@ -1193,6 +1142,7 @@ static int mdd_declare_link(const struct lu_env *env,
                             struct mdd_object *c,
                             const struct lu_name *name,
                            struct thandle *handle,
+                           struct lu_attr *la,
                            struct linkea_data *data)
 {
         int rc;
@@ -1205,11 +1155,13 @@ static int mdd_declare_link(const struct lu_env *env,
         if (rc)
                 return rc;
 
-        rc = mdo_declare_attr_set(env, p, NULL, handle);
-        if (rc)
-                return rc;
+       la->la_valid = LA_CTIME | LA_MTIME;
+       rc = mdo_declare_attr_set(env, p, la, handle);
+       if (rc != 0)
+               return rc;
 
-        rc = mdo_declare_attr_set(env, c, NULL, handle);
+       la->la_valid = LA_CTIME;
+       rc = mdo_declare_attr_set(env, c, la, handle);
         if (rc)
                 return rc;
 
@@ -1243,8 +1195,11 @@ static int mdd_link(const struct lu_env *env, struct md_object *tgt_obj,
 
        memset(ldata, 0, sizeof(*ldata));
 
+       LASSERT(ma->ma_attr.la_valid & LA_CTIME);
+       la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
+
        rc = mdd_declare_link(env, mdd, mdd_tobj, mdd_sobj, lname, handle,
-                             ldata);
+                             la, ldata);
         if (rc)
                 GOTO(stop, rc);
 
@@ -1274,9 +1229,6 @@ static int mdd_link(const struct lu_env *env, struct md_object *tgt_obj,
                GOTO(out_unlock, rc);
        }
 
-        LASSERT(ma->ma_attr.la_valid & LA_CTIME);
-        la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
-
         la->la_valid = LA_CTIME | LA_MTIME;
        rc = mdd_attr_check_set_internal(env, mdd_tobj, la, handle, 0);
         if (rc)
@@ -1338,8 +1290,9 @@ int mdd_finish_unlink(const struct lu_env *env,
 
         LASSERT(mdd_write_locked(env, obj) != 0);
 
-       if (rc == 0 && (ma->ma_attr.la_nlink == 0 || is_dir)) {
+       if (ma->ma_attr.la_nlink == 0 || is_dir) {
                 obj->mod_flags |= DEAD_OBJ;
+
                 /* add new orphan and the object
                  * will be deleted during mdd_close() */
                 if (obj->mod_count) {
@@ -1412,7 +1365,8 @@ static int mdd_declare_unlink(const struct lu_env *env, struct mdd_device *mdd,
                if (rc)
                        return rc;
 
-               rc = mdo_declare_attr_set(env, c, NULL, handle);
+               la->la_valid = LA_CTIME;
+               rc = mdo_declare_attr_set(env, c, la, handle);
                if (rc)
                        return rc;
 
@@ -1621,11 +1575,6 @@ static int mdd_create_data(const struct lu_env *env, struct md_object *pobj,
         int                rc;
         ENTRY;
 
-       /* do not let users to create stripes via .lustre/
-        * mdd_obf_setup() sets IMMUTE_OBJ on this directory */
-       if (pobj && mdd_pobj->mod_flags & IMMUTE_OBJ)
-               RETURN(-ENOENT);
-
         rc = mdd_cd_sanity_check(env, son);
         if (rc)
                 RETURN(rc);
@@ -1671,12 +1620,22 @@ static int mdd_create_data(const struct lu_env *env, struct md_object *pobj,
        if (rc)
                GOTO(stop, rc);
 
+       rc = mdd_declare_changelog_store(env, mdd, NULL, handle);
+       if (rc)
+               GOTO(stop, rc);
+
        rc = mdd_trans_start(env, mdd, handle);
        if (rc)
                GOTO(stop, rc);
 
        rc = dt_xattr_set(env, mdd_object_child(son), buf, XATTR_NAME_LOV,
                          0, handle, mdd_object_capa(env, son));
+
+       if (rc)
+               GOTO(stop, rc);
+
+       rc = mdd_changelog_data_store(env, mdd, CL_LAYOUT, 0, son, handle);
+
 stop:
        mdd_trans_stop(env, mdd, rc, handle);
 out_free:
@@ -1761,9 +1720,7 @@ static int mdd_declare_object_initialize(const struct lu_env *env,
                                              dotdot, handle);
         }
 
-       if (rc == 0 && (fid_is_norm(mdo2fid(child)) ||
-                       fid_is_dot_lustre(mdo2fid(child)) ||
-                       fid_is_root(mdo2fid(child))))
+       if (rc == 0)
                mdd_declare_links_add(env, child, handle, ldata);
 
        RETURN(rc);
@@ -1803,9 +1760,7 @@ static int mdd_object_initialize(const struct lu_env *env,
                         mdo_ref_del(env, child, handle);
         }
 
-       if (rc == 0 && (fid_is_norm(mdo2fid(child)) ||
-                       fid_is_dot_lustre(mdo2fid(child)) ||
-                       fid_is_root(mdo2fid(child))))
+       if (rc == 0)
                mdd_links_add(env, child, pfid, lname, handle, ldata, 1);
 
        RETURN(rc);
@@ -2390,6 +2345,9 @@ static int mdd_declare_rename(const struct lu_env *env,
        struct lu_attr    *la = &mdd_env_info(env)->mti_la_for_fix;
        int rc;
 
+       LASSERT(ma->ma_attr.la_valid & LA_CTIME);
+       la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
+
         LASSERT(mdd_spobj);
         LASSERT(mdd_tpobj);
         LASSERT(mdd_sobj);
@@ -2426,13 +2384,16 @@ static int mdd_declare_rename(const struct lu_env *env,
 
         }
 
-        rc = mdo_declare_attr_set(env, mdd_spobj, NULL, handle);
-        if (rc)
-                return rc;
-
-       LASSERT(ma->ma_attr.la_valid & LA_CTIME);
-       la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
        la->la_valid = LA_CTIME | LA_MTIME;
+       rc = mdo_declare_attr_set(env, mdd_spobj, la, handle);
+       if (rc != 0)
+               return rc;
+
+       rc = mdo_declare_attr_set(env, mdd_tpobj, la, handle);
+       if (rc != 0)
+               return rc;
+
+       la->la_valid = LA_CTIME;
        rc = mdo_declare_attr_set(env, mdd_sobj, la, handle);
        if (rc)
                return rc;
@@ -2441,10 +2402,6 @@ static int mdd_declare_rename(const struct lu_env *env,
        if (rc)
                return rc;
 
-        rc = mdo_declare_attr_set(env, mdd_tpobj, NULL, handle);
-        if (rc)
-                return rc;
-
         /* new name */
         rc = mdo_declare_index_insert(env, mdd_tpobj, mdo2fid(mdd_sobj),
                         tname->ln_name, handle);
@@ -2477,7 +2434,8 @@ static int mdd_declare_rename(const struct lu_env *env,
                                 return rc;
                 }
 
-                rc = mdo_declare_attr_set(env, mdd_tobj, NULL, handle);
+               la->la_valid = LA_CTIME;
+               rc = mdo_declare_attr_set(env, mdd_tobj, la, handle);
                 if (rc)
                         return rc;