Whamcloud - gitweb
LU-10850 fld: handle empty ranges in fld_index_init() 71/31871/2
authorJohn L. Hammond <john.hammond@intel.com>
Wed, 4 Apr 2018 15:13:16 +0000 (10:13 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Sun, 6 May 2018 03:41:56 +0000 (03:41 +0000)
In fld_index_init(), ignore the empty range corresponding to the
zeroed-out phantom record that is included in newly created ldiskfs
IAM indexes. (This phantom record will be removed in a subseuent
patch.) Ensure that lfs_new will be set when the FLD index was empty
of valid ranges. (Previously it was properly set on ZFS backed targets
but not on ldiskfs.)

Signed-off-by: John L. Hammond <john.hammond@intel.com>
Change-Id: I9850eac686e1488ffbd627f100075ce6f29200d8
Reviewed-on: https://review.whamcloud.com/31871
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Fan Yong <fan.yong@intel.com>
Reviewed-by: Mike Pershin <mike.pershin@intel.com>
Reviewed-by: Alex Zhuravlev <alexey.zhuravlev@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/fld/fld_index.c

index ab0ae6d..7399206 100644 (file)
@@ -335,6 +335,7 @@ int fld_index_init(const struct lu_env *env, struct lu_server_fld *fld,
        const struct dt_it_ops  *iops;
        int                     rc;
        __u32                   index;
        const struct dt_it_ops  *iops;
        int                     rc;
        __u32                   index;
+       int range_count = 0;
        ENTRY;
 
        info = lu_context_key_get(&env->le_ctx, &fld_thread_key);
        ENTRY;
 
        info = lu_context_key_get(&env->le_ctx, &fld_thread_key);
@@ -388,26 +389,39 @@ int fld_index_init(const struct lu_env *env, struct lu_server_fld *fld,
                GOTO(out, rc = PTR_ERR(it));
 
        rc = iops->load(env, it, 0);
                GOTO(out, rc = PTR_ERR(it));
 
        rc = iops->load(env, it, 0);
+       if (rc > 0)
+               rc = 0;
+       else if (rc == 0)
+               rc = iops->next(env, it);
+
        if (rc < 0)
                GOTO(out_it_fini, rc);
 
        if (rc < 0)
                GOTO(out_it_fini, rc);
 
-       if (rc > 0) {
-               /* Load FLD entry into server cache */
-               do {
-                       rc = iops->rec(env, it, (struct dt_rec *)range, 0);
-                       if (rc != 0)
-                               GOTO(out_it_put, rc);
-                       LASSERT(range != NULL);
-                       range_be_to_cpu(range, range);
+       while (rc == 0) {
+               rc = iops->rec(env, it, (struct dt_rec *)range, 0);
+               if (rc != 0)
+                       GOTO(out_it_put, rc);
+
+               range_be_to_cpu(range, range);
+
+               /* Newly created ldiskfs IAM indexes may include a
+                * zeroed-out key and record. Ignore it here. */
+               if (range->lsr_start < range->lsr_end) {
                        rc = fld_cache_insert(fld->lsf_cache, range);
                        if (rc != 0)
                                GOTO(out_it_put, rc);
                        rc = fld_cache_insert(fld->lsf_cache, range);
                        if (rc != 0)
                                GOTO(out_it_put, rc);
-                       rc = iops->next(env, it);
-               } while (rc == 0);
-       } else {
-               fld->lsf_new = 1;
+
+                       range_count++;
+               }
+
+               rc = iops->next(env, it);
+               if (rc < 0)
+                       GOTO(out_it_fini, rc);
        }
 
        }
 
+       if (range_count == 0)
+               fld->lsf_new = 1;
+
        rc = fld_name_to_index(fld->lsf_name, &index);
        if (rc < 0)
                GOTO(out_it_put, rc);
        rc = fld_name_to_index(fld->lsf_name, &index);
        if (rc < 0)
                GOTO(out_it_put, rc);