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