Whamcloud - gitweb
b=16823
[fs/lustre-release.git] / lustre / lov / lov_ea.c
index 174e1fc..63f2dc7 100755 (executable)
@@ -1,26 +1,41 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- *  Copyright (c) 2001-2005 Cluster File Systems, Inc.
- *   Author: Wang Di <wangdi@clusterfs.com>
+ * GPL HEADER START
  *
- *   This file is part of the Lustre file system, http://www.lustre.org
- *   Lustre is a trademark of Cluster File Systems, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- *   You may have signed or agreed to another license before downloading
- *   this software.  If so, you are bound by the terms and conditions
- *   of that agreement, and the following does not apply to you.  See the
- *   LICENSE file included with this distribution for more information.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
  *
- *   If you did not agree to a different license, then this copy of Lustre
- *   is open source software; you can redistribute it and/or modify it
- *   under the terms of version 2 of the GNU General Public License as
- *   published by the Free Software Foundation.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
  *
- *   In either case, Lustre is distributed in the hope that it will be
- *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
- *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   license text for more details.
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ *
+ * lustre/lov/lov_ea.c
+ *
+ * Author: Wang Di <wangdi@clusterfs.com>
  */
 
 #ifndef EXPORT_SYMTAB
@@ -53,29 +68,27 @@ static int lsm_lmm_verify_common(struct lov_mds_md *lmm, int lmm_bytes,
 
         if (stripe_count == 0 || stripe_count > LOV_V1_INSANE_STRIPE_COUNT) {
                 CERROR("bad stripe count %d\n", stripe_count);
-                lov_dump_lmm_v1(D_WARNING, lmm);
+                lov_dump_lmm(D_WARNING, lmm);
                 return -EINVAL;
         }
-        
+
         if (lmm->lmm_object_id == 0) {
                 CERROR("zero object id\n");
-                lov_dump_lmm_v1(D_WARNING, lmm);
+                lov_dump_lmm(D_WARNING, lmm);
                 return -EINVAL;
         }
-        
+
         if (lmm->lmm_pattern != cpu_to_le32(LOV_PATTERN_RAID0)) {
                 CERROR("bad striping pattern\n");
-                lov_dump_lmm_v1(D_WARNING, lmm);
+                lov_dump_lmm(D_WARNING, lmm);
                 return -EINVAL;
         }
 
         if (lmm->lmm_stripe_size == 0 ||
-            (stripe_count != -1 &&
-             (__u64)le32_to_cpu(lmm->lmm_stripe_size)*stripe_count >
-             0xffffffff)) {
+             (le32_to_cpu(lmm->lmm_stripe_size)&(LOV_MIN_STRIPE_SIZE-1)) != 0) {
                 CERROR("bad stripe size %u\n",
                        le32_to_cpu(lmm->lmm_stripe_size));
-                lov_dump_lmm_v1(D_WARNING, lmm);
+                lov_dump_lmm(D_WARNING, lmm);
                 return -EINVAL;
         }
         return 0;
@@ -97,12 +110,13 @@ struct lov_stripe_md *lsm_alloc_plain(int stripe_count, int *size)
                 return NULL;;
 
         for (i = 0; i < stripe_count; i++) {
-                OBD_SLAB_ALLOC(loi, lov_oinfo_slab, CFS_ALLOC_IO, sizeof(*loi));
+                OBD_SLAB_ALLOC_PTR_GFP(loi, lov_oinfo_slab, CFS_ALLOC_IO);
                 if (loi == NULL)
                         goto err;
                 lsm->lsm_oinfo[i] = loi;
         }
         lsm->lsm_stripe_count = stripe_count;
+        lsm->lsm_pool_name[0] = '\0';
         return lsm;
 
 err:
@@ -127,26 +141,31 @@ void lsm_free_plain(struct lov_stripe_md *lsm)
 static void lsm_unpackmd_common(struct lov_stripe_md *lsm,
                                 struct lov_mds_md *lmm)
 {
+        /*
+         * This supposes lov_mds_md_v1/v3 first fields are
+         * are the same
+         */
         lsm->lsm_object_id = le64_to_cpu(lmm->lmm_object_id);
         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_pool_name[0] = '\0';
 }
 
 static void
 lsm_stripe_by_index_plain(struct lov_stripe_md *lsm, int *stripeno,
-                           obd_off *lov_off, unsigned long *swidth)
+                           obd_off *lov_off, obd_off *swidth)
 {
         if (swidth)
-                *swidth = (unsigned long)lsm->lsm_stripe_size * lsm->lsm_stripe_count;
+                *swidth = (obd_off)lsm->lsm_stripe_size * lsm->lsm_stripe_count;
 }
 
 static void
 lsm_stripe_by_offset_plain(struct lov_stripe_md *lsm, int *stripeno,
-                           obd_off *lov_off, unsigned long *swidth)
+                           obd_off *lov_off, obd_off *swidth)
 {
         if (swidth)
-                *swidth = (unsigned long)lsm->lsm_stripe_size * lsm->lsm_stripe_count;
+                *swidth = (obd_off)lsm->lsm_stripe_size * lsm->lsm_stripe_count;
 }
 
 static obd_off
