1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
6 * This code is issued under the GNU General Public License.
7 * See the file COPYING in this distribution
13 #define IOC_OSC_TYPE 'h'
14 #define IOC_OSC_MIN_NR 20
15 #define IOC_OSC_SET_ACTIVE _IOWR(IOC_OSC_TYPE, 21, struct obd_device *)
16 #define IOC_OSC_MAX_NR 50
18 #define IOC_MDC_TYPE 'i'
19 #define IOC_MDC_MIN_NR 20
20 #define IOC_MDC_LOOKUP _IOWR(IOC_MDC_TYPE, 20, struct obd_device *)
21 #define IOC_MDC_GETSTRIPE _IOWR(IOC_MDC_TYPE, 21, struct lov_mds_md *)
22 #define IOC_MDC_MAX_NR 50
25 # include <linux/fs.h>
26 # include <linux/list.h>
27 # include <linux/sched.h> /* for struct task_struct, for current.h */
28 # include <asm/current.h> /* for smp_lock.h */
29 # include <linux/smp_lock.h>
30 # include <linux/proc_fs.h>
31 # include <linux/mount.h>
34 #include <linux/lustre_lib.h>
35 #include <linux/lustre_idl.h>
36 #include <linux/lustre_export.h>
38 /* this is really local to the OSC */
39 struct loi_oap_pages {
40 struct list_head lop_pending;
42 struct list_head lop_urgent;
43 struct list_head lop_pending_sync;
46 struct lov_oinfo { /* per-stripe data structure */
47 __u64 loi_id; /* object ID on the target OST */
48 __u64 loi_gr; /* object group on the target OST */
49 int loi_ost_idx; /* OST stripe index in lov_tgt_desc->tgts */
50 int loi_ost_gen; /* generation of this loi_ost_idx */
52 /* used by the osc to keep track of what objects to build into rpcs */
53 struct loi_oap_pages loi_read_lop;
54 struct loi_oap_pages loi_write_lop;
55 /* _cli_ is poorly named, it should be _ready_ */
56 struct list_head loi_cli_item;
57 struct list_head loi_write_item;
59 __u64 loi_kms; /* known minimum size */
60 __u64 loi_rss; /* recently seen size */
61 __u64 loi_mtime; /* recently seen mtime */
64 static inline void loi_init(struct lov_oinfo *loi)
66 INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending);
67 INIT_LIST_HEAD(&loi->loi_read_lop.lop_urgent);
68 INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending_sync);
69 INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending);
70 INIT_LIST_HEAD(&loi->loi_write_lop.lop_urgent);
71 INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending_sync);
72 INIT_LIST_HEAD(&loi->loi_cli_item);
73 INIT_LIST_HEAD(&loi->loi_write_item);
76 struct lov_stripe_md {
78 __u64 lsm_object_id; /* lov object id */
79 __u64 lsm_object_gr; /* lov object id */
82 /* LOV-private members start here -- only for use in lov/. */
84 __u32 lsm_stripe_size; /* size of the stripe */
85 __u32 lsm_pattern; /* striping pattern (RAID0, RAID1) */
86 unsigned lsm_stripe_count; /* number of objects being striped over */
87 struct lov_oinfo lsm_oinfo[0];
91 struct list_head typ_chain;
92 struct obd_ops *typ_ops;
93 struct proc_dir_entry *typ_procroot;
108 ASYNC_COUNT_STABLE = 0x4,
111 struct obd_async_page_ops {
112 int (*ap_make_ready)(void *data, int cmd);
113 int (*ap_refresh_count)(void *data, int cmd);
114 void (*ap_fill_obdo)(void *data, int cmd, struct obdo *oa);
115 void (*ap_completion)(void *data, int cmd, int rc);
118 /* the `osic' is passed down from a caller of obd rw methods. the callee
119 * records enough state such that the caller can sleep on the osic and
120 * be woken when all the callees have finished their work */
121 struct obd_sync_io_container {
122 spinlock_t osic_lock;
123 atomic_t osic_refcount;
126 struct list_head osic_occ_list;
127 wait_queue_head_t osic_waitq;
130 /* the osic callback context lets the callee of obd rw methods register
131 * for callbacks from the caller. */
132 struct osic_callback_context {
133 struct list_head occ_osic_item;
134 /* called when the caller has received a signal while sleeping.
135 * callees of this method are encouraged to abort their state
136 * in the osic. This may be called multiple times. */
137 void (*occ_interrupted)(struct osic_callback_context *occ);
140 /* if we find more consumers this could be generalized */
141 #define OBD_HIST_MAX 32
142 struct obd_histogram {
144 unsigned long oh_buckets[OBD_HIST_MAX];
147 /* Individual type definitions */
149 struct ost_server_data;
152 const char *fo_fstype;
153 struct super_block *fo_sb;
154 struct vfsmount *fo_vfsmnt;
155 struct dentry *fo_dentry_O;
156 struct dentry **fo_dentry_O_groups;
157 struct dentry **fo_dentry_O_sub;
158 spinlock_t fo_objidlock; /* protect fo_lastobjid increment */
159 spinlock_t fo_translock; /* protect fsd_last_rcvd increment */
160 struct file *fo_rcvd_filp;
161 struct filter_server_data *fo_fsd;
162 unsigned long *fo_last_rcvd_slots;
163 __u64 fo_mount_count;
165 struct file_operations *fo_fop;
166 struct inode_operations *fo_iop;
167 struct address_space_operations *fo_aops;
169 struct list_head fo_export_list;
171 obd_size fo_tot_dirty; /* protected by obd_osfs_lock */
172 obd_size fo_tot_granted; /* all values in bytes */
173 obd_size fo_tot_pending;
175 obd_size fo_readcache_max_filesize;
177 struct obd_import *fo_mdc_imp;
178 struct obd_uuid fo_mdc_uuid;
179 struct lustre_handle fo_mdc_conn;
181 struct ptlrpc_client fo_mdc_client;
183 struct file **fo_last_objid_files;
184 __u64 *fo_last_objids; /* last created objid for groups */
186 struct semaphore fo_alloc_lock;
188 struct obd_histogram fo_r_pages;
189 struct obd_histogram fo_w_pages;
190 struct obd_histogram fo_r_discont_pages;
191 struct obd_histogram fo_w_discont_pages;
192 struct obd_histogram fo_r_discont_blocks;
193 struct obd_histogram fo_w_discont_blocks;
196 struct mds_server_data;
198 #define OSC_MAX_RIF_DEFAULT 4
199 #define OSC_MAX_RIF_MAX 32
200 #define OSC_MAX_DIRTY_DEFAULT 4
201 #define OSC_MAX_DIRTY_MB_MAX 256 /* totally arbitrary */
205 struct obd_import *cl_import;
206 struct semaphore cl_sem;
208 /* max_mds_easize is purely a performance thing so we don't have to
209 * call obd_size_wiremd() all the time. */
210 int cl_max_mds_easize;
211 int cl_max_mds_cookiesize;
214 //struct llog_canceld_ctxt *cl_llcd; /* it's included by obd_llog_ctxt */
215 void *cl_llcd_offset;
217 struct obd_device *cl_mgmtcli_obd;
219 /* the grant values are protected by loi_list_lock below */
220 long cl_dirty; /* all _dirty_ in bytes */
221 long cl_dirty_max; /* allowed w/o rpc */
222 long cl_avail_grant; /* bytes of credit for ost */
223 long cl_lost_grant; /* lost credits (trunc) */
224 struct list_head cl_cache_waiters; /* waiting for cache/grant */
226 /* keep track of objects that have lois that contain pages which
227 * have been queued for async brw. this lock also protects the
228 * lists of osc_client_pages that hang off of the loi */
229 spinlock_t cl_loi_list_lock;
230 struct list_head cl_loi_ready_list;
231 struct list_head cl_loi_write_list;
232 int cl_brw_in_flight;
233 /* just a sum of the loi/lop pending numbers to be exported by /proc */
234 int cl_pending_w_pages;
235 int cl_pending_r_pages;
236 int cl_max_pages_per_rpc;
237 int cl_max_rpcs_in_flight;
238 struct obd_histogram cl_read_rpc_hist;
239 struct obd_histogram cl_write_rpc_hist;
240 struct obd_histogram cl_read_page_hist;
241 struct obd_histogram cl_write_page_hist;
243 struct mdc_rpc_lock *cl_rpc_lock;
244 struct mdc_rpc_lock *cl_setattr_lock;
247 /* Like a client, with some hangers-on. Keep mc_client_obd first so that we
248 * can reuse the various client setup/connect functions. */
250 struct client_obd mc_client_obd; /* nested */
251 struct ptlrpc_thread *mc_ping_thread;
252 struct obd_export *mc_ping_exp; /* XXX single-target */
253 struct list_head mc_registered;
257 #define mc_import mc_client_obd.cl_import
260 struct ptlrpc_service *mds_service;
261 struct ptlrpc_service *mds_setattr_service;
262 struct ptlrpc_service *mds_readpage_service;
263 struct super_block *mds_sb;
264 struct vfsmount *mds_vfsmnt;
265 struct dentry *mds_fid_de;
267 int mds_max_cookiesize;
268 struct file *mds_rcvd_filp;
269 spinlock_t mds_transno_lock;
270 __u64 mds_last_transno;
271 __u64 mds_mount_count;
273 struct semaphore mds_epoch_sem;
274 struct ll_fid mds_rootfid;
275 struct mds_server_data *mds_server_data;
276 struct dentry *mds_pending_dir;
277 struct dentry *mds_logs_dir;
278 struct dentry *mds_objects_dir;
279 struct llog_handle *mds_cfg_llh;
280 // struct llog_handle *mds_catalog;
281 struct obd_device *mds_osc_obd; /* XXX lov_obd */
282 struct obd_uuid mds_lov_uuid;
284 struct obd_export *mds_osc_exp; /* XXX lov_exp */
285 int mds_has_lov_desc;
286 struct lov_desc mds_lov_desc;
287 obd_id *mds_lov_objids;
288 int mds_lov_objids_valid;
289 int mds_lov_nextid_set;
290 struct file *mds_lov_objid_filp;
291 unsigned long *mds_client_bitmap;
292 struct semaphore mds_orphan_recovery_sem;
294 atomic_t mds_open_count;
311 * this struct does double-duty acting as either a client or
312 * server instance .. maybe not wise.
316 struct ptlrpc_service *ptlbd_service;
319 struct ptlrpc_client bd_client;
320 struct obd_import *bd_import;
321 struct obd_uuid bd_server_uuid;
322 struct obd_export *bd_exp;
323 int refcount; /* XXX sigh */
327 spinlock_t recovd_lock;
328 struct list_head recovd_managed_items; /* items managed */
329 struct list_head recovd_troubled_items; /* items in recovery */
331 wait_queue_head_t recovd_recovery_waitq;
332 wait_queue_head_t recovd_ctl_waitq;
333 wait_queue_head_t recovd_waitq;
334 struct task_struct *recovd_thread;
339 struct ptlrpc_service *ost_service;
340 struct ptlrpc_service *ost_create_service;
343 struct echo_client_obd {
344 struct obd_export *ec_exp; /* the local connection to osc/lov */
346 struct list_head ec_objects;
352 struct obd_export *cobd_target_exp;/* local connection to target obd */
353 struct obd_export *cobd_cache_exp; /* local connection to cache obd */
356 struct lov_tgt_desc {
357 struct obd_uuid uuid;
358 struct obd_export *ltd_exp;
359 int active; /* is this target up for requests */
364 struct lov_desc desc;
367 int lo_catalog_loaded:1;
368 struct lov_tgt_desc *tgts;
371 struct niobuf_local {
376 struct dentry *dentry;
382 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
383 #define N_LOCAL_TEMP_PAGE 0x10000000
385 struct obd_trans_info {
388 /* Only used on the server side for tracking acks. */
389 struct oti_req_ack_lock {
390 struct lustre_handle lock;
394 struct llog_cookie oti_onecookie;
395 struct llog_cookie *oti_logcookies;
399 static inline void oti_alloc_cookies(struct obd_trans_info *oti,int num_cookies)
404 if (num_cookies == 1)
405 oti->oti_logcookies = &oti->oti_onecookie;
407 OBD_ALLOC(oti->oti_logcookies,
408 num_cookies * sizeof(oti->oti_onecookie));
410 oti->oti_numcookies = num_cookies;
413 static inline void oti_free_cookies(struct obd_trans_info *oti)
415 if (!oti || !oti->oti_logcookies)
418 if (oti->oti_logcookies == &oti->oti_onecookie)
419 LASSERT(oti->oti_numcookies == 1);
421 OBD_FREE(oti->oti_logcookies,
422 oti->oti_numcookies * sizeof(oti->oti_onecookie));
423 oti->oti_logcookies = NULL;
424 oti->oti_numcookies = 0;
429 LLOG_CONFIG_ORIG_CTXT = 0,
430 LLOG_CONFIG_REPL_CTXT = 1,
431 LLOG_UNLINK_ORIG_CTXT = 2,
432 LLOG_UNLINK_REPL_CTXT = 3,
433 LLOG_SIZE_ORIG_CTXT = 4,
434 LLOG_SIZE_REPL_CTXT = 5,
435 LLOG_MD_ORIG_CTXT = 6,
436 LLOG_MD_REPL_CTXT = 7,
437 LLOG_RD1_ORIG_CTXT = 8,
438 LLOG_RD1_REPL_CTXT = 9,
439 LLOG_TEST_ORIG_CTXT = 10,
440 LLOG_TEST_REPL_CTXT = 11,
445 /* corresponds to one of the obd's */
447 struct obd_type *obd_type;
449 /* common and UUID name of this device */
451 struct obd_uuid obd_uuid;
454 int obd_attached:1, obd_set_up:1, obd_recovering:1,
455 obd_abort_recovery:1, obd_replayable:1, obd_no_transno:1,
456 obd_no_recov:1, obd_stopping:1;
457 atomic_t obd_refcount;
458 wait_queue_head_t obd_refcount_waitq;
459 struct proc_dir_entry *obd_proc_entry;
460 struct list_head obd_exports;
462 struct ldlm_namespace *obd_namespace;
463 struct ptlrpc_client obd_ldlm_client; /* XXX OST/MDS only */
464 /* a spinlock is OK for what we do now, may need a semaphore later */
465 spinlock_t obd_dev_lock;
466 __u64 obd_last_committed;
467 struct fsfilt_operations *obd_fsops;
468 spinlock_t obd_osfs_lock;
469 struct llog_ctxt *obd_llog_ctxt[LLOG_MAX_CTXTS];
470 struct obd_statfs obd_osfs;
471 unsigned long obd_osfs_age;
472 struct obd_run_ctxt obd_ctxt;
473 struct obd_device *obd_observer;
474 struct obd_export *obd_self_export;
476 /* XXX encapsulate all this recovery data into one struct */
477 svc_handler_t obd_recovery_handler;
478 int obd_max_recoverable_clients;
479 int obd_connected_clients;
480 int obd_recoverable_clients;
481 spinlock_t obd_processing_task_lock;
482 pid_t obd_processing_task;
483 __u64 obd_next_recovery_transno;
484 int obd_replayed_requests;
485 int obd_requests_queued_for_recovery;
486 wait_queue_head_t obd_next_transno_waitq;
487 struct list_head obd_uncommitted_replies;
488 spinlock_t obd_uncommitted_replies_lock;
489 struct timer_list obd_recovery_timer;
490 struct list_head obd_recovery_queue;
491 struct list_head obd_delayed_reply_queue;
494 struct filter_obd filter;
496 struct client_obd cli;
498 struct echo_client_obd echo_client;
499 struct echo_obd echo;
500 struct recovd_obd recovd;
502 struct cache_obd cobd;
503 struct ptlbd_obd ptlbd;
504 struct mgmtcli_obd mgmtcli;
506 /* Fields used by LProcFS */
507 unsigned int obd_cntr_base;
508 struct lprocfs_stats *obd_stats;
509 struct proc_dir_entry *obd_svc_procroot;
510 struct lprocfs_stats *obd_svc_stats;
513 #define OBD_OPT_FORCE 0x0001
514 #define OBD_OPT_FAILOVER 0x0002
516 #define OBD_LLOG_FL_SENDNOW 0x0001
519 struct module *o_owner;
520 int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
521 void *karg, void *uarg);
522 int (*o_get_info)(struct obd_export *, __u32 keylen, void *key,
523 __u32 *vallen, void *val);
524 int (*o_set_info)(struct obd_export *, __u32 keylen, void *key,
525 __u32 vallen, void *val);
526 int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
527 int (*o_detach)(struct obd_device *dev);
528 int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
529 int (*o_precleanup)(struct obd_device *dev, int flags);
530 int (*o_cleanup)(struct obd_device *dev, int flags);
531 int (*o_postrecov)(struct obd_device *dev);
532 int (*o_connect)(struct lustre_handle *conn, struct obd_device *src,
533 struct obd_uuid *cluuid);
534 int (*o_disconnect)(struct obd_export *exp, int flags);
536 int (*o_statfs)(struct obd_device *obd, struct obd_statfs *osfs,
537 unsigned long max_age);
538 int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
539 struct lov_stripe_md *mem_src);
540 int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
541 struct lov_mds_md *disk_src, int disk_len);
542 int (*o_preallocate)(struct lustre_handle *, obd_count *req,
544 int (*o_create)(struct obd_export *exp, struct obdo *oa,
545 struct lov_stripe_md **ea, struct obd_trans_info *oti);
546 int (*o_destroy)(struct obd_export *exp, struct obdo *oa,
547 struct lov_stripe_md *ea, struct obd_trans_info *oti);
548 int (*o_setattr)(struct obd_export *exp, struct obdo *oa,
549 struct lov_stripe_md *ea, struct obd_trans_info *oti);
550 int (*o_getattr)(struct obd_export *exp, struct obdo *oa,
551 struct lov_stripe_md *ea);
552 int (*o_getattr_async)(struct obd_export *exp, struct obdo *oa,
553 struct lov_stripe_md *ea,
554 struct ptlrpc_request_set *set);
555 int (*o_brw)(int rw, struct obd_export *exp, struct obdo *oa,
556 struct lov_stripe_md *ea, obd_count oa_bufs,
557 struct brw_page *pgarr, struct obd_trans_info *oti);
558 int (*o_brw_async)(int rw, struct obd_export *exp, struct obdo *oa,
559 struct lov_stripe_md *ea, obd_count oa_bufs,
560 struct brw_page *pgarr, struct ptlrpc_request_set *,
561 struct obd_trans_info *oti);
562 int (*o_prep_async_page)(struct obd_export *exp,
563 struct lov_stripe_md *lsm,
564 struct lov_oinfo *loi,
565 struct page *page, obd_off offset,
566 struct obd_async_page_ops *ops, void *data,
568 int (*o_queue_async_io)(struct obd_export *exp,
569 struct lov_stripe_md *lsm,
570 struct lov_oinfo *loi, void *cookie,
571 int cmd, obd_off off, int count,
572 obd_flag brw_flags, obd_flag async_flags);
573 int (*o_queue_sync_io)(struct obd_export *exp,
574 struct lov_stripe_md *lsm,
575 struct lov_oinfo *loi,
576 struct obd_sync_io_container *osic,
577 void *cookie, int cmd, obd_off off, int count,
579 int (*o_trigger_sync_io)(struct obd_export *exp,
580 struct lov_stripe_md *lsm,
581 struct lov_oinfo *loi,
582 struct obd_sync_io_container *osic);
583 int (*o_set_async_flags)(struct obd_export *exp,
584 struct lov_stripe_md *lsm,
585 struct lov_oinfo *loi, void *cookie,
586 obd_flag async_flags);
587 int (*o_teardown_async_page)(struct obd_export *exp,
588 struct lov_stripe_md *lsm,
589 struct lov_oinfo *loi, void *cookie);
590 int (*o_punch)(struct obd_export *exp, struct obdo *oa,
591 struct lov_stripe_md *ea, obd_size start,
592 obd_size end, struct obd_trans_info *oti);
593 int (*o_sync)(struct obd_export *exp, struct obdo *oa,
594 struct lov_stripe_md *ea, obd_size start, obd_size end);
595 int (*o_migrate)(struct lustre_handle *conn, struct lov_stripe_md *dst,
596 struct lov_stripe_md *src, obd_size start,
597 obd_size end, struct obd_trans_info *oti);
598 int (*o_copy)(struct lustre_handle *dstconn, struct lov_stripe_md *dst,
599 struct lustre_handle *srconn, struct lov_stripe_md *src,
600 obd_size start, obd_size end, struct obd_trans_info *);
601 int (*o_iterate)(struct lustre_handle *conn,
602 int (*)(obd_id, obd_gr, void *),
603 obd_id *startid, obd_gr group, void *data);
604 int (*o_preprw)(int cmd, struct obd_export *exp, struct obdo *oa,
605 int objcount, struct obd_ioobj *obj,
606 int niocount, struct niobuf_remote *remote,
607 struct niobuf_local *local, struct obd_trans_info *oti);
608 int (*o_commitrw)(int cmd, struct obd_export *exp, struct obdo *oa,
609 int objcount, struct obd_ioobj *obj,
610 int niocount, struct niobuf_local *local,
611 struct obd_trans_info *oti);
612 int (*o_enqueue)(struct obd_export *, struct lov_stripe_md *,
613 __u32 type, ldlm_policy_data_t *, __u32 mode,
614 int *flags, void *bl_cb, void *cp_cb, void *gl_cb,
615 void *data, __u32 lvb_len, void *lvb_swabber,
616 struct lustre_handle *lockh);
617 int (*o_match)(struct obd_export *, struct lov_stripe_md *, __u32 type,
618 ldlm_policy_data_t *, __u32 mode, int *flags, void *data,
619 struct lustre_handle *lockh);
620 int (*o_change_cbdata)(struct obd_export *, struct lov_stripe_md *,
621 ldlm_iterator_t it, void *data);
622 int (*o_cancel)(struct obd_export *, struct lov_stripe_md *md,
623 __u32 mode, struct lustre_handle *);
624 int (*o_cancel_unused)(struct obd_export *, struct lov_stripe_md *,
625 int flags, void *opaque);
626 int (*o_san_preprw)(int cmd, struct obd_export *exp,
627 struct obdo *oa, int objcount,
628 struct obd_ioobj *obj, int niocount,
629 struct niobuf_remote *remote);
630 int (*o_init_export)(struct obd_export *exp);
631 int (*o_destroy_export)(struct obd_export *exp);
633 /* llog related obd_methods */
634 int (*o_llog_init)(struct obd_device *obd, struct obd_device *disk_obd,
635 int count, struct llog_logid *logid);
636 int (*o_llog_finish)(struct obd_device *obd, int count);
638 /* metadata-only methods */
639 int (*o_pin)(struct obd_export *, obd_id ino, __u32 gen, int type,
640 struct obd_client_handle *, int flag);
641 int (*o_unpin)(struct obd_export *, struct obd_client_handle *, int);
643 int (*o_invalidate_import)(struct obd_device *, struct obd_import *);
645 int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
648 * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
649 * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
650 * Also, add a wrapper function in include/linux/obd_class.h.
655 static inline void obd_transno_commit_cb(struct obd_device *obd, __u64 transno,
659 CERROR("%s: transno "LPD64" commit error: %d\n",
660 obd->obd_name, transno, error);
663 CDEBUG(D_HA, "%s: transno "LPD64" committed\n",
664 obd->obd_name, transno);
665 if (transno > obd->obd_last_committed) {
666 obd->obd_last_committed = transno;
667 ptlrpc_commit_replies (obd);