4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 021110-1307, USA
24 * Copyright (c) 2012, Intel Corporation.
25 * Use is subject to license terms.
27 * Author: Johann Lombardi <johann.lombardi@intel.com>
30 #include <lustre/lustre_idl.h>
32 #include <md_object.h>
35 * Initialize new \a lma. Only fid is stored.
37 * \param lma - is the new LMA structure to be initialized
38 * \param fid - is the FID of the object this LMA belongs to
39 * \param incompat - features that MDS must understand to access object
41 void lustre_lma_init(struct lustre_mdt_attrs *lma, const struct lu_fid *fid,
45 lma->lma_incompat = incompat;
46 lma->lma_self_fid = *fid;
49 /* If a field is added in struct lustre_mdt_attrs, zero it explicitly
50 * and change the test below. */
51 LASSERT(sizeof(*lma) ==
52 (offsetof(struct lustre_mdt_attrs, lma_flags) +
53 sizeof(lma->lma_flags)));
55 EXPORT_SYMBOL(lustre_lma_init);
58 * Swab, if needed, LMA structure which is stored on-disk in little-endian order.
60 * \param lma - is a pointer to the LMA structure to be swabbed.
62 void lustre_lma_swab(struct lustre_mdt_attrs *lma)
64 /* Use LUSTRE_MSG_MAGIC to detect local endianess. */
65 if (LUSTRE_MSG_MAGIC != cpu_to_le32(LUSTRE_MSG_MAGIC)) {
66 __swab32s(&lma->lma_compat);
67 __swab32s(&lma->lma_incompat);
68 lustre_swab_lu_fid(&lma->lma_self_fid);
69 __swab64s(&lma->lma_flags);
72 EXPORT_SYMBOL(lustre_lma_swab);
75 * Swab, if needed, SOM structure which is stored on-disk in little-endian
78 * \param attrs - is a pointer to the SOM structure to be swabbed.
80 void lustre_som_swab(struct som_attrs *attrs)
82 /* Use LUSTRE_MSG_MAGIC to detect local endianess. */
83 if (LUSTRE_MSG_MAGIC != cpu_to_le32(LUSTRE_MSG_MAGIC)) {
84 __swab32s(&attrs->som_compat);
85 __swab32s(&attrs->som_incompat);
86 __swab64s(&attrs->som_ioepoch);
87 __swab64s(&attrs->som_size);
88 __swab64s(&attrs->som_blocks);
89 __swab64s(&attrs->som_mountid);
92 EXPORT_SYMBOL(lustre_som_swab);
95 * Swab and extract SOM attributes from on-disk xattr.
97 * \param buf - is a buffer containing the on-disk SOM extended attribute.
98 * \param rc - is the SOM xattr stored in \a buf
99 * \param msd - is the md_som_data structure where to extract SOM attributes.
101 int lustre_buf2som(void *buf, int rc, struct md_som_data *msd)
103 struct som_attrs *attrs = (struct som_attrs *)buf;
106 if (rc == 0 || rc == -ENODATA)
107 /* no SOM attributes */
111 /* error hit while fetching xattr */
114 /* check SOM compatibility */
115 if (attrs->som_incompat & ~cpu_to_le32(SOM_INCOMPAT_SUPP))
118 /* unpack SOM attributes */
119 lustre_som_swab(attrs);
121 /* fill in-memory msd structure */
122 msd->msd_compat = attrs->som_compat;
123 msd->msd_incompat = attrs->som_incompat;
124 msd->msd_ioepoch = attrs->som_ioepoch;
125 msd->msd_size = attrs->som_size;
126 msd->msd_blocks = attrs->som_blocks;
127 msd->msd_mountid = attrs->som_mountid;
131 EXPORT_SYMBOL(lustre_buf2som);
134 * Swab, if needed, HSM structure which is stored on-disk in little-endian
137 * \param attrs - is a pointer to the HSM structure to be swabbed.
139 void lustre_hsm_swab(struct hsm_attrs *attrs)
141 /* Use LUSTRE_MSG_MAGIC to detect local endianess. */
142 if (LUSTRE_MSG_MAGIC != cpu_to_le32(LUSTRE_MSG_MAGIC)) {
143 __swab32s(&attrs->hsm_compat);
144 __swab32s(&attrs->hsm_flags);
145 __swab64s(&attrs->hsm_arch_id);
146 __swab64s(&attrs->hsm_arch_ver);
149 EXPORT_SYMBOL(lustre_hsm_swab);
152 * Swab and extract HSM attributes from on-disk xattr.
154 * \param buf - is a buffer containing the on-disk HSM extended attribute.
155 * \param rc - is the HSM xattr stored in \a buf
156 * \param mh - is the md_hsm structure where to extract HSM attributes.
158 int lustre_buf2hsm(void *buf, int rc, struct md_hsm *mh)
160 struct hsm_attrs *attrs = (struct hsm_attrs *)buf;
163 if (rc == 0 || rc == -ENODATA)
164 /* no HSM attributes */
168 /* error hit while fetching xattr */
171 /* unpack HSM attributes */
172 lustre_hsm_swab(attrs);
174 /* fill md_hsm structure */
175 mh->mh_compat = attrs->hsm_compat;
176 mh->mh_flags = attrs->hsm_flags;
177 mh->mh_arch_id = attrs->hsm_arch_id;
178 mh->mh_arch_ver = attrs->hsm_arch_ver;
182 EXPORT_SYMBOL(lustre_buf2hsm);
185 * Pack HSM attributes.
187 * \param buf - is the output buffer where to pack the on-disk HSM xattr.
188 * \param mh - is the md_hsm structure to pack.
190 void lustre_hsm2buf(void *buf, struct md_hsm *mh)
192 struct hsm_attrs *attrs = (struct hsm_attrs *)buf;
195 /* copy HSM attributes */
196 attrs->hsm_compat = mh->mh_compat;
197 attrs->hsm_flags = mh->mh_flags;
198 attrs->hsm_arch_id = mh->mh_arch_id;
199 attrs->hsm_arch_ver = mh->mh_arch_ver;
202 lustre_hsm_swab(attrs);
204 EXPORT_SYMBOL(lustre_hsm2buf);