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 struct lustre_handle *loi_handle; /* open file handle for obj on OST */
50 int loi_ost_idx; /* OST stripe index in lov_tgt_desc->tgts */
51 int loi_ost_gen; /* generation of this loi_ost_idx */
53 /* tracking offsets per file, per stripe.. */
54 struct loi_oap_pages loi_read_lop;
55 struct loi_oap_pages loi_write_lop;
56 struct list_head loi_cli_item;
59 static inline void loi_init(struct lov_oinfo *loi)
61 INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending);
62 INIT_LIST_HEAD(&loi->loi_read_lop.lop_urgent);
63 INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending_sync);
64 INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending);
65 INIT_LIST_HEAD(&loi->loi_write_lop.lop_urgent);
66 INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending_sync);
67 INIT_LIST_HEAD(&loi->loi_cli_item);
70 struct lov_stripe_md {
72 __u64 lsm_object_id; /* lov object id */
73 __u64 lsm_object_gr; /* lov object id */
76 /* LOV-private members start here -- only for use in lov/. */
78 __u32 lsm_stripe_size; /* size of the stripe */
79 __u32 lsm_pattern; /* striping pattern (RAID0, RAID1) */
80 unsigned lsm_stripe_count; /* number of objects being striped over */
81 struct lov_oinfo lsm_oinfo[0];
85 struct list_head typ_chain;
86 struct obd_ops *typ_ops;
87 struct proc_dir_entry *typ_procroot;
102 ASYNC_COUNT_STABLE = 0x4,
105 struct obd_async_page_ops {
106 int (*ap_make_ready)(void *data, int cmd);
107 int (*ap_refresh_count)(void *data, int cmd);
108 void (*ap_fill_obdo)(void *data, int cmd, struct obdo *oa);
109 void (*ap_completion)(void *data, int cmd, int rc);
112 struct obd_sync_io_container {
113 spinlock_t osic_lock;
114 atomic_t osic_refcount;
117 wait_queue_head_t osic_waitq;
120 /* Individual type definitions */
122 struct ost_server_data;
125 const char *fo_fstype;
126 struct super_block *fo_sb;
127 struct vfsmount *fo_vfsmnt;
128 struct dentry *fo_dentry_O;
129 struct dentry **fo_dentry_O_groups;
130 struct dentry **fo_dentry_O_sub;
131 spinlock_t fo_objidlock; /* protect fo_lastobjid increment */
132 spinlock_t fo_translock; /* protect fsd_last_rcvd increment */
133 struct file *fo_rcvd_filp;
134 struct filter_server_data *fo_fsd;
135 unsigned long *fo_last_rcvd_slots;
136 __u64 fo_mount_count;
138 struct file_operations *fo_fop;
139 struct inode_operations *fo_iop;
140 struct address_space_operations *fo_aops;
142 struct list_head fo_export_list;
144 spinlock_t fo_grant_lock; /* protects tot_granted */
145 obd_size fo_tot_granted;
146 obd_size fo_tot_cached;
148 struct obd_import *fo_mdc_imp;
149 struct obd_uuid fo_mdc_uuid;
150 struct lustre_handle fo_mdc_conn;
152 struct ptlrpc_client fo_mdc_client;
154 struct file **fo_last_objid_files;
155 __u64 *fo_last_objids; //last created object ID for groups
157 struct semaphore fo_alloc_lock;
160 struct mds_server_data;
162 /* if we find more consumers this could be generalized */
163 #define OSC_HIST_MAX 32
164 struct osc_histogram {
166 unsigned long oh_buckets[OSC_HIST_MAX];
171 struct obd_import *cl_import;
172 struct semaphore cl_sem;
174 /* max_mds_easize is purely a performance thing so we don't have to
175 * call obd_size_wiremd() all the time. */
176 int cl_max_mds_easize;
177 int cl_max_mds_cookiesize;
180 //struct llog_canceld_ctxt *cl_llcd; /* it's included by obd_llog_ctxt */
181 void *cl_llcd_offset;
183 struct semaphore cl_dirty_sem;
184 obd_size cl_dirty; /* all _dirty_ in bytes */
185 obd_size cl_dirty_granted; /* from ost */
186 obd_size cl_dirty_max; /* allowed w/o rpc */
187 struct list_head cl_cache_waiters;
189 struct obd_device *cl_mgmtcli_obd;
191 /* this is just to keep existing infinitely caching behaviour between
192 * clients and OSTs that don't have the grant code in yet.. it can
193 * be yanked once everything speaks grants */
194 char cl_ost_can_grant;
196 /* keep track of objects that have lois that contain pages which
197 * have been queued for async brw. this lock also protects the
198 * lists of obd_client_pages that hang off of the loi */
199 spinlock_t cl_loi_list_lock;
200 struct list_head cl_loi_ready_list;
201 int cl_brw_in_flight;
202 /* just a sum of the loi/lop pending numbers to be exported by /proc */
203 int cl_pending_w_pages;
204 int cl_pending_r_pages;
205 int cl_max_pages_per_rpc;
206 int cl_max_rpcs_in_flight;
207 struct osc_histogram cl_read_rpc_hist;
208 struct osc_histogram cl_write_rpc_hist;
209 struct osc_histogram cl_read_page_hist;
210 struct osc_histogram cl_write_page_hist;
212 struct mdc_rpc_lock *cl_rpc_lock;
213 struct mdc_rpc_lock *cl_setattr_lock;
216 /* Like a client, with some hangers-on. Keep mc_client_obd first so that we
217 * can reuse the various client setup/connect functions. */
219 struct client_obd mc_client_obd; /* nested */
220 struct ptlrpc_thread *mc_ping_thread;
221 struct obd_export *mc_ping_exp; /* XXX single-target */
222 struct list_head mc_registered;
226 #define mc_import mc_client_obd.cl_import
229 struct ptlrpc_service *mds_service;
230 struct ptlrpc_service *mds_setattr_service;
231 struct ptlrpc_service *mds_readpage_service;
232 struct super_block *mds_sb;
233 struct vfsmount *mds_vfsmnt;
234 struct dentry *mds_fid_de;
236 int mds_max_cookiesize;
237 struct file *mds_rcvd_filp;
238 spinlock_t mds_transno_lock;
239 __u64 mds_last_transno;
240 __u64 mds_mount_count;
242 struct semaphore mds_epoch_sem;
243 struct ll_fid mds_rootfid;
244 struct mds_server_data *mds_server_data;
245 struct dentry *mds_pending_dir;
246 struct dentry *mds_logs_dir;
247 struct dentry *mds_objects_dir;
248 struct llog_handle *mds_cfg_llh;
249 // struct llog_handle *mds_catalog;
250 struct obd_device *mds_osc_obd; /* XXX lov_obd */
251 struct obd_uuid mds_lov_uuid;
253 struct obd_export *mds_osc_exp; /* XXX lov_exp */
254 int mds_has_lov_desc;
255 struct lov_desc mds_lov_desc;
256 obd_id *mds_lov_objids;
257 int mds_lov_objids_valid;
258 int mds_lov_nextid_set;
259 struct file *mds_lov_objid_filp;
260 unsigned long *mds_client_bitmap;
261 struct semaphore mds_orphan_recovery_sem;
263 atomic_t mds_open_count;
280 * this struct does double-duty acting as either a client or
281 * server instance .. maybe not wise.
285 struct ptlrpc_service *ptlbd_service;
288 struct ptlrpc_client bd_client;
289 struct obd_import *bd_import;
290 struct obd_uuid bd_server_uuid;
291 struct obd_export *bd_exp;
292 int refcount; /* XXX sigh */
296 spinlock_t recovd_lock;
297 struct list_head recovd_managed_items; /* items managed */
298 struct list_head recovd_troubled_items; /* items in recovery */
300 wait_queue_head_t recovd_recovery_waitq;
301 wait_queue_head_t recovd_ctl_waitq;
302 wait_queue_head_t recovd_waitq;
303 struct task_struct *recovd_thread;
308 struct ptlrpc_service *ost_service;
309 struct ptlrpc_service *ost_create_service;
312 struct echo_client_obd {
313 struct obd_export *ec_exp; /* the local connection to osc/lov */
315 struct list_head ec_objects;
321 struct obd_export *cobd_target_exp;/* local connection to target obd */
322 struct obd_export *cobd_cache_exp; /* local connection to cache obd */
325 struct lov_tgt_desc {
326 struct obd_uuid uuid;
327 struct obd_export *ltd_exp;
328 int active; /* is this target up for requests */
333 struct lov_desc desc;
336 int lo_catalog_loaded:1;
337 struct lov_tgt_desc *tgts;
340 struct niobuf_local {
346 struct dentry *dentry;
351 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
352 #define N_LOCAL_TEMP_PAGE 0x10000000
354 struct obd_trans_info {
357 /* Only used on the server side for tracking acks. */
358 struct oti_req_ack_lock {
359 struct lustre_handle lock;
363 struct llog_cookie oti_onecookie;
364 struct llog_cookie *oti_logcookies;
368 static inline void oti_alloc_cookies(struct obd_trans_info *oti,int num_cookies)
373 if (num_cookies == 1)
374 oti->oti_logcookies = &oti->oti_onecookie;
376 OBD_ALLOC(oti->oti_logcookies,
377 num_cookies * sizeof(oti->oti_onecookie));
379 oti->oti_numcookies = num_cookies;
382 static inline void oti_free_cookies(struct obd_trans_info *oti)
384 if (!oti || !oti->oti_logcookies)
387 if (oti->oti_logcookies == &oti->oti_onecookie)
388 LASSERT(oti->oti_numcookies == 1);
390 OBD_FREE(oti->oti_logcookies,
391 oti->oti_numcookies * sizeof(oti->oti_onecookie));
392 oti->oti_logcookies = NULL;
393 oti->oti_numcookies = 0;
398 LLOG_CONFIG_ORIG_CTXT = 0,
399 LLOG_CONFIG_REPL_CTXT = 1,
400 LLOG_UNLINK_ORIG_CTXT = 2,
401 LLOG_UNLINK_REPL_CTXT = 3,
402 LLOG_SIZE_ORIG_CTXT = 4,
403 LLOG_SIZE_REPL_CTXT = 5,
404 LLOG_MD_ORIG_CTXT = 6,
405 LLOG_MD_REPL_CTXT = 7,
406 LLOG_RD1_ORIG_CTXT = 8,
407 LLOG_RD1_REPL_CTXT = 9,
408 LLOG_TEST_ORIG_CTXT = 10,
409 LLOG_TEST_REPL_CTXT = 11,
414 /* corresponds to one of the obd's */
416 struct obd_type *obd_type;
418 /* common and UUID name of this device */
420 struct obd_uuid obd_uuid;
423 int obd_attached:1, obd_set_up:1, obd_recovering:1,
424 obd_abort_recovery:1, obd_replayable:1, obd_no_transno:1,
425 obd_no_recov:1, obd_stopping:1;
426 atomic_t obd_refcount;
427 wait_queue_head_t obd_refcount_waitq;
428 struct proc_dir_entry *obd_proc_entry;
429 struct list_head obd_exports;
431 struct ldlm_namespace *obd_namespace;
432 struct ptlrpc_client obd_ldlm_client; /* XXX OST/MDS only */
433 /* a spinlock is OK for what we do now, may need a semaphore later */
434 spinlock_t obd_dev_lock;
435 __u64 obd_last_committed;
436 struct fsfilt_operations *obd_fsops;
437 struct llog_ctxt *obd_llog_ctxt[LLOG_MAX_CTXTS];
438 struct obd_statfs obd_osfs;
439 unsigned long obd_osfs_age;
440 struct obd_run_ctxt obd_ctxt;
441 struct obd_device *obd_observer;
442 struct obd_export *obd_self_export;
444 /* XXX encapsulate all this recovery data into one struct */
445 svc_handler_t obd_recovery_handler;
446 int obd_max_recoverable_clients;
447 int obd_connected_clients;
448 int obd_recoverable_clients;
449 spinlock_t obd_processing_task_lock;
450 pid_t obd_processing_task;
451 __u64 obd_next_recovery_transno;
452 int obd_replayed_requests;
453 int obd_requests_queued_for_recovery;
454 wait_queue_head_t obd_next_transno_waitq;
455 wait_queue_head_t obd_commit_waitq;
456 struct timer_list obd_recovery_timer;
457 struct list_head obd_recovery_queue;
458 struct list_head obd_delayed_reply_queue;
461 struct filter_obd filter;
463 struct client_obd cli;
465 struct echo_client_obd echo_client;
466 struct echo_obd echo;
467 struct recovd_obd recovd;
469 struct cache_obd cobd;
470 struct ptlbd_obd ptlbd;
471 struct mgmtcli_obd mgmtcli;
473 /* Fields used by LProcFS */
474 unsigned int obd_cntr_base;
475 struct lprocfs_stats *obd_stats;
476 struct proc_dir_entry *obd_svc_procroot;
477 struct lprocfs_stats *obd_svc_stats;
480 #define OBD_OPT_FORCE 0x0001
481 #define OBD_OPT_FAILOVER 0x0002
483 #define OBD_LLOG_FL_SENDNOW 0x0001
486 struct module *o_owner;
487 int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
488 void *karg, void *uarg);
489 int (*o_get_info)(struct obd_export *, __u32 keylen, void *key,
490 __u32 *vallen, void *val);
491 int (*o_set_info)(struct obd_export *, __u32 keylen, void *key,
492 __u32 vallen, void *val);
493 int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
494 int (*o_detach)(struct obd_device *dev);
495 int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
496 int (*o_postsetup) (struct obd_device *dev);
497 int (*o_precleanup)(struct obd_device *dev, int flags);
498 int (*o_cleanup)(struct obd_device *dev, int flags);
499 int (*o_postrecov)(struct obd_device *dev);
500 int (*o_connect)(struct lustre_handle *conn, struct obd_device *src,
501 struct obd_uuid *cluuid);
502 int (*o_disconnect)(struct obd_export *exp, int flags);
504 int (*o_statfs)(struct obd_device *obd, struct obd_statfs *osfs,
505 unsigned long max_age);
506 int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
507 struct lov_stripe_md *mem_src);
508 int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
509 struct lov_mds_md *disk_src, int disk_len);
510 int (*o_preallocate)(struct lustre_handle *, obd_count *req,
512 int (*o_create)(struct obd_export *exp, struct obdo *oa,
513 struct lov_stripe_md **ea, struct obd_trans_info *oti);
514 int (*o_destroy)(struct obd_export *exp, struct obdo *oa,
515 struct lov_stripe_md *ea, struct obd_trans_info *oti);
516 int (*o_setattr)(struct obd_export *exp, struct obdo *oa,
517 struct lov_stripe_md *ea, struct obd_trans_info *oti);
518 int (*o_getattr)(struct obd_export *exp, struct obdo *oa,
519 struct lov_stripe_md *ea);
520 int (*o_getattr_async)(struct obd_export *exp, struct obdo *oa,
521 struct lov_stripe_md *ea,
522 struct ptlrpc_request_set *set);
523 int (*o_brw)(int rw, struct obd_export *exp, struct obdo *oa,
524 struct lov_stripe_md *ea, obd_count oa_bufs,
525 struct brw_page *pgarr, struct obd_trans_info *oti);
526 int (*o_brw_async)(int rw, struct obd_export *exp, struct obdo *oa,
527 struct lov_stripe_md *ea, obd_count oa_bufs,
528 struct brw_page *pgarr, struct ptlrpc_request_set *,
529 struct obd_trans_info *oti);
530 int (*o_prep_async_page)(struct obd_export *exp,
531 struct lov_stripe_md *lsm,
532 struct lov_oinfo *loi,
533 struct page *page, obd_off offset,
534 struct obd_async_page_ops *ops, void *data,
536 int (*o_queue_async_io)(struct obd_export *exp,
537 struct lov_stripe_md *lsm,
538 struct lov_oinfo *loi, void *cookie,
539 int cmd, obd_off off, int count,
540 obd_flag brw_flags, obd_flag async_flags);
541 int (*o_queue_sync_io)(struct obd_export *exp,
542 struct lov_stripe_md *lsm,
543 struct lov_oinfo *loi,
544 struct obd_sync_io_container *osic,
545 void *cookie, int cmd, obd_off off, int count,
547 int (*o_trigger_sync_io)(struct obd_export *exp,
548 struct lov_stripe_md *lsm,
549 struct lov_oinfo *loi,
550 struct obd_sync_io_container *osic);
551 int (*o_set_async_flags)(struct obd_export *exp,
552 struct lov_stripe_md *lsm,
553 struct lov_oinfo *loi, void *cookie,
554 obd_flag async_flags);
555 int (*o_teardown_async_page)(struct obd_export *exp,
556 struct lov_stripe_md *lsm,
557 struct lov_oinfo *loi, void *cookie);
558 int (*o_punch)(struct obd_export *exp, struct obdo *oa,
559 struct lov_stripe_md *ea, obd_size start,
560 obd_size end, struct obd_trans_info *oti);
561 int (*o_sync)(struct obd_export *exp, struct obdo *oa,
562 struct lov_stripe_md *ea, obd_size start, obd_size end);
563 int (*o_migrate)(struct lustre_handle *conn, struct lov_stripe_md *dst,
564 struct lov_stripe_md *src, obd_size start,
565 obd_size end, struct obd_trans_info *oti);
566 int (*o_copy)(struct lustre_handle *dstconn, struct lov_stripe_md *dst,
567 struct lustre_handle *srconn, struct lov_stripe_md *src,
568 obd_size start, obd_size end, struct obd_trans_info *);
569 int (*o_iterate)(struct lustre_handle *conn,
570 int (*)(obd_id, obd_gr, void *),
571 obd_id *startid, obd_gr group, void *data);
572 int (*o_preprw)(int cmd, struct obd_export *exp, struct obdo *oa,
573 int objcount, struct obd_ioobj *obj,
574 int niocount, struct niobuf_remote *remote,
575 struct niobuf_local *local, struct obd_trans_info *oti);
576 int (*o_commitrw)(int cmd, struct obd_export *exp, struct obdo *oa,
577 int objcount, struct obd_ioobj *obj,
578 int niocount, struct niobuf_local *local,
579 struct obd_trans_info *oti);
580 int (*o_enqueue)(struct obd_export *exp, struct lov_stripe_md *md,
581 struct lustre_handle *parent_lock,
582 __u32 type, void *cookie, int cookielen, __u32 mode,
583 int *flags, void *cb, void *data,
584 struct lustre_handle *lockh);
585 int (*o_match)(struct obd_export *exp, struct lov_stripe_md *md,
586 __u32 type, void *cookie, int cookielen, __u32 mode,
587 int *flags, void *data, struct lustre_handle *lockh);
588 int (*o_change_cbdata)(struct obd_export *exp,
589 struct lov_stripe_md *lsm, ldlm_iterator_t it,
591 int (*o_cancel)(struct obd_export *, struct lov_stripe_md *md,
592 __u32 mode, struct lustre_handle *);
593 int (*o_cancel_unused)(struct obd_export *, struct lov_stripe_md *,
594 int flags, void *opaque);
595 int (*o_san_preprw)(int cmd, struct obd_export *exp,
596 struct obdo *oa, int objcount,
597 struct obd_ioobj *obj, int niocount,
598 struct niobuf_remote *remote);
599 int (*o_init_export)(struct obd_export *exp);
600 int (*o_destroy_export)(struct obd_export *exp);
602 /* llog related obd_methods */
603 int (*o_llog_init)(struct obd_device *obd, struct obd_device *disk_obd,
604 int count, struct llog_logid *logid);
605 int (*o_llog_finish)(struct obd_device *obd, int count);
607 /* only until proper file size mechanics arrive */
608 int (*o_lock_contains)(struct obd_export *exp,
609 struct lov_stripe_md *lsm,
610 struct ldlm_lock *lock, obd_off offset);
612 /* metadata-only methods */
613 int (*o_pin)(struct obd_export *, obd_id ino, __u32 gen, int type,
614 struct obd_client_handle *, int flag);
615 int (*o_unpin)(struct obd_export *, struct obd_client_handle *, int);
617 int (*o_invalidate_import)(struct obd_device *, struct obd_import *);
619 int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
622 * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
623 * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
624 * Also, add a wrapper function in include/linux/obd_class.h.
630 static inline void obd_transno_commit_cb(struct obd_device *obd, __u64 transno,
634 CERROR("%s: transno "LPD64" commit error: %d\n",
635 obd->obd_name, transno, error);
638 CDEBUG(D_HA, "%s: transno "LPD64" committed\n",
639 obd->obd_name, transno);
640 if (transno > obd->obd_last_committed) {
641 obd->obd_last_committed = transno;
642 wake_up(&obd->obd_commit_waitq);