Whamcloud - gitweb
d65b6bd975c33852852373460a32a1e93625881c
[fs/lustre-release.git] / lustre / include / lustre_lmv.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License version 2 for more details.  A copy is
14  * included in the COPYING file that accompanied this code.
15
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2013, Intel Corporation.
24  */
25 /*
26  * lustre/include/lustre_lmv.h
27  *
28  * Lustre LMV structures and functions.
29  *
30  * Author: Di Wang <di.wang@intel.com>
31  */
32
33 #ifndef _LUSTRE_LMV_H
34 #define _LUSTRE_LMV_H
35 #include <lustre/lustre_idl.h>
36
37 struct lmv_oinfo {
38         struct lu_fid   lmo_fid;
39         mdsno_t         lmo_mds;
40         struct inode    *lmo_root;
41 };
42
43 struct lmv_stripe_md {
44         __u32   lsm_md_magic;
45         __u32   lsm_md_stripe_count;
46         __u32   lsm_md_master_mdt_index;
47         __u32   lsm_md_hash_type;
48         __u32   lsm_md_layout_version;
49         __u32   lsm_md_default_count;
50         __u32   lsm_md_default_index;
51         struct lu_fid   lsm_md_master_fid;
52         char    lsm_md_pool_name[LOV_MAXPOOLNAME];
53         struct lmv_oinfo lsm_md_oinfo[0];
54 };
55
56 static inline bool
57 lsm_md_eq(const struct lmv_stripe_md *lsm1, const struct lmv_stripe_md *lsm2)
58 {
59         int idx;
60
61         if (lsm1->lsm_md_magic != lsm2->lsm_md_magic ||
62             lsm1->lsm_md_stripe_count != lsm2->lsm_md_stripe_count ||
63             lsm1->lsm_md_master_mdt_index !=
64                                 lsm2->lsm_md_master_mdt_index ||
65             lsm1->lsm_md_hash_type != lsm2->lsm_md_hash_type ||
66             lsm1->lsm_md_layout_version !=
67                                 lsm2->lsm_md_layout_version ||
68             strcmp(lsm1->lsm_md_pool_name,
69                       lsm2->lsm_md_pool_name) != 0)
70                 return false;
71
72         for (idx = 0; idx < lsm1->lsm_md_stripe_count; idx++) {
73                 if (!lu_fid_eq(&lsm1->lsm_md_oinfo[idx].lmo_fid,
74                                &lsm2->lsm_md_oinfo[idx].lmo_fid))
75                         return false;
76         }
77
78         return true;
79 }
80 union lmv_mds_md;
81
82 int lmv_pack_md(union lmv_mds_md **lmmp, const struct lmv_stripe_md *lsm,
83                        int stripe_count);
84 int lmv_alloc_md(union lmv_mds_md **lmmp, int stripe_count);
85 void lmv_free_md(union lmv_mds_md *lmm);
86 int lmv_alloc_memmd(struct lmv_stripe_md **lsmp, int stripe_count);
87 void lmv_free_memmd(struct lmv_stripe_md *lsm);
88
89 static inline void lmv1_cpu_to_le(struct lmv_mds_md_v1 *lmv_dst,
90                                   const struct lmv_mds_md_v1 *lmv_src)
91 {
92         int i;
93
94         lmv_dst->lmv_magic = cpu_to_le32(lmv_src->lmv_magic);
95         lmv_dst->lmv_stripe_count = cpu_to_le32(lmv_src->lmv_stripe_count);
96         lmv_dst->lmv_master_mdt_index =
97                         cpu_to_le32(lmv_src->lmv_master_mdt_index);
98         lmv_dst->lmv_hash_type = cpu_to_le32(lmv_src->lmv_hash_type);
99         lmv_dst->lmv_layout_version = cpu_to_le32(lmv_src->lmv_layout_version);
100         for (i = 0; i < lmv_src->lmv_stripe_count; i++)
101                 fid_cpu_to_le(&lmv_dst->lmv_stripe_fids[i],
102                               &lmv_src->lmv_stripe_fids[i]);
103 }
104
105 static inline void lmv1_le_to_cpu(struct lmv_mds_md_v1 *lmv_dst,
106                                   const struct lmv_mds_md_v1 *lmv_src)
107 {
108         int i;
109
110         lmv_dst->lmv_magic = le32_to_cpu(lmv_src->lmv_magic);
111         lmv_dst->lmv_stripe_count = le32_to_cpu(lmv_src->lmv_stripe_count);
112         lmv_dst->lmv_master_mdt_index =
113                                 le32_to_cpu(lmv_src->lmv_master_mdt_index);
114         lmv_dst->lmv_hash_type = le32_to_cpu(lmv_src->lmv_hash_type);
115         lmv_dst->lmv_layout_version = le32_to_cpu(lmv_src->lmv_layout_version);
116         for (i = 0; i < lmv_src->lmv_stripe_count; i++)
117                 fid_le_to_cpu(&lmv_dst->lmv_stripe_fids[i],
118                               &lmv_src->lmv_stripe_fids[i]);
119 }
120
121 static inline void lmv_cpu_to_le(union lmv_mds_md *lmv_dst,
122                                  const union lmv_mds_md *lmv_src)
123 {
124         switch (lmv_src->lmv_magic) {
125         case LMV_MAGIC_V1:
126                 lmv1_cpu_to_le(&lmv_dst->lmv_md_v1, &lmv_src->lmv_md_v1);
127                 break;
128         default:
129                 break;
130         }
131 }
132
133 static inline void lmv_le_to_cpu(union lmv_mds_md *lmv_dst,
134                                  const union lmv_mds_md *lmv_src)
135 {
136         switch (le32_to_cpu(lmv_src->lmv_magic)) {
137         case LMV_MAGIC_V1:
138                 lmv1_le_to_cpu(&lmv_dst->lmv_md_v1, &lmv_src->lmv_md_v1);
139                 break;
140         default:
141                 break;
142         }
143 }
144
145 #endif