Whamcloud - gitweb
LU-2430 mdd: add lfs mv to migrate inode.
[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         char    lsm_md_pool_name[LOV_MAXPOOLNAME];
52         struct lmv_oinfo lsm_md_oinfo[0];
53 };
54
55 union lmv_mds_md;
56
57 int lmv_pack_md(union lmv_mds_md **lmmp, const struct lmv_stripe_md *lsm,
58                        int stripe_count);
59 int lmv_alloc_md(union lmv_mds_md **lmmp, int stripe_count);
60 void lmv_free_md(union lmv_mds_md *lmm);
61 int lmv_alloc_memmd(struct lmv_stripe_md **lsmp, int stripe_count);
62 void lmv_free_memmd(struct lmv_stripe_md *lsm);
63
64 static inline void lmv1_cpu_to_le(struct lmv_mds_md_v1 *lmv_dst,
65                                   const struct lmv_mds_md_v1 *lmv_src)
66 {
67         int i;
68
69         lmv_dst->lmv_magic = cpu_to_le32(lmv_src->lmv_magic);
70         lmv_dst->lmv_stripe_count = cpu_to_le32(lmv_src->lmv_stripe_count);
71         lmv_dst->lmv_master_mdt_index =
72                         cpu_to_le32(lmv_src->lmv_master_mdt_index);
73         lmv_dst->lmv_hash_type = cpu_to_le32(lmv_src->lmv_hash_type);
74         lmv_dst->lmv_layout_version = cpu_to_le32(lmv_src->lmv_layout_version);
75         for (i = 0; i < lmv_src->lmv_stripe_count; i++)
76                 fid_cpu_to_le(&lmv_dst->lmv_stripe_fids[i],
77                               &lmv_src->lmv_stripe_fids[i]);
78 }
79
80 static inline void lmv1_le_to_cpu(struct lmv_mds_md_v1 *lmv_dst,
81                                   const struct lmv_mds_md_v1 *lmv_src)
82 {
83         int i;
84
85         lmv_dst->lmv_magic = le32_to_cpu(lmv_src->lmv_magic);
86         lmv_dst->lmv_stripe_count = le32_to_cpu(lmv_src->lmv_stripe_count);
87         lmv_dst->lmv_master_mdt_index =
88                                 le32_to_cpu(lmv_src->lmv_master_mdt_index);
89         lmv_dst->lmv_hash_type = le32_to_cpu(lmv_src->lmv_hash_type);
90         lmv_dst->lmv_layout_version = le32_to_cpu(lmv_src->lmv_layout_version);
91         for (i = 0; i < lmv_src->lmv_stripe_count; i++)
92                 fid_le_to_cpu(&lmv_dst->lmv_stripe_fids[i],
93                               &lmv_src->lmv_stripe_fids[i]);
94 }
95
96 static inline void lmv_cpu_to_le(union lmv_mds_md *lmv_dst,
97                                  const union lmv_mds_md *lmv_src)
98 {
99         switch (lmv_src->lmv_magic) {
100         case LMV_MAGIC_V1:
101         case LMV_MAGIC_MIGRATE: {
102                 lmv1_cpu_to_le(&lmv_dst->lmv_md_v1, &lmv_src->lmv_md_v1);
103                 break;
104         }
105         default:
106                 break;
107         }
108 }
109
110 static inline void lmv_le_to_cpu(union lmv_mds_md *lmv_dst,
111                                  const union lmv_mds_md *lmv_src)
112 {
113         switch (le32_to_cpu(lmv_src->lmv_magic)) {
114         case LMV_MAGIC_V1:
115         case LMV_MAGIC_MIGRATE: {
116                 lmv1_le_to_cpu(&lmv_dst->lmv_md_v1, &lmv_src->lmv_md_v1);
117                 break;
118         }
119         default:
120                 break;
121         }
122 }
123
124 #endif