X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Finclude%2Flustre_osc.h;fp=lustre%2Fosc%2Fosc_cl_internal.h;h=77ee34bfb1fba9f81d2e2119698cfef62503f178;hp=f9b9faf3b21085445c31422db566761b101364ca;hb=036d987c6d716d2e3d8f5a12800b44f3cd01bb9c;hpb=e207f9f96fc51f3b6d219193cca3d83aaa99b3e8 diff --git a/lustre/osc/osc_cl_internal.h b/lustre/include/lustre_osc.h similarity index 73% rename from lustre/osc/osc_cl_internal.h rename to lustre/include/lustre_osc.h index f9b9faf..77ee34b 100644 --- a/lustre/osc/osc_cl_internal.h +++ b/lustre/include/lustre_osc.h @@ -30,28 +30,100 @@ * Lustre is a trademark of Sun Microsystems, Inc. */ /* - * This file is part of Lustre, http://www.lustre.org/ - * Lustre is a trademark of Sun Microsystems, Inc. + * lustre/include/lustre_osc.h + * + * OSC layer structures and methods common for both OSC and MDC. * - * Internal interfaces of OSC layer. + * This file contains OSC interfaces used by OSC and MDC. Most of them + * were just moved from lustre/osc/osc_cl_internal.h for Data-on-MDT + * purposes. * * Author: Nikita Danilov * Author: Jinshan Xiong + * Author: Mikhail Pershin */ -#ifndef OSC_CL_INTERNAL_H -#define OSC_CL_INTERNAL_H +#ifndef LUSTRE_OSC_H +#define LUSTRE_OSC_H #include #include -/* osc_build_res_name() */ #include -#include "osc_internal.h" /** \defgroup osc osc * @{ */ +struct osc_quota_info { + /** linkage for quota hash table */ + struct hlist_node oqi_hash; + __u32 oqi_id; +}; + +enum async_flags { + ASYNC_READY = 0x1, /* ap_make_ready will not be called before this + page is added to an rpc */ + ASYNC_URGENT = 0x2, /* page must be put into an RPC before return */ + ASYNC_COUNT_STABLE = 0x4, /* ap_refresh_count will not be called + to give the caller a chance to update + or cancel the size of the io */ + ASYNC_HP = 0x10, +}; + +struct osc_async_page { + int oap_magic; + unsigned short oap_cmd; + unsigned short oap_interrupted:1; + + struct list_head oap_pending_item; + struct list_head oap_rpc_item; + + loff_t oap_obj_off; + unsigned oap_page_off; + enum async_flags oap_async_flags; + + struct brw_page oap_brw_page; + + struct ptlrpc_request *oap_request; + struct client_obd *oap_cli; + struct osc_object *oap_obj; + + spinlock_t oap_lock; +}; + +#define oap_page oap_brw_page.pg +#define oap_count oap_brw_page.count +#define oap_brw_flags oap_brw_page.flag + +static inline struct osc_async_page *brw_page2oap(struct brw_page *pga) +{ + return container_of(pga, struct osc_async_page, oap_brw_page); +} + +struct osc_cache_waiter { + struct list_head ocw_entry; + wait_queue_head_t ocw_waitq; + struct osc_async_page *ocw_oap; + int ocw_grant; + int ocw_rc; +}; + +struct osc_device { + struct cl_device od_cl; + struct obd_export *od_exp; + + /* Write stats is actually protected by client_obd's lock. */ + struct osc_stats { + uint64_t os_lockless_writes; /* by bytes */ + uint64_t os_lockless_reads; /* by bytes */ + uint64_t os_lockless_truncates; /* by times */ + } od_stats; + + /* configuration item(s) */ + int od_contention_time; + int od_lockless_truncate; +}; + struct osc_extent; /** @@ -78,8 +150,8 @@ struct osc_io { struct obdo oi_oa; struct osc_async_cbargs { bool opc_rpc_sent; - int opc_rc; - struct completion opc_sync; + int opc_rc; + struct completion opc_sync; } oi_cbarg; }; @@ -87,7 +159,7 @@ struct osc_io { * State maintained by osc layer for the duration of a system call. */ struct osc_session { - struct osc_io os_io; + struct osc_io os_io; }; #define OTI_PVEC_SIZE 256 @@ -111,20 +183,20 @@ struct osc_thread_info { }; struct osc_object { - struct cl_object oo_cl; - struct lov_oinfo *oo_oinfo; - /** - * True if locking against this stripe got -EUSERS. - */ - int oo_contended; - cfs_time_t oo_contention_time; + struct cl_object oo_cl; + struct lov_oinfo *oo_oinfo; + /** + * True if locking against this stripe got -EUSERS. + */ + int oo_contended; + cfs_time_t oo_contention_time; #ifdef CONFIG_LUSTRE_DEBUG_EXPENSIVE_CHECK - /** - * IO context used for invariant checks in osc_lock_has_pages(). - */ - struct cl_io oo_debug_io; - /** Serialization object for osc_object::oo_debug_io. */ - struct mutex oo_debug_mutex; + /** + * IO context used for invariant checks in osc_lock_has_pages(). + */ + struct cl_io oo_debug_io; + /** Serialization object for osc_object::oo_debug_io. */ + struct mutex oo_debug_mutex; #endif /** * used by the osc to keep track of what objects to build into rpcs. @@ -138,7 +210,7 @@ struct osc_object { /** * extent is a red black tree to manage (async) dirty pages. */ - struct rb_root oo_root; + struct rb_root oo_root; /** * Manage write(dirty) extents. */ @@ -148,12 +220,12 @@ struct osc_object { struct list_head oo_reading_exts; - atomic_t oo_nr_reads; - atomic_t oo_nr_writes; + atomic_t oo_nr_reads; + atomic_t oo_nr_writes; /** Protect extent tree. Will be used to protect * oo_{read|write}_pages soon. */ - spinlock_t oo_lock; + spinlock_t oo_lock; /** * Radix tree for caching pages @@ -169,6 +241,8 @@ struct osc_object { /** number of active IOs of this object */ atomic_t oo_nr_ios; wait_queue_head_t oo_io_waitq; + + bool oo_initialized; }; static inline void osc_object_lock(struct osc_object *obj) @@ -204,11 +278,11 @@ static inline int osc_object_is_locked(struct osc_object *obj) * Lock "micro-states" for osc layer. */ enum osc_lock_state { - OLS_NEW, - OLS_ENQUEUED, - OLS_UPCALL_RECEIVED, - OLS_GRANTED, - OLS_CANCELLED + OLS_NEW, + OLS_ENQUEUED, + OLS_UPCALL_RECEIVED, + OLS_GRANTED, + OLS_CANCELLED }; /** @@ -271,53 +345,52 @@ struct osc_lock { /** DLM flags with which osc_lock::ols_lock was enqueued */ __u64 ols_flags; /** osc_lock::ols_lock handle */ - struct lustre_handle ols_handle; + struct lustre_handle ols_handle; struct ldlm_enqueue_info ols_einfo; - enum osc_lock_state ols_state; + enum osc_lock_state ols_state; /** lock value block */ struct ost_lvb ols_lvb; - /** - * true, if ldlm_lock_addref() was called against - * osc_lock::ols_lock. This is used for sanity checking. - * - * \see osc_lock::ols_has_ref - */ - unsigned ols_hold :1, - /** - * this is much like osc_lock::ols_hold, except that this bit is - * cleared _after_ reference in released in osc_lock_unuse(). This - * fine distinction is needed because: - * - * - if ldlm lock still has a reference, osc_ast_data_get() needs - * to return associated cl_lock (so that a flag is needed that is - * cleared after ldlm_lock_decref() returned), and - * - * - ldlm_lock_decref() can invoke blocking ast (for a - * LDLM_FL_CBPENDING lock), and osc_lock functions like - * osc_lock_cancel() called from there need to know whether to - * release lock reference (so that a flag is needed that is - * cleared before ldlm_lock_decref() is called). - */ - ols_has_ref:1, - /** - * inherit the lockless attribute from top level cl_io. - * If true, osc_lock_enqueue is able to tolerate the -EUSERS error. - */ - ols_locklessable:1, - /** - * if set, the osc_lock is a glimpse lock. For glimpse locks, we treat - * the EVAVAIL error as torerable, this will make upper logic happy - * to wait all glimpse locks to each OSTs to be completed. - * Glimpse lock converts to normal lock if the server lock is - * granted. - * Glimpse lock should be destroyed immediately after use. - */ - ols_glimpse:1, - /** - * For async glimpse lock. - */ - ols_agl:1; + /** + * true, if ldlm_lock_addref() was called against + * osc_lock::ols_lock. This is used for sanity checking. + * + * \see osc_lock::ols_has_ref + */ + unsigned ols_hold :1, + /** + * this is much like osc_lock::ols_hold, except that this bit is + * cleared _after_ reference in released in osc_lock_unuse(). This + * fine distinction is needed because: + * + * - if ldlm lock still has a reference, osc_ast_data_get() needs + * to return associated cl_lock (so that a flag is needed that is + * cleared after ldlm_lock_decref() returned), and + * + * - ldlm_lock_decref() can invoke blocking ast (for a + * LDLM_FL_CBPENDING lock), and osc_lock functions like + * osc_lock_cancel() called from there need to know whether to + * release lock reference (so that a flag is needed that is + * cleared before ldlm_lock_decref() is called). + */ + ols_has_ref:1, + /** + * inherit the lockless attribute from top level cl_io. + * If true, osc_lock_enqueue is able to tolerate the -EUSERS error. + */ + ols_locklessable:1, + /** + * if set, the osc_lock is a glimpse lock. For glimpse locks, we treat + * the EVAVAIL error as torerable, this will make upper logic happy + * to wait all glimpse locks to each OSTs to be completed. + * Glimpse lock converts to normal lock if the server lock is granted. + * Glimpse lock should be destroyed immediately after use. + */ + ols_glimpse:1, + /** + * For async glimpse lock. + */ + ols_agl:1; }; @@ -348,11 +421,11 @@ struct osc_page { /** * in LRU? */ - ops_in_lru:1, + ops_in_lru:1, /** * Set if the page must be transferred with OBD_BRW_SRVLOCK. */ - ops_srvlock:1; + ops_srvlock:1; /** * lru page list. See osc_lru_{del|use}() in osc_page.c for usage. */ @@ -360,7 +433,7 @@ struct osc_page { /** * Submit time - the time when the page is starting RPC. For debugging. */ - cfs_time_t ops_submit_time; + cfs_time_t ops_submit_time; }; extern struct kmem_cache *osc_lock_kmem; @@ -368,26 +441,17 @@ extern struct kmem_cache *osc_object_kmem; extern struct kmem_cache *osc_thread_kmem; extern struct kmem_cache *osc_session_kmem; extern struct kmem_cache *osc_extent_kmem; +extern struct kmem_cache *osc_quota_kmem; -extern struct lu_device_type osc_device_type; extern struct lu_context_key osc_key; extern struct lu_context_key osc_session_key; #define OSC_FLAGS (ASYNC_URGENT|ASYNC_READY) -int osc_lock_init(const struct lu_env *env, - struct cl_object *obj, struct cl_lock *lock, - const struct cl_io *io); -int osc_io_init (const struct lu_env *env, - struct cl_object *obj, struct cl_io *io); -struct lu_object *osc_object_alloc(const struct lu_env *env, - const struct lu_object_header *hdr, - struct lu_device *dev); int osc_page_init(const struct lu_env *env, struct cl_object *obj, struct cl_page *page, pgoff_t ind); - -void osc_index2policy(union ldlm_policy_data *policy, - const struct cl_object *obj, pgoff_t start, pgoff_t end); +void osc_index2policy(union ldlm_policy_data *policy, const struct cl_object *obj, + pgoff_t start, pgoff_t end); int osc_lvb_print(const struct lu_env *env, void *cookie, lu_printer_t p, const struct ost_lvb *lvb); @@ -420,55 +484,47 @@ void osc_io_unplug(const struct lu_env *env, struct client_obd *cli, struct osc_object *osc); int lru_queue_work(const struct lu_env *env, void *data); -void osc_object_set_contended (struct osc_object *obj); +void osc_object_set_contended(struct osc_object *obj); void osc_object_clear_contended(struct osc_object *obj); -int osc_object_is_contended (struct osc_object *obj); - -int osc_lock_is_lockless (const struct osc_lock *olck); +int osc_object_is_contended(struct osc_object *obj); +int osc_lock_is_lockless(const struct osc_lock *olck); /***************************************************************************** * - * Accessors. + * Accessors and type conversions. * */ - static inline struct osc_thread_info *osc_env_info(const struct lu_env *env) { - struct osc_thread_info *info; + struct osc_thread_info *info; - info = lu_context_key_get(&env->le_ctx, &osc_key); - LASSERT(info != NULL); - return info; + info = lu_context_key_get(&env->le_ctx, &osc_key); + LASSERT(info != NULL); + return info; } static inline struct osc_session *osc_env_session(const struct lu_env *env) { - struct osc_session *ses; + struct osc_session *ses; - ses = lu_context_key_get(env->le_ses, &osc_session_key); - LASSERT(ses != NULL); - return ses; + ses = lu_context_key_get(env->le_ses, &osc_session_key); + LASSERT(ses != NULL); + return ses; } static inline struct osc_io *osc_env_io(const struct lu_env *env) { - return &osc_env_session(env)->os_io; -} - -static inline int osc_is_object(const struct lu_object *obj) -{ - return obj->lo_dev->ld_type == &osc_device_type; + return &osc_env_session(env)->os_io; } static inline struct osc_device *lu2osc_dev(const struct lu_device *d) { - LINVRNT(d->ld_type == &osc_device_type); - return container_of0(d, struct osc_device, od_cl.cd_lu_dev); + return container_of0(d, struct osc_device, od_cl.cd_lu_dev); } static inline struct obd_export *osc_export(const struct osc_object *obj) { - return lu2osc_dev(obj->oo_cl.co_lu.lo_dev)->od_exp; + return lu2osc_dev(obj->oo_cl.co_lu.lo_dev)->od_exp; } static inline struct client_obd *osc_cli(const struct osc_object *obj) @@ -478,8 +534,7 @@ static inline struct client_obd *osc_cli(const struct osc_object *obj) static inline struct osc_object *cl2osc(const struct cl_object *obj) { - LINVRNT(osc_is_object(&obj->co_lu)); - return container_of0(obj, struct osc_object, oo_cl); + return container_of0(obj, struct osc_object, oo_cl); } static inline struct cl_object *osc2cl(const struct osc_object *obj) @@ -487,6 +542,36 @@ static inline struct cl_object *osc2cl(const struct osc_object *obj) return (struct cl_object *)&obj->oo_cl; } +static inline struct osc_device *obd2osc_dev(const struct obd_device *d) +{ + return container_of0(d->obd_lu_dev, struct osc_device, + od_cl.cd_lu_dev); +} + +static inline struct lu_device *osc2lu_dev(struct osc_device *osc) +{ + return &osc->od_cl.cd_lu_dev; +} + +static inline struct lu_object *osc2lu(struct osc_object *osc) +{ + return &osc->oo_cl.co_lu; +} + +static inline struct osc_object *lu2osc(const struct lu_object *obj) +{ + return container_of0(obj, struct osc_object, oo_cl.co_lu); +} + +static inline struct osc_io *cl2osc_io(const struct lu_env *env, + const struct cl_io_slice *slice) +{ + struct osc_io *oio = container_of0(slice, struct osc_io, oi_cl); + + LINVRNT(oio == osc_env_io(env)); + return oio; +} + static inline enum ldlm_mode osc_cl_lock2ldlm(enum cl_lock_mode mode) { LASSERT(mode == CLM_READ || mode == CLM_WRITE || mode == CLM_GROUP); @@ -509,8 +594,7 @@ static inline enum cl_lock_mode osc_ldlm2cl_lock(enum ldlm_mode mode) static inline struct osc_page *cl2osc_page(const struct cl_page_slice *slice) { - LINVRNT(osc_is_object(&slice->cpl_obj->co_lu)); - return container_of0(slice, struct osc_page, ops_cl); + return container_of0(slice, struct osc_page, ops_cl); } static inline struct osc_page *oap2osc(struct osc_async_page *oap) @@ -545,18 +629,12 @@ osc_cl_page_osc(struct cl_page *page, struct osc_object *osc) static inline struct osc_lock *cl2osc_lock(const struct cl_lock_slice *slice) { - LINVRNT(osc_is_object(&slice->cls_obj->co_lu)); - return container_of0(slice, struct osc_lock, ols_cl); -} - -static inline struct osc_lock *osc_lock_at(const struct cl_lock *lock) -{ - return cl2osc_lock(cl_lock_at(lock, &osc_device_type)); + return container_of0(slice, struct osc_lock, ols_cl); } static inline int osc_io_srvlock(struct osc_io *oio) { - return (oio->oi_lockless && !oio->oi_cl.cis_io->ci_no_srvlock); + return (oio->oi_lockless && !oio->oi_cl.cis_io->ci_no_srvlock); } enum osc_extent_state { @@ -672,4 +750,4 @@ int osc_page_gang_lookup(const struct lu_env *env, struct cl_io *io, osc_page_gang_cbt cb, void *cbdata); /** @} osc */ -#endif /* OSC_CL_INTERNAL_H */ +#endif /* LUSTRE_OSC_H */