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/lustre_idl.h>
31 #include <lu_object.h>
32 #include <lustre_lib.h>
33 #include <lustre_export.h>
34 #include <lustre_quota.h>
35 #include <lustre_fld.h>
37 #define MAX_OBD_DEVICES 8192
39 /* this is really local to the OSC */
40 struct loi_oap_pages {
41 struct list_head lop_pending;
42 struct list_head lop_urgent;
43 struct list_head lop_pending_group;
53 struct lov_oinfo { /* per-stripe data structure */
54 __u64 loi_id; /* object ID on the target OST */
55 __u64 loi_gr; /* object group on the target OST */
56 int loi_ost_idx; /* OST stripe index in lov_tgt_desc->tgts */
57 int loi_ost_gen; /* generation of this loi_ost_idx */
59 /* used by the osc to keep track of what objects to build into rpcs */
60 struct loi_oap_pages loi_read_lop;
61 struct loi_oap_pages loi_write_lop;
62 /* _cli_ is poorly named, it should be _ready_ */
63 struct list_head loi_cli_item;
64 struct list_head loi_write_item;
65 struct list_head loi_read_item;
67 unsigned loi_kms_valid:1;
68 __u64 loi_kms; /* known minimum size */
69 struct ost_lvb loi_lvb;
70 struct osc_async_rc loi_ar;
73 static inline void loi_init(struct lov_oinfo *loi)
75 CFS_INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending);
76 CFS_INIT_LIST_HEAD(&loi->loi_read_lop.lop_urgent);
77 CFS_INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending_group);
78 CFS_INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending);
79 CFS_INIT_LIST_HEAD(&loi->loi_write_lop.lop_urgent);
80 CFS_INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending_group);
81 CFS_INIT_LIST_HEAD(&loi->loi_cli_item);
82 CFS_INIT_LIST_HEAD(&loi->loi_write_item);
83 CFS_INIT_LIST_HEAD(&loi->loi_read_item);
86 /*extent array item for describing the joined file extent info*/
88 __u64 le_start; /* extent start */
89 __u64 le_len; /* extent length */
90 int le_loi_idx; /* extent #1 loi's index in lsm loi array */
91 int le_stripe_count; /* extent stripe count*/
94 /*Lov array info for describing joined file array EA info*/
95 struct lov_array_info {
96 struct llog_logid lai_array_id; /* MDS med llog object id */
97 unsigned lai_ext_count; /* number of extent count */
98 struct lov_extent *lai_ext_array; /* extent desc array */
101 struct lov_stripe_md {
103 void *lsm_lock_owner; /* debugging */
106 /* Public members. */
107 __u64 lw_object_id; /* lov object id */
108 __u64 lw_object_gr; /* lov object group */
109 __u64 lw_maxbytes; /* maximum possible file size */
111 /* LOV-private members start here -- only for use in lov/. */
113 __u32 lw_stripe_size; /* size of the stripe */
114 __u32 lw_pattern; /* striping pattern (RAID0, RAID1) */
115 unsigned lw_stripe_count; /* number of objects being striped over */
118 struct lov_array_info *lsm_array; /*Only for joined file array info*/
119 struct lov_oinfo lsm_oinfo[0];
122 #define lsm_object_id lsm_wire.lw_object_id
123 #define lsm_object_gr lsm_wire.lw_object_gr
124 #define lsm_maxbytes lsm_wire.lw_maxbytes
125 #define lsm_magic lsm_wire.lw_magic
126 #define lsm_stripe_size lsm_wire.lw_stripe_size
127 #define lsm_pattern lsm_wire.lw_pattern
128 #define lsm_stripe_count lsm_wire.lw_stripe_count
132 typedef int (*obd_enqueue_update_f)(struct obd_info *oinfo, int rc);
134 /* obd_enqueue parameters common for all levels (lov, osc). */
135 struct obd_enqueue_info {
136 /* Flags used while lock handling. */
138 /* Type of the lock being enqueued. */
140 /* Mode of the lock being enqueued. */
142 /* Different callbacks for lock handling (blocking, completion,
147 /* Data to be passed into callbacks. */
149 /* Request set for OSC async requests. */
150 struct ptlrpc_request_set *ei_rqset;
153 /* obd info for a particular level (lov, osc). */
155 /* Lock policy. It keeps an extent which is specific for a particular
156 * OSC. (e.g. lov_prep_enqueue_set initialises extent of the policy,
157 * and osc_enqueue passes it into ldlm_lock_match & ldlm_cli_enqueue. */
158 ldlm_policy_data_t oi_policy;
159 /* Lock handle specific for every OSC lock. */
160 struct lustre_handle *oi_lockh;
161 /* lsm data specific for every OSC. */
162 struct lov_stripe_md *oi_md;
163 /* obdo data specific for every OSC, if needed at all. */
165 /* statfs data specific for every OSC, if needed at all. */
166 struct obd_statfs *oi_osfs;
167 /* An update callback which is called to update some data on upper
168 * level. E.g. it is used for update lsm->lsm_oinfo at every recieved
169 * request in osc level for enqueue requests. It is also possible to
170 * update some caller data from LOV layer if needed. */
171 obd_enqueue_update_f oi_cb_up;
174 /* compare all relevant fields. */
175 static inline int lov_stripe_md_cmp(struct lov_stripe_md *m1,
176 struct lov_stripe_md *m2)
179 * ->lsm_wire contains padding, but it should be zeroed out during
182 return memcmp(&m1->lsm_wire, &m2->lsm_wire, sizeof m1->lsm_wire);
185 void lov_stripe_lock(struct lov_stripe_md *md);
186 void lov_stripe_unlock(struct lov_stripe_md *md);
189 struct list_head typ_chain;
190 struct obd_ops *typ_dt_ops;
191 struct md_ops *typ_md_ops;
192 struct proc_dir_entry *typ_procroot;
195 struct lu_device_type *typ_lu;
196 spinlock_t obd_type_lock;
207 ASYNC_READY = 0x1, /* ap_make_ready will not be called before this
208 page is added to an rpc */
209 ASYNC_URGENT = 0x2, /* page must be put into an RPC before return */
210 ASYNC_COUNT_STABLE = 0x4, /* ap_refresh_count will not be called
211 to give the caller a chance to update
212 or cancel the size of the io */
213 ASYNC_GROUP_SYNC = 0x8, /* ap_completion will not be called, instead
214 the page is accounted for in the
215 obd_io_group given to
216 obd_queue_group_io */
219 struct obd_async_page_ops {
220 int (*ap_make_ready)(void *data, int cmd);
221 int (*ap_refresh_count)(void *data, int cmd);
222 void (*ap_fill_obdo)(void *data, int cmd, struct obdo *oa);
223 void (*ap_update_obdo)(void *data, int cmd, struct obdo *oa,
225 int (*ap_completion)(void *data, int cmd, struct obdo *oa, int rc);
228 /* the `oig' is passed down from a caller of obd rw methods. the callee
229 * records enough state such that the caller can sleep on the oig and
230 * be woken when all the callees have finished their work */
231 struct obd_io_group {
233 atomic_t oig_refcount;
236 struct list_head oig_occ_list;
237 cfs_waitq_t oig_waitq;
240 /* the oig callback context lets the callee of obd rw methods register
241 * for callbacks from the caller. */
242 struct oig_callback_context {
243 struct list_head occ_oig_item;
244 /* called when the caller has received a signal while sleeping.
245 * callees of this method are encouraged to abort their state
246 * in the oig. This may be called multiple times. */
247 void (*occ_interrupted)(struct oig_callback_context *occ);
248 unsigned int interrupted:1;
251 /* if we find more consumers this could be generalized */
252 #define OBD_HIST_MAX 32
253 struct obd_histogram {
255 unsigned long oh_buckets[OBD_HIST_MAX];
258 /* Individual type definitions */
260 struct ost_server_data;
262 /* hold common fields for "target" device */
263 struct obd_device_target {
264 struct super_block *obt_sb;
265 atomic_t obt_quotachecking;
266 struct lustre_quota_ctxt obt_qctxt;
269 #define FILTER_SUBDIR_COUNT 32 /* set to zero for no subdirs */
271 #define FILTER_GROUP_LLOG 1
272 #define FILTER_GROUP_ECHO 2
273 #define FILTER_GROUP_MDS0 3
275 struct filter_subdirs {
276 cfs_dentry_t *dentry[FILTER_SUBDIR_COUNT];
286 /* NB this field MUST be first */
287 struct obd_device_target fo_obt;
288 const char *fo_fstype;
289 struct vfsmount *fo_vfsmnt;
292 cfs_dentry_t *fo_dentry_O;
293 cfs_dentry_t **fo_dentry_O_groups;
294 struct filter_subdirs *fo_dentry_O_sub;
295 struct semaphore fo_init_lock; /* group initialization lock */
296 int fo_committed_group;
299 spinlock_t fo_objidlock; /* protect fo_lastobjid */
300 spinlock_t fo_translock; /* protect fsd_last_transno */
301 struct file *fo_rcvd_filp;
302 struct file *fo_health_check_filp;
303 struct lr_server_data *fo_fsd;
304 unsigned long *fo_last_rcvd_slots;
305 __u64 fo_mount_count;
307 int fo_destroy_in_progress;
308 struct semaphore fo_create_lock;
310 struct list_head fo_export_list;
313 obd_size fo_tot_dirty; /* protected by obd_osfs_lock */
314 obd_size fo_tot_granted; /* all values in bytes */
315 obd_size fo_tot_pending;
317 obd_size fo_readcache_max_filesize;
319 struct obd_import *fo_mdc_imp;
320 struct obd_uuid fo_mdc_uuid;
321 struct lustre_handle fo_mdc_conn;
322 struct file **fo_last_objid_files;
323 __u64 *fo_last_objids; /* last created objid for groups,
324 * protected by fo_objidlock */
326 struct semaphore fo_alloc_lock;
328 atomic_t fo_r_in_flight;
329 atomic_t fo_w_in_flight;
332 * per-filter pool of kiobuf's allocated by filter_common_setup() and
333 * torn down by filter_cleanup(). Contains OST_NUM_THREADS elements of
334 * which ->fo_iobuf_count were allocated.
336 * This pool contains kiobuf used by
337 * filter_{prep,commit}rw_{read,write}() and is shared by all OST
340 * Locking: none, each OST thread uses only one element, determined by
341 * its "ordinal number", ->t_id.
343 struct filter_iobuf **fo_iobuf_pool;
346 struct obd_histogram fo_r_pages;
347 struct obd_histogram fo_w_pages;
348 struct obd_histogram fo_read_rpc_hist;
349 struct obd_histogram fo_write_rpc_hist;
350 struct obd_histogram fo_r_io_time;
351 struct obd_histogram fo_w_io_time;
352 struct obd_histogram fo_r_discont_pages;
353 struct obd_histogram fo_w_discont_pages;
354 struct obd_histogram fo_r_discont_blocks;
355 struct obd_histogram fo_w_discont_blocks;
356 struct obd_histogram fo_r_disk_iosize;
357 struct obd_histogram fo_w_disk_iosize;
358 struct obd_histogram fo_r_dio_frags;
359 struct obd_histogram fo_w_dio_frags;
361 struct lustre_quota_ctxt fo_quota_ctxt;
362 spinlock_t fo_quotacheck_lock;
363 atomic_t fo_quotachecking;
365 int fo_fmd_max_num; /* per exp filter_mod_data */
366 int fo_fmd_max_age; /* jiffies to fmd expiry */
369 #define OSC_MAX_RIF_DEFAULT 8
370 #define OSC_MAX_RIF_MAX 256
371 #define OSC_MAX_DIRTY_DEFAULT (OSC_MAX_RIF_DEFAULT * 4)
372 #define OSC_MAX_DIRTY_MB_MAX 2048 /* totally arbitrary */
374 #define MDC_MAX_RIF_DEFAULT 8
375 #define MDC_MAX_RIF_MAX 512
380 struct semaphore cl_sem;
381 struct obd_uuid cl_target_uuid;
382 struct obd_import *cl_import; /* ptlrpc connection state */
384 /* max_mds_easize is purely a performance thing so we don't have to
385 * call obd_size_diskmd() all the time. */
386 int cl_default_mds_easize;
387 int cl_max_mds_easize;
388 int cl_max_mds_cookiesize;
390 /* security configuration */
391 struct sec_flavor_config cl_sec_conf;
393 //struct llog_canceld_ctxt *cl_llcd; /* it's included by obd_llog_ctxt */
394 void *cl_llcd_offset;
396 /* the grant values are protected by loi_list_lock below */
397 long cl_dirty; /* all _dirty_ in bytes */
398 long cl_dirty_max; /* allowed w/o rpc */
399 long cl_avail_grant; /* bytes of credit for ost */
400 long cl_lost_grant; /* lost credits (trunc) */
401 struct list_head cl_cache_waiters; /* waiting for cache/grant */
403 /* keep track of objects that have lois that contain pages which
404 * have been queued for async brw. this lock also protects the
405 * lists of osc_client_pages that hang off of the loi */
407 * ->cl_loi_list_lock protects consistency of
408 * ->cl_loi_{ready,read,write}_list. ->ap_make_ready() and
409 * ->ap_completion() call-backs are executed under this lock. As we
410 * cannot guarantee that these call-backs never block on all platforms
411 * (as a matter of fact they do block on Mac OS X), type of
412 * ->cl_loi_list_lock is platform dependent: it's a spin-lock on Linux
413 * and blocking mutex on Mac OS X. (Alternative is to make this lock
414 * blocking everywhere, but we don't want to slow down fast-path of
415 * our main platform.)
417 * Exact type of ->cl_loi_list_lock is defined in arch/obd.h together
418 * with client_obd_list_{un,}lock() and
419 * client_obd_list_lock_{init,done}() functions.
421 client_obd_lock_t cl_loi_list_lock;
422 struct list_head cl_loi_ready_list;
423 struct list_head cl_loi_write_list;
424 struct list_head cl_loi_read_list;
427 /* just a sum of the loi/lop pending numbers to be exported by /proc */
428 int cl_pending_w_pages;
429 int cl_pending_r_pages;
430 int cl_max_pages_per_rpc;
431 int cl_max_rpcs_in_flight;
432 struct obd_histogram cl_read_rpc_hist;
433 struct obd_histogram cl_write_rpc_hist;
434 struct obd_histogram cl_read_page_hist;
435 struct obd_histogram cl_write_page_hist;
436 struct obd_histogram cl_read_offset_hist;
437 struct obd_histogram cl_write_offset_hist;
439 struct mdc_rpc_lock *cl_rpc_lock;
440 struct mdc_rpc_lock *cl_setattr_lock;
441 struct mdc_rpc_lock *cl_close_lock;
442 struct osc_creator cl_oscc;
445 struct semaphore cl_mgc_sem;
446 struct vfsmount *cl_mgc_vfsmnt;
447 struct dentry *cl_mgc_configs_dir;
448 atomic_t cl_mgc_refcount;
449 struct obd_export *cl_mgc_mgsexp;
452 unsigned int cl_checksum:1; /* debug checksums */
454 /* also protected by the poorly named _loi_list_lock lock above */
455 struct osc_async_rc cl_ar;
457 /* used by quotacheck */
458 int cl_qchk_stat; /* quotacheck stat of the peer */
460 /* sequence manager */
461 struct lu_client_seq *cl_seq;
463 #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
465 #define CL_NOT_QUOTACHECKED 1 /* client->cl_qchk_stat init value */
468 struct ptlrpc_service *mgs_service;
469 struct vfsmount *mgs_vfsmnt;
470 struct super_block *mgs_sb;
471 struct dentry *mgs_configs_dir;
472 struct dentry *mgs_fid_de;
473 struct list_head mgs_fs_db_list;
474 struct semaphore mgs_sem;
478 /* NB this field MUST be first */
479 struct obd_device_target mds_obt;
480 struct ptlrpc_service *mds_service;
481 struct ptlrpc_service *mds_setattr_service;
482 struct ptlrpc_service *mds_readpage_service;
483 struct vfsmount *mds_vfsmnt;
484 cfs_dentry_t *mds_fid_de;
486 int mds_max_cookiesize;
487 struct file *mds_rcvd_filp;
488 spinlock_t mds_transno_lock;
489 __u64 mds_last_transno;
490 __u64 mds_mount_count;
492 unsigned long mds_atime_diff;
493 struct semaphore mds_epoch_sem;
494 struct ll_fid mds_rootfid;
495 struct lr_server_data *mds_server_data;
496 cfs_dentry_t *mds_pending_dir;
497 cfs_dentry_t *mds_logs_dir;
498 cfs_dentry_t *mds_objects_dir;
499 struct llog_handle *mds_cfg_llh;
500 // struct llog_handle *mds_catalog;
501 struct obd_device *mds_osc_obd; /* XXX lov_obd */
502 struct obd_uuid mds_lov_uuid;
504 struct obd_export *mds_osc_exp; /* XXX lov_exp */
505 struct lov_desc mds_lov_desc;
507 obd_id *mds_lov_objids;
508 int mds_lov_objids_size;
509 __u32 mds_lov_objids_in_file;
510 unsigned int mds_lov_objids_dirty:1;
511 int mds_lov_nextid_set;
512 struct file *mds_lov_objid_filp;
513 struct file *mds_health_check_filp;
514 unsigned long *mds_client_bitmap;
515 struct upcall_cache *mds_group_hash;
517 struct lustre_quota_info mds_quota_info;
518 struct semaphore mds_qonoff_sem;
519 struct semaphore mds_health_sem;
520 unsigned long mds_lov_objids_valid:1,
529 struct lustre_handle eo_nl_lock;
534 struct ptlrpc_service *ost_service;
535 struct ptlrpc_service *ost_create_service;
536 struct ptlrpc_service *ost_io_service;
537 struct semaphore ost_health_sem;
540 struct echo_client_obd {
541 struct obd_export *ec_exp; /* the local connection to osc/lov */
543 struct list_head ec_objects;
549 struct obd_uuid lqo_uuid; /* ptlrpc's c_remote_uuid */
550 struct list_head lqo_oss_list; /* link to lov_qos */
551 __u32 lqo_ost_count; /* number of osts on this oss */
552 __u64 lqo_bavail; /* total bytes avail on OSS */
553 __u64 lqo_penalty; /* current penalty */
554 __u64 lqo_penalty_per_obj; /* penalty decrease every obj*/
558 struct lov_qos_oss *ltq_oss; /* oss info */
559 __u64 ltq_penalty; /* current penalty */
560 __u64 ltq_penalty_per_obj; /* penalty decrease every obj*/
561 __u64 ltq_weight; /* net weighting */
562 unsigned int ltq_usable:1; /* usable for striping */
566 struct list_head lq_oss_list; /* list of OSSs that targets use */
567 struct rw_semaphore lq_rw_sem;
568 __u32 lq_active_oss_count;
569 __u32 *lq_rr_array; /* round-robin optimized list */
570 unsigned int lq_rr_size; /* rr array size */
571 unsigned int lq_prio_free; /* priority for free space */
572 unsigned int lq_dirty:1, /* recalc qos data */
573 lq_dirty_rr:1, /* recalc round-robin list */
574 lq_same_space:1,/* the ost's all have approx.
575 the same space avail */
576 lq_reset:1; /* zero current penalties */
579 struct lov_tgt_desc {
580 struct obd_uuid ltd_uuid;
581 struct obd_export *ltd_exp;
582 struct ltd_qos ltd_qos; /* qos info per target */
584 __u32 ltd_index; /* index in lov_obd->tgts */
585 unsigned int ltd_active:1,/* is this target up for requests */
586 ltd_activate:1,/* should this target be activated */
587 ltd_reap:1; /* should this target be deleted */
591 struct lov_desc desc;
592 struct lov_tgt_desc **lov_tgts;
593 struct semaphore lov_lock;
594 struct obd_connect_data lov_ocd;
595 struct lov_qos lov_qos; /* qos info per lov */
596 atomic_t lov_refcount;
597 __u32 lov_tgt_count; /* how many OBD's */
598 __u32 lov_active_tgt_count; /* how many active */
599 __u32 lov_death_row;/* tgts scheduled to be deleted */
600 __u32 lov_tgt_size; /* size of tgts array */
601 __u32 lov_start_idx; /* start index of new inode */
602 __u32 lov_offset_idx; /* aliasing for start_idx */
603 int lov_start_count;/* reseed counter */
607 struct lmv_tgt_desc {
608 struct obd_uuid uuid;
609 struct obd_export *ltd_exp;
610 int active; /* is this target up for requests */
616 struct lu_client_fld lmv_fld;
618 struct lmv_desc desc;
619 struct obd_uuid cluuid;
620 struct obd_export *exp;
627 struct semaphore init_sem;
629 struct lmv_tgt_desc *tgts;
632 struct obd_connect_data *datas;
635 struct obd_connect_data conn_data;
638 struct niobuf_local {
643 cfs_dentry_t *dentry;
648 #define LUSTRE_OPC_MKDIR (1 << 0)
649 #define LUSTRE_OPC_SYMLINK (1 << 1)
650 #define LUSTRE_OPC_MKNOD (1 << 2)
651 #define LUSTRE_OPC_CREATE (1 << 3)
653 struct lu_placement_hint {
654 struct qstr *ph_pname;
655 struct lu_fid *ph_pfid;
656 struct qstr *ph_cname;
660 #define LUSTRE_FLD_NAME "fld"
661 #define LUSTRE_SEQ_NAME "seq"
663 #define LUSTRE_CMM_NAME "cmm"
664 #define LUSTRE_MDD_NAME "mdd"
665 #define LUSTRE_OSD_NAME "osd"
666 #define LUSTRE_LMV_NAME "lmv"
667 #define LUSTRE_CMM_MDC_NAME "cmm-mdc"
669 /* obd device type names */
670 /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */
671 #define LUSTRE_MDS_NAME "mds"
672 #define LUSTRE_MDT_NAME "mdt"
673 #define LUSTRE_MDC_NAME "mdc"
674 #define LUSTRE_OSS_NAME "ost" /* FIXME change name to oss */
675 #define LUSTRE_OST_NAME "obdfilter" /* FIXME change name to ost */
676 #define LUSTRE_OSC_NAME "osc"
677 #define LUSTRE_LOV_NAME "lov"
678 #define LUSTRE_MGS_NAME "mgs"
679 #define LUSTRE_MGC_NAME "mgc"
681 #define LUSTRE_CACHEOBD_NAME "cobd"
682 #define LUSTRE_ECHO_NAME "obdecho"
683 #define LUSTRE_ECHO_CLIENT_NAME "echo_client"
685 /* Constant obd names (post-rename) */
686 #define LUSTRE_MDS_OBDNAME "MDS"
687 #define LUSTRE_OSS_OBDNAME "OSS"
688 #define LUSTRE_MGS_OBDNAME "MGS"
689 #define LUSTRE_MGC_OBDNAME "MGC"
691 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
692 #define N_LOCAL_TEMP_PAGE 0x10000000
694 struct obd_trans_info {
698 /* Only used on the server side for tracking acks. */
699 struct oti_req_ack_lock {
700 struct lustre_handle lock;
704 struct llog_cookie oti_onecookie;
705 struct llog_cookie *oti_logcookies;
708 /* initial thread handling transaction */
713 static inline void oti_init(struct obd_trans_info *oti,
714 struct ptlrpc_request *req)
718 memset(oti, 0, sizeof *oti);
723 oti->oti_xid = req->rq_xid;
725 if (req->rq_repmsg && req->rq_reqmsg != 0)
726 oti->oti_transno = lustre_msg_get_transno(req->rq_repmsg);
727 oti->oti_thread_id = req->rq_svc_thread ? req->rq_svc_thread->t_id : -1;
728 oti->oti_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg);
731 static inline void oti_alloc_cookies(struct obd_trans_info *oti,int num_cookies)
736 if (num_cookies == 1)
737 oti->oti_logcookies = &oti->oti_onecookie;
739 OBD_ALLOC(oti->oti_logcookies,
740 num_cookies * sizeof(oti->oti_onecookie));
742 oti->oti_numcookies = num_cookies;
745 static inline void oti_free_cookies(struct obd_trans_info *oti)
747 if (!oti || !oti->oti_logcookies)
750 if (oti->oti_logcookies == &oti->oti_onecookie)
751 LASSERT(oti->oti_numcookies == 1);
753 OBD_FREE(oti->oti_logcookies,
754 oti->oti_numcookies * sizeof(oti->oti_onecookie));
755 oti->oti_logcookies = NULL;
756 oti->oti_numcookies = 0;
761 LLOG_CONFIG_ORIG_CTXT = 0,
762 LLOG_CONFIG_REPL_CTXT = 1,
763 LLOG_MDS_OST_ORIG_CTXT = 2,
764 LLOG_MDS_OST_REPL_CTXT = 3,
765 LLOG_SIZE_ORIG_CTXT = 4,
766 LLOG_SIZE_REPL_CTXT = 5,
767 LLOG_MD_ORIG_CTXT = 6,
768 LLOG_MD_REPL_CTXT = 7,
769 LLOG_RD1_ORIG_CTXT = 8,
770 LLOG_RD1_REPL_CTXT = 9,
771 LLOG_TEST_ORIG_CTXT = 10,
772 LLOG_TEST_REPL_CTXT = 11,
773 LLOG_LOVEA_ORIG_CTXT = 12,
774 LLOG_LOVEA_REPL_CTXT = 13,
779 * Events signalled through obd_notify() upcall-chain.
781 enum obd_notify_event {
782 /* Device activated */
784 /* Device deactivated */
786 /* Connect data for import were changed */
789 OBD_NOTIFY_SYNC_NONBLOCK,
793 #include <lu_object.h>
795 * Data structure used to pass obd_notify()-event to non-obd listeners (llite
796 * and liblustre being main examples).
798 struct obd_notify_upcall {
799 int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
800 enum obd_notify_event ev, void *owner);
801 /* Opaque datum supplied by upper layer listener */
805 /* corresponds to one of the obd's */
806 #define MAX_OBD_NAME 128
807 #define OBD_DEVICE_MAGIC 0XAB5CD6EF
809 struct obd_type *obd_type;
812 /* common and UUID name of this device */
813 char obd_name[MAX_OBD_NAME];
814 struct obd_uuid obd_uuid;
816 struct lu_device *obd_lu_dev;
819 unsigned int obd_attached:1, /* finished attach */
820 obd_set_up:1, /* finished setup */
821 obd_recovering:1, /* there are recoverable clients */
822 obd_abort_recovery:1,/* somebody ioctl'ed us to abort */
823 obd_replayable:1, /* recovery is enabled; inform clients */
824 obd_no_transno:1, /* no committed-transno notification */
825 obd_no_recov:1, /* fail instead of retry messages */
826 obd_stopping:1, /* started cleanup */
827 obd_starting:1, /* started setup */
828 obd_force:1, /* cleanup with > 0 obd refcount */
829 obd_fail:1, /* cleanup with failover */
830 obd_async_recov:1; /* allow asyncronous orphan cleanup */
831 atomic_t obd_refcount;
832 cfs_waitq_t obd_refcount_waitq;
833 cfs_proc_dir_entry_t *obd_proc_entry;
834 struct list_head obd_exports;
836 struct ldlm_namespace *obd_namespace;
837 struct ptlrpc_client obd_ldlm_client; /* XXX OST/MDS only */
838 /* a spinlock is OK for what we do now, may need a semaphore later */
839 spinlock_t obd_dev_lock;
840 struct semaphore obd_dev_sem;
841 __u64 obd_last_committed;
842 struct fsfilt_operations *obd_fsops;
843 spinlock_t obd_osfs_lock;
844 struct obd_statfs obd_osfs; /* locked by obd_osfs_lock */
846 struct lvfs_run_ctxt obd_lvfs_ctxt;
847 struct llog_ctxt *obd_llog_ctxt[LLOG_MAX_CTXTS];
848 struct obd_device *obd_observer;
849 struct obd_notify_upcall obd_upcall;
850 struct obd_export *obd_self_export;
851 /* list of exports in LRU order, for ping evictor, with obd_dev_lock */
852 struct list_head obd_exports_timed;
853 time_t obd_eviction_timer; /* for ping evictor */
855 /* XXX encapsulate all this recovery data into one struct */
856 svc_handler_t obd_recovery_handler;
857 int obd_max_recoverable_clients;
858 int obd_connected_clients;
859 int obd_recoverable_clients;
860 spinlock_t obd_processing_task_lock; /* BH lock (timer) */
861 pid_t obd_processing_task;
862 __u64 obd_next_recovery_transno;
863 int obd_replayed_requests;
864 int obd_requests_queued_for_recovery;
865 cfs_waitq_t obd_next_transno_waitq;
866 struct list_head obd_uncommitted_replies;
867 spinlock_t obd_uncommitted_replies_lock;
868 cfs_timer_t obd_recovery_timer;
869 struct list_head obd_recovery_queue;
870 struct list_head obd_delayed_reply_queue;
871 time_t obd_recovery_start;
872 time_t obd_recovery_end;
875 struct obd_device_target obt;
876 struct filter_obd filter;
878 struct client_obd cli;
880 struct echo_client_obd echo_client;
881 struct echo_obd echo;
886 /* Fields used by LProcFS */
887 unsigned int obd_cntr_base;
888 struct lprocfs_stats *obd_stats;
890 unsigned int md_cntr_base;
891 struct lprocfs_stats *md_stats;
893 cfs_proc_dir_entry_t *obd_svc_procroot;
894 struct lprocfs_stats *obd_svc_stats;
897 #define OBD_OPT_FORCE 0x0001
898 #define OBD_OPT_FAILOVER 0x0002
900 #define OBD_LLOG_FL_SENDNOW 0x0001
902 enum obd_cleanup_stage {
903 /* Special case hack for MDS LOVs */
905 /* Precleanup stage 1, we must make sure all exports (other than the
906 self-export) get destroyed. */
908 /* Precleanup stage 2, do other type-specific cleanup requiring the
910 OBD_CLEANUP_SELF_EXP,
911 /* FIXME we should eliminate the "precleanup" function and make them stages
912 of the "cleanup" function. */
916 /* get/set_info keys */
917 #define KEY_MDS_CONN "mds_conn"
918 #define KEY_NEXT_ID "next_id"
919 #define KEY_LOVDESC "lovdesc"
920 #define KEY_INIT_RECOV "initial_recov"
921 #define KEY_INIT_RECOV_BACKUP "init_recov_bk"
922 #define KEY_FLUSH_CTX "flush_ctx"
927 struct module *o_owner;
928 int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
929 void *karg, void *uarg);
930 int (*o_get_info)(struct obd_export *, __u32 keylen, void *key,
931 __u32 *vallen, void *val);
932 int (*o_set_info_async)(struct obd_export *, __u32 keylen, void *key,
933 __u32 vallen, void *val,
934 struct ptlrpc_request_set *set);
935 int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
936 int (*o_detach)(struct obd_device *dev);
937 int (*o_setup) (struct obd_device *dev, struct lustre_cfg *cfg);
938 int (*o_precleanup)(struct obd_device *dev,
939 enum obd_cleanup_stage cleanup_stage);
940 int (*o_cleanup)(struct obd_device *dev);
941 int (*o_process_config)(struct obd_device *dev, obd_count len,
943 int (*o_postrecov)(struct obd_device *dev);
944 int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
946 int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
947 /* connect to the target device with given connection
948 * data. @ocd->ocd_connect_flags is modified to reflect flags actually
949 * granted by the target, which are guaranteed to be a subset of flags
950 * asked for. If @ocd == NULL, use default parameters. */
951 int (*o_connect)(const struct lu_context *ctx,
952 struct lustre_handle *conn, struct obd_device *src,
953 struct obd_uuid *cluuid, struct obd_connect_data *ocd);
954 int (*o_reconnect)(struct obd_export *exp, struct obd_device *src,
955 struct obd_uuid *cluuid,
956 struct obd_connect_data *ocd);
957 int (*o_disconnect)(struct obd_export *exp);
959 /* maybe later these should be moved into separate fid_ops */
960 int (*o_fid_init)(struct obd_export *exp);
961 int (*o_fid_fini)(struct obd_export *exp);
963 int (*o_fid_alloc)(struct obd_export *exp, struct lu_fid *fid,
964 struct lu_placement_hint *hint);
966 int (*o_fid_delete)(struct obd_export *exp, const struct lu_fid *fid);
968 int (*o_statfs)(struct obd_device *obd, struct obd_statfs *osfs,
970 int (*o_statfs_async)(struct obd_device *obd, struct obd_info *oinfo,
971 __u64 max_age, struct ptlrpc_request_set *set);
972 int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
973 struct lov_stripe_md *mem_src);
974 int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
975 struct lov_mds_md *disk_src, int disk_len);
976 int (*o_checkmd)(struct obd_export *exp, struct obd_export *md_exp,
977 struct lov_stripe_md *mem_tgt);
978 int (*o_preallocate)(struct lustre_handle *, obd_count *req,
980 int (*o_create)(struct obd_export *exp, struct obdo *oa,
981 struct lov_stripe_md **ea, struct obd_trans_info *oti);
982 int (*o_destroy)(struct obd_export *exp, struct obdo *oa,
983 struct lov_stripe_md *ea, struct obd_trans_info *oti,
984 struct obd_export *md_exp);
985 int (*o_setattr)(struct obd_export *exp, struct obd_info *oinfo,
986 struct obd_trans_info *oti);
987 int (*o_setattr_async)(struct obd_export *exp, struct obd_info *oinfo,
988 struct obd_trans_info *oti,
989 struct ptlrpc_request_set *rqset);
990 int (*o_getattr)(struct obd_export *exp, struct obd_info *oinfo);
991 int (*o_getattr_async)(struct obd_export *exp, struct obd_info *oinfo,
992 struct ptlrpc_request_set *set);
993 int (*o_brw)(int rw, struct obd_export *exp, struct obd_info *oinfo,
994 obd_count oa_bufs, struct brw_page *pgarr,
995 struct obd_trans_info *oti);
996 int (*o_brw_async)(int rw, struct obd_export *exp,
997 struct obd_info *oinfo, obd_count oa_bufs,
998 struct brw_page *pgarr, struct obd_trans_info *oti,
999 struct ptlrpc_request_set *);
1000 int (*o_prep_async_page)(struct obd_export *exp,
1001 struct lov_stripe_md *lsm,
1002 struct lov_oinfo *loi,
1003 struct page *page, obd_off offset,
1004 struct obd_async_page_ops *ops, void *data,
1006 int (*o_queue_async_io)(struct obd_export *exp,
1007 struct lov_stripe_md *lsm,
1008 struct lov_oinfo *loi, void *cookie,
1009 int cmd, obd_off off, int count,
1010 obd_flag brw_flags, obd_flag async_flags);
1011 int (*o_queue_group_io)(struct obd_export *exp,
1012 struct lov_stripe_md *lsm,
1013 struct lov_oinfo *loi,
1014 struct obd_io_group *oig,
1015 void *cookie, int cmd, obd_off off, int count,
1016 obd_flag brw_flags, obd_flag async_flags);
1017 int (*o_trigger_group_io)(struct obd_export *exp,
1018 struct lov_stripe_md *lsm,
1019 struct lov_oinfo *loi,
1020 struct obd_io_group *oig);
1021 int (*o_set_async_flags)(struct obd_export *exp,
1022 struct lov_stripe_md *lsm,
1023 struct lov_oinfo *loi, void *cookie,
1024 obd_flag async_flags);
1025 int (*o_teardown_async_page)(struct obd_export *exp,
1026 struct lov_stripe_md *lsm,
1027 struct lov_oinfo *loi, void *cookie);
1028 int (*o_merge_lvb)(struct obd_export *exp, struct lov_stripe_md *lsm,
1029 struct ost_lvb *lvb, int kms_only);
1030 int (*o_adjust_kms)(struct obd_export *exp, struct lov_stripe_md *lsm,
1031 obd_off size, int shrink);
1032 int (*o_punch)(struct obd_export *exp, struct obd_info *oinfo,
1033 struct obd_trans_info *oti,
1034 struct ptlrpc_request_set *rqset);
1035 int (*o_sync)(struct obd_export *exp, struct obdo *oa,
1036 struct lov_stripe_md *ea, obd_size start, obd_size end);
1037 int (*o_migrate)(struct lustre_handle *conn, struct lov_stripe_md *dst,
1038 struct lov_stripe_md *src, obd_size start,
1039 obd_size end, struct obd_trans_info *oti);
1040 int (*o_copy)(struct lustre_handle *dstconn, struct lov_stripe_md *dst,
1041 struct lustre_handle *srconn, struct lov_stripe_md *src,
1042 obd_size start, obd_size end, struct obd_trans_info *);
1043 int (*o_iterate)(struct lustre_handle *conn,
1044 int (*)(obd_id, obd_gr, void *),
1045 obd_id *startid, obd_gr group, void *data);
1046 int (*o_preprw)(int cmd, struct obd_export *exp, struct obdo *oa,
1047 int objcount, struct obd_ioobj *obj,
1048 int niocount, struct niobuf_remote *remote,
1049 struct niobuf_local *local, struct obd_trans_info *oti);
1050 int (*o_commitrw)(int cmd, struct obd_export *exp, struct obdo *oa,
1051 int objcount, struct obd_ioobj *obj,
1052 int niocount, struct niobuf_local *local,
1053 struct obd_trans_info *oti, int rc);
1054 int (*o_enqueue)(struct obd_export *, struct obd_info *oinfo,
1055 struct obd_enqueue_info *einfo);
1056 int (*o_match)(struct obd_export *, struct lov_stripe_md *, __u32 type,
1057 ldlm_policy_data_t *, __u32 mode, int *flags, void *data,
1058 struct lustre_handle *lockh);
1059 int (*o_change_cbdata)(struct obd_export *, struct lov_stripe_md *,
1060 ldlm_iterator_t it, void *data);
1061 int (*o_cancel)(struct obd_export *, struct lov_stripe_md *md,
1062 __u32 mode, struct lustre_handle *);
1063 int (*o_cancel_unused)(struct obd_export *, struct lov_stripe_md *,
1064 int flags, void *opaque);
1065 int (*o_join_lru)(struct obd_export *, struct lov_stripe_md *,
1067 int (*o_init_export)(struct obd_export *exp);
1068 int (*o_destroy_export)(struct obd_export *exp);
1069 int (*o_extent_calc)(struct obd_export *, struct lov_stripe_md *,
1070 int cmd, obd_off *);
1072 /* llog related obd_methods */
1073 int (*o_llog_init)(struct obd_device *obd, struct obd_device *disk_obd,
1074 int count, struct llog_catid *logid,
1075 struct obd_uuid *uuid);
1076 int (*o_llog_finish)(struct obd_device *obd, int count);
1078 /* metadata-only methods */
1079 int (*o_pin)(struct obd_export *, const struct lu_fid *fid,
1080 struct obd_client_handle *, int flag);
1081 int (*o_unpin)(struct obd_export *, struct obd_client_handle *, int);
1083 int (*o_import_event)(struct obd_device *, struct obd_import *,
1084 enum obd_import_event);
1086 int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
1087 enum obd_notify_event ev, void *data);
1089 int (*o_health_check)(struct obd_device *);
1092 int (*o_quotacheck)(struct obd_export *, struct obd_quotactl *);
1093 int (*o_quotactl)(struct obd_export *, struct obd_quotactl *);
1095 int (*o_ping)(struct obd_export *exp);
1097 * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
1098 * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
1099 * Also, add a wrapper function in include/linux/obd_class.h. */
1103 int (*m_getstatus)(struct obd_export *, struct lu_fid *);
1104 int (*m_change_cbdata)(struct obd_export *, const struct lu_fid *,
1105 ldlm_iterator_t, void *);
1106 int (*m_close)(struct obd_export *, struct md_op_data *,
1107 struct obd_client_handle *, struct ptlrpc_request **);
1108 int (*m_create)(struct obd_export *, struct md_op_data *,
1109 const void *, int, int, __u32, __u32, __u32,
1110 __u64, struct ptlrpc_request **);
1111 int (*m_done_writing)(struct obd_export *, struct md_op_data *);
1112 int (*m_enqueue)(struct obd_export *, int, struct lookup_intent *,
1113 int, struct md_op_data *, struct lustre_handle *,
1114 void *, int, ldlm_completion_callback,
1115 ldlm_blocking_callback, void *, int);
1116 int (*m_getattr)(struct obd_export *, const struct lu_fid *,
1117 obd_valid, int, struct ptlrpc_request **);
1118 int (*m_getattr_name)(struct obd_export *, const struct lu_fid *,
1119 const char *, int, obd_valid,
1120 int, struct ptlrpc_request **);
1121 int (*m_intent_lock)(struct obd_export *, struct md_op_data *,
1122 void *, int, struct lookup_intent *, int,
1123 struct ptlrpc_request **,
1124 ldlm_blocking_callback, int);
1125 int (*m_link)(struct obd_export *, struct md_op_data *,
1126 struct ptlrpc_request **);
1127 int (*m_rename)(struct obd_export *, struct md_op_data *,
1128 const char *, int, const char *, int,
1129 struct ptlrpc_request **);
1130 int (*m_setattr)(struct obd_export *, struct md_op_data *,
1131 struct iattr *, void *, int , void *, int,
1132 struct ptlrpc_request **);
1133 int (*m_sync)(struct obd_export *, const struct lu_fid *,
1134 struct ptlrpc_request **);
1135 int (*m_readpage)(struct obd_export *, const struct lu_fid *,
1136 __u64, struct page *, struct ptlrpc_request **);
1138 int (*m_unlink)(struct obd_export *, struct md_op_data *,
1139 struct ptlrpc_request **);
1141 int (*m_setxattr)(struct obd_export *, const struct lu_fid *,
1142 obd_valid, const char *, const char *,
1143 int, int, int, struct ptlrpc_request **);
1145 int (*m_getxattr)(struct obd_export *, const struct lu_fid *,
1146 obd_valid, const char *, const char *,
1147 int, int, int, struct ptlrpc_request **);
1149 int (*m_init_ea_size)(struct obd_export *, int, int, int);
1151 int (*m_get_lustre_md)(struct obd_export *, struct ptlrpc_request *,
1152 int, struct obd_export *, struct obd_export *,
1153 struct lustre_md *);
1155 int (*m_free_lustre_md)(struct obd_export *, struct lustre_md *);
1157 int (*m_set_open_replay_data)(struct obd_export *,
1158 struct obd_client_handle *,
1159 struct ptlrpc_request *);
1160 int (*m_clear_open_replay_data)(struct obd_export *,
1161 struct obd_client_handle *);
1162 int (*m_set_lock_data)(struct obd_export *, __u64 *, void *);
1164 int (*m_lock_match)(struct obd_export *, int, const struct lu_fid *,
1165 ldlm_type_t, ldlm_policy_data_t *, ldlm_mode_t,
1166 struct lustre_handle *);
1168 int (*m_cancel_unused)(struct obd_export *, const struct lu_fid *,
1169 int flags, void *opaque);
1172 * NOTE: If adding ops, add another LPROCFS_MD_OP_INIT() line to
1173 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
1174 * wrapper function in include/linux/obd_class.h.
1178 struct lsm_operations {
1179 void (*lsm_free)(struct lov_stripe_md *);
1180 int (*lsm_destroy)(struct lov_stripe_md *, struct obdo *oa,
1181 struct obd_export *md_exp);
1182 void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *, obd_off *,
1184 void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *, obd_off *,
1186 obd_off (*lsm_stripe_offset_by_index)(struct lov_stripe_md *, int);
1187 obd_off (*lsm_stripe_offset_by_offset)(struct lov_stripe_md *, obd_off);
1188 int (*lsm_stripe_index_by_offset)(struct lov_stripe_md *, obd_off);
1189 int (*lsm_revalidate) (struct lov_stripe_md *, struct obd_device *obd);
1190 int (*lsm_lmm_verify) (struct lov_mds_md *lmm, int lmm_bytes,
1192 int (*lsm_unpackmd) (struct lov_obd *lov, struct lov_stripe_md *lsm,
1193 struct lov_mds_md *lmm);
1196 extern struct lsm_operations lsm_plain_ops;
1197 extern struct lsm_operations lsm_join_ops;
1198 static inline struct lsm_operations *lsm_op_find(int magic)
1202 return &lsm_plain_ops;
1203 case LOV_MAGIC_JOIN:
1204 return &lsm_join_ops;
1206 CERROR("Cannot recognize lsm_magic %d", magic);
1211 int lvfs_check_io_health(struct obd_device *obd, struct file *file);
1213 /* Requests for obd_extent_calc() */
1214 #define OBD_CALC_STRIPE_START 1
1215 #define OBD_CALC_STRIPE_END 2
1217 static inline void obd_transno_commit_cb(struct obd_device *obd, __u64 transno,
1221 CERROR("%s: transno "LPD64" commit error: %d\n",
1222 obd->obd_name, transno, error);
1225 CDEBUG(D_HA, "%s: transno "LPD64" committed\n",
1226 obd->obd_name, transno);
1227 if (transno > obd->obd_last_committed) {
1228 obd->obd_last_committed = transno;
1229 ptlrpc_commit_replies (obd);
1233 static inline void init_obd_quota_ops(quota_interface_t *interface,
1234 struct obd_ops *obd_ops)
1240 obd_ops->o_quotacheck = QUOTA_OP(interface, check);
1241 obd_ops->o_quotactl = QUOTA_OP(interface, ctl);
1244 #endif /* __OBD_H */