Whamcloud - gitweb
LU-17000 utils: handle_yaml_no_op() has wrong signature
[fs/lustre-release.git] / lustre / lod / lod_internal.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2
3 /*
4  * Copyright  2009 Sun Microsystems, Inc. All rights reserved
5  * Use is subject to license terms.
6  *
7  * Copyright (c) 2012, 2017, Intel Corporation.
8  */
9
10 /*
11  * This file is part of Lustre, http://www.lustre.org/
12  *
13  * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
14  * Author: Mikhail Pershin <mike.pershin@intel.com>
15  */
16
17 #ifndef _LOD_INTERNAL_H
18 #define _LOD_INTERNAL_H
19
20 #include <libcfs/libcfs.h>
21 #include <uapi/linux/lustre/lustre_cfg.h>
22 #include <obd.h>
23 #include <dt_object.h>
24
25 enum lod_uses_hint {
26         LOD_USES_ASSIGNED_STRIPE = 0,
27         LOD_USES_DEFAULT_STRIPE,
28 };
29
30 /* Special values to remove LOV EA from disk */
31 #define LOVEA_DELETE_VALUES(size, count, offset, pool)                  \
32         ((size) == 0 && (count) == 0 &&                                 \
33          (offset) == (typeof(offset))(-1) && (pool) == NULL)
34
35 #define LMVEA_DELETE_VALUES(count, offset)                              \
36         ((count) == 0 && (offset) == (typeof(offset))(-1))
37
38 struct lod_pool_desc {
39         char                     pool_name[LOV_MAXPOOLNAME + 1];
40         struct lu_tgt_pool       pool_obds;     /* pool members */
41         struct kref              pool_refcount;
42         struct lu_qos_rr         pool_rr;
43         struct rhash_head        pool_hash;     /* access by poolname */
44         struct list_head         pool_list;
45         struct rcu_head          pool_rcu;
46         struct proc_dir_entry   *pool_proc_entry;
47         struct obd_device       *pool_lobd;     /* owner */
48         time64_t                 pool_spill_expire;
49         struct proc_dir_entry   *pool_spill_proc_entry;
50         bool                     pool_spill_is_active;
51         unsigned int             pool_spill_threshold_pct;
52         atomic_t                 pool_spill_hit;
53         char                     pool_spill_target[LOV_MAXPOOLNAME + 1];
54         bool                     pool_same_space; /* targets in pool balanced*/
55         time64_t                 pool_same_space_expire; /*uses ld_qos_maxage*/
56         struct dentry           *pool_debugfs;
57 };
58
59 struct lod_device;
60 int lod_pool_hash_init(struct rhashtable *tbl);
61 void lod_pool_hash_destroy(struct rhashtable *tbl);
62 bool lod_pool_exists(struct lod_device *lod, char *poolname);
63
64 #define pool_tgt_count(p) ((p)->pool_obds.op_count)
65 #define pool_tgt_array(p)  ((p)->pool_obds.op_array)
66 #define pool_tgt_rw_sem(p) ((p)->pool_obds.op_rw_sem)
67
68 #define lod_tgt_desc    lu_tgt_desc
69 #define lod_tgt_descs   lu_tgt_descs
70
71 #define OST_TGT(lod, index)   LTD_TGT(&lod->lod_ost_descs, index)
72 #define MDT_TGT(lod, index)   LTD_TGT(&lod->lod_mdt_descs, index)
73
74 struct lod_avoid_guide {
75         /* ids of OSSs avoid guidance */
76         __u32                   *lag_oss_avoid_array;
77         /* number of filled array items */
78         unsigned int            lag_oaa_count;
79         /* number of allocated array items */
80         unsigned int            lag_oaa_size;
81         /* bitmap of OSTs avoid guidance */
82         unsigned long           *lag_ost_avoid_bitmap;
83         u32                     lag_ost_avoid_size;
84         /* how many OSTs are available for alloc */
85         __u32                   lag_ost_avail;
86 };
87
88 #define LOD_DOM_MIN_SIZE_KB (LOV_MIN_STRIPE_SIZE >> 10)
89 #define LOD_DOM_SFS_MAX_AGE 10
90
91 struct lod_device {
92         struct dt_device      lod_dt_dev;
93         struct obd_export    *lod_child_exp;
94         struct dt_device     *lod_child;
95         struct lprocfs_stats *lod_stats;
96         spinlock_t            lod_connects_lock;
97         int                   lod_connects;
98         unsigned int          lod_recovery_completed:1,
99                               lod_initialized:1,
100                               lod_lmv_failout:1,
101                               lod_child_got_update_log:1,
102                               lod_dist_txn_check_space:1;
103
104         /* protect ld_active_tgt_count, ltd_active and lod_md_root */
105         spinlock_t           lod_lock;
106
107         /* Description of OST */
108         struct lod_tgt_descs  lod_ost_descs;
109         /* Description of MDT */
110         struct lod_tgt_descs  lod_mdt_descs;
111
112         /* Recovery thread for lod_child */
113         struct task_struct   *lod_child_recovery_task;
114
115         /* maximum EA size underlied OSD may have */
116         unsigned int          lod_osd_max_easize;
117         /* maximum size of MDT stripe for Data-on-MDT files. */
118         unsigned int          lod_dom_stripesize_max_kb;
119         /* current DOM default stripe size adjusted by threshold */
120         unsigned int          lod_dom_stripesize_cur_kb;
121         /* Threshold at which DOM default stripe will start decreasing */
122         __u64                 lod_dom_threshold_free_mb;
123
124         /* Local OSD statfs cache */
125         spinlock_t            lod_lsfs_lock;
126         time64_t              lod_lsfs_age;
127         __u64                 lod_lsfs_total_mb;
128         __u64                 lod_lsfs_free_mb;
129
130         /* OST pool data */
131         int                     lod_pool_count;
132         struct rhashtable       lod_pools_hash_body; /* used for key access */
133         struct list_head        lod_pool_list; /* used for sequential access */
134         struct proc_dir_entry  *lod_pool_proc_entry;
135         struct proc_dir_entry  *lod_spill_proc_entry;
136
137         enum lustre_sec_part   lod_sp_me;
138
139         struct proc_dir_entry *lod_symlink;
140         struct dentry          *lod_debugfs;
141         struct dentry          *lod_pool_debugfs;
142
143         /* ROOT object, used to fetch FS default striping */
144         struct lod_object      *lod_md_root;
145
146         /* max stripe count if stripe count is set to -1. 0 means unlimited */
147         unsigned int            lod_max_stripecount;
148         unsigned int            lod_max_mdt_stripecount;
149         /* valid range: [1, LMV_MAX_STRIPES_PER_MDT] */
150         unsigned int            lod_max_stripes_per_mdt;
151 };
152
153 #define lod_ost_bitmap          lod_ost_descs.ltd_tgt_bitmap
154 #define lod_ost_count           lod_ost_descs.ltd_lov_desc.ld_tgt_count
155 #define lod_ost_active_count    lod_ost_descs.ltd_lov_desc.ld_active_tgt_count
156 #define lod_remote_mdt_count    lod_mdt_descs.ltd_lmv_desc.ld_tgt_count
157
158 struct lod_layout_component {
159         struct lu_extent          llc_extent;
160         __u32                     llc_id;
161         __u32                     llc_flags;
162         __u32                     llc_magic;
163         __u64                     llc_timestamp; /* snapshot time */
164         union {
165                 struct { /* plain layout V1/V3. */
166                         __u32                     llc_pattern;
167                         __u32                     llc_stripe_size;
168                         __u16                     llc_layout_gen;
169                         __u16                     llc_stripe_offset;
170                         __u16                     llc_stripe_count;
171                         __u16                     llc_stripes_allocated;
172                         char                     *llc_pool;
173                         /* ost list specified by LOV_USER_MAGIC_SPECIFIC lum */
174                         struct lu_tgt_pool        llc_ostlist;
175                         struct dt_object        **llc_stripe;
176                         __u32                    *llc_ost_indices;
177                 };
178                 struct { /* Foreign mirror layout component */
179                         __u32                     llc_length;
180                         __u32                     llc_type;
181                         __u32                     llc_foreign_flags;
182                         union {
183                                 /* Basic HSM layout information */
184                                 struct lov_hsm_base      llc_hsm;
185                                 /* Other kinds of foreign types (i.e. DAOS) */
186                                 char                    *llc_value;
187                         };
188                 };
189         };
190 };
191
192 struct lod_default_striping {
193         /* default LOV */
194         /* current layout component count */
195         __u16                           lds_def_comp_cnt;
196         __u16                           lds_def_mirror_cnt;
197         /* the largest comp count ever used */
198         __u32                           lds_def_comp_size_cnt;
199         struct lod_layout_component     *lds_def_comp_entries;
200         /* default LMV */
201         __u32                           lds_dir_def_stripe_count;
202         __u32                           lds_dir_def_stripe_offset;
203         __u32                           lds_dir_def_hash_type;
204         __u8                            lds_dir_def_max_inherit;
205         __u8                            lds_dir_def_max_inherit_rr;
206                                         /* default file striping flags (LOV) */
207         __u32                           lds_def_striping_set:1,
208                                         lds_def_striping_is_composite:1,
209                                         /* default dir striping flags (LMV) */
210                                         lds_dir_def_striping_set:1;
211 };
212
213 enum layout_verify_flags {
214         LVF_ALL_STALE           = BIT(0), /* check not all stale mirrors */
215 };
216
217 struct lod_mirror_entry {
218         __u16   lme_stale:1,
219                 lme_prefer:1,
220                 lme_hsm:1;
221         /* mirror id */
222         __u16   lme_id;
223         /* preference */
224         __u16   lme_preference;
225         /* start,end index of this mirror in ldo_comp_entries */
226         __u16   lme_start;
227         __u16   lme_end;
228 };
229
230 struct lod_object {
231         /* common fields for both files and directories */
232         struct dt_object                ldo_obj;
233         struct mutex                    ldo_layout_mutex;
234                                         /* foreign file/directory */
235         __u32                           ldo_is_foreign:1;
236         union {
237                 /* file stripe (LOV) */
238                 struct {
239                         __u32           ldo_layout_gen;
240                         /* Layout component count for a regular file.
241                          * It equals to 1 for non-composite layout. */
242                         __u16           ldo_comp_cnt;
243                         /* Layout mirror count for a PFLR file.
244                          * It's 0 for files with non-composite layout. */
245                         __u16           ldo_mirror_count;
246                         struct lod_mirror_entry *ldo_mirrors;
247                         __u32           ldo_is_composite:1,
248                                         ldo_flr_state:4,
249                                         ldo_comp_cached:1;
250                 };
251                 /* directory stripe (LMV) */
252                 struct {
253                         /* Slave stripe count for striped directory. */
254                         __u16           ldo_dir_stripe_count;
255                         /* How many stripes allocated for a striped directory */
256                         __u16           ldo_dir_stripes_allocated;
257                         __u32           ldo_dir_stripe_offset;
258                         __u32           ldo_dir_hash_type;
259                         __u32           ldo_dir_migrate_offset;
260                         __u32           ldo_dir_migrate_hash;
261                         __u32           ldo_dir_layout_version;
262                         /* Is a slave stripe of striped directory? */
263                         __u32           ldo_dir_slave_stripe:1,
264                                         ldo_dir_striped:1,
265                                         /* the stripe has been loaded */
266                                         ldo_dir_stripe_loaded:1;
267                         /*
268                          * This default LMV is parent default LMV, which will be
269                          * used in child creation, and it's not cached, so this
270                          * field is invalid after create, make sure it's used by
271                          * lod_dir_striping_create_internal() only.
272                          */
273                         struct lod_default_striping     *ldo_def_striping;
274                 };
275         };
276         union {
277                 struct {
278                         /* foreign/raw format LOV */
279                         char                            *ldo_foreign_lov;
280                         size_t                           ldo_foreign_lov_size;
281                 };
282                 struct {
283                         /* foreign/raw format LMV */
284                         char                            *ldo_foreign_lmv;
285                         size_t                           ldo_foreign_lmv_size;
286                 };
287                 struct {
288                         /* file stripe (LOV) */
289                         struct lod_layout_component     *ldo_comp_entries;
290                         /* slave stripes of striped directory (LMV) */
291                         struct dt_object                **ldo_stripe;
292                 };
293         };
294 };
295
296 #define ldo_dir_split_offset    ldo_dir_migrate_offset
297 #define ldo_dir_split_hash      ldo_dir_migrate_hash
298
299 #define lod_foreach_mirror_comp(comp, lo, mirror_idx)                      \
300 for (comp = &lo->ldo_comp_entries[lo->ldo_mirrors[mirror_idx].lme_start];  \
301      comp <= &lo->ldo_comp_entries[lo->ldo_mirrors[mirror_idx].lme_end];   \
302      comp++)
303
304 static inline bool lod_is_flr(const struct lod_object *lo)
305 {
306         if (!lo->ldo_is_composite)
307                 return false;
308
309         return (lo->ldo_flr_state & LCM_FL_FLR_MASK) != LCM_FL_NONE;
310 }
311
312 static inline bool lod_is_hsm(const struct lod_layout_component *lod_comp)
313 {
314         return lod_comp->llc_magic == LOV_MAGIC_FOREIGN &&
315                lov_hsm_type_supported(lod_comp->llc_type);
316 }
317
318 static inline bool lod_is_splitting(const struct lod_object *lo)
319 {
320         return lmv_hash_is_splitting(lo->ldo_dir_hash_type);
321 }
322
323 static inline bool lod_is_migrating(const struct lod_object *lo)
324 {
325         return lmv_hash_is_migrating(lo->ldo_dir_hash_type);
326 }
327
328 static inline bool lod_is_layout_changing(const struct lod_object *lo)
329 {
330         return lmv_hash_is_layout_changing(lo->ldo_dir_hash_type);
331 }
332
333 static inline int lod_set_pool(char **pool, const char *new_pool)
334 {
335         int len;
336
337         if (*pool == new_pool)
338                 return 0;
339
340         if (*pool != NULL) {
341                 len = strlen(*pool) + 1;
342                 OBD_FREE(*pool, len);
343                 *pool = NULL;
344         }
345         if (new_pool != NULL) {
346                 len = strlen(new_pool) + 1;
347                 OBD_ALLOC(*pool, len);
348                 if (*pool == NULL)
349                         return -ENOMEM;
350                 strscpy(*pool, new_pool, len);
351         }
352         return 0;
353 }
354
355 static inline int lod_obj_set_pool(struct lod_object *lo, int i,
356                                    const char *new_pool)
357 {
358         return lod_set_pool(&lo->ldo_comp_entries[i].llc_pool, new_pool);
359 }
360
361 /**
362  * Create new layout generation.
363  *
364  * The only requirement for layout generation is that it changes when
365  * the layout is modified, so a circular counter is sufficient for the
366  * low rate of layout modifications.
367  *
368  * Layout generation is also used to generate unique component ID.
369  * To detect generation overflow, we preserve the highest bit of the
370  * generation when it wrapped.
371  */
372 static inline void lod_obj_inc_layout_gen(struct lod_object *lo)
373 {
374         __u32 preserve = lo->ldo_layout_gen & ~LCME_ID_MASK;
375         lo->ldo_layout_gen++;
376         lo->ldo_layout_gen |= preserve;
377         /* Zero is not a valid generation */
378         if (unlikely((lo->ldo_layout_gen & LCME_ID_MASK) == 0)) {
379                 lo->ldo_layout_gen++;
380                 lo->ldo_layout_gen &= ~LU_LAYOUT_RESYNC;
381         }
382 }
383
384 struct lod_it {
385         struct dt_object        *lit_obj; /* object from the layer below */
386         /* stripe offset of iteration */
387         __u32                   lit_stripe_index;
388         __u32                   lit_attr;
389         struct dt_it            *lit_it;  /* iterator from the layer below */
390 };
391
392 #define LOD_OBJS_INTRANS 4
393 struct lod_thread_info {
394         /* per-thread buffer for LOV EA, may be vmalloc'd */
395         struct lu_buf                   lti_ea_buf;
396         /* per-thread buffer for LMV EA */
397         struct lu_buf                   lti_buf;
398         struct ost_id                   lti_ostid;
399         struct lu_fid                   lti_fid;
400         struct obd_statfs               lti_osfs;
401         struct lu_attr                  lti_attr;
402         struct lod_it                   lti_it;
403         struct ldlm_res_id              lti_res_id;
404         /* used to hold lu_dirent, sizeof(struct lu_dirent) + NAME_MAX */
405         char                            lti_key[sizeof(struct lu_dirent) +
406                                                 NAME_MAX];
407         struct dt_object_format         lti_format;
408         struct lu_name                  lti_name;
409         struct lu_buf                   lti_linkea_buf;
410         struct dt_insert_rec            lti_dt_rec;
411         struct llog_catid               lti_cid;
412         struct llog_cookie              lti_cookie;
413         struct lustre_cfg               lti_lustre_cfg;
414         /* used to store parent default striping in create */
415         struct lod_default_striping     lti_def_striping;
416         struct filter_fid               lti_ff;
417         __u32                           *lti_comp_idx;
418         size_t                          lti_comp_size;
419         size_t                          lti_count;
420         struct lu_attr                  lti_layout_attr;
421         /* object allocation avoid guide info */
422         struct lod_avoid_guide          lti_avoid;
423         union lmv_mds_md                lti_lmv;
424         struct dt_allocation_hint       lti_ah;
425         int lti_obj_count;
426         struct lod_object *lti_obj[LOD_OBJS_INTRANS];
427         __u32 lti_gen[LOD_OBJS_INTRANS];
428 };
429
430 #define lti_ea_store            lti_ea_buf.lb_buf
431 #define lti_ea_store_size       lti_ea_buf.lb_len
432
433 /**
434  * \retval      0 object's layout hasn't changed in the transaction
435  * \retval      > 0 object's layout has changed
436  * \retval      -ENOENT object's layout gen hasn't saved in transatoin
437  *              declaration
438  */
439 static inline int
440 lod_check_layout_gen_intrans(struct lod_thread_info *info,
441                              struct lod_object *lo)
442 {
443         int i;
444         int rc = -ENOENT;
445
446         for (i = 0; i < info->lti_obj_count; i++) {
447                 if (info->lti_obj[i] != lo)
448                         continue;
449
450                 if (info->lti_gen[i] == lo->ldo_layout_gen)
451                         rc = 0;
452                 else
453                         rc = i + 1;
454                 break;
455         }
456
457         return rc;
458 }
459
460 static inline int
461 lod_save_layout_gen_intrans(struct lod_thread_info *info, struct lod_object *lo)
462 {
463         struct lu_object *luo = &lo->ldo_obj.do_lu;
464         int rc;
465
466         rc = lod_check_layout_gen_intrans(info, lo);
467         if (rc == 0)
468                 return 0;
469         if (rc > 0) {
470                 CDEBUG(D_LAYOUT,
471                        "%s: obj %p gen changed from %d to %d in trans declaration\n",
472                        luo->lo_dev->ld_obd->obd_name, lo, info->lti_gen[rc - 1],
473                        lo->ldo_layout_gen);
474                 return -EINVAL;
475         }
476
477         if (unlikely(info->lti_obj_count == LOD_OBJS_INTRANS)) {
478                 CERROR("%s: "DFID
479                        " save too many lod_object (%d) in one transaction, use bigger LOD_OBJS_INTRANS: rc = %d\n",
480                        luo->lo_dev->ld_obd->obd_name,
481                        PFID(lu_object_fid(luo)), LOD_OBJS_INTRANS, -E2BIG);
482                 return -E2BIG;
483         }
484
485         info->lti_obj[info->lti_obj_count] = lo;
486         info->lti_gen[info->lti_obj_count] = lo->ldo_layout_gen;
487         info->lti_obj_count++;
488
489         return 0;
490 }
491
492 extern const struct lu_device_operations lod_lu_ops;
493
494 static inline int lu_device_is_lod(struct lu_device *d)
495 {
496         return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &lod_lu_ops);
497 }
498
499 static inline struct lod_device* lu2lod_dev(struct lu_device *d)
500 {
501         LASSERT(lu_device_is_lod(d));
502         return container_of_safe(d, struct lod_device, lod_dt_dev.dd_lu_dev);
503 }
504
505 static inline struct lu_device *lod2lu_dev(struct lod_device *d)
506 {
507         return &d->lod_dt_dev.dd_lu_dev;
508 }
509
510 static inline struct obd_device *lod2obd(struct lod_device *d)
511 {
512         return d->lod_dt_dev.dd_lu_dev.ld_obd;
513 }
514
515 static inline struct lod_device *dt2lod_dev(struct dt_device *d)
516 {
517         LASSERT(lu_device_is_lod(&d->dd_lu_dev));
518         return container_of(d, struct lod_device, lod_dt_dev);
519 }
520
521 static inline struct lod_object *lu2lod_obj(struct lu_object *o)
522 {
523         LASSERT(ergo(o != NULL, lu_device_is_lod(o->lo_dev)));
524         return container_of_safe(o, struct lod_object, ldo_obj.do_lu);
525 }
526
527 static inline struct lu_object *lod2lu_obj(struct lod_object *obj)
528 {
529         return &obj->ldo_obj.do_lu;
530 }
531
532 static inline const struct lu_fid *lod_object_fid(struct lod_object *obj)
533 {
534         return lu_object_fid(lod2lu_obj(obj));
535 }
536
537 static inline struct lod_object *lod_obj(const struct lu_object *o)
538 {
539         LASSERT(lu_device_is_lod(o->lo_dev));
540         return container_of(o, struct lod_object, ldo_obj.do_lu);
541 }
542
543 static inline struct lod_object *lod_dt_obj(const struct dt_object *d)
544 {
545         return lod_obj(&d->do_lu);
546 }
547
548 static inline struct dt_object* lod_object_child(struct lod_object *o)
549 {
550         return container_of(lu_object_next(lod2lu_obj(o)),
551                             struct dt_object, do_lu);
552 }
553
554 static inline bool lod_obj_is_striped(struct dt_object *dt)
555 {
556         struct lod_object *lo = lod_dt_obj(dt);
557         int i;
558         bool rc = false;
559
560         if (!dt_object_exists(dt_object_child(dt)))
561                 return false;
562
563         mutex_lock(&lo->ldo_layout_mutex);
564
565         if (S_ISDIR(dt->do_lu.lo_header->loh_attr)) {
566                 rc = lo->ldo_dir_stripe_count != 0;
567         } else if (lo->ldo_is_foreign) {
568                 rc = false;
569         } else {
570                 for (i = 0; i < lo->ldo_comp_cnt; i++) {
571                         if (lo->ldo_comp_entries[i].llc_magic ==
572                             LOV_MAGIC_FOREIGN)
573                                 continue;
574                         if (lo->ldo_comp_entries[i].llc_stripe == NULL)
575                                 continue;
576                         LASSERT(lo->ldo_comp_entries[i].llc_stripe_count > 0);
577                         rc = true;
578                         break;
579                 }
580         }
581
582         mutex_unlock(&lo->ldo_layout_mutex);
583         return rc;
584 }
585
586 extern struct lu_context_key lod_thread_key;
587
588 static inline struct lod_thread_info *lod_env_info(const struct lu_env *env)
589 {
590         struct lod_thread_info *info;
591         info = lu_context_key_get(&env->le_ctx, &lod_thread_key);
592         LASSERT(info);
593         return info;
594 }
595
596 static inline struct lu_name *
597 lod_name_get(const struct lu_env *env, const void *area, int len)
598 {
599         struct lu_name *lname;
600
601         lname = &lod_env_info(env)->lti_name;
602         lname->ln_name = area;
603         lname->ln_namelen = len;
604         return lname;
605 }
606
607 static inline struct lod_default_striping *
608 lod_lds_buf_get(const struct lu_env *env)
609 {
610         struct lod_thread_info *info = lod_env_info(env);
611
612         info->lti_def_striping.lds_def_striping_set = 0;
613         info->lti_def_striping.lds_dir_def_striping_set = 0;
614         return &info->lti_def_striping;
615 }
616
617 static inline void lod_layout_get_pool(struct lod_layout_component *entries,
618                                        int count, char *pool, int len)
619 {
620         int i;
621
622         for (i = 0; i < count; i++) {
623                 if (entries[i].llc_magic == LOV_MAGIC_FOREIGN)
624                         continue;
625                 if (entries[i].llc_pool != NULL) {
626                         strscpy(pool, entries[i].llc_pool, len);
627                         break;
628                 }
629         }
630 }
631
632 #define lod_foreach_mdt(lod, mdt) ltd_foreach_tgt(&(lod)->lod_mdt_descs, mdt)
633 #define lod_foreach_ost(lod, ost) ltd_foreach_tgt(&(lod)->lod_ost_descs, ost)
634
635 /* lod_dev.c */
636 extern struct kmem_cache *lod_object_kmem;
637 int lod_fld_lookup(const struct lu_env *env, struct lod_device *lod,
638                    const struct lu_fid *fid, __u32 *tgt, int *flags);
639 int lod_sub_init_llog(const struct lu_env *env, struct lod_device *lod,
640                       struct dt_device *dt);
641 void lod_sub_fini_llog(const struct lu_env *env,
642                        struct dt_device *dt, struct task_struct **taskp);
643 int lodname2mdt_index(char *lodname, __u32 *mdt_index);
644
645 /* lod_lov.c */
646 void lod_getref(struct lod_tgt_descs *ltd);
647 void lod_putref(struct lod_device *lod, struct lod_tgt_descs *ltd);
648 int lod_add_device(const struct lu_env *env, struct lod_device *lod,
649                    char *osp, unsigned index, unsigned gen, int mdt_index,
650                    char *type, int active);
651 int lod_del_device(const struct lu_env *env, struct lod_device *lod,
652                    struct lod_tgt_descs *ltd, char *osp, unsigned int idx,
653                    unsigned int gen);
654 int validate_lod_and_idx(struct lod_device *lod, __u32 idx);
655 int lod_fini_tgt(const struct lu_env *env, struct lod_device *lod,
656                  struct lod_tgt_descs *ltd);
657 int lod_striping_load(const struct lu_env *env, struct lod_object *lo);
658 int lod_striping_reload(const struct lu_env *env, struct lod_object *lo,
659                         const struct lu_buf *buf, enum layout_verify_flags lvf);
660 void lod_dom_stripesize_recalc(struct lod_device *d);
661
662 int lod_get_ea(const struct lu_env *env, struct lod_object *lo,
663                const char *name);
664 static inline int
665 lod_get_lov_ea(const struct lu_env *env, struct lod_object *lo)
666 {
667         return lod_get_ea(env, lo, XATTR_NAME_LOV);
668 }
669
670 static inline int
671 lod_get_lmv_ea(const struct lu_env *env, struct lod_object *lo)
672 {
673         return lod_get_ea(env, lo, XATTR_NAME_LMV);
674 }
675
676 static inline int
677 lod_get_default_lmv_ea(const struct lu_env *env, struct lod_object *lo)
678 {
679         return lod_get_ea(env, lo, XATTR_NAME_DEFAULT_LMV);
680 }
681
682 static inline void
683 lod_comp_set_init(struct lod_layout_component *entry)
684 {
685         entry->llc_flags |= LCME_FL_INIT;
686 }
687
688 static inline void
689 lod_comp_unset_init(struct lod_layout_component *entry)
690 {
691         entry->llc_flags &= ~LCME_FL_INIT;
692 }
693
694 static inline bool
695 lod_comp_inited(const struct lod_layout_component *entry)
696 {
697         return entry->llc_flags & LCME_FL_INIT;
698 }
699
700 /**
701  * For a PFL file, some of its component could be un-instantiated, so
702  * that their lov_ost_data_v1 array is not needed, we'd use this function
703  * to reduce the LOVEA buffer size.
704  *
705  * Note: if llc_ostlist contains value, we'd need lov_ost_data_v1 array to
706  * save the specified OST index list.
707  */
708 static inline void
709 lod_comp_shrink_stripe_count(struct lod_layout_component *lod_comp,
710                              __u16 *stripe_count)
711 {
712         /**
713          * Need one lov_ost_data_v1 to store invalid ost_idx, please refer to
714          * lod_parse_striping()
715          */
716         if (!lod_comp_inited(lod_comp) && lod_comp->llc_ostlist.op_count == 0)
717                 *stripe_count = 1;
718 }
719
720 void lod_fix_desc(struct lov_desc *desc);
721 void lod_fix_desc_qos_maxage(__u32 *val);
722 void lod_fix_desc_pattern(__u32 *val);
723 void lod_fix_desc_stripe_count(__u32 *val);
724 void lod_fix_desc_stripe_size(__u64 *val);
725 void lod_fix_lmv_desc_pattern(__u32 *val);
726 int lod_pools_init(struct lod_device *m, struct lustre_cfg *cfg);
727 int lod_pools_fini(struct lod_device *m);
728 int lod_parse_striping(const struct lu_env *env, struct lod_object *mo,
729                        const struct lu_buf *buf, enum layout_verify_flags lvf);
730 int lod_parse_dir_striping(const struct lu_env *env, struct lod_object *lo,
731                            const struct lu_buf *buf);
732 int lod_initialize_objects(const struct lu_env *env, struct lod_object *mo,
733                            struct lov_ost_data_v1 *objs, int index);
734 int lod_verify_striping(const struct lu_env *env, struct lod_device *d,
735                         struct lod_object *lo, const struct lu_buf *buf,
736                         bool is_from_disk);
737 int lod_generate_lovea(const struct lu_env *env, struct lod_object *lo,
738                        struct lov_mds_md *lmm, int *lmm_size, bool is_dir);
739 int lod_ea_store_resize(struct lod_thread_info *info, size_t size);
740 int lod_def_striping_comp_resize(struct lod_default_striping *lds, __u16 count);
741 void lod_free_def_comp_entries(struct lod_default_striping *lds);
742 void lod_free_comp_entries(struct lod_object *lo);
743 int lod_alloc_comp_entries(struct lod_object *lo, int mirror_cnt, int comp_cnt);
744 int lod_fill_mirrors(struct lod_object *lo);
745 int lod_init_comp_foreign(struct lod_layout_component *lod_comp, void *lmm);
746
747 /* lod_pool.c */
748 struct lod_pool_desc *lod_find_pool(struct lod_device *lod, const char *poolname);
749 void lod_pool_putref(struct lod_pool_desc *pool);
750 int lod_pool_del(struct obd_device *obd, char *poolname);
751 int lod_check_index_in_pool(__u32 idx, struct lod_pool_desc *pool);
752 int lod_pool_new(struct obd_device *obd, char *poolname);
753 int lod_pool_add(struct obd_device *obd, char *poolname, char *ostname);
754 int lod_pool_remove(struct obd_device *obd, char *poolname, char *ostname);
755
756 struct lod_obj_stripe_cb_data;
757 typedef int (*lod_obj_stripe_cb_t)(const struct lu_env *env,
758                                    struct lod_object *lo, struct dt_object *dt,
759                                    struct thandle *th,
760                                    int comp_idx, int stripe_idx,
761                                    struct lod_obj_stripe_cb_data *data);
762 typedef bool (*lod_obj_comp_skip_cb_t)(const struct lu_env *env,
763                                         struct lod_object *lo, int comp_idx,
764                                         struct lod_obj_stripe_cb_data *data);
765 typedef int (*lod_obj_comp_cb_t)(const struct lu_env *env,
766                                 struct lod_object *lo, int comp_idx,
767                                 struct lod_obj_stripe_cb_data *data);
768 struct lod_obj_stripe_cb_data {
769         union {
770                 const struct lu_attr    *locd_attr;
771                 int                     locd_ost_index;
772                 const struct lu_buf     *locd_buf;
773         };
774         lod_obj_stripe_cb_t             locd_stripe_cb;
775         lod_obj_comp_skip_cb_t          locd_comp_skip_cb;
776         lod_obj_comp_cb_t               locd_comp_cb;
777         bool                            locd_declare;
778 };
779
780 /* lod_qos.c */
781 int lod_mdt_alloc_qos(const struct lu_env *env, struct lod_object *lo,
782                       struct dt_object **stripes, u32 stripe_idx,
783                       u32 stripe_count);
784 int lod_mdt_alloc_rr(const struct lu_env *env, struct lod_object *lo,
785                      struct dt_object **stripes, u32 stripe_idx,
786                      u32 stripe_count);
787 int lod_prepare_create(const struct lu_env *env, struct lod_object *lo,
788                        struct lu_attr *attr, const struct lu_buf *buf,
789                        struct thandle *th);
790 int lod_use_defined_striping(const struct lu_env *, struct lod_object *,
791                              const struct lu_buf *);
792 int lod_qos_parse_config(const struct lu_env *env, struct lod_object *lo,
793                          const struct lu_buf *buf);
794 void lod_qos_set_pool(struct lod_object *lo, int pos, const char *pool_name);
795 int lod_qos_prep_create(const struct lu_env *env, struct lod_object *lo,
796                         struct lu_attr *attr, struct thandle *th,
797                         int comp_idx, __u64 reserve);
798 __u16 lod_comp_entry_stripe_count(struct lod_object *lo,
799                                   int comp_idx, bool is_dir);
800 __u16 lod_get_stripe_count_plain(struct lod_device *lod, struct lod_object *lo,
801                                  __u16 stripe_count, bool overstriping,
802                                  enum lod_uses_hint *flags);
803 __u16 lod_get_stripe_count(struct lod_device *lod, struct lod_object *lo,
804                            int comp_idx, __u16 stripe_count, bool overstriping,
805                            enum lod_uses_hint *flags);
806 void lod_qos_statfs_update(const struct lu_env *env, struct lod_device *lod,
807                            struct lu_tgt_descs *ltd);
808
809 /* lproc_lod.c */
810 int lod_procfs_init(struct lod_device *lod);
811 void lod_procfs_fini(struct lod_device *lod);
812
813 /* lod_object.c */
814 extern const struct dt_object_operations lod_obj_ops;
815 extern const struct lu_object_operations lod_lu_obj_ops;
816
817 int lod_load_lmv_shards(const struct lu_env *env, struct lod_object *lo,
818                         struct lu_buf *buf, bool resize);
819 int lod_declare_striped_create(const struct lu_env *env, struct dt_object *dt,
820                                struct lu_attr *attr,
821                                const struct lu_buf *lovea, struct thandle *th);
822 int lod_striped_create(const struct lu_env *env, struct dt_object *dt,
823                         struct lu_attr *attr, struct dt_object_format *dof,
824                         struct thandle *th);
825 int lod_alloc_foreign_lov(struct lod_object *lo, size_t size);
826 void lod_free_foreign_lov(struct lod_object *lo);
827 void lod_striping_free_nolock(const struct lu_env *env, struct lod_object *lo);
828 void lod_striping_free(const struct lu_env *env, struct lod_object *lo);
829
830 int lod_obj_for_each_stripe(const struct lu_env *env, struct lod_object *lo,
831                             struct thandle *th,
832                             struct lod_obj_stripe_cb_data *data);
833 int lod_comp_copy_ost_lists(struct lod_layout_component *lod_comp,
834                             struct lov_user_md_v3 *v3);
835 void lod_adjust_stripe_size(struct lod_layout_component *comp,
836                             __u32 def_stripe_size);
837
838 /* lod_sub_object.c */
839 struct thandle *lod_sub_get_thandle(const struct lu_env *env,
840                                     struct thandle *th,
841                                     const struct dt_object *sub_obj,
842                                     bool *record_update);
843 int lod_sub_declare_create(const struct lu_env *env, struct dt_object *dt,
844                            struct lu_attr *attr,
845                            struct dt_allocation_hint *hint,
846                            struct dt_object_format *dof, struct thandle *th);
847 int lod_sub_create(const struct lu_env *env, struct dt_object *dt,
848                    struct lu_attr *attr, struct dt_allocation_hint *hint,
849                    struct dt_object_format *dof, struct thandle *th);
850 int lod_sub_declare_ref_add(const struct lu_env *env, struct dt_object *dt,
851                             struct thandle *th);
852 int lod_sub_ref_add(const struct lu_env *env, struct dt_object *dt,
853                     struct thandle *th);
854 int lod_sub_declare_ref_del(const struct lu_env *env, struct dt_object *dt,
855                             struct thandle *th);
856 int lod_sub_ref_del(const struct lu_env *env, struct dt_object *dt,
857                     struct thandle *th);
858 int lod_sub_declare_destroy(const struct lu_env *env, struct dt_object *dt,
859                             struct thandle *th);
860 int lod_sub_destroy(const struct lu_env *env, struct dt_object *dt,
861                     struct thandle *th);
862 int lod_sub_declare_insert(const struct lu_env *env, struct dt_object *dt,
863                            const struct dt_rec *rec, const struct dt_key *key,
864                            struct thandle *th);
865 int lod_sub_insert(const struct lu_env *env, struct dt_object *dt,
866                    const struct dt_rec *rec, const struct dt_key *key,
867                    struct thandle *th);
868 int lod_sub_declare_delete(const struct lu_env *env, struct dt_object *dt,
869                            const struct dt_key *key, struct thandle *th);
870 int lod_sub_delete(const struct lu_env *env, struct dt_object *dt,
871                    const struct dt_key *name, struct thandle *th);
872 int lod_sub_declare_xattr_set(const struct lu_env *env, struct dt_object *dt,
873                               const struct lu_buf *buf, const char *name,
874                               int fl, struct thandle *th);
875 int lod_sub_xattr_set(const struct lu_env *env, struct dt_object *dt,
876                       const struct lu_buf *buf, const char *name, int fl,
877                       struct thandle *th);
878 int lod_sub_declare_attr_set(const struct lu_env *env, struct dt_object *dt,
879                              const struct lu_attr *attr, struct thandle *th);
880 int lod_sub_attr_set(const struct lu_env *env, struct dt_object *dt,
881                      const struct lu_attr *attr, struct thandle *th);
882 int lod_sub_declare_xattr_del(const struct lu_env *env, struct dt_object *dt,
883                               const char *name, struct thandle *th);
884 int lod_sub_xattr_del(const struct lu_env *env, struct dt_object *dt,
885                       const char *name, struct thandle *th);
886 int lod_sub_declare_write(const struct lu_env *env, struct dt_object *dt,
887                           const struct lu_buf *buf, loff_t pos,
888                           struct thandle *th);
889 ssize_t lod_sub_write(const struct lu_env *env, struct dt_object *dt,
890                       const struct lu_buf *buf, loff_t *pos,
891                       struct thandle *th);
892 int lod_sub_declare_punch(const struct lu_env *env, struct dt_object *dt,
893                           __u64 start, __u64 end, struct thandle *th);
894 int lod_sub_punch(const struct lu_env *env, struct dt_object *dt,
895                   __u64 start, __u64 end, struct thandle *th);
896
897 int lod_sub_prep_llog(const struct lu_env *env, struct lod_device *lod,
898                       struct dt_device *dt, int index);
899 void lod_check_and_spill_pool(const struct lu_env *env, struct lod_device *lod,
900                               char **poolname);
901 void lod_spill_target_refresh(const struct lu_env *env, struct lod_device *lod,
902                               struct lod_pool_desc *pool);
903 struct lod_pool_desc *lod_pool_find(struct lod_device *lod, const char *poolname);
904 int lod_tgt_weights_seq_show(struct seq_file *m, struct lod_device *lod,
905                              struct lu_tgt_pool *tgts, bool mdt);
906 int lod_tgt_weights_seq_write(struct seq_file *m, const char __user *buf,
907                               size_t count, struct lod_device *lod,
908                               struct lu_tgt_pool *tgts, bool is_mdt);
909 extern struct lprocfs_vars lprocfs_lod_spill_vars[];
910 #endif