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_MAX_NR 50
24 # include <linux/fs.h>
25 # include <linux/list.h>
26 # include <linux/sched.h> /* for struct task_struct, for current.h */
27 # include <asm/current.h> /* for smp_lock.h */
28 # include <linux/smp_lock.h>
29 # include <linux/proc_fs.h>
30 # include <linux/mount.h>
33 #include <linux/lustre_lib.h>
34 #include <linux/lustre_idl.h>
35 #include <linux/lustre_export.h>
37 /* this is really local to the OSC */
38 struct loi_oap_pages {
39 struct list_head lop_pending;
41 struct list_head lop_urgent;
42 struct list_head lop_pending_group;
45 struct lov_oinfo { /* per-stripe data structure */
46 __u64 loi_id; /* object ID on the target OST */
47 __u64 loi_gr; /* object group on the target OST */
48 int loi_ost_idx; /* OST stripe index in lov_tgt_desc->tgts */
49 int loi_ost_gen; /* generation of this loi_ost_idx */
51 /* used by the osc to keep track of what objects to build into rpcs */
52 struct loi_oap_pages loi_read_lop;
53 struct loi_oap_pages loi_write_lop;
54 /* _cli_ is poorly named, it should be _ready_ */
55 struct list_head loi_cli_item;
56 struct list_head loi_write_item;
58 __u64 loi_kms; /* known minimum size */
59 __u64 loi_rss; /* recently seen size */
60 __u64 loi_mtime; /* recently seen mtime */
63 static inline void loi_init(struct lov_oinfo *loi)
65 INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending);
66 INIT_LIST_HEAD(&loi->loi_read_lop.lop_urgent);
67 INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending_group);
68 INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending);
69 INIT_LIST_HEAD(&loi->loi_write_lop.lop_urgent);
70 INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending_group);
71 INIT_LIST_HEAD(&loi->loi_cli_item);
72 INIT_LIST_HEAD(&loi->loi_write_item);
75 struct lov_stripe_md {
77 __u64 lsm_object_id; /* lov object id */
78 __u64 lsm_object_gr; /* lov object id */
81 /* LOV-private members start here -- only for use in lov/. */
83 __u32 lsm_stripe_size; /* size of the stripe */
84 __u32 lsm_pattern; /* striping pattern (RAID0, RAID1) */
85 unsigned lsm_stripe_count; /* number of objects being striped over */
86 struct lov_oinfo lsm_oinfo[0];
90 struct list_head typ_chain;
91 struct obd_ops *typ_ops;
92 struct proc_dir_entry *typ_procroot;
105 ASYNC_READY = 0x1, /* ap_make_ready will not be called before this
106 page is added to an rpc */
108 ASYNC_COUNT_STABLE = 0x4, /* ap_refresh_count will not be called
109 to give the caller a chance to update
110 or cancel the size of the io */
111 ASYNC_GROUP_SYNC = 0x8, /* ap_completion will not be called, instead
112 the page is accounted for in the
113 obd_io_group given to
114 obd_queue_group_io */
117 struct obd_async_page_ops {
118 int (*ap_make_ready)(void *data, int cmd);
119 int (*ap_refresh_count)(void *data, int cmd);
120 void (*ap_fill_obdo)(void *data, int cmd, struct obdo *oa);
121 void (*ap_completion)(void *data, int cmd, int rc);
124 /* the `oig' is passed down from a caller of obd rw methods. the callee
125 * records enough state such that the caller can sleep on the oig and
126 * be woken when all the callees have finished their work */
127 struct obd_io_group {
129 atomic_t oig_refcount;
132 struct list_head oig_occ_list;
133 wait_queue_head_t oig_waitq;
136 /* the oig callback context lets the callee of obd rw methods register
137 * for callbacks from the caller. */
138 struct oig_callback_context {
139 struct list_head occ_oig_item;
140 /* called when the caller has received a signal while sleeping.
141 * callees of this method are encouraged to abort their state
142 * in the oig. This may be called multiple times. */
143 void (*occ_interrupted)(struct oig_callback_context *occ);
146 /* if we find more consumers this could be generalized */
147 #define OBD_HIST_MAX 32
148 struct obd_histogram {
150 unsigned long oh_buckets[OBD_HIST_MAX];
153 /* Individual type definitions */
155 struct ost_server_data;
158 const char *fo_fstype;
159 struct super_block *fo_sb;
160 struct vfsmount *fo_vfsmnt;
161 struct dentry *fo_dentry_O;
162 struct dentry **fo_dentry_O_groups;
163 struct dentry **fo_dentry_O_sub;
164 spinlock_t fo_objidlock; /* protect fo_lastobjid increment */
165 spinlock_t fo_translock; /* protect fsd_last_rcvd increment */
166 struct file *fo_rcvd_filp;
167 struct filter_server_data *fo_fsd;
168 unsigned long *fo_last_rcvd_slots;
169 __u64 fo_mount_count;
171 struct file_operations *fo_fop;
172 struct inode_operations *fo_iop;
173 struct address_space_operations *fo_aops;
175 struct list_head fo_export_list;
177 obd_size fo_tot_dirty; /* protected by obd_osfs_lock */
178 obd_size fo_tot_granted; /* all values in bytes */
179 obd_size fo_tot_pending;
181 obd_size fo_readcache_max_filesize;
183 struct obd_import *fo_mdc_imp;
184 struct obd_uuid fo_mdc_uuid;
185 struct lustre_handle fo_mdc_conn;
187 struct ptlrpc_client fo_mdc_client;
189 struct file **fo_last_objid_files;
190 __u64 *fo_last_objids; /* last created objid for groups */
192 struct semaphore fo_alloc_lock;
194 struct obd_histogram fo_r_pages;
195 struct obd_histogram fo_w_pages;
196 struct obd_histogram fo_r_discont_pages;
197 struct obd_histogram fo_w_discont_pages;
198 struct obd_histogram fo_r_discont_blocks;
199 struct obd_histogram fo_w_discont_blocks;
202 struct mds_server_data;
204 #define OSC_MAX_RIF_DEFAULT 4
205 #define OSC_MAX_RIF_MAX 32
206 #define OSC_MAX_DIRTY_DEFAULT 4
207 #define OSC_MAX_DIRTY_MB_MAX 256 /* totally arbitrary */
211 struct obd_import *cl_import;
212 struct semaphore cl_sem;
214 /* max_mds_easize is purely a performance thing so we don't have to
215 * call obd_size_wiremd() all the time. */
216 int cl_max_mds_easize;
217 int cl_max_mds_cookiesize;
220 //struct llog_canceld_ctxt *cl_llcd; /* it's included by obd_llog_ctxt */
221 void *cl_llcd_offset;
223 struct obd_device *cl_mgmtcli_obd;
225 /* the grant values are protected by loi_list_lock below */
226 long cl_dirty; /* all _dirty_ in bytes */
227 long cl_dirty_max; /* allowed w/o rpc */
228 long cl_avail_grant; /* bytes of credit for ost */
229 long cl_lost_grant; /* lost credits (trunc) */
230 struct list_head cl_cache_waiters; /* waiting for cache/grant */
232 /* keep track of objects that have lois that contain pages which
233 * have been queued for async brw. this lock also protects the
234 * lists of osc_client_pages that hang off of the loi */
235 spinlock_t cl_loi_list_lock;
236 struct list_head cl_loi_ready_list;
237 struct list_head cl_loi_write_list;
238 int cl_brw_in_flight;
239 /* just a sum of the loi/lop pending numbers to be exported by /proc */
240 int cl_pending_w_pages;
241 int cl_pending_r_pages;
242 int cl_max_pages_per_rpc;
243 int cl_max_rpcs_in_flight;
244 struct obd_histogram cl_read_rpc_hist;
245 struct obd_histogram cl_write_rpc_hist;
246 struct obd_histogram cl_read_page_hist;
247 struct obd_histogram cl_write_page_hist;
249 struct mdc_rpc_lock *cl_rpc_lock;
250 struct mdc_rpc_lock *cl_setattr_lock;
253 /* Like a client, with some hangers-on. Keep mc_client_obd first so that we
254 * can reuse the various client setup/connect functions. */
256 struct client_obd mc_client_obd; /* nested */
257 struct ptlrpc_thread *mc_ping_thread;
258 struct obd_export *mc_ping_exp; /* XXX single-target */
259 struct list_head mc_registered;
263 #define mc_import mc_client_obd.cl_import
266 struct ptlrpc_service *mds_service;
267 struct ptlrpc_service *mds_setattr_service;
268 struct ptlrpc_service *mds_readpage_service;
269 struct super_block *mds_sb;
270 struct vfsmount *mds_vfsmnt;
271 struct dentry *mds_fid_de;
273 int mds_max_cookiesize;
274 struct file *mds_rcvd_filp;
275 spinlock_t mds_transno_lock;
276 __u64 mds_last_transno;
277 __u64 mds_mount_count;
279 struct semaphore mds_epoch_sem;
280 struct ll_fid mds_rootfid;
281 struct mds_server_data *mds_server_data;
282 struct dentry *mds_pending_dir;
283 struct dentry *mds_logs_dir;
284 struct dentry *mds_objects_dir;
285 struct llog_handle *mds_cfg_llh;
286 // struct llog_handle *mds_catalog;
287 struct obd_device *mds_osc_obd; /* XXX lov_obd */
288 struct obd_uuid mds_lov_uuid;
290 struct obd_export *mds_osc_exp; /* XXX lov_exp */
291 int mds_has_lov_desc;
292 struct lov_desc mds_lov_desc;
293 obd_id *mds_lov_objids;
294 int mds_lov_objids_valid;
295 int mds_lov_nextid_set;
296 struct file *mds_lov_objid_filp;
297 unsigned long *mds_client_bitmap;
298 struct semaphore mds_orphan_recovery_sem;
300 atomic_t mds_open_count;
317 * this struct does double-duty acting as either a client or
318 * server instance .. maybe not wise.
322 struct ptlrpc_service *ptlbd_service;
325 struct ptlrpc_client bd_client;
326 struct obd_import *bd_import;
327 struct obd_uuid bd_server_uuid;
328 struct obd_export *bd_exp;
329 int refcount; /* XXX sigh */
333 spinlock_t recovd_lock;
334 struct list_head recovd_managed_items; /* items managed */
335 struct list_head recovd_troubled_items; /* items in recovery */
337 wait_queue_head_t recovd_recovery_waitq;
338 wait_queue_head_t recovd_ctl_waitq;
339 wait_queue_head_t recovd_waitq;
340 struct task_struct *recovd_thread;
345 struct ptlrpc_service *ost_service;
346 struct ptlrpc_service *ost_create_service;
349 struct echo_client_obd {
350 struct obd_export *ec_exp; /* the local connection to osc/lov */
352 struct list_head ec_objects;
358 struct obd_export *cobd_target_exp;/* local connection to target obd */
359 struct obd_export *cobd_cache_exp; /* local connection to cache obd */
362 struct lov_tgt_desc {
363 struct obd_uuid uuid;
364 struct obd_export *ltd_exp;
365 int active; /* is this target up for requests */
370 struct lov_desc desc;
373 int lo_catalog_loaded:1;
374 struct lov_tgt_desc *tgts;
377 struct niobuf_local {
382 struct dentry *dentry;
388 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
389 #define N_LOCAL_TEMP_PAGE 0x10000000
391 struct obd_trans_info {
394 /* Only used on the server side for tracking acks. */
395 struct oti_req_ack_lock {
396 struct lustre_handle lock;
400 struct llog_cookie oti_onecookie;
401 struct llog_cookie *oti_logcookies;
405 static inline void oti_alloc_cookies(struct obd_trans_info *oti,int num_cookies)
410 if (num_cookies == 1)
411 oti->oti_logcookies = &oti->oti_onecookie;
413 OBD_ALLOC(oti->oti_logcookies,
414 num_cookies * sizeof(oti->oti_onecookie));
416 oti->oti_numcookies = num_cookies;
419 static inline void oti_free_cookies(struct obd_trans_info *oti)
421 if (!oti || !oti->oti_logcookies)
424 if (oti->oti_logcookies == &oti->oti_onecookie)
425 LASSERT(oti->oti_numcookies == 1);
427 OBD_FREE(oti->oti_logcookies,
428 oti->oti_numcookies * sizeof(oti->oti_onecookie));
429 oti->oti_logcookies = NULL;
430 oti->oti_numcookies = 0;
435 LLOG_CONFIG_ORIG_CTXT = 0,
436 LLOG_CONFIG_REPL_CTXT = 1,
437 LLOG_UNLINK_ORIG_CTXT = 2,
438 LLOG_UNLINK_REPL_CTXT = 3,
439 LLOG_SIZE_ORIG_CTXT = 4,
440 LLOG_SIZE_REPL_CTXT = 5,
441 LLOG_MD_ORIG_CTXT = 6,
442 LLOG_MD_REPL_CTXT = 7,
443 LLOG_RD1_ORIG_CTXT = 8,
444 LLOG_RD1_REPL_CTXT = 9,
445 LLOG_TEST_ORIG_CTXT = 10,
446 LLOG_TEST_REPL_CTXT = 11,
451 /* corresponds to one of the obd's */
453 struct obd_type *obd_type;
455 /* common and UUID name of this device */
457 struct obd_uuid obd_uuid;
460 int obd_attached:1, obd_set_up:1, obd_recovering:1,
461 obd_abort_recovery:1, obd_replayable:1, obd_no_transno:1,
462 obd_no_recov:1, obd_stopping:1;
463 atomic_t obd_refcount;
464 wait_queue_head_t obd_refcount_waitq;
465 struct proc_dir_entry *obd_proc_entry;
466 struct list_head obd_exports;
468 struct ldlm_namespace *obd_namespace;
469 struct ptlrpc_client obd_ldlm_client; /* XXX OST/MDS only */
470 /* a spinlock is OK for what we do now, may need a semaphore later */
471 spinlock_t obd_dev_lock;
472 __u64 obd_last_committed;
473 struct fsfilt_operations *obd_fsops;
474 spinlock_t obd_osfs_lock;
475 struct llog_ctxt *obd_llog_ctxt[LLOG_MAX_CTXTS];
476 struct obd_statfs obd_osfs;
477 unsigned long obd_osfs_age;
478 struct obd_run_ctxt obd_ctxt;
479 struct obd_device *obd_observer;
480 struct obd_export *obd_self_export;
482 /* XXX encapsulate all this recovery data into one struct */
483 svc_handler_t obd_recovery_handler;
484 int obd_max_recoverable_clients;
485 int obd_connected_clients;
486 int obd_recoverable_clients;
487 spinlock_t obd_processing_task_lock;
488 pid_t obd_processing_task;
489 __u64 obd_next_recovery_transno;
490 int obd_replayed_requests;
491 int obd_requests_queued_for_recovery;
492 wait_queue_head_t obd_next_transno_waitq;
493 struct list_head obd_uncommitted_replies;
494 spinlock_t obd_uncommitted_replies_lock;
495 struct timer_list obd_recovery_timer;
496 struct list_head obd_recovery_queue;
497 struct list_head obd_delayed_reply_queue;
500 struct filter_obd filter;
502 struct client_obd cli;
504 struct echo_client_obd echo_client;
505 struct echo_obd echo;
506 struct recovd_obd recovd;
508 struct cache_obd cobd;
509 struct ptlbd_obd ptlbd;
510 struct mgmtcli_obd mgmtcli;
512 /* Fields used by LProcFS */
513 unsigned int obd_cntr_base;
514 struct lprocfs_stats *obd_stats;
515 struct proc_dir_entry *obd_svc_procroot;
516 struct lprocfs_stats *obd_svc_stats;
519 #define OBD_OPT_FORCE 0x0001
520 #define OBD_OPT_FAILOVER 0x0002
522 #define OBD_LLOG_FL_SENDNOW 0x0001
525 struct module *o_owner;
526 int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
527 void *karg, void *uarg);
528 int (*o_get_info)(struct obd_export *, __u32 keylen, void *key,
529 __u32 *vallen, void *val);
530 int (*o_set_info)(struct obd_export *, __u32 keylen, void *key,
531 __u32 vallen, void *val);
532 int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
533 int (*o_detach)(struct obd_device *dev);
534 int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
535 int (*o_precleanup)(struct obd_device *dev, int flags);
536 int (*o_cleanup)(struct obd_device *dev, int flags);
537 int (*o_postrecov)(struct obd_device *dev);
538 int (*o_connect)(struct lustre_handle *conn, struct obd_device *src,
539 struct obd_uuid *cluuid);
540 int (*o_disconnect)(struct obd_export *exp, int flags);
542 int (*o_statfs)(struct obd_device *obd, struct obd_statfs *osfs,
543 unsigned long max_age);
544 int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
545 struct lov_stripe_md *mem_src);
546 int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
547 struct lov_mds_md *disk_src, int disk_len);
548 int (*o_preallocate)(struct lustre_handle *, obd_count *req,
550 int (*o_create)(struct obd_export *exp, struct obdo *oa,
551 struct lov_stripe_md **ea, struct obd_trans_info *oti);
552 int (*o_destroy)(struct obd_export *exp, struct obdo *oa,
553 struct lov_stripe_md *ea, struct obd_trans_info *oti);
554 int (*o_setattr)(struct obd_export *exp, struct obdo *oa,
555 struct lov_stripe_md *ea, struct obd_trans_info *oti);
556 int (*o_getattr)(struct obd_export *exp, struct obdo *oa,
557 struct lov_stripe_md *ea);
558 int (*o_getattr_async)(struct obd_export *exp, struct obdo *oa,
559 struct lov_stripe_md *ea,
560 struct ptlrpc_request_set *set);
561 int (*o_brw)(int rw, struct obd_export *exp, struct obdo *oa,
562 struct lov_stripe_md *ea, obd_count oa_bufs,
563 struct brw_page *pgarr, struct obd_trans_info *oti);
564 int (*o_brw_async)(int rw, struct obd_export *exp, struct obdo *oa,
565 struct lov_stripe_md *ea, obd_count oa_bufs,
566 struct brw_page *pgarr, struct ptlrpc_request_set *,
567 struct obd_trans_info *oti);
568 int (*o_prep_async_page)(struct obd_export *exp,
569 struct lov_stripe_md *lsm,
570 struct lov_oinfo *loi,
571 struct page *page, obd_off offset,
572 struct obd_async_page_ops *ops, void *data,
574 int (*o_queue_async_io)(struct obd_export *exp,
575 struct lov_stripe_md *lsm,
576 struct lov_oinfo *loi, void *cookie,
577 int cmd, obd_off off, int count,
578 obd_flag brw_flags, obd_flag async_flags);
579 int (*o_queue_group_io)(struct obd_export *exp,
580 struct lov_stripe_md *lsm,
581 struct lov_oinfo *loi,
582 struct obd_io_group *oig,
583 void *cookie, int cmd, obd_off off, int count,
584 obd_flag brw_flags, obd_flag async_flags);
585 int (*o_trigger_group_io)(struct obd_export *exp,
586 struct lov_stripe_md *lsm,
587 struct lov_oinfo *loi,
588 struct obd_io_group *oig);
589 int (*o_set_async_flags)(struct obd_export *exp,
590 struct lov_stripe_md *lsm,
591 struct lov_oinfo *loi, void *cookie,
592 obd_flag async_flags);
593 int (*o_teardown_async_page)(struct obd_export *exp,
594 struct lov_stripe_md *lsm,
595 struct lov_oinfo *loi, void *cookie);
596 int (*o_punch)(struct obd_export *exp, struct obdo *oa,
597 struct lov_stripe_md *ea, obd_size start,
598 obd_size end, struct obd_trans_info *oti);
599 int (*o_sync)(struct obd_export *exp, struct obdo *oa,
600 struct lov_stripe_md *ea, obd_size start, obd_size end);
601 int (*o_migrate)(struct lustre_handle *conn, struct lov_stripe_md *dst,
602 struct lov_stripe_md *src, obd_size start,
603 obd_size end, struct obd_trans_info *oti);
604 int (*o_copy)(struct lustre_handle *dstconn, struct lov_stripe_md *dst,
605 struct lustre_handle *srconn, struct lov_stripe_md *src,
606 obd_size start, obd_size end, struct obd_trans_info *);
607 int (*o_iterate)(struct lustre_handle *conn,
608 int (*)(obd_id, obd_gr, void *),
609 obd_id *startid, obd_gr group, void *data);
610 int (*o_preprw)(int cmd, struct obd_export *exp, struct obdo *oa,
611 int objcount, struct obd_ioobj *obj,
612 int niocount, struct niobuf_remote *remote,
613 struct niobuf_local *local, struct obd_trans_info *oti);
614 int (*o_commitrw)(int cmd, struct obd_export *exp, struct obdo *oa,
615 int objcount, struct obd_ioobj *obj,
616 int niocount, struct niobuf_local *local,
617 struct obd_trans_info *oti);
618 int (*o_enqueue)(struct obd_export *, struct lov_stripe_md *,
619 __u32 type, ldlm_policy_data_t *, __u32 mode,
620 int *flags, void *bl_cb, void *cp_cb, void *gl_cb,
621 void *data, __u32 lvb_len, void *lvb_swabber,
622 struct lustre_handle *lockh);
623 int (*o_match)(struct obd_export *, struct lov_stripe_md *, __u32 type,
624 ldlm_policy_data_t *, __u32 mode, int *flags, void *data,
625 struct lustre_handle *lockh);
626 int (*o_change_cbdata)(struct obd_export *, struct lov_stripe_md *,
627 ldlm_iterator_t it, void *data);
628 int (*o_cancel)(struct obd_export *, struct lov_stripe_md *md,
629 __u32 mode, struct lustre_handle *);
630 int (*o_cancel_unused)(struct obd_export *, struct lov_stripe_md *,
631 int flags, void *opaque);
632 int (*o_san_preprw)(int cmd, struct obd_export *exp,
633 struct obdo *oa, int objcount,
634 struct obd_ioobj *obj, int niocount,
635 struct niobuf_remote *remote);
636 int (*o_init_export)(struct obd_export *exp);
637 int (*o_destroy_export)(struct obd_export *exp);
639 /* llog related obd_methods */
640 int (*o_llog_init)(struct obd_device *obd, struct obd_device *disk_obd,
641 int count, struct llog_logid *logid);
642 int (*o_llog_finish)(struct obd_device *obd, int count);
644 /* metadata-only methods */
645 int (*o_pin)(struct obd_export *, obd_id ino, __u32 gen, int type,
646 struct obd_client_handle *, int flag);
647 int (*o_unpin)(struct obd_export *, struct obd_client_handle *, int);
649 int (*o_invalidate_import)(struct obd_device *, struct obd_import *);
651 int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
654 * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
655 * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
656 * Also, add a wrapper function in include/linux/obd_class.h.
661 static inline void obd_transno_commit_cb(struct obd_device *obd, __u64 transno,
665 CERROR("%s: transno "LPD64" commit error: %d\n",
666 obd->obd_name, transno, error);
669 CDEBUG(D_HA, "%s: transno "LPD64" committed\n",
670 obd->obd_name, transno);
671 if (transno > obd->obd_last_committed) {
672 obd->obd_last_committed = transno;
673 ptlrpc_commit_replies (obd);