Whamcloud - gitweb
add ability to resend request if it isn't fit in reply buffer.
[fs/lustre-release.git] / lustre / include / obd.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef __OBD_H
38 #define __OBD_H
39
40 #if defined(__linux__)
41 #include <linux/obd.h>
42 #elif defined(__APPLE__)
43 #include <darwin/obd.h>
44 #elif defined(__WINNT__)
45 #include <winnt/obd.h>
46 #else
47 #error Unsupported operating system.
48 #endif
49
50 #define IOC_OSC_TYPE         'h'
51 #define IOC_OSC_MIN_NR       20
52 #define IOC_OSC_SET_ACTIVE   _IOWR(IOC_OSC_TYPE, 21, struct obd_device *)
53 #define IOC_OSC_MAX_NR       50
54
55 #define IOC_MDC_TYPE         'i'
56 #define IOC_MDC_MIN_NR       20
57 /* Moved to lustre_user.h
58 #define IOC_MDC_LOOKUP       _IOWR(IOC_MDC_TYPE, 20, struct obd_ioctl_data *)
59 #define IOC_MDC_GETSTRIPE    _IOWR(IOC_MDC_TYPE, 21, struct lov_mds_md *) */
60 #define IOC_MDC_MAX_NR       50
61
62 #include <lustre_lib.h>
63 #include <lustre/lustre_idl.h>
64 #include <lustre_export.h>
65 #include <lustre_quota.h>
66 #include <class_hash.h>
67
68 #include <libcfs/bitmap.h>
69
70
71 #define MAX_OBD_DEVICES 8192
72
73 /* this is really local to the OSC */
74 struct loi_oap_pages {
75         struct list_head        lop_pending;
76         struct list_head        lop_urgent;
77         struct list_head        lop_pending_group;
78         int                     lop_num_pending;
79 };
80
81 struct osc_async_rc {
82         int     ar_rc;
83         int     ar_force_sync;
84         __u64   ar_min_xid;
85 };
86
87 struct lov_oinfo {                 /* per-stripe data structure */
88         __u64 loi_id;              /* object ID on the target OST */
89         __u64 loi_gr;              /* object group on the target OST */
90         int loi_ost_idx;           /* OST stripe index in lov_tgt_desc->tgts */
91         int loi_ost_gen;           /* generation of this loi_ost_idx */
92
93         /* used by the osc to keep track of what objects to build into rpcs */
94         struct loi_oap_pages loi_read_lop;
95         struct loi_oap_pages loi_write_lop;
96         struct list_head loi_ready_item;
97         struct list_head loi_hp_ready_item;
98         struct list_head loi_write_item;
99         struct list_head loi_read_item;
100
101         unsigned long loi_kms_valid:1;
102         __u64 loi_kms;             /* known minimum size */
103         struct ost_lvb loi_lvb;
104         struct osc_async_rc     loi_ar;
105 };
106
107 static inline void loi_init(struct lov_oinfo *loi)
108 {
109         CFS_INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending);
110         CFS_INIT_LIST_HEAD(&loi->loi_read_lop.lop_urgent);
111         CFS_INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending_group);
112         CFS_INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending);
113         CFS_INIT_LIST_HEAD(&loi->loi_write_lop.lop_urgent);
114         CFS_INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending_group);
115         CFS_INIT_LIST_HEAD(&loi->loi_ready_item);
116         CFS_INIT_LIST_HEAD(&loi->loi_hp_ready_item);
117         CFS_INIT_LIST_HEAD(&loi->loi_write_item);
118         CFS_INIT_LIST_HEAD(&loi->loi_read_item);
119 }
120
121 /*extent array item for describing the joined file extent info*/
122 struct lov_extent {
123         __u64 le_start;            /* extent start */
124         __u64 le_len;              /* extent length */
125         int   le_loi_idx;          /* extent #1 loi's index in lsm loi array */
126         int   le_stripe_count;     /* extent stripe count*/
127 };
128
129 /*Lov array info for describing joined file array EA info*/
130 struct lov_array_info {
131         struct llog_logid    lai_array_id;    /* MDS med llog object id */
132         unsigned             lai_ext_count; /* number of extent count */
133         struct lov_extent    *lai_ext_array; /* extent desc array */
134 };
135
136 struct lov_stripe_md {
137         spinlock_t       lsm_lock;
138         void            *lsm_lock_owner; /* debugging */
139
140         struct {
141                 /* Public members. */
142                 __u64 lw_object_id;        /* lov object id */
143                 __u64 lw_object_gr;        /* lov object group */
144                 __u64 lw_maxbytes;         /* maximum possible file size */
145
146                 /* LOV-private members start here -- only for use in lov/. */
147                 __u32 lw_magic;
148                 __u32 lw_stripe_size;      /* size of the stripe */
149                 __u32 lw_pattern;          /* striping pattern (RAID0, RAID1) */
150                 unsigned lw_stripe_count;  /* number of objects being striped over */
151                 char  lw_pool_name[LOV_MAXPOOLNAME]; /* pool name */
152         } lsm_wire;
153
154         struct lov_array_info *lsm_array; /*Only for joined file array info*/
155         struct lov_oinfo *lsm_oinfo[0];
156 };
157
158 #define lsm_object_id    lsm_wire.lw_object_id
159 #define lsm_object_gr    lsm_wire.lw_object_gr
160 #define lsm_maxbytes     lsm_wire.lw_maxbytes
161 #define lsm_magic        lsm_wire.lw_magic
162 #define lsm_stripe_size  lsm_wire.lw_stripe_size
163 #define lsm_pattern      lsm_wire.lw_pattern
164 #define lsm_stripe_count lsm_wire.lw_stripe_count
165 #define lsm_pool_name    lsm_wire.lw_pool_name
166
167 struct obd_info;
168
169 typedef int (*obd_enqueue_update_f)(struct obd_info *oinfo, int rc);
170
171 /* obd info for a particular level (lov, osc). */
172 struct obd_info {
173         /* Lock policy. It keeps an extent which is specific for a particular
174          * OSC. (e.g. lov_prep_enqueue_set initialises extent of the policy,
175          * and osc_enqueue passes it into ldlm_lock_match & ldlm_cli_enqueue. */
176         ldlm_policy_data_t      oi_policy;
177         /* Flags used for set request specific flags:
178            - while lock handling, the flags obtained on the enqueue
179            request are set here.
180            - while stats, the flags used for control delay/resend.
181          */
182         int                     oi_flags;
183         /* Lock handle specific for every OSC lock. */
184         struct lustre_handle   *oi_lockh;
185         /* lsm data specific for every OSC. */
186         struct lov_stripe_md   *oi_md;
187         /* obdo data specific for every OSC, if needed at all. */
188         struct obdo            *oi_oa;
189         /* statfs data specific for every OSC, if needed at all. */
190         struct obd_statfs      *oi_osfs;
191         /* An update callback which is called to update some data on upper
192          * level. E.g. it is used for update lsm->lsm_oinfo at every recieved
193          * request in osc level for enqueue requests. It is also possible to
194          * update some caller data from LOV layer if needed. */
195         obd_enqueue_update_f    oi_cb_up;
196 };
197
198 /* compare all relevant fields. */
199 static inline int lov_stripe_md_cmp(struct lov_stripe_md *m1,
200                                     struct lov_stripe_md *m2)
201 {
202         int len = sizeof(m1->lsm_wire);
203
204         /*
205          * ->lsm_wire contains padding, but it should be zeroed out during
206          * allocation. If either lsm is LOV_MAGIC_V1 do not check that
207          * the pool is the same, due to downgrade/upgrade (b=20318).  This
208          * assumes that lw_pool_name is the last member in lsm_wire.
209          */
210         if (m1->lsm_magic == LOV_MAGIC_V1 || m2->lsm_magic == LOV_MAGIC_V1)
211                  len -= LOV_MAXPOOLNAME;
212         return memcmp(&m1->lsm_wire, &m2->lsm_wire, len);
213 }
214
215 void lov_stripe_lock(struct lov_stripe_md *md);
216 void lov_stripe_unlock(struct lov_stripe_md *md);
217
218 struct obd_type {
219         struct list_head typ_chain;
220         struct obd_ops *typ_ops;
221         cfs_proc_dir_entry_t *typ_procroot;
222         char *typ_name;
223         int  typ_refcnt;
224         spinlock_t obd_type_lock;
225 };
226
227 struct brw_page {
228         obd_off  off;
229         cfs_page_t *pg;
230         int count;
231         obd_flag flag;
232 };
233
234 enum async_flags {
235         ASYNC_READY = 0x1, /* ap_make_ready will not be called before this
236                               page is added to an rpc */
237         ASYNC_URGENT = 0x2, /* page must be put into an RPC before return */
238         ASYNC_COUNT_STABLE = 0x4, /* ap_refresh_count will not be called
239                                      to give the caller a chance to update
240                                      or cancel the size of the io */
241         ASYNC_GROUP_SYNC = 0x8,  /* ap_completion will not be called, instead
242                                     the page is accounted for in the
243                                     obd_io_group given to
244                                     obd_queue_group_io */
245         ASYNC_HP = 0x10,
246 };
247
248 struct obd_async_page_ops {
249         int  (*ap_make_ready)(void *data, int cmd);
250         int  (*ap_refresh_count)(void *data, int cmd);
251         void (*ap_fill_obdo)(void *data, int cmd, struct obdo *oa);
252         void (*ap_update_obdo)(void *data, int cmd, struct obdo *oa,
253                                obd_valid valid);
254         int  (*ap_completion)(void *data, int cmd, struct obdo *oa, int rc);
255 };
256
257 /* the `oig' is passed down from a caller of obd rw methods.  the callee
258  * records enough state such that the caller can sleep on the oig and
259  * be woken when all the callees have finished their work */
260 struct obd_io_group {
261         spinlock_t      oig_lock;
262         atomic_t        oig_refcount;
263         int             oig_pending;
264         int             oig_rc;
265         struct list_head oig_occ_list;
266         cfs_waitq_t     oig_waitq;
267 };
268
269 /* the oig callback context lets the callee of obd rw methods register
270  * for callbacks from the caller. */
271 struct oig_callback_context {
272         struct list_head occ_oig_item;
273         /* called when the caller has received a signal while sleeping.
274          * callees of this method are encouraged to abort their state
275          * in the oig.  This may be called multiple times. */
276         void (*occ_interrupted)(struct oig_callback_context *occ);
277         unsigned long interrupted:1;
278 };
279
280 /* Individual type definitions */
281
282 struct ost_server_data;
283
284 /* hold common fields for "target" device */
285 struct obd_device_target {
286         struct super_block       *obt_sb;
287         /** last_rcvd file */
288         struct file              *obt_rcvd_filp;
289         /** server data in last_rcvd file */
290         struct lr_server_data    *obt_lsd;
291         /** Lock protecting client bitmap */
292         spinlock_t                obt_client_bitmap_lock;
293         /** Bitmap of known clients */
294         unsigned long            *obt_client_bitmap;
295         /** Server last transaction number */
296         __u64                     obt_last_transno;
297         /** Lock protecting last transaction number */
298         spinlock_t                obt_translock;
299         /** Number of mounts */
300         __u64                     obt_mount_count;
301         atomic_t                  obt_quotachecking;
302         struct lustre_quota_ctxt  obt_qctxt;
303         lustre_quota_version_t    obt_qfmt;
304         __u32                     obt_stale_export_age;
305         spinlock_t                obt_trans_table_lock;
306         struct vfsmount          *obt_vfsmnt;
307         struct file              *obt_health_check_filp;
308 };
309
310 typedef void (*obd_pin_extent_cb)(void *data);
311 typedef int (*obd_page_removal_cb_t)(void *data, int discard);
312 typedef int (*obd_lock_cancel_cb)(struct ldlm_lock *,struct ldlm_lock_desc *,
313                                    void *, int);
314
315 #define FILTER_GROUP_LLOG 1
316 #define FILTER_GROUP_ECHO 2
317
318 struct filter_ext {
319         __u64                fe_start;
320         __u64                fe_end;
321 };
322
323 struct filter_obd {
324         /* NB this field MUST be first */
325         struct obd_device_target fo_obt;
326         const char          *fo_fstype;
327         cfs_dentry_t        *fo_dentry_O;
328         cfs_dentry_t       **fo_dentry_O_groups;
329         cfs_dentry_t       **fo_dentry_O_sub;
330         spinlock_t           fo_objidlock;      /* protect fo_lastobjid */
331
332         int                  fo_destroy_in_progress;
333         struct semaphore     fo_create_lock;
334
335         struct list_head     fo_export_list;
336         int                  fo_subdir_count;
337
338         obd_size             fo_tot_dirty;      /* protected by obd_osfs_lock */
339         obd_size             fo_tot_granted;    /* all values in bytes */
340         obd_size             fo_tot_pending;
341         int                  fo_tot_granted_clients;
342
343         obd_size             fo_readcache_max_filesize;
344         unsigned long        fo_read_cache:1,         /* read-only cache */
345                              fo_writethrough_cache:1, /* writetrhough cache */
346                              fo_syncjournal:1,      /* sync journal on writes */
347                              fo_raid_degraded:1;    /* RAID device degraded */
348
349         struct obd_import   *fo_mdc_imp;
350         struct obd_uuid      fo_mdc_uuid;
351         struct lustre_handle fo_mdc_conn;
352         struct file        **fo_last_objid_files;
353         __u64               *fo_last_objids; /* last created objid for groups,
354                                               * protected by fo_objidlock */
355
356         struct semaphore     fo_alloc_lock;
357
358         atomic_t             fo_r_in_flight;
359         atomic_t             fo_w_in_flight;
360
361         /*
362          * per-filter pool of kiobuf's allocated by filter_common_setup() and
363          * torn down by filter_cleanup(). Contains OST_NUM_THREADS elements of
364          * which ->fo_iobuf_count were allocated.
365          *
366          * This pool contains kiobuf used by
367          * filter_{prep,commit}rw_{read,write}() and is shared by all OST
368          * threads.
369          *
370          * Locking: none, each OST thread uses only one element, determined by
371          * its "ordinal number", ->t_id.
372          */
373         struct filter_iobuf    **fo_iobuf_pool;
374         int                      fo_iobuf_count;
375
376         struct brw_stats         fo_filter_stats;
377         struct lustre_quota_ctxt fo_quota_ctxt;
378         spinlock_t               fo_quotacheck_lock;
379         atomic_t                 fo_quotachecking;
380
381         int                      fo_fmd_max_num; /* per exp filter_mod_data */
382         int                      fo_fmd_max_age; /* jiffies to fmd expiry */
383         struct llog_commit_master *fo_lcm;
384 };
385
386 #define fo_translock            fo_obt.obt_translock
387 #define fo_rcvd_filp            fo_obt.obt_rcvd_filp
388 #define fo_fsd                  fo_obt.obt_lsd
389 #define fo_last_rcvd_slots      fo_obt.obt_client_bitmap
390 #define fo_mount_count          fo_obt.obt_mount_count
391 #define fo_vfsmnt               fo_obt.obt_vfsmnt
392
393 #define OSC_MAX_RIF_DEFAULT       8
394 #define OSC_MAX_RIF_MAX         256
395 #define OSC_MAX_DIRTY_DEFAULT  (OSC_MAX_RIF_DEFAULT * 4)
396 #define OSC_MAX_DIRTY_MB_MAX   2048     /* arbitrary, but < MAX_LONG bytes */
397 #define OSC_DEFAULT_RESENDS      10
398
399 #define MDC_MAX_RIF_DEFAULT       8
400 #define MDC_MAX_RIF_MAX         512
401
402 #define CLIENT_QUOTA_DEFAULT_RESENDS 10
403
404 struct mdc_rpc_lock;
405 struct obd_import;
406 struct lustre_cache;
407
408 struct timeout_item {
409         enum timeout_event ti_event;
410         cfs_time_t         ti_timeout;
411         timeout_cb_t       ti_cb;
412         void              *ti_cb_data;
413         struct list_head   ti_obd_list;
414         struct list_head   ti_chain;
415 };
416
417 struct client_obd {
418         struct rw_semaphore      cl_sem;
419         struct obd_uuid          cl_target_uuid;
420         struct obd_import       *cl_import; /* ptlrpc connection state */
421         int                      cl_conn_count;
422         /* max_mds_easize is purely a performance thing so we don't have to
423          * call obd_size_diskmd() all the time. */
424         unsigned                 cl_default_mds_easize;
425         unsigned                 cl_max_mds_easize;
426         unsigned                 cl_max_mds_cookiesize;
427
428         //struct llog_canceld_ctxt *cl_llcd; /* it's included by obd_llog_ctxt */
429         void                    *cl_llcd_offset;
430
431         /* the grant values are protected by loi_list_lock below */
432         long                     cl_dirty;         /* all _dirty_ in bytes */
433         long                     cl_dirty_max;     /* allowed w/o rpc */
434         long                     cl_avail_grant;   /* bytes of credit for ost */
435         long                     cl_lost_grant;    /* lost credits (trunc) */
436         struct list_head         cl_cache_waiters; /* waiting for cache/grant */
437         cfs_time_t               cl_next_shrink_grant;   /* jiffies */
438         struct list_head         cl_grant_shrink_list;  /* Timeout event list */
439         struct semaphore         cl_grant_sem;   /*grant shrink list semaphore*/
440         int                      cl_grant_shrink_interval; /* seconds */
441
442         /* keep track of objects that have lois that contain pages which
443          * have been queued for async brw.  this lock also protects the
444          * lists of osc_client_pages that hang off of the loi */
445         /*
446          * ->cl_loi_list_lock protects consistency of
447          * ->cl_loi_{ready,read,write}_list. ->ap_make_ready() and
448          * ->ap_completion() call-backs are executed under this lock. As we
449          * cannot guarantee that these call-backs never block on all platforms
450          * (as a matter of fact they do block on Mac OS X), type of
451          * ->cl_loi_list_lock is platform dependent: it's a spin-lock on Linux
452          * and blocking mutex on Mac OS X. (Alternative is to make this lock
453          * blocking everywhere, but we don't want to slow down fast-path of
454          * our main platform.)
455          *
456          * Exact type of ->cl_loi_list_lock is defined in arch/obd.h together
457          * with client_obd_list_{un,}lock() and
458          * client_obd_list_lock_{init,done}() functions.
459          */
460         client_obd_lock_t        cl_loi_list_lock;
461         struct list_head         cl_loi_ready_list;
462         struct list_head         cl_loi_hp_ready_list;
463         struct list_head         cl_loi_write_list;
464         struct list_head         cl_loi_read_list;
465         int                      cl_r_in_flight;
466         int                      cl_w_in_flight;
467         /* just a sum of the loi/lop pending numbers to be exported by /proc */
468         int                      cl_pending_w_pages;
469         int                      cl_pending_r_pages;
470         int                      cl_max_pages_per_rpc;
471         int                      cl_max_rpcs_in_flight;
472         struct obd_histogram     cl_read_rpc_hist;
473         struct obd_histogram     cl_write_rpc_hist;
474         struct obd_histogram     cl_read_page_hist;
475         struct obd_histogram     cl_write_page_hist;
476         struct obd_histogram     cl_read_offset_hist;
477         struct obd_histogram     cl_write_offset_hist;
478
479         /* number of in flight destroy rpcs is limited to max_rpcs_in_flight */
480         atomic_t                 cl_destroy_in_flight;
481         cfs_waitq_t              cl_destroy_waitq;
482
483         struct mdc_rpc_lock     *cl_rpc_lock;
484         struct mdc_rpc_lock     *cl_setattr_lock;
485         struct mdc_rpc_lock     *cl_close_lock;
486         struct osc_creator       cl_oscc;
487
488         /* mgc datastruct */
489         struct semaphore         cl_mgc_sem;
490         struct vfsmount         *cl_mgc_vfsmnt;
491         struct dentry           *cl_mgc_configs_dir;
492         atomic_t                 cl_mgc_refcount;
493         struct obd_export       *cl_mgc_mgsexp;
494
495         /* checksumming for data sent over the network */
496         unsigned int             cl_checksum:1; /* 0 = disabled, 1 = enabled */
497         /* supported checksum types that are worked out at connect time */
498         __u32                    cl_supp_cksum_types;
499         /* checksum algorithm to be used */
500         cksum_type_t             cl_cksum_type;
501
502         /* also protected by the poorly named _loi_list_lock lock above */
503         struct osc_async_rc      cl_ar;
504
505         /* used by quotacheck */
506         int                      cl_qchk_stat; /* quotacheck stat of the peer */
507
508         /* sequence manager */
509         struct lu_client_seq    *cl_seq;
510
511         atomic_t                 cl_resends; /* resend count */
512         atomic_t                 cl_quota_resends; /* quota related resend count */
513
514         /* Cache of triples */
515         struct lustre_cache     *cl_cache;
516         obd_lock_cancel_cb       cl_ext_lock_cancel_cb;
517 };
518 #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
519
520 #define CL_NOT_QUOTACHECKED 1   /* client->cl_qchk_stat init value */
521
522 struct mgs_obd {
523         struct ptlrpc_service           *mgs_service;
524         struct vfsmount                 *mgs_vfsmnt;
525         struct super_block              *mgs_sb;
526         struct dentry                   *mgs_configs_dir;
527         struct dentry                   *mgs_fid_de;
528         struct list_head                 mgs_fs_db_list;
529         struct semaphore                 mgs_sem;
530         cfs_proc_dir_entry_t            *mgs_proc_live;
531 };
532
533 struct mds_obd {
534         /* NB this field MUST be first */
535         struct obd_device_target         mds_obt;
536         struct ptlrpc_service           *mds_service;
537         struct ptlrpc_service           *mds_setattr_service;
538         struct ptlrpc_service           *mds_readpage_service;
539         cfs_dentry_t                    *mds_fid_de;
540         int                              mds_max_mdsize;
541         int                              mds_max_cookiesize;
542         __u64                            mds_io_epoch;
543         unsigned long                    mds_atime_diff;
544         struct semaphore                 mds_epoch_sem;
545         struct ll_fid                    mds_rootfid;
546         cfs_dentry_t                    *mds_pending_dir;
547         cfs_dentry_t                    *mds_logs_dir;
548         cfs_dentry_t                    *mds_objects_dir;
549         struct llog_handle              *mds_cfg_llh;
550 //        struct llog_handle              *mds_catalog;
551         struct obd_device               *mds_osc_obd; /* XXX lov_obd */
552         struct obd_uuid                  mds_lov_uuid;
553         char                            *mds_profile;
554         struct obd_export               *mds_osc_exp; /* XXX lov_exp */
555         struct lov_desc                  mds_lov_desc;
556
557         /* mark pages dirty for write. */
558         bitmap_t                         *mds_lov_page_dirty;
559         /* array for store pages with obd_id */
560         void                            **mds_lov_page_array;
561         /* file for store objid */
562         struct file                     *mds_lov_objid_filp;
563         __u32                            mds_lov_objid_count;
564         __u32                            mds_lov_objid_max_index;
565         __u32                            mds_lov_objid_lastpage;
566         __u32                            mds_lov_objid_lastidx;
567
568         struct upcall_cache             *mds_group_hash;
569
570         struct lustre_quota_info         mds_quota_info;
571         struct semaphore                 mds_qonoff_sem;
572         struct semaphore                 mds_health_sem;
573         unsigned long                    mds_fl_user_xattr:1,
574                                          mds_fl_acl:1,
575                                          mds_fl_cfglog:1,
576                                          mds_fl_synced:1,
577                                          mds_fl_target:1, /* mds have one or
578                                                            * more targets */
579                                          mds_evict_ost_nids:1;
580
581         uid_t                            mds_squash_uid;
582         gid_t                            mds_squash_gid;
583         lnet_nid_t                       mds_nosquash_nid;
584         /* do we need permission sync */
585         unsigned int                     mds_sync_permission;
586 };
587
588 #define mds_transno_lock         mds_obt.obt_translock
589 #define mds_rcvd_filp            mds_obt.obt_rcvd_filp
590 #define mds_server_data          mds_obt.obt_lsd
591 #define mds_client_bitmap        mds_obt.obt_client_bitmap
592 #define mds_mount_count          mds_obt.obt_mount_count
593 #define mds_last_transno         mds_obt.obt_last_transno
594 #define mds_vfsmnt               mds_obt.obt_vfsmnt
595
596 /* lov objid */
597 #define mds_max_ost_index  (0xFFFF)
598 #define MDS_LOV_ALLOC_SIZE (CFS_PAGE_SIZE)
599
600 #define OBJID_PER_PAGE() (MDS_LOV_ALLOC_SIZE / sizeof(obd_id))
601
602 #define MDS_LOV_OBJID_PAGES_COUNT (mds_max_ost_index/OBJID_PER_PAGE())
603
604 extern int mds_lov_init_objids(struct obd_device *obd);
605 extern void mds_lov_destroy_objids(struct obd_device *obd);
606
607 struct obd_id_info {
608         __u32   idx;
609         obd_id  *data;
610 };
611
612 /* */
613
614 struct echo_obd {
615         struct obdo          eo_oa;
616         spinlock_t           eo_lock;
617         __u64                eo_lastino;
618         struct lustre_handle eo_nl_lock;
619         atomic_t             eo_prep;
620 };
621
622 struct ost_obd {
623         struct ptlrpc_service *ost_service;
624         struct ptlrpc_service *ost_create_service;
625         struct ptlrpc_service *ost_io_service;
626         struct semaphore       ost_health_sem;
627         int                    ost_sync_on_lock_cancel;
628 };
629
630 struct echo_client_obd {
631         struct obd_export   *ec_exp;   /* the local connection to osc/lov */
632         spinlock_t           ec_lock;
633         struct list_head     ec_objects;
634         int                  ec_nstripes;
635         __u64                ec_unique;
636 };
637
638 struct lov_qos_oss {
639         struct obd_uuid     lqo_uuid;       /* ptlrpc's c_remote_uuid */
640         struct list_head    lqo_oss_list;   /* link to lov_qos */
641         __u64               lqo_bavail;     /* total bytes avail on OSS */
642         __u64               lqo_penalty;    /* current penalty */
643         __u64               lqo_penalty_per_obj; /* penalty decrease every obj*/
644         time_t              lqo_used;       /* last used time, seconds */
645         __u32               lqo_ost_count;  /* number of osts on this oss */
646 };
647
648 struct ltd_qos {
649         struct lov_qos_oss *ltq_oss;         /* oss info */
650         __u64               ltq_penalty;     /* current penalty */
651         __u64               ltq_penalty_per_obj; /* penalty decrease every obj*/
652         __u64               ltq_weight;      /* net weighting */
653         time_t              ltq_used;        /* last used time, seconds */
654         unsigned int        ltq_usable:1;    /* usable for striping */
655 };
656
657 /* Generic subset of OSTs */
658 struct ost_pool {
659         __u32              *op_array;        /* array of index of
660                                                 lov_obd->lov_tgts */
661         unsigned int        op_count;        /* number of OSTs in the array */
662         unsigned int        op_size;         /* allocated size of lp_array */
663         struct rw_semaphore op_rw_sem;       /* to protect ost_pool use */
664 };
665
666 /* Round-robin allocator data */
667 struct lov_qos_rr {
668         __u32               lqr_start_idx;   /* start index of new inode */
669         __u32               lqr_offset_idx;  /* aliasing for start_idx  */
670         int                 lqr_start_count; /* reseed counter */
671         struct ost_pool     lqr_pool;        /* round-robin optimized list */
672         unsigned long       lqr_dirty:1;     /* recalc round-robin list */
673 };
674
675 struct lov_statfs_data {
676         struct obd_info   lsd_oi;
677         struct obd_statfs lsd_statfs;
678 };
679 /* Stripe placement optimization */
680 struct lov_qos {
681         struct list_head    lq_oss_list;    /* list of OSSs that targets use */
682         struct rw_semaphore lq_rw_sem;
683         __u32               lq_active_oss_count;
684         unsigned int        lq_prio_free;   /* priority for free space */
685         unsigned int        lq_threshold_rr;/* priority for rr */
686         struct lov_qos_rr   lq_rr;          /* round robin qos data */
687         unsigned long       lq_dirty:1,     /* recalc qos data */
688                             lq_same_space:1,/* the ost's all have approx.
689                                                the same space avail */
690                             lq_reset:1,     /* zero current penalties */
691                             lq_statfs_in_progress:1; /* statfs op in progress */
692         /* qos statfs data */
693         struct lov_statfs_data *lq_statfs_data;
694         cfs_waitq_t         lq_statfs_waitq; /* waitqueue to notify statfs
695                                               * requests completion */
696 };
697
698 struct lov_tgt_desc {
699         struct list_head    ltd_kill;
700         struct obd_uuid     ltd_uuid;
701         struct obd_device  *ltd_obd;
702         struct obd_export  *ltd_exp;
703         struct ltd_qos      ltd_qos;     /* qos info per target */
704         __u32               ltd_gen;
705         __u32               ltd_index;   /* index in lov_obd->tgts */
706         unsigned long       ltd_active:1,/* is this target up for requests */
707                             ltd_activate:1,/* should this target be activated */
708                             ltd_reap:1;  /* should this target be deleted */
709 };
710
711 /* Pool metadata */
712 #define pool_tgt_size(_p)   _p->pool_obds.op_size
713 #define pool_tgt_count(_p)  _p->pool_obds.op_count
714 #define pool_tgt_array(_p)  _p->pool_obds.op_array
715 #define pool_tgt_rw_sem(_p) _p->pool_obds.op_rw_sem
716 #define pool_tgt(_p, _i)    _p->pool_lov->lov_tgts[_p->pool_obds.op_array[_i]]
717
718 struct pool_desc {
719         char                  pool_name[LOV_MAXPOOLNAME + 1]; /* name of pool */
720         struct ost_pool       pool_obds;              /* pool members */
721         atomic_t              pool_refcount;          /* pool ref. counter */
722         struct lov_qos_rr     pool_rr;                /* round robin qos */
723         struct hlist_node     pool_hash;              /* access by poolname */
724         struct list_head      pool_list;              /* serial access */
725         cfs_proc_dir_entry_t *pool_proc_entry;        /* file in /proc */
726         struct lov_obd       *pool_lov;               /* lov obd to which this
727                                                          pool belong */
728 };
729
730 struct lov_obd {
731         struct lov_desc         desc;
732         struct lov_tgt_desc   **lov_tgts;              /* sparse array */
733         struct ost_pool         lov_packed;            /* all OSTs in a packed
734                                                           array */
735         struct semaphore        lov_lock;
736         struct obd_connect_data lov_ocd;
737         struct lov_qos          lov_qos;               /* qos info per lov */
738         atomic_t                lov_refcount;
739         __u32                   lov_tgt_count;         /* how many OBD's */
740         __u32                   lov_active_tgt_count;  /* how many active */
741         __u32                   lov_death_row;/* tgts scheduled to be deleted */
742         __u32                   lov_tgt_size;   /* size of tgts array */
743         int                     lov_connects;
744         obd_page_removal_cb_t   lov_page_removal_cb;
745         obd_pin_extent_cb       lov_page_pin_cb;
746         obd_lock_cancel_cb      lov_lock_cancel_cb;
747         int                     lov_pool_count;
748         lustre_hash_t          *lov_pools_hash_body; /* used for key access */
749         struct list_head        lov_pool_list; /* used for sequential access */
750         cfs_proc_dir_entry_t   *lov_pool_proc_entry;
751 };
752
753 struct niobuf_local {
754         __u64 offset;
755         __u32 len;
756         __u32 flags;
757         cfs_page_t    *page;
758         cfs_dentry_t  *dentry;
759         int lnb_grant_used;
760         int rc;
761 };
762
763 /* obd device type names */
764  /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */
765 #define LUSTRE_MDS_NAME         "mds"
766 #define LUSTRE_MDT_NAME         "mdt"
767 #define LUSTRE_MDC_NAME         "mdc"
768 #define LUSTRE_OSS_NAME         "ost" /*FIXME change name to oss*/
769 #define LUSTRE_OST_NAME         "obdfilter" /* FIXME change name to ost*/
770 #define LUSTRE_OSC_NAME         "osc"
771 #define LUSTRE_LOV_NAME         "lov"
772 #define LUSTRE_MGS_NAME         "mgs"
773 #define LUSTRE_MGC_NAME         "mgc"
774
775 #define LUSTRE_CACHEOBD_NAME    "cobd"
776 #define LUSTRE_ECHO_NAME        "obdecho"
777 #define LUSTRE_ECHO_CLIENT_NAME "echo_client"
778
779 /* Constant obd names (post-rename) */
780 #define LUSTRE_MDS_OBDNAME "MDS"
781 #define LUSTRE_OSS_OBDNAME "OSS"
782 #define LUSTRE_MGS_OBDNAME "MGS"
783 #define LUSTRE_MGC_OBDNAME "MGC"
784
785 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
786 #define N_LOCAL_TEMP_PAGE 0x10000000
787
788 struct obd_trans_info {
789         __u64                    oti_transno;
790         __u64                    oti_xid;
791         /* Only used on the server side for tracking acks. */
792         struct oti_req_ack_lock {
793                 struct lustre_handle lock;
794                 __u32                mode;
795         }                        oti_ack_locks[4];
796         void                    *oti_handle;
797         struct llog_cookie       oti_onecookie;
798         struct llog_cookie      *oti_logcookies;
799         int                      oti_numcookies;
800
801         /* initial thread handling transaction */
802         struct ptlrpc_thread *   oti_thread;
803         __u32                    oti_conn_cnt;
804         /* VBR: versions */
805         __u64                    oti_pre_version;
806
807         struct obd_uuid         *oti_ost_uuid;
808 };
809
810 static inline void oti_init(struct obd_trans_info *oti,
811                             struct ptlrpc_request *req)
812 {
813         if (oti == NULL)
814                 return;
815         memset(oti, 0, sizeof(*oti));
816
817         if (req == NULL)
818                 return;
819
820         oti->oti_xid = req->rq_xid;
821         /* VBR: take versions from request */
822         if (req->rq_reqmsg != NULL &&
823             lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
824                 __u64 *pre_version = lustre_msg_get_versions(req->rq_reqmsg);
825                 /* b1.6 interoperability check. pre_versions may be NULL */
826                 oti->oti_pre_version = pre_version ? pre_version[0] : 0;
827                 oti->oti_transno = lustre_msg_get_transno(req->rq_reqmsg);
828         }
829
830         /* called from mds_create_objects */
831         if (req->rq_repmsg != NULL)
832                 oti->oti_transno = lustre_msg_get_transno(req->rq_repmsg);
833         oti->oti_thread = req->rq_svc_thread;
834         if (req->rq_reqmsg != NULL)
835                 oti->oti_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg);
836 }
837
838 static inline void oti_alloc_cookies(struct obd_trans_info *oti,int num_cookies)
839 {
840         if (!oti)
841                 return;
842
843         if (num_cookies == 1)
844                 oti->oti_logcookies = &oti->oti_onecookie;
845         else
846                 OBD_ALLOC(oti->oti_logcookies,
847                           num_cookies * sizeof(oti->oti_onecookie));
848
849         oti->oti_numcookies = num_cookies;
850 }
851
852 static inline void oti_free_cookies(struct obd_trans_info *oti)
853 {
854         if (!oti || !oti->oti_logcookies)
855                 return;
856
857         if (oti->oti_logcookies == &oti->oti_onecookie)
858                 LASSERT(oti->oti_numcookies == 1);
859         else
860                 OBD_FREE(oti->oti_logcookies,
861                          oti->oti_numcookies * sizeof(oti->oti_onecookie));
862         oti->oti_logcookies = NULL;
863         oti->oti_numcookies = 0;
864 }
865
866 /* llog contexts */
867 enum llog_ctxt_id {
868         LLOG_CONFIG_ORIG_CTXT  =  0,
869         LLOG_CONFIG_REPL_CTXT  =  1,
870         LLOG_MDS_OST_ORIG_CTXT =  2,
871         LLOG_MDS_OST_REPL_CTXT =  3,
872         LLOG_SIZE_ORIG_CTXT    =  4,
873         LLOG_SIZE_REPL_CTXT    =  5,
874         LLOG_MD_ORIG_CTXT      =  6,
875         LLOG_MD_REPL_CTXT      =  7,
876         LLOG_RD1_ORIG_CTXT     =  8,
877         LLOG_RD1_REPL_CTXT     =  9,
878         LLOG_TEST_ORIG_CTXT    = 10,
879         LLOG_TEST_REPL_CTXT    = 11,
880         LLOG_LOVEA_ORIG_CTXT   = 12,
881         LLOG_LOVEA_REPL_CTXT   = 13,
882         LLOG_MAX_CTXTS
883 };
884
885 /*
886  * Events signalled through obd_notify() upcall-chain.
887  */
888 enum obd_notify_event {
889         /* device target is created */
890         OBD_NOTIFY_CREATE,
891         /* DEVICE connect start */
892         OBD_NOTIFY_CONNECT,
893         /* Device activated */
894         OBD_NOTIFY_ACTIVE,
895         /* Device deactivated */
896         OBD_NOTIFY_INACTIVE,
897         /* Connect data for import were changed */
898         OBD_NOTIFY_OCD,
899         /* Sync request */
900         OBD_NOTIFY_SYNC_NONBLOCK,
901         OBD_NOTIFY_SYNC,
902         /* Configuration event */
903         OBD_NOTIFY_CONFIG
904 };
905
906 #define CONFIG_LOG      0x1  /* finished processing config log */
907 #define CONFIG_SYNC     0x2  /* mdt synced 1 ost */
908 #define CONFIG_TARGET   0x4  /* one target is added */
909
910 /*
911  * Data structure used to pass obd_notify()-event to non-obd listeners (llite
912  * and liblustre being main examples).
913  */
914 struct obd_notify_upcall {
915         int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
916                           enum obd_notify_event ev, void *owner);
917         /* Opaque datum supplied by upper layer listener */
918         void *onu_owner;
919 };
920
921 /* corresponds to one of the obd's */
922 #define MAX_OBD_NAME 128
923 #define OBD_DEVICE_MAGIC        0XAB5CD6EF
924 #define OBD_DEV_BY_DEVNAME      0xffffd0de
925 struct obd_device {
926         struct obd_type        *obd_type;
927         __u32                   obd_magic;
928
929         /* common and UUID name of this device */
930         char                    obd_name[MAX_OBD_NAME];
931         struct obd_uuid         obd_uuid;
932
933         int                     obd_minor;
934         unsigned long obd_attached:1,      /* finished attach */
935                       obd_set_up:1,        /* finished setup */
936                       obd_recovering:1,    /* there are recoverable clients */
937                       obd_abort_recovery:1,/* recovery expired */
938                       obd_version_recov:1, /* obd uses version checking */
939                       obd_replayable:1,    /* recovery is enabled; inform clients */
940                       obd_no_transno:1,    /* no committed-transno notification */
941                       obd_no_recov:1,      /* fail instead of retry messages */
942                       obd_stopping:1,      /* started cleanup */
943                       obd_starting:1,      /* started setup */
944                       obd_force:1,         /* cleanup with > 0 obd refcount */
945                       obd_fail:1,          /* cleanup with failover */
946                       obd_async_recov:1,   /* allow asyncronous orphan cleanup */
947                       obd_no_conn:1,       /* deny new connections */
948                       obd_inactive:1;      /* device active/inactive
949                                             * (for /proc/status only!!) */
950         /* uuid-export hash body */
951         struct lustre_hash     *obd_uuid_hash;
952         /* nid-export hash body */
953         struct lustre_hash     *obd_nid_hash;
954         /* nid stats body */
955         struct lustre_hash     *obd_nid_stats_hash;
956         struct list_head        obd_nid_stats;
957         atomic_t                obd_refcount;
958         cfs_waitq_t             obd_refcount_waitq;
959         struct list_head        obd_exports;
960         struct list_head        obd_delayed_exports;
961         int                     obd_num_exports;
962         spinlock_t              obd_nid_lock;
963         struct ldlm_namespace  *obd_namespace;
964         struct ptlrpc_client    obd_ldlm_client; /* XXX OST/MDS only */
965         /* a spinlock is OK for what we do now, may need a semaphore later */
966         spinlock_t              obd_dev_lock;
967         struct semaphore        obd_dev_sem;
968         __u64                   obd_last_committed;
969         struct fsfilt_operations *obd_fsops;
970         spinlock_t              obd_osfs_lock;
971         struct obd_statfs       obd_osfs;       /* locked by obd_osfs_lock */
972         __u64                   obd_osfs_age;
973         struct lvfs_run_ctxt    obd_lvfs_ctxt;
974
975         struct llog_ctxt        *obd_llog_ctxt[LLOG_MAX_CTXTS];
976         struct semaphore        obd_llog_cat_process;
977         cfs_waitq_t             obd_llog_waitq;
978
979         struct obd_device       *obd_observer;
980         struct obd_notify_upcall obd_upcall;
981         struct obd_export       *obd_self_export;
982         /* list of exports in LRU order, for ping evictor, with obd_dev_lock */
983         struct list_head        obd_exports_timed;
984         time_t                  obd_eviction_timer; /* for ping evictor */
985
986         /* XXX encapsulate all this recovery data into one struct */
987         svc_handler_t                    obd_recovery_handler;
988         int                              obd_max_recoverable_clients;
989         int                              obd_connected_clients;
990         int                              obd_recoverable_clients;
991         int                              obd_stale_clients;
992         int                              obd_delayed_clients;
993         spinlock_t                       obd_processing_task_lock; /* BH lock (timer) */
994         pid_t                            obd_processing_task;
995         /* thread to handle recovery queue */
996         struct ptlrpc_thread            *obd_recovery_thread;
997         __u64                            obd_next_recovery_transno;
998         int                              obd_replayed_requests;
999         int                              obd_requests_queued_for_recovery;
1000         cfs_waitq_t                      obd_next_transno_waitq;
1001         cfs_timer_t                      obd_recovery_timer;
1002         struct list_head                 obd_recovery_queue;
1003         struct list_head                 obd_delayed_reply_queue;
1004         time_t                           obd_recovery_start; /* seconds */
1005         time_t                           obd_recovery_end; /* seconds, for lprocfs_status */
1006         time_t                           obd_recovery_time_hard;
1007         int                              obd_recovery_timeout;
1008
1009         union {
1010                 struct obd_device_target obt;
1011                 struct filter_obd filter;
1012                 struct mds_obd mds;
1013                 struct client_obd cli;
1014                 struct ost_obd ost;
1015                 struct echo_client_obd echo_client;
1016                 struct echo_obd echo;
1017                 struct lov_obd lov;
1018                 struct mgs_obd mgs;
1019         } u;
1020         /* Fields used by LProcFS */
1021         cfs_proc_dir_entry_t  *obd_proc_entry;
1022         cfs_proc_dir_entry_t  *obd_proc_exports_entry;
1023         cfs_proc_dir_entry_t  *obd_svc_procroot;
1024         struct lprocfs_stats  *obd_stats;
1025         struct lprocfs_stats  *obd_svc_stats;
1026         unsigned int           obd_cntr_base;
1027         atomic_t               obd_evict_inprogress;
1028         cfs_waitq_t            obd_evict_inprogress_waitq;
1029
1030         /* Ldlm pool part. Save last calculated SLV and Limit. */
1031         rwlock_t               obd_pool_lock;
1032         int                    obd_pool_limit;
1033         __u64                  obd_pool_slv;
1034 };
1035
1036 #define OBD_LLOG_FL_SENDNOW     0x0001
1037
1038 enum obd_cleanup_stage {
1039 /* Special case hack for MDS LOVs */
1040         OBD_CLEANUP_EARLY,
1041 /* Precleanup stage 1, we must make sure all exports (other than the
1042    self-export) get destroyed. */
1043         OBD_CLEANUP_EXPORTS,
1044 /* Precleanup stage 2,  do other type-specific cleanup requiring the
1045    self-export. */
1046         OBD_CLEANUP_SELF_EXP,
1047 /* FIXME we should eliminate the "precleanup" function and make them stages
1048    of the "cleanup" function. */
1049         OBD_CLEANUP_OBD,
1050 };
1051
1052 /* get/set_info keys */
1053 #define KEY_MDS_CONN            "mds_conn"
1054 #define KEY_NEXT_ID             "next_id"
1055 #define KEY_LOVDESC             "lovdesc"
1056 #define KEY_INIT_RECOV          "initial_recov"
1057 #define KEY_INIT_RECOV_BACKUP   "init_recov_bk"
1058 #define KEY_LAST_ID             "last_id"
1059 #define KEY_LOCK_TO_STRIPE      "lock_to_stripe"
1060 #define KEY_CHECKSUM            "checksum"
1061 #define KEY_READONLY            "read-only"
1062 #define KEY_READONLY_166COMPAT  "readonly"
1063 #define KEY_UNLINKED            "unlinked"
1064 #define KEY_EVICT_BY_NID        "evict_by_nid"
1065 #define KEY_REGISTER_TARGET     "register_target"
1066 #define KEY_SET_FS              "set_fs"
1067 #define KEY_CLEAR_FS            "clear_fs"
1068 #define KEY_SET_INFO            "set_info"
1069 #define KEY_BLOCKSIZE           "blocksize"
1070 #define KEY_BLOCKSIZE_BITS      "blocksize_bits"
1071 #define KEY_MAX_EASIZE          "max_ea_size"
1072 #define KEY_FIEMAP              "fiemap"
1073 /* XXX unused */
1074 #define KEY_ASYNC               "async"
1075 #define KEY_CAPA_KEY            "capa_key"
1076 #define KEY_GRANT_SHRINK        "grant_shrink"
1077 #define KEY_OFF_RPCSIZE         "off_rpcsize"
1078
1079 struct obd_ops {
1080         struct module *o_owner;
1081         int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
1082                            void *karg, void *uarg);
1083         int (*o_get_info)(struct obd_export *, __u32 keylen, void *key,
1084                           __u32 *vallen, void *val, struct lov_stripe_md *lsm);
1085         int (*o_set_info_async)(struct obd_export *, __u32 keylen, void *key,
1086                                 __u32 vallen, void *val,
1087                                 struct ptlrpc_request_set *set);
1088         int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
1089         int (*o_detach)(struct obd_device *dev);
1090         int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
1091         int (*o_precleanup)(struct obd_device *dev,
1092                             enum obd_cleanup_stage cleanup_stage);
1093         int (*o_cleanup)(struct obd_device *dev);
1094         int (*o_process_config)(struct obd_device *dev, obd_count len,
1095                                 void *data);
1096         int (*o_postrecov)(struct obd_device *dev);
1097         int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
1098                           int priority);
1099         int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
1100         /* connect to the target device with given connection
1101          * data. @ocd->ocd_connect_flags is modified to reflect flags actually
1102          * granted by the target, which are guaranteed to be a subset of flags
1103          * asked for. If @ocd == NULL, use default parameters. */
1104         int (*o_connect)(struct lustre_handle *conn, struct obd_device *src,
1105                          struct obd_uuid *cluuid, struct obd_connect_data *ocd,
1106                          void *localdata);
1107         int (*o_reconnect)(struct obd_export *exp, struct obd_device *src,
1108                            struct obd_uuid *cluuid,
1109                            struct obd_connect_data *ocd,
1110                            void *localdata);
1111         int (*o_disconnect)(struct obd_export *exp);
1112
1113         /* Initialize/finalize fids infrastructure. */
1114         int (*o_fid_init)(struct obd_export *exp);
1115         int (*o_fid_fini)(struct obd_export *exp);
1116
1117         int (*o_statfs)(struct obd_device *obd, struct obd_statfs *osfs,
1118                         __u64 max_age, __u32 flags);
1119         int (*o_statfs_async)(struct obd_device *obd, struct obd_info *oinfo,
1120                               __u64 max_age, struct ptlrpc_request_set *set);
1121         int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
1122                         struct lov_stripe_md *mem_src);
1123         int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
1124                           struct lov_mds_md *disk_src, int disk_len);
1125         int (*o_checkmd)(struct obd_export *exp, struct obd_export *md_exp,
1126                          struct lov_stripe_md *mem_tgt);
1127         int (*o_preallocate)(struct lustre_handle *, obd_count *req,
1128                              obd_id *ids);
1129         int (*o_precreate)(struct obd_export *exp);
1130         int (*o_create)(struct obd_export *exp,  struct obdo *oa,
1131                         struct lov_stripe_md **ea, struct obd_trans_info *oti);
1132         int (*o_create_async)(struct obd_export *exp,  struct obd_info *oinfo,
1133                               struct lov_stripe_md **ea,
1134                               struct obd_trans_info *oti);
1135         int (*o_destroy)(struct obd_export *exp, struct obdo *oa,
1136                          struct lov_stripe_md *ea, struct obd_trans_info *oti,
1137                          struct obd_export *md_exp);
1138         int (*o_setattr)(struct obd_export *exp, struct obd_info *oinfo,
1139                          struct obd_trans_info *oti);
1140         int (*o_setattr_async)(struct obd_export *exp, struct obd_info *oinfo,
1141                                struct obd_trans_info *oti,
1142                                struct ptlrpc_request_set *rqset);
1143         int (*o_getattr)(struct obd_export *exp, struct obd_info *oinfo);
1144         int (*o_getattr_async)(struct obd_export *exp, struct obd_info *oinfo,
1145                                struct ptlrpc_request_set *set);
1146         int (*o_brw)(int rw, struct obd_export *exp, struct obd_info *oinfo,
1147                      obd_count oa_bufs, struct brw_page *pgarr,
1148                      struct obd_trans_info *oti);
1149         int (*o_brw_async)(int rw, struct obd_export *exp,
1150                            struct obd_info *oinfo, obd_count oa_bufs,
1151                            struct brw_page *pgarr, struct obd_trans_info *oti,
1152                            struct ptlrpc_request_set *, int pshift);
1153         int (*o_prep_async_page)(struct obd_export *exp,
1154                                  struct lov_stripe_md *lsm,
1155                                  struct lov_oinfo *loi,
1156                                  cfs_page_t *page, obd_off offset,
1157                                  struct obd_async_page_ops *ops, void *data,
1158                                  void **res, int flags,
1159                                  struct lustre_handle *lockh);
1160         int (*o_get_lock)(struct obd_export *exp, struct lov_stripe_md *lsm,
1161                           void **res, int rw, obd_off start, obd_off end,
1162                           struct lustre_handle *lockh, int flags);
1163         int (*o_queue_async_io)(struct obd_export *exp,
1164                                 struct lov_stripe_md *lsm,
1165                                 struct lov_oinfo *loi, void *cookie,
1166                                 int cmd, obd_off off, int count,
1167                                 obd_flag brw_flags, obd_flag async_flags);
1168         int (*o_queue_group_io)(struct obd_export *exp,
1169                                 struct lov_stripe_md *lsm,
1170                                 struct lov_oinfo *loi,
1171                                 struct obd_io_group *oig,
1172                                 void *cookie, int cmd, obd_off off, int count,
1173                                 obd_flag brw_flags, obd_flag async_flags);
1174         int (*o_trigger_group_io)(struct obd_export *exp,
1175                                   struct lov_stripe_md *lsm,
1176                                   struct lov_oinfo *loi,
1177                                   struct obd_io_group *oig);
1178         int (*o_set_async_flags)(struct obd_export *exp,
1179                                 struct lov_stripe_md *lsm,
1180                                 struct lov_oinfo *loi, void *cookie,
1181                                 obd_flag async_flags);
1182         int (*o_teardown_async_page)(struct obd_export *exp,
1183                                      struct lov_stripe_md *lsm,
1184                                      struct lov_oinfo *loi, void *cookie);
1185         int (*o_merge_lvb)(struct obd_export *exp, struct lov_stripe_md *lsm,
1186                            struct ost_lvb *lvb, int kms_only);
1187         int (*o_update_lvb)(struct obd_export *exp, struct lov_stripe_md *lsm,
1188                             struct ost_lvb *lvb, obd_flag valid);
1189         int (*o_adjust_kms)(struct obd_export *exp, struct lov_stripe_md *lsm,
1190                             obd_off size, int shrink);
1191         int (*o_punch)(struct obd_export *exp, struct obd_info *oinfo,
1192                        struct obd_trans_info *oti,
1193                        struct ptlrpc_request_set *rqset);
1194         int (*o_sync)(struct obd_export *exp, struct obd_info *oinfo,
1195                       obd_size start, obd_size end,
1196                       struct ptlrpc_request_set *rqset);
1197         int (*o_migrate)(struct lustre_handle *conn, struct lov_stripe_md *dst,
1198                          struct lov_stripe_md *src, obd_size start,
1199                          obd_size end, struct obd_trans_info *oti);
1200         int (*o_copy)(struct lustre_handle *dstconn, struct lov_stripe_md *dst,
1201                       struct lustre_handle *srconn, struct lov_stripe_md *src,
1202                       obd_size start, obd_size end, struct obd_trans_info *);
1203         int (*o_iterate)(struct lustre_handle *conn,
1204                          int (*)(obd_id, obd_gr, void *),
1205                          obd_id *startid, obd_gr group, void *data);
1206         int (*o_preprw)(int cmd, struct obd_export *exp, struct obdo *oa,
1207                         int objcount, struct obd_ioobj *obj,
1208                         struct niobuf_remote *remote, int *nr_pages,
1209                         struct niobuf_local *local,
1210                         struct obd_trans_info *oti);
1211         int (*o_commitrw)(int cmd, struct obd_export *exp, struct obdo *oa,
1212                           int objcount, struct obd_ioobj *obj,
1213                           struct niobuf_remote *remote, int pages,
1214                           struct niobuf_local *local,
1215                           struct obd_trans_info *oti, int rc);
1216         int (*o_enqueue)(struct obd_export *, struct obd_info *oinfo,
1217                          struct ldlm_enqueue_info *einfo,
1218                          struct ptlrpc_request_set *rqset);
1219         int (*o_match)(struct obd_export *, struct lov_stripe_md *, __u32 type,
1220                        ldlm_policy_data_t *, __u32 mode, int *flags, void *data,
1221                        struct lustre_handle *lockh, int *n_matches);
1222         int (*o_change_cbdata)(struct obd_export *, struct lov_stripe_md *,
1223                                ldlm_iterator_t it, void *data);
1224         int (*o_cancel)(struct obd_export *, struct lov_stripe_md *md,
1225                         __u32 mode, struct lustre_handle *, int flags,
1226                         obd_off end);
1227         int (*o_cancel_unused)(struct obd_export *, struct lov_stripe_md *,
1228                                int flags, void *opaque);
1229         int (*o_join_lru)(struct obd_export *, struct lov_stripe_md *,
1230                          int join);
1231         int (*o_init_export)(struct obd_export *exp);
1232         int (*o_destroy_export)(struct obd_export *exp);
1233         int (*o_extent_calc)(struct obd_export *, struct lov_stripe_md *,
1234                              int cmd, obd_off *);
1235
1236         /* llog related obd_methods */
1237         int (*o_llog_init)(struct obd_device *obd, struct obd_device *disk_obd,
1238                            int *idx);
1239         int (*o_llog_finish)(struct obd_device *obd, int count);
1240
1241         /* metadata-only methods */
1242         int (*o_pin)(struct obd_export *, struct ll_fid *,
1243                      struct obd_client_handle *, int flag);
1244         int (*o_unpin)(struct obd_export *, struct obd_client_handle *, int);
1245
1246         int (*o_import_event)(struct obd_device *, struct obd_import *,
1247                               enum obd_import_event);
1248
1249         int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
1250                         enum obd_notify_event ev, void *data);
1251
1252         int (*o_health_check)(struct obd_device *);
1253
1254         /* quota methods */
1255         int (*o_quotacheck)(struct obd_export *, struct obd_quotactl *);
1256         int (*o_quotactl)(struct obd_export *, struct obd_quotactl *);
1257         int (*o_quota_adjust_qunit)(struct obd_export *exp,
1258                                     struct quota_adjust_qunit *oqaq,
1259                                     struct lustre_quota_ctxt *qctxt);
1260
1261
1262         int (*o_ping)(struct obd_export *exp);
1263
1264         int (*o_register_page_removal_cb)(struct obd_device *obd,
1265                                           obd_page_removal_cb_t cb,
1266                                           obd_pin_extent_cb pin_cb);
1267         int (*o_unregister_page_removal_cb)(struct obd_device *obd,
1268                                             obd_page_removal_cb_t cb);
1269         int (*o_register_lock_cancel_cb)(struct obd_device *obd,
1270                                        obd_lock_cancel_cb cb);
1271         int (*o_unregister_lock_cancel_cb)(struct obd_device *obd,
1272                                          obd_lock_cancel_cb cb);
1273         /* pools methods */
1274         int (*o_pool_new)(struct obd_device *obd, char *poolname);
1275         int (*o_pool_del)(struct obd_device *obd, char *poolname);
1276         int (*o_pool_add)(struct obd_device *obd, char *poolname,
1277                           char *ostname);
1278         int (*o_pool_rem)(struct obd_device *obd, char *poolname,
1279                           char *ostname);
1280         void (*o_getref)(struct obd_device *obd);
1281         void (*o_putref)(struct obd_device *obd);
1282
1283         /*
1284          * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
1285          * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
1286          * Also, add a wrapper function in include/linux/obd_class.h. */
1287 };
1288
1289 struct lsm_operations {
1290         void (*lsm_free)(struct lov_stripe_md *);
1291         int (*lsm_destroy)(struct lov_stripe_md *, struct obdo *oa,
1292                            struct obd_export *md_exp);
1293         void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *, obd_off *,
1294                                     obd_off *);
1295         void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *, obd_off *,
1296                                      obd_off *);
1297         obd_off (*lsm_stripe_offset_by_index)(struct lov_stripe_md *, int);
1298         obd_off (*lsm_stripe_offset_by_offset)(struct lov_stripe_md *, obd_off);
1299         int (*lsm_stripe_index_by_offset)(struct lov_stripe_md *, obd_off);
1300         int (*lsm_revalidate) (struct lov_stripe_md *, struct obd_device *obd);
1301         int (*lsm_lmm_verify) (struct lov_mds_md *lmm, int lmm_bytes,
1302                                int *stripe_count);
1303         int (*lsm_unpackmd) (struct lov_obd *lov, struct lov_stripe_md *lsm,
1304                              struct lov_mds_md *lmm);
1305 };
1306
1307 extern struct lsm_operations lsm_v1_ops;
1308 extern struct lsm_operations lsm_join_ops;
1309 extern struct lsm_operations lsm_v3_ops;
1310 static inline struct lsm_operations *lsm_op_find(int magic)
1311 {
1312         switch(magic) {
1313         case LOV_MAGIC_V1:
1314                return &lsm_v1_ops;
1315         case LOV_MAGIC_JOIN:
1316                return &lsm_join_ops;
1317         case LOV_MAGIC_V3:
1318                return &lsm_v3_ops;
1319         default:
1320                CERROR("Cannot recognize lsm_magic %x\n", magic);
1321                return NULL;
1322         }
1323 }
1324
1325 int lvfs_check_io_health(struct obd_device *obd, struct file *file);
1326
1327 /* Requests for obd_extent_calc() */
1328 #define OBD_CALC_STRIPE_START          0x0001
1329 #define OBD_CALC_STRIPE_END            0x0010
1330 #define OBD_CALC_STRIPE_RPC_ALIGN      0x0100
1331
1332 #define OBD_CALC_STRIPE_RPC_START_ALIGN (OBD_CALC_STRIPE_START | \
1333                                          OBD_CALC_STRIPE_RPC_ALIGN)
1334 #define OBD_CALC_STRIPE_RPC_END_ALIGN (OBD_CALC_STRIPE_START | \
1335                                        OBD_CALC_STRIPE_RPC_ALIGN)
1336
1337 static inline void obd_transno_commit_cb(struct obd_device *obd, __u64 transno,
1338                                          struct obd_export *exp, int error)
1339 {
1340         if (error) {
1341                 CERROR("%s: transno "LPU64" commit error: %d\n",
1342                        obd->obd_name, transno, error);
1343                 return;
1344         }
1345         if (exp && transno > exp->exp_last_committed) {
1346                 CDEBUG(D_INFO, "%s: transno "LPU64" committed\n",
1347                        obd->obd_name, transno);
1348                 exp->exp_last_committed = transno;
1349                 ptlrpc_commit_replies(exp);
1350         } else {
1351                 CDEBUG(D_INFO, "%s: transno "LPU64" committed\n",
1352                        obd->obd_name, transno);
1353         }
1354         if (transno > obd->obd_last_committed)
1355                 obd->obd_last_committed = transno;
1356 }
1357
1358 static inline void init_obd_quota_ops(quota_interface_t *interface,
1359                                       struct obd_ops *obd_ops)
1360 {
1361         if (!interface)
1362                 return;
1363
1364         LASSERT(obd_ops);
1365         obd_ops->o_quotacheck = QUOTA_OP(interface, check);
1366         obd_ops->o_quotactl = QUOTA_OP(interface, ctl);
1367         obd_ops->o_quota_adjust_qunit = QUOTA_OP(interface, adjust_qunit);
1368 }
1369
1370 /*
1371  * Checksums
1372  */
1373
1374 #ifdef HAVE_ADLER
1375 /* Default preferred checksum algorithm to use (if supported by the server) */
1376 #define OSC_DEFAULT_CKSUM OBD_CKSUM_ADLER
1377 /* Adler-32 is supported */
1378 #define CHECKSUM_ADLER OBD_CKSUM_ADLER
1379 #else
1380 #define OSC_DEFAULT_CKSUM OBD_CKSUM_CRC32
1381 #define CHECKSUM_ADLER 0
1382 #endif
1383
1384 #define OBD_CKSUM_ALL (OBD_CKSUM_CRC32 | CHECKSUM_ADLER)
1385
1386 /* Checksum algorithm names. Must be defined in the same order as the
1387  * OBD_CKSUM_* flags. */
1388 #define DECLARE_CKSUM_NAME char *cksum_name[] = {"crc32", "adler"}
1389
1390 #endif /* __OBD_H */