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_REGISTER_LOV _IOWR(IOC_OSC_TYPE, 20, struct obd_device *)
16 #define IOC_OSC_SET_ACTIVE _IOWR(IOC_OSC_TYPE, 21, struct obd_device *)
17 #define IOC_OSC_MAX_NR 50
19 #define IOC_MDC_TYPE 'i'
20 #define IOC_MDC_MIN_NR 20
21 #define IOC_MDC_LOOKUP _IOWR(IOC_MDC_TYPE, 20, struct obd_device *)
22 #define IOC_MDC_GETSTRIPE _IOWR(IOC_MDC_TYPE, 21, struct lov_mds_md *)
23 #define IOC_MDC_MAX_NR 50
26 # include <linux/fs.h>
27 # include <linux/list.h>
28 # include <linux/sched.h> /* for struct task_struct, for current.h */
29 # include <asm/current.h> /* for smp_lock.h */
30 # include <linux/smp_lock.h>
31 # include <linux/proc_fs.h>
32 # include <linux/mount.h>
35 #include <linux/lustre_lib.h>
36 #include <linux/lustre_idl.h>
37 #include <linux/lustre_export.h>
38 #include <linux/lustre_otree.h>
40 struct lov_oinfo { /* per-child structure */
41 __u64 loi_id; /* object ID on the target OST */
42 struct lustre_handle *loi_handle; /* open file handle for obj on OST */
43 int loi_ost_idx; /* OST stripe index in lmd_objects array */
44 /* tracking offsets per file, per stripe.. */
45 struct otree *loi_dirty_ot; /* lets lov stack on osc */
46 struct otree loi_dirty_ot_inline;
49 struct lov_stripe_md {
51 __u64 lsm_object_id; /* lov object id */
54 /* LOV-private members start here -- only for use in lov/. */
56 __u32 lsm_stripe_size; /* size of the stripe */
57 unsigned lsm_stripe_offset; /* offset of first stripe in lmd_objects */
58 unsigned lsm_stripe_count; /* how many objects are being striped on */
59 struct lov_oinfo lsm_oinfo[0];
63 struct list_head typ_chain;
64 struct obd_ops *typ_ops;
65 struct proc_dir_entry *typ_procroot;
77 /* Individual type definitions */
79 struct ost_server_data;
82 const char *fo_fstype;
84 struct super_block *fo_sb;
85 struct vfsmount *fo_vfsmnt;
86 struct obd_run_ctxt fo_ctxt;
87 struct dentry *fo_dentry_O;
88 struct dentry *fo_dentry_O_mode[16];
89 struct dentry **fo_dentry_O_sub;
90 spinlock_t fo_objidlock; /* protect fo_lastobjid increment */
91 spinlock_t fo_translock; /* protect fsd_last_rcvd increment */
92 struct file *fo_rcvd_filp;
93 struct filter_server_data *fo_fsd;
94 unsigned long *fo_last_rcvd_slots;
96 struct file_operations *fo_fop;
97 struct inode_operations *fo_iop;
98 struct address_space_operations *fo_aops;
100 struct list_head fo_export_list;
101 spinlock_t fo_fddlock; /* protect setting dentry->d_fsdata */
103 spinlock_t fo_grant_lock; /* protects tot_granted */
104 obd_size fo_tot_granted;
105 obd_size fo_tot_cached;
107 struct llog_handle *fo_catalog;
108 struct obd_import *fo_mdc_imp;
109 struct obd_uuid fo_mdc_uuid;
110 struct lustre_handle fo_mdc_conn;
111 struct ptlrpc_client fo_mdc_client;
112 struct llog_commit_data *fo_llcd;
113 struct semaphore fo_sem; /* protects fo_llcd */
116 struct mds_server_data;
119 struct obd_import *cl_import;
120 struct semaphore cl_sem;
122 /* max_mds_easize is purely a performance thing so we don't have to
123 * call obd_size_wiremd() all the time. */
124 int cl_max_mds_easize;
125 int cl_max_mds_cookiesize;
126 /* XXX can we replace cl_containing_lov with mgmt-events? */
127 struct obd_device *cl_containing_lov;
130 struct llog_commit_data *cl_llcd;
131 void *cl_llcd_offset;
133 struct semaphore cl_dirty_sem;
134 obd_size cl_dirty; /* both in bytes */
135 obd_size cl_dirty_granted;
137 struct obd_device *cl_mgmtcli_obd;
139 /* this is just to keep existing infinitely caching behaviour between
140 * clients and OSTs that don't have the grant code in yet.. it can
141 * be yanked once everything speaks grants */
142 char cl_ost_can_grant;
145 /* Like a client, with some hangers-on. Keep mc_client_obd first so that we
146 * can reuse the various client setup/connect functions. */
148 struct client_obd mc_client_obd; /* nested */
149 struct ptlrpc_thread *mc_ping_thread;
150 struct lustre_handle mc_ping_handle; /* XXX single-target */
151 struct list_head mc_registered;
155 #define mc_import mc_client_obd.cl_import
158 struct ptlrpc_service *mds_service;
159 struct ptlrpc_service *mds_setattr_service;
160 struct ptlrpc_service *mds_readpage_service;
162 struct super_block *mds_sb;
163 struct vfsmount *mds_vfsmnt;
164 struct dentry *mds_fid_de;
165 struct obd_run_ctxt mds_ctxt;
166 struct file_operations *mds_fop;
167 struct inode_operations *mds_iop;
168 struct address_space_operations *mds_aops;
171 int mds_max_cookiesize;
172 struct file *mds_rcvd_filp;
173 spinlock_t mds_transno_lock;
174 __u64 mds_last_transno;
175 __u64 mds_mount_count;
176 struct ll_fid mds_rootfid;
177 struct mds_server_data *mds_server_data;
178 struct dentry *mds_pending_dir;
179 struct dentry *mds_logs_dir;
181 struct llog_handle *mds_catalog;
182 struct obd_device *mds_osc_obd;
183 struct obd_uuid mds_osc_uuid;
184 struct lustre_handle mds_osc_conn;
186 int mds_has_lov_desc;
187 struct lov_desc mds_lov_desc;
188 unsigned long *mds_client_bitmap;
192 struct ptlrpc_service *ldlm_cb_service;
193 struct ptlrpc_service *ldlm_cancel_service;
194 struct ptlrpc_client *ldlm_client;
195 struct ptlrpc_connection *ldlm_server_conn;
212 * this struct does double-duty acting as either a client or
213 * server instance .. maybe not wise.
217 struct ptlrpc_service *ptlbd_service;
220 struct ptlrpc_client bd_client;
221 struct obd_import *bd_import;
222 struct obd_uuid bd_server_uuid;
223 struct lustre_handle bd_connect_handle;
224 int refcount; /* XXX sigh */
228 spinlock_t recovd_lock;
229 struct list_head recovd_managed_items; /* items managed */
230 struct list_head recovd_troubled_items; /* items in recovery */
232 wait_queue_head_t recovd_recovery_waitq;
233 wait_queue_head_t recovd_ctl_waitq;
234 wait_queue_head_t recovd_waitq;
235 struct task_struct *recovd_thread;
240 struct ptlrpc_service *ost_service;
243 struct echo_client_obd {
244 struct lustre_handle ec_conn; /* the local connection to osc/lov */
246 struct list_head ec_objects;
253 struct lustre_handle cobd_target; /* local connection to target obd */
254 struct lustre_handle cobd_cache; /* local connection to cache obd */
257 struct lov_tgt_desc {
258 struct obd_uuid uuid;
259 struct lustre_handle conn;
260 struct llog_handle *ltd_cathandle;
261 int active; /* is this target available for requests, etc */
266 struct obd_device *mdcobd;
267 struct lov_desc desc;
270 int lo_catalog_loaded:1;
271 struct lov_tgt_desc *tgts;
274 struct niobuf_local {
280 struct dentry *dentry;
284 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
285 #define N_LOCAL_TEMP_PAGE 0x10000000
287 struct obd_trans_info {
289 /* Only used on the server side for tracking acks. */
290 struct oti_req_ack_lock {
291 struct lustre_handle lock;
295 struct llog_cookie oti_onecookie;
296 struct llog_cookie *oti_logcookies;
300 static inline void oti_alloc_cookies(struct obd_trans_info *oti,int num_cookies)
305 if (num_cookies == 1)
306 oti->oti_logcookies = &oti->oti_onecookie;
308 OBD_ALLOC(oti->oti_logcookies,
309 num_cookies * sizeof(oti->oti_onecookie));
311 oti->oti_numcookies = num_cookies;
314 static inline void oti_free_cookies(struct obd_trans_info *oti)
316 if (!oti || !oti->oti_logcookies)
319 if (oti->oti_logcookies == &oti->oti_onecookie)
320 LASSERT(oti->oti_numcookies == 1);
322 OBD_FREE(oti->oti_logcookies,
323 oti->oti_numcookies * sizeof(oti->oti_onecookie));
324 oti->oti_logcookies = NULL;
325 oti->oti_numcookies = 0;
328 /* corresponds to one of the obd's */
330 struct obd_type *obd_type;
332 /* common and UUID name of this device */
334 struct obd_uuid obd_uuid;
337 int obd_attached:1, obd_set_up:1, obd_recovering:1,
338 obd_abort_recovery:1, obd_replayable:1, obd_no_transno:1,
339 obd_no_recov:1, obd_stopping:1;
340 atomic_t obd_refcount;
341 wait_queue_head_t obd_refcount_waitq;
342 struct proc_dir_entry *obd_proc_entry;
343 struct list_head obd_exports;
345 struct list_head obd_imports;
346 struct ldlm_namespace *obd_namespace;
347 struct ptlrpc_client obd_ldlm_client; /* XXX OST/MDS only */
348 /* a spinlock is OK for what we do now, may need a semaphore later */
349 spinlock_t obd_dev_lock;
350 __u64 obd_last_committed;
351 struct fsfilt_operations *obd_fsops;
352 struct obd_statfs obd_osfs;
353 unsigned long obd_osfs_age;
355 /* XXX encapsulate all this recovery data into one struct */
356 svc_handler_t obd_recovery_handler;
357 int obd_recoverable_clients;
358 spinlock_t obd_processing_task_lock;
359 pid_t obd_processing_task;
360 __u64 obd_next_recovery_transno;
361 wait_queue_head_t obd_next_transno_waitq;
362 wait_queue_head_t obd_commit_waitq;
363 struct timer_list obd_recovery_timer;
364 struct list_head obd_recovery_queue;
365 struct list_head obd_delayed_reply_queue;
368 struct filter_obd filter;
370 struct client_obd cli;
372 struct echo_client_obd echo_client;
373 struct ldlm_obd ldlm;
374 struct echo_obd echo;
375 struct recovd_obd recovd;
377 struct cache_obd cobd;
378 struct ptlbd_obd ptlbd;
379 struct mgmtcli_obd mgmtcli;
381 /* Fields used by LProcFS */
382 unsigned int obd_cntr_base;
383 struct lprocfs_stats *obd_stats;
386 #define OBD_OPT_FORCE 0x0001
387 #define OBD_OPT_FAILOVER 0x0002
389 #define OBD_LLOG_FL_SENDNOW 0x0001
392 struct module *o_owner;
393 int (*o_iocontrol)(unsigned int cmd, struct lustre_handle *, int len,
394 void *karg, void *uarg);
395 int (*o_get_info)(struct lustre_handle *, __u32 keylen, void *key,
396 __u32 *vallen, void *val);
397 int (*o_set_info)(struct lustre_handle *, __u32 keylen, void *key,
398 __u32 vallen, void *val);
399 int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
400 int (*o_detach)(struct obd_device *dev);
401 int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
402 int (*o_cleanup)(struct obd_device *dev, int flags);
403 int (*o_connect)(struct lustre_handle *conn, struct obd_device *src,
404 struct obd_uuid *cluuid);
405 int (*o_disconnect)(struct lustre_handle *conn, int flags);
407 int (*o_statfs)(struct obd_device *obd, struct obd_statfs *osfs,
408 unsigned long max_age);
409 int (*o_syncfs)(struct obd_export *exp);
410 int (*o_packmd)(struct lustre_handle *, struct lov_mds_md **disk_tgt,
411 struct lov_stripe_md *mem_src);
412 int (*o_unpackmd)(struct lustre_handle *conn,
413 struct lov_stripe_md **mem_tgt,
414 struct lov_mds_md *disk_src, int disk_len);
415 int (*o_preallocate)(struct lustre_handle *, obd_count *req,
417 int (*o_create)(struct lustre_handle *conn, struct obdo *oa,
418 struct lov_stripe_md **ea, struct obd_trans_info *oti);
419 int (*o_destroy)(struct lustre_handle *conn, struct obdo *oa,
420 struct lov_stripe_md *ea, struct obd_trans_info *oti);
421 int (*o_setattr)(struct lustre_handle *conn, struct obdo *oa,
422 struct lov_stripe_md *ea, struct obd_trans_info *oti);
423 int (*o_getattr)(struct lustre_handle *conn, struct obdo *oa,
424 struct lov_stripe_md *ea);
425 int (*o_getattr_async)(struct lustre_handle *conn, struct obdo *oa,
426 struct lov_stripe_md *ea,
427 struct ptlrpc_request_set *set);
428 int (*o_open)(struct lustre_handle *conn, struct obdo *oa,
429 struct lov_stripe_md *ea, struct obd_trans_info *oti,
430 struct obd_client_handle *och);
431 int (*o_close)(struct lustre_handle *conn, struct obdo *oa,
432 struct lov_stripe_md *ea, struct obd_trans_info *oti);
433 int (*o_brw)(int rw, struct lustre_handle *conn, struct obdo *oa,
434 struct lov_stripe_md *ea, obd_count oa_bufs,
435 struct brw_page *pgarr, struct obd_trans_info *oti);
436 int (*o_brw_async)(int rw, struct lustre_handle *conn, struct obdo *oa,
437 struct lov_stripe_md *ea, obd_count oa_bufs,
438 struct brw_page *pgarr, struct ptlrpc_request_set *,
439 struct obd_trans_info *oti);
440 int (*o_punch)(struct lustre_handle *conn, struct obdo *oa,
441 struct lov_stripe_md *ea, obd_size count,
442 obd_off offset, struct obd_trans_info *oti);
443 int (*o_sync)(struct lustre_handle *conn, struct obdo *oa,
444 obd_size count, obd_off offset);
445 int (*o_migrate)(struct lustre_handle *conn, struct lov_stripe_md *dst,
446 struct lov_stripe_md *src, obd_size count,
448 int (*o_copy)(struct lustre_handle *dstconn, struct lov_stripe_md *dst,
449 struct lustre_handle *srconn, struct lov_stripe_md *src,
450 obd_size count, obd_off offset, struct obd_trans_info *);
451 int (*o_iterate)(struct lustre_handle *conn,
452 int (*)(obd_id, obd_gr, void *),
453 obd_id *startid, obd_gr group, void *data);
454 int (*o_preprw)(int cmd, struct obd_export *exp, struct obdo *oa,
455 int objcount, struct obd_ioobj *obj,
456 int niocount, struct niobuf_remote *remote,
457 struct niobuf_local *local, struct obd_trans_info *oti);
458 int (*o_commitrw)(int cmd, struct obd_export *exp, struct obdo *oa,
459 int objcount, struct obd_ioobj *obj,
460 int niocount, struct niobuf_local *local,
461 struct obd_trans_info *oti);
462 int (*o_enqueue)(struct lustre_handle *conn, struct lov_stripe_md *md,
463 struct lustre_handle *parent_lock,
464 __u32 type, void *cookie, int cookielen, __u32 mode,
465 int *flags, void *cb, void *data,
466 struct lustre_handle *lockh);
467 int (*o_match)(struct lustre_handle *conn, struct lov_stripe_md *md,
468 __u32 type, void *cookie, int cookielen, __u32 mode,
469 int *flags, void *data, struct lustre_handle *lockh);
470 int (*o_cancel)(struct lustre_handle *, struct lov_stripe_md *md,
471 __u32 mode, struct lustre_handle *);
472 int (*o_cancel_unused)(struct lustre_handle *, struct lov_stripe_md *,
473 int flags, void *opaque);
474 int (*o_log_add)(struct lustre_handle *conn,
475 struct llog_handle *cathandle,
476 struct llog_trans_hdr *rec, struct lov_stripe_md *lsm,
477 struct llog_cookie *logcookies, int numcookies);
478 int (*o_log_cancel)(struct lustre_handle *, struct lov_stripe_md *,
479 int count, struct llog_cookie *, int flags);
480 int (*o_san_preprw)(int cmd, struct obd_export *exp,
481 struct obdo *oa, int objcount,
482 struct obd_ioobj *obj, int niocount,
483 struct niobuf_remote *remote);
484 int (*o_mark_page_dirty)(struct lustre_handle *conn,
485 struct lov_stripe_md *ea,
486 unsigned long offset);
487 int (*o_clear_dirty_pages)(struct lustre_handle *conn,
488 struct lov_stripe_md *ea,
491 unsigned long *cleared);
492 int (*o_last_dirty_offset)(struct lustre_handle *conn,
493 struct lov_stripe_md *ea,
494 unsigned long *offset);
495 void (*o_destroy_export)(struct obd_export *exp);
497 /* metadata-only methods */
498 int (*o_pin)(struct lustre_handle *, obd_id ino, __u32 gen, int type,
499 struct obd_client_handle *, int flag);
500 int (*o_unpin)(struct lustre_handle *, struct obd_client_handle *, int);
502 /* If adding ops, also update obdclass/lprocfs_status.c,
503 * and include/linux/obd_class.h */
506 static inline void obd_transno_commit_cb(struct obd_device *obd, __u64 transno,
510 CERROR("%s: transno "LPD64" commit error: %d\n",
511 obd->obd_name, transno, error);
514 CDEBUG(D_HA, "%s: transno "LPD64" committed\n",
515 obd->obd_name, transno);
516 if (transno > obd->obd_last_committed) {
517 obd->obd_last_committed = transno;
518 wake_up(&obd->obd_commit_waitq);