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