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