Whamcloud - gitweb
LU-11796 lov: Remove unnecessary assert
[fs/lustre-release.git] / lustre / lov / lov_object.c
index 23d7a5f..200f943 100644 (file)
@@ -37,6 +37,8 @@
 
 #define DEBUG_SUBSYSTEM S_LOV
 
+#include <linux/random.h>
+
 #include "lov_cl_internal.h"
 
 static inline struct lov_device *lov_object_dev(struct lov_object *obj)
@@ -211,9 +213,8 @@ 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;
-       LASSERT(r0->lo_nr <= lov_targets_nr(dev));
 
-       OBD_ALLOC_LARGE(r0->lo_sub, r0->lo_nr * sizeof r0->lo_sub[0]);
+       OBD_ALLOC_LARGE(r0->lo_sub, r0->lo_nr * sizeof(r0->lo_sub[0]));
        if (r0->lo_sub == NULL)
                GOTO(out, result = -ENOMEM);
 
@@ -280,14 +281,14 @@ static void lov_subobject_kill(const struct lu_env *env, struct lov_object *lov,
 {
        struct cl_object        *sub;
        struct lu_site          *site;
-       struct lu_site_bkt_data *bkt;
-       wait_queue_t          *waiter;
+       wait_queue_head_t *wq;
+       wait_queue_entry_t *waiter;
 
         LASSERT(r0->lo_sub[idx] == los);
 
-        sub  = lovsub2cl(los);
-        site = sub->co_lu.lo_dev->ld_site;
-        bkt  = lu_site_bkt_from_fid(site, &sub->co_lu.lo_header->loh_fid);
+       sub = lovsub2cl(los);
+       site = sub->co_lu.lo_dev->ld_site;
+       wq = lu_site_wq_from_fid(site, &sub->co_lu.lo_header->loh_fid);
 
         cl_object_kill(env, sub);
         /* release a reference to the sub-object and ... */
@@ -299,7 +300,7 @@ static void lov_subobject_kill(const struct lu_env *env, struct lov_object *lov,
        if (r0->lo_sub[idx] == los) {
                waiter = &lov_env_info(env)->lti_waiter;
                init_waitqueue_entry(waiter, current);
-               add_wait_queue(&bkt->lsb_marche_funebre, waiter);
+               add_wait_queue(wq, waiter);
                set_current_state(TASK_UNINTERRUPTIBLE);
                while (1) {
                        /* this wait-queue is signaled at the end of
@@ -315,7 +316,7 @@ static void lov_subobject_kill(const struct lu_env *env, struct lov_object *lov,
                                break;
                        }
                }
-               remove_wait_queue(&bkt->lsb_marche_funebre, waiter);
+               remove_wait_queue(wq, waiter);
        }
        LASSERT(r0->lo_sub[idx] == NULL);
 }
@@ -635,6 +636,7 @@ static int lov_init_composite(const struct lu_env *env, struct lov_device *dev,
        unsigned int mirror_count;
        int flr_state = lsm->lsm_flags & LCM_FL_FLR_MASK;
        int result = 0;
+       unsigned int seq;
        int i, j;
 
        ENTRY;
@@ -654,7 +656,7 @@ static int lov_init_composite(const struct lu_env *env, struct lov_device *dev,
        comp->lo_entry_count = lsm->lsm_entry_count;
        comp->lo_preferred_mirror = -1;
 
-       if (equi(flr_state == LCM_FL_NOT_FLR, comp->lo_mirror_count > 1))
+       if (equi(flr_state == LCM_FL_NONE, comp->lo_mirror_count > 1))
                RETURN(-EINVAL);
 
        OBD_ALLOC(comp->lo_mirrors,
@@ -692,7 +694,7 @@ static int lov_init_composite(const struct lu_env *env, struct lov_device *dev,
                lle->lle_extent = &lle->lle_lsme->lsme_extent;
                lle->lle_valid = !(lle->lle_lsme->lsme_flags & LCME_FL_STALE);
 
-               if (flr_state != LCM_FL_NOT_FLR)
+               if (flr_state != LCM_FL_NONE)
                        mirror_id = mirror_id_of(lle->lle_lsme->lsme_id);
 
                lre = &comp->lo_mirrors[j];
@@ -717,8 +719,8 @@ static int lov_init_composite(const struct lu_env *env, struct lov_device *dev,
                /* entries must be sorted by mirrors */
                lre->lre_mirror_id = mirror_id;
                lre->lre_start = lre->lre_end = i;
-               lre->lre_preferred = (lle->lle_lsme->lsme_flags &
-                                       LCME_FL_PREFERRED);
+               lre->lre_preferred = !!(lle->lle_lsme->lsme_flags &
+                                       LCME_FL_PREF_RD);
                lre->lre_valid = lle->lle_valid;
                lre->lre_stale = !lle->lle_valid;
        }
@@ -756,43 +758,28 @@ static int lov_init_composite(const struct lu_env *env, struct lov_device *dev,
        if (psz > 0)
                cl_object_header(&lov->lo_cl)->coh_page_bufsize += psz;
 
-       /* decide the preferred mirror */
-       mirror_count = 0, i = 0;
-       lov_foreach_mirror_entry(lov, lre) {
-               i++;
+       /* decide the preferred mirror. It uses the hash value of lov_object
+        * so that different clients would use different mirrors for read. */
+       mirror_count = 0;
+       seq = hash_long((unsigned long)lov, 8);
+       for (i = 0; i < comp->lo_mirror_count; i++) {
+               unsigned int idx = (i + seq) % comp->lo_mirror_count;
+
+               lre = lov_mirror_entry(lov, idx);
                if (lre->lre_stale)
                        continue;
 
                mirror_count++; /* valid mirror */
 
                if (lre->lre_preferred || comp->lo_preferred_mirror < 0)
-                       comp->lo_preferred_mirror = i - 1;
+                       comp->lo_preferred_mirror = idx;
        }
-       if (mirror_count == 0) {
+       if (!mirror_count) {
                CDEBUG(D_INODE, DFID
                       " doesn't have any valid mirrors\n",
                       PFID(lu_object_fid(lov2lu(lov))));
 
-               GOTO(out, result = -EINVAL);
-       }
-
-       if (OBD_FAIL_CHECK(OBD_FAIL_FLR_RANDOM_PICK_MIRROR)) {
-               unsigned int seq;
-
-               get_random_bytes(&seq, sizeof(seq));
-               seq %= mirror_count;
-
-               i = 0;
-               lov_foreach_mirror_entry(lov, lre) {
-                       i++;
-                       if (lre->lre_stale)
-                               continue;
-
-                       if (!seq--) {
-                               comp->lo_preferred_mirror = i - 1;
-                               break;
-                       }
-               }
+               comp->lo_preferred_mirror = 0;
        }
 
        LASSERT(comp->lo_preferred_mirror >= 0);
@@ -1817,8 +1804,11 @@ static int lov_object_fiemap(const struct lu_env *env, struct cl_object *obj,
        ENTRY;
 
        lsm = lov_lsm_addref(cl2lov(obj));
-       if (lsm == NULL)
-               RETURN(-ENODATA);
+       if (lsm == NULL) {
+               /* no extent: there is no object for mapping */
+               fiemap->fm_mapped_extents = 0;
+               return 0;
+       }
 
        if (!(fiemap->fm_flags & FIEMAP_FLAG_DEVICE_ORDER)) {
                /**