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