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