Whamcloud - gitweb
fix lmake to link to correct ia64 kernels
[fs/lustre-release.git] / lustre / lov / lov_pack.c
index 2cf14fd..1b40327 100644 (file)
@@ -23,7 +23,7 @@
  *
  */
 
-#define DEBUG_SUBSYSTEM S_LLITE
+#define DEBUG_SUBSYSTEM S_LOV
 #ifndef __KERNEL__
 #include <liblustre.h>
 #endif
@@ -295,6 +295,7 @@ int lov_alloc_memmd(struct lov_stripe_md **lsmp, int stripe_count, int pattern)
         (*lsmp)->lsm_magic = LOV_MAGIC;
         (*lsmp)->lsm_stripe_count = stripe_count;
         (*lsmp)->lsm_maxbytes = LUSTRE_STRIPE_MAXBYTES * stripe_count;
+        (*lsmp)->lsm_xfersize = PTL_MTU * stripe_count;
         (*lsmp)->lsm_pattern = pattern;
         (*lsmp)->lsm_oinfo[0].loi_ost_idx = ~0;
 
@@ -319,6 +320,7 @@ int lov_unpackmd_v0(struct lov_obd *lov, struct lov_stripe_md *lsm,
         lsm->lsm_object_id = le64_to_cpu(lmm->lmm_object_id);
         /* lsm->lsm_object_gr = 0; implicit */
         lsm->lsm_stripe_size = le32_to_cpu(lmm->lmm_stripe_size);
+        lsm->lsm_xfersize = lsm->lsm_stripe_size * lsm->lsm_stripe_count;
         lsm->lsm_pattern = LOV_PATTERN_RAID0;
         ost_offset = le32_to_cpu(lmm->lmm_stripe_offset);
         ost_count = le16_to_cpu(lmm->lmm_ost_count);
@@ -356,6 +358,7 @@ int lov_unpackmd_v1(struct lov_obd *lov, struct lov_stripe_md *lsm,
         lsm->lsm_object_gr = le64_to_cpu(lmm->lmm_object_gr);
         lsm->lsm_stripe_size = le32_to_cpu(lmm->lmm_stripe_size);
         lsm->lsm_pattern = le32_to_cpu(lmm->lmm_pattern);
+        lsm->lsm_xfersize = lsm->lsm_stripe_size * lsm->lsm_stripe_count;
 
         for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++) {
                 /* XXX LOV STACKING call down to osc_unpackmd() */
@@ -496,10 +499,49 @@ int lov_setstripe(struct obd_export *exp, struct lov_stripe_md **lsmp,
 
         (*lsmp)->lsm_oinfo[0].loi_ost_idx = lum.lmm_stripe_offset;
         (*lsmp)->lsm_stripe_size = lum.lmm_stripe_size;
+        (*lsmp)->lsm_xfersize = lum.lmm_stripe_size * stripe_count;
 
         RETURN(0);
 }
 
+int lov_setea(struct obd_export *exp, struct lov_stripe_md **lsmp,
+                  struct lov_user_md *lump)
+{
+        int i;
+        int rc;
+        struct obd_export *oexp;
+        struct lov_obd *lov = &exp->exp_obd->u.lov;
+        obd_id last_id = 0;
+
+        for (i = 0; i < lump->lmm_stripe_count; i++) {
+                __u32 len = sizeof(last_id);
+                oexp = lov->tgts[lump->lmm_objects[i].l_ost_idx].ltd_exp;
+                rc = obd_get_info(oexp, strlen("last_id"), "last_id", 
+                                  &len, &last_id); 
+                if (rc)
+                        RETURN(rc);
+                if (last_id < lump->lmm_objects[i].l_object_id) {
+                        CERROR("Setting EA for object > than last id on "
+                          "ost idx %d "LPD64" > "LPD64" \n", 
+                          lump->lmm_objects[i].l_ost_idx,
+                          lump->lmm_objects[i].l_object_id, last_id);
+                        RETURN(-EINVAL);
+                }
+        }
+
+        rc = lov_setstripe(exp, lsmp, lump);
+        if (rc) 
+                RETURN(rc);
+        for (i = 0; i < lump->lmm_stripe_count; i++) {
+                (*lsmp)->lsm_oinfo[i].loi_ost_idx = 
+                                                 lump->lmm_objects[i].l_ost_idx;
+                (*lsmp)->lsm_oinfo[i].loi_id = lump->lmm_objects[i].l_object_id;
+                (*lsmp)->lsm_oinfo[i].loi_gr = lump->lmm_objects[i].l_object_gr;
+        }
+        RETURN(0);
+}
+
+
 /* Retrieve object striping information.
  *
  * @lump is a pointer to an in-core struct with lmm_ost_count indicating
@@ -535,10 +577,14 @@ int lov_getstripe(struct obd_export *exp, struct lov_stripe_md *lsm,
         LASSERT(sizeof(lum.lmm_objects[0]) == sizeof(lmmk->lmm_objects[0]));
 
         /* User wasn't expecting this many OST entries */
-        if (lum.lmm_stripe_count < lmmk->lmm_stripe_count)
+        if (lum.lmm_stripe_count == 0) {
+                if (copy_to_user(lump, lmmk, sizeof(lum)))
+                        rc = -EFAULT;
+        } else if (lum.lmm_stripe_count < lmmk->lmm_stripe_count) {
                 rc = -EOVERFLOW;
-        else if (copy_to_user(lump, lmmk, lmm_size))
+        } else if (copy_to_user(lump, lmmk, lmm_size)) {
                 rc = -EFAULT;
+        }
 
         obd_free_diskmd(exp, &lmmk);