Whamcloud - gitweb
LU-744 clio: save memory allocations for cl_page
[fs/lustre-release.git] / lustre / lov / lov_object.c
index 65e4466..4b1d3af 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, Whamcloud, Inc.
+ * Copyright (c) 2011, 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -67,10 +67,8 @@ struct lov_layout_operations {
                             union lov_layout_state *state);
         int  (*llo_print)(const struct lu_env *env, void *cookie,
                           lu_printer_t p, const struct lu_object *o);
-        struct cl_page *(*llo_page_init)(const struct lu_env *env,
-                                         struct cl_object *obj,
-                                         struct cl_page *page,
-                                         cfs_page_t *vmpage);
+        int  (*llo_page_init)(const struct lu_env *env, struct cl_object *obj,
+                               struct cl_page *page, cfs_page_t *vmpage);
         int  (*llo_lock_init)(const struct lu_env *env,
                               struct cl_object *obj, struct cl_lock *lock,
                               const struct cl_io *io);
@@ -133,6 +131,12 @@ static int lov_init_sub(const struct lu_env *env, struct lov_object *lov,
         int result;
 
        if (OBD_FAIL_CHECK(OBD_FAIL_LOV_INIT)) {
+               /* For sanity:test_206.
+                * Do not leave the object in cache to avoid accessing
+                * freed memory. This is because osc_object is referring to
+                * lov_oinfo of lsm_stripe_data which will be freed due to
+                * this failure. */
+               cl_object_kill(env, stripe);
                cl_object_put(env, stripe);
                return -EIO;
        }
@@ -541,8 +545,13 @@ static int lov_layout_wait(const struct lu_env *env, struct lov_object *lov)
                RETURN(0);
 
        LASSERT(cfs_atomic_read(&lsm->lsm_refc) > 0);
-       while (cfs_atomic_read(&lsm->lsm_refc) > 1) {
+       while (cfs_atomic_read(&lsm->lsm_refc) > 1 && lov->lo_lsm_invalid) {
                lov_conf_unlock(lov);
+
+               CDEBUG(D_INODE, "file:"DFID" wait for active IO, now: %d.\n",
+                       PFID(lu_object_fid(lov2lu(lov))),
+                       cfs_atomic_read(&lsm->lsm_refc));
+
                l_wait_event(lov->lo_waitq,
                             cfs_atomic_read(&lsm->lsm_refc) == 1, &lwi);
                lov_conf_lock(lov);
@@ -624,6 +633,8 @@ int lov_object_init(const struct lu_env *env, struct lu_object *obj,
        init_rwsem(&lov->lo_type_guard);
        cfs_waitq_init(&lov->lo_waitq);
 
+       cl_object_page_init(lu2cl(obj), sizeof(struct lov_page));
+
         /* no locking is necessary, as object is being created */
         lov->lo_type = cconf->u.coc_md->lsm != NULL ? LLT_RAID0 : LLT_EMPTY;
         ops = &lov_dispatch[lov->lo_type];
@@ -642,23 +653,34 @@ static int lov_conf_set(const struct lu_env *env, struct cl_object *obj,
        ENTRY;
 
        lov_conf_lock(lov);
-       if (conf->coc_invalidate) {
+       if (conf->coc_opc == OBJECT_CONF_INVALIDATE) {
                lov->lo_lsm_invalid = 1;
                GOTO(out, result = 0);
        }
 
+       if (conf->coc_opc == OBJECT_CONF_WAIT) {
+               result = lov_layout_wait(env, lov);
+               GOTO(out, result);
+       }
+
+       LASSERT(conf->coc_opc == OBJECT_CONF_SET);
+
        if (conf->u.coc_md != NULL)
                lsm = conf->u.coc_md->lsm;
-
        if ((lsm == NULL && lov->lo_lsm == NULL) ||
            (lsm != NULL && lov->lo_lsm != NULL &&
             lov->lo_lsm->lsm_layout_gen == lsm->lsm_layout_gen)) {
+               /* same version of layout */
                lov->lo_lsm_invalid = 0;
                GOTO(out, result = 0);
        }
 
-       /* will change layout */
-       lov_layout_wait(env, lov);
+       /* will change layout - check if there still exists active IO. */
+       if (lov->lo_lsm != NULL &&
+           cfs_atomic_read(&lov->lo_lsm->lsm_refc) > 1) {
+               lov->lo_lsm_invalid = 1;
+               GOTO(out, result = -EBUSY);
+       }
 
        /*
         * Only LLT_EMPTY <-> LLT_RAID0 transitions are supported.
@@ -711,8 +733,8 @@ static int lov_object_print(const struct lu_env *env, void *cookie,
         return LOV_2DISPATCH(lu2lov(o), llo_print, env, cookie, p, o);
 }
 
-struct cl_page *lov_page_init(const struct lu_env *env, struct cl_object *obj,
-                              struct cl_page *page, cfs_page_t *vmpage)
+int lov_page_init(const struct lu_env *env, struct cl_object *obj,
+               struct cl_page *page, cfs_page_t *vmpage)
 {
         return LOV_2DISPATCH_NOLOCK(cl2lov(obj),
                                    llo_page_init, env, obj, page, vmpage);