Whamcloud - gitweb
LU-15702 lov: remove lo_trunc_stripeno 40/46940/2
authorJohn L. Hammond <jhammond@whamcloud.com>
Mon, 28 Mar 2022 17:24:54 +0000 (12:24 -0500)
committerOleg Drokin <green@whamcloud.com>
Sat, 2 Apr 2022 06:58:11 +0000 (06:58 +0000)
Remove the lo_trunc_stripeno member of struct lov_layout_raid0 and add
an lis_trunc_stripe_index array to struct lov_io. This makes the
truncate stripe index information belong to the IO and not to the
concurrently accessed object. This is needed because we do not have
locking that protects it from its initialization in lov_io_iter_init()
to its use in lov_lock_sub_init(). Also remove the unused
lo_write_lock member of struct lov_object.

Fixes: 9801500451 ("LU-14128 lov: correctly set OST obj size")
Signed-off-by: John L. Hammond <jhammond@whamcloud.com>
Change-Id: I799e07059212629fe9d84c5e58c349035a40da9e
Reviewed-on: https://review.whamcloud.com/46940
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Patrick Farrell <pfarrell@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Bobi Jam <bobijam@hotmail.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/lov/lov_cl_internal.h
lustre/lov/lov_io.c
lustre/lov/lov_lock.c
lustre/lov/lov_object.c

