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