Whamcloud - gitweb
LU-3157 llite: A not locked mutex can be unlocked.
[fs/lustre-release.git] / lustre / lov / lov_object.c
index 060e629..07ed284 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, 2012, Intel Corporation.
+ * Copyright (c) 2011, 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -78,6 +78,8 @@ struct lov_layout_operations {
                             struct cl_attr *attr);
 };
 
+static int lov_layout_wait(const struct lu_env *env, struct lov_object *lov);
+
 /*****************************************************************************
  *
  * Lov object layout operations.
@@ -146,12 +148,11 @@ static int lov_init_sub(const struct lu_env *env, struct lov_object *lov,
         parent = subhdr->coh_parent;
 
        oinfo = lov->lo_lsm->lsm_oinfo[idx];
-        CDEBUG(D_INODE, DFID"@%p[%d] -> "DFID"@%p: id: "LPU64" seq: "LPU64
-               " idx: %d gen: %d\n",
-               PFID(&subhdr->coh_lu.loh_fid), subhdr, idx,
-               PFID(&hdr->coh_lu.loh_fid), hdr,
-               oinfo->loi_id, oinfo->loi_seq,
-               oinfo->loi_ost_idx, oinfo->loi_ost_gen);
+       CDEBUG(D_INODE, DFID"@%p[%d] -> "DFID"@%p: ostid: "DOSTID
+              " idx: %d gen: %d\n",
+              PFID(&subhdr->coh_lu.loh_fid), subhdr, idx,
+              PFID(&hdr->coh_lu.loh_fid), hdr, POSTID(&oinfo->loi_oi),
+              oinfo->loi_ost_idx, oinfo->loi_ost_gen);
 
         if (parent == NULL) {
                 subhdr->coh_parent = hdr;
@@ -229,8 +230,11 @@ static int lov_init_raid0(const struct lu_env *env,
                         struct lov_oinfo *oinfo = lsm->lsm_oinfo[i];
                         int ost_idx = oinfo->loi_ost_idx;
 
-                        fid_ostid_unpack(ofid, &oinfo->loi_oi,
-                                         oinfo->loi_ost_idx);
+                        result = ostid_to_fid(ofid, &oinfo->loi_oi,
+                                             oinfo->loi_ost_idx);
+                       if (result != 0)
+                               GOTO(out, result);
+
                         subdev = lovsub2cl_dev(dev->ld_target[ost_idx]);
                         subconf->u.coc_oinfo = oinfo;
                         LASSERTF(subdev != NULL, "not init ost %d\n", ost_idx);
@@ -250,6 +254,7 @@ static int lov_init_raid0(const struct lu_env *env,
                 }
         } else
                 result = -ENOMEM;
+out:
         RETURN(result);
 }
 
@@ -257,8 +262,8 @@ static int lov_delete_empty(const struct lu_env *env, struct lov_object *lov,
                            union lov_layout_state *state)
 {
        LASSERT(lov->lo_type == LLT_EMPTY);
-       if (cfs_atomic_read(&lov->lo_active_ios) > 0)
-               RETURN(-EBUSY);
+
+       lov_layout_wait(env, lov);
 
        cl_object_prune(env, &lov->lo_cl);
        return 0;
@@ -321,9 +326,8 @@ static int lov_delete_raid0(const struct lu_env *env, struct lov_object *lov,
        ENTRY;
 
        dump_lsm(D_INODE, lsm);
-       if (cfs_atomic_read(&lov->lo_active_ios) > 0)
-               RETURN(-EBUSY);
 
+       lov_layout_wait(env, lov);
         if (r0->lo_sub != NULL) {
                 for (i = 0; i < r0->lo_nr; ++i) {
                         struct lovsub_object *los = r0->lo_sub[i];
@@ -579,19 +583,13 @@ static int lov_layout_wait(const struct lu_env *env, struct lov_object *lov)
        struct l_wait_info lwi = { 0 };
        ENTRY;
 
-       if (!lov->lo_layout_invalid)
-               RETURN(0);
-
        while (cfs_atomic_read(&lov->lo_active_ios) > 0) {
-               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(&lov->lo_active_ios));
 
                l_wait_event(lov->lo_waitq,
                             cfs_atomic_read(&lov->lo_active_ios) == 0, &lwi);
-               lov_conf_lock(lov);
        }
        RETURN(0);
 }
@@ -702,7 +700,12 @@ static int lov_conf_set(const struct lu_env *env, struct cl_object *obj,
        }
 
        if (conf->coc_opc == OBJECT_CONF_WAIT) {
-               result = lov_layout_wait(env, lov);
+               if (lov->lo_layout_invalid &&
+                   cfs_atomic_read(&lov->lo_active_ios) > 0) {
+                       lov_conf_unlock(lov);
+                       result = lov_layout_wait(env, lov);
+                       lov_conf_lock(lov);
+               }
                GOTO(out, result);
        }
 
@@ -719,7 +722,7 @@ static int lov_conf_set(const struct lu_env *env, struct cl_object *obj,
        }
 
        /* will change layout - check if there still exists active IO. */
-       if (cfs_atomic_read(&lov->lo_active_ios) > 1) {
+       if (cfs_atomic_read(&lov->lo_active_ios) > 0) {
                lov->lo_layout_invalid = true;
                GOTO(out, result = -EBUSY);
        }