index 9563315..7e14876 100644 (file)
@@ -175,11 +175,6 @@ struct lov_comp_layout_entry_ops {
 struct lov_layout_raid0 {
        unsigned               lo_nr;
        /**
-        * record the stripe no before the truncate size, used for setting OST
-        * object size for truncate. LU-14128.
-        */
-       int                    lo_trunc_stripeno;
-       /**
         * When this is true, lov_object::lo_attr contains
         * valid up to date attributes for a top-level
         * object. This field is reset to 0 when attributes of
@@ -323,11 +318,6 @@ struct lov_object {
                         */
                        int             lo_preferred_mirror;
                        /**
-                        * For FLR: the lock to protect access to
-                        * lo_preferred_mirror.
-                        */
-                       spinlock_t      lo_write_lock;
-                       /**
                         * For FLR: Number of (valid) mirrors.
                         */
                        unsigned        lo_mirror_count;
@@ -558,6 +548,13 @@ struct lov_io {
          */
         loff_t             lis_io_endpos;
 
+       /**
+        * Record the stripe index before the truncate size, used for setting OST
+        * object size for truncate. LU-14128. lis_trunc_stripe_index[i] refers to
+        * lov_object.u.composite.lo_entries[i].
+        */
+       int *lis_trunc_stripe_index;
+
         /**
          * starting position within a file, for the current io loop iteration
          * (stripe), used by ci_io_loop().
index 1adb722..ce4fa30 100644 (file)
@@ -790,6 +790,7 @@ static int lov_io_iter_init(const struct lu_env *env,
 {
        struct lov_io *lio = cl2lov_io(env, ios);
        struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
+       bool is_trunc = cl_io_is_trunc(ios->cis_io);
        struct lov_io_sub *sub;
        struct lu_extent ext;
        int index;
@@ -800,6 +801,13 @@ static int lov_io_iter_init(const struct lu_env *env,
        ext.e_start = lio->lis_pos;
        ext.e_end = lio->lis_endpos;
 
+       if (is_trunc) {
+               OBD_ALLOC_PTR_ARRAY(lio->lis_trunc_stripe_index,
+                                   lio->lis_object->u.composite.lo_entry_count);
+               if (lio->lis_trunc_stripe_index == NULL)
+                       RETURN(-ENOMEM);
+       }
+
        lov_foreach_io_layout(index, lio, &ext) {
                struct lov_layout_entry *le = lov_entry(lio->lis_object, index);
                struct lov_layout_raid0 *r0 = &le->lle_raid0;
@@ -808,7 +816,8 @@ static int lov_io_iter_init(const struct lu_env *env,
                int stripe;
                bool tested_trunc_stripe = false;
 
-               r0->lo_trunc_stripeno = -1;
+               if (is_trunc)
+                       lio->lis_trunc_stripe_index[index] = -1;
 
                CDEBUG(D_VFSTRACE, "component[%d] flags %#x\n",
                       index, lsm->lsm_entries[index]->lsme_flags);
@@ -843,8 +852,7 @@ static int lov_io_iter_init(const struct lu_env *env,
                                continue;
                        }
 
-                       if (cl_io_is_trunc(ios->cis_io) &&
-                           !tested_trunc_stripe) {
+                       if (is_trunc && !tested_trunc_stripe) {
                                int prev;
                                u64 tr_start;
 
@@ -859,7 +867,7 @@ static int lov_io_iter_init(const struct lu_env *env,
                                if (ext.e_start < lsm->lsm_entries[index]->
                                                        lsme_extent.e_start) {
                                        /* need previous stripe involvement */
-                                       r0->lo_trunc_stripeno = prev;
+                                       lio->lis_trunc_stripe_index[index] = prev;
                                } else {
                                        tr_start = ext.e_start;
                                        tr_start = lov_do_div64(tr_start,
@@ -868,13 +876,13 @@ static int lov_io_iter_init(const struct lu_env *env,
                                        if (tr_start == stripe * lsm->
                                                        lsm_entries[index]->
                                                        lsme_stripe_size)
-                                               r0->lo_trunc_stripeno = prev;
+                                               lio->lis_trunc_stripe_index[index] = prev;
                                }
                        }
 
                        /* if the last stripe is the trunc stripeno */
-                       if (r0->lo_trunc_stripeno == stripe)
-                               r0->lo_trunc_stripeno = -1;
+                       if (is_trunc && lio->lis_trunc_stripe_index[index] == stripe)
+                               lio->lis_trunc_stripe_index[index] = -1;
 
                        sub = lov_sub_get(env, lio,
                                          lov_comp_index(index, stripe));
@@ -888,10 +896,10 @@ static int lov_io_iter_init(const struct lu_env *env,
                if (rc != 0)
                        break;
 
-               if (r0->lo_trunc_stripeno != -1) {
-                       stripe = r0->lo_trunc_stripeno;
+               if (is_trunc && lio->lis_trunc_stripe_index[index] != -1) {
+                       stripe = lio->lis_trunc_stripe_index[index];
                        if (unlikely(!r0->lo_sub[stripe])) {
-                               r0->lo_trunc_stripeno = -1;
+                               lio->lis_trunc_stripe_index[index] = -1;
                                continue;
                        }
                        sub = lov_sub_get(env, lio,
@@ -905,7 +913,7 @@ static int lov_io_iter_init(const struct lu_env *env,
                         * read get wrong kms.
                         */
                        if (!list_empty(&sub->sub_linkage)) {
-                               r0->lo_trunc_stripeno = -1;
+                               lio->lis_trunc_stripe_index[index] = -1;
                                continue;
                        }
 
@@ -1113,6 +1121,12 @@ static void lov_io_iter_fini(const struct lu_env *env,
        int rc;
 
        ENTRY;
+
+       if (lio->lis_trunc_stripe_index != NULL)
+               OBD_FREE_PTR_ARRAY(lio->lis_trunc_stripe_index,
+                                  lio->lis_object->u.composite.lo_entry_count);
+       lio->lis_trunc_stripe_index = NULL;
+
        rc = lov_io_call(env, lio, lov_io_iter_fini_wrapper);
        LASSERT(rc == 0);
        while (!list_empty(&lio->lis_active))
index 93d0fbf..40777f3 100644 (file)
@@ -116,6 +116,8 @@ static struct lov_lock *lov_lock_sub_init(const struct lu_env *env,
                                          struct cl_lock *lock)
 {
        struct lov_object *lov = cl2lov(obj);
+       struct lov_io *lio = lov_env_io(env);
+       bool is_trunc = cl_io_is_trunc(io);
        struct lov_lock *lovlck;
        struct lu_extent ext;
        loff_t start;
@@ -127,6 +129,8 @@ static struct lov_lock *lov_lock_sub_init(const struct lu_env *env,
 
        ENTRY;
 
+       LASSERT(ergo(is_trunc, lio->lis_trunc_stripe_index != NULL));
+
        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;
@@ -134,16 +138,13 @@ static struct lov_lock *lov_lock_sub_init(const struct lu_env *env,
                ext.e_end  = cl_offset(obj, lock->cll_descr.cld_end + 1);
 
        nr = 0;
-       lov_foreach_io_layout(index, lov_env_io(env), &ext) {
+       lov_foreach_io_layout(index, lio, &ext) {
                struct lov_layout_raid0 *r0 = lov_r0(lov, index);
 
                for (i = 0; i < r0->lo_nr; i++) {
                        if (likely(r0->lo_sub[i])) {/* spare layout */
-                               if (lov_stripe_intersects(lov->lo_lsm, index, i,
-                                                         &ext, &start, &end))
-                                       nr++;
-                               else if (cl_io_is_trunc(io) &&
-                                        r0->lo_trunc_stripeno == i)
+                               if (lov_stripe_intersects(lov->lo_lsm, index, i, &ext, &start, &end) ||
+                                   (is_trunc && i == lio->lis_trunc_stripe_index[index]))
                                        nr++;
                        }
                }
@@ -164,24 +165,21 @@ static struct lov_lock *lov_lock_sub_init(const struct lu_env *env,
                struct lov_layout_raid0 *r0 = lov_r0(lov, index);
 
                for (i = 0; i < r0->lo_nr; ++i) {
-                       struct lov_lock_sub *lls = &lovlck->lls_sub[nr];
-                       struct cl_lock_descr *descr = &lls->sub_lock.cll_descr;
-                       bool intersect = false;
+                       struct lov_lock_sub *lls;
+                       struct cl_lock_descr *descr;
 
                        if (unlikely(!r0->lo_sub[i]))
                                continue;
 
-                       intersect = lov_stripe_intersects(lov->lo_lsm, index, i,
-                                                         &ext, &start, &end);
-                       if (intersect)
-                               goto init_sublock;
-
-                       if (cl_io_is_trunc(io) && i == r0->lo_trunc_stripeno)
+                       if (lov_stripe_intersects(lov->lo_lsm, index, i, &ext, &start, &end) ||
+                           (is_trunc && i == lio->lis_trunc_stripe_index[index]))
                                goto init_sublock;
 
                        continue;
-
 init_sublock:
+                       LASSERT(nr < lovlck->lls_nr);
+                       lls = &lovlck->lls_sub[nr];
+                       descr = &lls->sub_lock.cll_descr;
                        LASSERT(descr->cld_obj == NULL);
                        descr->cld_obj   = lovsub2cl(r0->lo_sub[i]);
                        descr->cld_start = cl_index(descr->cld_obj, start);
index 870a592..11b8df7 100644 (file)
@@ -215,7 +215,6 @@ static int lov_init_raid0(const struct lu_env *env, struct lov_device *dev,
 
        spin_lock_init(&r0->lo_sub_lock);
        r0->lo_nr = lse->lsme_stripe_count;
-       r0->lo_trunc_stripeno = -1;
 
        OBD_ALLOC_PTR_ARRAY_LARGE(r0->lo_sub, r0->lo_nr);
        if (r0->lo_sub == NULL)
@@ -646,7 +645,6 @@ static int lov_init_composite(const struct lu_env *env, struct lov_device *dev,
 
        entry_count = lsm->lsm_entry_count;
 
-       spin_lock_init(&comp->lo_write_lock);
        comp->lo_flags = lsm->lsm_flags;
        comp->lo_mirror_count = lsm->lsm_mirror_count + 1;
        comp->lo_entry_count = lsm->lsm_entry_count;