Whamcloud - gitweb
LU-5275 lprocfs: remove last of non seq data structs and functions.
[fs/lustre-release.git] / 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, 2013, 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/spinlock.h>
41 #include <linux/obd.h>
42
43 #include <lustre/lustre_idl.h>
44 #include <lustre_lib.h>
45 #include <libcfs/bitmap.h>
46 #ifdef HAVE_SERVER_SUPPORT
47 # include <lu_target.h>
48 # include <obd_target.h>
49 #endif
50 #include <lu_ref.h>
51 #include <lustre_export.h>
52 #include <lustre_fid.h>
53 #include <lustre_fld.h>
54 #include <lustre_handles.h>
55 #include <lustre_intent.h>
56 #include <lustre_capa.h>
57 #include <lvfs.h>
58
59 #define MAX_OBD_DEVICES 8192
60
61 struct osc_async_rc {
62         int     ar_rc;
63         int     ar_force_sync;
64         __u64   ar_min_xid;
65 };
66
67 struct lov_oinfo {                 /* per-stripe data structure */
68         struct ost_id   loi_oi;    /* object ID/Sequence on the target OST */
69         int loi_ost_idx;           /* OST stripe index in lov_tgt_desc->tgts */
70         int loi_ost_gen;           /* generation of this loi_ost_idx */
71
72         unsigned long loi_kms_valid:1;
73         __u64 loi_kms;             /* known minimum size */
74         struct ost_lvb loi_lvb;
75         struct osc_async_rc     loi_ar;
76 };
77
78 static inline void loi_kms_set(struct lov_oinfo *oinfo, __u64 kms)
79 {
80         oinfo->loi_kms = kms;
81         oinfo->loi_kms_valid = 1;
82 }
83
84 static inline void loi_init(struct lov_oinfo *loi)
85 {
86 }
87
88 /* If we are unable to get the maximum object size from the OST in
89  * ocd_maxbytes using OBD_CONNECT_MAXBYTES, then we fall back to using
90  * the old maximum object size from ext3. */
91 #define LUSTRE_EXT3_STRIPE_MAXBYTES 0x1fffffff000ULL
92
93 struct lov_stripe_md {
94         atomic_t        lsm_refc;
95         spinlock_t      lsm_lock;
96         pid_t           lsm_lock_owner; /* debugging */
97
98         /* maximum possible file size, might change as OSTs status changes,
99          * e.g. disconnected, deactivated */
100         __u64            lsm_maxbytes;
101         struct {
102                 /* Public members. */
103                 struct ost_id lw_object_oi; /* lov object id/seq */
104
105                 /* LOV-private members start here -- only for use in lov/. */
106                 __u32 lw_magic;
107                 __u32 lw_stripe_size;      /* size of the stripe */
108                 __u32 lw_pattern;          /* striping pattern (RAID0, RAID1) */
109                 __u16 lw_stripe_count;  /* number of objects being striped over */
110                 __u16 lw_layout_gen;       /* generation of the layout */
111                 char  lw_pool_name[LOV_MAXPOOLNAME + 1]; /* pool name */
112         } lsm_wire;
113
114         struct lov_oinfo *lsm_oinfo[0];
115 };
116
117 #define lsm_oi           lsm_wire.lw_object_oi
118 #define lsm_magic        lsm_wire.lw_magic
119 #define lsm_layout_gen   lsm_wire.lw_layout_gen
120 #define lsm_stripe_size  lsm_wire.lw_stripe_size
121 #define lsm_pattern      lsm_wire.lw_pattern
122 #define lsm_stripe_count lsm_wire.lw_stripe_count
123 #define lsm_pool_name    lsm_wire.lw_pool_name
124
125 static inline bool lsm_is_released(struct lov_stripe_md *lsm)
126 {
127         return !!(lsm->lsm_pattern & LOV_PATTERN_F_RELEASED);
128 }
129
130 static inline bool lsm_has_objects(struct lov_stripe_md *lsm)
131 {
132         if (lsm == NULL)
133                 return false;
134         if (lsm_is_released(lsm))
135                 return false;
136         return true;
137 }
138
139 static inline int lov_stripe_md_size(unsigned int stripe_count)
140 {
141         struct lov_stripe_md lsm;
142
143         return sizeof(lsm) + stripe_count * sizeof(lsm.lsm_oinfo[0]);
144 }
145
146 struct obd_info;
147
148 typedef int (*obd_enqueue_update_f)(void *cookie, int rc);
149
150 /* obd info for a particular level (lov, osc). */
151 struct obd_info {
152         /* Lock policy. It keeps an extent which is specific for a particular
153          * OSC. (e.g. lov_prep_enqueue_set initialises extent of the policy,
154          * and osc_enqueue passes it into ldlm_lock_match & ldlm_cli_enqueue. */
155         ldlm_policy_data_t      oi_policy;
156         /* Flags used for set request specific flags:
157            - while lock handling, the flags obtained on the enqueue
158            request are set here.
159            - while stats, the flags used for control delay/resend.
160            - while setattr, the flags used for distinguish punch operation
161          */
162         __u64                   oi_flags;
163         /* lsm data specific for every OSC. */
164         struct lov_stripe_md   *oi_md;
165         /* obdo data specific for every OSC, if needed at all. */
166         struct obdo            *oi_oa;
167         /* statfs data specific for every OSC, if needed at all. */
168         struct obd_statfs      *oi_osfs;
169         /* An update callback which is called to update some data on upper
170          * level. E.g. it is used for update lsm->lsm_oinfo at every recieved
171          * request in osc level for enqueue requests. It is also possible to
172          * update some caller data from LOV layer if needed. */
173         obd_enqueue_update_f    oi_cb_up;
174         /* oss capability, its type is obd_capa in client to avoid copy.
175          * in contrary its type is lustre_capa in OSS. */
176         void                   *oi_capa;
177 };
178
179 struct obd_type {
180         struct list_head         typ_chain;
181         struct obd_ops          *typ_dt_ops;
182         struct md_ops           *typ_md_ops;
183         struct proc_dir_entry   *typ_procroot;
184         struct proc_dir_entry   *typ_procsym;
185         __u32                    typ_sym_filter;
186         char                    *typ_name;
187         int                      typ_refcnt;
188         struct lu_device_type   *typ_lu;
189         spinlock_t               obd_type_lock;
190 };
191
192 struct brw_page {
193         obd_off  off;
194         struct page *pg;
195         int count;
196         obd_flag flag;
197 };
198
199 struct timeout_item {
200         enum timeout_event ti_event;
201         cfs_time_t         ti_timeout;
202         timeout_cb_t       ti_cb;
203         void              *ti_cb_data;
204         struct list_head   ti_obd_list;
205         struct list_head   ti_chain;
206 };
207
208 #define OBD_MAX_RIF_DEFAULT     8
209 #define OBD_MAX_RIF_MAX         512
210 #define OSC_MAX_RIF_MAX         256
211 #define OSC_MAX_DIRTY_DEFAULT   (OBD_MAX_RIF_DEFAULT * 4)
212 #define OSC_MAX_DIRTY_MB_MAX    2048     /* arbitrary, but < MAX_LONG bytes */
213 #define OSC_DEFAULT_RESENDS     10
214
215 /* possible values for fo_sync_lock_cancel */
216 enum {
217         NEVER_SYNC_ON_CANCEL = 0,
218         BLOCKING_SYNC_ON_CANCEL = 1,
219         ALWAYS_SYNC_ON_CANCEL = 2,
220         NUM_SYNC_ON_CANCEL_STATES
221 };
222
223 struct mdc_rpc_lock;
224 struct obd_import;
225 struct client_obd {
226         struct rw_semaphore      cl_sem;
227         struct obd_uuid          cl_target_uuid;
228         struct obd_import       *cl_import; /* ptlrpc connection state */
229         int                      cl_conn_count;
230         /* max_mds_easize is purely a performance thing so we don't have to
231          * call obd_size_diskmd() all the time. */
232         __u32                    cl_default_mds_easize;
233         __u32                    cl_max_mds_easize;
234         __u32                    cl_default_mds_cookiesize;
235         __u32                    cl_max_mds_cookiesize;
236
237         enum lustre_sec_part     cl_sp_me;
238         enum lustre_sec_part     cl_sp_to;
239         struct sptlrpc_flavor    cl_flvr_mgc;   /* fixed flavor of mgc->mgs */
240
241         /* the grant values are protected by loi_list_lock below */
242         unsigned long            cl_dirty_pages;      /* all _dirty_ in pages */
243         unsigned long            cl_dirty_max_pages;  /* allowed w/o rpc */
244         unsigned long            cl_dirty_transit;    /* dirty synchronous */
245         unsigned long            cl_avail_grant;   /* bytes of credit for ost */
246         unsigned long            cl_lost_grant;    /* lost credits (trunc) */
247
248         /* since we allocate grant by blocks, we don't know how many grant will
249          * be used to add a page into cache. As a solution, we reserve maximum
250          * grant before trying to dirty a page and unreserve the rest.
251          * See osc_{reserve|unreserve}_grant for details. */
252         long                    cl_reserved_grant;
253         struct list_head        cl_cache_waiters; /* waiting for cache/grant */
254         cfs_time_t              cl_next_shrink_grant;   /* jiffies */
255         struct list_head        cl_grant_shrink_list;  /* Timeout event list */
256         int                     cl_grant_shrink_interval; /* seconds */
257
258         /* A chunk is an optimal size used by osc_extent to determine
259          * the extent size. A chunk is max(PAGE_CACHE_SIZE, OST block size) */
260         int                     cl_chunkbits;
261         int                     cl_extent_tax;  /* extent overhead, by bytes */
262
263         /* keep track of objects that have lois that contain pages which
264          * have been queued for async brw.  this lock also protects the
265          * lists of osc_client_pages that hang off of the loi */
266         /*
267          * ->cl_loi_list_lock protects consistency of
268          * ->cl_loi_{ready,read,write}_list. ->ap_make_ready() and
269          * ->ap_completion() call-backs are executed under this lock. As we
270          * cannot guarantee that these call-backs never block on all platforms
271          * (as a matter of fact they do block on Mac OS X), type of
272          * ->cl_loi_list_lock is platform dependent: it's a spin-lock on Linux
273          * and blocking mutex on Mac OS X. (Alternative is to make this lock
274          * blocking everywhere, but we don't want to slow down fast-path of
275          * our main platform.)
276          *
277          * NB by Jinshan: though field names are still _loi_, but actually
278          * osc_object{}s are in the list.
279          */
280         spinlock_t              cl_loi_list_lock;
281         struct list_head        cl_loi_ready_list;
282         struct list_head        cl_loi_hp_ready_list;
283         struct list_head        cl_loi_write_list;
284         struct list_head        cl_loi_read_list;
285         __u32                   cl_r_in_flight;
286         __u32                   cl_w_in_flight;
287         /* just a sum of the loi/lop pending numbers to be exported by /proc */
288         atomic_t                cl_pending_w_pages;
289         atomic_t                cl_pending_r_pages;
290         __u32                   cl_max_pages_per_rpc;
291         __u32                   cl_max_rpcs_in_flight;
292         struct obd_histogram    cl_read_rpc_hist;
293         struct obd_histogram    cl_write_rpc_hist;
294         struct obd_histogram    cl_read_page_hist;
295         struct obd_histogram    cl_write_page_hist;
296         struct obd_histogram    cl_read_offset_hist;
297         struct obd_histogram    cl_write_offset_hist;
298
299         /* lru for osc caching pages */
300         struct cl_client_cache  *cl_cache;
301         struct list_head         cl_lru_osc; /* member of cl_cache->ccc_lru */
302         atomic_long_t           *cl_lru_left;
303         atomic_long_t            cl_lru_busy;
304         atomic_long_t            cl_lru_in_list;
305         atomic_long_t            cl_unstable_count;
306         struct list_head         cl_lru_list; /* lru page list */
307         spinlock_t               cl_lru_list_lock; /* page list protector */
308         atomic_t                 cl_lru_shrinkers;
309
310         /* number of in flight destroy rpcs is limited to max_rpcs_in_flight */
311         atomic_t                 cl_destroy_in_flight;
312         wait_queue_head_t        cl_destroy_waitq;
313
314         struct mdc_rpc_lock     *cl_rpc_lock;
315         struct mdc_rpc_lock     *cl_close_lock;
316
317         /* mgc datastruct */
318         struct mutex              cl_mgc_mutex;
319         struct local_oid_storage *cl_mgc_los;
320         struct dt_object         *cl_mgc_configs_dir;
321         atomic_t                  cl_mgc_refcount;
322         struct obd_export        *cl_mgc_mgsexp;
323
324         /* checksumming for data sent over the network */
325         unsigned int             cl_checksum:1; /* 0 = disabled, 1 = enabled */
326         /* supported checksum types that are worked out at connect time */
327         __u32                    cl_supp_cksum_types;
328         /* checksum algorithm to be used */
329         cksum_type_t             cl_cksum_type;
330
331         /* also protected by the poorly named _loi_list_lock lock above */
332         struct osc_async_rc      cl_ar;
333
334         /* used by quotacheck when the servers are older than 2.4 */
335         int                      cl_qchk_stat; /* quotacheck stat of the peer */
336 #define CL_NOT_QUOTACHECKED 1   /* client->cl_qchk_stat init value */
337 #if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 7, 53, 0)
338 #warning "please consider removing quotacheck compatibility code"
339 #endif
340
341         /* sequence manager */
342         struct lu_client_seq    *cl_seq;
343
344         atomic_t             cl_resends; /* resend count */
345
346         /* ptlrpc work for writeback in ptlrpcd context */
347         void                    *cl_writeback_work;
348         void                    *cl_lru_work;
349         /* hash tables for osc_quota_info */
350         cfs_hash_t              *cl_quota_hash[MAXQUOTAS];
351 };
352 #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
353
354 struct obd_id_info {
355         __u32   idx;
356         obd_id  *data;
357 };
358
359 struct echo_client_obd {
360         struct obd_export      *ec_exp; /* the local connection to osc/lov */
361         spinlock_t              ec_lock;
362         struct list_head        ec_objects;
363         struct list_head        ec_locks;
364         __u64                   ec_unique;
365 };
366
367 /* Generic subset of OSTs */
368 struct ost_pool {
369         __u32              *op_array;      /* array of index of
370                                                    lov_obd->lov_tgts */
371         unsigned int        op_count;      /* number of OSTs in the array */
372         unsigned int        op_size;       /* allocated size of lp_array */
373         struct rw_semaphore op_rw_sem;     /* to protect ost_pool use */
374 };
375
376 /* allow statfs data caching for 1 second */
377 #define OBD_STATFS_CACHE_SECONDS 1
378
379 struct lov_tgt_desc {
380         struct list_head    ltd_kill;
381         struct obd_uuid     ltd_uuid;
382         struct obd_device  *ltd_obd;
383         struct obd_export  *ltd_exp;
384         __u32               ltd_gen;
385         __u32               ltd_index;   /* index in lov_obd->tgts */
386         unsigned long       ltd_active:1,/* is this target up for requests */
387                             ltd_activate:1,/* should  target be activated */
388                             ltd_reap:1;  /* should this target be deleted */
389 };
390
391 struct lov_obd {
392         struct lov_desc         desc;
393         struct lov_tgt_desc   **lov_tgts;               /* sparse array */
394         struct ost_pool         lov_packed;             /* all OSTs in a packed
395                                                            array */
396         struct mutex            lov_lock;
397         struct obd_connect_data lov_ocd;
398         struct proc_dir_entry  *targets_proc_entry;
399         atomic_t                lov_refcount;
400         __u32                   lov_death_row;  /* tgts scheduled to be deleted */
401         __u32                   lov_tgt_size;   /* size of tgts array */
402         int                     lov_connects;
403         int                     lov_pool_count;
404         cfs_hash_t             *lov_pools_hash_body; /* used for key access */
405         struct list_head        lov_pool_list;  /* used for sequential access */
406         struct proc_dir_entry  *lov_pool_proc_entry;
407         enum lustre_sec_part    lov_sp_me;
408
409         /* Cached LRU and unstable data from upper layer */
410         void                   *lov_cache;
411
412         struct rw_semaphore     lov_notify_lock;
413 };
414
415 struct lmv_tgt_desc {
416         struct obd_uuid         ltd_uuid;
417         struct obd_export       *ltd_exp;
418         __u32                   ltd_idx;
419         struct mutex            ltd_fid_mutex;
420         unsigned long           ltd_active:1; /* target up for requests */
421 };
422
423 enum placement_policy {
424         PLACEMENT_CHAR_POLICY   = 0,
425         PLACEMENT_NID_POLICY    = 1,
426         PLACEMENT_INVAL_POLICY  = 2,
427         PLACEMENT_MAX_POLICY
428 };
429
430 typedef enum placement_policy placement_policy_t;
431
432 struct lmv_obd {
433         int                     refcount;
434         struct lu_client_fld    lmv_fld;
435         spinlock_t              lmv_lock;
436         placement_policy_t      lmv_placement;
437         struct lmv_desc         desc;
438         struct obd_uuid         cluuid;
439         struct obd_export       *exp;
440         struct proc_dir_entry   *targets_proc_entry;
441
442         struct mutex            lmv_init_mutex;
443         int                     connected;
444         int                     max_easize;
445         int                     max_def_easize;
446         int                     max_cookiesize;
447         int                     max_def_cookiesize;
448
449         __u32                   tgts_size; /* size of tgts array */
450         struct lmv_tgt_desc     **tgts;
451
452         struct obd_connect_data conn_data;
453 };
454
455 struct niobuf_local {
456         __u64           lnb_file_offset;
457         __u32           lnb_page_offset;
458         __u32           lnb_len;
459         __u32           lnb_flags;
460         struct page     *lnb_page;
461         void            *lnb_data;
462         int             lnb_rc;
463 };
464
465 #define LUSTRE_FLD_NAME         "fld"
466 #define LUSTRE_SEQ_NAME         "seq"
467
468 #define LUSTRE_MDD_NAME         "mdd"
469 #define LUSTRE_OSD_LDISKFS_NAME "osd-ldiskfs"
470 #define LUSTRE_OSD_ZFS_NAME     "osd-zfs"
471 #define LUSTRE_VVP_NAME         "vvp"
472 #define LUSTRE_LMV_NAME         "lmv"
473 #define LUSTRE_SLP_NAME         "slp"
474 #define LUSTRE_LOD_NAME         "lod"
475 #define LUSTRE_OSP_NAME         "osp"
476 #define LUSTRE_LWP_NAME         "lwp"
477
478 /* obd device type names */
479  /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */
480 #define LUSTRE_MDS_NAME         "mds"
481 #define LUSTRE_MDT_NAME         "mdt"
482 #define LUSTRE_MDC_NAME         "mdc"
483 #define LUSTRE_OSS_NAME         "ost"       /* FIXME change name to oss */
484 #define LUSTRE_OST_NAME         "obdfilter" /* FIXME change name to ost */
485 #define LUSTRE_OSC_NAME         "osc"
486 #define LUSTRE_LOV_NAME         "lov"
487 #define LUSTRE_MGS_NAME         "mgs"
488 #define LUSTRE_MGC_NAME         "mgc"
489
490 #define LUSTRE_ECHO_NAME        "obdecho"
491 #define LUSTRE_ECHO_CLIENT_NAME "echo_client"
492 #define LUSTRE_QMT_NAME         "qmt"
493
494 /* Constant obd names (post-rename) */
495 #define LUSTRE_MDS_OBDNAME "MDS"
496 #define LUSTRE_OSS_OBDNAME "OSS"
497 #define LUSTRE_MGS_OBDNAME "MGS"
498 #define LUSTRE_MGC_OBDNAME "MGC"
499
500 struct obd_trans_info {
501         __u64                    oti_xid;
502         /* Only used on the server side for tracking acks. */
503         struct oti_req_ack_lock {
504                 struct lustre_handle    lock;
505                 __u32                   mode;
506         }                        oti_ack_locks[4];
507         void                    *oti_handle;
508         struct llog_cookie       oti_onecookie;
509         struct llog_cookie      *oti_logcookies;
510
511         /** VBR: versions */
512         __u64                    oti_pre_version;
513 };
514
515 /*
516  * Events signalled through obd_notify() upcall-chain.
517  */
518 enum obd_notify_event {
519         /* target added */
520         OBD_NOTIFY_CREATE,
521         /* Device connect start */
522         OBD_NOTIFY_CONNECT,
523         /* Device activated */
524         OBD_NOTIFY_ACTIVE,
525         /* Device deactivated */
526         OBD_NOTIFY_INACTIVE,
527         /* Device disconnected */
528         OBD_NOTIFY_DISCON,
529         /* Connect data for import were changed */
530         OBD_NOTIFY_OCD,
531         /* Sync request */
532         OBD_NOTIFY_SYNC_NONBLOCK,
533         OBD_NOTIFY_SYNC,
534         /* Configuration event */
535         OBD_NOTIFY_CONFIG,
536         /* Administratively deactivate/activate event */
537         OBD_NOTIFY_DEACTIVATE,
538         OBD_NOTIFY_ACTIVATE
539 };
540
541 /* bit-mask flags for config events */
542 enum config_flags {
543         CONFIG_LOG      = 0x1,  /* finished processing config log */
544         CONFIG_SYNC     = 0x2,  /* mdt synced 1 ost */
545         CONFIG_TARGET   = 0x4   /* one target is added */
546 };
547
548 /*
549  * Data structure used to pass obd_notify()-event to non-obd listeners (llite
550  * and liblustre being main examples).
551  */
552 struct obd_notify_upcall {
553         int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
554                           enum obd_notify_event ev, void *owner, void *data);
555         /* Opaque datum supplied by upper layer listener */
556         void *onu_owner;
557 };
558
559 struct target_recovery_data {
560         svc_handler_t           trd_recovery_handler;
561         pid_t                   trd_processing_task;
562         struct completion       trd_starting;
563         struct completion       trd_finishing;
564 };
565
566 struct obd_llog_group {
567         struct llog_ctxt   *olg_ctxts[LLOG_MAX_CTXTS];
568         wait_queue_head_t  olg_waitq;
569         spinlock_t         olg_lock;
570         struct mutex       olg_cat_processing;
571 };
572
573 /* corresponds to one of the obd's */
574 #define OBD_DEVICE_MAGIC        0XAB5CD6EF
575
576 struct obd_device {
577         struct obd_type         *obd_type;
578         __u32                    obd_magic;
579
580         /* common and UUID name of this device */
581         char                     obd_name[MAX_OBD_NAME];
582         struct obd_uuid          obd_uuid;
583         int                      obd_minor;
584         struct lu_device        *obd_lu_dev;
585
586         /* bitfield modification is protected by obd_dev_lock */
587         unsigned long
588                 obd_attached:1,         /* finished attach */
589                 obd_set_up:1,           /* finished setup */
590                 obd_recovering:1,       /* there are recoverable clients */
591                 obd_abort_recovery:1,   /* recovery expired */
592                 obd_version_recov:1,    /* obd uses version checking */
593                 obd_replayable:1,       /* recovery is enabled;
594                                          * inform clients */
595                 obd_no_transno:1,       /* no committed-transno notification */
596                 obd_no_recov:1,         /* fail instead of retry messages */
597                 obd_stopping:1,         /* started cleanup */
598                 obd_starting:1,         /* started setup */
599                 obd_force:1,            /* cleanup with > 0 obd refcount */
600                 obd_fail:1,             /* cleanup with failover */
601                 obd_no_conn:1,          /* deny new connections */
602                 obd_inactive:1,         /* device active/inactive
603                                          * (for /proc/status only!!) */
604                 obd_no_ir:1,            /* no imperative recovery. */
605                 obd_process_conf:1,     /* device is processing mgs config */
606                 obd_uses_nid_stats:1;   /* maintain per-client OBD stats */
607
608         /* use separate field as it is set in interrupt to don't mess with
609          * protection of other bits using _bh lock */
610         unsigned long obd_recovery_expired:1;
611         /* uuid-export hash body */
612         cfs_hash_t             *obd_uuid_hash;
613         /* nid-export hash body */
614         cfs_hash_t             *obd_nid_hash;
615         /* nid stats body */
616         cfs_hash_t             *obd_nid_stats_hash;
617         struct list_head        obd_nid_stats;
618         atomic_t                obd_refcount;
619         struct list_head        obd_exports;
620         struct list_head        obd_unlinked_exports;
621         struct list_head        obd_delayed_exports;
622         struct list_head        obd_lwp_list;
623         int                     obd_num_exports;
624         spinlock_t              obd_nid_lock;
625         struct ldlm_namespace  *obd_namespace;
626         struct ptlrpc_client    obd_ldlm_client; /* XXX OST/MDS only */
627         /* a spinlock is OK for what we do now, may need a semaphore later */
628         spinlock_t              obd_dev_lock; /* protect OBD bitfield above */
629         struct mutex            obd_dev_mutex;
630         __u64                   obd_last_committed;
631         spinlock_t              obd_osfs_lock;
632         struct obd_statfs       obd_osfs;       /* locked by obd_osfs_lock */
633         __u64                   obd_osfs_age;
634         struct lvfs_run_ctxt    obd_lvfs_ctxt;
635         struct obd_llog_group   obd_olg;        /* default llog group */
636         struct obd_device       *obd_observer;
637         struct rw_semaphore     obd_observer_link_sem;
638         struct obd_notify_upcall obd_upcall;
639         struct obd_export       *obd_self_export;
640         struct obd_export       *obd_lwp_export;
641         /* list of exports in LRU order, for ping evictor, with obd_dev_lock */
642         struct list_head        obd_exports_timed;
643         time_t                  obd_eviction_timer;     /* for ping evictor */
644
645         int                     obd_max_recoverable_clients;
646         atomic_t                obd_connected_clients;
647         int                     obd_stale_clients;
648         /* this lock protects all recovery list_heads, timer and
649          * obd_next_recovery_transno value */
650         spinlock_t              obd_recovery_task_lock;
651         __u64                   obd_next_recovery_transno;
652         int                     obd_replayed_requests;
653         int                     obd_requests_queued_for_recovery;
654         wait_queue_head_t       obd_next_transno_waitq;
655         /* protected by obd_recovery_task_lock */
656         struct timer_list       obd_recovery_timer;
657         /* seconds */
658         time_t                  obd_recovery_start;
659         /* seconds, for lprocfs_status */
660         time_t                  obd_recovery_end;
661         int                     obd_recovery_time_hard;
662         int                     obd_recovery_timeout;
663         int                     obd_recovery_ir_factor;
664
665         /* new recovery stuff from CMD2 */
666         struct target_recovery_data     obd_recovery_data;
667         int                             obd_replayed_locks;
668         atomic_t                        obd_req_replay_clients;
669         atomic_t                        obd_lock_replay_clients;
670         /* all lists are protected by obd_recovery_task_lock */
671         struct list_head                obd_req_replay_queue;
672         struct list_head                obd_lock_replay_queue;
673         struct list_head                obd_final_req_queue;
674
675         union {
676 #ifdef HAVE_SERVER_SUPPORT
677                 struct obd_device_target obt;
678                 struct filter_obd filter;
679                 struct ost_obd ost;
680                 struct echo_obd echo;
681 #endif
682                 struct client_obd cli;
683                 struct echo_client_obd echo_client;
684                 struct lov_obd lov;
685                 struct lmv_obd lmv;
686         } u;
687         /* Fields used by LProcFS */
688         unsigned int           obd_cntr_base;
689         struct lprocfs_stats  *obd_stats;
690
691         unsigned int           obd_md_cntr_base;
692         struct lprocfs_stats  *obd_md_stats;
693
694         struct proc_dir_entry   *obd_proc_entry;
695         struct proc_dir_entry   *obd_proc_exports_entry;
696         struct proc_dir_entry   *obd_svc_procroot;
697         struct lprocfs_stats    *obd_svc_stats;
698         struct lprocfs_vars     *obd_vars;
699         atomic_t                obd_evict_inprogress;
700         wait_queue_head_t       obd_evict_inprogress_waitq;
701         struct list_head        obd_evict_list; /* protected with pet_lock */
702
703         /**
704          * Ldlm pool part. Save last calculated SLV and Limit.
705          */
706         rwlock_t                obd_pool_lock;
707         int                     obd_pool_limit;
708         __u64                   obd_pool_slv;
709
710         /**
711          * A list of outstanding class_incref()'s against this obd. For
712          * debugging.
713          */
714         struct lu_ref          obd_reference;
715
716         int                    obd_conn_inprogress;
717 };
718
719 enum obd_cleanup_stage {
720 /* Special case hack for MDS LOVs */
721         OBD_CLEANUP_EARLY,
722 /* can be directly mapped to .ldto_device_fini() */
723         OBD_CLEANUP_EXPORTS,
724 };
725
726 /* get/set_info keys */
727 #define KEY_ASYNC               "async"
728 #define KEY_CAPA_KEY            "capa_key"
729 #define KEY_CHANGELOG_CLEAR     "changelog_clear"
730 #define KEY_FID2PATH            "fid2path"
731 #define KEY_CHECKSUM            "checksum"
732 #define KEY_CLEAR_FS            "clear_fs"
733 #define KEY_CONN_DATA           "conn_data"
734 #define KEY_EVICT_BY_NID        "evict_by_nid"
735 #define KEY_FIEMAP              "fiemap"
736 #define KEY_FLUSH_CTX           "flush_ctx"
737 #define KEY_GRANT_SHRINK        "grant_shrink"
738 #define KEY_HSM_COPYTOOL_SEND   "hsm_send"
739 #define KEY_INIT_RECOV_BACKUP   "init_recov_bk"
740 #define KEY_INTERMDS            "inter_mds"
741 #define KEY_LAST_ID             "last_id"
742 #define KEY_LAST_FID            "last_fid"
743 #define KEY_LOVDESC             "lovdesc"
744 #define KEY_MAX_EASIZE          "max_easize"
745 #define KEY_DEFAULT_EASIZE      "default_easize"
746 #define KEY_MAX_COOKIESIZE      "max_cookiesize"
747 #define KEY_DEFAULT_COOKIESIZE  "default_cookiesize"
748 #define KEY_MGSSEC              "mgssec"
749 #define KEY_READ_ONLY           "read-only"
750 #define KEY_REGISTER_TARGET     "register_target"
751 #define KEY_SET_FS              "set_fs"
752 #define KEY_TGT_COUNT           "tgt_count"
753 /*      KEY_SET_INFO in lustre_idl.h */
754 #define KEY_SPTLRPC_CONF        "sptlrpc_conf"
755
756 #define KEY_CACHE_SET           "cache_set"
757 #define KEY_CACHE_LRU_SHRINK    "cache_lru_shrink"
758 #define KEY_OSP_CONNECTED       "osp_connected"
759
760 struct lu_context;
761
762 /* /!\ must be coherent with include/linux/namei.h on patched kernel */
763 #define IT_OPEN     (1 << 0)
764 #define IT_CREAT    (1 << 1)
765 #define IT_READDIR  (1 << 2)
766 #define IT_GETATTR  (1 << 3)
767 #define IT_LOOKUP   (1 << 4)
768 #define IT_UNLINK   (1 << 5)
769 #define IT_TRUNC    (1 << 6)
770 #define IT_GETXATTR (1 << 7)
771 #define IT_EXEC     (1 << 8)
772 #define IT_PIN      (1 << 9)
773 #define IT_LAYOUT   (1 << 10)
774 #define IT_QUOTA_DQACQ (1 << 11)
775 #define IT_QUOTA_CONN  (1 << 12)
776 #define IT_SETXATTR (1 << 13)
777
778 static inline int it_to_lock_mode(struct lookup_intent *it)
779 {
780         /* CREAT needs to be tested before open (both could be set) */
781         if (it->it_op & IT_CREAT)
782                 return LCK_CW;
783         else if (it->it_op & (IT_GETATTR | IT_OPEN | IT_LOOKUP |
784                               IT_LAYOUT))
785                 return LCK_CR;
786         else if (it->it_op &  IT_READDIR)
787                 return LCK_PR;
788         else if (it->it_op &  IT_GETXATTR)
789                 return LCK_PR;
790         else if (it->it_op &  IT_SETXATTR)
791                 return LCK_PW;
792
793         LASSERTF(0, "Invalid it_op: %d\n", it->it_op);
794         return -EINVAL;
795 }
796
797 enum md_cli_flags {
798         CLI_SET_MEA     = 1 << 0,
799         CLI_RM_ENTRY    = 1 << 1,
800         CLI_HASH64      = 1 << 2,
801         CLI_API32       = 1 << 3,
802         CLI_MIGRATE     = 1 << 4,
803 };
804
805 struct md_op_data {
806         struct lu_fid           op_fid1; /* operation fid1 (usualy parent) */
807         struct lu_fid           op_fid2; /* operation fid2 (usualy child) */
808         struct lu_fid           op_fid3; /* 2 extra fids to find conflicting */
809         struct lu_fid           op_fid4; /* to the operation locks. */
810         u32                     op_mds;  /* what mds server open will go to */
811         struct lustre_handle    op_handle;
812         obd_time                op_mod_time;
813         const char             *op_name;
814         size_t                  op_namelen;
815         __u32                   op_mode;
816         struct lmv_stripe_md   *op_mea1;
817         struct lmv_stripe_md   *op_mea2;
818         __u32                   op_suppgids[2];
819         __u32                   op_fsuid;
820         __u32                   op_fsgid;
821         cfs_cap_t               op_cap;
822         void                   *op_data;
823         size_t                  op_data_size;
824
825         /* iattr fields and blocks. */
826         struct iattr            op_attr;
827         loff_t                  op_attr_blocks;
828         unsigned int            op_attr_flags; /* LUSTRE_{SYNC,..}_FL */
829         __u64                   op_valid; /* OBD_MD_* */
830
831         /* Size-on-MDS epoch and flags. */
832         __u64                   op_ioepoch;
833         enum md_op_flags        op_flags;
834
835         /* Capa fields */
836         struct obd_capa        *op_capa1;
837         struct obd_capa        *op_capa2;
838
839         /* Various operation flags. */
840         enum mds_op_bias        op_bias;
841
842         /* Used by readdir */
843         unsigned int            op_max_pages;
844
845         /* used to transfer info between the stacks of MD client
846          * see enum op_cli_flags */
847         enum md_cli_flags       op_cli_flags;
848
849         /* File object data version for HSM release, on client */
850         __u64                   op_data_version;
851         struct lustre_handle    op_lease_handle;
852 };
853
854 struct md_callback {
855         int (*md_blocking_ast)(struct ldlm_lock *lock,
856                                struct ldlm_lock_desc *desc,
857                                void *data, int flag);
858 };
859
860 struct md_enqueue_info;
861 /* metadata stat-ahead */
862 typedef int (* md_enqueue_cb_t)(struct ptlrpc_request *req,
863                                 struct md_enqueue_info *minfo,
864                                 int rc);
865
866 struct md_enqueue_info {
867         struct md_op_data       mi_data;
868         struct lookup_intent    mi_it;
869         struct lustre_handle    mi_lockh;
870         struct inode           *mi_dir;
871         md_enqueue_cb_t         mi_cb;
872         void                   *mi_cbdata;
873 };
874
875 struct obd_ops {
876         struct module *o_owner;
877         int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
878                            void *karg, void __user *uarg);
879         int (*o_get_info)(const struct lu_env *env, struct obd_export *,
880                           __u32 keylen, void *key, __u32 *vallen, void *val,
881                           struct lov_stripe_md *lsm);
882         int (*o_set_info_async)(const struct lu_env *, struct obd_export *,
883                                 __u32 keylen, void *key,
884                                 __u32 vallen, void *val,
885                                 struct ptlrpc_request_set *set);
886         int (*o_setup) (struct obd_device *dev, struct lustre_cfg *cfg);
887         int (*o_precleanup)(struct obd_device *dev,
888                             enum obd_cleanup_stage cleanup_stage);
889         int (*o_cleanup)(struct obd_device *dev);
890         int (*o_process_config)(struct obd_device *dev, obd_count len,
891                                 void *data);
892         int (*o_postrecov)(struct obd_device *dev);
893         int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
894                           int priority);
895         int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
896         /* connect to the target device with given connection
897          * data. @ocd->ocd_connect_flags is modified to reflect flags actually
898          * granted by the target, which are guaranteed to be a subset of flags
899          * asked for. If @ocd == NULL, use default parameters. */
900         int (*o_connect)(const struct lu_env *env,
901                          struct obd_export **exp, struct obd_device *src,
902                          struct obd_uuid *cluuid, struct obd_connect_data *ocd,
903                          void *localdata);
904         int (*o_reconnect)(const struct lu_env *env,
905                            struct obd_export *exp, struct obd_device *src,
906                            struct obd_uuid *cluuid,
907                            struct obd_connect_data *ocd,
908                            void *localdata);
909         int (*o_disconnect)(struct obd_export *exp);
910
911         /* Initialize/finalize fids infrastructure. */
912         int (*o_fid_init)(struct obd_device *obd,
913                           struct obd_export *exp, enum lu_cli_type type);
914         int (*o_fid_fini)(struct obd_device *obd);
915
916         /* Allocate new fid according to passed @hint. */
917         int (*o_fid_alloc)(const struct lu_env *env, struct obd_export *exp,
918                            struct lu_fid *fid, struct md_op_data *op_data);
919
920         /*
921          * Object with @fid is getting deleted, we may want to do something
922          * about this.
923          */
924         int (*o_statfs)(const struct lu_env *, struct obd_export *exp,
925                         struct obd_statfs *osfs, __u64 max_age, __u32 flags);
926         int (*o_statfs_async)(struct obd_export *exp, struct obd_info *oinfo,
927                               __u64 max_age, struct ptlrpc_request_set *set);
928         int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
929                         struct lov_stripe_md *mem_src);
930         int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
931                           struct lov_mds_md *disk_src, int disk_len);
932         int (*o_create)(const struct lu_env *env, struct obd_export *exp,
933                         struct obdo *oa, struct obd_trans_info *oti);
934         int (*o_destroy)(const struct lu_env *env, struct obd_export *exp,
935                          struct obdo *oa, struct obd_trans_info *oti);
936         int (*o_setattr)(const struct lu_env *, struct obd_export *exp,
937                          struct obd_info *oinfo, struct obd_trans_info *oti);
938         int (*o_setattr_async)(struct obd_export *exp, struct obd_info *oinfo,
939                                struct obd_trans_info *oti,
940                                struct ptlrpc_request_set *rqset);
941         int (*o_getattr)(const struct lu_env *env, struct obd_export *exp,
942                          struct obd_info *oinfo);
943         int (*o_getattr_async)(struct obd_export *exp, struct obd_info *oinfo,
944                                struct ptlrpc_request_set *set);
945         int (*o_preprw)(const struct lu_env *env, int cmd,
946                         struct obd_export *exp, struct obdo *oa, int objcount,
947                         struct obd_ioobj *obj, struct niobuf_remote *remote,
948                         int *nr_pages, struct niobuf_local *local,
949                         struct obd_trans_info *oti, struct lustre_capa *capa);
950         int (*o_commitrw)(const struct lu_env *env, int cmd,
951                           struct obd_export *exp, struct obdo *oa,
952                           int objcount, struct obd_ioobj *obj,
953                           struct niobuf_remote *remote, int pages,
954                           struct niobuf_local *local,
955                           struct obd_trans_info *oti, int rc);
956         int (*o_change_cbdata)(struct obd_export *, struct lov_stripe_md *,
957                                ldlm_iterator_t it, void *data);
958         int (*o_find_cbdata)(struct obd_export *, struct lov_stripe_md *,
959                              ldlm_iterator_t it, void *data);
960         int (*o_init_export)(struct obd_export *exp);
961         int (*o_destroy_export)(struct obd_export *exp);
962
963         int (*o_import_event)(struct obd_device *, struct obd_import *,
964                               enum obd_import_event);
965
966         int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
967                         enum obd_notify_event ev, void *data);
968
969         int (*o_health_check)(const struct lu_env *env, struct obd_device *);
970         struct obd_uuid *(*o_get_uuid) (struct obd_export *exp);
971
972         /* quota methods */
973         int (*o_quotacheck)(struct obd_device *, struct obd_export *,
974                             struct obd_quotactl *);
975         int (*o_quotactl)(struct obd_device *, struct obd_export *,
976                           struct obd_quotactl *);
977
978         int (*o_ping)(const struct lu_env *, struct obd_export *exp);
979
980         /* pools methods */
981         int (*o_pool_new)(struct obd_device *obd, char *poolname);
982         int (*o_pool_del)(struct obd_device *obd, char *poolname);
983         int (*o_pool_add)(struct obd_device *obd, char *poolname,
984                           char *ostname);
985         int (*o_pool_rem)(struct obd_device *obd, char *poolname,
986                           char *ostname);
987         void (*o_getref)(struct obd_device *obd);
988         void (*o_putref)(struct obd_device *obd);
989         /*
990          * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
991          * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
992          * Also, add a wrapper function in include/linux/obd_class.h. */
993 };
994
995 /* lmv structures */
996 struct lustre_md {
997         struct mdt_body         *body;
998         struct lov_stripe_md    *lsm;
999         struct lmv_stripe_md    *lmv;
1000 #ifdef CONFIG_FS_POSIX_ACL
1001         struct posix_acl        *posix_acl;
1002 #endif
1003         struct mdt_remote_perm  *remote_perm;
1004         struct obd_capa         *mds_capa;
1005         struct obd_capa         *oss_capa;
1006 };
1007
1008 struct md_open_data {
1009         struct obd_client_handle        *mod_och;
1010         struct ptlrpc_request           *mod_open_req;
1011         struct ptlrpc_request           *mod_close_req;
1012         atomic_t                         mod_refcount;
1013         bool                             mod_is_create;
1014 };
1015
1016 struct obd_client_handle {
1017         struct lustre_handle     och_fh;
1018         struct lu_fid            och_fid;
1019         struct md_open_data     *och_mod;
1020         struct lustre_handle     och_lease_handle; /* open lock for lease */
1021         __u32                    och_magic;
1022         int                      och_flags;
1023 };
1024
1025 #define OBD_CLIENT_HANDLE_MAGIC 0xd15ea5ed
1026
1027 struct lookup_intent;
1028 struct cl_attr;
1029
1030 struct md_ops {
1031         /* Every operation from MD_STATS_FIRST_OP up to and including
1032          * MD_STATS_LAST_OP will be counted by EXP_MD_OP_INCREMENT()
1033          * and will appear in /proc/fs/lustre/{lmv,mdc}/.../md_stats.
1034          * Operations after MD_STATS_LAST_OP are excluded from stats.
1035          * There are a few reasons for doing this: we prune the 17
1036          * counters which will be of minimal use in understanding
1037          * metadata utilization, we save memory by allocating 15
1038          * instead of 32 counters, we save cycles by not counting.
1039          *
1040          * MD_STATS_FIRST_OP must be the first member of md_ops.
1041          */
1042 #define MD_STATS_FIRST_OP m_close
1043         int (*m_close)(struct obd_export *, struct md_op_data *,
1044                        struct md_open_data *, struct ptlrpc_request **);
1045
1046         int (*m_create)(struct obd_export *, struct md_op_data *,
1047                         const void *, size_t, umode_t, uid_t, gid_t,
1048                         cfs_cap_t, __u64, struct ptlrpc_request **);
1049
1050         int (*m_enqueue)(struct obd_export *, struct ldlm_enqueue_info *,
1051                          const union ldlm_policy_data *,
1052                          struct lookup_intent *, struct md_op_data *,
1053                          struct lustre_handle *, __u64);
1054
1055         int (*m_getattr)(struct obd_export *, struct md_op_data *,
1056                          struct ptlrpc_request **);
1057
1058         int (*m_intent_lock)(struct obd_export *, struct md_op_data *,
1059                              struct lookup_intent *,
1060                              struct ptlrpc_request **,
1061                              ldlm_blocking_callback, __u64);
1062
1063         int (*m_link)(struct obd_export *, struct md_op_data *,
1064                       struct ptlrpc_request **);
1065
1066         int (*m_rename)(struct obd_export *, struct md_op_data *,
1067                         const char *, size_t, const char *, size_t,
1068                         struct ptlrpc_request **);
1069
1070         int (*m_setattr)(struct obd_export *, struct md_op_data *, void *,
1071                         size_t , void *, size_t, struct ptlrpc_request **,
1072                          struct md_open_data **mod);
1073
1074         int (*m_fsync)(struct obd_export *, const struct lu_fid *,
1075                        struct obd_capa *, struct ptlrpc_request **);
1076
1077         int (*m_read_page)(struct obd_export *, struct md_op_data *,
1078                            struct md_callback *cb_op, __u64 hash_offset,
1079                            struct page **ppage);
1080
1081         int (*m_unlink)(struct obd_export *, struct md_op_data *,
1082                         struct ptlrpc_request **);
1083
1084         int (*m_setxattr)(struct obd_export *, const struct lu_fid *,
1085                           struct obd_capa *, obd_valid, const char *,
1086                           const char *, int, int, int, __u32,
1087                           struct ptlrpc_request **);
1088
1089         int (*m_getxattr)(struct obd_export *, const struct lu_fid *,
1090                           struct obd_capa *, obd_valid, const char *,
1091                           const char *, int, int, int,
1092                           struct ptlrpc_request **);
1093
1094         int (*m_intent_getattr_async)(struct obd_export *,
1095                                       struct md_enqueue_info *,
1096                                       struct ldlm_enqueue_info *);
1097
1098         int (*m_revalidate_lock)(struct obd_export *, struct lookup_intent *,
1099                                  struct lu_fid *, __u64 *bits);
1100
1101 #define MD_STATS_LAST_OP m_revalidate_lock
1102
1103         int (*m_getstatus)(struct obd_export *, struct lu_fid *,
1104                            struct obd_capa **);
1105
1106         int (*m_null_inode)(struct obd_export *, const struct lu_fid *);
1107
1108         int (*m_find_cbdata)(struct obd_export *, const struct lu_fid *,
1109                              ldlm_iterator_t, void *);
1110
1111         int (*m_done_writing)(struct obd_export *, struct md_op_data  *,
1112                               struct md_open_data *);
1113
1114         int (*m_getattr_name)(struct obd_export *, struct md_op_data *,
1115                               struct ptlrpc_request **);
1116
1117         int (*m_init_ea_size)(struct obd_export *, __u32, __u32, __u32, __u32);
1118
1119         int (*m_get_lustre_md)(struct obd_export *, struct ptlrpc_request *,
1120                                struct obd_export *, struct obd_export *,
1121                                struct lustre_md *);
1122
1123         int (*m_free_lustre_md)(struct obd_export *, struct lustre_md *);
1124
1125         int (*m_merge_attr)(struct obd_export *,
1126                             const struct lmv_stripe_md *lsm,
1127                             struct cl_attr *attr);
1128
1129         int (*m_update_lsm_md)(struct obd_export *, struct lmv_stripe_md *lsm,
1130                                struct mdt_body *, ldlm_blocking_callback);
1131
1132         int (*m_set_open_replay_data)(struct obd_export *,
1133                                       struct obd_client_handle *,
1134                                       struct lookup_intent *);
1135
1136         int (*m_clear_open_replay_data)(struct obd_export *,
1137                                         struct obd_client_handle *);
1138
1139         int (*m_set_lock_data)(struct obd_export *, __u64 *, void *, __u64 *);
1140
1141         ldlm_mode_t (*m_lock_match)(struct obd_export *, __u64,
1142                                     const struct lu_fid *, ldlm_type_t,
1143                                     ldlm_policy_data_t *, ldlm_mode_t,
1144                                     struct lustre_handle *);
1145
1146         int (*m_cancel_unused)(struct obd_export *, const struct lu_fid *,
1147                                ldlm_policy_data_t *, ldlm_mode_t,
1148                                ldlm_cancel_flags_t flags, void *opaque);
1149
1150         int (*m_renew_capa)(struct obd_export *, struct obd_capa *oc,
1151                             renew_capa_cb_t cb);
1152
1153         int (*m_unpack_capa)(struct obd_export *, struct ptlrpc_request *,
1154                              const struct req_msg_field *, struct obd_capa **);
1155
1156         int (*m_get_remote_perm)(struct obd_export *, const struct lu_fid *,
1157                                  struct obd_capa *, __u32,
1158                                  struct ptlrpc_request **);
1159
1160         int (*m_get_fid_from_lsm)(struct obd_export *,
1161                                   const struct lmv_stripe_md *,
1162                                   const char *name, int namelen,
1163                                   struct lu_fid *fid);
1164 };
1165
1166 struct lsm_operations {
1167         void (*lsm_free)(struct lov_stripe_md *);
1168         void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *, obd_off *,
1169                                     obd_off *);
1170         void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *, obd_off *,
1171                                      obd_off *);
1172         int (*lsm_lmm_verify) (struct lov_mds_md *lmm, int lmm_bytes,
1173                                __u16 *stripe_count);
1174         int (*lsm_unpackmd) (struct lov_obd *lov, struct lov_stripe_md *lsm,
1175                              struct lov_mds_md *lmm);
1176 };
1177
1178 extern const struct lsm_operations lsm_v1_ops;
1179 extern const struct lsm_operations lsm_v3_ops;
1180 static inline const struct lsm_operations *lsm_op_find(int magic)
1181 {
1182         switch(magic) {
1183         case LOV_MAGIC_V1:
1184                return &lsm_v1_ops;
1185         case LOV_MAGIC_V3:
1186                return &lsm_v3_ops;
1187         default:
1188                CERROR("Cannot recognize lsm_magic %08x\n", magic);
1189                return NULL;
1190         }
1191 }
1192
1193 static inline struct md_open_data *obd_mod_alloc(void)
1194 {
1195         struct md_open_data *mod;
1196         OBD_ALLOC_PTR(mod);
1197         if (mod == NULL)
1198                 return NULL;
1199         atomic_set(&mod->mod_refcount, 1);
1200         return mod;
1201 }
1202
1203 #define obd_mod_get(mod) atomic_inc(&(mod)->mod_refcount)
1204 #define obd_mod_put(mod)                                          \
1205 ({                                                                \
1206         if (atomic_dec_and_test(&(mod)->mod_refcount)) {          \
1207                 if ((mod)->mod_open_req)                          \
1208                         ptlrpc_req_finished((mod)->mod_open_req); \
1209                 OBD_FREE_PTR(mod);                                \
1210         }                                                         \
1211 })
1212
1213 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
1214 void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent);
1215
1216 /* return 1 if client should be resend request */
1217 static inline int client_should_resend(int resend, struct client_obd *cli)
1218 {
1219         return atomic_read(&cli->cl_resends) ?
1220                atomic_read(&cli->cl_resends) > resend : 1;
1221 }
1222
1223 /**
1224  * Return device name for this device
1225  *
1226  * XXX: lu_device is declared before obd_device, while a pointer pointing
1227  * back to obd_device in lu_device, so this helper function defines here
1228  * instead of in lu_object.h
1229  */
1230 static inline const char *lu_dev_name(const struct lu_device *lu_dev)
1231 {
1232         return lu_dev->ld_obd->obd_name;
1233 }
1234
1235 static inline bool filename_is_volatile(const char *name, size_t namelen,
1236                                         int *idx)
1237 {
1238         const char      *start;
1239         char            *end;
1240
1241         if (strncmp(name, LUSTRE_VOLATILE_HDR, LUSTRE_VOLATILE_HDR_LEN) != 0)
1242                 return false;
1243
1244         /* caller does not care of idx */
1245         if (idx == NULL)
1246                 return true;
1247
1248         /* volatile file, the MDT can be set from name */
1249         /* name format is LUSTRE_VOLATILE_HDR:[idx]: */
1250         /* if no MDT is specified, use std way */
1251         if (namelen < LUSTRE_VOLATILE_HDR_LEN + 2)
1252                 goto bad_format;
1253         /* test for no MDT idx case */
1254         if ((*(name + LUSTRE_VOLATILE_HDR_LEN) == ':') &&
1255             (*(name + LUSTRE_VOLATILE_HDR_LEN + 1) == ':')) {
1256                 *idx = -1;
1257                 return true;
1258         }
1259         /* we have an idx, read it */
1260         start = name + LUSTRE_VOLATILE_HDR_LEN + 1;
1261         *idx = strtoul(start, &end, 16);
1262         /* error cases:
1263          * no digit, no trailing :, negative value
1264          */
1265         if (((*idx == 0) && (end == start)) ||
1266             (*end != ':') || (*idx < 0))
1267                 goto bad_format;
1268
1269         return true;
1270 bad_format:
1271         /* bad format of mdt idx, we cannot return an error
1272          * to caller so we use hash algo */
1273         CERROR("Bad volatile file name format: %s\n",
1274                name + LUSTRE_VOLATILE_HDR_LEN);
1275         return false;
1276 }
1277
1278 static inline int cli_brw_size(struct obd_device *obd)
1279 {
1280         LASSERT(obd != NULL);
1281         return obd->u.cli.cl_max_pages_per_rpc << PAGE_CACHE_SHIFT;
1282 }
1283
1284 /* when RPC size or the max RPCs in flight is increased, the max dirty pages
1285  * of the client should be increased accordingly to avoid sending fragmented
1286  * RPCs over the network when the client runs out of the maximum dirty space
1287  * when so many RPCs are being generated.
1288  */
1289 static inline void client_adjust_max_dirty(struct client_obd *cli)
1290 {
1291          /* initializing */
1292         if (cli->cl_dirty_max_pages <= 0)
1293                 cli->cl_dirty_max_pages = (OSC_MAX_DIRTY_DEFAULT * 1024 * 1024)
1294                                                         >> PAGE_CACHE_SHIFT;
1295         else {
1296                 unsigned long dirty_max = cli->cl_max_rpcs_in_flight *
1297                                           cli->cl_max_pages_per_rpc;
1298
1299                 if (dirty_max > cli->cl_dirty_max_pages)
1300                         cli->cl_dirty_max_pages = dirty_max;
1301         }
1302
1303         if (cli->cl_dirty_max_pages > totalram_pages / 8)
1304                 cli->cl_dirty_max_pages = totalram_pages / 8;
1305 }
1306
1307 #endif /* __OBD_H */