]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/lustre/lustre/include/obd.h
staging/lustre: Get rid of client_obd_lock_t typedef
[karo-tx-linux.git] / 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, 2015, 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 "lu_ref.h"
54 #include "lustre_export.h"
55 #include "lustre_fid.h"
56 #include "lustre_fld.h"
57
58 #define MAX_OBD_DEVICES 8192
59
60 struct osc_async_rc {
61         int     ar_rc;
62         int     ar_force_sync;
63         __u64   ar_min_xid;
64 };
65
66 struct lov_oinfo {               /* per-stripe data structure */
67         struct ost_id   loi_oi;    /* object ID/Sequence on the target OST */
68         int loi_ost_idx;           /* OST stripe index in lov_tgt_desc->tgts */
69         int loi_ost_gen;           /* generation of this loi_ost_idx */
70
71         unsigned long loi_kms_valid:1;
72         __u64 loi_kms;       /* known minimum size */
73         struct ost_lvb loi_lvb;
74         struct osc_async_rc     loi_ar;
75 };
76
77 static inline void loi_kms_set(struct lov_oinfo *oinfo, __u64 kms)
78 {
79         oinfo->loi_kms = kms;
80         oinfo->loi_kms_valid = 1;
81 }
82
83 static inline void loi_init(struct lov_oinfo *loi)
84 {
85 }
86
87 struct lov_stripe_md {
88         atomic_t     lsm_refc;
89         spinlock_t      lsm_lock;
90         pid_t       lsm_lock_owner; /* debugging */
91
92         /* maximum possible file size, might change as OSTs status changes,
93          * e.g. disconnected, deactivated */
94         __u64       lsm_maxbytes;
95         struct {
96                 /* Public members. */
97                 struct ost_id lw_object_oi; /* lov object id/seq */
98
99                 /* LOV-private members start here -- only for use in lov/. */
100                 __u32 lw_magic;
101                 __u32 lw_stripe_size;      /* size of the stripe */
102                 __u32 lw_pattern;         /* striping pattern (RAID0, RAID1) */
103                 __u16 lw_stripe_count;  /* number of objects being striped over */
104                 __u16 lw_layout_gen;       /* generation of the layout */
105                 char  lw_pool_name[LOV_MAXPOOLNAME]; /* pool name */
106         } lsm_wire;
107
108         struct lov_oinfo *lsm_oinfo[0];
109 };
110
111 #define lsm_oi           lsm_wire.lw_object_oi
112 #define lsm_magic       lsm_wire.lw_magic
113 #define lsm_layout_gen   lsm_wire.lw_layout_gen
114 #define lsm_stripe_size  lsm_wire.lw_stripe_size
115 #define lsm_pattern      lsm_wire.lw_pattern
116 #define lsm_stripe_count lsm_wire.lw_stripe_count
117 #define lsm_pool_name    lsm_wire.lw_pool_name
118
119 static inline bool lsm_is_released(struct lov_stripe_md *lsm)
120 {
121         return !!(lsm->lsm_pattern & LOV_PATTERN_F_RELEASED);
122 }
123
124 static inline bool lsm_has_objects(struct lov_stripe_md *lsm)
125 {
126         if (!lsm)
127                 return false;
128         if (lsm_is_released(lsm))
129                 return false;
130         return true;
131 }
132
133 static inline int lov_stripe_md_size(unsigned int stripe_count)
134 {
135         struct lov_stripe_md lsm;
136
137         return sizeof(lsm) + stripe_count * sizeof(lsm.lsm_oinfo[0]);
138 }
139
140 struct obd_info;
141
142 typedef int (*obd_enqueue_update_f)(void *cookie, int rc);
143
144 /* obd info for a particular level (lov, osc). */
145 struct obd_info {
146         /* Flags used for set request specific flags:
147            - while lock handling, the flags obtained on the enqueue
148            request are set here.
149            - while stats, the flags used for control delay/resend.
150            - while setattr, the flags used for distinguish punch operation
151          */
152         __u64              oi_flags;
153         /* lsm data specific for every OSC. */
154         struct lov_stripe_md   *oi_md;
155         /* obdo data specific for every OSC, if needed at all. */
156         struct obdo         *oi_oa;
157         /* statfs data specific for every OSC, if needed at all. */
158         struct obd_statfs      *oi_osfs;
159         /* An update callback which is called to update some data on upper
160          * level. E.g. it is used for update lsm->lsm_oinfo at every received
161          * request in osc level for enqueue requests. It is also possible to
162          * update some caller data from LOV layer if needed. */
163         obd_enqueue_update_f    oi_cb_up;
164 };
165
166 void lov_stripe_lock(struct lov_stripe_md *md);
167 void lov_stripe_unlock(struct lov_stripe_md *md);
168
169 struct obd_type {
170         struct list_head typ_chain;
171         struct obd_ops *typ_dt_ops;
172         struct md_ops *typ_md_ops;
173         struct dentry *typ_debugfs_entry;
174         char *typ_name;
175         int  typ_refcnt;
176         struct lu_device_type *typ_lu;
177         spinlock_t obd_type_lock;
178         struct kobject *typ_kobj;
179 };
180
181 struct brw_page {
182         u64 off;
183         struct page *pg;
184         int count;
185         u32 flag;
186 };
187
188 /* llog contexts */
189 enum llog_ctxt_id {
190         LLOG_CONFIG_ORIG_CTXT  =  0,
191         LLOG_CONFIG_REPL_CTXT,
192         LLOG_MDS_OST_ORIG_CTXT,
193         LLOG_MDS_OST_REPL_CTXT,
194         LLOG_SIZE_ORIG_CTXT,
195         LLOG_SIZE_REPL_CTXT,
196         LLOG_RD1_ORIG_CTXT,
197         LLOG_RD1_REPL_CTXT,
198         LLOG_TEST_ORIG_CTXT,
199         LLOG_TEST_REPL_CTXT,
200         LLOG_LOVEA_ORIG_CTXT,
201         LLOG_LOVEA_REPL_CTXT,
202         LLOG_CHANGELOG_ORIG_CTXT,       /**< changelog generation on mdd */
203         LLOG_CHANGELOG_REPL_CTXT,       /**< changelog access on clients */
204         LLOG_CHANGELOG_USER_ORIG_CTXT,  /**< for multiple changelog consumers */
205         LLOG_AGENT_ORIG_CTXT,           /**< agent requests generation on cdt */
206         LLOG_MAX_CTXTS
207 };
208
209 struct timeout_item {
210         enum timeout_event ti_event;
211         unsigned long    ti_timeout;
212         timeout_cb_t       ti_cb;
213         void          *ti_cb_data;
214         struct list_head         ti_obd_list;
215         struct list_head         ti_chain;
216 };
217
218 #define OSC_MAX_RIF_DEFAULT       8
219 #define OSC_MAX_RIF_MAX  256
220 #define OSC_MAX_DIRTY_DEFAULT  (OSC_MAX_RIF_DEFAULT * 4)
221 #define OSC_MAX_DIRTY_MB_MAX   2048     /* arbitrary, but < MAX_LONG bytes */
222 #define OSC_DEFAULT_RESENDS      10
223
224 /* possible values for fo_sync_lock_cancel */
225 enum {
226         NEVER_SYNC_ON_CANCEL = 0,
227         BLOCKING_SYNC_ON_CANCEL = 1,
228         ALWAYS_SYNC_ON_CANCEL = 2,
229         NUM_SYNC_ON_CANCEL_STATES
230 };
231
232 #define MDC_MAX_RIF_DEFAULT       8
233 #define MDC_MAX_RIF_MAX  512
234
235 struct mdc_rpc_lock;
236 struct obd_import;
237 struct client_obd {
238         struct rw_semaphore  cl_sem;
239         struct obd_uuid   cl_target_uuid;
240         struct obd_import       *cl_import; /* ptlrpc connection state */
241         int                   cl_conn_count;
242         /* max_mds_easize is purely a performance thing so we don't have to
243          * call obd_size_diskmd() all the time. */
244         int                      cl_default_mds_easize;
245         int                      cl_max_mds_easize;
246         int                      cl_default_mds_cookiesize;
247         int                      cl_max_mds_cookiesize;
248
249         enum lustre_sec_part     cl_sp_me;
250         enum lustre_sec_part     cl_sp_to;
251         struct sptlrpc_flavor    cl_flvr_mgc;   /* fixed flavor of mgc->mgs */
252
253         /* the grant values are protected by loi_list_lock below */
254         long                 cl_dirty;   /* all _dirty_ in bytes */
255         long                 cl_dirty_max;     /* allowed w/o rpc */
256         long                 cl_dirty_transit; /* dirty synchronous */
257         long                 cl_avail_grant;   /* bytes of credit for ost */
258         long                 cl_lost_grant;    /* lost credits (trunc) */
259
260         /* since we allocate grant by blocks, we don't know how many grant will
261          * be used to add a page into cache. As a solution, we reserve maximum
262          * grant before trying to dirty a page and unreserve the rest.
263          * See osc_{reserve|unreserve}_grant for details. */
264         long             cl_reserved_grant;
265         struct list_head cl_cache_waiters; /* waiting for cache/grant */
266         unsigned long    cl_next_shrink_grant;   /* jiffies */
267         struct list_head cl_grant_shrink_list;  /* Timeout event list */
268         int              cl_grant_shrink_interval; /* seconds */
269
270         /* A chunk is an optimal size used by osc_extent to determine
271          * the extent size. A chunk is max(PAGE_CACHE_SIZE, OST block size) */
272         int               cl_chunkbits;
273         int               cl_chunk;
274         int               cl_extent_tax; /* extent overhead, by bytes */
275
276         /* keep track of objects that have lois that contain pages which
277          * have been queued for async brw.  this lock also protects the
278          * lists of osc_client_pages that hang off of the loi */
279         /*
280          * ->cl_loi_list_lock protects consistency of
281          * ->cl_loi_{ready,read,write}_list. ->ap_make_ready() and
282          * ->ap_completion() call-backs are executed under this lock. As we
283          * cannot guarantee that these call-backs never block on all platforms
284          * (as a matter of fact they do block on Mac OS X), type of
285          * ->cl_loi_list_lock is platform dependent: it's a spin-lock on Linux
286          * and blocking mutex on Mac OS X. (Alternative is to make this lock
287          * blocking everywhere, but we don't want to slow down fast-path of
288          * our main platform.)
289          *
290          * Exact type of ->cl_loi_list_lock is defined in arch/obd.h together
291          * with client_obd_list_{un,}lock() and
292          * client_obd_list_lock_{init,done}() functions.
293          *
294          * NB by Jinshan: though field names are still _loi_, but actually
295          * osc_object{}s are in the list.
296          */
297         struct client_obd_lock         cl_loi_list_lock;
298         struct list_head               cl_loi_ready_list;
299         struct list_head               cl_loi_hp_ready_list;
300         struct list_head               cl_loi_write_list;
301         struct list_head               cl_loi_read_list;
302         int                   cl_r_in_flight;
303         int                   cl_w_in_flight;
304         /* just a sum of the loi/lop pending numbers to be exported by sysfs */
305         atomic_t             cl_pending_w_pages;
306         atomic_t             cl_pending_r_pages;
307         __u32                    cl_max_pages_per_rpc;
308         int                   cl_max_rpcs_in_flight;
309         struct obd_histogram     cl_read_rpc_hist;
310         struct obd_histogram     cl_write_rpc_hist;
311         struct obd_histogram     cl_read_page_hist;
312         struct obd_histogram     cl_write_page_hist;
313         struct obd_histogram     cl_read_offset_hist;
314         struct obd_histogram     cl_write_offset_hist;
315
316         /* lru for osc caching pages */
317         struct cl_client_cache  *cl_cache;
318         struct list_head         cl_lru_osc; /* member of cl_cache->ccc_lru */
319         atomic_t                *cl_lru_left;
320         atomic_t                 cl_lru_busy;
321         atomic_t                 cl_lru_shrinkers;
322         atomic_t                 cl_lru_in_list;
323         struct list_head         cl_lru_list; /* lru page list */
324         struct client_obd_lock   cl_lru_list_lock; /* page list protector */
325
326         /* number of in flight destroy rpcs is limited to max_rpcs_in_flight */
327         atomic_t             cl_destroy_in_flight;
328         wait_queue_head_t             cl_destroy_waitq;
329
330         struct mdc_rpc_lock     *cl_rpc_lock;
331         struct mdc_rpc_lock     *cl_close_lock;
332
333         /* mgc datastruct */
334         atomic_t             cl_mgc_refcount;
335         struct obd_export       *cl_mgc_mgsexp;
336
337         /* checksumming for data sent over the network */
338         unsigned int         cl_checksum:1; /* 0 = disabled, 1 = enabled */
339         /* supported checksum types that are worked out at connect time */
340         __u32               cl_supp_cksum_types;
341         /* checksum algorithm to be used */
342         cksum_type_t         cl_cksum_type;
343
344         /* also protected by the poorly named _loi_list_lock lock above */
345         struct osc_async_rc      cl_ar;
346
347         /* used by quotacheck when the servers are older than 2.4 */
348         int                   cl_qchk_stat; /* quotacheck stat of the peer */
349 #define CL_NOT_QUOTACHECKED 1   /* client->cl_qchk_stat init value */
350 #if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 7, 50, 0)
351 #warning "please consider removing quotacheck compatibility code"
352 #endif
353
354         /* sequence manager */
355         struct lu_client_seq    *cl_seq;
356
357         atomic_t             cl_resends; /* resend count */
358
359         /* ptlrpc work for writeback in ptlrpcd context */
360         void                *cl_writeback_work;
361         /* hash tables for osc_quota_info */
362         struct cfs_hash       *cl_quota_hash[MAXQUOTAS];
363 };
364
365 #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
366
367 struct obd_id_info {
368         __u32   idx;
369         u64     *data;
370 };
371
372 struct echo_client_obd {
373         struct obd_export       *ec_exp;   /* the local connection to osc/lov */
374         spinlock_t              ec_lock;
375         struct list_head           ec_objects;
376         struct list_head           ec_locks;
377         __u64           ec_unique;
378 };
379
380 /* Generic subset of OSTs */
381 struct ost_pool {
382         __u32         *op_array;      /* array of index of
383                                                    lov_obd->lov_tgts */
384         unsigned int    op_count;      /* number of OSTs in the array */
385         unsigned int    op_size;       /* allocated size of lp_array */
386         struct rw_semaphore op_rw_sem;     /* to protect ost_pool use */
387 };
388
389 /* Round-robin allocator data */
390 struct lov_qos_rr {
391         __u32          lqr_start_idx;   /* start index of new inode */
392         __u32          lqr_offset_idx;  /* aliasing for start_idx  */
393         int              lqr_start_count; /* reseed counter */
394         struct ost_pool     lqr_pool;   /* round-robin optimized list */
395         unsigned long       lqr_dirty:1;     /* recalc round-robin list */
396 };
397
398 /* allow statfs data caching for 1 second */
399 #define OBD_STATFS_CACHE_SECONDS 1
400
401 struct lov_statfs_data {
402         struct obd_info   lsd_oi;
403         struct obd_statfs lsd_statfs;
404 };
405
406 /* Stripe placement optimization */
407 struct lov_qos {
408         struct list_head    lq_oss_list; /* list of OSSs that targets use */
409         struct rw_semaphore lq_rw_sem;
410         __u32           lq_active_oss_count;
411         unsigned int    lq_prio_free;   /* priority for free space */
412         unsigned int    lq_threshold_rr;/* priority for rr */
413         struct lov_qos_rr   lq_rr;        /* round robin qos data */
414         unsigned long       lq_dirty:1,     /* recalc qos data */
415                             lq_same_space:1,/* the ost's all have approx.
416                                                the same space avail */
417                             lq_reset:1,     /* zero current penalties */
418                             lq_statfs_in_progress:1; /* statfs op in
419                                                         progress */
420         /* qos statfs data */
421         struct lov_statfs_data *lq_statfs_data;
422         wait_queue_head_t        lq_statfs_waitq; /* waitqueue to notify statfs
423                                               * requests completion */
424 };
425
426 struct lov_tgt_desc {
427         struct list_head          ltd_kill;
428         struct obd_uuid     ltd_uuid;
429         struct obd_device  *ltd_obd;
430         struct obd_export  *ltd_exp;
431         __u32          ltd_gen;
432         __u32          ltd_index;   /* index in lov_obd->tgts */
433         unsigned long       ltd_active:1,/* is this target up for requests */
434                             ltd_activate:1,/* should  target be activated */
435                             ltd_reap:1;  /* should this target be deleted */
436 };
437
438 /* Pool metadata */
439 #define pool_tgt_size(_p)   _p->pool_obds.op_size
440 #define pool_tgt_count(_p)  _p->pool_obds.op_count
441 #define pool_tgt_array(_p)  _p->pool_obds.op_array
442 #define pool_tgt_rw_sem(_p) _p->pool_obds.op_rw_sem
443
444 struct pool_desc {
445         char              pool_name[LOV_MAXPOOLNAME + 1]; /* name of pool */
446         struct ost_pool       pool_obds;              /* pool members */
447         atomic_t          pool_refcount;          /* pool ref. counter */
448         struct lov_qos_rr     pool_rr;          /* round robin qos */
449         struct hlist_node      pool_hash;             /* access by poolname */
450         struct list_head            pool_list;        /* serial access */
451         struct dentry           *pool_debugfs_entry;    /* file in debugfs */
452         struct obd_device    *pool_lobd;        /* obd of the lov/lod to which
453                                                 *  this pool belongs */
454 };
455
456 struct lov_obd {
457         struct lov_desc  desc;
458         struct lov_tgt_desc   **lov_tgts;             /* sparse array */
459         struct ost_pool  lov_packed;        /* all OSTs in a packed
460                                                           array */
461         struct mutex            lov_lock;
462         struct obd_connect_data lov_ocd;
463         atomic_t            lov_refcount;
464         __u32              lov_tgt_count;        /* how many OBD's */
465         __u32              lov_active_tgt_count;  /* how many active */
466         __u32              lov_death_row;/* tgts scheduled to be deleted */
467         __u32              lov_tgt_size;   /* size of tgts array */
468         int                  lov_connects;
469         int                  lov_pool_count;
470         struct cfs_hash      *lov_pools_hash_body; /* used for key access */
471         struct list_head        lov_pool_list; /* used for sequential access */
472         struct dentry           *lov_pool_debugfs_entry;
473         enum lustre_sec_part    lov_sp_me;
474
475         /* Cached LRU pages from upper layer */
476         void                   *lov_cache;
477
478         struct rw_semaphore     lov_notify_lock;
479
480         struct kobject          *lov_tgts_kobj;
481 };
482
483 struct lmv_tgt_desc {
484         struct obd_uuid         ltd_uuid;
485         struct obd_export       *ltd_exp;
486         int                     ltd_idx;
487         struct mutex            ltd_fid_mutex;
488         unsigned long           ltd_active:1; /* target up for requests */
489 };
490
491 enum placement_policy {
492         PLACEMENT_CHAR_POLICY   = 0,
493         PLACEMENT_NID_POLICY    = 1,
494         PLACEMENT_INVAL_POLICY  = 2,
495         PLACEMENT_MAX_POLICY
496 };
497
498 struct lmv_obd {
499         int                     refcount;
500         struct lu_client_fld    lmv_fld;
501         spinlock_t              lmv_lock;
502         enum placement_policy   lmv_placement;
503         struct lmv_desc         desc;
504         struct obd_uuid         cluuid;
505         struct obd_export       *exp;
506
507         struct mutex            init_mutex;
508         int                     connected;
509         int                     max_easize;
510         int                     max_def_easize;
511         int                     max_cookiesize;
512         int                     max_def_cookiesize;
513         int                     server_timeout;
514
515         int                     tgts_size; /* size of tgts array */
516         struct lmv_tgt_desc     **tgts;
517
518         struct obd_connect_data conn_data;
519         struct kobject          *lmv_tgts_kobj;
520 };
521
522 struct niobuf_local {
523         __u64           lnb_file_offset;
524         __u32           lnb_page_offset;
525         __u32           len;
526         __u32           flags;
527         struct page     *page;
528         struct dentry   *dentry;
529         int             lnb_grant_used;
530         int             rc;
531 };
532
533 #define LUSTRE_FLD_NAME  "fld"
534 #define LUSTRE_SEQ_NAME  "seq"
535
536 #define LUSTRE_MDD_NAME  "mdd"
537 #define LUSTRE_OSD_LDISKFS_NAME "osd-ldiskfs"
538 #define LUSTRE_OSD_ZFS_NAME     "osd-zfs"
539 #define LUSTRE_VVP_NAME  "vvp"
540 #define LUSTRE_LMV_NAME  "lmv"
541 #define LUSTRE_SLP_NAME  "slp"
542 #define LUSTRE_LOD_NAME         "lod"
543 #define LUSTRE_OSP_NAME         "osp"
544 #define LUSTRE_LWP_NAME         "lwp"
545
546 /* obd device type names */
547  /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */
548 #define LUSTRE_MDS_NAME  "mds"
549 #define LUSTRE_MDT_NAME  "mdt"
550 #define LUSTRE_MDC_NAME  "mdc"
551 #define LUSTRE_OSS_NAME  "ost"       /* FIXME change name to oss */
552 #define LUSTRE_OST_NAME  "obdfilter" /* FIXME change name to ost */
553 #define LUSTRE_OSC_NAME  "osc"
554 #define LUSTRE_LOV_NAME  "lov"
555 #define LUSTRE_MGS_NAME  "mgs"
556 #define LUSTRE_MGC_NAME  "mgc"
557
558 #define LUSTRE_ECHO_NAME        "obdecho"
559 #define LUSTRE_ECHO_CLIENT_NAME "echo_client"
560 #define LUSTRE_QMT_NAME  "qmt"
561
562 /* Constant obd names (post-rename) */
563 #define LUSTRE_MDS_OBDNAME "MDS"
564 #define LUSTRE_OSS_OBDNAME "OSS"
565 #define LUSTRE_MGS_OBDNAME "MGS"
566 #define LUSTRE_MGC_OBDNAME "MGC"
567
568 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
569 #define N_LOCAL_TEMP_PAGE 0x10000000
570
571 struct obd_trans_info {
572         __u64               oti_transno;
573         __u64               oti_xid;
574         /* Only used on the server side for tracking acks. */
575         struct oti_req_ack_lock {
576                 struct lustre_handle lock;
577                 __u32           mode;
578         }                       oti_ack_locks[4];
579         void                *oti_handle;
580         struct llog_cookie       oti_onecookie;
581         struct llog_cookie      *oti_logcookies;
582         int                   oti_numcookies;
583         /** synchronous write is needed */
584         unsigned long            oti_sync_write:1;
585
586         /* initial thread handling transaction */
587         struct ptlrpc_thread *oti_thread;
588         __u32               oti_conn_cnt;
589         /** VBR: versions */
590         __u64               oti_pre_version;
591         /** JobID */
592         char                *oti_jobid;
593
594         struct obd_uuid  *oti_ost_uuid;
595 };
596
597 static inline void oti_alloc_cookies(struct obd_trans_info *oti,
598                                      int num_cookies)
599 {
600         if (!oti)
601                 return;
602
603         if (num_cookies == 1)
604                 oti->oti_logcookies = &oti->oti_onecookie;
605         else
606                 oti->oti_logcookies = libcfs_kvzalloc(num_cookies * sizeof(oti->oti_onecookie),
607                                                       GFP_NOFS);
608
609         oti->oti_numcookies = num_cookies;
610 }
611
612 static inline void oti_free_cookies(struct obd_trans_info *oti)
613 {
614         if (!oti || !oti->oti_logcookies)
615                 return;
616
617         if (oti->oti_logcookies == &oti->oti_onecookie)
618                 LASSERT(oti->oti_numcookies == 1);
619         else
620                 kvfree(oti->oti_logcookies);
621
622         oti->oti_logcookies = NULL;
623         oti->oti_numcookies = 0;
624 }
625
626 /*
627  * Events signalled through obd_notify() upcall-chain.
628  */
629 enum obd_notify_event {
630         /* target added */
631         OBD_NOTIFY_CREATE,
632         /* Device connect start */
633         OBD_NOTIFY_CONNECT,
634         /* Device activated */
635         OBD_NOTIFY_ACTIVE,
636         /* Device deactivated */
637         OBD_NOTIFY_INACTIVE,
638         /* Device disconnected */
639         OBD_NOTIFY_DISCON,
640         /* Connect data for import were changed */
641         OBD_NOTIFY_OCD,
642         /* Sync request */
643         OBD_NOTIFY_SYNC_NONBLOCK,
644         OBD_NOTIFY_SYNC,
645         /* Configuration event */
646         OBD_NOTIFY_CONFIG,
647         /* Administratively deactivate/activate event */
648         OBD_NOTIFY_DEACTIVATE,
649         OBD_NOTIFY_ACTIVATE
650 };
651
652 /*
653  * Data structure used to pass obd_notify()-event to non-obd listeners (llite
654  * and liblustre being main examples).
655  */
656 struct obd_notify_upcall {
657         int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
658                           enum obd_notify_event ev, void *owner, void *data);
659         /* Opaque datum supplied by upper layer listener */
660         void *onu_owner;
661 };
662
663 struct target_recovery_data {
664         svc_handler_t           trd_recovery_handler;
665         pid_t                   trd_processing_task;
666         struct completion       trd_starting;
667         struct completion       trd_finishing;
668 };
669
670 struct obd_llog_group {
671         int             olg_seq;
672         struct llog_ctxt  *olg_ctxts[LLOG_MAX_CTXTS];
673         wait_queue_head_t       olg_waitq;
674         spinlock_t         olg_lock;
675         struct mutex       olg_cat_processing;
676 };
677
678 /* corresponds to one of the obd's */
679 #define OBD_DEVICE_MAGIC        0XAB5CD6EF
680 #define OBD_DEV_BY_DEVNAME      0xffffd0de
681
682 struct lvfs_run_ctxt {
683         struct dt_device *dt;
684 };
685
686 struct obd_device {
687         struct obd_type *obd_type;
688         __u32              obd_magic;
689
690         /* common and UUID name of this device */
691         char                obd_name[MAX_OBD_NAME];
692         struct obd_uuid  obd_uuid;
693
694         struct lu_device       *obd_lu_dev;
695
696         int                  obd_minor;
697         /* bitfield modification is protected by obd_dev_lock */
698         unsigned long obd_attached:1,      /* finished attach */
699                       obd_set_up:1,     /* finished setup */
700                       obd_version_recov:1, /* obd uses version checking */
701                       obd_replayable:1,    /* recovery is enabled; inform clients */
702                       obd_no_transno:1,    /* no committed-transno notification */
703                       obd_no_recov:1,      /* fail instead of retry messages */
704                       obd_stopping:1,      /* started cleanup */
705                       obd_starting:1,      /* started setup */
706                       obd_force:1,       /* cleanup with > 0 obd refcount */
707                       obd_fail:1,         /* cleanup with failover */
708                       obd_async_recov:1,   /* allow asynchronous orphan cleanup */
709                       obd_no_conn:1,       /* deny new connections */
710                       obd_inactive:1,      /* device active/inactive
711                                             * (for sysfs status only!!)
712                                             */
713                       obd_no_ir:1,       /* no imperative recovery. */
714                       obd_process_conf:1;  /* device is processing mgs config */
715         /* use separate field as it is set in interrupt to don't mess with
716          * protection of other bits using _bh lock */
717         unsigned long obd_recovery_expired:1;
718         /* uuid-export hash body */
719         struct cfs_hash      *obd_uuid_hash;
720         atomic_t            obd_refcount;
721         wait_queue_head_t            obd_refcount_waitq;
722         struct list_head              obd_exports;
723         struct list_head              obd_unlinked_exports;
724         struct list_head              obd_delayed_exports;
725         int                  obd_num_exports;
726         spinlock_t              obd_nid_lock;
727         struct ldlm_namespace  *obd_namespace;
728         struct ptlrpc_client    obd_ldlm_client; /* XXX OST/MDS only */
729         /* a spinlock is OK for what we do now, may need a semaphore later */
730         spinlock_t              obd_dev_lock; /* protect OBD bitfield above */
731         struct mutex            obd_dev_mutex;
732         __u64                   obd_last_committed;
733         spinlock_t              obd_osfs_lock;
734         struct obd_statfs       obd_osfs;       /* locked by obd_osfs_lock */
735         __u64                   obd_osfs_age;
736         struct lvfs_run_ctxt    obd_lvfs_ctxt;
737         struct obd_llog_group   obd_olg;        /* default llog group */
738         struct obd_device       *obd_observer;
739         struct rw_semaphore     obd_observer_link_sem;
740         struct obd_notify_upcall obd_upcall;
741         struct obd_export       *obd_self_export;
742
743         union {
744                 struct client_obd cli;
745                 struct echo_client_obd echo_client;
746                 struct lov_obd lov;
747                 struct lmv_obd lmv;
748         } u;
749         /* Fields used by LProcFS */
750         unsigned int       obd_cntr_base;
751         struct lprocfs_stats  *obd_stats;
752
753         unsigned int       md_cntr_base;
754         struct lprocfs_stats  *md_stats;
755
756         struct dentry           *obd_debugfs_entry;
757         struct dentry           *obd_svc_debugfs_entry;
758         struct lprocfs_stats  *obd_svc_stats;
759         atomic_t           obd_evict_inprogress;
760         wait_queue_head_t           obd_evict_inprogress_waitq;
761         struct list_head        obd_evict_list; /* protected with pet_lock */
762
763         /**
764          * Ldlm pool part. Save last calculated SLV and Limit.
765          */
766         rwlock_t                obd_pool_lock;
767         int                 obd_pool_limit;
768         __u64             obd_pool_slv;
769
770         /**
771          * A list of outstanding class_incref()'s against this obd. For
772          * debugging.
773          */
774         struct lu_ref     obd_reference;
775
776         int                    obd_conn_inprogress;
777
778         struct kobject          obd_kobj; /* sysfs object */
779         struct completion       obd_kobj_unregister;
780 };
781
782 #define OBD_LLOG_FL_SENDNOW     0x0001
783 #define OBD_LLOG_FL_EXIT        0x0002
784
785 enum obd_cleanup_stage {
786 /* Special case hack for MDS LOVs */
787         OBD_CLEANUP_EARLY,
788 /* can be directly mapped to .ldto_device_fini() */
789         OBD_CLEANUP_EXPORTS,
790 };
791
792 /* get/set_info keys */
793 #define KEY_ASYNC              "async"
794 #define KEY_BLOCKSIZE_BITS      "blocksize_bits"
795 #define KEY_BLOCKSIZE      "blocksize"
796 #define KEY_CHANGELOG_CLEAR     "changelog_clear"
797 #define KEY_FID2PATH        "fid2path"
798 #define KEY_CHECKSUM        "checksum"
799 #define KEY_CLEAR_FS        "clear_fs"
800 #define KEY_CONN_DATA      "conn_data"
801 #define KEY_EVICT_BY_NID        "evict_by_nid"
802 #define KEY_FIEMAP            "fiemap"
803 #define KEY_FLUSH_CTX      "flush_ctx"
804 #define KEY_GRANT_SHRINK        "grant_shrink"
805 #define KEY_HSM_COPYTOOL_SEND   "hsm_send"
806 #define KEY_INIT_RECOV_BACKUP   "init_recov_bk"
807 #define KEY_INIT_RECOV    "initial_recov"
808 #define KEY_INTERMDS        "inter_mds"
809 #define KEY_LAST_ID          "last_id"
810 #define KEY_LAST_FID            "last_fid"
811 #define KEY_LOCK_TO_STRIPE      "lock_to_stripe"
812 #define KEY_LOVDESC          "lovdesc"
813 #define KEY_LOV_IDX          "lov_idx"
814 #define KEY_MAX_EASIZE          "max_easize"
815 #define KEY_DEFAULT_EASIZE      "default_easize"
816 #define KEY_MDS_CONN        "mds_conn"
817 #define KEY_MGSSEC            "mgssec"
818 #define KEY_NEXT_ID          "next_id"
819 #define KEY_READ_ONLY      "read-only"
820 #define KEY_REGISTER_TARGET     "register_target"
821 #define KEY_SET_FS            "set_fs"
822 #define KEY_TGT_COUNT      "tgt_count"
823 /*      KEY_SET_INFO in lustre_idl.h */
824 #define KEY_SPTLRPC_CONF        "sptlrpc_conf"
825 #define KEY_CONNECT_FLAG        "connect_flags"
826 #define KEY_SYNC_LOCK_CANCEL    "sync_lock_cancel"
827
828 #define KEY_CACHE_SET           "cache_set"
829 #define KEY_CACHE_LRU_SHRINK    "cache_lru_shrink"
830 #define KEY_CHANGELOG_INDEX     "changelog_index"
831
832 struct lu_context;
833
834 /* /!\ must be coherent with include/linux/namei.h on patched kernel */
835 #define IT_OPEN     (1 << 0)
836 #define IT_CREAT    (1 << 1)
837 #define IT_READDIR  (1 << 2)
838 #define IT_GETATTR  (1 << 3)
839 #define IT_LOOKUP   (1 << 4)
840 #define IT_UNLINK   (1 << 5)
841 #define IT_TRUNC    (1 << 6)
842 #define IT_GETXATTR (1 << 7)
843 #define IT_EXEC     (1 << 8)
844 #define IT_PIN      (1 << 9)
845 #define IT_LAYOUT   (1 << 10)
846 #define IT_QUOTA_DQACQ (1 << 11)
847 #define IT_QUOTA_CONN  (1 << 12)
848 #define IT_SETXATTR (1 << 13)
849
850 static inline int it_to_lock_mode(struct lookup_intent *it)
851 {
852         /* CREAT needs to be tested before open (both could be set) */
853         if (it->it_op & IT_CREAT)
854                 return LCK_CW;
855         else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_LOOKUP |
856                               IT_LAYOUT))
857                 return LCK_CR;
858         else if (it->it_op &  IT_GETXATTR)
859                 return LCK_PR;
860         else if (it->it_op &  IT_SETXATTR)
861                 return LCK_PW;
862
863         LASSERTF(0, "Invalid it_op: %d\n", it->it_op);
864         return -EINVAL;
865 }
866
867 struct md_op_data {
868         struct lu_fid      op_fid1; /* operation fid1 (usually parent) */
869         struct lu_fid      op_fid2; /* operation fid2 (usually child) */
870         struct lu_fid      op_fid3; /* 2 extra fids to find conflicting */
871         struct lu_fid      op_fid4; /* to the operation locks. */
872         u32                     op_mds;  /* what mds server open will go to */
873         struct lustre_handle    op_handle;
874         s64                     op_mod_time;
875         const char           *op_name;
876         int                  op_namelen;
877         __u32              op_mode;
878         struct lmv_stripe_md   *op_mea1;
879         struct lmv_stripe_md   *op_mea2;
880         __u32              op_suppgids[2];
881         __u32              op_fsuid;
882         __u32              op_fsgid;
883         cfs_cap_t              op_cap;
884         void               *op_data;
885
886         /* iattr fields and blocks. */
887         struct iattr        op_attr;
888         unsigned int        op_attr_flags;
889         __u64              op_valid;
890         loff_t            op_attr_blocks;
891
892         /* Size-on-MDS epoch and flags. */
893         __u64              op_ioepoch;
894         __u32              op_flags;
895
896         /* Various operation flags. */
897         enum mds_op_bias        op_bias;
898
899         /* Operation type */
900         __u32              op_opc;
901
902         /* Used by readdir */
903         __u64              op_offset;
904
905         /* Used by readdir */
906         __u32              op_npages;
907
908         /* used to transfer info between the stacks of MD client
909          * see enum op_cli_flags */
910         __u32                   op_cli_flags;
911
912         /* File object data version for HSM release, on client */
913         __u64                   op_data_version;
914         struct lustre_handle    op_lease_handle;
915 };
916
917 enum op_cli_flags {
918         CLI_SET_MEA     = 1 << 0,
919         CLI_RM_ENTRY    = 1 << 1,
920 };
921
922 struct md_enqueue_info;
923 /* metadata stat-ahead */
924
925 struct md_enqueue_info {
926         struct md_op_data       mi_data;
927         struct lookup_intent    mi_it;
928         struct lustre_handle    mi_lockh;
929         struct inode       *mi_dir;
930         int (*mi_cb)(struct ptlrpc_request *req,
931                 struct md_enqueue_info *minfo, int rc);
932         __u64              mi_cbdata;
933         unsigned int        mi_generation;
934 };
935
936 struct obd_ops {
937         struct module *owner;
938         int (*iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
939                          void *karg, void __user *uarg);
940         int (*get_info)(const struct lu_env *env, struct obd_export *,
941                         __u32 keylen, void *key, __u32 *vallen, void *val,
942                         struct lov_stripe_md *lsm);
943         int (*set_info_async)(const struct lu_env *, struct obd_export *,
944                               __u32 keylen, void *key,
945                               __u32 vallen, void *val,
946                               struct ptlrpc_request_set *set);
947         int (*attach)(struct obd_device *dev, u32 len, void *data);
948         int (*detach)(struct obd_device *dev);
949         int (*setup)(struct obd_device *dev, struct lustre_cfg *cfg);
950         int (*precleanup)(struct obd_device *dev,
951                           enum obd_cleanup_stage cleanup_stage);
952         int (*cleanup)(struct obd_device *dev);
953         int (*process_config)(struct obd_device *dev, u32 len, void *data);
954         int (*postrecov)(struct obd_device *dev);
955         int (*add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
956                         int priority);
957         int (*del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
958         /* connect to the target device with given connection
959          * data. @ocd->ocd_connect_flags is modified to reflect flags actually
960          * granted by the target, which are guaranteed to be a subset of flags
961          * asked for. If @ocd == NULL, use default parameters. */
962         int (*connect)(const struct lu_env *env,
963                        struct obd_export **exp, struct obd_device *src,
964                        struct obd_uuid *cluuid, struct obd_connect_data *ocd,
965                        void *localdata);
966         int (*reconnect)(const struct lu_env *env,
967                          struct obd_export *exp, struct obd_device *src,
968                          struct obd_uuid *cluuid,
969                          struct obd_connect_data *ocd,
970                          void *localdata);
971         int (*disconnect)(struct obd_export *exp);
972
973         /* Initialize/finalize fids infrastructure. */
974         int (*fid_init)(struct obd_device *obd,
975                         struct obd_export *exp, enum lu_cli_type type);
976         int (*fid_fini)(struct obd_device *obd);
977
978         /* Allocate new fid according to passed @hint. */
979         int (*fid_alloc)(struct obd_export *exp, struct lu_fid *fid,
980                          struct md_op_data *op_data);
981
982         /*
983          * Object with @fid is getting deleted, we may want to do something
984          * about this.
985          */
986         int (*statfs)(const struct lu_env *, struct obd_export *exp,
987                       struct obd_statfs *osfs, __u64 max_age, __u32 flags);
988         int (*statfs_async)(struct obd_export *exp, struct obd_info *oinfo,
989                             __u64 max_age, struct ptlrpc_request_set *set);
990         int (*packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
991                       struct lov_stripe_md *mem_src);
992         int (*unpackmd)(struct obd_export *exp,
993                         struct lov_stripe_md **mem_tgt,
994                         struct lov_mds_md *disk_src, int disk_len);
995         int (*preallocate)(struct lustre_handle *, u32 *req, u64 *ids);
996         int (*create)(const struct lu_env *env, struct obd_export *exp,
997                       struct obdo *oa, struct lov_stripe_md **ea,
998                       struct obd_trans_info *oti);
999         int (*destroy)(const struct lu_env *env, struct obd_export *exp,
1000                        struct obdo *oa, struct lov_stripe_md *ea,
1001                        struct obd_trans_info *oti, struct obd_export *md_exp);
1002         int (*setattr)(const struct lu_env *, struct obd_export *exp,
1003                        struct obd_info *oinfo, struct obd_trans_info *oti);
1004         int (*setattr_async)(struct obd_export *exp, struct obd_info *oinfo,
1005                              struct obd_trans_info *oti,
1006                              struct ptlrpc_request_set *rqset);
1007         int (*getattr)(const struct lu_env *env, struct obd_export *exp,
1008                        struct obd_info *oinfo);
1009         int (*getattr_async)(struct obd_export *exp, struct obd_info *oinfo,
1010                              struct ptlrpc_request_set *set);
1011         int (*adjust_kms)(struct obd_export *exp, struct lov_stripe_md *lsm,
1012                           u64 size, int shrink);
1013         int (*preprw)(const struct lu_env *env, int cmd,
1014                       struct obd_export *exp, struct obdo *oa, int objcount,
1015                       struct obd_ioobj *obj, struct niobuf_remote *remote,
1016                       int *nr_pages, struct niobuf_local *local,
1017                       struct obd_trans_info *oti);
1018         int (*commitrw)(const struct lu_env *env, int cmd,
1019                         struct obd_export *exp, struct obdo *oa,
1020                         int objcount, struct obd_ioobj *obj,
1021                         struct niobuf_remote *remote, int pages,
1022                         struct niobuf_local *local,
1023                         struct obd_trans_info *oti, int rc);
1024         int (*find_cbdata)(struct obd_export *, struct lov_stripe_md *,
1025                            ldlm_iterator_t it, void *data);
1026         int (*init_export)(struct obd_export *exp);
1027         int (*destroy_export)(struct obd_export *exp);
1028
1029         /* metadata-only methods */
1030         int (*import_event)(struct obd_device *, struct obd_import *,
1031                             enum obd_import_event);
1032
1033         int (*notify)(struct obd_device *obd, struct obd_device *watched,
1034                       enum obd_notify_event ev, void *data);
1035
1036         int (*health_check)(const struct lu_env *env, struct obd_device *);
1037         struct obd_uuid *(*get_uuid)(struct obd_export *exp);
1038
1039         /* quota methods */
1040         int (*quotacheck)(struct obd_device *, struct obd_export *,
1041                           struct obd_quotactl *);
1042         int (*quotactl)(struct obd_device *, struct obd_export *,
1043                         struct obd_quotactl *);
1044
1045         /* pools methods */
1046         int (*pool_new)(struct obd_device *obd, char *poolname);
1047         int (*pool_del)(struct obd_device *obd, char *poolname);
1048         int (*pool_add)(struct obd_device *obd, char *poolname,
1049                         char *ostname);
1050         int (*pool_rem)(struct obd_device *obd, char *poolname,
1051                         char *ostname);
1052         void (*getref)(struct obd_device *obd);
1053         void (*putref)(struct obd_device *obd);
1054         /*
1055          * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
1056          * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
1057          * Also, add a wrapper function in include/linux/obd_class.h. */
1058 };
1059
1060 enum {
1061         LUSTRE_OPC_MKDIR    = (1 << 0),
1062         LUSTRE_OPC_SYMLINK  = (1 << 1),
1063         LUSTRE_OPC_MKNOD    = (1 << 2),
1064         LUSTRE_OPC_CREATE   = (1 << 3),
1065         LUSTRE_OPC_ANY      = (1 << 4)
1066 };
1067
1068 /* lmv structures */
1069 #define MEA_MAGIC_LAST_CHAR      0xb2221ca1
1070 #define MEA_MAGIC_ALL_CHARS      0xb222a11c
1071 #define MEA_MAGIC_HASH_SEGMENT   0xb222a11b
1072
1073 #define MAX_HASH_SIZE_32         0x7fffffffUL
1074 #define MAX_HASH_SIZE       0x7fffffffffffffffULL
1075 #define MAX_HASH_HIGHEST_BIT     0x1000000000000000ULL
1076
1077 struct lustre_md {
1078         struct mdt_body  *body;
1079         struct lov_stripe_md    *lsm;
1080         struct lmv_stripe_md    *mea;
1081 #ifdef CONFIG_FS_POSIX_ACL
1082         struct posix_acl        *posix_acl;
1083 #endif
1084         struct mdt_remote_perm  *remote_perm;
1085 };
1086
1087 struct md_open_data {
1088         struct obd_client_handle *mod_och;
1089         struct ptlrpc_request    *mod_open_req;
1090         struct ptlrpc_request    *mod_close_req;
1091         atomic_t                  mod_refcount;
1092         bool                      mod_is_create;
1093 };
1094
1095 struct lookup_intent;
1096
1097 struct md_ops {
1098         int (*getstatus)(struct obd_export *, struct lu_fid *);
1099         int (*null_inode)(struct obd_export *, const struct lu_fid *);
1100         int (*find_cbdata)(struct obd_export *, const struct lu_fid *,
1101                            ldlm_iterator_t, void *);
1102         int (*close)(struct obd_export *, struct md_op_data *,
1103                      struct md_open_data *, struct ptlrpc_request **);
1104         int (*create)(struct obd_export *, struct md_op_data *,
1105                       const void *, int, int, __u32, __u32, cfs_cap_t,
1106                       __u64, struct ptlrpc_request **);
1107         int (*done_writing)(struct obd_export *, struct md_op_data  *,
1108                             struct md_open_data *);
1109         int (*enqueue)(struct obd_export *, struct ldlm_enqueue_info *,
1110                        struct lookup_intent *, struct md_op_data *,
1111                        struct lustre_handle *, void *, int,
1112                        struct ptlrpc_request **, __u64);
1113         int (*getattr)(struct obd_export *, struct md_op_data *,
1114                        struct ptlrpc_request **);
1115         int (*getattr_name)(struct obd_export *, struct md_op_data *,
1116                             struct ptlrpc_request **);
1117         int (*intent_lock)(struct obd_export *, struct md_op_data *,
1118                            void *, int, struct lookup_intent *, int,
1119                            struct ptlrpc_request **,
1120                            ldlm_blocking_callback, __u64);
1121         int (*link)(struct obd_export *, struct md_op_data *,
1122                     struct ptlrpc_request **);
1123         int (*rename)(struct obd_export *, struct md_op_data *,
1124                       const char *, int, const char *, int,
1125                       struct ptlrpc_request **);
1126         int (*is_subdir)(struct obd_export *, const struct lu_fid *,
1127                          const struct lu_fid *,
1128                            struct ptlrpc_request **);
1129         int (*setattr)(struct obd_export *, struct md_op_data *, void *,
1130                        int, void *, int, struct ptlrpc_request **,
1131                          struct md_open_data **mod);
1132         int (*sync)(struct obd_export *, const struct lu_fid *,
1133                     struct ptlrpc_request **);
1134         int (*readpage)(struct obd_export *, struct md_op_data *,
1135                         struct page **, struct ptlrpc_request **);
1136
1137         int (*unlink)(struct obd_export *, struct md_op_data *,
1138                       struct ptlrpc_request **);
1139
1140         int (*setxattr)(struct obd_export *, const struct lu_fid *,
1141                         u64, const char *, const char *, int, int, int, __u32,
1142                         struct ptlrpc_request **);
1143
1144         int (*getxattr)(struct obd_export *, const struct lu_fid *,
1145                         u64, const char *, const char *, int, int, int,
1146                         struct ptlrpc_request **);
1147
1148         int (*init_ea_size)(struct obd_export *, int, int, int, int);
1149
1150         int (*get_lustre_md)(struct obd_export *, struct ptlrpc_request *,
1151                              struct obd_export *, struct obd_export *,
1152                              struct lustre_md *);
1153
1154         int (*free_lustre_md)(struct obd_export *, struct lustre_md *);
1155
1156         int (*set_open_replay_data)(struct obd_export *,
1157                                     struct obd_client_handle *,
1158                                     struct lookup_intent *);
1159         int (*clear_open_replay_data)(struct obd_export *,
1160                                       struct obd_client_handle *);
1161         int (*set_lock_data)(struct obd_export *, __u64 *, void *, __u64 *);
1162
1163         ldlm_mode_t (*lock_match)(struct obd_export *, __u64,
1164                                   const struct lu_fid *, ldlm_type_t,
1165                                   ldlm_policy_data_t *, ldlm_mode_t,
1166                                   struct lustre_handle *);
1167
1168         int (*cancel_unused)(struct obd_export *, const struct lu_fid *,
1169                              ldlm_policy_data_t *, ldlm_mode_t,
1170                              ldlm_cancel_flags_t flags, void *opaque);
1171
1172         int (*get_remote_perm)(struct obd_export *, const struct lu_fid *,
1173                                __u32, struct ptlrpc_request **);
1174
1175         int (*intent_getattr_async)(struct obd_export *,
1176                                     struct md_enqueue_info *,
1177                                     struct ldlm_enqueue_info *);
1178
1179         int (*revalidate_lock)(struct obd_export *, struct lookup_intent *,
1180                                struct lu_fid *, __u64 *bits);
1181
1182         /*
1183          * NOTE: If adding ops, add another LPROCFS_MD_OP_INIT() line to
1184          * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
1185          * wrapper function in include/linux/obd_class.h.
1186          */
1187 };
1188
1189 struct lsm_operations {
1190         void (*lsm_free)(struct lov_stripe_md *);
1191         int (*lsm_destroy)(struct lov_stripe_md *, struct obdo *oa,
1192                            struct obd_export *md_exp);
1193         void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *, u64 *,
1194                                     u64 *);
1195         void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *, u64 *,
1196                                      u64 *);
1197         int (*lsm_lmm_verify)(struct lov_mds_md *lmm, int lmm_bytes,
1198                                __u16 *stripe_count);
1199         int (*lsm_unpackmd)(struct lov_obd *lov, struct lov_stripe_md *lsm,
1200                              struct lov_mds_md *lmm);
1201 };
1202
1203 extern const struct lsm_operations lsm_v1_ops;
1204 extern const struct lsm_operations lsm_v3_ops;
1205 static inline const struct lsm_operations *lsm_op_find(int magic)
1206 {
1207         switch (magic) {
1208         case LOV_MAGIC_V1:
1209                return &lsm_v1_ops;
1210         case LOV_MAGIC_V3:
1211                return &lsm_v3_ops;
1212         default:
1213                CERROR("Cannot recognize lsm_magic %08x\n", magic);
1214                return NULL;
1215         }
1216 }
1217
1218 /* Requests for obd_extent_calc() */
1219 #define OBD_CALC_STRIPE_START   1
1220 #define OBD_CALC_STRIPE_END     2
1221
1222 static inline struct md_open_data *obd_mod_alloc(void)
1223 {
1224         struct md_open_data *mod;
1225
1226         mod = kzalloc(sizeof(*mod), GFP_NOFS);
1227         if (!mod)
1228                 return NULL;
1229         atomic_set(&mod->mod_refcount, 1);
1230         return mod;
1231 }
1232
1233 #define obd_mod_get(mod) atomic_inc(&(mod)->mod_refcount)
1234 #define obd_mod_put(mod)                                        \
1235 ({                                                            \
1236         if (atomic_dec_and_test(&(mod)->mod_refcount)) {          \
1237                 if ((mod)->mod_open_req)                          \
1238                         ptlrpc_req_finished((mod)->mod_open_req);   \
1239                 kfree(mod);                           \
1240         }                                                      \
1241 })
1242
1243 void obdo_from_inode(struct obdo *dst, struct inode *src, u32 valid);
1244 void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent);
1245
1246 /* return 1 if client should be resend request */
1247 static inline int client_should_resend(int resend, struct client_obd *cli)
1248 {
1249         return atomic_read(&cli->cl_resends) ?
1250                atomic_read(&cli->cl_resends) > resend : 1;
1251 }
1252
1253 /**
1254  * Return device name for this device
1255  *
1256  * XXX: lu_device is declared before obd_device, while a pointer pointing
1257  * back to obd_device in lu_device, so this helper function defines here
1258  * instead of in lu_object.h
1259  */
1260 static inline const char *lu_dev_name(const struct lu_device *lu_dev)
1261 {
1262         return lu_dev->ld_obd->obd_name;
1263 }
1264
1265 static inline bool filename_is_volatile(const char *name, int namelen, int *idx)
1266 {
1267         const char      *start;
1268         char            *end;
1269
1270         if (strncmp(name, LUSTRE_VOLATILE_HDR, LUSTRE_VOLATILE_HDR_LEN) != 0)
1271                 return false;
1272
1273         /* caller does not care of idx */
1274         if (!idx)
1275                 return true;
1276
1277         /* volatile file, the MDT can be set from name */
1278         /* name format is LUSTRE_VOLATILE_HDR:[idx]: */
1279         /* if no MDT is specified, use std way */
1280         if (namelen < LUSTRE_VOLATILE_HDR_LEN + 2)
1281                 goto bad_format;
1282         /* test for no MDT idx case */
1283         if ((*(name + LUSTRE_VOLATILE_HDR_LEN) == ':') &&
1284             (*(name + LUSTRE_VOLATILE_HDR_LEN + 1) == ':')) {
1285                 *idx = -1;
1286                 return true;
1287         }
1288         /* we have an idx, read it */
1289         start = name + LUSTRE_VOLATILE_HDR_LEN + 1;
1290         *idx = simple_strtoul(start, &end, 0);
1291         /* error cases:
1292          * no digit, no trailing :, negative value
1293          */
1294         if (((*idx == 0) && (end == start)) ||
1295             (*end != ':') || (*idx < 0))
1296                 goto bad_format;
1297
1298         return true;
1299 bad_format:
1300         /* bad format of mdt idx, we cannot return an error
1301          * to caller so we use hash algo */
1302         CERROR("Bad volatile file name format: %s\n",
1303                name + LUSTRE_VOLATILE_HDR_LEN);
1304         return false;
1305 }
1306
1307 static inline int cli_brw_size(struct obd_device *obd)
1308 {
1309         return obd->u.cli.cl_max_pages_per_rpc << PAGE_CACHE_SHIFT;
1310 }
1311
1312 #endif /* __OBD_H */