Whamcloud - gitweb
ba848a9760f745e7b5f94c537223e2a856c79b9f
[fs/lustre-release.git] / lustre / include / linux / obd.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  */
9
10 #ifndef __OBD_H
11 #define __OBD_H
12
13 #include <linux/lustre_otree.h>
14
15 struct lov_oinfo { /* per-child structure */
16         __u64 loi_id;              /* object ID on the target OST */
17         struct lustre_handle *loi_handle; /* open file handle for obj on OST */
18         int loi_ost_idx;           /* OST stripe index in lmd_objects array */
19         /* tracking offsets per file, per stripe.. */
20         struct otree *loi_dirty_ot; /* lets lov stack on osc */
21         struct otree loi_dirty_ot_inline;
22 };
23
24 struct lov_stripe_md {
25         /* Public members. */
26         __u64 lsm_object_id;        /* lov object id */
27         __u64 lsm_maxbytes;
28
29         /* LOV-private members start here -- only for use in lov/. */
30         __u32 lsm_magic;
31         __u32 lsm_stripe_size;      /* size of the stripe */
32         unsigned lsm_stripe_offset; /* offset of first stripe in lmd_objects */
33         unsigned lsm_stripe_count;  /* how many objects are being striped on */
34         struct lov_oinfo lsm_oinfo[0];
35 };
36
37 #define IOC_OSC_TYPE         'h'
38 #define IOC_OSC_MIN_NR       20
39 #define IOC_OSC_REGISTER_LOV _IOWR(IOC_OSC_TYPE, 20, struct obd_device *)
40 #define IOC_OSC_SET_ACTIVE   _IOWR(IOC_OSC_TYPE, 21, struct obd_device *)
41 #define IOC_OSC_MAX_NR       50
42
43 #define IOC_MDC_TYPE         'i'
44 #define IOC_MDC_MIN_NR       20
45 #define IOC_MDC_LOOKUP       _IOWR(IOC_MDC_TYPE, 20, struct obd_device *)
46 #define IOC_MDC_MAX_NR       50
47
48 #ifdef __KERNEL__
49 # include <linux/fs.h>
50 # include <linux/list.h>
51 # include <linux/sched.h> /* for struct task_struct, for current.h */
52 # include <asm/current.h> /* for smp_lock.h */
53 # include <linux/smp_lock.h>
54 # include <linux/proc_fs.h>
55
56 # include <linux/lustre_lib.h>
57 # include <linux/lustre_idl.h>
58 # include <linux/lustre_mds.h>
59 # include <linux/lustre_export.h>
60 #endif
61
62 struct obd_type {
63         struct list_head typ_chain;
64         struct obd_ops *typ_ops;
65         struct proc_dir_entry *typ_procroot;
66         char *typ_name;
67         int  typ_refcnt;
68 };
69
70 struct brw_page {
71         obd_off  off;
72         struct page *pg;
73         int count;
74         obd_flag flag;
75 };
76
77 /* Individual type definitions */
78
79 struct ost_server_data;
80
81 struct filter_obd {
82         const char          *fo_fstype;
83         char *fo_nspath;
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;
95
96         struct file_operations *fo_fop;
97         struct inode_operations *fo_iop;
98         struct address_space_operations *fo_aops;
99
100         struct list_head     fo_export_list;
101         spinlock_t           fo_fddlock; /* protect setting dentry->d_fsdata */
102         int                  fo_subdir_count;
103         spinlock_t           fo_grant_lock;       /* protects tot_granted */
104         obd_size             fo_tot_granted;
105         obd_size             fo_tot_cached;
106 };
107
108 struct mds_server_data;
109
110 struct client_obd {
111         struct obd_import   *cl_import;
112         struct semaphore     cl_sem;
113         int                  cl_conn_count;
114         /* max_mds_easize is purely a performance thing so we don't have to
115          * call obd_size_wiremd() all the time. */
116         int                  cl_max_mds_easize;
117         struct obd_device   *cl_containing_lov;
118         kdev_t               cl_sandev;
119         struct semaphore     cl_dirty_sem;
120         obd_size             cl_dirty;  /* both in bytes */
121         obd_size             cl_dirty_granted;
122         /* this is just to keep existing infinitely caching behaviour between 
123          * clients and OSTs that don't have the grant code in yet.. it can 
124          * be yanked once everything speaks grants */
125         char                 cl_ost_can_grant;
126 };
127
128 struct mds_obd {
129         struct ptlrpc_service           *mds_service;
130         struct ptlrpc_service           *mds_setattr_service;
131         struct ptlrpc_service           *mds_readpage_service;
132
133         struct super_block              *mds_sb;
134         struct vfsmount                 *mds_vfsmnt;
135         struct dentry                   *mds_fid_de;
136         struct obd_run_ctxt              mds_ctxt;
137         struct file_operations          *mds_fop;
138         struct inode_operations         *mds_iop;
139         struct address_space_operations *mds_aops;
140
141         int                              mds_max_mdsize;
142         struct file                     *mds_rcvd_filp;
143         spinlock_t                       mds_transno_lock;
144         __u64                            mds_last_transno;
145         __u64                            mds_mount_count;
146         struct ll_fid                    mds_rootfid;
147         struct mds_server_data          *mds_server_data;
148
149         int                              mds_has_lov_desc;
150         struct lov_desc                  mds_lov_desc;
151         unsigned long                   *mds_client_bitmap;
152 };
153
154 struct ldlm_obd {
155         struct ptlrpc_service *ldlm_cb_service;
156         struct ptlrpc_service *ldlm_cancel_service;
157         struct ptlrpc_client *ldlm_client;
158         struct ptlrpc_connection *ldlm_server_conn;
159 };
160
161 struct echo_obd {
162         char *eo_fstype;
163         struct obdo oa;
164         spinlock_t eo_lock;
165         __u64 eo_lastino;
166         atomic_t eo_getattr;
167         atomic_t eo_setattr;
168         atomic_t eo_create;
169         atomic_t eo_destroy;
170         atomic_t eo_prep;
171         atomic_t eo_read;
172         atomic_t eo_write;
173 };
174
175 /*
176  * this struct does double-duty acting as either a client or
177  * server instance .. maybe not wise.
178  */
179 struct ptlbd_obd {
180         /* server's */
181         struct ptlrpc_service *ptlbd_service;
182         struct file *filp;
183         /* client's */
184         struct ptlrpc_client    bd_client;
185         struct obd_import       *bd_import;
186         struct obd_uuid         bd_server_uuid;
187         struct lustre_handle    bd_connect_handle;
188         int refcount; /* XXX sigh */
189 };
190
191 struct recovd_obd {
192         spinlock_t            recovd_lock;
193         struct list_head      recovd_managed_items; /* items managed  */
194         struct list_head      recovd_troubled_items; /* items in recovery */
195
196         wait_queue_head_t     recovd_recovery_waitq;
197         wait_queue_head_t     recovd_ctl_waitq;
198         wait_queue_head_t     recovd_waitq;
199         struct task_struct   *recovd_thread;
200         __u32                 recovd_state;
201 };
202
203 struct ost_obd {
204         struct ptlrpc_service *ost_service;
205 };
206
207 struct echo_client_obd {
208         struct lustre_handle ec_conn;   /* the local connection to osc/lov */
209         spinlock_t           ec_lock;
210         struct list_head     ec_objects;
211         int                  ec_lsmsize;
212         int                  ec_nstripes;
213         __u64                ec_unique;
214 };
215
216 struct cache_obd {
217         struct lustre_handle cobd_target;   /* local connection to target obd */
218         struct lustre_handle cobd_cache;    /* local connection to cache obd */
219 };
220
221 struct lov_tgt_desc {
222         struct obd_uuid uuid;
223         struct lustre_handle conn;
224         int active; /* is this target available for requests, etc */
225 };
226
227 struct lov_obd {
228         spinlock_t lov_lock;
229         struct obd_device *mdcobd;
230         struct lov_desc desc;
231         int bufsize;
232         int refcount;
233         struct lov_tgt_desc *tgts;
234 };
235
236 struct niobuf_local {
237         __u64 offset;
238         __u32 len;
239         __u32 flags;
240         __u32 rc;
241         struct page *page;
242         struct dentry *dentry;
243         unsigned long start;
244 };
245
246 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
247 #define N_LOCAL_TEMP_PAGE 0x10000000
248
249 struct obd_trans_info {
250         __u64     oti_transno;
251         /* Only used on the server side for tracking acks. */
252         struct oti_req_ack_lock {
253                 struct lustre_handle lock;
254                 __u32                mode;
255         } oti_ack_locks[4];
256 };
257
258 /* corresponds to one of the obd's */
259 struct obd_device {
260         struct obd_type *obd_type;
261
262         /* common and UUID name of this device */
263         char *obd_name;
264         struct obd_uuid obd_uuid;
265
266         int obd_minor;
267         int obd_attached:1, obd_set_up:1, obd_recovering:1,
268             obd_abort_recovery:1, obd_replayable:1, obd_no_transno:1,
269             obd_no_recov:1, obd_stopping:1;
270         atomic_t obd_refcount;
271         wait_queue_head_t obd_refcount_waitq;
272         struct proc_dir_entry *obd_proc_entry;
273         struct list_head       obd_exports;
274         int                    obd_num_exports;
275         struct list_head       obd_imports;
276         struct ldlm_namespace *obd_namespace;
277         struct ptlrpc_client   obd_ldlm_client; /* XXX OST/MDS only */
278         /* a spinlock is OK for what we do now, may need a semaphore later */
279         spinlock_t obd_dev_lock;
280         __u64                  obd_last_committed;
281         struct fsfilt_operations *obd_fsops;
282
283         /* XXX encapsulate all this recovery data into one struct */
284         svc_handler_t                    obd_recovery_handler;
285         int                              obd_recoverable_clients;
286         spinlock_t                       obd_processing_task_lock;
287         pid_t                            obd_processing_task;
288         __u64                            obd_next_recovery_transno;
289         wait_queue_head_t                obd_next_transno_waitq;
290         wait_queue_head_t                obd_commit_waitq;
291         struct timer_list                obd_recovery_timer;
292         struct list_head                 obd_recovery_queue;
293         struct list_head                 obd_delayed_reply_queue;
294
295         union {
296                 struct filter_obd filter;
297                 struct mds_obd mds;
298                 struct client_obd cli;
299                 struct ost_obd ost;
300                 struct echo_client_obd echo_client;;
301                 struct ldlm_obd ldlm;
302                 struct echo_obd echo;
303                 struct recovd_obd recovd;
304                 struct lov_obd lov;
305                 struct cache_obd cobd;
306                 struct ptlbd_obd ptlbd;
307         } u;
308        /* Fields used by LProcFS */
309         unsigned int           obd_cntr_base;
310         struct lprocfs_stats  *obd_stats;
311 };
312
313 struct obd_ops {
314         struct module *o_owner;
315         int (*o_iocontrol)(unsigned int cmd, struct lustre_handle *, int len,
316                            void *karg, void *uarg);
317         int (*o_get_info)(struct lustre_handle *, __u32 keylen, void *key,
318                           __u32 *vallen, void *val);
319         int (*o_set_info)(struct lustre_handle *, __u32 keylen, void *key,
320                           __u32 vallen, void *val);
321         int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
322         int (*o_detach)(struct obd_device *dev);
323         int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
324         int (*o_cleanup)(struct obd_device *dev, int force, int failover);
325         int (*o_connect)(struct lustre_handle *conn, struct obd_device *src,
326                          struct obd_uuid *cluuid);
327         int (*o_disconnect)(struct lustre_handle *conn, int failover);
328
329         int (*o_statfs)(struct obd_export *exp, struct obd_statfs *osfs);
330         int (*o_syncfs)(struct obd_export *);
331         int (*o_packmd)(struct lustre_handle *, struct lov_mds_md **disk_tgt,
332                         struct lov_stripe_md *mem_src);
333         int (*o_unpackmd)(struct lustre_handle *,
334                           struct lov_stripe_md **mem_tgt,
335                           struct lov_mds_md *disk_src, int disk_len);
336         int (*o_preallocate)(struct lustre_handle *, obd_count *req,
337                              obd_id *ids);
338         int (*o_create)(struct lustre_handle *conn,  struct obdo *oa,
339                         struct lov_stripe_md **ea, struct obd_trans_info *oti);
340         int (*o_destroy)(struct lustre_handle *conn, struct obdo *oa,
341                          struct lov_stripe_md *ea, struct obd_trans_info *oti);
342         int (*o_setattr)(struct lustre_handle *conn, struct obdo *oa,
343                          struct lov_stripe_md *ea, struct obd_trans_info *oti);
344         int (*o_getattr)(struct lustre_handle *conn, struct obdo *oa,
345                          struct lov_stripe_md *ea);
346         int (*o_getattr_async)(struct lustre_handle *conn, struct obdo *oa,
347                                struct lov_stripe_md *ea, 
348                                struct ptlrpc_request_set *set);
349         int (*o_open)(struct lustre_handle *conn, struct obdo *oa,
350                       struct lov_stripe_md *ea, struct obd_trans_info *oti,
351                       struct obd_client_handle *och);
352         int (*o_close)(struct lustre_handle *conn, struct obdo *oa,
353                        struct lov_stripe_md *ea, struct obd_trans_info *oti);
354         int (*o_brw)(int rw, struct lustre_handle *conn,
355                      struct lov_stripe_md *ea, obd_count oa_bufs,
356                      struct brw_page *pgarr, struct obd_trans_info *oti);
357         int (*o_brw_async)(int rw, struct lustre_handle *conn,
358                            struct lov_stripe_md *ea, obd_count oa_bufs,
359                            struct brw_page *pgarr, struct ptlrpc_request_set *,
360                            struct obd_trans_info *oti);
361         int (*o_punch)(struct lustre_handle *conn, struct obdo *tgt,
362                        struct lov_stripe_md *ea, obd_size count,
363                        obd_off offset, struct obd_trans_info *oti);
364         int (*o_sync)(struct lustre_handle *conn, struct obdo *tgt,
365                       obd_size count, obd_off offset);
366         int (*o_migrate)(struct lustre_handle *conn, struct obdo *dst,
367                          struct obdo *src, obd_size count, obd_off offset);
368         int (*o_copy)(struct lustre_handle *dstconn, struct obdo *dst,
369                       struct lustre_handle *srconn, struct obdo *src,
370                       obd_size count, obd_off offset, struct obd_trans_info *);
371         int (*o_iterate)(struct lustre_handle *conn,
372                          int (*)(obd_id, obd_gr, void *),
373                          obd_id *startid, obd_gr group, void *data);
374         int (*o_preprw)(int cmd, struct obd_export *, struct obdo *obdo,
375                         int objcount, struct obd_ioobj *obj,
376                         int niocount, struct niobuf_remote *remote,
377                         struct niobuf_local *local, void **desc_private, 
378                         struct obd_trans_info *oti);
379         int (*o_commitrw)(int cmd, struct obd_export *,
380                           int objcount, struct obd_ioobj *obj,
381                           int niocount, struct niobuf_local *local,
382                           void *desc_private, struct obd_trans_info *oti);
383         int (*o_enqueue)(struct lustre_handle *conn, struct lov_stripe_md *md,
384                          struct lustre_handle *parent_lock,
385                          __u32 type, void *cookie, int cookielen, __u32 mode,
386                          int *flags, void *cb, void *data,
387                          struct lustre_handle *lockh);
388         int (*o_match)(struct lustre_handle *conn, struct lov_stripe_md *md,
389                          __u32 type, void *cookie, int cookielen, __u32 mode,
390                          int *flags, void *data, struct lustre_handle *lockh);
391         int (*o_cancel)(struct lustre_handle *, struct lov_stripe_md *md,
392                         __u32 mode, struct lustre_handle *);
393         int (*o_cancel_unused)(struct lustre_handle *, struct lov_stripe_md *,
394                                int local_only, void *opaque);
395         int (*o_san_preprw)(int cmd, struct lustre_handle *conn,
396                             int objcount, struct obd_ioobj *obj,
397                             int niocount, struct niobuf_remote *remote);
398         int (*o_mark_page_dirty)(struct lustre_handle *conn,
399                                  struct lov_stripe_md *ea,
400                                  unsigned long offset);
401         int (*o_clear_dirty_pages)(struct lustre_handle *conn,
402                                    struct lov_stripe_md *ea,
403                                    unsigned long start,
404                                    unsigned long end,
405                                    unsigned long *cleared);
406         int (*o_last_dirty_offset)(struct lustre_handle *conn,
407                                    struct lov_stripe_md *ea,
408                                    unsigned long *offset);
409         void (*o_destroy_export)(struct obd_export *export);
410 };
411
412 static inline void obd_transno_commit_cb(struct obd_device *obd, __u64 transno,
413                                          int error)
414 {
415         if (error) {
416                 CDEBUG(D_ERROR, "%s: transno "LPD64" commit error: %d\n",
417                        obd->obd_name, transno, error);
418                 return;
419         }
420         CDEBUG(D_HA, "%s: transno "LPD64" committed\n",
421                obd->obd_name, transno);
422         if (transno > obd->obd_last_committed) {
423                 obd->obd_last_committed = transno;
424                 wake_up(&obd->obd_commit_waitq);
425         }
426 }
427
428 /* When adding a function pointer to struct obd_ops, please update 
429  * function lprocfs_alloc_obd_counters() in obdclass/lprocfs_status.c
430  * accordingly. */
431
432 #endif /* __OBD_H */