Whamcloud - gitweb
LU-1214 ldlm: splits server specific lock handling from client
[fs/lustre-release.git] / lustre / include / obd_lov.h
index da3ca51..859beb5 100644 (file)
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2012, Whamcloud, Inc.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 #ifndef _OBD_LOV_H__
 #define _OBD_LOV_H__
 
-static inline int lov_stripe_md_size(int stripes)
+static inline int lov_stripe_md_size(__u16 stripes)
 {
         return sizeof(struct lov_stripe_md) + stripes*sizeof(struct lov_oinfo*);
 }
 
-static inline int lov_mds_md_size(int stripes, int lmm_magic)
+static inline __u32 lov_mds_md_size(__u16 stripes, __u32 lmm_magic)
 {
         if (lmm_magic == LOV_MAGIC_V3)
                 return sizeof(struct lov_mds_md_v3) +
@@ -52,6 +54,35 @@ static inline int lov_mds_md_size(int stripes, int lmm_magic)
                         stripes * sizeof(struct lov_ost_data_v1);
 }
 
+struct lov_version_size {
+        __u32   lvs_magic;
+        size_t  lvs_lmm_size;
+        size_t  lvs_lod_size;
+};
+
+static inline __u32 lov_mds_md_stripecnt(int ea_size, __u32 lmm_magic)
+{
+        static const struct lov_version_size lmm_ver_size[] = {
+                        { .lvs_magic = LOV_MAGIC_V3,
+                          .lvs_lmm_size = sizeof(struct lov_mds_md_v3),
+                          .lvs_lod_size = sizeof(struct lov_ost_data_v1) },
+                        { .lvs_magic = LOV_MAGIC_V1,
+                          .lvs_lmm_size = sizeof(struct lov_mds_md_v1),
+                          .lvs_lod_size = sizeof(struct lov_ost_data_v1)} };
+        int i;
+
+        for (i = 0; i < ARRAY_SIZE(lmm_ver_size); i++) {
+                if (lmm_magic == lmm_ver_size[i].lvs_magic) {
+                        if (ea_size <= lmm_ver_size[i].lvs_lmm_size)
+                                return 0;
+                        return (ea_size - lmm_ver_size[i].lvs_lmm_size) /
+                                lmm_ver_size[i].lvs_lod_size;
+                }
+        }
+
+        /* Invalid LOV magic, so no stripes could fit */
+        return 0;
+}
 
 #define IOC_LOV_TYPE                   'g'
 #define IOC_LOV_MIN_NR                 50