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 for set request specific flags:
143 - while lock handling, the flags obtained on the enqueue
144 request are set here.
145 - while stats, the flags used for control delay/resend.
148 /* Lock handle specific for every OSC lock. */
149 struct lustre_handle *oi_lockh;
150 /* lsm data specific for every OSC. */
151 struct lov_stripe_md *oi_md;
152 /* obdo data specific for every OSC, if needed at all. */
154 /* statfs data specific for every OSC, if needed at all. */
155 struct obd_statfs *oi_osfs;
156 /* An update callback which is called to update some data on upper
157 * level. E.g. it is used for update lsm->lsm_oinfo at every recieved
158 * request in osc level for enqueue requests. It is also possible to
159 * update some caller data from LOV layer if needed. */
160 obd_enqueue_update_f oi_cb_up;
163 /* compare all relevant fields. */
164 static inline int lov_stripe_md_cmp(struct lov_stripe_md *m1,
165 struct lov_stripe_md *m2)
168 * ->lsm_wire contains padding, but it should be zeroed out during
171 return memcmp(&m1->lsm_wire, &m2->lsm_wire, sizeof m1->lsm_wire);
174 void lov_stripe_lock(struct lov_stripe_md *md);
175 void lov_stripe_unlock(struct lov_stripe_md *md);
178 struct list_head typ_chain;
179 struct obd_ops *typ_ops;
180 cfs_proc_dir_entry_t *typ_procroot;
183 spinlock_t obd_type_lock;
194 ASYNC_READY = 0x1, /* ap_make_ready will not be called before this
195 page is added to an rpc */
196 ASYNC_URGENT = 0x2, /* page must be put into an RPC before return */
197 ASYNC_COUNT_STABLE = 0x4, /* ap_refresh_count will not be called
198 to give the caller a chance to update
199 or cancel the size of the io */
200 ASYNC_GROUP_SYNC = 0x8, /* ap_completion will not be called, instead
201 the page is accounted for in the
202 obd_io_group given to
203 obd_queue_group_io */
206 struct obd_async_page_ops {
207 int (*ap_make_ready)(void *data, int cmd);
208 int (*ap_refresh_count)(void *data, int cmd);
209 void (*ap_fill_obdo)(void *data, int cmd, struct obdo *oa);
210 void (*ap_update_obdo)(void *data, int cmd, struct obdo *oa,
212 int (*ap_completion)(void *data, int cmd, struct obdo *oa, int rc);
215 /* the `oig' is passed down from a caller of obd rw methods. the callee
216 * records enough state such that the caller can sleep on the oig and
217 * be woken when all the callees have finished their work */
218 struct obd_io_group {
220 atomic_t oig_refcount;
223 struct list_head oig_occ_list;
224 cfs_waitq_t oig_waitq;
227 /* the oig callback context lets the callee of obd rw methods register
228 * for callbacks from the caller. */
229 struct oig_callback_context {
230 struct list_head occ_oig_item;
231 /* called when the caller has received a signal while sleeping.
232 * callees of this method are encouraged to abort their state
233 * in the oig. This may be called multiple times. */
234 void (*occ_interrupted)(struct oig_callback_context *occ);
235 unsigned long interrupted:1;
238 /* Individual type definitions */
240 struct ost_server_data;
242 /* hold common fields for "target" device */
243 struct obd_device_target {
244 struct super_block *obt_sb;
245 atomic_t obt_quotachecking;
246 struct lustre_quota_ctxt obt_qctxt;
249 typedef void (*obd_pin_extent_cb)(void *data);
250 typedef int (*obd_page_removal_cb_t)(void *data, int discard);
251 typedef int (*obd_lock_cancel_cb)(struct ldlm_lock *,struct ldlm_lock_desc *,
254 #define FILTER_GROUP_LLOG 1
255 #define FILTER_GROUP_ECHO 2
263 /* NB this field MUST be first */
264 struct obd_device_target fo_obt;
265 const char *fo_fstype;
266 struct vfsmount *fo_vfsmnt;
267 cfs_dentry_t *fo_dentry_O;
268 cfs_dentry_t **fo_dentry_O_groups;
269 cfs_dentry_t **fo_dentry_O_sub;
270 spinlock_t fo_objidlock; /* protect fo_lastobjid */
271 spinlock_t fo_translock; /* protect fsd_last_transno */
272 struct file *fo_rcvd_filp;
273 struct file *fo_health_check_filp;
274 struct lr_server_data *fo_fsd;
275 unsigned long *fo_last_rcvd_slots;
276 __u64 fo_mount_count;
278 int fo_destroy_in_progress;
279 struct semaphore fo_create_lock;
281 struct list_head fo_export_list;
284 obd_size fo_tot_dirty; /* protected by obd_osfs_lock */
285 obd_size fo_tot_granted; /* all values in bytes */
286 obd_size fo_tot_pending;
288 obd_size fo_readcache_max_filesize;
290 struct obd_import *fo_mdc_imp;
291 struct obd_uuid fo_mdc_uuid;
292 struct lustre_handle fo_mdc_conn;
293 struct file **fo_last_objid_files;
294 __u64 *fo_last_objids; /* last created objid for groups,
295 * protected by fo_objidlock */
297 struct semaphore fo_alloc_lock;
299 atomic_t fo_r_in_flight;
300 atomic_t fo_w_in_flight;
303 * per-filter pool of kiobuf's allocated by filter_common_setup() and
304 * torn down by filter_cleanup(). Contains OST_NUM_THREADS elements of
305 * which ->fo_iobuf_count were allocated.
307 * This pool contains kiobuf used by
308 * filter_{prep,commit}rw_{read,write}() and is shared by all OST
311 * Locking: none, each OST thread uses only one element, determined by
312 * its "ordinal number", ->t_id.
314 struct filter_iobuf **fo_iobuf_pool;
317 struct brw_stats fo_filter_stats;
318 struct lustre_quota_ctxt fo_quota_ctxt;
319 spinlock_t fo_quotacheck_lock;
320 atomic_t fo_quotachecking;
322 int fo_fmd_max_num; /* per exp filter_mod_data */
323 int fo_fmd_max_age; /* jiffies to fmd expiry */
327 #define OSC_MAX_RIF_DEFAULT 8
328 #define OSC_MAX_RIF_MAX 256
329 #define OSC_MAX_DIRTY_DEFAULT (OSC_MAX_RIF_DEFAULT * 4)
330 #define OSC_MAX_DIRTY_MB_MAX 2048 /* arbitrary, but < MAX_LONG bytes */
331 #define OSC_DEFAULT_RESENDS 10
333 #define MDC_MAX_RIF_DEFAULT 8
334 #define MDC_MAX_RIF_MAX 512
340 struct semaphore cl_sem;
341 struct obd_uuid cl_target_uuid;
342 struct obd_import *cl_import; /* ptlrpc connection state */
344 /* max_mds_easize is purely a performance thing so we don't have to
345 * call obd_size_diskmd() all the time. */
346 int cl_default_mds_easize;
347 int cl_max_mds_easize;
348 int cl_max_mds_cookiesize;
350 //struct llog_canceld_ctxt *cl_llcd; /* it's included by obd_llog_ctxt */
351 void *cl_llcd_offset;
353 /* the grant values are protected by loi_list_lock below */
354 long cl_dirty; /* all _dirty_ in bytes */
355 long cl_dirty_max; /* allowed w/o rpc */
356 long cl_avail_grant; /* bytes of credit for ost */
357 long cl_lost_grant; /* lost credits (trunc) */
358 struct list_head cl_cache_waiters; /* waiting for cache/grant */
360 /* keep track of objects that have lois that contain pages which
361 * have been queued for async brw. this lock also protects the
362 * lists of osc_client_pages that hang off of the loi */
364 * ->cl_loi_list_lock protects consistency of
365 * ->cl_loi_{ready,read,write}_list. ->ap_make_ready() and
366 * ->ap_completion() call-backs are executed under this lock. As we
367 * cannot guarantee that these call-backs never block on all platforms
368 * (as a matter of fact they do block on Mac OS X), type of
369 * ->cl_loi_list_lock is platform dependent: it's a spin-lock on Linux
370 * and blocking mutex on Mac OS X. (Alternative is to make this lock
371 * blocking everywhere, but we don't want to slow down fast-path of
372 * our main platform.)
374 * Exact type of ->cl_loi_list_lock is defined in arch/obd.h together
375 * with client_obd_list_{un,}lock() and
376 * client_obd_list_lock_{init,done}() functions.
378 client_obd_lock_t cl_loi_list_lock;
379 struct list_head cl_loi_ready_list;
380 struct list_head cl_loi_write_list;
381 struct list_head cl_loi_read_list;
384 /* just a sum of the loi/lop pending numbers to be exported by /proc */
385 int cl_pending_w_pages;
386 int cl_pending_r_pages;
387 int cl_max_pages_per_rpc;
388 int cl_max_rpcs_in_flight;
389 struct obd_histogram cl_read_rpc_hist;
390 struct obd_histogram cl_write_rpc_hist;
391 struct obd_histogram cl_read_page_hist;
392 struct obd_histogram cl_write_page_hist;
393 struct obd_histogram cl_read_offset_hist;
394 struct obd_histogram cl_write_offset_hist;
396 /* number of in flight destroy rpcs is limited to max_rpcs_in_flight */
397 atomic_t cl_destroy_in_flight;
398 cfs_waitq_t cl_destroy_waitq;
400 struct mdc_rpc_lock *cl_rpc_lock;
401 struct mdc_rpc_lock *cl_setattr_lock;
402 struct mdc_rpc_lock *cl_close_lock;
403 struct osc_creator cl_oscc;
406 struct semaphore cl_mgc_sem;
407 struct vfsmount *cl_mgc_vfsmnt;
408 struct dentry *cl_mgc_configs_dir;
409 atomic_t cl_mgc_refcount;
410 struct obd_export *cl_mgc_mgsexp;
412 /* checksumming for data sent over the network */
413 unsigned int cl_checksum:1; /* 0 = disabled, 1 = enabled */
414 /* supported checksum types that are worked out at connect time */
415 __u32 cl_supp_cksum_types;
416 /* checksum algorithm to be used */
417 cksum_type_t cl_cksum_type;
419 /* also protected by the poorly named _loi_list_lock lock above */
420 struct osc_async_rc cl_ar;
422 /* used by quotacheck */
423 int cl_qchk_stat; /* quotacheck stat of the peer */
424 atomic_t cl_resends; /* resend count */
425 /* Cache of triples */
426 struct lustre_cache *cl_cache;
427 obd_lock_cancel_cb cl_ext_lock_cancel_cb;
429 #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
431 #define CL_NOT_QUOTACHECKED 1 /* client->cl_qchk_stat init value */
434 struct ptlrpc_service *mgs_service;
435 struct vfsmount *mgs_vfsmnt;
436 struct super_block *mgs_sb;
437 struct dentry *mgs_configs_dir;
438 struct dentry *mgs_fid_de;
439 struct list_head mgs_fs_db_list;
440 struct semaphore mgs_sem;
441 cfs_proc_dir_entry_t *mgs_proc_live;
445 /* NB this field MUST be first */
446 struct obd_device_target mds_obt;
447 struct ptlrpc_service *mds_service;
448 struct ptlrpc_service *mds_setattr_service;
449 struct ptlrpc_service *mds_readpage_service;
450 struct vfsmount *mds_vfsmnt;
451 cfs_dentry_t *mds_fid_de;
453 int mds_max_cookiesize;
454 struct file *mds_rcvd_filp;
455 spinlock_t mds_transno_lock;
456 __u64 mds_last_transno;
457 __u64 mds_mount_count;
459 unsigned long mds_atime_diff;
460 struct semaphore mds_epoch_sem;
461 struct ll_fid mds_rootfid;
462 struct lr_server_data *mds_server_data;
463 cfs_dentry_t *mds_pending_dir;
464 cfs_dentry_t *mds_logs_dir;
465 cfs_dentry_t *mds_objects_dir;
466 struct llog_handle *mds_cfg_llh;
467 // struct llog_handle *mds_catalog;
468 struct obd_device *mds_osc_obd; /* XXX lov_obd */
469 struct obd_uuid mds_lov_uuid;
471 struct obd_export *mds_osc_exp; /* XXX lov_exp */
472 struct lov_desc mds_lov_desc;
474 /* mark pages dirty for write. */
475 bitmap_t *mds_lov_page_dirty;
476 /* array for store pages with obd_id */
477 void **mds_lov_page_array;
478 /* file for store objid */
479 struct file *mds_lov_objid_filp;
480 __u32 mds_lov_objid_count;
481 __u32 mds_lov_objid_lastpage;
482 __u32 mds_lov_objid_lastidx;
484 struct file *mds_health_check_filp;
485 unsigned long *mds_client_bitmap;
486 struct upcall_cache *mds_group_hash;
488 struct lustre_quota_info mds_quota_info;
489 struct semaphore mds_qonoff_sem;
490 struct semaphore mds_health_sem;
491 unsigned long mds_fl_user_xattr:1,
495 mds_evict_ost_nids:1;
497 uid_t mds_squash_uid;
498 gid_t mds_squash_gid;
499 lnet_nid_t mds_nosquash_nid;
503 #define mds_max_ost_index (0xFFFF)
504 #define MDS_LOV_ALLOC_SIZE (CFS_PAGE_SIZE)
506 #define OBJID_PER_PAGE() (MDS_LOV_ALLOC_SIZE / sizeof(obd_id))
508 #define MDS_LOV_OBJID_PAGES_COUNT (mds_max_ost_index/OBJID_PER_PAGE())
510 extern int mds_lov_init_objids(struct obd_device *obd);
511 extern void mds_lov_destroy_objids(struct obd_device *obd);
524 struct lustre_handle eo_nl_lock;
529 struct ptlrpc_service *ost_service;
530 struct ptlrpc_service *ost_create_service;
531 struct ptlrpc_service *ost_io_service;
532 struct semaphore ost_health_sem;
535 struct echo_client_obd {
536 struct obd_export *ec_exp; /* the local connection to osc/lov */
538 struct list_head ec_objects;
544 struct obd_uuid lqo_uuid; /* ptlrpc's c_remote_uuid */
545 struct list_head lqo_oss_list; /* link to lov_qos */
546 __u32 lqo_ost_count; /* number of osts on this oss */
547 __u64 lqo_bavail; /* total bytes avail on OSS */
548 __u64 lqo_penalty; /* current penalty */
549 __u64 lqo_penalty_per_obj; /* penalty decrease every obj*/
553 struct lov_qos_oss *ltq_oss; /* oss info */
554 __u64 ltq_penalty; /* current penalty */
555 __u64 ltq_penalty_per_obj; /* penalty decrease every obj*/
556 __u64 ltq_weight; /* net weighting */
557 unsigned int ltq_usable:1; /* usable for striping */
561 struct list_head lq_oss_list; /* list of OSSs that targets use */
562 struct rw_semaphore lq_rw_sem;
563 __u32 lq_active_oss_count;
564 __u32 *lq_rr_array; /* round-robin optimized list */
565 unsigned int lq_rr_size; /* rr array size */
566 unsigned int lq_prio_free; /* priority for free space */
567 unsigned long lq_dirty:1, /* recalc qos data */
568 lq_dirty_rr:1, /* recalc round-robin list */
569 lq_same_space:1,/* the ost's all have approx.
570 the same space avail */
571 lq_reset:1; /* zero current penalties */
574 struct lov_tgt_desc {
575 struct obd_uuid ltd_uuid;
576 struct obd_export *ltd_exp;
577 struct ltd_qos ltd_qos; /* qos info per target */
579 __u32 ltd_index; /* index in lov_obd->tgts */
580 unsigned long ltd_active:1,/* is this target up for requests */
581 ltd_activate:1,/* should this target be activated */
582 ltd_reap:1; /* should this target be deleted */
586 struct lov_desc desc;
587 struct lov_tgt_desc **lov_tgts;
588 struct semaphore lov_lock;
589 struct obd_connect_data lov_ocd;
590 struct lov_qos lov_qos; /* qos info per lov */
591 atomic_t lov_refcount;
592 __u32 lov_tgt_count; /* how many OBD's */
593 __u32 lov_active_tgt_count; /* how many active */
594 __u32 lov_death_row;/* tgts scheduled to be deleted */
595 __u32 lov_tgt_size; /* size of tgts array */
596 __u32 lov_start_idx; /* start index of new inode */
597 __u32 lov_offset_idx; /* aliasing for start_idx */
598 int lov_start_count;/* reseed counter */
600 obd_page_removal_cb_t lov_page_removal_cb;
601 obd_pin_extent_cb lov_page_pin_cb;
602 obd_lock_cancel_cb lov_lock_cancel_cb;
605 struct niobuf_local {
610 cfs_dentry_t *dentry;
615 /* obd device type names */
616 /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */
617 #define LUSTRE_MDS_NAME "mds"
618 #define LUSTRE_MDT_NAME "mdt"
619 #define LUSTRE_MDC_NAME "mdc"
620 #define LUSTRE_OSS_NAME "ost" /*FIXME change name to oss*/
621 #define LUSTRE_OST_NAME "obdfilter" /* FIXME change name to ost*/
622 #define LUSTRE_OSC_NAME "osc"
623 #define LUSTRE_LOV_NAME "lov"
624 #define LUSTRE_MGS_NAME "mgs"
625 #define LUSTRE_MGC_NAME "mgc"
627 #define LUSTRE_CACHEOBD_NAME "cobd"
628 #define LUSTRE_ECHO_NAME "obdecho"
629 #define LUSTRE_ECHO_CLIENT_NAME "echo_client"
631 /* Constant obd names (post-rename) */
632 #define LUSTRE_MDS_OBDNAME "MDS"
633 #define LUSTRE_OSS_OBDNAME "OSS"
634 #define LUSTRE_MGS_OBDNAME "MGS"
635 #define LUSTRE_MGC_OBDNAME "MGC"
637 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
638 #define N_LOCAL_TEMP_PAGE 0x10000000
640 struct obd_trans_info {
643 /* Only used on the server side for tracking acks. */
644 struct oti_req_ack_lock {
645 struct lustre_handle lock;
649 struct llog_cookie oti_onecookie;
650 struct llog_cookie *oti_logcookies;
653 /* initial thread handling transaction */
657 struct obd_uuid *oti_ost_uuid;
660 static inline void oti_init(struct obd_trans_info *oti,
661 struct ptlrpc_request *req)
665 memset(oti, 0, sizeof(*oti));
670 oti->oti_xid = req->rq_xid;
672 if (req->rq_repmsg != NULL)
673 oti->oti_transno = lustre_msg_get_transno(req->rq_repmsg);
674 oti->oti_thread_id = req->rq_svc_thread ? req->rq_svc_thread->t_id : -1;
675 if (req->rq_reqmsg != NULL)
676 oti->oti_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg);
679 static inline void oti_alloc_cookies(struct obd_trans_info *oti,int num_cookies)
684 if (num_cookies == 1)
685 oti->oti_logcookies = &oti->oti_onecookie;
687 OBD_ALLOC(oti->oti_logcookies,
688 num_cookies * sizeof(oti->oti_onecookie));
690 oti->oti_numcookies = num_cookies;
693 static inline void oti_free_cookies(struct obd_trans_info *oti)
695 if (!oti || !oti->oti_logcookies)
698 if (oti->oti_logcookies == &oti->oti_onecookie)
699 LASSERT(oti->oti_numcookies == 1);
701 OBD_FREE(oti->oti_logcookies,
702 oti->oti_numcookies * sizeof(oti->oti_onecookie));
703 oti->oti_logcookies = NULL;
704 oti->oti_numcookies = 0;
709 LLOG_CONFIG_ORIG_CTXT = 0,
710 LLOG_CONFIG_REPL_CTXT = 1,
711 LLOG_MDS_OST_ORIG_CTXT = 2,
712 LLOG_MDS_OST_REPL_CTXT = 3,
713 LLOG_SIZE_ORIG_CTXT = 4,
714 LLOG_SIZE_REPL_CTXT = 5,
715 LLOG_MD_ORIG_CTXT = 6,
716 LLOG_MD_REPL_CTXT = 7,
717 LLOG_RD1_ORIG_CTXT = 8,
718 LLOG_RD1_REPL_CTXT = 9,
719 LLOG_TEST_ORIG_CTXT = 10,
720 LLOG_TEST_REPL_CTXT = 11,
721 LLOG_LOVEA_ORIG_CTXT = 12,
722 LLOG_LOVEA_REPL_CTXT = 13,
727 * Events signalled through obd_notify() upcall-chain.
729 enum obd_notify_event {
730 /* Device activated */
732 /* Device deactivated */
734 /* Connect data for import were changed */
737 OBD_NOTIFY_SYNC_NONBLOCK,
739 /* Configuration event */
743 #define CONFIG_LOG 0x1 /* finished processing config log */
744 #define CONFIG_SYNC 0x2 /* mdt synced 1 ost */
747 * Data structure used to pass obd_notify()-event to non-obd listeners (llite
748 * and liblustre being main examples).
750 struct obd_notify_upcall {
751 int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
752 enum obd_notify_event ev, void *owner);
753 /* Opaque datum supplied by upper layer listener */
757 /* corresponds to one of the obd's */
758 #define MAX_OBD_NAME 128
759 #define OBD_DEVICE_MAGIC 0XAB5CD6EF
761 struct obd_type *obd_type;
764 /* common and UUID name of this device */
765 char obd_name[MAX_OBD_NAME];
766 struct obd_uuid obd_uuid;
769 unsigned long obd_attached:1, /* finished attach */
770 obd_set_up:1, /* finished setup */
771 obd_recovering:1, /* there are recoverable clients */
772 obd_abort_recovery:1,/* somebody ioctl'ed us to abort */
773 obd_replayable:1, /* recovery is enabled; inform clients */
774 obd_no_transno:1, /* no committed-transno notification */
775 obd_no_recov:1, /* fail instead of retry messages */
776 obd_stopping:1, /* started cleanup */
777 obd_starting:1, /* started setup */
778 obd_force:1, /* cleanup with > 0 obd refcount */
779 obd_fail:1, /* cleanup with failover */
780 obd_async_recov:1, /* allow asyncronous orphan cleanup */
781 obd_no_conn:1, /* deny new connections */
782 obd_inactive:1; /* device active/inactive
783 * (for /proc/status only!!) */
784 /* uuid-export hash body */
785 struct lustre_class_hash_body *obd_uuid_hash_body;
786 /* nid-export hash body */
787 struct lustre_class_hash_body *obd_nid_hash_body;
789 struct lustre_class_hash_body *obd_nid_stats_hash_body;
790 struct list_head obd_nid_stats;
791 atomic_t obd_refcount;
792 cfs_waitq_t obd_refcount_waitq;
793 cfs_waitq_t obd_llog_waitq;
794 struct list_head obd_exports;
797 struct ldlm_namespace *obd_namespace;
798 struct ptlrpc_client obd_ldlm_client; /* XXX OST/MDS only */
799 /* a spinlock is OK for what we do now, may need a semaphore later */
800 spinlock_t obd_dev_lock;
801 struct semaphore obd_dev_sem;
802 __u64 obd_last_committed;
803 struct fsfilt_operations *obd_fsops;
804 spinlock_t obd_osfs_lock;
805 struct obd_statfs obd_osfs; /* locked by obd_osfs_lock */
807 struct lvfs_run_ctxt obd_lvfs_ctxt;
808 struct llog_ctxt *obd_llog_ctxt[LLOG_MAX_CTXTS];
809 struct obd_device *obd_observer;
810 struct obd_notify_upcall obd_upcall;
811 struct obd_export *obd_self_export;
812 /* list of exports in LRU order, for ping evictor, with obd_dev_lock */
813 struct list_head obd_exports_timed;
814 time_t obd_eviction_timer; /* for ping evictor */
816 /* XXX encapsulate all this recovery data into one struct */
817 svc_handler_t obd_recovery_handler;
818 int obd_max_recoverable_clients;
819 int obd_connected_clients;
820 int obd_recoverable_clients;
821 spinlock_t obd_processing_task_lock; /* BH lock (timer) */
822 pid_t obd_processing_task;
823 __u64 obd_next_recovery_transno;
824 int obd_replayed_requests;
825 int obd_requests_queued_for_recovery;
826 cfs_waitq_t obd_next_transno_waitq;
827 struct list_head obd_uncommitted_replies;
828 spinlock_t obd_uncommitted_replies_lock;
829 cfs_timer_t obd_recovery_timer;
830 struct list_head obd_recovery_queue;
831 struct list_head obd_delayed_reply_queue;
832 time_t obd_recovery_start; /* seconds */
833 time_t obd_recovery_end; /* seconds, for lprocfs_status */
835 time_t obd_recovery_max_time; /* seconds, bz13079 */
837 int obd_recovery_timeout;
840 struct obd_device_target obt;
841 struct filter_obd filter;
843 struct client_obd cli;
845 struct echo_client_obd echo_client;
846 struct echo_obd echo;
850 /* Fields used by LProcFS */
851 cfs_proc_dir_entry_t *obd_proc_entry;
852 cfs_proc_dir_entry_t *obd_proc_exports_entry;
853 cfs_proc_dir_entry_t *obd_svc_procroot;
854 struct lprocfs_stats *obd_stats;
855 struct lprocfs_stats *obd_svc_stats;
856 unsigned int obd_cntr_base;
857 atomic_t obd_evict_inprogress;
858 cfs_waitq_t obd_evict_inprogress_waitq;
861 #define OBD_OPT_FORCE 0x0001
862 #define OBD_OPT_FAILOVER 0x0002
864 #define OBD_LLOG_FL_SENDNOW 0x0001
866 enum obd_cleanup_stage {
867 /* Special case hack for MDS LOVs */
869 /* Precleanup stage 1, we must make sure all exports (other than the
870 self-export) get destroyed. */
872 /* Precleanup stage 2, do other type-specific cleanup requiring the
874 OBD_CLEANUP_SELF_EXP,
875 /* FIXME we should eliminate the "precleanup" function and make them stages
876 of the "cleanup" function. */
880 /* get/set_info keys */
881 #define KEY_MDS_CONN "mds_conn"
882 #define KEY_NEXT_ID "next_id"
883 #define KEY_LOVDESC "lovdesc"
884 #define KEY_INIT_RECOV "initial_recov"
885 #define KEY_INIT_RECOV_BACKUP "init_recov_bk"
886 #define KEY_LOV_IDX "lov_idx"
887 #define KEY_LAST_ID "last_id"
890 struct module *o_owner;
891 int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
892 void *karg, void *uarg);
893 int (*o_get_info)(struct obd_export *, __u32 keylen, void *key,
894 __u32 *vallen, void *val);
895 int (*o_set_info_async)(struct obd_export *, __u32 keylen, void *key,
896 __u32 vallen, void *val,
897 struct ptlrpc_request_set *set);
898 int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
899 int (*o_detach)(struct obd_device *dev);
900 int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
901 int (*o_precleanup)(struct obd_device *dev,
902 enum obd_cleanup_stage cleanup_stage);
903 int (*o_cleanup)(struct obd_device *dev);
904 int (*o_process_config)(struct obd_device *dev, obd_count len,
906 int (*o_postrecov)(struct obd_device *dev);
907 int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
909 int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
910 /* connect to the target device with given connection
911 * data. @ocd->ocd_connect_flags is modified to reflect flags actually
912 * granted by the target, which are guaranteed to be a subset of flags
913 * asked for. If @ocd == NULL, use default parameters. */
914 int (*o_connect)(struct lustre_handle *conn, struct obd_device *src,
915 struct obd_uuid *cluuid, struct obd_connect_data *ocd,
917 int (*o_reconnect)(struct obd_export *exp, struct obd_device *src,
918 struct obd_uuid *cluuid,
919 struct obd_connect_data *ocd);
920 int (*o_disconnect)(struct obd_export *exp);
922 int (*o_statfs)(struct obd_device *obd, struct obd_statfs *osfs,
923 __u64 max_age, __u32 flags);
924 int (*o_statfs_async)(struct obd_device *obd, struct obd_info *oinfo,
925 __u64 max_age, struct ptlrpc_request_set *set);
926 int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
927 struct lov_stripe_md *mem_src);
928 int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
929 struct lov_mds_md *disk_src, int disk_len);
930 int (*o_checkmd)(struct obd_export *exp, struct obd_export *md_exp,
931 struct lov_stripe_md *mem_tgt);
932 int (*o_preallocate)(struct lustre_handle *, obd_count *req,
934 int (*o_precreate)(struct obd_export *exp);
935 int (*o_create)(struct obd_export *exp, struct obdo *oa,
936 struct lov_stripe_md **ea, struct obd_trans_info *oti);
937 int (*o_destroy)(struct obd_export *exp, struct obdo *oa,
938 struct lov_stripe_md *ea, struct obd_trans_info *oti,
939 struct obd_export *md_exp);
940 int (*o_setattr)(struct obd_export *exp, struct obd_info *oinfo,
941 struct obd_trans_info *oti);
942 int (*o_setattr_async)(struct obd_export *exp, struct obd_info *oinfo,
943 struct obd_trans_info *oti,
944 struct ptlrpc_request_set *rqset);
945 int (*o_getattr)(struct obd_export *exp, struct obd_info *oinfo);
946 int (*o_getattr_async)(struct obd_export *exp, struct obd_info *oinfo,
947 struct ptlrpc_request_set *set);
948 int (*o_brw)(int rw, struct obd_export *exp, struct obd_info *oinfo,
949 obd_count oa_bufs, struct brw_page *pgarr,
950 struct obd_trans_info *oti);
951 int (*o_brw_async)(int rw, struct obd_export *exp,
952 struct obd_info *oinfo, obd_count oa_bufs,
953 struct brw_page *pgarr, struct obd_trans_info *oti,
954 struct ptlrpc_request_set *);
955 int (*o_prep_async_page)(struct obd_export *exp,
956 struct lov_stripe_md *lsm,
957 struct lov_oinfo *loi,
958 cfs_page_t *page, obd_off offset,
959 struct obd_async_page_ops *ops, void *data,
960 void **res, int nocache,
961 struct lustre_handle *lockh);
962 int (*o_queue_async_io)(struct obd_export *exp,
963 struct lov_stripe_md *lsm,
964 struct lov_oinfo *loi, void *cookie,
965 int cmd, obd_off off, int count,
966 obd_flag brw_flags, obd_flag async_flags);
967 int (*o_queue_group_io)(struct obd_export *exp,
968 struct lov_stripe_md *lsm,
969 struct lov_oinfo *loi,
970 struct obd_io_group *oig,
971 void *cookie, int cmd, obd_off off, int count,
972 obd_flag brw_flags, obd_flag async_flags);
973 int (*o_trigger_group_io)(struct obd_export *exp,
974 struct lov_stripe_md *lsm,
975 struct lov_oinfo *loi,
976 struct obd_io_group *oig);
977 int (*o_set_async_flags)(struct obd_export *exp,
978 struct lov_stripe_md *lsm,
979 struct lov_oinfo *loi, void *cookie,
980 obd_flag async_flags);
981 int (*o_teardown_async_page)(struct obd_export *exp,
982 struct lov_stripe_md *lsm,
983 struct lov_oinfo *loi, void *cookie);
984 int (*o_merge_lvb)(struct obd_export *exp, struct lov_stripe_md *lsm,
985 struct ost_lvb *lvb, int kms_only);
986 int (*o_adjust_kms)(struct obd_export *exp, struct lov_stripe_md *lsm,
987 obd_off size, int shrink);
988 int (*o_punch)(struct obd_export *exp, struct obd_info *oinfo,
989 struct obd_trans_info *oti,
990 struct ptlrpc_request_set *rqset);
991 int (*o_sync)(struct obd_export *exp, struct obdo *oa,
992 struct lov_stripe_md *ea, obd_size start, obd_size end);
993 int (*o_migrate)(struct lustre_handle *conn, struct lov_stripe_md *dst,
994 struct lov_stripe_md *src, obd_size start,
995 obd_size end, struct obd_trans_info *oti);
996 int (*o_copy)(struct lustre_handle *dstconn, struct lov_stripe_md *dst,
997 struct lustre_handle *srconn, struct lov_stripe_md *src,
998 obd_size start, obd_size end, struct obd_trans_info *);
999 int (*o_iterate)(struct lustre_handle *conn,
1000 int (*)(obd_id, obd_gr, void *),
1001 obd_id *startid, obd_gr group, void *data);
1002 int (*o_preprw)(int cmd, struct obd_export *exp, struct obdo *oa,
1003 int objcount, struct obd_ioobj *obj,
1004 int niocount, struct niobuf_remote *remote,
1005 struct niobuf_local *local, struct obd_trans_info *oti);
1006 int (*o_commitrw)(int cmd, struct obd_export *exp, struct obdo *oa,
1007 int objcount, struct obd_ioobj *obj,
1008 int niocount, struct niobuf_local *local,
1009 struct obd_trans_info *oti, int rc);
1010 int (*o_enqueue)(struct obd_export *, struct obd_info *oinfo,
1011 struct ldlm_enqueue_info *einfo,
1012 struct ptlrpc_request_set *rqset);
1013 int (*o_match)(struct obd_export *, struct lov_stripe_md *, __u32 type,
1014 ldlm_policy_data_t *, __u32 mode, int *flags, void *data,
1015 struct lustre_handle *lockh);
1016 int (*o_change_cbdata)(struct obd_export *, struct lov_stripe_md *,
1017 ldlm_iterator_t it, void *data);
1018 int (*o_cancel)(struct obd_export *, struct lov_stripe_md *md,
1019 __u32 mode, struct lustre_handle *);
1020 int (*o_cancel_unused)(struct obd_export *, struct lov_stripe_md *,
1021 int flags, void *opaque);
1022 int (*o_join_lru)(struct obd_export *, struct lov_stripe_md *,
1024 int (*o_init_export)(struct obd_export *exp);
1025 int (*o_destroy_export)(struct obd_export *exp);
1026 int (*o_extent_calc)(struct obd_export *, struct lov_stripe_md *,
1027 int cmd, obd_off *);
1029 /* llog related obd_methods */
1030 int (*o_llog_init)(struct obd_device *obd, struct obd_device *disk_obd,
1031 int count, struct llog_catid *logid,
1032 struct obd_uuid *uuid);
1033 int (*o_llog_finish)(struct obd_device *obd, int count);
1035 /* metadata-only methods */
1036 int (*o_pin)(struct obd_export *, obd_id ino, __u32 gen, int type,
1037 struct obd_client_handle *, int flag);
1038 int (*o_unpin)(struct obd_export *, struct obd_client_handle *, int);
1040 int (*o_import_event)(struct obd_device *, struct obd_import *,
1041 enum obd_import_event);
1043 int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
1044 enum obd_notify_event ev, void *data);
1046 int (*o_health_check)(struct obd_device *);
1049 int (*o_quotacheck)(struct obd_export *, struct obd_quotactl *);
1050 int (*o_quotactl)(struct obd_export *, struct obd_quotactl *);
1051 int (*o_quota_adjust_qunit)(struct obd_export *exp,
1052 struct quota_adjust_qunit *oqaq);
1055 int (*o_ping)(struct obd_export *exp);
1057 int (*o_register_page_removal_cb)(struct obd_export *exp,
1058 obd_page_removal_cb_t cb,
1059 obd_pin_extent_cb pin_cb);
1060 int (*o_unregister_page_removal_cb)(struct obd_export *exp,
1061 obd_page_removal_cb_t cb);
1062 int (*o_register_lock_cancel_cb)(struct obd_export *exp,
1063 obd_lock_cancel_cb cb);
1064 int (*o_unregister_lock_cancel_cb)(struct obd_export *exp,
1065 obd_lock_cancel_cb cb);
1068 * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
1069 * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
1070 * Also, add a wrapper function in include/linux/obd_class.h. */
1073 struct lsm_operations {
1074 void (*lsm_free)(struct lov_stripe_md *);
1075 int (*lsm_destroy)(struct lov_stripe_md *, struct obdo *oa,
1076 struct obd_export *md_exp);
1077 void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *, obd_off *,
1079 void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *, obd_off *,
1081 obd_off (*lsm_stripe_offset_by_index)(struct lov_stripe_md *, int);
1082 obd_off (*lsm_stripe_offset_by_offset)(struct lov_stripe_md *, obd_off);
1083 int (*lsm_stripe_index_by_offset)(struct lov_stripe_md *, obd_off);
1084 int (*lsm_revalidate) (struct lov_stripe_md *, struct obd_device *obd);
1085 int (*lsm_lmm_verify) (struct lov_mds_md *lmm, int lmm_bytes,
1087 int (*lsm_unpackmd) (struct lov_obd *lov, struct lov_stripe_md *lsm,
1088 struct lov_mds_md *lmm);
1091 extern struct lsm_operations lsm_plain_ops;
1092 extern struct lsm_operations lsm_join_ops;
1093 static inline struct lsm_operations *lsm_op_find(int magic)
1097 return &lsm_plain_ops;
1098 case LOV_MAGIC_JOIN:
1099 return &lsm_join_ops;
1101 CERROR("Cannot recognize lsm_magic %d", magic);
1106 int lvfs_check_io_health(struct obd_device *obd, struct file *file);
1108 /* Requests for obd_extent_calc() */
1109 #define OBD_CALC_STRIPE_START 1
1110 #define OBD_CALC_STRIPE_END 2
1112 static inline void obd_transno_commit_cb(struct obd_device *obd, __u64 transno,
1116 CERROR("%s: transno "LPU64" commit error: %d\n",
1117 obd->obd_name, transno, error);
1120 CDEBUG(D_HA, "%s: transno "LPU64" committed\n",
1121 obd->obd_name, transno);
1122 if (transno > obd->obd_last_committed) {
1123 obd->obd_last_committed = transno;
1124 ptlrpc_commit_replies (obd);
1128 static inline void init_obd_quota_ops(quota_interface_t *interface,
1129 struct obd_ops *obd_ops)
1135 obd_ops->o_quotacheck = QUOTA_OP(interface, check);
1136 obd_ops->o_quotactl = QUOTA_OP(interface, ctl);
1137 obd_ops->o_quota_adjust_qunit = QUOTA_OP(interface, adjust_qunit);
1145 /* Default preferred checksum algorithm to use (if supported by the server) */
1146 #define OSC_DEFAULT_CKSUM OBD_CKSUM_ADLER
1147 /* Adler-32 is supported */
1148 #define CHECKSUM_ADLER OBD_CKSUM_ADLER
1150 #define OSC_DEFAULT_CKSUM OBD_CKSUM_CRC32
1151 #define CHECKSUM_ADLER 0
1154 #define OBD_CKSUM_ALL (OBD_CKSUM_CRC32 | CHECKSUM_ADLER)
1156 /* Checksum algorithm names. Must be defined in the same order as the
1157 * OBD_CKSUM_* flags. */
1158 #define DECLARE_CKSUM_NAME char *cksum_name[] = {"crc32", "adler"}
1160 #endif /* __OBD_H */