Whamcloud - gitweb
LU-5223 lmv: build master LMV EA dynamically build via readdir
[fs/lustre-release.git] / lustre / lod / lod_lov.c
index 1a8f09a..80e96cd 100644 (file)
 /*
  * lustre/lod/lod_lov.c
  *
- * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com> 
+ * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
  */
 
 #define DEBUG_SUBSYSTEM S_MDS
 
 #include <obd_class.h>
 #include <lustre_lfsck.h>
+#include <lustre_lmv.h>
 
 #include "lod_internal.h"
 
@@ -676,8 +677,8 @@ int lod_store_def_striping(const struct lu_env *env, struct dt_object *dt,
        v3->lmm_stripe_count = cpu_to_le16(lo->ldo_def_stripenr);
        v3->lmm_stripe_offset = cpu_to_le16(lo->ldo_def_stripe_offset);
        v3->lmm_stripe_size = cpu_to_le32(lo->ldo_def_stripe_size);
-       if (lo->ldo_pool)
-               strncpy(v3->lmm_pool_name, lo->ldo_pool,
+       if (lo->ldo_pool != NULL)
+               strlcpy(v3->lmm_pool_name, lo->ldo_pool,
                        sizeof(v3->lmm_pool_name));
        info->lti_buf.lb_buf = v3;
        info->lti_buf.lb_len = sizeof(*v3);
@@ -780,6 +781,7 @@ out:
                                lu_object_put(env, &stripe[i]->do_lu);
 
                OBD_FREE(stripe, sizeof(stripe[0]) * stripe_len);
+               lo->ldo_stripenr = 0;
        } else {
                lo->ldo_stripe = stripe;
                lo->ldo_stripes_allocated = stripe_len;
@@ -842,6 +844,7 @@ out:
 int lod_load_striping_locked(const struct lu_env *env, struct lod_object *lo)
 {
        struct lod_thread_info  *info = lod_env_info(env);
+       struct lu_buf           *buf  = &info->lti_buf;
        struct dt_object        *next = dt_object_child(&lo->ldo_obj);
        int                      rc = 0;
        ENTRY;
@@ -857,8 +860,7 @@ int lod_load_striping_locked(const struct lu_env *env, struct lod_object *lo)
        if (lo->ldo_dir_slave_stripe)
                GOTO(out, rc = 0);
 
-       /* only regular files can be striped */
-       if (lu_object_attr(lod2lu_obj(lo)) & S_IFREG) {
+       if (S_ISREG(lu_object_attr(lod2lu_obj(lo)))) {
                rc = lod_get_lov_ea(env, lo);
                if (rc <= 0)
                        GOTO(out, rc);
@@ -866,20 +868,34 @@ int lod_load_striping_locked(const struct lu_env *env, struct lod_object *lo)
                 * there is LOV EA (striping information) in this object
                 * let's parse it and create in-core objects for the stripes
                 */
-               info->lti_buf.lb_buf = info->lti_ea_store;
-               info->lti_buf.lb_len = info->lti_ea_store_size;
-               rc = lod_parse_striping(env, lo, &info->lti_buf);
-       } else if (lu_object_attr(lod2lu_obj(lo)) & S_IFDIR) {
+               buf->lb_buf = info->lti_ea_store;
+               buf->lb_len = info->lti_ea_store_size;
+               rc = lod_parse_striping(env, lo, buf);
+       } else if (S_ISDIR(lu_object_attr(lod2lu_obj(lo)))) {
                rc = lod_get_lmv_ea(env, lo);
-               if (rc <= 0)
-                       GOTO(out, rc);
+               if (rc < sizeof(struct lmv_mds_md_v1))
+                       GOTO(out, rc = rc > 0 ? -EINVAL : rc);
+
+               buf->lb_buf = info->lti_ea_store;
+               buf->lb_len = info->lti_ea_store_size;
+               if (rc == sizeof(struct lmv_mds_md_v1)) {
+                       rc = lod_load_lmv_shards(env, lo, buf, true);
+                       if (buf->lb_buf != info->lti_ea_store) {
+                               OBD_FREE_LARGE(info->lti_ea_store,
+                                              info->lti_ea_store_size);
+                               info->lti_ea_store = buf->lb_buf;
+                               info->lti_ea_store_size = buf->lb_len;
+                       }
+
+                       if (rc < 0)
+                               GOTO(out, rc);
+               }
+
                /*
                 * there is LOV EA (striping information) in this object
                 * let's parse it and create in-core objects for the stripes
                 */
-               info->lti_buf.lb_buf = info->lti_ea_store;
-               info->lti_buf.lb_len = info->lti_ea_store_size;
-               rc = lod_parse_dir_striping(env, lo, &info->lti_buf);
+               rc = lod_parse_dir_striping(env, lo, buf);
        }
 out:
        RETURN(rc);