Whamcloud - gitweb
LU-19098 hsm: don't print progname twice with lhsmtool
[fs/lustre-release.git] / lustre / lov / lov_internal.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2
3 /*
4  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
5  * Use is subject to license terms.
6  *
7  * Copyright (c) 2011, 2017, Intel Corporation.
8  */
9
10 /*
11  * This file is part of Lustre, http://www.lustre.org/
12  */
13
14 #ifndef LOV_INTERNAL_H
15 #define LOV_INTERNAL_H
16
17 #include <obd_class.h>
18 #include <uapi/linux/lustre/lustre_user.h>
19
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)
26
27 struct lov_stripe_md_entry {
28         struct lu_extent        lsme_extent;
29         u32                     lsme_id;
30         u32                     lsme_magic;
31         u32                     lsme_flags;
32         u32                     lsme_pattern;
33         u64                     lsme_timestamp;
34         union {
35                 struct { /* For stripe objects */
36                         u32     lsme_stripe_size;
37                         u16     lsme_stripe_count;
38                         u16     lsme_layout_gen;
39                         char    lsme_pool_name[LOV_MAXPOOLNAME + 1];
40                         struct lov_oinfo        *lsme_oinfo[];
41                 };
42                 struct { /* For foreign layout (i.e. HSM, DAOS) */
43                         u32     lsme_length;
44                         u32     lsme_type;
45                         u32     lsme_foreign_flags;
46                         u32     lsme_padding;
47                         union {
48                                 /* inline HSM layout data */
49                                 struct lov_hsm_base      lsme_hsm;
50                                 /* Other kind of foreign layout (i.e. DAOS) */
51                                 char                    *lsme_value;
52                         };
53                 };
54         };
55 };
56
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
60
61 static inline bool lsme_is_dom(struct lov_stripe_md_entry *lsme)
62 {
63         return (lov_pattern(lsme->lsme_pattern) & LOV_PATTERN_MDT);
64 }
65
66 static inline void copy_lsm_entry(struct lov_stripe_md_entry *dst,
67                                   struct lov_stripe_md_entry *src)
68 {
69         unsigned i;
70
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));
74 }
75
76 struct lov_stripe_md {
77         struct kref     lsm_refc;
78         spinlock_t      lsm_lock;
79         pid_t           lsm_lock_owner; /* debugging */
80
81         union {
82                 /* maximum possible file size, might change as OSTs status
83                  * changes, e.g. disconnected, deactivated
84                  */
85                 loff_t          lsm_maxbytes;
86                 /* size of full foreign LOV */
87                 size_t          lsm_foreign_size;
88         };
89         struct ost_id   lsm_oi;
90         u32             lsm_magic;
91         u32             lsm_layout_gen;
92         u16             lsm_flags;
93         bool            lsm_is_released;
94         bool            lsm_is_rdonly;
95         u16             lsm_mirror_count;
96         u16             lsm_entry_count;
97         struct lov_stripe_md_entry *lsm_entries[];
98 };
99
100 #define lsm_foreign(lsm) (lsm->lsm_entries[0])
101
102 static inline bool lsme_is_foreign(const struct lov_stripe_md_entry *lsme)
103 {
104         return lsme->lsme_magic == LOV_MAGIC_FOREIGN;
105 }
106
107 static inline bool lsm_entry_is_foreign(const struct lov_stripe_md *lsm,
108                                         int index)
109 {
110         return lsme_is_foreign(lsm->lsm_entries[index]);
111 }
112
113 static inline bool lsme_inited(const struct lov_stripe_md_entry *lsme)
114 {
115         return lsme->lsme_flags & LCME_FL_INIT;
116 }
117
118 static inline bool lsm_entry_inited(const struct lov_stripe_md *lsm, int index)
119 {
120         return lsme_inited(lsm->lsm_entries[index]);
121 }
122
123 static inline bool lsm_is_composite(__u32 magic)
124 {
125         return magic == LOV_MAGIC_COMP_V1;
126 }
127
128 static inline bool lsm_is_rdonly(const struct lov_stripe_md *lsm)
129 {
130         return lsm->lsm_is_rdonly;
131 }
132
133 static inline size_t lov_comp_md_size(const struct lov_stripe_md *lsm)
134 {
135         struct lov_stripe_md_entry *lsme;
136         size_t size;
137         int entry;
138
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);
142
143         if (lsm->lsm_magic == LOV_MAGIC_FOREIGN)
144                 return lsm->lsm_foreign_size;
145
146         LASSERT(lsm->lsm_magic == LOV_MAGIC_COMP_V1);
147
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++) {
151                 u16 stripe_count;
152
153                 lsme = lsm->lsm_entries[entry];
154
155                 if (lsme->lsme_magic == LOV_MAGIC_FOREIGN) {
156                         size += lov_foreign_md_size(lsme->lsme_length);
157                 } else {
158                         if (lsme_inited(lsme))
159                                 stripe_count = lsme->lsme_stripe_count;
160                         else
161                                 stripe_count = 0;
162
163                         size += lov_mds_md_size(stripe_count, lsme->lsme_magic);
164                 }
165         }
166
167         return size;
168 }
169
170 static inline bool lsm_has_objects(struct lov_stripe_md *lsm)
171 {
172         return lsm != NULL && !lsm->lsm_is_released;
173 }
174
175 static inline unsigned int lov_comp_index(int entry, int stripe)
176 {
177         LASSERT(entry >= 0 && entry <= SHRT_MAX);
178         LASSERT(stripe >= 0 && stripe < USHRT_MAX);
179
180         return entry << 16 | stripe;
181 }
182
183 static inline int lov_comp_stripe(int index)
184 {
185         return index & 0xffff;
186 }
187
188 static inline int lov_comp_entry(int index)
189 {
190         return index >> 16;
191 }
192
193 struct lsm_operations {
194         struct lov_stripe_md *(*lsm_unpackmd)(struct lov_obd *, void *, size_t);
195 };
196
197 const struct lsm_operations *lsm_op_find(int magic);
198 void lsm_free(struct kref *kref);
199
200 static inline bool lov_supported_comp_magic(unsigned int magic)
201 {
202         return magic == LOV_MAGIC_V1 || magic == LOV_MAGIC_V3 ||
203                magic == LOV_MAGIC_FOREIGN;
204 }
205
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)
209
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 */
219 };
220
221 int lov_pool_hash_init(struct rhashtable *tbl);
222 void lov_pool_hash_destroy(struct rhashtable *tbl);
223
224 struct lov_request {
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 */
229 };
230
231 struct lov_request_set {
232         struct obd_info         *set_oi;
233         struct obd_device       *set_obd;
234         int                      set_count;
235         atomic_t                 set_completes;
236         atomic_t                 set_success;
237         struct list_head         set_list;
238 };
239
240 extern struct kmem_cache *lov_oinfo_slab;
241
242 extern struct lu_kmem_descr lov_caches[];
243
244 static inline struct lu_tgt_desc *lov_tgt(struct lov_obd *lov, u32 index)
245 {
246         return index < lov->lov_ost_descs.ltd_tgts_size ?
247                 LTD_TGT(&lov->lov_ost_descs, index) : NULL;
248 }
249
250 #define lov_uuid2str(lv, index) \
251         (char *)(lov_tgt(lv, index)->ltd_uuid.uuid)
252
253 #define lov_foreach_tgt(lov, tgt) \
254         ltd_foreach_tgt(&(lov)->lov_ost_descs, tgt)
255
256 /* lov_merge.c */
257 int lov_merge_lvb_kms(struct lov_stripe_md *lsm, int index,
258                       struct cl_attr *attr);
259
260 /* lov_offset.c */
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,
267                           int stripeno);
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);
273
274 /* lov_request.c */
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);
278
279 /* lov_obd.c */
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,
290                            __u16 stripe_count);
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);
299
300 /* lov_pack.c */
301 ssize_t lov_lsm_pack(const struct lov_stripe_md *lsm, void *buf,
302                      size_t buf_size);
303 struct lov_stripe_md *lov_unpackmd(struct lov_obd *lov, void *buf,
304                                    size_t buf_size);
305 void lov_free_memmd(struct lov_stripe_md **lsmp);
306
307 void lov_dump_lmm_v1(int level, struct lov_mds_md_v1 *lmm);
308 void lov_dump_lmm_common(int level, void *lmmp);
309
310 /* lov_ea.c */
311 void lsm_free_plain(struct lov_stripe_md *lsm);
312 void dump_lsm(unsigned int level, const struct lov_stripe_md *lsm);
313
314 /* lproc_lov.c */
315 int lov_tunables_init(struct obd_device *obd);
316
317 /* lov_cl.c */
318 extern struct lu_device_type lov_device_type;
319
320 #define LOV_MDC_TGT_MAX 256
321
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);
327
328 static inline struct lov_stripe_md *lsm_addref(struct lov_stripe_md *lsm)
329 {
330         kref_get(&lsm->lsm_refc);
331         return lsm;
332 }
333
334 static inline bool lov_oinfo_is_dummy(const struct lov_oinfo *loi)
335 {
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))
340                 return true;
341
342         return false;
343 }
344
345 static inline struct obd_device *lov2obd(const struct lov_obd *lov)
346 {
347         return container_of_safe(lov, struct obd_device, u.lov);
348 }
349
350 static inline void lov_lsm2layout(struct lov_stripe_md *lsm,
351                                   struct lov_stripe_md_entry *lsme,
352                                   struct ost_layout *ol)
353 {
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;
360         } else {
361                 ol->ol_comp_start = 0;
362                 ol->ol_comp_end = 0;
363                 ol->ol_comp_id = 0;
364         }
365 }
366
367 struct lov_pool_desc *lov_pool_find(struct obd_device *obd, char *poolname);
368 void lov_pool_putref(struct lov_pool_desc *pool);
369 #endif