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