Whamcloud - gitweb
LU-9311 pfl: shouldn't reprocess done/no-op resent request
[fs/lustre-release.git] / lustre / lov / lov_lock.c
index 60af105..efa4cc1 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -27,7 +23,7 @@
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2014, Intel Corporation.
+ * Copyright (c) 2011, 2016, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -54,7 +50,7 @@
 
 static struct lov_sublock_env *lov_sublock_env_get(const struct lu_env *env,
                                                   const struct cl_lock *parent,
-                                                   struct lov_lock_sub *lls)
+                                                  struct lov_lock_sub *lls)
 {
         struct lov_sublock_env *subenv;
         struct lov_io          *lio    = lov_env_io(env);
@@ -72,27 +68,19 @@ static struct lov_sublock_env *lov_sublock_env_get(const struct lu_env *env,
          * they are not initialized at all. As a temp fix, in this case,
          * we still borrow the parent's env to call sublock operations.
          */
-        if (!io || !cl_object_same(io->ci_obj, parent->cll_descr.cld_obj)) {
-                subenv->lse_env = env;
-                subenv->lse_io  = io;
-                subenv->lse_sub = NULL;
-        } else {
-                sub = lov_sub_get(env, lio, lls->sub_stripe);
-                if (!IS_ERR(sub)) {
-                        subenv->lse_env = sub->sub_env;
-                        subenv->lse_io  = sub->sub_io;
-                        subenv->lse_sub = sub;
-                } else {
-                        subenv = (void*)sub;
-                }
-        }
-        return subenv;
-}
-
-static void lov_sublock_env_put(struct lov_sublock_env *subenv)
-{
-        if (subenv && subenv->lse_sub)
-                lov_sub_put(subenv->lse_sub);
+       if (!io || !cl_object_same(io->ci_obj, parent->cll_descr.cld_obj)) {
+               subenv->lse_env = env;
+               subenv->lse_io = io;
+       } else {
+               sub = lov_sub_get(env, lio, lls->sub_index);
+               if (!IS_ERR(sub)) {
+                       subenv->lse_env = sub->sub_env;
+                       subenv->lse_io  = &sub->sub_io;
+               } else {
+                       subenv = (void *)sub;
+               }
+       }
+       return subenv;
 }
 
 static int lov_sublock_init(const struct lu_env *env,
@@ -107,7 +95,6 @@ static int lov_sublock_init(const struct lu_env *env,
        if (!IS_ERR(subenv)) {
                result = cl_lock_init(subenv->lse_env, &lls->sub_lock,
                                      subenv->lse_io);
-               lov_sublock_env_put(subenv);
        } else {
                /* error occurs. */
                result = PTR_ERR(subenv);
@@ -127,53 +114,69 @@ static struct lov_lock *lov_lock_sub_init(const struct lu_env *env,
                                          const struct cl_object *obj,
                                          struct cl_lock *lock)
 {
+       struct lov_object *lov = cl2lov(obj);
+       struct lov_lock *lovlck;
+       struct lu_extent ext;
+       loff_t start;
+       loff_t end;
        int result = 0;
        int i;
+       int index;
        int nr;
-       loff_t start;
-       loff_t end;
-       loff_t file_start;
-       loff_t file_end;
-
-       struct lov_object       *loo    = cl2lov(obj);
-       struct lov_layout_raid0 *r0     = lov_r0(loo);
-       struct lov_lock         *lovlck;
 
        ENTRY;
 
-       CDEBUG(D_INODE, "%p: lock/io FID "DFID"/"DFID", lock/io clobj %p/%p\n",
-              loo, PFID(lu_object_fid(lov2lu(loo))),
-              PFID(lu_object_fid(&obj->co_lu)),
-              lov2cl(loo), obj);
-
-       file_start = cl_offset(lov2cl(loo), lock->cll_descr.cld_start);
-       file_end   = cl_offset(lov2cl(loo), lock->cll_descr.cld_end + 1) - 1;
-
-        for (i = 0, nr = 0; i < r0->lo_nr; i++) {
-                /*
-                 * XXX for wide striping smarter algorithm is desirable,
-                 * breaking out of the loop, early.
-                 */
-               if (likely(r0->lo_sub[i] != NULL) && /* spare layout */
-                   lov_stripe_intersects(loo->lo_lsm, i,
-                                         file_start, file_end, &start, &end))
-                       nr++;
+       ext.e_start = cl_offset(obj, lock->cll_descr.cld_start);
+       if (lock->cll_descr.cld_end == CL_PAGE_EOF)
+               ext.e_end = OBD_OBJECT_EOF;
+       else
+               ext.e_end  = cl_offset(obj, lock->cll_descr.cld_end + 1);
+
+       nr = 0;
+       for (index = lov_lsm_entry(lov->lo_lsm, ext.e_start);
+            index >= 0 && index < lov->lo_lsm->lsm_entry_count; index++) {
+               struct lov_layout_raid0 *r0 = lov_r0(lov, index);
+
+               /* assume lsm entries are sorted. */
+               if (!lu_extent_is_overlapped(&ext,
+                                            &lov_lse(lov, index)->lsme_extent))
+                       break;
+
+               for (i = 0; i < r0->lo_nr; i++) {
+                       if (likely(r0->lo_sub[i] != NULL) && /* spare layout */
+                           lov_stripe_intersects(lov->lo_lsm, index, i,
+                                                 &ext, &start, &end))
+                               nr++;
+               }
        }
-       LASSERT(nr > 0);
+       /**
+        * Aggressive lock request (from cl_setattr_ost) which asks for
+        * [eof, -1) lock, could come across uninstantiated layout extent,
+        * hence a 0 nr is possible.
+        */
 
        OBD_ALLOC_LARGE(lovlck, offsetof(struct lov_lock, lls_sub[nr]));
        if (lovlck == NULL)
                RETURN(ERR_PTR(-ENOMEM));
 
        lovlck->lls_nr = nr;
-       for (i = 0, nr = 0; i < r0->lo_nr; ++i) {
-               if (likely(r0->lo_sub[i] != NULL) &&
-                   lov_stripe_intersects(loo->lo_lsm, i,
-                                         file_start, file_end, &start, &end)) {
+       nr = 0;
+       for (index = lov_lsm_entry(lov->lo_lsm, ext.e_start);
+            index >= 0 && index < lov->lo_lsm->lsm_entry_count; index++) {
+               struct lov_layout_raid0 *r0 = lov_r0(lov, index);
+
+               /* assume lsm entries are sorted. */
+               if (!lu_extent_is_overlapped(&ext,
+                                            &lov_lse(lov, index)->lsme_extent))
+                       break;
+               for (i = 0; i < r0->lo_nr; ++i) {
                        struct lov_lock_sub *lls = &lovlck->lls_sub[nr];
-                       struct cl_lock_descr *descr;
+                       struct cl_lock_descr *descr = &lls->sub_lock.cll_descr;
 
-                       descr = &lls->sub_lock.cll_descr;
+                       if (unlikely(r0->lo_sub[i] == NULL) ||
+                           !lov_stripe_intersects(lov->lo_lsm, index, i,
+                                                  &ext, &start, &end))
+                               continue;
 
                        LASSERT(descr->cld_obj == NULL);
                        descr->cld_obj   = lovsub2cl(r0->lo_sub[i]);
@@ -183,7 +186,7 @@ static struct lov_lock *lov_lock_sub_init(const struct lu_env *env,
                        descr->cld_gid   = lock->cll_descr.cld_gid;
                        descr->cld_enq_flags = lock->cll_descr.cld_enq_flags;
 
-                       lls->sub_stripe = i;
+                       lls->sub_index = lov_comp_index(index, i);
 
                        /* initialize sub lock */
                        result = lov_sublock_init(env, lock, lls);
@@ -260,7 +263,6 @@ static int lov_lock_enqueue(const struct lu_env *env,
 
                rc = cl_lock_enqueue(subenv->lse_env, subenv->lse_io,
                                     &lls->sub_lock, anchor);
-               lov_sublock_env_put(subenv);
                if (rc != 0)
                        break;
 
@@ -290,7 +292,6 @@ static void lov_lock_cancel(const struct lu_env *env,
                subenv = lov_sublock_env_get(env, lock, lls);
                if (!IS_ERR(subenv)) {
                        cl_lock_cancel(subenv->lse_env, sublock);
-                       lov_sublock_env_put(subenv);
                } else {
                        CL_LOCK_DEBUG(D_ERROR, env, slice->cls_lock,
                                      "lov_lock_cancel fails with %ld.\n",
@@ -323,8 +324,8 @@ static const struct cl_lock_operations lov_lock_ops = {
         .clo_print     = lov_lock_print
 };
 
-int lov_lock_init_raid0(const struct lu_env *env, struct cl_object *obj,
-                       struct cl_lock *lock, const struct cl_io *io)
+int lov_lock_init_composite(const struct lu_env *env, struct cl_object *obj,
+                           struct cl_lock *lock, const struct cl_io *io)
 {
        struct lov_lock *lck;
        int result = 0;