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, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
32 #ifndef __LUSTRE_LU_OBJECT_H
33 #define __LUSTRE_LU_OBJECT_H
35 #ifdef HAVE_LINUX_STDARG_HEADER
36 #include <linux/stdarg.h>
40 #include <libcfs/libcfs.h>
41 #include <uapi/linux/lustre/lustre_idl.h>
43 #include <linux/percpu_counter.h>
44 #include <linux/rhashtable.h>
45 #include <linux/ctype.h>
48 struct proc_dir_entry;
54 * lu_* data-types represent server-side entities shared by data and meta-data
59 * -# support for layering.
61 * Server side object is split into layers, one per device in the
62 * corresponding device stack. Individual layer is represented by struct
63 * lu_object. Compound layered object --- by struct lu_object_header. Most
64 * interface functions take lu_object as an argument and operate on the
65 * whole compound object. This decision was made due to the following
68 * - it's envisaged that lu_object will be used much more often than
71 * - we want lower (non-top) layers to be able to initiate operations
72 * on the whole object.
74 * Generic code supports layering more complex than simple stacking, e.g.,
75 * it is possible that at some layer object "spawns" multiple sub-objects
78 * -# fid-based identification.
80 * Compound object is uniquely identified by its fid. Objects are indexed
81 * by their fids (hash table is used for index).
83 * -# caching and life-cycle management.
85 * Object's life-time is controlled by reference counting. When reference
86 * count drops to 0, object is returned to cache. Cached objects still
87 * retain their identity (i.e., fid), and can be recovered from cache.
89 * Objects are kept in the global LRU list, and lu_site_purge() function
90 * can be used to reclaim given number of unused objects from the tail of
93 * -# avoiding recursion.
95 * Generic code tries to replace recursion through layers by iterations
96 * where possible. Additionally to the end of reducing stack consumption,
97 * data, when practically possible, are allocated through lu_context_key
98 * interface rather than on stack.
105 struct lu_object_header;
111 * Operations common for data and meta-data devices.
113 struct lu_device_operations {
115 * Allocate object for the given device (without lower-layer
116 * parts). This is called by lu_object_operations::loo_object_init()
117 * from the parent layer, and should setup at least lu_object::lo_dev
118 * and lu_object::lo_ops fields of resulting lu_object.
120 * Object creation protocol.
122 * Due to design goal of avoiding recursion, object creation (see
123 * lu_object_alloc()) is somewhat involved:
125 * - first, lu_device_operations::ldo_object_alloc() method of the
126 * top-level device in the stack is called. It should allocate top
127 * level object (including lu_object_header), but without any
128 * lower-layer sub-object(s).
130 * - then lu_object_alloc() sets fid in the header of newly created
133 * - then lu_object_operations::loo_object_init() is called. It has
134 * to allocate lower-layer object(s). To do this,
135 * lu_object_operations::loo_object_init() calls ldo_object_alloc()
136 * of the lower-layer device(s).
138 * - for all new objects allocated by
139 * lu_object_operations::loo_object_init() (and inserted into object
140 * stack), lu_object_operations::loo_object_init() is called again
141 * repeatedly, until no new objects are created.
143 * \post ergo(!IS_ERR(result), result->lo_dev == d &&
144 * result->lo_ops != NULL);
146 struct lu_object *(*ldo_object_alloc)(const struct lu_env *env,
147 const struct lu_object_header *h,
148 struct lu_device *d);
150 * process config specific for device.
152 int (*ldo_process_config)(const struct lu_env *env,
153 struct lu_device *, struct lustre_cfg *);
154 int (*ldo_recovery_complete)(const struct lu_env *,
158 * initialize local objects for device. this method called after layer has
159 * been initialized (after LCFG_SETUP stage) and before it starts serving
163 int (*ldo_prepare)(const struct lu_env *,
164 struct lu_device *parent,
165 struct lu_device *dev);
169 * Allocate new FID for file with @name under @parent
171 * \param[in] env execution environment for this thread
172 * \param[in] dev dt device
173 * \param[out] fid new FID allocated
174 * \param[in] parent parent object
175 * \param[in] name lu_name
177 * \retval 0 0 FID allocated successfully.
178 * \retval 1 1 FID allocated successfully and new sequence
179 * requested from seq meta server
180 * \retval negative negative errno if FID allocation failed.
182 int (*ldo_fid_alloc)(const struct lu_env *env,
183 struct lu_device *dev,
185 struct lu_object *parent,
186 const struct lu_name *name);
190 * For lu_object_conf flags
193 /* This is a new object to be allocated, or the file
194 * corresponding to the object does not exists. */
195 LOC_F_NEW = 0x00000001,
199 * Object configuration, describing particulars of object being created. On
200 * server this is not used, as server objects are full identified by fid. On
201 * client configuration contains struct lustre_md.
203 struct lu_object_conf {
205 * Some hints for obj find and alloc.
207 loc_flags_t loc_flags;
211 * Type of "printer" function used by lu_object_operations::loo_object_print()
214 * Printer function is needed to provide some flexibility in (semi-)debugging
215 * output: possible implementations: printk, CDEBUG, sysfs/seq_file
217 typedef int (*lu_printer_t)(const struct lu_env *env,
218 void *cookie, const char *format, ...)
219 __attribute__ ((format (printf, 3, 4)));
222 * Operations specific for particular lu_object.
224 struct lu_object_operations {
227 * Allocate lower-layer parts of the object by calling
228 * lu_device_operations::ldo_object_alloc() of the corresponding
231 * This method is called once for each object inserted into object
232 * stack. It's responsibility of this method to insert lower-layer
233 * object(s) it create into appropriate places of object stack.
235 int (*loo_object_init)(const struct lu_env *env,
237 const struct lu_object_conf *conf);
239 * Called (in top-to-bottom order) during object allocation after all
240 * layers were allocated and initialized. Can be used to perform
241 * initialization depending on lower layers.
243 int (*loo_object_start)(const struct lu_env *env,
244 struct lu_object *o);
246 * Called before lu_object_operations::loo_object_free() to signal
247 * that object is being destroyed. Dual to
248 * lu_object_operations::loo_object_init().
250 void (*loo_object_delete)(const struct lu_env *env,
251 struct lu_object *o);
253 * Dual to lu_device_operations::ldo_object_alloc(). Called when
254 * object is removed from memory. Must use call_rcu or kfree_rcu
255 * if the object contains an lu_object_header.
257 void (*loo_object_free)(const struct lu_env *env,
258 struct lu_object *o);
260 * Called when last active reference to the object is released (and
261 * object returns to the cache). This method is optional.
263 void (*loo_object_release)(const struct lu_env *env,
264 struct lu_object *o);
266 * Optional debugging helper. Print given object.
268 int (*loo_object_print)(const struct lu_env *env, void *cookie,
269 lu_printer_t p, const struct lu_object *o);
271 * Optional debugging method. Returns true iff method is internally
274 int (*loo_object_invariant)(const struct lu_object *o);
280 struct lu_device_type;
283 * Device: a layer in the server side abstraction stacking.
287 * reference count. This is incremented, in particular, on each object
288 * created at this layer.
290 * \todo XXX which means that atomic_t is probably too small.
294 * Pointer to device type. Never modified once set.
296 struct lu_device_type *ld_type;
298 * Operation vector for this device.
300 const struct lu_device_operations *ld_ops;
302 * Stack this device belongs to.
304 struct lu_site *ld_site;
305 struct proc_dir_entry *ld_proc_entry;
307 /** \todo XXX: temporary back pointer into obd. */
308 struct obd_device *ld_obd;
310 * A list of references to this object, for debugging.
312 struct lu_ref ld_reference;
314 * Link the device to the site.
316 struct list_head ld_linkage;
319 struct lu_device_type_operations;
322 * Tag bits for device type. They are used to distinguish certain groups of
326 /** this is meta-data device */
327 LU_DEVICE_MD = BIT(0),
328 /** this is data device */
329 LU_DEVICE_DT = BIT(1),
330 /** data device in the client stack */
331 LU_DEVICE_CL = BIT(2)
337 struct lu_device_type {
339 * Tag bits. Taken from enum lu_device_tag. Never modified once set.
343 * Name of this class. Unique system-wide. Never modified once set.
347 * Operations for this type.
349 const struct lu_device_type_operations *ldt_ops;
351 * \todo XXX: temporary: context tags used by obd_*() calls.
355 * Number of existing device type instances.
357 atomic_t ldt_device_nr;
361 * Operations on a device type.
363 struct lu_device_type_operations {
365 * Allocate new device.
367 struct lu_device *(*ldto_device_alloc)(const struct lu_env *env,
368 struct lu_device_type *t,
369 struct lustre_cfg *lcfg);
371 * Free device. Dual to
372 * lu_device_type_operations::ldto_device_alloc(). Returns pointer to
373 * the next device in the stack.
375 struct lu_device *(*ldto_device_free)(const struct lu_env *,
379 * Initialize the devices after allocation
381 int (*ldto_device_init)(const struct lu_env *env,
382 struct lu_device *, const char *,
385 * Finalize device. Dual to
386 * lu_device_type_operations::ldto_device_init(). Returns pointer to
387 * the next device in the stack.
389 struct lu_device *(*ldto_device_fini)(const struct lu_env *env,
392 * Initialize device type. This is called on module load.
394 int (*ldto_init)(struct lu_device_type *t);
396 * Finalize device type. Dual to
397 * lu_device_type_operations::ldto_init(). Called on module unload.
399 void (*ldto_fini)(struct lu_device_type *t);
401 * Called when the first device is created.
403 void (*ldto_start)(struct lu_device_type *t);
405 * Called when number of devices drops to 0.
407 void (*ldto_stop)(struct lu_device_type *t);
410 static inline int lu_device_is_md(const struct lu_device *d)
412 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD);
416 * Common object attributes.
427 /** modification time in seconds since Epoch */
429 /** access time in seconds since Epoch */
431 /** change time in seconds since Epoch */
433 /** create time in seconds since Epoch */
435 /** 512-byte blocks allocated to object */
437 /** permission bits and file type */
445 /** number of persistent references to this object */
447 /** blk bits of the object*/
449 /** blk size of the object*/
455 /** set layout version to OST objects. */
456 __u32 la_layout_version;
458 __u64 la_dirent_count;
461 #define LU_DIRENT_COUNT_UNSET ~0ULL
464 * Layer in the layered object.
468 * Header for this object.
470 struct lu_object_header *lo_header;
472 * Device for this layer.
474 struct lu_device *lo_dev;
476 * Operations for this object.
478 const struct lu_object_operations *lo_ops;
480 * Linkage into list of all layers.
482 struct list_head lo_linkage;
484 * Link to the device, for debugging.
486 struct lu_ref_link lo_dev_ref;
489 enum lu_object_header_flags {
491 * Don't keep this object in cache. Object will be destroyed as soon
492 * as last reference to it is released. This flag cannot be cleared
495 LU_OBJECT_HEARD_BANSHEE = 0,
497 * Mark this object has already been taken out of cache.
499 LU_OBJECT_UNHASHED = 1,
501 * Object is initialized, when object is found in cache, it may not be
502 * intialized yet, the object allocator will initialize it.
504 LU_OBJECT_INITED = 2,
507 enum lu_object_header_attr {
508 LOHA_EXISTS = BIT(0),
509 LOHA_REMOTE = BIT(1),
510 LOHA_HAS_AGENT_ENTRY = BIT(2),
512 * UNIX file type is stored in S_IFMT bits.
514 LOHA_FT_START = 001 << 12, /**< S_IFIFO */
515 LOHA_FT_END = 017 << 12, /**< S_IFMT */
519 * "Compound" object, consisting of multiple layers.
521 * Compound object with given fid is unique with given lu_site.
523 * Note, that object does *not* necessary correspond to the real object in the
524 * persistent storage: object is an anchor for locking and method calling, so
525 * it is created for things like not-yet-existing child created by mkdir or
526 * create calls. lu_object_operations::loo_exists() can be used to check
527 * whether object is backed by persistent storage entity.
528 * Any object containing this structre which might be placed in an
529 * rhashtable via loh_hash MUST be freed using call_rcu() or rcu_kfree().
531 struct lu_object_header {
533 * Fid, uniquely identifying this object.
535 struct lu_fid loh_fid;
537 * Object flags from enum lu_object_header_flags. Set and checked
540 unsigned long loh_flags;
542 * Object reference count. Protected by lu_site::ls_guard.
546 * Common object attributes, cached for efficiency. From enum
547 * lu_object_header_attr.
551 * Linkage into per-site hash table.
553 struct rhash_head loh_hash;
555 * Linkage into per-site LRU list. Protected by lu_site::ls_guard.
557 struct list_head loh_lru;
559 * Linkage into list of layers. Never modified once set (except lately
560 * during object destruction). No locking is necessary.
562 struct list_head loh_layers;
564 * A list of references to this object, for debugging.
566 struct lu_ref loh_reference;
568 * Handle used for kfree_rcu() or similar.
570 struct rcu_head loh_rcu;
580 LU_SS_CACHE_DEATH_RACE,
586 * lu_site is a "compartment" within which objects are unique, and LRU
587 * discipline is maintained.
589 * lu_site exists so that multiple layered stacks can co-exist in the same
592 * lu_site has the same relation to lu_device as lu_object_header to
599 struct rhashtable ls_obj_hash;
601 * buckets for summary data
603 struct lu_site_bkt_data *ls_bkts;
607 * index of bucket on hash table while purging
609 unsigned int ls_purge_start;
611 * Top-level device for this stack.
613 struct lu_device *ls_top_dev;
615 * Bottom-level device for this stack
617 struct lu_device *ls_bottom_dev;
619 * Linkage into global list of sites.
621 struct list_head ls_linkage;
623 * List for lu device for this site, protected
626 struct list_head ls_ld_linkage;
627 spinlock_t ls_ld_lock;
629 * Lock to serialize site purge.
631 struct mutex ls_purge_mutex;
635 struct lprocfs_stats *ls_stats;
637 * XXX: a hack! fld has to find md_site via site, remove when possible
639 struct seq_server_site *ld_seq_site;
641 * Pointer to the lu_target for this site.
643 struct lu_target *ls_tgt;
646 * Number of objects in lsb_lru_lists - used for shrinking
648 struct percpu_counter ls_lru_len_counter;
652 lu_site_wq_from_fid(struct lu_site *site, struct lu_fid *fid);
654 static inline struct seq_server_site *lu_site2seq(const struct lu_site *s)
656 return s->ld_seq_site;
660 * Constructors/destructors.
664 int lu_site_init (struct lu_site *s, struct lu_device *d);
665 void lu_site_fini (struct lu_site *s);
666 int lu_site_init_finish (struct lu_site *s);
667 void lu_stack_fini (const struct lu_env *env, struct lu_device *top);
668 void lu_device_get (struct lu_device *d);
669 void lu_device_put (struct lu_device *d);
670 int lu_device_init (struct lu_device *d, struct lu_device_type *t);
671 void lu_device_fini (struct lu_device *d);
672 int lu_object_header_init(struct lu_object_header *h);
673 void lu_object_header_fini(struct lu_object_header *h);
674 void lu_object_header_free(struct lu_object_header *h);
675 int lu_object_init (struct lu_object *o,
676 struct lu_object_header *h, struct lu_device *d);
677 void lu_object_fini (struct lu_object *o);
678 void lu_object_add_top (struct lu_object_header *h, struct lu_object *o);
679 void lu_object_add (struct lu_object *before, struct lu_object *o);
680 struct lu_object *lu_object_get_first(struct lu_object_header *h,
681 struct lu_device *dev);
682 void lu_dev_add_linkage(struct lu_site *s, struct lu_device *d);
683 void lu_dev_del_linkage(struct lu_site *s, struct lu_device *d);
686 * Helpers to initialize and finalize device types.
689 int lu_device_type_init(struct lu_device_type *ldt);
690 void lu_device_type_fini(struct lu_device_type *ldt);
695 * Caching and reference counting.
700 * Acquire additional reference to the given object. This function is used to
701 * attain additional reference. To acquire initial reference use
704 static inline void lu_object_get(struct lu_object *o)
706 LASSERT(atomic_read(&o->lo_header->loh_ref) > 0);
707 atomic_inc(&o->lo_header->loh_ref);
711 * Return true if object will not be cached after last reference to it is
714 static inline int lu_object_is_dying(const struct lu_object_header *h)
716 return test_bit(LU_OBJECT_HEARD_BANSHEE, &h->loh_flags);
720 * Return true if object is initialized.
722 static inline int lu_object_is_inited(const struct lu_object_header *h)
724 return test_bit(LU_OBJECT_INITED, &h->loh_flags);
727 void lu_object_put(const struct lu_env *env, struct lu_object *o);
728 void lu_object_put_nocache(const struct lu_env *env, struct lu_object *o);
729 void lu_object_unhash(const struct lu_env *env, struct lu_object *o);
730 int lu_site_purge_objects(const struct lu_env *env, struct lu_site *s, int nr,
733 static inline int lu_site_purge(const struct lu_env *env, struct lu_site *s,
736 return lu_site_purge_objects(env, s, nr, 1);
739 void lu_site_print(const struct lu_env *env, struct lu_site *s, atomic_t *ref,
740 int msg_flags, lu_printer_t printer);
741 struct lu_object *lu_object_find(const struct lu_env *env,
742 struct lu_device *dev, const struct lu_fid *f,
743 const struct lu_object_conf *conf);
744 struct lu_object *lu_object_find_at(const struct lu_env *env,
745 struct lu_device *dev,
746 const struct lu_fid *f,
747 const struct lu_object_conf *conf);
748 struct lu_object *lu_object_find_slice(const struct lu_env *env,
749 struct lu_device *dev,
750 const struct lu_fid *f,
751 const struct lu_object_conf *conf);
760 * First (topmost) sub-object of given compound object
762 static inline struct lu_object *lu_object_top(struct lu_object_header *h)
764 LASSERT(!list_empty(&h->loh_layers));
765 return container_of(h->loh_layers.next, struct lu_object, lo_linkage);
769 * Next sub-object in the layering
771 static inline struct lu_object *lu_object_next(const struct lu_object *o)
773 return container_of(o->lo_linkage.next, struct lu_object, lo_linkage);
777 * Pointer to the fid of this object.
779 static inline const struct lu_fid *lu_object_fid(const struct lu_object *o)
781 return &o->lo_header->loh_fid;
785 * return device operations vector for this object
787 static const inline struct lu_device_operations *
788 lu_object_ops(const struct lu_object *o)
790 return o->lo_dev->ld_ops;
794 * Given a compound object, find its slice, corresponding to the device type
797 struct lu_object *lu_object_locate(struct lu_object_header *h,
798 const struct lu_device_type *dtype);
801 * Printer function emitting messages through libcfs_debug_msg().
803 int lu_cdebug_printer(const struct lu_env *env,
804 void *cookie, const char *format, ...);
807 * Print object description followed by a user-supplied message.
809 #define LU_OBJECT_DEBUG(mask, env, object, format, ...) \
811 if (cfs_cdebug_show(mask, DEBUG_SUBSYSTEM)) { \
812 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, mask, NULL); \
813 lu_object_print(env, &msgdata, lu_cdebug_printer, object);\
814 CDEBUG(mask, format "\n", ## __VA_ARGS__); \
819 * Print short object description followed by a user-supplied message.
821 #define LU_OBJECT_HEADER(mask, env, object, format, ...) \
823 if (cfs_cdebug_show(mask, DEBUG_SUBSYSTEM)) { \
824 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, mask, NULL); \
825 lu_object_header_print(env, &msgdata, lu_cdebug_printer,\
826 (object)->lo_header); \
827 lu_cdebug_printer(env, &msgdata, "\n"); \
828 CDEBUG(mask, format , ## __VA_ARGS__); \
832 void lu_object_print (const struct lu_env *env, void *cookie,
833 lu_printer_t printer, const struct lu_object *o);
834 void lu_object_header_print(const struct lu_env *env, void *cookie,
835 lu_printer_t printer,
836 const struct lu_object_header *hdr);
839 * Check object consistency.
841 int lu_object_invariant(const struct lu_object *o);
845 * Check whether object exists, no matter on local or remote storage.
846 * Note: LOHA_EXISTS will be set once some one created the object,
847 * and it does not needs to be committed to storage.
849 #define lu_object_exists(o) ((o)->lo_header->loh_attr & LOHA_EXISTS)
852 * Check whether object on the remote storage.
854 #define lu_object_remote(o) unlikely((o)->lo_header->loh_attr & LOHA_REMOTE)
857 * Check whether the object as agent entry on current target
859 #define lu_object_has_agent_entry(o) \
860 unlikely((o)->lo_header->loh_attr & LOHA_HAS_AGENT_ENTRY)
862 static inline void lu_object_set_agent_entry(struct lu_object *o)
864 o->lo_header->loh_attr |= LOHA_HAS_AGENT_ENTRY;
867 static inline void lu_object_clear_agent_entry(struct lu_object *o)
869 o->lo_header->loh_attr &= ~LOHA_HAS_AGENT_ENTRY;
872 static inline int lu_object_assert_exists(const struct lu_object *o)
874 return lu_object_exists(o);
877 static inline int lu_object_assert_not_exists(const struct lu_object *o)
879 return !lu_object_exists(o);
883 * Attr of this object.
885 static inline __u32 lu_object_attr(const struct lu_object *o)
887 LASSERT(lu_object_exists(o) != 0);
889 return o->lo_header->loh_attr & S_IFMT;
892 static inline void lu_object_ref_add_atomic(struct lu_object *o,
896 lu_ref_add_atomic(&o->lo_header->loh_reference, scope, source);
899 static inline void lu_object_ref_add(struct lu_object *o,
903 lu_ref_add(&o->lo_header->loh_reference, scope, source);
906 static inline void lu_object_ref_add_at(struct lu_object *o,
907 struct lu_ref_link *link,
911 lu_ref_add_at(&o->lo_header->loh_reference, link, scope, source);
914 static inline void lu_object_ref_del(struct lu_object *o,
915 const char *scope, const void *source)
917 lu_ref_del(&o->lo_header->loh_reference, scope, source);
920 static inline void lu_object_ref_del_at(struct lu_object *o,
921 struct lu_ref_link *link,
922 const char *scope, const void *source)
924 lu_ref_del_at(&o->lo_header->loh_reference, link, scope, source);
927 /** input params, should be filled out by mdt */
931 /** count in bytes */
932 unsigned int rp_count;
933 /** number of pages */
934 unsigned int rp_npages;
935 /** requested attr */
937 /** pointers to pages */
938 struct page **rp_pages;
941 enum lu_xattr_flags {
942 LU_XATTR_REPLACE = BIT(0),
943 LU_XATTR_CREATE = BIT(1),
944 LU_XATTR_MERGE = BIT(2),
945 LU_XATTR_SPLIT = BIT(3),
946 LU_XATTR_PURGE = BIT(4),
954 /** For lu_context health-checks */
955 enum lu_context_state {
964 * lu_context. Execution context for lu_object methods. Currently associated
967 * All lu_object methods, except device and device type methods (called during
968 * system initialization and shutdown) are executed "within" some
969 * lu_context. This means, that pointer to some "current" lu_context is passed
970 * as an argument to all methods.
972 * All service ptlrpc threads create lu_context as part of their
973 * initialization. It is possible to create "stand-alone" context for other
974 * execution environments (like system calls).
976 * lu_object methods mainly use lu_context through lu_context_key interface
977 * that allows each layer to associate arbitrary pieces of data with each
978 * context (see pthread_key_create(3) for similar interface).
980 * On a client, lu_context is bound to a thread, see cl_env_get().
982 * \see lu_context_key
986 * lu_context is used on the client side too. Yet we don't want to
987 * allocate values of server-side keys for the client contexts and
990 * To achieve this, set of tags in introduced. Contexts and keys are
991 * marked with tags. Key value are created only for context whose set
992 * of tags has non-empty intersection with one for key. Tags are taken
993 * from enum lu_context_tag.
996 enum lu_context_state lc_state;
998 * Pointer to the home service thread. NULL for other execution
1001 struct ptlrpc_thread *lc_thread;
1003 * Pointer to an array with key values. Internal implementation
1008 * Linkage into a list of all remembered contexts. Only
1009 * `non-transient' contexts, i.e., ones created for service threads
1012 struct list_head lc_remember;
1014 * Version counter used to skip calls to lu_context_refill() when no
1015 * keys were registered.
1017 unsigned lc_version;
1025 * lu_context_key interface. Similar to pthread_key.
1028 enum lu_context_tag {
1030 * Thread on md server
1032 LCT_MD_THREAD = BIT(0),
1034 * Thread on dt server
1036 LCT_DT_THREAD = BIT(1),
1040 LCT_CL_THREAD = BIT(3),
1042 * A per-request session on a server, and a per-system-call session on
1045 LCT_SESSION = BIT(4),
1047 * A per-request data on OSP device
1049 LCT_OSP_THREAD = BIT(5),
1053 LCT_MG_THREAD = BIT(6),
1055 * Context for local operations
1059 * session for server thread
1061 LCT_SERVER_SESSION = BIT(8),
1063 * Set when at least one of keys, having values in this context has
1064 * non-NULL lu_context_key::lct_exit() method. This is used to
1065 * optimize lu_context_exit() call.
1067 LCT_HAS_EXIT = BIT(28),
1069 * Don't add references for modules creating key values in that context.
1070 * This is only for contexts used internally by lu_object framework.
1072 LCT_NOREF = BIT(29),
1074 * Key is being prepared for retiring, don't create new values for it.
1076 LCT_QUIESCENT = BIT(30),
1078 * Context should be remembered.
1080 LCT_REMEMBER = BIT(31),
1082 * Contexts usable in cache shrinker thread.
1084 LCT_SHRINKER = LCT_MD_THREAD|LCT_DT_THREAD|LCT_CL_THREAD|LCT_NOREF,
1088 * Key. Represents per-context value slot.
1090 * Keys are usually registered when module owning the key is initialized, and
1091 * de-registered when module is unloaded. Once key is registered, all new
1092 * contexts with matching tags, will get key value. "Old" contexts, already
1093 * initialized at the time of key registration, can be forced to get key value
1094 * by calling lu_context_refill().
1096 * Every key value is counted in lu_context_key::lct_used and acquires a
1097 * reference on an owning module. This means, that all key values have to be
1098 * destroyed before module can be unloaded. This is usually achieved by
1099 * stopping threads started by the module, that created contexts in their
1100 * entry functions. Situation is complicated by the threads shared by multiple
1101 * modules, like ptlrpcd daemon on a client. To work around this problem,
1102 * contexts, created in such threads, are `remembered' (see
1103 * LCT_REMEMBER)---i.e., added into a global list. When module is preparing
1104 * for unloading it does the following:
1106 * - marks its keys as `quiescent' (lu_context_tag::LCT_QUIESCENT)
1107 * preventing new key values from being allocated in the new contexts,
1110 * - scans a list of remembered contexts, destroying values of module
1111 * keys, thus releasing references to the module.
1113 * This is done by lu_context_key_quiesce(). If module is re-activated
1114 * before key has been de-registered, lu_context_key_revive() call clears
1115 * `quiescent' marker.
1117 * lu_context code doesn't provide any internal synchronization for these
1118 * activities---it's assumed that startup (including threads start-up) and
1119 * shutdown are serialized by some external means.
1123 struct lu_context_key {
1125 * Set of tags for which values of this key are to be instantiated.
1129 * Value constructor. This is called when new value is created for a
1130 * context. Returns pointer to new value of error pointer.
1132 void *(*lct_init)(const struct lu_context *ctx,
1133 struct lu_context_key *key);
1135 * Value destructor. Called when context with previously allocated
1136 * value of this slot is destroyed. \a data is a value that was returned
1137 * by a matching call to lu_context_key::lct_init().
1139 void (*lct_fini)(const struct lu_context *ctx,
1140 struct lu_context_key *key, void *data);
1142 * Optional method called on lu_context_exit() for all allocated
1143 * keys. Can be used by debugging code checking that locks are
1146 void (*lct_exit)(const struct lu_context *ctx,
1147 struct lu_context_key *key, void *data);
1149 * Internal implementation detail: index within lu_context::lc_value[]
1150 * reserved for this key.
1154 * Internal implementation detail: number of values created for this
1159 * Internal implementation detail: module for this key.
1161 struct module *lct_owner;
1163 * References to this key. For debugging.
1165 struct lu_ref lct_reference;
1168 #define LU_KEY_INIT(mod, type) \
1169 static void *mod##_key_init(const struct lu_context *ctx, \
1170 struct lu_context_key *key) \
1174 BUILD_BUG_ON(PAGE_SIZE < sizeof(*value)); \
1176 OBD_ALLOC_PTR(value); \
1177 if (value == NULL) \
1178 value = ERR_PTR(-ENOMEM); \
1182 struct __##mod##__dummy_init { ; } /* semicolon catcher */
1184 #define LU_KEY_FINI(mod, type) \
1185 static void mod##_key_fini(const struct lu_context *ctx, \
1186 struct lu_context_key *key, void* data) \
1188 type *info = data; \
1190 OBD_FREE_PTR(info); \
1192 struct __##mod##__dummy_fini {;} /* semicolon catcher */
1194 #define LU_KEY_INIT_FINI(mod, type) \
1195 LU_KEY_INIT(mod,type); \
1196 LU_KEY_FINI(mod,type)
1198 #define LU_CONTEXT_KEY_DEFINE(mod, tags) \
1199 struct lu_context_key mod##_thread_key = { \
1201 .lct_init = mod##_key_init, \
1202 .lct_fini = mod##_key_fini \
1205 #define LU_CONTEXT_KEY_INIT(key) \
1207 (key)->lct_owner = THIS_MODULE; \
1210 int lu_context_key_register(struct lu_context_key *key);
1211 void lu_context_key_degister(struct lu_context_key *key);
1212 void *lu_context_key_get (const struct lu_context *ctx,
1213 const struct lu_context_key *key);
1214 void lu_context_key_quiesce(struct lu_device_type *t,
1215 struct lu_context_key *key);
1216 void lu_context_key_revive(struct lu_context_key *key);
1220 * LU_KEY_INIT_GENERIC() has to be a macro to correctly determine an
1224 #define LU_KEY_INIT_GENERIC(mod) \
1225 static void mod##_key_init_generic(struct lu_context_key *k, ...) \
1227 struct lu_context_key *key = k; \
1230 va_start(args, k); \
1232 LU_CONTEXT_KEY_INIT(key); \
1233 key = va_arg(args, struct lu_context_key *); \
1234 } while (key != NULL); \
1238 #define LU_TYPE_INIT(mod, ...) \
1239 LU_KEY_INIT_GENERIC(mod) \
1240 static int mod##_type_init(struct lu_device_type *t) \
1242 mod##_key_init_generic(__VA_ARGS__, NULL); \
1243 return lu_context_key_register_many(__VA_ARGS__, NULL); \
1245 struct __##mod##_dummy_type_init {;}
1247 #define LU_TYPE_FINI(mod, ...) \
1248 static void mod##_type_fini(struct lu_device_type *t) \
1250 lu_context_key_degister_many(__VA_ARGS__, NULL); \
1252 struct __##mod##_dummy_type_fini {;}
1254 #define LU_TYPE_START(mod, ...) \
1255 static void mod##_type_start(struct lu_device_type *t) \
1257 lu_context_key_revive_many(__VA_ARGS__, NULL); \
1259 struct __##mod##_dummy_type_start {;}
1261 #define LU_TYPE_STOP(mod, ...) \
1262 static void mod##_type_stop(struct lu_device_type *t) \
1264 lu_context_key_quiesce_many(t, __VA_ARGS__, NULL); \
1266 struct __##mod##_dummy_type_stop { }
1270 #define LU_TYPE_INIT_FINI(mod, ...) \
1271 LU_TYPE_INIT(mod, __VA_ARGS__); \
1272 LU_TYPE_FINI(mod, __VA_ARGS__); \
1273 LU_TYPE_START(mod, __VA_ARGS__); \
1274 LU_TYPE_STOP(mod, __VA_ARGS__)
1276 int lu_context_init (struct lu_context *ctx, __u32 tags);
1277 void lu_context_fini (struct lu_context *ctx);
1278 void lu_context_enter (struct lu_context *ctx);
1279 void lu_context_exit (struct lu_context *ctx);
1280 int lu_context_refill(struct lu_context *ctx);
1283 * Helper functions to operate on multiple keys. These are used by the default
1284 * device type operations, defined by LU_TYPE_INIT_FINI().
1287 int lu_context_key_register_many(struct lu_context_key *k, ...);
1288 void lu_context_key_degister_many(struct lu_context_key *k, ...);
1289 void lu_context_key_revive_many (struct lu_context_key *k, ...);
1290 void lu_context_key_quiesce_many(struct lu_device_type *t,
1291 struct lu_context_key *k, ...);
1294 * update/clear ctx/ses tags.
1296 void lu_context_tags_update(__u32 tags);
1297 void lu_context_tags_clear(__u32 tags);
1298 void lu_session_tags_update(__u32 tags);
1299 void lu_session_tags_clear(__u32 tags);
1306 * "Local" context, used to store data instead of stack.
1308 struct lu_context le_ctx;
1310 * "Session" context for per-request data.
1312 struct lu_context *le_ses;
1315 int lu_env_init (struct lu_env *env, __u32 tags);
1316 void lu_env_fini (struct lu_env *env);
1317 int lu_env_refill(struct lu_env *env);
1318 int lu_env_refill_by_tags(struct lu_env *env, __u32 ctags, __u32 stags);
1320 static inline void* lu_env_info(const struct lu_env *env,
1321 const struct lu_context_key *key)
1324 info = lu_context_key_get(&env->le_ctx, key);
1326 if (!lu_env_refill((struct lu_env *)env))
1327 info = lu_context_key_get(&env->le_ctx, key);
1333 struct lu_env *lu_env_find(void);
1334 int lu_env_add(struct lu_env *env);
1335 int lu_env_add_task(struct lu_env *env, struct task_struct *task);
1336 void lu_env_remove(struct lu_env *env);
1338 /** @} lu_context */
1341 * Output site statistical counters into a buffer. Suitable for
1342 * ll_rd_*()-style functions.
1344 int lu_site_stats_seq_print(const struct lu_site *s, struct seq_file *m);
1347 * Common name structure to be passed around for various name related methods.
1350 const char *ln_name;
1354 static inline bool name_is_dot_or_dotdot(const char *name, int namelen)
1356 return name[0] == '.' &&
1357 (namelen == 1 || (namelen == 2 && name[1] == '.'));
1360 static inline bool lu_name_is_dot_or_dotdot(const struct lu_name *lname)
1362 return name_is_dot_or_dotdot(lname->ln_name, lname->ln_namelen);
1366 * Determine if filename should be considered a "temporary" name.
1368 * For temporary names, use only the main part of the filename and ignore
1369 * the suffix, so that the filename will hash to the same MDT after it is
1370 * renamed. That avoids creating spurious remote entries for rsync, dcp,
1371 * vi, and other tools that create a temporary name before renaming the file.
1373 * The "CRUSH" and "CRUSH2" hash types are slightly different, and should
1374 * not be modified without introducing a new hash type. The hash algorithm
1375 * forms an important part of the network protocol for striped directories,
1376 * so if the hash function were "fixed" in any way it would prevent clients
1377 * from looking up a filename on the right MDT. LU-15692.
1379 * \param[in] name filename
1380 * \param[in] namelen length of @name
1381 * \param[in] dot_prefix if @name needs a leading '.' to be temporary
1382 * \param[in] suffixlen number of characters after '.' in @name to check
1383 * \param[in] crush2 whether CRUSH or CRUSH2 heuristic should be used
1385 static inline bool lu_name_is_temp_file(const char *name, int namelen,
1386 bool dot_prefix, int suffixlen,
1392 int len = suffixlen;
1394 if (dot_prefix && name[0] != '.')
1397 if (namelen < dot_prefix + suffixlen + 2 ||
1398 name[namelen - suffixlen - 1] != '.')
1401 /* Any non-alphanumeric chars in the suffix for CRUSH2 mean the
1402 * filename is *not* temporary. The original CRUSH was incorrectly
1403 * matching if a '.' happens to be in the right place, for example
1404 * file.mdtest.12.12345 or output.6334.log, which is bad. LU-15692
1407 if (islower(name[namelen - len]))
1409 else if (isupper(name[namelen - len]))
1411 else if (isdigit(name[namelen - len]))
1418 /* mktemp() suffixes normally have a mix of upper- and lower-case
1419 * letters and/or digits, rarely all upper- or lower-case or digits.
1420 * Random all-digit suffixes are rare (1/45k for suffixlen=6), but
1421 * common in normal usage (incrementing versions, dates, ranks, etc),
1422 * so are considered non-temporary even if 1 or 2 non-numeric chars.
1424 * About 0.07% of randomly-generated names will slip through, which
1425 * only means that they may be renamed to a different MDT (slowdown),
1426 * but this avoids 99.93% of cross-MDT renames for those files.
1428 if (upper == suffixlen || lower == suffixlen)
1432 if (digit >= suffixlen - 1 &&
1433 isdigit(name[namelen - suffixlen]))
1435 } else { /* old crush incorrectly returns "true" for all-digit suffix */
1436 if (digit >= suffixlen - 1 &&
1437 !isdigit(name[namelen - suffixlen]))
1444 static inline bool lu_name_is_backup_file(const char *name, int namelen,
1448 name[namelen - 2] != '.' && name[namelen - 1] == '~') {
1454 if (namelen > 4 && name[namelen - 4] == '.' &&
1455 (!strncasecmp(name + namelen - 3, "bak", 3) ||
1456 !strncasecmp(name + namelen - 3, "sav", 3))) {
1462 if (namelen > 5 && name[namelen - 5] == '.' &&
1463 !strncasecmp(name + namelen - 4, "orig", 4)) {
1472 static inline bool lu_name_is_valid_len(const char *name, size_t name_len)
1474 return name != NULL &&
1476 name_len < INT_MAX &&
1477 strlen(name) == name_len &&
1478 memchr(name, '/', name_len) == NULL;
1482 * Validate names (path components)
1484 * To be valid \a name must be non-empty, '\0' terminated of length \a
1485 * name_len, and not contain '/'. The maximum length of a name (before
1486 * say -ENAMETOOLONG will be returned) is really controlled by llite
1487 * and the server. We only check for something insane coming from bad
1488 * integer handling here.
1490 static inline bool lu_name_is_valid_2(const char *name, size_t name_len)
1492 return lu_name_is_valid_len(name, name_len) && name[name_len] == '\0';
1495 static inline bool lu_name_is_valid(const struct lu_name *ln)
1497 return lu_name_is_valid_2(ln->ln_name, ln->ln_namelen);
1500 #define DNAME "%.*s"
1502 (lu_name_is_valid(ln) ? (ln)->ln_namelen : 0), \
1503 (lu_name_is_valid(ln) ? (ln)->ln_name : "")
1506 * Common buffer structure to be passed around for various xattr_{s,g}et()
1514 #define DLUBUF "(%p %zu)"
1515 #define PLUBUF(buf) (buf)->lb_buf, (buf)->lb_len
1517 /* read buffer params, should be filled out by out */
1519 /** number of buffers */
1520 unsigned int rb_nbufs;
1521 /** pointers to buffers */
1522 struct lu_buf rb_bufs[];
1526 * One-time initializers, called at obdclass module initialization, not
1531 * Initialization of global lu_* data.
1533 int lu_global_init(void);
1536 * Dual to lu_global_init().
1538 void lu_global_fini(void);
1540 struct lu_kmem_descr {
1541 struct kmem_cache **ckd_cache;
1542 const char *ckd_name;
1543 const size_t ckd_size;
1546 int lu_kmem_init(struct lu_kmem_descr *caches);
1547 void lu_kmem_fini(struct lu_kmem_descr *caches);
1549 void lu_object_assign_fid(const struct lu_env *env, struct lu_object *o,
1550 const struct lu_fid *fid);
1551 struct lu_object *lu_object_anon(const struct lu_env *env,
1552 struct lu_device *dev,
1553 const struct lu_object_conf *conf);
1556 extern struct lu_buf LU_BUF_NULL;
1558 void lu_buf_free(struct lu_buf *buf);
1559 void lu_buf_alloc(struct lu_buf *buf, size_t size);
1560 void lu_buf_realloc(struct lu_buf *buf, size_t size);
1562 int lu_buf_check_and_grow(struct lu_buf *buf, size_t len);
1563 struct lu_buf *lu_buf_check_and_alloc(struct lu_buf *buf, size_t len);
1565 extern __u32 lu_context_tags_default;
1566 extern __u32 lu_session_tags_default;
1568 static inline bool lu_device_is_cl(const struct lu_device *d)
1570 return d->ld_type->ldt_tags & LU_DEVICE_CL;
1573 static inline bool lu_object_is_cl(const struct lu_object *o)
1575 return lu_device_is_cl(o->lo_dev);
1578 /* Generic subset of tgts */
1579 struct lu_tgt_pool {
1580 __u32 *op_array; /* array of index of
1583 unsigned int op_count; /* number of tgts in the array */
1584 unsigned int op_size; /* allocated size of op_array */
1585 struct rw_semaphore op_rw_sem; /* to protect lu_tgt_pool use */
1588 int lu_tgt_pool_init(struct lu_tgt_pool *op, unsigned int count);
1589 int lu_tgt_pool_add(struct lu_tgt_pool *op, __u32 idx, unsigned int min_count);
1590 int lu_tgt_pool_remove(struct lu_tgt_pool *op, __u32 idx);
1591 void lu_tgt_pool_free(struct lu_tgt_pool *op);
1592 int lu_tgt_check_index(int idx, struct lu_tgt_pool *osts);
1593 int lu_tgt_pool_extend(struct lu_tgt_pool *op, unsigned int min_count);
1595 /* bitflags used in rr / qos allocation */
1597 LQ_DIRTY = 0, /* recalc qos data */
1598 LQ_SAME_SPACE, /* the OSTs all have approx.
1599 * the same space avail */
1600 LQ_RESET, /* zero current penalties */
1601 LQ_SF_PROGRESS, /* statfs op in progress */
1604 #ifdef HAVE_SERVER_SUPPORT
1605 /* round-robin QoS data for LOD/LMV */
1607 spinlock_t lqr_alloc; /* protect allocation index */
1608 atomic_t lqr_start_idx; /* start index of new inode */
1609 __u32 lqr_offset_idx;/* aliasing for start_idx */
1610 int lqr_start_count;/* reseed counter */
1611 struct lu_tgt_pool lqr_pool; /* round-robin optimized list */
1612 unsigned long lqr_flags;
1615 static inline void lu_qos_rr_init(struct lu_qos_rr *lqr)
1617 spin_lock_init(&lqr->lqr_alloc);
1618 set_bit(LQ_DIRTY, &lqr->lqr_flags);
1621 #endif /* HAVE_SERVER_SUPPORT */
1623 /* QoS data per MDS/OSS */
1625 struct obd_uuid lsq_uuid; /* ptlrpc's c_remote_uuid */
1626 struct list_head lsq_svr_list; /* link to lq_svr_list */
1627 __u64 lsq_bavail; /* total bytes avail on svr */
1628 __u64 lsq_iavail; /* total inode avail on svr */
1629 __u64 lsq_penalty; /* current penalty */
1630 __u64 lsq_penalty_per_obj; /* penalty decrease
1632 time64_t lsq_used; /* last used time, seconds */
1633 __u32 lsq_tgt_count; /* number of tgts on this svr */
1634 __u32 lsq_id; /* unique svr id */
1637 /* QoS data per MDT/OST */
1639 struct lu_svr_qos *ltq_svr; /* svr info */
1640 __u64 ltq_penalty; /* current penalty */
1641 __u64 ltq_penalty_per_obj; /* penalty decrease
1643 __u64 ltq_avail; /* bytes/inode avail */
1644 __u64 ltq_weight; /* net weighting */
1645 time64_t ltq_used; /* last used time, seconds */
1646 bool ltq_usable:1; /* usable for striping */
1649 /* target descriptor */
1650 #define LOV_QOS_DEF_THRESHOLD_RR_PCT 17
1651 #define LMV_QOS_DEF_THRESHOLD_RR_PCT 5
1653 #define LOV_QOS_DEF_PRIO_FREE 90
1654 #define LMV_QOS_DEF_PRIO_FREE 90
1656 struct lu_tgt_desc {
1658 struct dt_device *ltd_tgt;
1659 struct obd_device *ltd_obd;
1661 struct obd_export *ltd_exp;
1662 struct obd_uuid ltd_uuid;
1665 struct list_head ltd_kill;
1666 struct task_struct *ltd_recovery_task;
1667 struct mutex ltd_fid_mutex;
1668 struct lu_tgt_qos ltd_qos; /* qos info per target */
1669 struct obd_statfs ltd_statfs;
1670 time64_t ltd_statfs_age;
1671 unsigned long ltd_active:1,/* is this target up for requests */
1672 ltd_activate:1,/* should target be activated */
1673 ltd_reap:1, /* should this target be deleted */
1674 ltd_got_update_log:1, /* Already got update log */
1675 ltd_connecting:1; /* target is connecting */
1678 static inline __u64 tgt_statfs_bavail(struct lu_tgt_desc *tgt)
1680 struct obd_statfs *statfs = &tgt->ltd_statfs;
1682 return statfs->os_bavail * statfs->os_bsize;
1685 static inline __u64 tgt_statfs_iavail(struct lu_tgt_desc *tgt)
1687 return tgt->ltd_statfs.os_ffree;
1690 /* number of pointers at 2nd level */
1691 #define TGT_PTRS_PER_BLOCK (PAGE_SIZE / sizeof(void *))
1692 /* number of pointers at 1st level - only need as many as max OST/MDT count */
1693 #define TGT_PTRS ((LOV_ALL_STRIPES + 1) / TGT_PTRS_PER_BLOCK)
1695 struct lu_tgt_desc_idx {
1696 struct lu_tgt_desc *ldi_tgt[TGT_PTRS_PER_BLOCK];
1700 /* QoS data for LOD/LMV */
1701 #define QOS_THRESHOLD_MAX 256 /* should be power of two */
1703 struct list_head lq_svr_list; /* lu_svr_qos list */
1704 struct rw_semaphore lq_rw_sem;
1705 __u32 lq_active_svr_count;
1706 unsigned int lq_prio_free; /* priority for free space */
1707 unsigned int lq_threshold_rr;/* priority for rr */
1708 #ifdef HAVE_SERVER_SUPPORT
1709 struct lu_qos_rr lq_rr; /* round robin qos data */
1711 unsigned long lq_flags;
1713 unsigned long lq_dirty:1, /* recalc qos data */
1714 lq_same_space:1,/* the servers all have approx.
1715 * the same space avail */
1716 lq_reset:1; /* zero current penalties */
1720 struct lu_tgt_descs {
1722 struct lov_desc ltd_lov_desc;
1723 struct lmv_desc ltd_lmv_desc;
1725 /* list of known TGTs */
1726 struct lu_tgt_desc_idx *ltd_tgt_idx[TGT_PTRS];
1727 /* Size of the lu_tgts array, granted to be a power of 2 */
1728 __u32 ltd_tgts_size;
1729 /* bitmap of TGTs available */
1730 unsigned long *ltd_tgt_bitmap;
1731 /* TGTs scheduled to be deleted */
1732 __u32 ltd_death_row;
1733 /* Table refcount used for delayed deletion */
1735 /* mutex to serialize concurrent updates to the tgt table */
1736 struct mutex ltd_mutex;
1737 /* read/write semaphore used for array relocation */
1738 struct rw_semaphore ltd_rw_sem;
1740 struct lu_qos ltd_qos;
1741 /* all tgts in a packed array */
1742 struct lu_tgt_pool ltd_tgt_pool;
1743 /* true if tgt is MDT */
1747 #define LTD_TGT(ltd, index) \
1748 (ltd)->ltd_tgt_idx[(index) / TGT_PTRS_PER_BLOCK]-> \
1749 ldi_tgt[(index) % TGT_PTRS_PER_BLOCK]
1751 u64 lu_prandom_u64_max(u64 ep_ro);
1752 int lu_qos_add_tgt(struct lu_qos *qos, struct lu_tgt_desc *ltd);
1753 int lu_qos_del_tgt(struct lu_qos *qos, struct lu_tgt_desc *ltd);
1754 void lu_tgt_qos_weight_calc(struct lu_tgt_desc *tgt, bool is_mdt);
1756 int lu_tgt_descs_init(struct lu_tgt_descs *ltd, bool is_mdt);
1757 void lu_tgt_descs_fini(struct lu_tgt_descs *ltd);
1758 int ltd_add_tgt(struct lu_tgt_descs *ltd, struct lu_tgt_desc *tgt);
1759 void ltd_del_tgt(struct lu_tgt_descs *ltd, struct lu_tgt_desc *tgt);
1760 int ltd_qos_penalties_calc(struct lu_tgt_descs *ltd);
1761 int ltd_qos_update(struct lu_tgt_descs *ltd, struct lu_tgt_desc *tgt,
1765 * Whether MDT inode and space usages are balanced.
1767 static inline bool ltd_qos_is_balanced(struct lu_tgt_descs *ltd)
1769 return !test_bit(LQ_DIRTY, <d->ltd_qos.lq_flags) &&
1770 test_bit(LQ_SAME_SPACE, <d->ltd_qos.lq_flags);
1774 * Whether QoS data is up-to-date and QoS can be applied.
1776 static inline bool ltd_qos_is_usable(struct lu_tgt_descs *ltd)
1778 if (ltd_qos_is_balanced(ltd))
1781 if (ltd->ltd_lov_desc.ld_active_tgt_count < 2)
1787 static inline struct lu_tgt_desc *ltd_first_tgt(struct lu_tgt_descs *ltd)
1791 index = find_first_bit(ltd->ltd_tgt_bitmap,
1792 ltd->ltd_tgts_size);
1793 return (index < ltd->ltd_tgts_size) ? LTD_TGT(ltd, index) : NULL;
1796 static inline struct lu_tgt_desc *ltd_next_tgt(struct lu_tgt_descs *ltd,
1797 struct lu_tgt_desc *tgt)
1804 index = tgt->ltd_index;
1805 LASSERT(index < ltd->ltd_tgts_size);
1806 index = find_next_bit(ltd->ltd_tgt_bitmap,
1807 ltd->ltd_tgts_size, index + 1);
1808 return (index < ltd->ltd_tgts_size) ? LTD_TGT(ltd, index) : NULL;
1811 #define ltd_foreach_tgt(ltd, tgt) \
1812 for (tgt = ltd_first_tgt(ltd); tgt; tgt = ltd_next_tgt(ltd, tgt))
1814 #define ltd_foreach_tgt_safe(ltd, tgt, tmp) \
1815 for (tgt = ltd_first_tgt(ltd), tmp = ltd_next_tgt(ltd, tgt); tgt; \
1816 tgt = tmp, tmp = ltd_next_tgt(ltd, tgt))
1819 #endif /* __LUSTRE_LU_OBJECT_H */