@@ -182,20 +201,20 @@ static int lsm_destroy_plain(struct lov_stripe_md *lsm, struct obdo *oa,
         return 0;
 }
 
-static int lsm_lmm_verify_plain(struct lov_mds_md *lmm, int lmm_bytes,
+static int lsm_lmm_verify_v1(struct lov_mds_md_v1 *lmm, int lmm_bytes,
                              int *stripe_count)
 {
         if (lmm_bytes < sizeof(*lmm)) {
-                CERROR("lov_mds_md too small: %d, need at least %d\n",
+                CERROR("lov_mds_md_v1 too small: %d, need at least %d\n",
                        lmm_bytes, (int)sizeof(*lmm));
                 return -EINVAL;
         }
 
         *stripe_count = le32_to_cpu(lmm->lmm_stripe_count);
 
-        if (lmm_bytes < lov_mds_md_v1_size(*stripe_count)) {
-                CERROR("LOV EA too small: %d, need %d\n",
-                       lmm_bytes, lov_mds_md_v1_size(*stripe_count));
+        if (lmm_bytes < lov_mds_md_size(*stripe_count, LOV_MAGIC_V1)) {
+                CERROR("LOV EA V1 too small: %d, need %d\n",
+                       lmm_bytes, lov_mds_md_size(*stripe_count, LOV_MAGIC_V1));
                 lov_dump_lmm_v1(D_WARNING, lmm);
                 return -EINVAL;
         }
@@ -203,7 +222,7 @@ static int lsm_lmm_verify_plain(struct lov_mds_md *lmm, int lmm_bytes,
         return lsm_lmm_verify_common(lmm, lmm_bytes, *stripe_count);
 }
 
-int lsm_unpackmd_plain(struct lov_obd *lov, struct lov_stripe_md *lsm,
+int lsm_unpackmd_v1(struct lov_obd *lov, struct lov_stripe_md *lsm,
                     struct lov_mds_md_v1 *lmm)
 {
         struct lov_oinfo *loi;
@@ -234,7 +253,7 @@ int lsm_unpackmd_plain(struct lov_obd *lov, struct lov_stripe_md *lsm,
         return 0;
 }
 
-struct lsm_operations lsm_plain_ops = {
+const struct lsm_operations lsm_v1_ops = {
         .lsm_free            = lsm_free_plain,
         .lsm_destroy         = lsm_destroy_plain,
         .lsm_stripe_by_index    = lsm_stripe_by_index_plain,
@@ -243,8 +262,8 @@ struct lsm_operations lsm_plain_ops = {
         .lsm_stripe_offset_by_index  = lsm_stripe_offset_by_index_plain,
         .lsm_stripe_offset_by_offset = lsm_stripe_offset_by_offset_plain,
         .lsm_stripe_index_by_offset  = lsm_stripe_index_by_offset_plain,
-        .lsm_lmm_verify         = lsm_lmm_verify_plain,
-        .lsm_unpackmd           = lsm_unpackmd_plain,
+        .lsm_lmm_verify         = lsm_lmm_verify_v1,
+        .lsm_unpackmd           = lsm_unpackmd_v1,
 };
 
 struct lov_extent *lovea_off2le(struct lov_stripe_md *lsm, obd_off lov_off)
@@ -316,7 +335,7 @@ static void lsm_free_join(struct lov_stripe_md *lsm)
 
 static void
 lsm_stripe_by_index_join(struct lov_stripe_md *lsm, int *stripeno,
-                           obd_off *lov_off, unsigned long *swidth)
+                           obd_off *lov_off, obd_off *swidth)
 {
         struct lov_extent *le;
 
@@ -329,7 +348,7 @@ lsm_stripe_by_index_join(struct lov_stripe_md *lsm, int *stripeno,
         *stripeno -= le->le_loi_idx;
 
         if (swidth)
-                *swidth = (unsigned long)lsm->lsm_stripe_size * le->le_stripe_count;
+                *swidth = (obd_off)lsm->lsm_stripe_size * le->le_stripe_count;
 
         if (lov_off) {
                 struct lov_extent *lov_le = lovea_off2le(lsm, *lov_off);
@@ -346,7 +365,7 @@ lsm_stripe_by_index_join(struct lov_stripe_md *lsm, int *stripeno,
 
 static void
 lsm_stripe_by_offset_join(struct lov_stripe_md *lsm, int *stripeno,
-                           obd_off *lov_off, unsigned long *swidth)
+                           obd_off *lov_off, obd_off *swidth)
 {
         struct lov_extent *le;
 
@@ -362,7 +381,7 @@ lsm_stripe_by_offset_join(struct lov_stripe_md *lsm, int *stripeno,
                 *stripeno -= le->le_loi_idx;
 
         if (swidth)
-                *swidth = (unsigned long)lsm->lsm_stripe_size * le->le_stripe_count;
+                *swidth = (obd_off)lsm->lsm_stripe_size * le->le_stripe_count;
 }
 
 static obd_off
@@ -429,7 +448,8 @@ static int lovea_unpack_array(struct llog_handle *handle,
         /* insert extent desc into lsm extent array  */
         lai->lai_ext_array[cursor].le_start = le64_to_cpu(med->med_start);
         lai->lai_ext_array[cursor].le_len   = le64_to_cpu(med->med_len);
-        lai->lai_ext_array[cursor].le_stripe_count = lmm->lmm_stripe_count;
+        lai->lai_ext_array[cursor].le_stripe_count =
+                                   le32_to_cpu(lmm->lmm_stripe_count);
 
         /* unpack extent's lmm to lov_oinfo array */
         loi_index = lai->lai_ext_array[cursor].le_loi_idx;
@@ -478,7 +498,7 @@ static int lsm_revalidate_join(struct lov_stripe_md *lsm,
         OBD_ALLOC(lsm->lsm_array->lai_ext_array,lsm->lsm_array->lai_ext_count *
                                                 sizeof (struct lov_extent));
         if (!lsm->lsm_array->lai_ext_array)
-                GOTO(release_ctxt, rc = -ENOMEM);        
+                GOTO(release_ctxt, rc = -ENOMEM);
 
         CDEBUG(D_INFO, "get lsm logid: "LPU64":"LPU64"\n",
                lsm->lsm_array->lai_array_id.lgl_oid,
@@ -504,7 +524,7 @@ release_ctxt:
         RETURN(rc);
 }
 
-int lsm_destroy_join(struct lov_stripe_md *lsm, struct obdo *oa, 
+int lsm_destroy_join(struct lov_stripe_md *lsm, struct obdo *oa,
                       struct obd_export *md_exp)
 {
         struct llog_ctxt *ctxt;
@@ -569,8 +589,10 @@ static int lovea_init_array_info(struct lov_stripe_md *lsm,
         if (!lai)
                 RETURN(-ENOMEM);
 
-        lai->lai_array_id = *logid;
-        lai->lai_ext_count = extent_count;
+        lai->lai_array_id.lgl_oid = le64_to_cpu(logid->lgl_oid);
+        lai->lai_array_id.lgl_ogr = le64_to_cpu(logid->lgl_ogr);
+        lai->lai_array_id.lgl_ogen = le32_to_cpu(logid->lgl_ogen);
+        lai->lai_ext_count = le32_to_cpu(extent_count);
         lsm->lsm_array = lai;
         RETURN(0);
 }
@@ -595,7 +617,7 @@ out:
         RETURN(rc);
 }
 
-struct lsm_operations lsm_join_ops = {
+const struct lsm_operations lsm_join_ops = {
         .lsm_free             = lsm_free_join,
         .lsm_destroy          = lsm_destroy_join,
         .lsm_stripe_by_index  = lsm_stripe_by_index_join,
@@ -609,3 +631,77 @@ struct lsm_operations lsm_join_ops = {
 };
 
 
+static int lsm_lmm_verify_v3(struct lov_mds_md *lmmv1, int lmm_bytes,
+                             int *stripe_count)
+{
+        struct lov_mds_md_v3 *lmm;
+
+        lmm = (struct lov_mds_md_v3 *)lmmv1;
+
+        if (lmm_bytes < sizeof(*lmm)) {
+                CERROR("lov_mds_md_v3 too small: %d, need at least %d\n",
+                       lmm_bytes, (int)sizeof(*lmm));
+                return -EINVAL;
+        }
+
+        *stripe_count = le32_to_cpu(lmm->lmm_stripe_count);
+
+        if (lmm_bytes < lov_mds_md_size(*stripe_count, LOV_MAGIC_V3)) {
+                CERROR("LOV EA V3 too small: %d, need %d\n",
+                       lmm_bytes, lov_mds_md_size(*stripe_count, LOV_MAGIC_V3));
+                lov_dump_lmm_v3(D_WARNING, lmm);
+                return -EINVAL;
+        }
+
+        return lsm_lmm_verify_common((struct lov_mds_md_v1 *)lmm, lmm_bytes,
+                                     *stripe_count);
+}
+
+int lsm_unpackmd_v3(struct lov_obd *lov, struct lov_stripe_md *lsm,
+                    struct lov_mds_md *lmmv1)
+{
+        struct lov_mds_md_v3 *lmm;
+        struct lov_oinfo *loi;
+        int i;
+
+        lmm = (struct lov_mds_md_v3 *)lmmv1;
+
+        lsm_unpackmd_common(lsm, (struct lov_mds_md_v1 *)lmm);
+        strncpy(lsm->lsm_pool_name, lmm->lmm_pool_name, LOV_MAXPOOLNAME);
+
+        for (i = 0; i < lsm->lsm_stripe_count; i++) {
+                /* XXX LOV STACKING call down to osc_unpackmd() */
+                loi = lsm->lsm_oinfo[i];
+                loi->loi_id = le64_to_cpu(lmm->lmm_objects[i].l_object_id);
+                loi->loi_gr = le64_to_cpu(lmm->lmm_objects[i].l_object_gr);
+                loi->loi_ost_idx = le32_to_cpu(lmm->lmm_objects[i].l_ost_idx);
+                loi->loi_ost_gen = le32_to_cpu(lmm->lmm_objects[i].l_ost_gen);
+                if (loi->loi_ost_idx >= lov->desc.ld_tgt_count) {
+                        CERROR("OST index %d more than OST count %d\n",
+                               loi->loi_ost_idx, lov->desc.ld_tgt_count);
+                        lov_dump_lmm_v3(D_WARNING, lmm);
+                        return -EINVAL;
+                }
+                if (!lov->lov_tgts[loi->loi_ost_idx]) {
+                        CERROR("OST index %d missing\n", loi->loi_ost_idx);
+                        lov_dump_lmm_v3(D_WARNING, lmm);
+                        return -EINVAL;
+                }
+        }
+
+        return 0;
+}
+
+const struct lsm_operations lsm_v3_ops = {
+        .lsm_free            = lsm_free_plain,
+        .lsm_destroy         = lsm_destroy_plain,
+        .lsm_stripe_by_index    = lsm_stripe_by_index_plain,
+        .lsm_stripe_by_offset   = lsm_stripe_by_offset_plain,
+        .lsm_revalidate         = lsm_revalidate_plain,
+        .lsm_stripe_offset_by_index  = lsm_stripe_offset_by_index_plain,
+        .lsm_stripe_offset_by_offset = lsm_stripe_offset_by_offset_plain,
+        .lsm_stripe_index_by_offset  = lsm_stripe_index_by_offset_plain,
+        .lsm_lmm_verify         = lsm_lmm_verify_v3,
+        .lsm_unpackmd           = lsm_unpackmd_v3,
+};
+