]> Pileus Git - ~andy/linux/blob - drivers/staging/lustre/lustre/include/obd.h
staging/lustre/hsm: Add hsm_release feature.
[~andy/linux] / drivers / staging / lustre / lustre / include / obd.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Intel Corporation.
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 #include <linux/obd.h>
41
42 #define IOC_OSC_TYPE     'h'
43 #define IOC_OSC_MIN_NR       20
44 #define IOC_OSC_SET_ACTIVE   _IOWR(IOC_OSC_TYPE, 21, struct obd_device *)
45 #define IOC_OSC_MAX_NR       50
46
47 #define IOC_MDC_TYPE     'i'
48 #define IOC_MDC_MIN_NR       20
49 #define IOC_MDC_MAX_NR       50
50
51 #include <lustre/lustre_idl.h>
52 #include <lustre_lib.h>
53 #include <linux/libcfs/bitmap.h>
54 #include <lu_ref.h>
55 #include <lustre_export.h>
56 #include <lustre_fid.h>
57 #include <lustre_fld.h>
58 #include <lustre_capa.h>
59
60 #define MAX_OBD_DEVICES 8192
61
62 struct osc_async_rc {
63         int     ar_rc;
64         int     ar_force_sync;
65         __u64   ar_min_xid;
66 };
67
68 struct lov_oinfo {               /* per-stripe data structure */
69         struct ost_id   loi_oi;    /* object ID/Sequence on the target OST */
70         int loi_ost_idx;           /* OST stripe index in lov_tgt_desc->tgts */
71         int loi_ost_gen;           /* generation of this loi_ost_idx */
72
73         unsigned long loi_kms_valid:1;
74         __u64 loi_kms;       /* known minimum size */
75         struct ost_lvb loi_lvb;
76         struct osc_async_rc     loi_ar;
77 };
78
79 static inline void loi_kms_set(struct lov_oinfo *oinfo, __u64 kms)
80 {
81         oinfo->loi_kms = kms;
82         oinfo->loi_kms_valid = 1;
83 }
84
85 static inline void loi_init(struct lov_oinfo *loi)
86 {
87 }
88
89 struct lov_stripe_md {
90         atomic_t     lsm_refc;
91         spinlock_t      lsm_lock;
92         pid_t       lsm_lock_owner; /* debugging */
93
94         /* maximum possible file size, might change as OSTs status changes,
95          * e.g. disconnected, deactivated */
96         __u64       lsm_maxbytes;
97         struct {
98                 /* Public members. */
99                 struct ost_id lw_object_oi; /* lov object id/seq */
100
101                 /* LOV-private members start here -- only for use in lov/. */
102                 __u32 lw_magic;
103                 __u32 lw_stripe_size;      /* size of the stripe */
104                 __u32 lw_pattern;         /* striping pattern (RAID0, RAID1) */
105                 __u16 lw_stripe_count;  /* number of objects being striped over */
106                 __u16 lw_layout_gen;       /* generation of the layout */
107                 char  lw_pool_name[LOV_MAXPOOLNAME]; /* pool name */
108         } lsm_wire;
109
110         struct lov_oinfo *lsm_oinfo[0];
111 };
112
113 #define lsm_oi           lsm_wire.lw_object_oi
114 #define lsm_magic       lsm_wire.lw_magic
115 #define lsm_layout_gen   lsm_wire.lw_layout_gen
116 #define lsm_stripe_size  lsm_wire.lw_stripe_size
117 #define lsm_pattern      lsm_wire.lw_pattern
118 #define lsm_stripe_count lsm_wire.lw_stripe_count
119 #define lsm_pool_name    lsm_wire.lw_pool_name
120
121 static inline bool lsm_is_released(struct lov_stripe_md *lsm)
122 {
123         return !!(lsm->lsm_pattern & LOV_PATTERN_F_RELEASED);
124 }
125
126 static inline bool lsm_has_objects(struct lov_stripe_md *lsm)
127 {
128         if (lsm == NULL)
129                 return false;
130         if (lsm_is_released(lsm))
131                 return false;
132         return true;
133 }
134
135 struct obd_info;
136
137 typedef int (*obd_enqueue_update_f)(void *cookie, int rc);
138
139 /* obd info for a particular level (lov, osc). */
140 struct obd_info {
141         /* Lock policy. It keeps an extent which is specific for a particular
142          * OSC. (e.g. lov_prep_enqueue_set initialises extent of the policy,
143          * and osc_enqueue passes it into ldlm_lock_match & ldlm_cli_enqueue. */
144         ldlm_policy_data_t      oi_policy;
145         /* Flags used for set request specific flags:
146            - while lock handling, the flags obtained on the enqueue
147            request are set here.
148            - while stats, the flags used for control delay/resend.
149            - while setattr, the flags used for distinguish punch operation
150          */
151         __u64              oi_flags;
152         /* Lock handle specific for every OSC lock. */
153         struct lustre_handle   *oi_lockh;
154         /* lsm data specific for every OSC. */
155         struct lov_stripe_md   *oi_md;
156         /* obdo data specific for every OSC, if needed at all. */
157         struct obdo         *oi_oa;
158         /* statfs data specific for every OSC, if needed at all. */
159         struct obd_statfs      *oi_osfs;
160         /* An update callback which is called to update some data on upper
161          * level. E.g. it is used for update lsm->lsm_oinfo at every recieved
162          * request in osc level for enqueue requests. It is also possible to
163          * update some caller data from LOV layer if needed. */
164         obd_enqueue_update_f    oi_cb_up;
165         /* oss capability, its type is obd_capa in client to avoid copy.
166          * in contrary its type is lustre_capa in OSS. */
167         void               *oi_capa;
168         /* transfer jobid from ost_sync() to filter_sync()... */
169         char               *oi_jobid;
170 };
171
172 /* compare all relevant fields. */
173 static inline int lov_stripe_md_cmp(struct lov_stripe_md *m1,
174                                     struct lov_stripe_md *m2)
175 {
176         /*
177          * ->lsm_wire contains padding, but it should be zeroed out during
178          * allocation.
179          */
180         return memcmp(&m1->lsm_wire, &m2->lsm_wire, sizeof(m1->lsm_wire));
181 }
182
183 static inline int lov_lum_lsm_cmp(struct lov_user_md *lum,
184                                   struct lov_stripe_md  *lsm)
185 {
186         if (lsm->lsm_magic != lum->lmm_magic)
187                 return 1;
188         if ((lsm->lsm_stripe_count != 0) && (lum->lmm_stripe_count != 0) &&
189             (lsm->lsm_stripe_count != lum->lmm_stripe_count))
190                 return 2;
191         if ((lsm->lsm_stripe_size != 0) && (lum->lmm_stripe_size != 0) &&
192             (lsm->lsm_stripe_size != lum->lmm_stripe_size))
193                 return 3;
194         if ((lsm->lsm_pattern != 0) && (lum->lmm_pattern != 0) &&
195             (lsm->lsm_pattern != lum->lmm_pattern))
196                 return 4;
197         if ((lsm->lsm_magic == LOV_MAGIC_V3) &&
198             (strncmp(lsm->lsm_pool_name,
199                      ((struct lov_user_md_v3 *)lum)->lmm_pool_name,
200                      LOV_MAXPOOLNAME) != 0))
201                 return 5;
202         return 0;
203 }
204
205 static inline int lov_lum_swab_if_needed(struct lov_user_md_v3 *lumv3,
206                                          int *lmm_magic,
207                                          struct lov_user_md *lum)
208 {
209         if (lum && copy_from_user(lumv3, lum,sizeof(struct lov_user_md_v1)))
210                 return -EFAULT;
211
212         *lmm_magic = lumv3->lmm_magic;
213
214         if (*lmm_magic == __swab32(LOV_USER_MAGIC_V1)) {
215                 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lumv3);
216                 *lmm_magic = LOV_USER_MAGIC_V1;
217         } else if (*lmm_magic == LOV_USER_MAGIC_V3) {
218                 if (lum && copy_from_user(lumv3, lum, sizeof(*lumv3)))
219                         return -EFAULT;
220         } else if (*lmm_magic == __swab32(LOV_USER_MAGIC_V3)) {
221                 if (lum && copy_from_user(lumv3, lum, sizeof(*lumv3)))
222                         return -EFAULT;
223                 lustre_swab_lov_user_md_v3(lumv3);
224                 *lmm_magic = LOV_USER_MAGIC_V3;
225         } else if (*lmm_magic != LOV_USER_MAGIC_V1) {
226                 CDEBUG(D_IOCTL,
227                        "bad userland LOV MAGIC: %#08x != %#08x nor %#08x\n",
228                        *lmm_magic, LOV_USER_MAGIC_V1, LOV_USER_MAGIC_V3);
229                        return -EINVAL;
230         }
231         return 0;
232 }
233
234 void lov_stripe_lock(struct lov_stripe_md *md);
235 void lov_stripe_unlock(struct lov_stripe_md *md);
236
237 struct obd_type {
238         struct list_head typ_chain;
239         struct obd_ops *typ_dt_ops;
240         struct md_ops *typ_md_ops;
241         struct proc_dir_entry *typ_procroot;
242         char *typ_name;
243         int  typ_refcnt;
244         struct lu_device_type *typ_lu;
245         spinlock_t obd_type_lock;
246 };
247
248 struct brw_page {
249         obd_off  off;
250         struct page *pg;
251         int count;
252         obd_flag flag;
253 };
254
255 /* llog contexts */
256 enum llog_ctxt_id {
257         LLOG_CONFIG_ORIG_CTXT  =  0,
258         LLOG_CONFIG_REPL_CTXT,
259         LLOG_MDS_OST_ORIG_CTXT,
260         LLOG_MDS_OST_REPL_CTXT,
261         LLOG_SIZE_ORIG_CTXT,
262         LLOG_SIZE_REPL_CTXT,
263         LLOG_RD1_ORIG_CTXT,
264         LLOG_RD1_REPL_CTXT,
265         LLOG_TEST_ORIG_CTXT,
266         LLOG_TEST_REPL_CTXT,
267         LLOG_LOVEA_ORIG_CTXT,
268         LLOG_LOVEA_REPL_CTXT,
269         LLOG_CHANGELOG_ORIG_CTXT,       /**< changelog generation on mdd */
270         LLOG_CHANGELOG_REPL_CTXT,       /**< changelog access on clients */
271         LLOG_CHANGELOG_USER_ORIG_CTXT,  /**< for multiple changelog consumers */
272         LLOG_AGENT_ORIG_CTXT,           /**< agent requests generation on cdt */
273         LLOG_MAX_CTXTS
274 };
275
276 struct timeout_item {
277         enum timeout_event ti_event;
278         cfs_time_t       ti_timeout;
279         timeout_cb_t       ti_cb;
280         void          *ti_cb_data;
281         struct list_head         ti_obd_list;
282         struct list_head         ti_chain;
283 };
284
285 #define OSC_MAX_RIF_DEFAULT       8
286 #define MDS_OSC_MAX_RIF_DEFAULT   50
287 #define OSC_MAX_RIF_MAX  256
288 #define OSC_MAX_DIRTY_DEFAULT  (OSC_MAX_RIF_DEFAULT * 4)
289 #define OSC_MAX_DIRTY_MB_MAX   2048     /* arbitrary, but < MAX_LONG bytes */
290 #define OSC_DEFAULT_RESENDS      10
291
292 /* possible values for fo_sync_lock_cancel */
293 enum {
294         NEVER_SYNC_ON_CANCEL = 0,
295         BLOCKING_SYNC_ON_CANCEL = 1,
296         ALWAYS_SYNC_ON_CANCEL = 2,
297         NUM_SYNC_ON_CANCEL_STATES
298 };
299
300 #define MDC_MAX_RIF_DEFAULT       8
301 #define MDC_MAX_RIF_MAX  512
302
303 struct mdc_rpc_lock;
304 struct obd_import;
305 struct client_obd {
306         struct rw_semaphore  cl_sem;
307         struct obd_uuid   cl_target_uuid;
308         struct obd_import       *cl_import; /* ptlrpc connection state */
309         int                   cl_conn_count;
310         /* max_mds_easize is purely a performance thing so we don't have to
311          * call obd_size_diskmd() all the time. */
312         int                   cl_default_mds_easize;
313         int                   cl_max_mds_easize;
314         int                   cl_max_mds_cookiesize;
315
316         enum lustre_sec_part     cl_sp_me;
317         enum lustre_sec_part     cl_sp_to;
318         struct sptlrpc_flavor    cl_flvr_mgc;   /* fixed flavor of mgc->mgs */
319
320         /* the grant values are protected by loi_list_lock below */
321         long                 cl_dirty;   /* all _dirty_ in bytes */
322         long                 cl_dirty_max;     /* allowed w/o rpc */
323         long                 cl_dirty_transit; /* dirty synchronous */
324         long                 cl_avail_grant;   /* bytes of credit for ost */
325         long                 cl_lost_grant;    /* lost credits (trunc) */
326
327         /* since we allocate grant by blocks, we don't know how many grant will
328          * be used to add a page into cache. As a solution, we reserve maximum
329          * grant before trying to dirty a page and unreserve the rest.
330          * See osc_{reserve|unreserve}_grant for details. */
331         long             cl_reserved_grant;
332         struct list_head           cl_cache_waiters; /* waiting for cache/grant */
333         cfs_time_t         cl_next_shrink_grant;   /* jiffies */
334         struct list_head           cl_grant_shrink_list;  /* Timeout event list */
335         int               cl_grant_shrink_interval; /* seconds */
336
337         /* A chunk is an optimal size used by osc_extent to determine
338          * the extent size. A chunk is max(PAGE_CACHE_SIZE, OST block size) */
339         int               cl_chunkbits;
340         int               cl_chunk;
341         int               cl_extent_tax; /* extent overhead, by bytes */
342
343         /* keep track of objects that have lois that contain pages which
344          * have been queued for async brw.  this lock also protects the
345          * lists of osc_client_pages that hang off of the loi */
346         /*
347          * ->cl_loi_list_lock protects consistency of
348          * ->cl_loi_{ready,read,write}_list. ->ap_make_ready() and
349          * ->ap_completion() call-backs are executed under this lock. As we
350          * cannot guarantee that these call-backs never block on all platforms
351          * (as a matter of fact they do block on Mac OS X), type of
352          * ->cl_loi_list_lock is platform dependent: it's a spin-lock on Linux
353          * and blocking mutex on Mac OS X. (Alternative is to make this lock
354          * blocking everywhere, but we don't want to slow down fast-path of
355          * our main platform.)
356          *
357          * Exact type of ->cl_loi_list_lock is defined in arch/obd.h together
358          * with client_obd_list_{un,}lock() and
359          * client_obd_list_lock_{init,done}() functions.
360          *
361          * NB by Jinshan: though field names are still _loi_, but actually
362          * osc_object{}s are in the list.
363          */
364         client_obd_lock_t       cl_loi_list_lock;
365         struct list_head               cl_loi_ready_list;
366         struct list_head               cl_loi_hp_ready_list;
367         struct list_head               cl_loi_write_list;
368         struct list_head               cl_loi_read_list;
369         int                   cl_r_in_flight;
370         int                   cl_w_in_flight;
371         /* just a sum of the loi/lop pending numbers to be exported by /proc */
372         atomic_t             cl_pending_w_pages;
373         atomic_t             cl_pending_r_pages;
374         __u32                    cl_max_pages_per_rpc;
375         int                   cl_max_rpcs_in_flight;
376         struct obd_histogram     cl_read_rpc_hist;
377         struct obd_histogram     cl_write_rpc_hist;
378         struct obd_histogram     cl_read_page_hist;
379         struct obd_histogram     cl_write_page_hist;
380         struct obd_histogram     cl_read_offset_hist;
381         struct obd_histogram     cl_write_offset_hist;
382
383         /* lru for osc caching pages */
384         struct cl_client_cache  *cl_cache;
385         struct list_head                 cl_lru_osc; /* member of cl_cache->ccc_lru */
386         atomic_t                *cl_lru_left;
387         atomic_t                 cl_lru_busy;
388         atomic_t                 cl_lru_shrinkers;
389         atomic_t                 cl_lru_in_list;
390         struct list_head                 cl_lru_list; /* lru page list */
391         client_obd_lock_t        cl_lru_list_lock; /* page list protector */
392
393         /* number of in flight destroy rpcs is limited to max_rpcs_in_flight */
394         atomic_t             cl_destroy_in_flight;
395         wait_queue_head_t             cl_destroy_waitq;
396
397         struct mdc_rpc_lock     *cl_rpc_lock;
398         struct mdc_rpc_lock     *cl_close_lock;
399
400         /* mgc datastruct */
401         struct semaphore         cl_mgc_sem;
402         struct local_oid_storage *cl_mgc_los;
403         struct dt_object        *cl_mgc_configs_dir;
404         atomic_t             cl_mgc_refcount;
405         struct obd_export       *cl_mgc_mgsexp;
406
407         /* checksumming for data sent over the network */
408         unsigned int         cl_checksum:1; /* 0 = disabled, 1 = enabled */
409         /* supported checksum types that are worked out at connect time */
410         __u32               cl_supp_cksum_types;
411         /* checksum algorithm to be used */
412         cksum_type_t         cl_cksum_type;
413
414         /* also protected by the poorly named _loi_list_lock lock above */
415         struct osc_async_rc      cl_ar;
416
417         /* used by quotacheck when the servers are older than 2.4 */
418         int                   cl_qchk_stat; /* quotacheck stat of the peer */
419 #define CL_NOT_QUOTACHECKED 1   /* client->cl_qchk_stat init value */
420 #if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 7, 50, 0)
421 #warning "please consider removing quotacheck compatibility code"
422 #endif
423
424         /* sequence manager */
425         struct lu_client_seq    *cl_seq;
426
427         atomic_t             cl_resends; /* resend count */
428
429         /* ptlrpc work for writeback in ptlrpcd context */
430         void                *cl_writeback_work;
431         /* hash tables for osc_quota_info */
432         struct cfs_hash       *cl_quota_hash[MAXQUOTAS];
433 };
434 #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
435
436 struct obd_id_info {
437         __u32   idx;
438         obd_id  *data;
439 };
440
441 struct echo_client_obd {
442         struct obd_export       *ec_exp;   /* the local connection to osc/lov */
443         spinlock_t              ec_lock;
444         struct list_head           ec_objects;
445         struct list_head           ec_locks;
446         int               ec_nstripes;
447         __u64           ec_unique;
448 };
449
450 struct lov_qos_oss {
451         struct obd_uuid     lqo_uuid;       /* ptlrpc's c_remote_uuid */
452         struct list_head          lqo_oss_list;   /* link to lov_qos */
453         __u64          lqo_bavail;     /* total bytes avail on OSS */
454         __u64          lqo_penalty;    /* current penalty */
455         __u64          lqo_penalty_per_obj;/* penalty decrease every obj*/
456         time_t        lqo_used;       /* last used time, seconds */
457         __u32          lqo_ost_count;  /* number of osts on this oss */
458 };
459
460 struct ltd_qos {
461         struct lov_qos_oss *ltq_oss;     /* oss info */
462         __u64          ltq_penalty;     /* current penalty */
463         __u64          ltq_penalty_per_obj; /* penalty decrease every obj*/
464         __u64          ltq_weight;      /* net weighting */
465         time_t        ltq_used; /* last used time, seconds */
466         unsigned int    ltq_usable:1;    /* usable for striping */
467 };
468
469 /* Generic subset of OSTs */
470 struct ost_pool {
471         __u32         *op_array;      /* array of index of
472                                                    lov_obd->lov_tgts */
473         unsigned int    op_count;      /* number of OSTs in the array */
474         unsigned int    op_size;       /* allocated size of lp_array */
475         struct rw_semaphore op_rw_sem;     /* to protect ost_pool use */
476 };
477
478 /* Round-robin allocator data */
479 struct lov_qos_rr {
480         __u32          lqr_start_idx;   /* start index of new inode */
481         __u32          lqr_offset_idx;  /* aliasing for start_idx  */
482         int              lqr_start_count; /* reseed counter */
483         struct ost_pool     lqr_pool;   /* round-robin optimized list */
484         unsigned long       lqr_dirty:1;     /* recalc round-robin list */
485 };
486
487 /* allow statfs data caching for 1 second */
488 #define OBD_STATFS_CACHE_SECONDS 1
489
490 struct lov_statfs_data {
491         struct obd_info   lsd_oi;
492         struct obd_statfs lsd_statfs;
493 };
494 /* Stripe placement optimization */
495 struct lov_qos {
496         struct list_head          lq_oss_list; /* list of OSSs that targets use */
497         struct rw_semaphore lq_rw_sem;
498         __u32          lq_active_oss_count;
499         unsigned int    lq_prio_free;   /* priority for free space */
500         unsigned int    lq_threshold_rr;/* priority for rr */
501         struct lov_qos_rr   lq_rr;        /* round robin qos data */
502         unsigned long       lq_dirty:1,     /* recalc qos data */
503                             lq_same_space:1,/* the ost's all have approx.
504                                                the same space avail */
505                             lq_reset:1,     /* zero current penalties */
506                             lq_statfs_in_progress:1; /* statfs op in
507                                                         progress */
508         /* qos statfs data */
509         struct lov_statfs_data *lq_statfs_data;
510         wait_queue_head_t        lq_statfs_waitq; /* waitqueue to notify statfs
511                                               * requests completion */
512 };
513
514 struct lov_tgt_desc {
515         struct list_head          ltd_kill;
516         struct obd_uuid     ltd_uuid;
517         struct obd_device  *ltd_obd;
518         struct obd_export  *ltd_exp;
519         struct ltd_qos      ltd_qos;     /* qos info per target */
520         __u32          ltd_gen;
521         __u32          ltd_index;   /* index in lov_obd->tgts */
522         unsigned long       ltd_active:1,/* is this target up for requests */
523                             ltd_activate:1,/* should  target be activated */
524                             ltd_reap:1;  /* should this target be deleted */
525 };
526
527 /* Pool metadata */
528 #define pool_tgt_size(_p)   _p->pool_obds.op_size
529 #define pool_tgt_count(_p)  _p->pool_obds.op_count
530 #define pool_tgt_array(_p)  _p->pool_obds.op_array
531 #define pool_tgt_rw_sem(_p) _p->pool_obds.op_rw_sem
532
533 struct pool_desc {
534         char              pool_name[LOV_MAXPOOLNAME + 1]; /* name of pool */
535         struct ost_pool       pool_obds;              /* pool members */
536         atomic_t          pool_refcount;          /* pool ref. counter */
537         struct lov_qos_rr     pool_rr;          /* round robin qos */
538         struct hlist_node      pool_hash;             /* access by poolname */
539         struct list_head            pool_list;        /* serial access */
540         struct proc_dir_entry *pool_proc_entry; /* file in /proc */
541         struct obd_device    *pool_lobd;              /* obd of the lov/lod to which
542                                                        * this pool belongs */
543 };
544
545 struct lov_obd {
546         struct lov_desc  desc;
547         struct lov_tgt_desc   **lov_tgts;             /* sparse array */
548         struct ost_pool  lov_packed;        /* all OSTs in a packed
549                                                           array */
550         struct mutex            lov_lock;
551         struct obd_connect_data lov_ocd;
552         atomic_t            lov_refcount;
553         __u32              lov_tgt_count;        /* how many OBD's */
554         __u32              lov_active_tgt_count;  /* how many active */
555         __u32              lov_death_row;/* tgts scheduled to be deleted */
556         __u32              lov_tgt_size;   /* size of tgts array */
557         int                  lov_connects;
558         int                  lov_pool_count;
559         struct cfs_hash      *lov_pools_hash_body; /* used for key access */
560         struct list_head              lov_pool_list; /* used for sequential access */
561         struct proc_dir_entry   *lov_pool_proc_entry;
562         enum lustre_sec_part    lov_sp_me;
563
564         /* Cached LRU pages from upper layer */
565         void                   *lov_cache;
566
567         struct rw_semaphore     lov_notify_lock;
568 };
569
570 struct lmv_tgt_desc {
571         struct obd_uuid         ltd_uuid;
572         struct obd_export       *ltd_exp;
573         int                     ltd_idx;
574         struct mutex            ltd_fid_mutex;
575         unsigned long           ltd_active:1; /* target up for requests */
576 };
577
578 enum placement_policy {
579         PLACEMENT_CHAR_POLICY   = 0,
580         PLACEMENT_NID_POLICY    = 1,
581         PLACEMENT_INVAL_POLICY  = 2,
582         PLACEMENT_MAX_POLICY
583 };
584
585 typedef enum placement_policy placement_policy_t;
586
587 struct lmv_obd {
588         int                     refcount;
589         struct lu_client_fld    lmv_fld;
590         spinlock_t              lmv_lock;
591         placement_policy_t      lmv_placement;
592         struct lmv_desc         desc;
593         struct obd_uuid         cluuid;
594         struct obd_export       *exp;
595
596         struct mutex            init_mutex;
597         int                     connected;
598         int                     max_easize;
599         int                     max_def_easize;
600         int                     max_cookiesize;
601         int                     server_timeout;
602
603         int                     tgts_size; /* size of tgts array */
604         struct lmv_tgt_desc     **tgts;
605
606         struct obd_connect_data conn_data;
607 };
608
609 struct niobuf_local {
610         __u64           lnb_file_offset;
611         __u32           lnb_page_offset;
612         __u32           len;
613         __u32           flags;
614         struct page     *page;
615         struct dentry   *dentry;
616         int             lnb_grant_used;
617         int             rc;
618 };
619
620 #define LUSTRE_FLD_NAME  "fld"
621 #define LUSTRE_SEQ_NAME  "seq"
622
623 #define LUSTRE_MDD_NAME  "mdd"
624 #define LUSTRE_OSD_LDISKFS_NAME "osd-ldiskfs"
625 #define LUSTRE_OSD_ZFS_NAME     "osd-zfs"
626 #define LUSTRE_VVP_NAME  "vvp"
627 #define LUSTRE_LMV_NAME  "lmv"
628 #define LUSTRE_SLP_NAME  "slp"
629 #define LUSTRE_LOD_NAME         "lod"
630 #define LUSTRE_OSP_NAME         "osp"
631 #define LUSTRE_LWP_NAME         "lwp"
632
633 /* obd device type names */
634  /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */
635 #define LUSTRE_MDS_NAME  "mds"
636 #define LUSTRE_MDT_NAME  "mdt"
637 #define LUSTRE_MDC_NAME  "mdc"
638 #define LUSTRE_OSS_NAME  "ost"       /* FIXME change name to oss */
639 #define LUSTRE_OST_NAME  "obdfilter" /* FIXME change name to ost */
640 #define LUSTRE_OSC_NAME  "osc"
641 #define LUSTRE_LOV_NAME  "lov"
642 #define LUSTRE_MGS_NAME  "mgs"
643 #define LUSTRE_MGC_NAME  "mgc"
644
645 #define LUSTRE_ECHO_NAME        "obdecho"
646 #define LUSTRE_ECHO_CLIENT_NAME "echo_client"
647 #define LUSTRE_QMT_NAME  "qmt"
648
649 /* Constant obd names (post-rename) */
650 #define LUSTRE_MDS_OBDNAME "MDS"
651 #define LUSTRE_OSS_OBDNAME "OSS"
652 #define LUSTRE_MGS_OBDNAME "MGS"
653 #define LUSTRE_MGC_OBDNAME "MGC"
654
655 static inline int is_osp_on_mdt(char *name)
656 {
657         char   *ptr;
658
659         ptr = strrchr(name, '-');
660         if (ptr == NULL) {
661                 CERROR("%s is not a obdname\n", name);
662                 return 0;
663         }
664
665         /* 1.8 OSC/OSP name on MDT is fsname-OSTxxxx-osc */
666         if (strncmp(ptr + 1, "osc", 3) == 0)
667                 return 1;
668
669         if (strncmp(ptr + 1, "MDT", 3) != 0)
670                 return 0;
671
672         while (*(--ptr) != '-' && ptr != name);
673
674         if (ptr == name)
675                 return 0;
676
677         if (strncmp(ptr + 1, LUSTRE_OSP_NAME, strlen(LUSTRE_OSP_NAME)) != 0 &&
678             strncmp(ptr + 1, LUSTRE_OSC_NAME, strlen(LUSTRE_OSC_NAME)) != 0)
679                 return 0;
680
681         return 1;
682 }
683
684 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
685 #define N_LOCAL_TEMP_PAGE 0x10000000
686
687 struct obd_trans_info {
688         __u64               oti_transno;
689         __u64               oti_xid;
690         /* Only used on the server side for tracking acks. */
691         struct oti_req_ack_lock {
692                 struct lustre_handle lock;
693                 __u32           mode;
694         }                       oti_ack_locks[4];
695         void                *oti_handle;
696         struct llog_cookie       oti_onecookie;
697         struct llog_cookie      *oti_logcookies;
698         int                   oti_numcookies;
699         /** synchronous write is needed */
700         unsigned long            oti_sync_write:1;
701
702         /* initial thread handling transaction */
703         struct ptlrpc_thread *   oti_thread;
704         __u32               oti_conn_cnt;
705         /** VBR: versions */
706         __u64               oti_pre_version;
707         /** JobID */
708         char                *oti_jobid;
709
710         struct obd_uuid  *oti_ost_uuid;
711 };
712
713 static inline void oti_init(struct obd_trans_info *oti,
714                             struct ptlrpc_request *req)
715 {
716         if (oti == NULL)
717                 return;
718         memset(oti, 0, sizeof(*oti));
719
720         if (req == NULL)
721                 return;
722
723         oti->oti_xid = req->rq_xid;
724         /** VBR: take versions from request */
725         if (req->rq_reqmsg != NULL &&
726             lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
727                 __u64 *pre_version = lustre_msg_get_versions(req->rq_reqmsg);
728                 oti->oti_pre_version = pre_version ? pre_version[0] : 0;
729                 oti->oti_transno = lustre_msg_get_transno(req->rq_reqmsg);
730         }
731
732         /** called from mds_create_objects */
733         if (req->rq_repmsg != NULL)
734                 oti->oti_transno = lustre_msg_get_transno(req->rq_repmsg);
735         oti->oti_thread = req->rq_svc_thread;
736         if (req->rq_reqmsg != NULL)
737                 oti->oti_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg);
738 }
739
740 static inline void oti_alloc_cookies(struct obd_trans_info *oti,int num_cookies)
741 {
742         if (!oti)
743                 return;
744
745         if (num_cookies == 1)
746                 oti->oti_logcookies = &oti->oti_onecookie;
747         else
748                 OBD_ALLOC_LARGE(oti->oti_logcookies,
749                                 num_cookies * sizeof(oti->oti_onecookie));
750
751         oti->oti_numcookies = num_cookies;
752 }
753
754 static inline void oti_free_cookies(struct obd_trans_info *oti)
755 {
756         if (!oti || !oti->oti_logcookies)
757                 return;
758
759         if (oti->oti_logcookies == &oti->oti_onecookie)
760                 LASSERT(oti->oti_numcookies == 1);
761         else
762                 OBD_FREE_LARGE(oti->oti_logcookies,
763                                oti->oti_numcookies*sizeof(oti->oti_onecookie));
764         oti->oti_logcookies = NULL;
765         oti->oti_numcookies = 0;
766 }
767
768 /*
769  * Events signalled through obd_notify() upcall-chain.
770  */
771 enum obd_notify_event {
772         /* target added */
773         OBD_NOTIFY_CREATE,
774         /* Device connect start */
775         OBD_NOTIFY_CONNECT,
776         /* Device activated */
777         OBD_NOTIFY_ACTIVE,
778         /* Device deactivated */
779         OBD_NOTIFY_INACTIVE,
780         /* Device disconnected */
781         OBD_NOTIFY_DISCON,
782         /* Connect data for import were changed */
783         OBD_NOTIFY_OCD,
784         /* Sync request */
785         OBD_NOTIFY_SYNC_NONBLOCK,
786         OBD_NOTIFY_SYNC,
787         /* Configuration event */
788         OBD_NOTIFY_CONFIG,
789         /* Administratively deactivate/activate event */
790         OBD_NOTIFY_DEACTIVATE,
791         OBD_NOTIFY_ACTIVATE
792 };
793
794 /*
795  * Data structure used to pass obd_notify()-event to non-obd listeners (llite
796  * and liblustre being main examples).
797  */
798 struct obd_notify_upcall {
799         int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
800                           enum obd_notify_event ev, void *owner, void *data);
801         /* Opaque datum supplied by upper layer listener */
802         void *onu_owner;
803 };
804
805 struct target_recovery_data {
806         svc_handler_t           trd_recovery_handler;
807         pid_t                   trd_processing_task;
808         struct completion       trd_starting;
809         struct completion       trd_finishing;
810 };
811
812 struct obd_llog_group {
813         int             olg_seq;
814         struct llog_ctxt  *olg_ctxts[LLOG_MAX_CTXTS];
815         wait_queue_head_t       olg_waitq;
816         spinlock_t         olg_lock;
817         struct mutex       olg_cat_processing;
818 };
819
820 /* corresponds to one of the obd's */
821 #define OBD_DEVICE_MAGIC        0XAB5CD6EF
822 #define OBD_DEV_BY_DEVNAME      0xffffd0de
823
824 struct obd_device {
825         struct obd_type *obd_type;
826         __u32              obd_magic;
827
828         /* common and UUID name of this device */
829         char                obd_name[MAX_OBD_NAME];
830         struct obd_uuid  obd_uuid;
831
832         struct lu_device       *obd_lu_dev;
833
834         int                  obd_minor;
835         /* bitfield modification is protected by obd_dev_lock */
836         unsigned long obd_attached:1,      /* finished attach */
837                       obd_set_up:1,     /* finished setup */
838                       obd_recovering:1,    /* there are recoverable clients */
839                       obd_abort_recovery:1,/* recovery expired */
840                       obd_version_recov:1, /* obd uses version checking */
841                       obd_replayable:1,    /* recovery is enabled; inform clients */
842                       obd_no_transno:1,    /* no committed-transno notification */
843                       obd_no_recov:1,      /* fail instead of retry messages */
844                       obd_stopping:1,      /* started cleanup */
845                       obd_starting:1,      /* started setup */
846                       obd_force:1,       /* cleanup with > 0 obd refcount */
847                       obd_fail:1,         /* cleanup with failover */
848                       obd_async_recov:1,   /* allow asynchronous orphan cleanup */
849                       obd_no_conn:1,       /* deny new connections */
850                       obd_inactive:1,      /* device active/inactive
851                                            * (for /proc/status only!!) */
852                       obd_no_ir:1,       /* no imperative recovery. */
853                       obd_process_conf:1;  /* device is processing mgs config */
854         /* use separate field as it is set in interrupt to don't mess with
855          * protection of other bits using _bh lock */
856         unsigned long obd_recovery_expired:1;
857         /* uuid-export hash body */
858         struct cfs_hash      *obd_uuid_hash;
859         /* nid-export hash body */
860         struct cfs_hash      *obd_nid_hash;
861         /* nid stats body */
862         struct cfs_hash      *obd_nid_stats_hash;
863         struct list_head              obd_nid_stats;
864         atomic_t            obd_refcount;
865         wait_queue_head_t            obd_refcount_waitq;
866         struct list_head              obd_exports;
867         struct list_head              obd_unlinked_exports;
868         struct list_head              obd_delayed_exports;
869         int                  obd_num_exports;
870         spinlock_t              obd_nid_lock;
871         struct ldlm_namespace  *obd_namespace;
872         struct ptlrpc_client    obd_ldlm_client; /* XXX OST/MDS only */
873         /* a spinlock is OK for what we do now, may need a semaphore later */
874         spinlock_t              obd_dev_lock; /* protect OBD bitfield above */
875         struct mutex            obd_dev_mutex;
876         __u64                   obd_last_committed;
877         struct fsfilt_operations *obd_fsops;
878         spinlock_t              obd_osfs_lock;
879         struct obd_statfs       obd_osfs;       /* locked by obd_osfs_lock */
880         __u64                   obd_osfs_age;
881         struct lvfs_run_ctxt    obd_lvfs_ctxt;
882         struct obd_llog_group   obd_olg;        /* default llog group */
883         struct obd_device       *obd_observer;
884         struct rw_semaphore     obd_observer_link_sem;
885         struct obd_notify_upcall obd_upcall;
886         struct obd_export       *obd_self_export;
887         /* list of exports in LRU order, for ping evictor, with obd_dev_lock */
888         struct list_head              obd_exports_timed;
889         time_t            obd_eviction_timer; /* for ping evictor */
890
891         int                           obd_max_recoverable_clients;
892         atomic_t                     obd_connected_clients;
893         int                           obd_stale_clients;
894         int                           obd_delayed_clients;
895         /* this lock protects all recovery list_heads, timer and
896          * obd_next_recovery_transno value */
897         spinlock_t                       obd_recovery_task_lock;
898         __u64                       obd_next_recovery_transno;
899         int                           obd_replayed_requests;
900         int                           obd_requests_queued_for_recovery;
901         wait_queue_head_t                     obd_next_transno_waitq;
902         /* protected by obd_recovery_task_lock */
903         struct timer_list             obd_recovery_timer;
904         time_t                     obd_recovery_start; /* seconds */
905         time_t                     obd_recovery_end; /* seconds, for lprocfs_status */
906         int                           obd_recovery_time_hard;
907         int                           obd_recovery_timeout;
908         int                           obd_recovery_ir_factor;
909
910         /* new recovery stuff from CMD2 */
911         struct target_recovery_data      obd_recovery_data;
912         int                           obd_replayed_locks;
913         atomic_t                     obd_req_replay_clients;
914         atomic_t                     obd_lock_replay_clients;
915         /* all lists are protected by obd_recovery_task_lock */
916         struct list_head                       obd_req_replay_queue;
917         struct list_head                       obd_lock_replay_queue;
918         struct list_head                       obd_final_req_queue;
919         int                           obd_recovery_stage;
920
921         union {
922                 struct client_obd cli;
923                 struct echo_client_obd echo_client;
924                 struct lov_obd lov;
925                 struct lmv_obd lmv;
926         } u;
927         /* Fields used by LProcFS */
928         unsigned int       obd_cntr_base;
929         struct lprocfs_stats  *obd_stats;
930
931         unsigned int       md_cntr_base;
932         struct lprocfs_stats  *md_stats;
933
934         struct proc_dir_entry  *obd_proc_entry;
935         void              *obd_proc_private; /* type private PDEs */
936         struct proc_dir_entry  *obd_proc_exports_entry;
937         struct proc_dir_entry  *obd_svc_procroot;
938         struct lprocfs_stats  *obd_svc_stats;
939         atomic_t           obd_evict_inprogress;
940         wait_queue_head_t           obd_evict_inprogress_waitq;
941         struct list_head             obd_evict_list; /* protected with pet_lock */
942
943         /**
944          * Ldlm pool part. Save last calculated SLV and Limit.
945          */
946         rwlock_t                obd_pool_lock;
947         int                 obd_pool_limit;
948         __u64             obd_pool_slv;
949
950         /**
951          * A list of outstanding class_incref()'s against this obd. For
952          * debugging.
953          */
954         struct lu_ref     obd_reference;
955
956         int                    obd_conn_inprogress;
957 };
958
959 #define OBD_LLOG_FL_SENDNOW     0x0001
960 #define OBD_LLOG_FL_EXIT        0x0002
961
962 enum obd_cleanup_stage {
963 /* Special case hack for MDS LOVs */
964         OBD_CLEANUP_EARLY,
965 /* can be directly mapped to .ldto_device_fini() */
966         OBD_CLEANUP_EXPORTS,
967 };
968
969 /* get/set_info keys */
970 #define KEY_ASYNC              "async"
971 #define KEY_BLOCKSIZE_BITS      "blocksize_bits"
972 #define KEY_BLOCKSIZE      "blocksize"
973 #define KEY_CAPA_KEY        "capa_key"
974 #define KEY_CHANGELOG_CLEAR     "changelog_clear"
975 #define KEY_FID2PATH        "fid2path"
976 #define KEY_CHECKSUM        "checksum"
977 #define KEY_CLEAR_FS        "clear_fs"
978 #define KEY_CONN_DATA      "conn_data"
979 #define KEY_EVICT_BY_NID        "evict_by_nid"
980 #define KEY_FIEMAP            "fiemap"
981 #define KEY_FLUSH_CTX      "flush_ctx"
982 #define KEY_GRANT_SHRINK        "grant_shrink"
983 #define KEY_HSM_COPYTOOL_SEND   "hsm_send"
984 #define KEY_INIT_RECOV_BACKUP   "init_recov_bk"
985 #define KEY_INIT_RECOV    "initial_recov"
986 #define KEY_INTERMDS        "inter_mds"
987 #define KEY_LAST_ID          "last_id"
988 #define KEY_LAST_FID            "last_fid"
989 #define KEY_LOCK_TO_STRIPE      "lock_to_stripe"
990 #define KEY_LOVDESC          "lovdesc"
991 #define KEY_LOV_IDX          "lov_idx"
992 #define KEY_MAX_EASIZE    "max_easize"
993 #define KEY_MDS_CONN        "mds_conn"
994 #define KEY_MGSSEC            "mgssec"
995 #define KEY_NEXT_ID          "next_id"
996 #define KEY_READ_ONLY      "read-only"
997 #define KEY_REGISTER_TARGET     "register_target"
998 #define KEY_SET_FS            "set_fs"
999 #define KEY_TGT_COUNT      "tgt_count"
1000 /*      KEY_SET_INFO in lustre_idl.h */
1001 #define KEY_SPTLRPC_CONF        "sptlrpc_conf"
1002 #define KEY_CONNECT_FLAG        "connect_flags"
1003 #define KEY_SYNC_LOCK_CANCEL    "sync_lock_cancel"
1004
1005 #define KEY_CACHE_SET           "cache_set"
1006 #define KEY_CACHE_LRU_SHRINK    "cache_lru_shrink"
1007 #define KEY_CHANGELOG_INDEX     "changelog_index"
1008
1009 struct lu_context;
1010
1011 /* /!\ must be coherent with include/linux/namei.h on patched kernel */
1012 #define IT_OPEN     (1 << 0)
1013 #define IT_CREAT    (1 << 1)
1014 #define IT_READDIR  (1 << 2)
1015 #define IT_GETATTR  (1 << 3)
1016 #define IT_LOOKUP   (1 << 4)
1017 #define IT_UNLINK   (1 << 5)
1018 #define IT_TRUNC    (1 << 6)
1019 #define IT_GETXATTR (1 << 7)
1020 #define IT_EXEC     (1 << 8)
1021 #define IT_PIN      (1 << 9)
1022 #define IT_LAYOUT   (1 << 10)
1023 #define IT_QUOTA_DQACQ (1 << 11)
1024 #define IT_QUOTA_CONN  (1 << 12)
1025
1026 static inline int it_to_lock_mode(struct lookup_intent *it)
1027 {
1028         /* CREAT needs to be tested before open (both could be set) */
1029         if (it->it_op & IT_CREAT)
1030                 return LCK_CW;
1031         else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_LOOKUP |
1032                               IT_LAYOUT))
1033                 return LCK_CR;
1034
1035         LASSERTF(0, "Invalid it_op: %d\n", it->it_op);
1036         return -EINVAL;
1037 }
1038
1039 struct md_op_data {
1040         struct lu_fid      op_fid1; /* operation fid1 (usualy parent) */
1041         struct lu_fid      op_fid2; /* operation fid2 (usualy child) */
1042         struct lu_fid      op_fid3; /* 2 extra fids to find conflicting */
1043         struct lu_fid      op_fid4; /* to the operation locks. */
1044         mdsno_t          op_mds;  /* what mds server open will go to */
1045         struct lustre_handle    op_handle;
1046         obd_time                op_mod_time;
1047         const char           *op_name;
1048         int                  op_namelen;
1049         __u32              op_mode;
1050         struct lmv_stripe_md   *op_mea1;
1051         struct lmv_stripe_md   *op_mea2;
1052         __u32              op_suppgids[2];
1053         __u32              op_fsuid;
1054         __u32              op_fsgid;
1055         cfs_cap_t              op_cap;
1056         void               *op_data;
1057
1058         /* iattr fields and blocks. */
1059         struct iattr        op_attr;
1060         unsigned int        op_attr_flags;
1061         __u64              op_valid;
1062         loff_t            op_attr_blocks;
1063
1064         /* Size-on-MDS epoch and flags. */
1065         __u64              op_ioepoch;
1066         __u32              op_flags;
1067
1068         /* Capa fields */
1069         struct obd_capa *op_capa1;
1070         struct obd_capa *op_capa2;
1071
1072         /* Various operation flags. */
1073         enum mds_op_bias        op_bias;
1074
1075         /* Operation type */
1076         __u32              op_opc;
1077
1078         /* Used by readdir */
1079         __u64              op_offset;
1080
1081         /* Used by readdir */
1082         __u32              op_npages;
1083
1084         /* used to transfer info between the stacks of MD client
1085          * see enum op_cli_flags */
1086         __u32                   op_cli_flags;
1087
1088         /* File object data version for HSM release, on client */
1089         __u64                   op_data_version;
1090         struct lustre_handle    op_lease_handle;
1091 };
1092
1093 enum op_cli_flags {
1094         CLI_SET_MEA     = 1 << 0,
1095         CLI_RM_ENTRY    = 1 << 1,
1096 };
1097
1098 struct md_enqueue_info;
1099 /* metadata stat-ahead */
1100 typedef int (* md_enqueue_cb_t)(struct ptlrpc_request *req,
1101                                 struct md_enqueue_info *minfo,
1102                                 int rc);
1103
1104 struct md_enqueue_info {
1105         struct md_op_data       mi_data;
1106         struct lookup_intent    mi_it;
1107         struct lustre_handle    mi_lockh;
1108         struct inode       *mi_dir;
1109         md_enqueue_cb_t  mi_cb;
1110         __u64              mi_cbdata;
1111         unsigned int        mi_generation;
1112 };
1113
1114 struct obd_ops {
1115         struct module *o_owner;
1116         int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
1117                            void *karg, void *uarg);
1118         int (*o_get_info)(const struct lu_env *env, struct obd_export *,
1119                           __u32 keylen, void *key, __u32 *vallen, void *val,
1120                           struct lov_stripe_md *lsm);
1121         int (*o_set_info_async)(const struct lu_env *, struct obd_export *,
1122                                 __u32 keylen, void *key,
1123                                 __u32 vallen, void *val,
1124                                 struct ptlrpc_request_set *set);
1125         int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
1126         int (*o_detach)(struct obd_device *dev);
1127         int (*o_setup) (struct obd_device *dev, struct lustre_cfg *cfg);
1128         int (*o_precleanup)(struct obd_device *dev,
1129                             enum obd_cleanup_stage cleanup_stage);
1130         int (*o_cleanup)(struct obd_device *dev);
1131         int (*o_process_config)(struct obd_device *dev, obd_count len,
1132                                 void *data);
1133         int (*o_postrecov)(struct obd_device *dev);
1134         int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
1135                           int priority);
1136         int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
1137         /* connect to the target device with given connection
1138          * data. @ocd->ocd_connect_flags is modified to reflect flags actually
1139          * granted by the target, which are guaranteed to be a subset of flags
1140          * asked for. If @ocd == NULL, use default parameters. */
1141         int (*o_connect)(const struct lu_env *env,
1142                          struct obd_export **exp, struct obd_device *src,
1143                          struct obd_uuid *cluuid, struct obd_connect_data *ocd,
1144                          void *localdata);
1145         int (*o_reconnect)(const struct lu_env *env,
1146                            struct obd_export *exp, struct obd_device *src,
1147                            struct obd_uuid *cluuid,
1148                            struct obd_connect_data *ocd,
1149                            void *localdata);
1150         int (*o_disconnect)(struct obd_export *exp);
1151
1152         /* Initialize/finalize fids infrastructure. */
1153         int (*o_fid_init)(struct obd_device *obd,
1154                           struct obd_export *exp, enum lu_cli_type type);
1155         int (*o_fid_fini)(struct obd_device *obd);
1156
1157         /* Allocate new fid according to passed @hint. */
1158         int (*o_fid_alloc)(struct obd_export *exp, struct lu_fid *fid,
1159                            struct md_op_data *op_data);
1160
1161         /*
1162          * Object with @fid is getting deleted, we may want to do something
1163          * about this.
1164          */
1165         int (*o_statfs)(const struct lu_env *, struct obd_export *exp,
1166                         struct obd_statfs *osfs, __u64 max_age, __u32 flags);
1167         int (*o_statfs_async)(struct obd_export *exp, struct obd_info *oinfo,
1168                               __u64 max_age, struct ptlrpc_request_set *set);
1169         int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
1170                         struct lov_stripe_md *mem_src);
1171         int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
1172                           struct lov_mds_md *disk_src, int disk_len);
1173         int (*o_preallocate)(struct lustre_handle *, obd_count *req,
1174                              obd_id *ids);
1175         /* FIXME: add fid capability support for create & destroy! */
1176         int (*o_precreate)(struct obd_export *exp);
1177         int (*o_create)(const struct lu_env *env, struct obd_export *exp,
1178                         struct obdo *oa, struct lov_stripe_md **ea,
1179                         struct obd_trans_info *oti);
1180         int (*o_create_async)(struct obd_export *exp,  struct obd_info *oinfo,
1181                               struct lov_stripe_md **ea,
1182                               struct obd_trans_info *oti);
1183         int (*o_destroy)(const struct lu_env *env, struct obd_export *exp,
1184                          struct obdo *oa, struct lov_stripe_md *ea,
1185                          struct obd_trans_info *oti, struct obd_export *md_exp,
1186                          void *capa);
1187         int (*o_setattr)(const struct lu_env *, struct obd_export *exp,
1188                          struct obd_info *oinfo, struct obd_trans_info *oti);
1189         int (*o_setattr_async)(struct obd_export *exp, struct obd_info *oinfo,
1190                                struct obd_trans_info *oti,
1191                                struct ptlrpc_request_set *rqset);
1192         int (*o_getattr)(const struct lu_env *env, struct obd_export *exp,
1193                          struct obd_info *oinfo);
1194         int (*o_getattr_async)(struct obd_export *exp, struct obd_info *oinfo,
1195                                struct ptlrpc_request_set *set);
1196         int (*o_brw)(int rw, struct obd_export *exp, struct obd_info *oinfo,
1197                      obd_count oa_bufs, struct brw_page *pgarr,
1198                      struct obd_trans_info *oti);
1199         int (*o_merge_lvb)(struct obd_export *exp, struct lov_stripe_md *lsm,
1200                            struct ost_lvb *lvb, int kms_only);
1201         int (*o_adjust_kms)(struct obd_export *exp, struct lov_stripe_md *lsm,
1202                             obd_off size, int shrink);
1203         int (*o_punch)(const struct lu_env *, struct obd_export *exp,
1204                        struct obd_info *oinfo, struct obd_trans_info *oti,
1205                        struct ptlrpc_request_set *rqset);
1206         int (*o_sync)(const struct lu_env *env, struct obd_export *exp,
1207                       struct obd_info *oinfo, obd_size start, obd_size end,
1208                       struct ptlrpc_request_set *set);
1209         int (*o_migrate)(struct lustre_handle *conn, struct lov_stripe_md *dst,
1210                          struct lov_stripe_md *src, obd_size start,
1211                          obd_size end, struct obd_trans_info *oti);
1212         int (*o_copy)(struct lustre_handle *dstconn, struct lov_stripe_md *dst,
1213                       struct lustre_handle *srconn, struct lov_stripe_md *src,
1214                       obd_size start, obd_size end, struct obd_trans_info *);
1215         int (*o_iterate)(struct lustre_handle *conn,
1216                          int (*)(obd_id, obd_seq, void *),
1217                          obd_id *startid, obd_seq seq, void *data);
1218         int (*o_preprw)(const struct lu_env *env, int cmd,
1219                         struct obd_export *exp, struct obdo *oa, int objcount,
1220                         struct obd_ioobj *obj, struct niobuf_remote *remote,
1221                         int *nr_pages, struct niobuf_local *local,
1222                         struct obd_trans_info *oti, struct lustre_capa *capa);
1223         int (*o_commitrw)(const struct lu_env *env, int cmd,
1224                           struct obd_export *exp, struct obdo *oa,
1225                           int objcount, struct obd_ioobj *obj,
1226                           struct niobuf_remote *remote, int pages,
1227                           struct niobuf_local *local,
1228                           struct obd_trans_info *oti, int rc);
1229         int (*o_enqueue)(struct obd_export *, struct obd_info *oinfo,
1230                          struct ldlm_enqueue_info *einfo,
1231                          struct ptlrpc_request_set *rqset);
1232         int (*o_change_cbdata)(struct obd_export *, struct lov_stripe_md *,
1233                                ldlm_iterator_t it, void *data);
1234         int (*o_find_cbdata)(struct obd_export *, struct lov_stripe_md *,
1235                              ldlm_iterator_t it, void *data);
1236         int (*o_cancel)(struct obd_export *, struct lov_stripe_md *md,
1237                         __u32 mode, struct lustre_handle *);
1238         int (*o_cancel_unused)(struct obd_export *, struct lov_stripe_md *,
1239                                ldlm_cancel_flags_t flags, void *opaque);
1240         int (*o_init_export)(struct obd_export *exp);
1241         int (*o_destroy_export)(struct obd_export *exp);
1242         int (*o_extent_calc)(struct obd_export *, struct lov_stripe_md *,
1243                              int cmd, obd_off *);
1244
1245         /* llog related obd_methods */
1246         int (*o_llog_init)(struct obd_device *obd, struct obd_llog_group *grp,
1247                            struct obd_device *disk_obd, int *idx);
1248         int (*o_llog_finish)(struct obd_device *obd, int count);
1249         int (*o_llog_connect)(struct obd_export *, struct llogd_conn_body *);
1250
1251         /* metadata-only methods */
1252         int (*o_pin)(struct obd_export *, const struct lu_fid *fid,
1253                      struct obd_capa *, struct obd_client_handle *, int flag);
1254         int (*o_unpin)(struct obd_export *, struct obd_client_handle *, int);
1255
1256         int (*o_import_event)(struct obd_device *, struct obd_import *,
1257                               enum obd_import_event);
1258
1259         int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
1260                         enum obd_notify_event ev, void *data);
1261
1262         int (*o_health_check)(const struct lu_env *env, struct obd_device *);
1263         struct obd_uuid *(*o_get_uuid) (struct obd_export *exp);
1264
1265         /* quota methods */
1266         int (*o_quotacheck)(struct obd_device *, struct obd_export *,
1267                             struct obd_quotactl *);
1268         int (*o_quotactl)(struct obd_device *, struct obd_export *,
1269                           struct obd_quotactl *);
1270
1271         int (*o_ping)(const struct lu_env *, struct obd_export *exp);
1272
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          * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
1284          * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
1285          * Also, add a wrapper function in include/linux/obd_class.h. */
1286 };
1287
1288 enum {
1289         LUSTRE_OPC_MKDIR    = (1 << 0),
1290         LUSTRE_OPC_SYMLINK  = (1 << 1),
1291         LUSTRE_OPC_MKNOD    = (1 << 2),
1292         LUSTRE_OPC_CREATE   = (1 << 3),
1293         LUSTRE_OPC_ANY      = (1 << 4)
1294 };
1295
1296 /* lmv structures */
1297 #define MEA_MAGIC_LAST_CHAR      0xb2221ca1
1298 #define MEA_MAGIC_ALL_CHARS      0xb222a11c
1299 #define MEA_MAGIC_HASH_SEGMENT   0xb222a11b
1300
1301 #define MAX_HASH_SIZE_32         0x7fffffffUL
1302 #define MAX_HASH_SIZE       0x7fffffffffffffffULL
1303 #define MAX_HASH_HIGHEST_BIT     0x1000000000000000ULL
1304
1305 struct lustre_md {
1306         struct mdt_body  *body;
1307         struct lov_stripe_md    *lsm;
1308         struct lmv_stripe_md    *mea;
1309 #ifdef CONFIG_FS_POSIX_ACL
1310         struct posix_acl        *posix_acl;
1311 #endif
1312         struct mdt_remote_perm  *remote_perm;
1313         struct obd_capa  *mds_capa;
1314         struct obd_capa  *oss_capa;
1315 };
1316
1317 struct md_open_data {
1318         struct obd_client_handle *mod_och;
1319         struct ptlrpc_request    *mod_open_req;
1320         struct ptlrpc_request    *mod_close_req;
1321         atomic_t              mod_refcount;
1322 };
1323
1324 struct lookup_intent;
1325
1326 struct md_ops {
1327         int (*m_getstatus)(struct obd_export *, struct lu_fid *,
1328                            struct obd_capa **);
1329         int (*m_null_inode)(struct obd_export *, const struct lu_fid *);
1330         int (*m_find_cbdata)(struct obd_export *, const struct lu_fid *,
1331                              ldlm_iterator_t, void *);
1332         int (*m_close)(struct obd_export *, struct md_op_data *,
1333                        struct md_open_data *, struct ptlrpc_request **);
1334         int (*m_create)(struct obd_export *, struct md_op_data *,
1335                         const void *, int, int, __u32, __u32, cfs_cap_t,
1336                         __u64, struct ptlrpc_request **);
1337         int (*m_done_writing)(struct obd_export *, struct md_op_data  *,
1338                               struct md_open_data *);
1339         int (*m_enqueue)(struct obd_export *, struct ldlm_enqueue_info *,
1340                          struct lookup_intent *, struct md_op_data *,
1341                          struct lustre_handle *, void *, int,
1342                          struct ptlrpc_request **, __u64);
1343         int (*m_getattr)(struct obd_export *, struct md_op_data *,
1344                          struct ptlrpc_request **);
1345         int (*m_getattr_name)(struct obd_export *, struct md_op_data *,
1346                               struct ptlrpc_request **);
1347         int (*m_intent_lock)(struct obd_export *, struct md_op_data *,
1348                              void *, int, struct lookup_intent *, int,
1349                              struct ptlrpc_request **,
1350                              ldlm_blocking_callback, __u64);
1351         int (*m_link)(struct obd_export *, struct md_op_data *,
1352                       struct ptlrpc_request **);
1353         int (*m_rename)(struct obd_export *, struct md_op_data *,
1354                         const char *, int, const char *, int,
1355                         struct ptlrpc_request **);
1356         int (*m_is_subdir)(struct obd_export *, const struct lu_fid *,
1357                            const struct lu_fid *,
1358                            struct ptlrpc_request **);
1359         int (*m_setattr)(struct obd_export *, struct md_op_data *, void *,
1360                          int , void *, int, struct ptlrpc_request **,
1361                          struct md_open_data **mod);
1362         int (*m_sync)(struct obd_export *, const struct lu_fid *,
1363                       struct obd_capa *, struct ptlrpc_request **);
1364         int (*m_readpage)(struct obd_export *, struct md_op_data *,
1365                           struct page **, struct ptlrpc_request **);
1366
1367         int (*m_unlink)(struct obd_export *, struct md_op_data *,
1368                         struct ptlrpc_request **);
1369
1370         int (*m_setxattr)(struct obd_export *, const struct lu_fid *,
1371                           struct obd_capa *, obd_valid, const char *,
1372                           const char *, int, int, int, __u32,
1373                           struct ptlrpc_request **);
1374
1375         int (*m_getxattr)(struct obd_export *, const struct lu_fid *,
1376                           struct obd_capa *, obd_valid, const char *,
1377                           const char *, int, int, int,
1378                           struct ptlrpc_request **);
1379
1380         int (*m_init_ea_size)(struct obd_export *, int, int, int);
1381
1382         int (*m_get_lustre_md)(struct obd_export *, struct ptlrpc_request *,
1383                                struct obd_export *, struct obd_export *,
1384                                struct lustre_md *);
1385
1386         int (*m_free_lustre_md)(struct obd_export *, struct lustre_md *);
1387
1388         int (*m_set_open_replay_data)(struct obd_export *,
1389                                       struct obd_client_handle *,
1390                                       struct ptlrpc_request *);
1391         int (*m_clear_open_replay_data)(struct obd_export *,
1392                                         struct obd_client_handle *);
1393         int (*m_set_lock_data)(struct obd_export *, __u64 *, void *, __u64 *);
1394
1395         ldlm_mode_t (*m_lock_match)(struct obd_export *, __u64,
1396                                     const struct lu_fid *, ldlm_type_t,
1397                                     ldlm_policy_data_t *, ldlm_mode_t,
1398                                     struct lustre_handle *);
1399
1400         int (*m_cancel_unused)(struct obd_export *, const struct lu_fid *,
1401                                ldlm_policy_data_t *, ldlm_mode_t,
1402                                ldlm_cancel_flags_t flags, void *opaque);
1403         int (*m_renew_capa)(struct obd_export *, struct obd_capa *oc,
1404                             renew_capa_cb_t cb);
1405         int (*m_unpack_capa)(struct obd_export *, struct ptlrpc_request *,
1406                              const struct req_msg_field *, struct obd_capa **);
1407
1408         int (*m_get_remote_perm)(struct obd_export *, const struct lu_fid *,
1409                                  struct obd_capa *, __u32,
1410                                  struct ptlrpc_request **);
1411
1412         int (*m_intent_getattr_async)(struct obd_export *,
1413                                       struct md_enqueue_info *,
1414                                       struct ldlm_enqueue_info *);
1415
1416         int (*m_revalidate_lock)(struct obd_export *, struct lookup_intent *,
1417                                  struct lu_fid *, __u64 *bits);
1418
1419         /*
1420          * NOTE: If adding ops, add another LPROCFS_MD_OP_INIT() line to
1421          * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
1422          * wrapper function in include/linux/obd_class.h.
1423          */
1424 };
1425
1426 struct lsm_operations {
1427         void (*lsm_free)(struct lov_stripe_md *);
1428         int (*lsm_destroy)(struct lov_stripe_md *, struct obdo *oa,
1429                            struct obd_export *md_exp);
1430         void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *, obd_off *,
1431                                     obd_off *);
1432         void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *, obd_off *,
1433                                      obd_off *);
1434         int (*lsm_lmm_verify) (struct lov_mds_md *lmm, int lmm_bytes,
1435                                __u16 *stripe_count);
1436         int (*lsm_unpackmd) (struct lov_obd *lov, struct lov_stripe_md *lsm,
1437                              struct lov_mds_md *lmm);
1438 };
1439
1440 extern const struct lsm_operations lsm_v1_ops;
1441 extern const struct lsm_operations lsm_v3_ops;
1442 static inline const struct lsm_operations *lsm_op_find(int magic)
1443 {
1444         switch(magic) {
1445         case LOV_MAGIC_V1:
1446                return &lsm_v1_ops;
1447         case LOV_MAGIC_V3:
1448                return &lsm_v3_ops;
1449         default:
1450                CERROR("Cannot recognize lsm_magic %08x\n", magic);
1451                return NULL;
1452         }
1453 }
1454
1455 /* Requests for obd_extent_calc() */
1456 #define OBD_CALC_STRIPE_START   1
1457 #define OBD_CALC_STRIPE_END     2
1458
1459 static inline struct lustre_capa *oinfo_capa(struct obd_info *oinfo)
1460 {
1461         return oinfo->oi_capa;
1462 }
1463
1464 static inline struct md_open_data *obd_mod_alloc(void)
1465 {
1466         struct md_open_data *mod;
1467         OBD_ALLOC_PTR(mod);
1468         if (mod == NULL)
1469                 return NULL;
1470         atomic_set(&mod->mod_refcount, 1);
1471         return mod;
1472 }
1473
1474 #define obd_mod_get(mod) atomic_inc(&(mod)->mod_refcount)
1475 #define obd_mod_put(mod)                                        \
1476 ({                                                            \
1477         if (atomic_dec_and_test(&(mod)->mod_refcount)) {          \
1478                 if ((mod)->mod_open_req)                          \
1479                         ptlrpc_req_finished((mod)->mod_open_req);   \
1480                 OBD_FREE_PTR(mod);                            \
1481         }                                                      \
1482 })
1483
1484 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
1485 void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent);
1486
1487 /* return 1 if client should be resend request */
1488 static inline int client_should_resend(int resend, struct client_obd *cli)
1489 {
1490         return atomic_read(&cli->cl_resends) ?
1491                atomic_read(&cli->cl_resends) > resend : 1;
1492 }
1493
1494 /**
1495  * Return device name for this device
1496  *
1497  * XXX: lu_device is declared before obd_device, while a pointer pointing
1498  * back to obd_device in lu_device, so this helper function defines here
1499  * instead of in lu_object.h
1500  */
1501 static inline const char *lu_dev_name(const struct lu_device *lu_dev)
1502 {
1503         return lu_dev->ld_obd->obd_name;
1504 }
1505
1506 static inline bool filename_is_volatile(const char *name, int namelen, int *idx)
1507 {
1508         const char      *start;
1509         char            *end;
1510
1511         if (strncmp(name, LUSTRE_VOLATILE_HDR, LUSTRE_VOLATILE_HDR_LEN) != 0)
1512                 return false;
1513
1514         /* caller does not care of idx */
1515         if (idx == NULL)
1516                 return true;
1517
1518         /* volatile file, the MDT can be set from name */
1519         /* name format is LUSTRE_VOLATILE_HDR:[idx]: */
1520         /* if no MDT is specified, use std way */
1521         if (namelen < LUSTRE_VOLATILE_HDR_LEN + 2)
1522                 goto bad_format;
1523         /* test for no MDT idx case */
1524         if ((*(name + LUSTRE_VOLATILE_HDR_LEN) == ':') &&
1525             (*(name + LUSTRE_VOLATILE_HDR_LEN + 1) == ':')) {
1526                 *idx = -1;
1527                 return true;
1528         }
1529         /* we have an idx, read it */
1530         start = name + LUSTRE_VOLATILE_HDR_LEN + 1;
1531         *idx = strtoul(start, &end, 0);
1532         /* error cases:
1533          * no digit, no trailing :, negative value
1534          */
1535         if (((*idx == 0) && (end == start)) ||
1536             (*end != ':') || (*idx < 0))
1537                 goto bad_format;
1538
1539         return true;
1540 bad_format:
1541         /* bad format of mdt idx, we cannot return an error
1542          * to caller so we use hash algo */
1543         CERROR("Bad volatile file name format: %s\n",
1544                name + LUSTRE_VOLATILE_HDR_LEN);
1545         return false;
1546 }
1547
1548 static inline int cli_brw_size(struct obd_device *obd)
1549 {
1550         LASSERT(obd != NULL);
1551         return obd->u.cli.cl_max_pages_per_rpc << PAGE_CACHE_SHIFT;
1552 }
1553
1554 #endif /* __OBD_H */