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