1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
10 #elif defined(__APPLE__)
11 #include <darwin/obd.h>
12 #elif defined(__WINNT__)
13 #include <winnt/obd.h>
15 #error Unsupported operating system.
18 #define IOC_OSC_TYPE 'h'
19 #define IOC_OSC_MIN_NR 20
20 #define IOC_OSC_SET_ACTIVE _IOWR(IOC_OSC_TYPE, 21, struct obd_device *)
21 #define IOC_OSC_MAX_NR 50
23 #define IOC_MDC_TYPE 'i'
24 #define IOC_MDC_MIN_NR 20
25 /* Moved to lustre_user.h
26 #define IOC_MDC_LOOKUP _IOWR(IOC_MDC_TYPE, 20, struct obd_ioctl_data *)
27 #define IOC_MDC_GETSTRIPE _IOWR(IOC_MDC_TYPE, 21, struct lov_mds_md *) */
28 #define IOC_MDC_MAX_NR 50
30 #include <lustre_lib.h>
31 #include <lustre/lustre_idl.h>
32 #include <lustre_export.h>
33 #include <lustre_quota.h>
34 #include <class_hash.h>
36 #include <libcfs/bitmap.h>
39 #define MAX_OBD_DEVICES 8192
41 /* this is really local to the OSC */
42 struct loi_oap_pages {
43 struct list_head lop_pending;
44 struct list_head lop_urgent;
45 struct list_head lop_pending_group;
55 struct lov_oinfo { /* per-stripe data structure */
56 __u64 loi_id; /* object ID on the target OST */
57 __u64 loi_gr; /* object group on the target OST */
58 int loi_ost_idx; /* OST stripe index in lov_tgt_desc->tgts */
59 int loi_ost_gen; /* generation of this loi_ost_idx */
61 /* used by the osc to keep track of what objects to build into rpcs */
62 struct loi_oap_pages loi_read_lop;
63 struct loi_oap_pages loi_write_lop;
64 /* _cli_ is poorly named, it should be _ready_ */
65 struct list_head loi_cli_item;
66 struct list_head loi_write_item;
67 struct list_head loi_read_item;
69 unsigned long loi_kms_valid:1;
70 __u64 loi_kms; /* known minimum size */
71 struct ost_lvb loi_lvb;
72 struct osc_async_rc loi_ar;
75 static inline void loi_init(struct lov_oinfo *loi)
77 CFS_INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending);
78 CFS_INIT_LIST_HEAD(&loi->loi_read_lop.lop_urgent);
79 CFS_INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending_group);
80 CFS_INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending);
81 CFS_INIT_LIST_HEAD(&loi->loi_write_lop.lop_urgent);
82 CFS_INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending_group);
83 CFS_INIT_LIST_HEAD(&loi->loi_cli_item);
84 CFS_INIT_LIST_HEAD(&loi->loi_write_item);
85 CFS_INIT_LIST_HEAD(&loi->loi_read_item);
88 /*extent array item for describing the joined file extent info*/
90 __u64 le_start; /* extent start */
91 __u64 le_len; /* extent length */
92 int le_loi_idx; /* extent #1 loi's index in lsm loi array */
93 int le_stripe_count; /* extent stripe count*/
96 /*Lov array info for describing joined file array EA info*/
97 struct lov_array_info {
98 struct llog_logid lai_array_id; /* MDS med llog object id */
99 unsigned lai_ext_count; /* number of extent count */
100 struct lov_extent *lai_ext_array; /* extent desc array */
103 struct lov_stripe_md {
105 void *lsm_lock_owner; /* debugging */
108 /* Public members. */
109 __u64 lw_object_id; /* lov object id */
110 __u64 lw_object_gr; /* lov object group */
111 __u64 lw_maxbytes; /* maximum possible file size */
113 /* LOV-private members start here -- only for use in lov/. */
115 __u32 lw_stripe_size; /* size of the stripe */
116 __u32 lw_pattern; /* striping pattern (RAID0, RAID1) */
117 unsigned lw_stripe_count; /* number of objects being striped over */
120 struct lov_array_info *lsm_array; /*Only for joined file array info*/
121 struct lov_oinfo *lsm_oinfo[0];
124 #define lsm_object_id lsm_wire.lw_object_id
125 #define lsm_object_gr lsm_wire.lw_object_gr
126 #define lsm_maxbytes lsm_wire.lw_maxbytes
127 #define lsm_magic lsm_wire.lw_magic
128 #define lsm_stripe_size lsm_wire.lw_stripe_size
129 #define lsm_pattern lsm_wire.lw_pattern
130 #define lsm_stripe_count lsm_wire.lw_stripe_count
134 typedef int (*obd_enqueue_update_f)(struct obd_info *oinfo, int rc);
136 /* obd info for a particular level (lov, osc). */
138 /* Lock policy. It keeps an extent which is specific for a particular
139 * OSC. (e.g. lov_prep_enqueue_set initialises extent of the policy,
140 * and osc_enqueue passes it into ldlm_lock_match & ldlm_cli_enqueue. */
141 ldlm_policy_data_t oi_policy;
142 /* Flags used while lock handling. The flags obtained on the enqueue
143 * request are set here, therefore they are request specific. */
145 /* Lock handle specific for every OSC lock. */
146 struct lustre_handle *oi_lockh;
147 /* lsm data specific for every OSC. */
148 struct lov_stripe_md *oi_md;
149 /* obdo data specific for every OSC, if needed at all. */
151 /* statfs data specific for every OSC, if needed at all. */
152 struct obd_statfs *oi_osfs;
153 /* An update callback which is called to update some data on upper
154 * level. E.g. it is used for update lsm->lsm_oinfo at every recieved
155 * request in osc level for enqueue requests. It is also possible to
156 * update some caller data from LOV layer if needed. */
157 obd_enqueue_update_f oi_cb_up;
160 /* compare all relevant fields. */
161 static inline int lov_stripe_md_cmp(struct lov_stripe_md *m1,
162 struct lov_stripe_md *m2)
165 * ->lsm_wire contains padding, but it should be zeroed out during
168 return memcmp(&m1->lsm_wire, &m2->lsm_wire, sizeof m1->lsm_wire);
171 void lov_stripe_lock(struct lov_stripe_md *md);
172 void lov_stripe_unlock(struct lov_stripe_md *md);
175 struct list_head typ_chain;
176 struct obd_ops *typ_ops;
177 cfs_proc_dir_entry_t *typ_procroot;
180 spinlock_t obd_type_lock;
191 ASYNC_READY = 0x1, /* ap_make_ready will not be called before this
192 page is added to an rpc */
193 ASYNC_URGENT = 0x2, /* page must be put into an RPC before return */
194 ASYNC_COUNT_STABLE = 0x4, /* ap_refresh_count will not be called
195 to give the caller a chance to update
196 or cancel the size of the io */
197 ASYNC_GROUP_SYNC = 0x8, /* ap_completion will not be called, instead
198 the page is accounted for in the
199 obd_io_group given to
200 obd_queue_group_io */
203 struct obd_async_page_ops {
204 int (*ap_make_ready)(void *data, int cmd);
205 int (*ap_refresh_count)(void *data, int cmd);
206 void (*ap_fill_obdo)(void *data, int cmd, struct obdo *oa);
207 void (*ap_update_obdo)(void *data, int cmd, struct obdo *oa,
209 int (*ap_completion)(void *data, int cmd, struct obdo *oa, int rc);
212 /* the `oig' is passed down from a caller of obd rw methods. the callee
213 * records enough state such that the caller can sleep on the oig and
214 * be woken when all the callees have finished their work */
215 struct obd_io_group {
217 atomic_t oig_refcount;
220 struct list_head oig_occ_list;
221 cfs_waitq_t oig_waitq;
224 /* the oig callback context lets the callee of obd rw methods register
225 * for callbacks from the caller. */
226 struct oig_callback_context {
227 struct list_head occ_oig_item;
228 /* called when the caller has received a signal while sleeping.
229 * callees of this method are encouraged to abort their state
230 * in the oig. This may be called multiple times. */
231 void (*occ_interrupted)(struct oig_callback_context *occ);
232 unsigned long interrupted:1;
235 /* Individual type definitions */
237 struct ost_server_data;
239 /* hold common fields for "target" device */
240 struct obd_device_target {
241 struct super_block *obt_sb;
242 atomic_t obt_quotachecking;
243 struct lustre_quota_ctxt obt_qctxt;
246 typedef void (*obd_pin_extent_cb)(void *data);
247 typedef int (*obd_page_removal_cb_t)(void *data, int discard);
248 typedef int (*obd_lock_cancel_cb)(struct ldlm_lock *,struct ldlm_lock_desc *,
251 #define FILTER_GROUP_LLOG 1
252 #define FILTER_GROUP_ECHO 2
260 /* NB this field MUST be first */
261 struct obd_device_target fo_obt;
262 const char *fo_fstype;
263 struct vfsmount *fo_vfsmnt;
264 cfs_dentry_t *fo_dentry_O;
265 cfs_dentry_t **fo_dentry_O_groups;
266 cfs_dentry_t **fo_dentry_O_sub;
267 spinlock_t fo_objidlock; /* protect fo_lastobjid */
268 spinlock_t fo_translock; /* protect fsd_last_transno */
269 struct file *fo_rcvd_filp;
270 struct file *fo_health_check_filp;
271 struct lr_server_data *fo_fsd;
272 unsigned long *fo_last_rcvd_slots;
273 __u64 fo_mount_count;
275 int fo_destroy_in_progress;
276 struct semaphore fo_create_lock;
278 struct list_head fo_export_list;
281 obd_size fo_tot_dirty; /* protected by obd_osfs_lock */
282 obd_size fo_tot_granted; /* all values in bytes */
283 obd_size fo_tot_pending;
285 obd_size fo_readcache_max_filesize;
287 struct obd_import *fo_mdc_imp;
288 struct obd_uuid fo_mdc_uuid;
289 struct lustre_handle fo_mdc_conn;
290 struct file **fo_last_objid_files;
291 __u64 *fo_last_objids; /* last created objid for groups,
292 * protected by fo_objidlock */
294 struct semaphore fo_alloc_lock;
296 atomic_t fo_r_in_flight;
297 atomic_t fo_w_in_flight;
300 * per-filter pool of kiobuf's allocated by filter_common_setup() and
301 * torn down by filter_cleanup(). Contains OST_NUM_THREADS elements of
302 * which ->fo_iobuf_count were allocated.
304 * This pool contains kiobuf used by
305 * filter_{prep,commit}rw_{read,write}() and is shared by all OST
308 * Locking: none, each OST thread uses only one element, determined by
309 * its "ordinal number", ->t_id.
311 struct filter_iobuf **fo_iobuf_pool;
314 struct brw_stats fo_filter_stats;
315 struct lustre_quota_ctxt fo_quota_ctxt;
316 spinlock_t fo_quotacheck_lock;
317 atomic_t fo_quotachecking;
319 int fo_fmd_max_num; /* per exp filter_mod_data */
320 int fo_fmd_max_age; /* jiffies to fmd expiry */
324 #define OSC_MAX_RIF_DEFAULT 8
325 #define OSC_MAX_RIF_MAX 256
326 #define OSC_MAX_DIRTY_DEFAULT (OSC_MAX_RIF_DEFAULT * 4)
327 #define OSC_MAX_DIRTY_MB_MAX 2048 /* arbitrary, but < MAX_LONG bytes */
328 #define OSC_DEFAULT_RESENDS 10
330 #define MDC_MAX_RIF_DEFAULT 8
331 #define MDC_MAX_RIF_MAX 512
337 struct semaphore cl_sem;
338 struct obd_uuid cl_target_uuid;
339 struct obd_import *cl_import; /* ptlrpc connection state */
341 /* max_mds_easize is purely a performance thing so we don't have to
342 * call obd_size_diskmd() all the time. */
343 int cl_default_mds_easize;
344 int cl_max_mds_easize;
345 int cl_max_mds_cookiesize;
347 //struct llog_canceld_ctxt *cl_llcd; /* it's included by obd_llog_ctxt */
348 void *cl_llcd_offset;
350 /* the grant values are protected by loi_list_lock below */
351 long cl_dirty; /* all _dirty_ in bytes */
352 long cl_dirty_max; /* allowed w/o rpc */
353 long cl_avail_grant; /* bytes of credit for ost */
354 long cl_lost_grant; /* lost credits (trunc) */
355 struct list_head cl_cache_waiters; /* waiting for cache/grant */
357 /* keep track of objects that have lois that contain pages which
358 * have been queued for async brw. this lock also protects the
359 * lists of osc_client_pages that hang off of the loi */
361 * ->cl_loi_list_lock protects consistency of
362 * ->cl_loi_{ready,read,write}_list. ->ap_make_ready() and
363 * ->ap_completion() call-backs are executed under this lock. As we
364 * cannot guarantee that these call-backs never block on all platforms
365 * (as a matter of fact they do block on Mac OS X), type of
366 * ->cl_loi_list_lock is platform dependent: it's a spin-lock on Linux
367 * and blocking mutex on Mac OS X. (Alternative is to make this lock
368 * blocking everywhere, but we don't want to slow down fast-path of
369 * our main platform.)
371 * Exact type of ->cl_loi_list_lock is defined in arch/obd.h together
372 * with client_obd_list_{un,}lock() and
373 * client_obd_list_lock_{init,done}() functions.
375 client_obd_lock_t cl_loi_list_lock;
376 struct list_head cl_loi_ready_list;
377 struct list_head cl_loi_write_list;
378 struct list_head cl_loi_read_list;
381 /* just a sum of the loi/lop pending numbers to be exported by /proc */
382 int cl_pending_w_pages;
383 int cl_pending_r_pages;
384 int cl_max_pages_per_rpc;
385 int cl_max_rpcs_in_flight;
386 struct obd_histogram cl_read_rpc_hist;
387 struct obd_histogram cl_write_rpc_hist;
388 struct obd_histogram cl_read_page_hist;
389 struct obd_histogram cl_write_page_hist;
390 struct obd_histogram cl_read_offset_hist;
391 struct obd_histogram cl_write_offset_hist;
393 /* number of in flight destroy rpcs is limited to max_rpcs_in_flight */
394 atomic_t cl_destroy_in_flight;
395 cfs_waitq_t cl_destroy_waitq;
397 struct mdc_rpc_lock *cl_rpc_lock;
398 struct mdc_rpc_lock *cl_setattr_lock;
399 struct mdc_rpc_lock *cl_close_lock;
400 struct osc_creator cl_oscc;
403 struct semaphore cl_mgc_sem;
404 struct vfsmount *cl_mgc_vfsmnt;
405 struct dentry *cl_mgc_configs_dir;
406 atomic_t cl_mgc_refcount;
407 struct obd_export *cl_mgc_mgsexp;
409 /* checksumming for data sent over the network */
410 unsigned int cl_checksum:1; /* 0 = disabled, 1 = enabled */
411 /* supported checksum types that are worked out at connect time */
412 __u32 cl_supp_cksum_types;
413 /* checksum algorithm to be used */
414 cksum_type_t cl_cksum_type;
416 /* also protected by the poorly named _loi_list_lock lock above */
417 struct osc_async_rc cl_ar;
419 /* used by quotacheck */
420 int cl_qchk_stat; /* quotacheck stat of the peer */
421 atomic_t cl_resends; /* resend count */
422 /* Cache of triples */
423 struct lustre_cache *cl_cache;
424 obd_lock_cancel_cb cl_ext_lock_cancel_cb;
426 #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
428 #define CL_NOT_QUOTACHECKED 1 /* client->cl_qchk_stat init value */
431 struct ptlrpc_service *mgs_service;
432 struct vfsmount *mgs_vfsmnt;
433 struct super_block *mgs_sb;
434 struct dentry *mgs_configs_dir;
435 struct dentry *mgs_fid_de;
436 struct list_head mgs_fs_db_list;
437 struct semaphore mgs_sem;
438 cfs_proc_dir_entry_t *mgs_proc_live;
442 /* NB this field MUST be first */
443 struct obd_device_target mds_obt;
444 struct ptlrpc_service *mds_service;
445 struct ptlrpc_service *mds_setattr_service;
446 struct ptlrpc_service *mds_readpage_service;
447 struct vfsmount *mds_vfsmnt;
448 cfs_dentry_t *mds_fid_de;
450 int mds_max_cookiesize;
451 struct file *mds_rcvd_filp;
452 spinlock_t mds_transno_lock;
453 __u64 mds_last_transno;
454 __u64 mds_mount_count;
456 unsigned long mds_atime_diff;
457 struct semaphore mds_epoch_sem;
458 struct ll_fid mds_rootfid;
459 struct lr_server_data *mds_server_data;
460 cfs_dentry_t *mds_pending_dir;
461 cfs_dentry_t *mds_logs_dir;
462 cfs_dentry_t *mds_objects_dir;
463 struct llog_handle *mds_cfg_llh;
464 // struct llog_handle *mds_catalog;
465 struct obd_device *mds_osc_obd; /* XXX lov_obd */
466 struct obd_uuid mds_lov_uuid;
468 struct obd_export *mds_osc_exp; /* XXX lov_exp */
469 struct lov_desc mds_lov_desc;
471 /* mark pages dirty for write. */
472 bitmap_t *mds_lov_page_dirty;
473 /* array for store pages with obd_id */
474 void **mds_lov_page_array;
475 /* file for store objid */
476 struct file *mds_lov_objid_filp;
477 __u32 mds_lov_objid_count;
478 __u32 mds_lov_objid_lastpage;
479 __u32 mds_lov_objid_lastidx;
481 struct file *mds_health_check_filp;
482 unsigned long *mds_client_bitmap;
483 struct upcall_cache *mds_group_hash;
485 struct lustre_quota_info mds_quota_info;
486 struct semaphore mds_qonoff_sem;
487 struct semaphore mds_health_sem;
488 unsigned long mds_fl_user_xattr:1,
492 mds_evict_ost_nids:1;
494 uid_t mds_squash_uid;
495 gid_t mds_squash_gid;
496 lnet_nid_t mds_nosquash_nid;
500 #define mds_max_ost_index (0xFFFF)
501 #define MDS_LOV_ALLOC_SIZE (CFS_PAGE_SIZE)
503 #define OBJID_PER_PAGE() (MDS_LOV_ALLOC_SIZE / sizeof(obd_id))
505 #define MDS_LOV_OBJID_PAGES_COUNT (mds_max_ost_index/OBJID_PER_PAGE())
507 extern int mds_lov_init_objids(struct obd_device *obd);
508 extern void mds_lov_destroy_objids(struct obd_device *obd);
521 struct lustre_handle eo_nl_lock;
526 struct ptlrpc_service *ost_service;
527 struct ptlrpc_service *ost_create_service;
528 struct ptlrpc_service *ost_io_service;
529 struct semaphore ost_health_sem;
532 struct echo_client_obd {
533 struct obd_export *ec_exp; /* the local connection to osc/lov */
535 struct list_head ec_objects;
541 struct obd_uuid lqo_uuid; /* ptlrpc's c_remote_uuid */
542 struct list_head lqo_oss_list; /* link to lov_qos */
543 __u32 lqo_ost_count; /* number of osts on this oss */
544 __u64 lqo_bavail; /* total bytes avail on OSS */
545 __u64 lqo_penalty; /* current penalty */
546 __u64 lqo_penalty_per_obj; /* penalty decrease every obj*/
550 struct lov_qos_oss *ltq_oss; /* oss info */
551 __u64 ltq_penalty; /* current penalty */
552 __u64 ltq_penalty_per_obj; /* penalty decrease every obj*/
553 __u64 ltq_weight; /* net weighting */
554 unsigned int ltq_usable:1; /* usable for striping */
558 struct list_head lq_oss_list; /* list of OSSs that targets use */
559 struct rw_semaphore lq_rw_sem;
560 __u32 lq_active_oss_count;
561 __u32 *lq_rr_array; /* round-robin optimized list */
562 unsigned int lq_rr_size; /* rr array size */
563 unsigned int lq_prio_free; /* priority for free space */
564 unsigned long lq_dirty:1, /* recalc qos data */
565 lq_dirty_rr:1, /* recalc round-robin list */
566 lq_same_space:1,/* the ost's all have approx.
567 the same space avail */
568 lq_reset:1; /* zero current penalties */
571 struct lov_tgt_desc {
572 struct obd_uuid ltd_uuid;
573 struct obd_export *ltd_exp;
574 struct ltd_qos ltd_qos; /* qos info per target */
576 __u32 ltd_index; /* index in lov_obd->tgts */
577 unsigned long ltd_active:1,/* is this target up for requests */
578 ltd_activate:1,/* should this target be activated */
579 ltd_reap:1; /* should this target be deleted */
583 struct lov_desc desc;
584 struct lov_tgt_desc **lov_tgts;
585 struct semaphore lov_lock;
586 struct obd_connect_data lov_ocd;
587 struct lov_qos lov_qos; /* qos info per lov */
588 atomic_t lov_refcount;
589 __u32 lov_tgt_count; /* how many OBD's */
590 __u32 lov_active_tgt_count; /* how many active */
591 __u32 lov_death_row;/* tgts scheduled to be deleted */
592 __u32 lov_tgt_size; /* size of tgts array */
593 __u32 lov_start_idx; /* start index of new inode */
594 __u32 lov_offset_idx; /* aliasing for start_idx */
595 int lov_start_count;/* reseed counter */
597 obd_page_removal_cb_t lov_page_removal_cb;
598 obd_pin_extent_cb lov_page_pin_cb;
599 obd_lock_cancel_cb lov_lock_cancel_cb;
602 struct niobuf_local {
607 cfs_dentry_t *dentry;
612 /* obd device type names */
613 /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */
614 #define LUSTRE_MDS_NAME "mds"
615 #define LUSTRE_MDT_NAME "mdt"
616 #define LUSTRE_MDC_NAME "mdc"
617 #define LUSTRE_OSS_NAME "ost" /*FIXME change name to oss*/
618 #define LUSTRE_OST_NAME "obdfilter" /* FIXME change name to ost*/
619 #define LUSTRE_OSC_NAME "osc"
620 #define LUSTRE_LOV_NAME "lov"
621 #define LUSTRE_MGS_NAME "mgs"
622 #define LUSTRE_MGC_NAME "mgc"
624 #define LUSTRE_CACHEOBD_NAME "cobd"
625 #define LUSTRE_ECHO_NAME "obdecho"
626 #define LUSTRE_ECHO_CLIENT_NAME "echo_client"
628 /* Constant obd names (post-rename) */
629 #define LUSTRE_MDS_OBDNAME "MDS"
630 #define LUSTRE_OSS_OBDNAME "OSS"
631 #define LUSTRE_MGS_OBDNAME "MGS"
632 #define LUSTRE_MGC_OBDNAME "MGC"
634 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
635 #define N_LOCAL_TEMP_PAGE 0x10000000
637 struct obd_trans_info {
640 /* Only used on the server side for tracking acks. */
641 struct oti_req_ack_lock {
642 struct lustre_handle lock;
646 struct llog_cookie oti_onecookie;
647 struct llog_cookie *oti_logcookies;
650 /* initial thread handling transaction */
655 static inline void oti_init(struct obd_trans_info *oti,
656 struct ptlrpc_request *req)
660 memset(oti, 0, sizeof *oti);
665 oti->oti_xid = req->rq_xid;
667 if ((req->rq_reqmsg != NULL) && (req->rq_repmsg != NULL))
668 oti->oti_transno = lustre_msg_get_transno(req->rq_repmsg);
669 oti->oti_thread_id = req->rq_svc_thread ? req->rq_svc_thread->t_id : -1;
670 oti->oti_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg);
673 static inline void oti_alloc_cookies(struct obd_trans_info *oti,int num_cookies)
678 if (num_cookies == 1)
679 oti->oti_logcookies = &oti->oti_onecookie;
681 OBD_ALLOC(oti->oti_logcookies,
682 num_cookies * sizeof(oti->oti_onecookie));
684 oti->oti_numcookies = num_cookies;
687 static inline void oti_free_cookies(struct obd_trans_info *oti)
689 if (!oti || !oti->oti_logcookies)
692 if (oti->oti_logcookies == &oti->oti_onecookie)
693 LASSERT(oti->oti_numcookies == 1);
695 OBD_FREE(oti->oti_logcookies,
696 oti->oti_numcookies * sizeof(oti->oti_onecookie));
697 oti->oti_logcookies = NULL;
698 oti->oti_numcookies = 0;
703 LLOG_CONFIG_ORIG_CTXT = 0,
704 LLOG_CONFIG_REPL_CTXT = 1,
705 LLOG_MDS_OST_ORIG_CTXT = 2,
706 LLOG_MDS_OST_REPL_CTXT = 3,
707 LLOG_SIZE_ORIG_CTXT = 4,
708 LLOG_SIZE_REPL_CTXT = 5,
709 LLOG_MD_ORIG_CTXT = 6,
710 LLOG_MD_REPL_CTXT = 7,
711 LLOG_RD1_ORIG_CTXT = 8,
712 LLOG_RD1_REPL_CTXT = 9,
713 LLOG_TEST_ORIG_CTXT = 10,
714 LLOG_TEST_REPL_CTXT = 11,
715 LLOG_LOVEA_ORIG_CTXT = 12,
716 LLOG_LOVEA_REPL_CTXT = 13,
721 * Events signalled through obd_notify() upcall-chain.
723 enum obd_notify_event {
724 /* Device activated */
726 /* Device deactivated */
728 /* Connect data for import were changed */
731 OBD_NOTIFY_SYNC_NONBLOCK,
733 /* Configuration event */
737 #define CONFIG_LOG 0x1 /* finished processing config log */
738 #define CONFIG_SYNC 0x2 /* mdt synced 1 ost */
741 * Data structure used to pass obd_notify()-event to non-obd listeners (llite
742 * and liblustre being main examples).
744 struct obd_notify_upcall {
745 int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
746 enum obd_notify_event ev, void *owner);
747 /* Opaque datum supplied by upper layer listener */
751 /* corresponds to one of the obd's */
752 #define MAX_OBD_NAME 128
753 #define OBD_DEVICE_MAGIC 0XAB5CD6EF
755 struct obd_type *obd_type;
758 /* common and UUID name of this device */
759 char obd_name[MAX_OBD_NAME];
760 struct obd_uuid obd_uuid;
763 unsigned long obd_attached:1, /* finished attach */
764 obd_set_up:1, /* finished setup */
765 obd_recovering:1, /* there are recoverable clients */
766 obd_abort_recovery:1,/* somebody ioctl'ed us to abort */
767 obd_replayable:1, /* recovery is enabled; inform clients */
768 obd_no_transno:1, /* no committed-transno notification */
769 obd_no_recov:1, /* fail instead of retry messages */
770 obd_stopping:1, /* started cleanup */
771 obd_starting:1, /* started setup */
772 obd_force:1, /* cleanup with > 0 obd refcount */
773 obd_fail:1, /* cleanup with failover */
774 obd_async_recov:1, /* allow asyncronous orphan cleanup */
775 obd_no_conn:1, /* deny new connections */
776 obd_inactive:1; /* device active/inactive
777 * (for /proc/status only!!) */
778 /* uuid-export hash body */
779 struct lustre_class_hash_body *obd_uuid_hash_body;
780 /* nid-export hash body */
781 struct lustre_class_hash_body *obd_nid_hash_body;
783 struct lustre_class_hash_body *obd_nid_stats_hash_body;
784 struct list_head obd_nid_stats;
785 atomic_t obd_refcount;
786 cfs_waitq_t obd_refcount_waitq;
787 cfs_waitq_t obd_llog_waitq;
788 struct list_head obd_exports;
791 struct ldlm_namespace *obd_namespace;
792 struct ptlrpc_client obd_ldlm_client; /* XXX OST/MDS only */
793 /* a spinlock is OK for what we do now, may need a semaphore later */
794 spinlock_t obd_dev_lock;
795 struct semaphore obd_dev_sem;
796 __u64 obd_last_committed;
797 struct fsfilt_operations *obd_fsops;
798 spinlock_t obd_osfs_lock;
799 struct obd_statfs obd_osfs; /* locked by obd_osfs_lock */
801 struct lvfs_run_ctxt obd_lvfs_ctxt;
802 struct llog_ctxt *obd_llog_ctxt[LLOG_MAX_CTXTS];
803 struct obd_device *obd_observer;
804 struct obd_notify_upcall obd_upcall;
805 struct obd_export *obd_self_export;
806 /* list of exports in LRU order, for ping evictor, with obd_dev_lock */
807 struct list_head obd_exports_timed;
808 time_t obd_eviction_timer; /* for ping evictor */
810 /* XXX encapsulate all this recovery data into one struct */
811 svc_handler_t obd_recovery_handler;
812 int obd_max_recoverable_clients;
813 int obd_connected_clients;
814 int obd_recoverable_clients;
815 spinlock_t obd_processing_task_lock; /* BH lock (timer) */
816 pid_t obd_processing_task;
817 __u64 obd_next_recovery_transno;
818 int obd_replayed_requests;
819 int obd_requests_queued_for_recovery;
820 cfs_waitq_t obd_next_transno_waitq;
821 struct list_head obd_uncommitted_replies;
822 spinlock_t obd_uncommitted_replies_lock;
823 cfs_timer_t obd_recovery_timer;
824 struct list_head obd_recovery_queue;
825 struct list_head obd_delayed_reply_queue;
826 time_t obd_recovery_start; /* seconds */
827 time_t obd_recovery_end; /* seconds, for lprocfs_status */
829 time_t obd_recovery_max_time; /* seconds, bz13079 */
831 int obd_recovery_timeout;
834 struct obd_device_target obt;
835 struct filter_obd filter;
837 struct client_obd cli;
839 struct echo_client_obd echo_client;
840 struct echo_obd echo;
844 /* Fields used by LProcFS */
845 cfs_proc_dir_entry_t *obd_proc_entry;
846 cfs_proc_dir_entry_t *obd_proc_exports_entry;
847 cfs_proc_dir_entry_t *obd_svc_procroot;
848 struct lprocfs_stats *obd_stats;
849 struct lprocfs_stats *obd_svc_stats;
850 unsigned int obd_cntr_base;
851 atomic_t obd_evict_inprogress;
852 cfs_waitq_t obd_evict_inprogress_waitq;
855 #define OBD_OPT_FORCE 0x0001
856 #define OBD_OPT_FAILOVER 0x0002
858 #define OBD_LLOG_FL_SENDNOW 0x0001
860 enum obd_cleanup_stage {
861 /* Special case hack for MDS LOVs */
863 /* Precleanup stage 1, we must make sure all exports (other than the
864 self-export) get destroyed. */
866 /* Precleanup stage 2, do other type-specific cleanup requiring the
868 OBD_CLEANUP_SELF_EXP,
869 /* FIXME we should eliminate the "precleanup" function and make them stages
870 of the "cleanup" function. */
874 /* get/set_info keys */
875 #define KEY_MDS_CONN "mds_conn"
876 #define KEY_NEXT_ID "next_id"
877 #define KEY_LOVDESC "lovdesc"
878 #define KEY_INIT_RECOV "initial_recov"
879 #define KEY_INIT_RECOV_BACKUP "init_recov_bk"
880 #define KEY_LOV_IDX "lov_idx"
881 #define KEY_LAST_ID "last_id"
884 struct module *o_owner;
885 int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
886 void *karg, void *uarg);
887 int (*o_get_info)(struct obd_export *, __u32 keylen, void *key,
888 __u32 *vallen, void *val);
889 int (*o_set_info_async)(struct obd_export *, __u32 keylen, void *key,
890 __u32 vallen, void *val,
891 struct ptlrpc_request_set *set);
892 int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
893 int (*o_detach)(struct obd_device *dev);
894 int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
895 int (*o_precleanup)(struct obd_device *dev,
896 enum obd_cleanup_stage cleanup_stage);
897 int (*o_cleanup)(struct obd_device *dev);
898 int (*o_process_config)(struct obd_device *dev, obd_count len,
900 int (*o_postrecov)(struct obd_device *dev);
901 int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
903 int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
904 /* connect to the target device with given connection
905 * data. @ocd->ocd_connect_flags is modified to reflect flags actually
906 * granted by the target, which are guaranteed to be a subset of flags
907 * asked for. If @ocd == NULL, use default parameters. */
908 int (*o_connect)(struct lustre_handle *conn, struct obd_device *src,
909 struct obd_uuid *cluuid, struct obd_connect_data *ocd,
911 int (*o_reconnect)(struct obd_export *exp, struct obd_device *src,
912 struct obd_uuid *cluuid,
913 struct obd_connect_data *ocd);
914 int (*o_disconnect)(struct obd_export *exp);
916 int (*o_statfs)(struct obd_device *obd, struct obd_statfs *osfs,
918 int (*o_statfs_async)(struct obd_device *obd, struct obd_info *oinfo,
919 __u64 max_age, struct ptlrpc_request_set *set);
920 int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
921 struct lov_stripe_md *mem_src);
922 int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
923 struct lov_mds_md *disk_src, int disk_len);
924 int (*o_checkmd)(struct obd_export *exp, struct obd_export *md_exp,
925 struct lov_stripe_md *mem_tgt);
926 int (*o_preallocate)(struct lustre_handle *, obd_count *req,
928 int (*o_precreate)(struct obd_export *exp);
929 int (*o_create)(struct obd_export *exp, struct obdo *oa,
930 struct lov_stripe_md **ea, struct obd_trans_info *oti);
931 int (*o_destroy)(struct obd_export *exp, struct obdo *oa,
932 struct lov_stripe_md *ea, struct obd_trans_info *oti,
933 struct obd_export *md_exp);
934 int (*o_setattr)(struct obd_export *exp, struct obd_info *oinfo,
935 struct obd_trans_info *oti);
936 int (*o_setattr_async)(struct obd_export *exp, struct obd_info *oinfo,
937 struct obd_trans_info *oti,
938 struct ptlrpc_request_set *rqset);
939 int (*o_getattr)(struct obd_export *exp, struct obd_info *oinfo);
940 int (*o_getattr_async)(struct obd_export *exp, struct obd_info *oinfo,
941 struct ptlrpc_request_set *set);
942 int (*o_brw)(int rw, struct obd_export *exp, struct obd_info *oinfo,
943 obd_count oa_bufs, struct brw_page *pgarr,
944 struct obd_trans_info *oti);
945 int (*o_brw_async)(int rw, struct obd_export *exp,
946 struct obd_info *oinfo, obd_count oa_bufs,
947 struct brw_page *pgarr, struct obd_trans_info *oti,
948 struct ptlrpc_request_set *);
949 int (*o_prep_async_page)(struct obd_export *exp,
950 struct lov_stripe_md *lsm,
951 struct lov_oinfo *loi,
952 cfs_page_t *page, obd_off offset,
953 struct obd_async_page_ops *ops, void *data,
954 void **res, int nocache,
955 struct lustre_handle *lockh);
956 int (*o_queue_async_io)(struct obd_export *exp,
957 struct lov_stripe_md *lsm,
958 struct lov_oinfo *loi, void *cookie,
959 int cmd, obd_off off, int count,
960 obd_flag brw_flags, obd_flag async_flags);
961 int (*o_queue_group_io)(struct obd_export *exp,
962 struct lov_stripe_md *lsm,
963 struct lov_oinfo *loi,
964 struct obd_io_group *oig,
965 void *cookie, int cmd, obd_off off, int count,
966 obd_flag brw_flags, obd_flag async_flags);
967 int (*o_trigger_group_io)(struct obd_export *exp,
968 struct lov_stripe_md *lsm,
969 struct lov_oinfo *loi,
970 struct obd_io_group *oig);
971 int (*o_set_async_flags)(struct obd_export *exp,
972 struct lov_stripe_md *lsm,
973 struct lov_oinfo *loi, void *cookie,
974 obd_flag async_flags);
975 int (*o_teardown_async_page)(struct obd_export *exp,
976 struct lov_stripe_md *lsm,
977 struct lov_oinfo *loi, void *cookie);
978 int (*o_merge_lvb)(struct obd_export *exp, struct lov_stripe_md *lsm,
979 struct ost_lvb *lvb, int kms_only);
980 int (*o_adjust_kms)(struct obd_export *exp, struct lov_stripe_md *lsm,
981 obd_off size, int shrink);
982 int (*o_punch)(struct obd_export *exp, struct obd_info *oinfo,
983 struct obd_trans_info *oti,
984 struct ptlrpc_request_set *rqset);
985 int (*o_sync)(struct obd_export *exp, struct obdo *oa,
986 struct lov_stripe_md *ea, obd_size start, obd_size end);
987 int (*o_migrate)(struct lustre_handle *conn, struct lov_stripe_md *dst,
988 struct lov_stripe_md *src, obd_size start,
989 obd_size end, struct obd_trans_info *oti);
990 int (*o_copy)(struct lustre_handle *dstconn, struct lov_stripe_md *dst,
991 struct lustre_handle *srconn, struct lov_stripe_md *src,
992 obd_size start, obd_size end, struct obd_trans_info *);
993 int (*o_iterate)(struct lustre_handle *conn,
994 int (*)(obd_id, obd_gr, void *),
995 obd_id *startid, obd_gr group, void *data);
996 int (*o_preprw)(int cmd, struct obd_export *exp, struct obdo *oa,
997 int objcount, struct obd_ioobj *obj,
998 int niocount, struct niobuf_remote *remote,
999 struct niobuf_local *local, struct obd_trans_info *oti);
1000 int (*o_commitrw)(int cmd, struct obd_export *exp, struct obdo *oa,
1001 int objcount, struct obd_ioobj *obj,
1002 int niocount, struct niobuf_local *local,
1003 struct obd_trans_info *oti, int rc);
1004 int (*o_enqueue)(struct obd_export *, struct obd_info *oinfo,
1005 struct ldlm_enqueue_info *einfo,
1006 struct ptlrpc_request_set *rqset);
1007 int (*o_match)(struct obd_export *, struct lov_stripe_md *, __u32 type,
1008 ldlm_policy_data_t *, __u32 mode, int *flags, void *data,
1009 struct lustre_handle *lockh);
1010 int (*o_change_cbdata)(struct obd_export *, struct lov_stripe_md *,
1011 ldlm_iterator_t it, void *data);
1012 int (*o_cancel)(struct obd_export *, struct lov_stripe_md *md,
1013 __u32 mode, struct lustre_handle *);
1014 int (*o_cancel_unused)(struct obd_export *, struct lov_stripe_md *,
1015 int flags, void *opaque);
1016 int (*o_join_lru)(struct obd_export *, struct lov_stripe_md *,
1018 int (*o_init_export)(struct obd_export *exp);
1019 int (*o_destroy_export)(struct obd_export *exp);
1020 int (*o_extent_calc)(struct obd_export *, struct lov_stripe_md *,
1021 int cmd, obd_off *);
1023 /* llog related obd_methods */
1024 int (*o_llog_init)(struct obd_device *obd, struct obd_device *disk_obd,
1025 int count, struct llog_catid *logid,
1026 struct obd_uuid *uuid);
1027 int (*o_llog_finish)(struct obd_device *obd, int count);
1029 /* metadata-only methods */
1030 int (*o_pin)(struct obd_export *, obd_id ino, __u32 gen, int type,
1031 struct obd_client_handle *, int flag);
1032 int (*o_unpin)(struct obd_export *, struct obd_client_handle *, int);
1034 int (*o_import_event)(struct obd_device *, struct obd_import *,
1035 enum obd_import_event);
1037 int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
1038 enum obd_notify_event ev, void *data);
1040 int (*o_health_check)(struct obd_device *);
1043 int (*o_quotacheck)(struct obd_export *, struct obd_quotactl *);
1044 int (*o_quotactl)(struct obd_export *, struct obd_quotactl *);
1045 int (*o_quota_adjust_qunit)(struct obd_export *exp,
1046 struct quota_adjust_qunit *oqaq);
1049 int (*o_ping)(struct obd_export *exp);
1051 int (*o_register_page_removal_cb)(struct obd_export *exp,
1052 obd_page_removal_cb_t cb,
1053 obd_pin_extent_cb pin_cb);
1054 int (*o_unregister_page_removal_cb)(struct obd_export *exp,
1055 obd_page_removal_cb_t cb);
1056 int (*o_register_lock_cancel_cb)(struct obd_export *exp,
1057 obd_lock_cancel_cb cb);
1058 int (*o_unregister_lock_cancel_cb)(struct obd_export *exp,
1059 obd_lock_cancel_cb cb);
1062 * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
1063 * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
1064 * Also, add a wrapper function in include/linux/obd_class.h. */
1067 struct lsm_operations {
1068 void (*lsm_free)(struct lov_stripe_md *);
1069 int (*lsm_destroy)(struct lov_stripe_md *, struct obdo *oa,
1070 struct obd_export *md_exp);
1071 void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *, obd_off *,
1073 void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *, obd_off *,
1075 obd_off (*lsm_stripe_offset_by_index)(struct lov_stripe_md *, int);
1076 obd_off (*lsm_stripe_offset_by_offset)(struct lov_stripe_md *, obd_off);
1077 int (*lsm_stripe_index_by_offset)(struct lov_stripe_md *, obd_off);
1078 int (*lsm_revalidate) (struct lov_stripe_md *, struct obd_device *obd);
1079 int (*lsm_lmm_verify) (struct lov_mds_md *lmm, int lmm_bytes,
1081 int (*lsm_unpackmd) (struct lov_obd *lov, struct lov_stripe_md *lsm,
1082 struct lov_mds_md *lmm);
1085 extern struct lsm_operations lsm_plain_ops;
1086 extern struct lsm_operations lsm_join_ops;
1087 static inline struct lsm_operations *lsm_op_find(int magic)
1091 return &lsm_plain_ops;
1092 case LOV_MAGIC_JOIN:
1093 return &lsm_join_ops;
1095 CERROR("Cannot recognize lsm_magic %d", magic);
1100 int lvfs_check_io_health(struct obd_device *obd, struct file *file);
1102 /* Requests for obd_extent_calc() */
1103 #define OBD_CALC_STRIPE_START 1
1104 #define OBD_CALC_STRIPE_END 2
1106 static inline void obd_transno_commit_cb(struct obd_device *obd, __u64 transno,
1110 CERROR("%s: transno "LPD64" commit error: %d\n",
1111 obd->obd_name, transno, error);
1114 CDEBUG(D_HA, "%s: transno "LPD64" committed\n",
1115 obd->obd_name, transno);
1116 if (transno > obd->obd_last_committed) {
1117 obd->obd_last_committed = transno;
1118 ptlrpc_commit_replies (obd);
1122 static inline void init_obd_quota_ops(quota_interface_t *interface,
1123 struct obd_ops *obd_ops)
1129 obd_ops->o_quotacheck = QUOTA_OP(interface, check);
1130 obd_ops->o_quotactl = QUOTA_OP(interface, ctl);
1131 obd_ops->o_quota_adjust_qunit = QUOTA_OP(interface, adjust_qunit);
1139 /* Default preferred checksum algorithm to use (if supported by the server) */
1140 #define OSC_DEFAULT_CKSUM OBD_CKSUM_ADLER
1141 /* Adler-32 is supported */
1142 #define CHECKSUM_ADLER OBD_CKSUM_ADLER
1144 #define OSC_DEFAULT_CKSUM OBD_CKSUM_CRC32
1145 #define CHECKSUM_ADLER 0
1148 #define OBD_CKSUM_ALL (OBD_CKSUM_CRC32 | CHECKSUM_ADLER)
1150 /* Checksum algorithm names. Must be defined in the same order as the
1151 * OBD_CKSUM_* flags. */
1152 #define DECLARE_CKSUM_NAME char *cksum_name[] = {"crc32", "adler"}
1154 #endif /* __OBD_H */