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