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