Whamcloud - gitweb
LU-1302 llog: pass lu_env as parametr in llog functions
[fs/lustre-release.git] / lustre / lov / lov_object.c
index 7f92431..9b52f34 100644 (file)
@@ -107,7 +107,6 @@ static void lov_install_raid0(const struct lu_env *env,
                               struct lov_object *lov,
                               union  lov_layout_state *state)
 {
-        lov->u = *state;
 }
 
 static struct cl_object *lov_sub_find(const struct lu_env *env,
@@ -133,6 +132,11 @@ static int lov_init_sub(const struct lu_env *env, struct lov_object *lov,
         struct lov_oinfo        *oinfo;
         int result;
 
+       if (OBD_FAIL_CHECK(OBD_FAIL_LOV_INIT)) {
+               cl_object_put(env, stripe);
+               return -EIO;
+       }
+
         hdr    = cl_object_header(lov2cl(lov));
         subhdr = cl_object_header(stripe);
         parent = subhdr->coh_parent;
@@ -286,7 +290,7 @@ static int lov_delete_raid0(const struct lu_env *env, struct lov_object *lov,
        ENTRY;
 
        dump_lsm(D_INODE, lsm);
-       if (cfs_atomic_read(&lsm->lsm_refc) > 1)
+       if (lov->lo_lsm_invalid && cfs_atomic_read(&lsm->lsm_refc) > 1)
                RETURN(-EBUSY);
 
         if (r0->lo_sub != NULL) {
@@ -313,20 +317,16 @@ static void lov_fini_empty(const struct lu_env *env, struct lov_object *lov,
 static void lov_fini_raid0(const struct lu_env *env, struct lov_object *lov,
                            union lov_layout_state *state)
 {
-        struct lov_layout_raid0 *r0 = &state->raid0;
-
-        ENTRY;
+       struct lov_layout_raid0 *r0 = &state->raid0;
+       ENTRY;
 
-        if (r0->lo_sub != NULL) {
-                OBD_FREE_LARGE(r0->lo_sub, r0->lo_nr * sizeof r0->lo_sub[0]);
-                r0->lo_sub = NULL;
-        }
+       if (r0->lo_sub != NULL) {
+               OBD_FREE_LARGE(r0->lo_sub, r0->lo_nr * sizeof r0->lo_sub[0]);
+               r0->lo_sub = NULL;
+       }
 
-       LASSERTF(cfs_atomic_read(&lov->lo_lsm->lsm_refc) == 1,
-               "actual %d proc %p.\n",
-               cfs_atomic_read(&lov->lo_lsm->lsm_refc), cfs_current());
+       dump_lsm(D_INODE, lov->lo_lsm);
        lov_free_memmd(&lov->lo_lsm);
-       lov->lo_lsm = NULL;
 
        EXIT;
 }
@@ -523,7 +523,7 @@ static int lov_layout_change(const struct lu_env *env,
                              const struct cl_object_conf *conf)
 {
        int result;
-       union lov_layout_state *state = &lov_env_info(env)->lti_state;
+       union lov_layout_state *state = &lov->u;
        const struct lov_layout_operations *old_ops;
        const struct lov_layout_operations *new_ops;
 
@@ -555,12 +555,17 @@ static int lov_layout_change(const struct lu_env *env,
                LASSERT(hdr->coh_tree.rnode == NULL);
                LASSERT(hdr->coh_pages == 0);
 
+               lov->lo_type = LLT_EMPTY;
                result = new_ops->llo_init(env,
                                        lu2lov_dev(lov->lo_cl.co_lu.lo_dev),
                                        lov, conf, state);
                if (result == 0) {
                        new_ops->llo_install(env, lov, state);
                        lov->lo_type = llt;
+               } else {
+                       new_ops->llo_delete(env, lov, state);
+                       new_ops->llo_fini(env, lov, state);
+                       /* this file becomes an EMPTY file. */
                }
        }
        RETURN(result);
@@ -578,7 +583,7 @@ int lov_object_init(const struct lu_env *env, struct lu_object *obj,
         struct lov_device            *dev   = lu2lov_dev(obj->lo_dev);
         struct lov_object            *lov   = lu2lov(obj);
         const struct cl_object_conf  *cconf = lu2cl_conf(conf);
-        union  lov_layout_state      *set   = &lov_env_info(env)->lti_state;
+        union  lov_layout_state      *set   = &lov->u;
         const struct lov_layout_operations *ops;
         int result;
 
@@ -592,8 +597,6 @@ int lov_object_init(const struct lu_env *env, struct lu_object *obj,
         result = ops->llo_init(env, dev, lov, cconf, set);
         if (result == 0)
                 ops->llo_install(env, lov, set);
-        else
-                ops->llo_fini(env, lov, set);
         RETURN(result);
 }
 
@@ -687,29 +690,17 @@ struct cl_page *lov_page_init(const struct lu_env *env, struct cl_object *obj,
  * layer. Dispatches to the appropriate layout io initialization method.
  */
 int lov_io_init(const struct lu_env *env, struct cl_object *obj,
-                struct cl_io *io)
+               struct cl_io *io)
 {
        struct lov_io *lio = lov_env_io(env);
 
-        CL_IO_SLICE_CLEAN(lov_env_io(env), lis_cl);
+       CL_IO_SLICE_CLEAN(lov_env_io(env), lis_cl);
 
        /* hold lsm before initializing because io relies on it */
        lio->lis_lsm = lov_lsm_addref(cl2lov(obj));
 
-        /*
-         * Do not take lock in case of CIT_MISC io, because
-         *
-         *     - if this is an io for a glimpse, then we don't care;
-         *
-         *     - if this not a glimpse (writepage or lock cancellation), then
-         *       layout change cannot happen because a page or a lock
-         *       already exist; and
-         *
-         *     - lock ordering (lock mutex nests within layout rw-semaphore)
-         *       is obeyed in case of lock cancellation.
-         */
-        return LOV_2DISPATCH_MAYLOCK(cl2lov(obj), llo_io_init,
-                                     io->ci_type != CIT_MISC, env, obj, io);
+       /* No need to lock because we've taken one refcount of layout.  */
+       return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_io_init, env, obj, io);
 }
 
 /**
@@ -735,9 +726,11 @@ static int lov_attr_set(const struct lu_env *env, struct cl_object *obj,
 }
 
 int lov_lock_init(const struct lu_env *env, struct cl_object *obj,
-                  struct cl_lock *lock, const struct cl_io *io)
+                 struct cl_lock *lock, const struct cl_io *io)
 {
-        return LOV_2DISPATCH(cl2lov(obj), llo_lock_init, env, obj, lock, io);
+       /* No need to lock because we've taken one refcount of layout.  */
+       return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_lock_init, env, obj, lock,
+                                   io);
 }
 
 static const struct cl_object_operations lov_ops = {