1 /* SPDX-License-Identifier: GPL-2.0 */
4 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
5 * Use is subject to license terms.
7 * Copyright (c) 2011, 2017, Intel Corporation.
11 * This file is part of Lustre, http://www.lustre.org/
14 #ifndef LOV_INTERNAL_H
15 #define LOV_INTERNAL_H
17 #include <obd_class.h>
18 #include <uapi/linux/lustre/lustre_user.h>
20 /* If we are unable to get the maximum object size from the OST in
21 * ocd_maxbytes using OBD_CONNECT_MAXBYTES or LSM component don't init,
22 * then we fall back to using the maximum object size from ldiskfs.
23 * Once indirect's blocks don't supported for ost now, ldiskfs
24 * extent limit used */
25 #define LUSTRE_EXT4_STRIPE_MAXBYTES (((1ULL << 32) - 1) << 12)
27 struct lov_stripe_md_entry {
28 struct lu_extent lsme_extent;
35 struct { /* For stripe objects */
37 u16 lsme_stripe_count;
39 char lsme_pool_name[LOV_MAXPOOLNAME + 1];
40 struct lov_oinfo *lsme_oinfo[];
42 struct { /* For foreign layout (i.e. HSM, DAOS) */
45 u32 lsme_foreign_flags;
48 /* inline HSM layout data */
49 struct lov_hsm_base lsme_hsm;
50 /* Other kind of foreign layout (i.e. DAOS) */
57 #define lsme_archive_id lsme_hsm.lhb_archive_id
58 #define lsme_archive_ver lsme_hsm.lhb_archive_ver
59 #define lsme_uuid lsme_hsm.lhb_uuid
61 static inline bool lsme_is_dom(struct lov_stripe_md_entry *lsme)
63 return (lov_pattern(lsme->lsme_pattern) & LOV_PATTERN_MDT);
66 static inline void copy_lsm_entry(struct lov_stripe_md_entry *dst,
67 struct lov_stripe_md_entry *src)
71 for (i = 0; i < src->lsme_stripe_count; i++)
72 *dst->lsme_oinfo[i] = *src->lsme_oinfo[i];
73 memcpy(dst, src, offsetof(typeof(*src), lsme_oinfo));
76 struct lov_stripe_md {
79 pid_t lsm_lock_owner; /* debugging */
82 /* maximum possible file size, might change as OSTs status
83 * changes, e.g. disconnected, deactivated
86 /* size of full foreign LOV */
87 size_t lsm_foreign_size;
97 struct lov_stripe_md_entry *lsm_entries[];
100 #define lsm_foreign(lsm) (lsm->lsm_entries[0])
102 static inline bool lsme_is_foreign(const struct lov_stripe_md_entry *lsme)
104 return lsme->lsme_magic == LOV_MAGIC_FOREIGN;
107 static inline bool lsm_entry_is_foreign(const struct lov_stripe_md *lsm,
110 return lsme_is_foreign(lsm->lsm_entries[index]);
113 static inline bool lsme_inited(const struct lov_stripe_md_entry *lsme)
115 return lsme->lsme_flags & LCME_FL_INIT;
118 static inline bool lsm_entry_inited(const struct lov_stripe_md *lsm, int index)
120 return lsme_inited(lsm->lsm_entries[index]);
123 static inline bool lsm_is_composite(__u32 magic)
125 return magic == LOV_MAGIC_COMP_V1;
128 static inline bool lsm_is_rdonly(const struct lov_stripe_md *lsm)
130 return lsm->lsm_is_rdonly;
133 static inline size_t lov_comp_md_size(const struct lov_stripe_md *lsm)
135 struct lov_stripe_md_entry *lsme;
139 if (lsm->lsm_magic == LOV_MAGIC_V1 || lsm->lsm_magic == LOV_MAGIC_V3)
140 return lov_mds_md_size(lsm->lsm_entries[0]->lsme_stripe_count,
141 lsm->lsm_entries[0]->lsme_magic);
143 if (lsm->lsm_magic == LOV_MAGIC_FOREIGN)
144 return lsm->lsm_foreign_size;
146 LASSERT(lsm->lsm_magic == LOV_MAGIC_COMP_V1);
148 size = sizeof(struct lov_comp_md_v1) +
149 sizeof(struct lov_comp_md_entry_v1) * lsm->lsm_entry_count;
150 for (entry = 0; entry < lsm->lsm_entry_count; entry++) {
153 lsme = lsm->lsm_entries[entry];
155 if (lsme->lsme_magic == LOV_MAGIC_FOREIGN) {
156 size += lov_foreign_md_size(lsme->lsme_length);
158 if (lsme_inited(lsme))
159 stripe_count = lsme->lsme_stripe_count;
163 size += lov_mds_md_size(stripe_count, lsme->lsme_magic);
170 static inline bool lsm_has_objects(struct lov_stripe_md *lsm)
172 return lsm != NULL && !lsm->lsm_is_released;
175 static inline unsigned int lov_comp_index(int entry, int stripe)
177 LASSERT(entry >= 0 && entry <= SHRT_MAX);
178 LASSERT(stripe >= 0 && stripe < USHRT_MAX);
180 return entry << 16 | stripe;
183 static inline int lov_comp_stripe(int index)
185 return index & 0xffff;
188 static inline int lov_comp_entry(int index)
193 struct lsm_operations {
194 struct lov_stripe_md *(*lsm_unpackmd)(struct lov_obd *, void *, size_t);
197 const struct lsm_operations *lsm_op_find(int magic);
198 void lsm_free(struct kref *kref);
200 static inline bool lov_supported_comp_magic(unsigned int magic)
202 return magic == LOV_MAGIC_V1 || magic == LOV_MAGIC_V3 ||
203 magic == LOV_MAGIC_FOREIGN;
206 #define pool_tgt_count(p) ((p)->pool_obds.op_count)
207 #define pool_tgt_array(p) ((p)->pool_obds.op_array)
208 #define pool_tgt_rw_sem(p) ((p)->pool_obds.op_rw_sem)
210 struct lov_pool_desc {
211 char pool_name[LOV_MAXPOOLNAME + 1];
212 struct lu_tgt_pool pool_obds;
213 struct kref pool_refcount;
214 struct rhash_head pool_hash; /* access by poolname */
215 struct list_head pool_list; /* serial access */
216 struct rcu_head pool_rcu;
217 struct proc_dir_entry *pool_proc_entry;
218 struct obd_device *pool_lobd; /* owner */
221 int lov_pool_hash_init(struct rhashtable *tbl);
222 void lov_pool_hash_destroy(struct rhashtable *tbl);
225 struct obd_info rq_oi;
226 struct lov_request_set *rq_rqset;
227 struct list_head rq_link;
228 int rq_idx; /* index in lov->tgts array */
231 struct lov_request_set {
232 struct obd_info *set_oi;
233 struct obd_device *set_obd;
235 atomic_t set_completes;
236 atomic_t set_success;
237 struct list_head set_list;
240 extern struct kmem_cache *lov_oinfo_slab;
242 extern struct lu_kmem_descr lov_caches[];
244 static inline struct lu_tgt_desc *lov_tgt(struct lov_obd *lov, u32 index)
246 return index < lov->lov_ost_descs.ltd_tgts_size ?
247 LTD_TGT(&lov->lov_ost_descs, index) : NULL;
250 #define lov_uuid2str(lv, index) \
251 (char *)(lov_tgt(lv, index)->ltd_uuid.uuid)
253 #define lov_foreach_tgt(lov, tgt) \
254 ltd_foreach_tgt(&(lov)->lov_ost_descs, tgt)
257 int lov_merge_lvb_kms(struct lov_stripe_md *lsm, int index,
258 struct cl_attr *attr);
261 u64 stripe_width(struct lov_stripe_md *lsm, unsigned int index);
262 u64 lov_stripe_size(struct lov_stripe_md *lsm, int index,
263 u64 ost_size, int stripeno);
264 int lov_stripe_offset(struct lov_stripe_md *lsm, int index, loff_t lov_off,
265 int stripeno, loff_t *obd_off);
266 loff_t lov_size_to_stripe(struct lov_stripe_md *lsm, int index, u64 file_size,
268 int lov_stripe_intersects(struct lov_stripe_md *lsm, int index, int stripeno,
269 struct lu_extent *ext, u64 *obd_start, u64 *obd_end);
270 int lov_stripe_number(struct lov_stripe_md *lsm, int index, u64 lov_off);
271 pgoff_t lov_stripe_pgoff(struct lov_stripe_md *lsm, int index,
272 pgoff_t stripe_index, int stripe);
275 int lov_prep_statfs_set(struct obd_device *obd, struct obd_info *oinfo,
276 struct lov_request_set **reqset);
277 int lov_fini_statfs_set(struct lov_request_set *set);
280 void lov_tgts_getref(struct obd_device *obd);
281 void lov_tgts_putref(struct obd_device *obd);
282 void lov_stripe_lock(struct lov_stripe_md *md);
283 void lov_stripe_unlock(struct lov_stripe_md *md);
284 void lov_fix_desc(struct lov_desc *desc);
285 void lov_fix_desc_stripe_size(__u64 *val);
286 void lov_fix_desc_stripe_count(__u32 *val);
287 void lov_fix_desc_pattern(__u32 *val);
288 void lov_fix_desc_qos_maxage(__u32 *val);
289 __u16 lov_get_stripe_count(struct lov_obd *lov, __u32 magic,
291 int lov_connect_obd(struct obd_device *obd, u32 index, int activate,
292 struct obd_connect_data *data);
293 int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
294 int lov_cleanup(struct obd_device *obd);
295 int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg,
296 u32 *indexp, int *genp);
297 int lov_del_target(struct obd_device *obd, u32 index,
298 struct obd_uuid *uuidp, int gen);
301 ssize_t lov_lsm_pack(const struct lov_stripe_md *lsm, void *buf,
303 struct lov_stripe_md *lov_unpackmd(struct lov_obd *lov, void *buf,
305 void lov_free_memmd(struct lov_stripe_md **lsmp);
307 void lov_dump_lmm_v1(int level, struct lov_mds_md_v1 *lmm);
308 void lov_dump_lmm_common(int level, void *lmmp);
311 void lsm_free_plain(struct lov_stripe_md *lsm);
312 void dump_lsm(unsigned int level, const struct lov_stripe_md *lsm);
315 int lov_tunables_init(struct obd_device *obd);
318 extern struct lu_device_type lov_device_type;
320 #define LOV_MDC_TGT_MAX 256
322 /* high level pool methods */
323 int lov_pool_new(struct obd_device *obd, char *poolname);
324 int lov_pool_del(struct obd_device *obd, char *poolname);
325 int lov_pool_add(struct obd_device *obd, char *poolname, char *ostname);
326 int lov_pool_remove(struct obd_device *obd, char *poolname, char *ostname);
328 static inline struct lov_stripe_md *lsm_addref(struct lov_stripe_md *lsm)
330 kref_get(&lsm->lsm_refc);
334 static inline bool lov_oinfo_is_dummy(const struct lov_oinfo *loi)
336 if (unlikely(loi->loi_oi.oi.oi_id == 0 &&
337 loi->loi_oi.oi.oi_seq == 0 &&
338 loi->loi_ost_idx == 0 &&
339 loi->loi_ost_gen == 0))
345 static inline struct obd_device *lov2obd(const struct lov_obd *lov)
347 return container_of_safe(lov, struct obd_device, u.lov);
350 static inline void lov_lsm2layout(struct lov_stripe_md *lsm,
351 struct lov_stripe_md_entry *lsme,
352 struct ost_layout *ol)
354 ol->ol_stripe_size = lsme->lsme_stripe_size;
355 ol->ol_stripe_count = lsme->lsme_stripe_count;
356 if (lsm->lsm_magic == LOV_MAGIC_COMP_V1) {
357 ol->ol_comp_start = lsme->lsme_extent.e_start;
358 ol->ol_comp_end = lsme->lsme_extent.e_end;
359 ol->ol_comp_id = lsme->lsme_id;
361 ol->ol_comp_start = 0;
367 struct lov_pool_desc *lov_pool_find(struct obd_device *obd, char *poolname);
368 void lov_pool_putref(struct lov_pool_desc *pool);