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