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