0f48e9c3d9e30f14153ec2533299ed3c52b9a321
[linux-2.6-microblaze.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_handles.h"
45 #include "lustre_intent.h"
46
47 #define MAX_OBD_DEVICES 8192
48
49 struct osc_async_rc {
50         int     ar_rc;
51         int     ar_force_sync;
52         __u64   ar_min_xid;
53 };
54
55 struct lov_oinfo {               /* per-stripe data structure */
56         struct ost_id   loi_oi;    /* object ID/Sequence on the target OST */
57         int loi_ost_idx;           /* OST stripe index in lov_tgt_desc->tgts */
58         int loi_ost_gen;           /* generation of this loi_ost_idx */
59
60         unsigned long loi_kms_valid:1;
61         __u64 loi_kms;       /* known minimum size */
62         struct ost_lvb loi_lvb;
63         struct osc_async_rc     loi_ar;
64 };
65
66 static inline void loi_kms_set(struct lov_oinfo *oinfo, __u64 kms)
67 {
68         oinfo->loi_kms = kms;
69         oinfo->loi_kms_valid = 1;
70 }
71
72 static inline void loi_init(struct lov_oinfo *loi)
73 {
74 }
75
76 struct lov_stripe_md;
77 struct obd_info;
78
79 typedef int (*obd_enqueue_update_f)(void *cookie, int rc);
80
81 /* obd info for a particular level (lov, osc). */
82 struct obd_info {
83         /* OBD_STATFS_* flags */
84         __u64              oi_flags;
85         /* lsm data specific for every OSC. */
86         struct lov_stripe_md   *oi_md;
87         /* statfs data specific for every OSC, if needed at all. */
88         struct obd_statfs      *oi_osfs;
89         /* An update callback which is called to update some data on upper
90          * level. E.g. it is used for update lsm->lsm_oinfo at every received
91          * request in osc level for enqueue requests. It is also possible to
92          * update some caller data from LOV layer if needed.
93          */
94         obd_enqueue_update_f    oi_cb_up;
95 };
96
97 struct obd_type {
98         struct list_head typ_chain;
99         struct obd_ops *typ_dt_ops;
100         struct md_ops *typ_md_ops;
101         struct dentry *typ_debugfs_entry;
102         char *typ_name;
103         int  typ_refcnt;
104         struct lu_device_type *typ_lu;
105         spinlock_t obd_type_lock;
106         struct kobject *typ_kobj;
107 };
108
109 struct brw_page {
110         u64 off;
111         struct page *pg;
112         unsigned int count;
113         u32 flag;
114 };
115
116 struct timeout_item {
117         enum timeout_event ti_event;
118         unsigned long    ti_timeout;
119         timeout_cb_t       ti_cb;
120         void          *ti_cb_data;
121         struct list_head         ti_obd_list;
122         struct list_head         ti_chain;
123 };
124
125 #define OBD_MAX_RIF_DEFAULT     8
126 #define OBD_MAX_RIF_MAX         512
127 #define OSC_MAX_RIF_MAX         256
128 #define OSC_MAX_DIRTY_DEFAULT   (OBD_MAX_RIF_DEFAULT * 4)
129 #define OSC_MAX_DIRTY_MB_MAX    2048    /* arbitrary, but < MAX_LONG bytes */
130 #define OSC_DEFAULT_RESENDS     10
131
132 /* possible values for fo_sync_lock_cancel */
133 enum {
134         NEVER_SYNC_ON_CANCEL = 0,
135         BLOCKING_SYNC_ON_CANCEL = 1,
136         ALWAYS_SYNC_ON_CANCEL = 2,
137         NUM_SYNC_ON_CANCEL_STATES
138 };
139
140 enum obd_cl_sem_lock_class {
141         OBD_CLI_SEM_NORMAL,
142         OBD_CLI_SEM_MGC,
143         OBD_CLI_SEM_MDCOSC,
144 };
145
146 /*
147  * Limit reply buffer size for striping data to one x86_64 page. This
148  * value is chosen to fit the striping data for common use cases while
149  * staying well below the limit at which the buffer must be backed by
150  * vmalloc(). Excessive use of vmalloc() may cause spinlock contention
151  * on the MDS.
152  */
153 #define OBD_MAX_DEFAULT_EA_SIZE         4096
154
155 struct mdc_rpc_lock;
156 struct obd_import;
157 struct client_obd {
158         struct rw_semaphore  cl_sem;
159         struct obd_uuid   cl_target_uuid;
160         struct obd_import       *cl_import; /* ptlrpc connection state */
161         size_t                   cl_conn_count;
162         /*
163          * Cache maximum and default values for easize. This is
164          * strictly a performance optimization to minimize calls to
165          * obd_size_diskmd(). The default values are used to calculate the
166          * initial size of a request buffer. The ptlrpc layer will resize the
167          * buffer as needed to accommodate a larger reply from the
168          * server. The default values should be small enough to avoid wasted
169          * memory and excessive use of vmalloc(), yet large enough to avoid
170          * reallocating the buffer in the common use case.
171          */
172         /*
173          * Default EA size for striping attributes. It is initialized at
174          * mount-time based on the default stripe width of the filesystem,
175          * then it tracks the largest observed EA size advertised by
176          * the MDT, up to a maximum value of OBD_MAX_DEFAULT_EA_SIZE.
177          */
178         u32                      cl_default_mds_easize;
179         /* Maximum possible EA size computed at mount-time based on
180          * the number of OSTs in the filesystem. May be increased at
181          * run-time if a larger observed size is advertised by the MDT.
182          */
183         u32                      cl_max_mds_easize;
184
185         enum lustre_sec_part     cl_sp_me;
186         enum lustre_sec_part     cl_sp_to;
187         struct sptlrpc_flavor    cl_flvr_mgc;   /* fixed flavor of mgc->mgs */
188
189         /* the grant values are protected by loi_list_lock below */
190         unsigned long            cl_dirty_pages;        /* all _dirty_ in pahges */
191         unsigned long            cl_dirty_max_pages;    /* allowed w/o rpc */
192         unsigned long            cl_dirty_transit;      /* dirty synchronous */
193         unsigned long            cl_avail_grant;        /* bytes of credit for ost */
194         unsigned long            cl_lost_grant;         /* lost credits (trunc) */
195
196         /* since we allocate grant by blocks, we don't know how many grant will
197          * be used to add a page into cache. As a solution, we reserve maximum
198          * grant before trying to dirty a page and unreserve the rest.
199          * See osc_{reserve|unreserve}_grant for details.
200          */
201         long             cl_reserved_grant;
202         struct list_head cl_cache_waiters; /* waiting for cache/grant */
203         unsigned long    cl_next_shrink_grant;   /* jiffies */
204         struct list_head cl_grant_shrink_list;  /* Timeout event list */
205         int              cl_grant_shrink_interval; /* seconds */
206
207         /* A chunk is an optimal size used by osc_extent to determine
208          * the extent size. A chunk is max(PAGE_SIZE, OST block size)
209          */
210         int               cl_chunkbits;
211         unsigned int      cl_extent_tax; /* extent overhead, by bytes */
212
213         /* keep track of objects that have lois that contain pages which
214          * have been queued for async brw.  this lock also protects the
215          * lists of osc_client_pages that hang off of the loi
216          */
217         /*
218          * ->cl_loi_list_lock protects consistency of
219          * ->cl_loi_{ready,read,write}_list. ->ap_make_ready() and
220          * ->ap_completion() call-backs are executed under this lock. As we
221          * cannot guarantee that these call-backs never block on all platforms
222          * (as a matter of fact they do block on Mac OS X), type of
223          * ->cl_loi_list_lock is platform dependent: it's a spin-lock on Linux
224          * and blocking mutex on Mac OS X. (Alternative is to make this lock
225          * blocking everywhere, but we don't want to slow down fast-path of
226          * our main platform.)
227          *
228          * NB by Jinshan: though field names are still _loi_, but actually
229          * osc_object{}s are in the list.
230          */
231         spinlock_t                     cl_loi_list_lock;
232         struct list_head               cl_loi_ready_list;
233         struct list_head               cl_loi_hp_ready_list;
234         struct list_head               cl_loi_write_list;
235         struct list_head               cl_loi_read_list;
236         __u32                    cl_r_in_flight;
237         __u32                    cl_w_in_flight;
238         /* just a sum of the loi/lop pending numbers to be exported by sysfs */
239         atomic_t             cl_pending_w_pages;
240         atomic_t             cl_pending_r_pages;
241         __u32                    cl_max_pages_per_rpc;
242         __u32                    cl_max_rpcs_in_flight;
243         struct obd_histogram     cl_read_rpc_hist;
244         struct obd_histogram     cl_write_rpc_hist;
245         struct obd_histogram     cl_read_page_hist;
246         struct obd_histogram     cl_write_page_hist;
247         struct obd_histogram     cl_read_offset_hist;
248         struct obd_histogram     cl_write_offset_hist;
249
250         /* LRU for osc caching pages */
251         struct cl_client_cache  *cl_cache;
252         /** member of cl_cache->ccc_lru */
253         struct list_head         cl_lru_osc;
254         /** # of available LRU slots left in the per-OSC cache.
255          * Available LRU slots are shared by all OSCs of the same file system,
256          * therefore this is a pointer to cl_client_cache::ccc_lru_left.
257          */
258         atomic_long_t           *cl_lru_left;
259         /** # of busy LRU pages. A page is considered busy if it's in writeback
260          * queue, or in transfer. Busy pages can't be discarded so they are not
261          * in LRU cache.
262          */
263         atomic_long_t            cl_lru_busy;
264         /** # of LRU pages in the cache for this client_obd */
265         atomic_long_t            cl_lru_in_list;
266         /** # of threads are shrinking LRU cache. To avoid contention, it's not
267          * allowed to have multiple threads shrinking LRU cache.
268          */
269         atomic_t                 cl_lru_shrinkers;
270         /** The time when this LRU cache was last used. */
271         time64_t                 cl_lru_last_used;
272         /** stats: how many reclaims have happened for this client_obd.
273          * reclaim and shrink - shrink is async, voluntarily rebalancing;
274          * reclaim is sync, initiated by IO thread when the LRU slots are
275          * in shortage.
276          */
277         u64                      cl_lru_reclaim;
278         /** List of LRU pages for this client_obd */
279         struct list_head         cl_lru_list;
280         /** Lock for LRU page list */
281         spinlock_t               cl_lru_list_lock;
282         /** # of unstable pages in this client_obd.
283          * An unstable page is a page state that WRITE RPC has finished but
284          * the transaction has NOT yet committed.
285          */
286         atomic_long_t            cl_unstable_count;
287
288         /* number of in flight destroy rpcs is limited to max_rpcs_in_flight */
289         atomic_t             cl_destroy_in_flight;
290         wait_queue_head_t             cl_destroy_waitq;
291
292         struct mdc_rpc_lock     *cl_rpc_lock;
293
294         /* modify rpcs in flight
295          * currently used for metadata only
296          */
297         spinlock_t               cl_mod_rpcs_lock;
298         u16                      cl_max_mod_rpcs_in_flight;
299         u16                      cl_mod_rpcs_in_flight;
300         u16                      cl_close_rpcs_in_flight;
301         wait_queue_head_t        cl_mod_rpcs_waitq;
302         unsigned long           *cl_mod_tag_bitmap;
303         struct obd_histogram     cl_mod_rpcs_hist;
304
305         /* mgc datastruct */
306         atomic_t             cl_mgc_refcount;
307         struct obd_export       *cl_mgc_mgsexp;
308
309         /* checksumming for data sent over the network */
310         unsigned int         cl_checksum:1; /* 0 = disabled, 1 = enabled */
311         /* supported checksum types that are worked out at connect time */
312         __u32               cl_supp_cksum_types;
313         /* checksum algorithm to be used */
314         enum cksum_type      cl_cksum_type;
315
316         /* also protected by the poorly named _loi_list_lock lock above */
317         struct osc_async_rc      cl_ar;
318
319         /* sequence manager */
320         struct lu_client_seq    *cl_seq;
321
322         atomic_t             cl_resends; /* resend count */
323
324         /* ptlrpc work for writeback in ptlrpcd context */
325         void                *cl_writeback_work;
326         void                    *cl_lru_work;
327         /* hash tables for osc_quota_info */
328         struct cfs_hash       *cl_quota_hash[MAXQUOTAS];
329 };
330
331 #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
332
333 struct obd_id_info {
334         __u32   idx;
335         u64     *data;
336 };
337
338 struct echo_client_obd {
339         struct obd_export       *ec_exp;   /* the local connection to osc/lov */
340         spinlock_t              ec_lock;
341         struct list_head           ec_objects;
342         struct list_head           ec_locks;
343         __u64           ec_unique;
344 };
345
346 /* Generic subset of OSTs */
347 struct ost_pool {
348         __u32         *op_array;      /* array of index of lov_obd->lov_tgts */
349         unsigned int    op_count;      /* number of OSTs in the array */
350         unsigned int    op_size;       /* allocated size of lp_array */
351         struct rw_semaphore op_rw_sem;     /* to protect ost_pool use */
352 };
353
354 /* allow statfs data caching for 1 second */
355 #define OBD_STATFS_CACHE_SECONDS 1
356
357 struct lov_tgt_desc {
358         struct list_head          ltd_kill;
359         struct obd_uuid     ltd_uuid;
360         struct obd_device  *ltd_obd;
361         struct obd_export  *ltd_exp;
362         __u32          ltd_gen;
363         __u32          ltd_index;   /* index in lov_obd->tgts */
364         unsigned long       ltd_active:1,/* is this target up for requests */
365                             ltd_activate:1,/* should  target be activated */
366                             ltd_reap:1;  /* should this target be deleted */
367 };
368
369 struct lov_obd {
370         struct lov_desc  desc;
371         struct lov_tgt_desc   **lov_tgts;             /* sparse array */
372         struct ost_pool  lov_packed;        /* all OSTs in a packed array */
373         struct mutex            lov_lock;
374         struct obd_connect_data lov_ocd;
375         atomic_t            lov_refcount;
376         __u32              lov_death_row;/* tgts scheduled to be deleted */
377         __u32              lov_tgt_size;   /* size of tgts array */
378         int                  lov_connects;
379         int                  lov_pool_count;
380         struct cfs_hash      *lov_pools_hash_body; /* used for key access */
381         struct list_head        lov_pool_list; /* used for sequential access */
382         struct dentry           *lov_pool_debugfs_entry;
383         enum lustre_sec_part    lov_sp_me;
384
385         /* Cached LRU and unstable data from upper layer */
386         struct cl_client_cache *lov_cache;
387
388         struct rw_semaphore     lov_notify_lock;
389
390         struct kobject          *lov_tgts_kobj;
391 };
392
393 struct lmv_tgt_desc {
394         struct obd_uuid         ltd_uuid;
395         struct obd_export       *ltd_exp;
396         u32                     ltd_idx;
397         struct mutex            ltd_fid_mutex;
398         unsigned long           ltd_active:1; /* target up for requests */
399 };
400
401 enum placement_policy {
402         PLACEMENT_CHAR_POLICY   = 0,
403         PLACEMENT_NID_POLICY    = 1,
404         PLACEMENT_INVAL_POLICY  = 2,
405         PLACEMENT_MAX_POLICY
406 };
407
408 struct lmv_obd {
409         int                     refcount;
410         struct lu_client_fld    lmv_fld;
411         spinlock_t              lmv_lock;
412         enum placement_policy   lmv_placement;
413         struct lmv_desc         desc;
414         struct obd_uuid         cluuid;
415         struct obd_export       *exp;
416
417         struct mutex            lmv_init_mutex;
418         int                     connected;
419         int                     max_easize;
420         int                     max_def_easize;
421
422         u32                     tgts_size; /* size of tgts array */
423         struct lmv_tgt_desc     **tgts;
424
425         struct obd_connect_data conn_data;
426         struct kobject          *lmv_tgts_kobj;
427 };
428
429 struct niobuf_local {
430         __u64           lnb_file_offset;
431         __u32           lnb_page_offset;
432         __u32           lnb_len;
433         __u32           lnb_flags;
434         int             lnb_rc;
435         struct page     *lnb_page;
436         void            *lnb_data;
437 };
438
439 #define LUSTRE_FLD_NAME  "fld"
440 #define LUSTRE_SEQ_NAME  "seq"
441
442 #define LUSTRE_MDD_NAME  "mdd"
443 #define LUSTRE_OSD_LDISKFS_NAME "osd-ldiskfs"
444 #define LUSTRE_OSD_ZFS_NAME     "osd-zfs"
445 #define LUSTRE_VVP_NAME  "vvp"
446 #define LUSTRE_LMV_NAME  "lmv"
447 #define LUSTRE_SLP_NAME  "slp"
448 #define LUSTRE_LOD_NAME         "lod"
449 #define LUSTRE_OSP_NAME         "osp"
450 #define LUSTRE_LWP_NAME         "lwp"
451
452 /* obd device type names */
453  /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */
454 #define LUSTRE_MDS_NAME  "mds"
455 #define LUSTRE_MDT_NAME  "mdt"
456 #define LUSTRE_MDC_NAME  "mdc"
457 #define LUSTRE_OSS_NAME  "ost"       /* FIXME change name to oss */
458 #define LUSTRE_OST_NAME  "obdfilter" /* FIXME change name to ost */
459 #define LUSTRE_OSC_NAME  "osc"
460 #define LUSTRE_LOV_NAME  "lov"
461 #define LUSTRE_MGS_NAME  "mgs"
462 #define LUSTRE_MGC_NAME  "mgc"
463
464 #define LUSTRE_ECHO_NAME        "obdecho"
465 #define LUSTRE_ECHO_CLIENT_NAME "echo_client"
466 #define LUSTRE_QMT_NAME  "qmt"
467
468 /* Constant obd names (post-rename) */
469 #define LUSTRE_MDS_OBDNAME "MDS"
470 #define LUSTRE_OSS_OBDNAME "OSS"
471 #define LUSTRE_MGS_OBDNAME "MGS"
472 #define LUSTRE_MGC_OBDNAME "MGC"
473
474 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
475 #define N_LOCAL_TEMP_PAGE 0x10000000
476
477 /*
478  * Events signalled through obd_notify() upcall-chain.
479  */
480 enum obd_notify_event {
481         /* target added */
482         OBD_NOTIFY_CREATE,
483         /* Device connect start */
484         OBD_NOTIFY_CONNECT,
485         /* Device activated */
486         OBD_NOTIFY_ACTIVE,
487         /* Device deactivated */
488         OBD_NOTIFY_INACTIVE,
489         /* Device disconnected */
490         OBD_NOTIFY_DISCON,
491         /* Connect data for import were changed */
492         OBD_NOTIFY_OCD,
493         /* Sync request */
494         OBD_NOTIFY_SYNC_NONBLOCK,
495         OBD_NOTIFY_SYNC,
496         /* Configuration event */
497         OBD_NOTIFY_CONFIG,
498         /* Administratively deactivate/activate event */
499         OBD_NOTIFY_DEACTIVATE,
500         OBD_NOTIFY_ACTIVATE
501 };
502
503 /*
504  * Data structure used to pass obd_notify()-event to non-obd listeners (llite
505  * being main example).
506  */
507 struct obd_notify_upcall {
508         int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
509                           enum obd_notify_event ev, void *owner, void *data);
510         /* Opaque datum supplied by upper layer listener */
511         void *onu_owner;
512 };
513
514 struct target_recovery_data {
515         svc_handler_t           trd_recovery_handler;
516         pid_t                   trd_processing_task;
517         struct completion       trd_starting;
518         struct completion       trd_finishing;
519 };
520
521 struct obd_llog_group {
522         struct llog_ctxt  *olg_ctxts[LLOG_MAX_CTXTS];
523         wait_queue_head_t       olg_waitq;
524         spinlock_t         olg_lock;
525         struct mutex       olg_cat_processing;
526 };
527
528 /* corresponds to one of the obd's */
529 #define OBD_DEVICE_MAGIC        0XAB5CD6EF
530
531 struct lvfs_run_ctxt {
532         struct dt_device *dt;
533 };
534
535 struct obd_device {
536         struct obd_type *obd_type;
537         u32                      obd_magic; /* OBD_DEVICE_MAGIC */
538         int                      obd_minor; /* device number: lctl dl */
539         struct lu_device        *obd_lu_dev;
540
541         /* common and UUID name of this device */
542         struct obd_uuid          obd_uuid;
543         char                     obd_name[MAX_OBD_NAME];
544
545         /* bitfield modification is protected by obd_dev_lock */
546         unsigned long obd_attached:1,      /* finished attach */
547                       obd_set_up:1,     /* finished setup */
548                       obd_version_recov:1, /* obd uses version checking */
549                       obd_replayable:1,/* recovery is enabled; inform clients */
550                       obd_no_transno:1,  /* no committed-transno notification */
551                       obd_no_recov:1,      /* fail instead of retry messages */
552                       obd_stopping:1,      /* started cleanup */
553                       obd_starting:1,      /* started setup */
554                       obd_force:1,       /* cleanup with > 0 obd refcount */
555                       obd_fail:1,        /* cleanup with failover */
556                       obd_no_conn:1,       /* deny new connections */
557                       obd_inactive:1,      /* device active/inactive
558                                             * (for sysfs status only!!)
559                                             */
560                       obd_no_ir:1,       /* no imperative recovery. */
561                       obd_process_conf:1;  /* device is processing mgs config */
562         /* use separate field as it is set in interrupt to don't mess with
563          * protection of other bits using _bh lock
564          */
565         unsigned long obd_recovery_expired:1;
566         /* uuid-export hash body */
567         struct cfs_hash      *obd_uuid_hash;
568         wait_queue_head_t            obd_refcount_waitq;
569         struct list_head              obd_exports;
570         struct list_head              obd_unlinked_exports;
571         struct list_head              obd_delayed_exports;
572         atomic_t                        obd_refcount;
573         int                  obd_num_exports;
574         spinlock_t              obd_nid_lock;
575         struct ldlm_namespace  *obd_namespace;
576         struct ptlrpc_client    obd_ldlm_client; /* XXX OST/MDS only */
577         /* a spinlock is OK for what we do now, may need a semaphore later */
578         spinlock_t              obd_dev_lock; /* protect OBD bitfield above */
579         spinlock_t              obd_osfs_lock;
580         struct obd_statfs       obd_osfs;       /* locked by obd_osfs_lock */
581         __u64                   obd_osfs_age;
582         u64                     obd_last_committed;
583         struct mutex            obd_dev_mutex;
584         struct lvfs_run_ctxt    obd_lvfs_ctxt;
585         struct obd_llog_group   obd_olg;        /* default llog group */
586         struct obd_device       *obd_observer;
587         struct rw_semaphore     obd_observer_link_sem;
588         struct obd_notify_upcall obd_upcall;
589         struct obd_export       *obd_self_export;
590
591         union {
592                 struct client_obd cli;
593                 struct echo_client_obd echo_client;
594                 struct lov_obd lov;
595                 struct lmv_obd lmv;
596         } u;
597
598         /* Fields used by LProcFS */
599         struct lprocfs_stats    *obd_stats;
600         unsigned int             obd_cntr_base;
601
602         struct lprocfs_stats    *md_stats;
603         unsigned int             md_cntr_base;
604
605         struct dentry           *obd_debugfs_entry;
606         struct dentry           *obd_svc_debugfs_entry;
607         struct lprocfs_stats  *obd_svc_stats;
608         atomic_t           obd_evict_inprogress;
609         wait_queue_head_t           obd_evict_inprogress_waitq;
610         struct list_head        obd_evict_list; /* protected with pet_lock */
611
612         /**
613          * Ldlm pool part. Save last calculated SLV and Limit.
614          */
615         rwlock_t                 obd_pool_lock;
616         u64                      obd_pool_slv;
617         int                      obd_pool_limit;
618
619         int                      obd_conn_inprogress;
620
621         /**
622          * A list of outstanding class_incref()'s against this obd. For
623          * debugging.
624          */
625         struct lu_ref     obd_reference;
626
627         struct kobject          obd_kobj; /* sysfs object */
628         struct completion       obd_kobj_unregister;
629 };
630
631 /* get/set_info keys */
632 #define KEY_ASYNC              "async"
633 #define KEY_CHANGELOG_CLEAR     "changelog_clear"
634 #define KEY_FID2PATH        "fid2path"
635 #define KEY_CHECKSUM        "checksum"
636 #define KEY_CLEAR_FS        "clear_fs"
637 #define KEY_CONN_DATA      "conn_data"
638 #define KEY_EVICT_BY_NID        "evict_by_nid"
639 #define KEY_FIEMAP            "fiemap"
640 #define KEY_FLUSH_CTX      "flush_ctx"
641 #define KEY_GRANT_SHRINK        "grant_shrink"
642 #define KEY_HSM_COPYTOOL_SEND   "hsm_send"
643 #define KEY_INIT_RECOV_BACKUP   "init_recov_bk"
644 #define KEY_INTERMDS        "inter_mds"
645 #define KEY_LAST_ID          "last_id"
646 #define KEY_LAST_FID            "last_fid"
647 #define KEY_MAX_EASIZE          "max_easize"
648 #define KEY_DEFAULT_EASIZE      "default_easize"
649 #define KEY_MGSSEC            "mgssec"
650 #define KEY_READ_ONLY      "read-only"
651 #define KEY_REGISTER_TARGET     "register_target"
652 #define KEY_SET_FS            "set_fs"
653 #define KEY_TGT_COUNT      "tgt_count"
654 /*      KEY_SET_INFO in lustre_idl.h */
655 #define KEY_SPTLRPC_CONF        "sptlrpc_conf"
656
657 #define KEY_CACHE_SET           "cache_set"
658 #define KEY_CACHE_LRU_SHRINK    "cache_lru_shrink"
659
660 struct lu_context;
661
662 static inline int it_to_lock_mode(struct lookup_intent *it)
663 {
664         /* CREAT needs to be tested before open (both could be set) */
665         if (it->it_op & IT_CREAT)
666                 return LCK_CW;
667         else if (it->it_op & (IT_GETATTR | IT_OPEN | IT_LOOKUP |
668                               IT_LAYOUT))
669                 return LCK_CR;
670         else if (it->it_op & IT_READDIR)
671                 return LCK_PR;
672         else if (it->it_op &  IT_GETXATTR)
673                 return LCK_PR;
674         else if (it->it_op &  IT_SETXATTR)
675                 return LCK_PW;
676
677         LASSERTF(0, "Invalid it_op: %d\n", it->it_op);
678         return -EINVAL;
679 }
680
681 enum md_op_flags {
682         MF_MDC_CANCEL_FID1      = BIT(0),
683         MF_MDC_CANCEL_FID2      = BIT(1),
684         MF_MDC_CANCEL_FID3      = BIT(2),
685         MF_MDC_CANCEL_FID4      = BIT(3),
686         MF_GET_MDT_IDX          = BIT(4),
687 };
688
689 enum md_cli_flags {
690         CLI_SET_MEA     = BIT(0),
691         CLI_RM_ENTRY    = BIT(1),
692         CLI_HASH64      = BIT(2),
693         CLI_API32       = BIT(3),
694         CLI_MIGRATE     = BIT(4),
695 };
696
697 struct md_op_data {
698         struct lu_fid      op_fid1; /* operation fid1 (usually parent) */
699         struct lu_fid      op_fid2; /* operation fid2 (usually child) */
700         struct lu_fid      op_fid3; /* 2 extra fids to find conflicting */
701         struct lu_fid      op_fid4; /* to the operation locks. */
702         u32                     op_mds;  /* what mds server open will go to */
703         struct lustre_handle    op_handle;
704         s64                     op_mod_time;
705         const char           *op_name;
706         size_t                  op_namelen;
707         __u32              op_mode;
708         struct lmv_stripe_md   *op_mea1;
709         struct lmv_stripe_md   *op_mea2;
710         __u32              op_suppgids[2];
711         __u32              op_fsuid;
712         __u32              op_fsgid;
713         cfs_cap_t              op_cap;
714         void               *op_data;
715         size_t                  op_data_size;
716
717         /* iattr fields and blocks. */
718         struct iattr        op_attr;
719         unsigned int        op_attr_flags;
720         __u64              op_valid;
721         loff_t            op_attr_blocks;
722
723         __u32              op_flags;
724
725         /* Various operation flags. */
726         enum mds_op_bias        op_bias;
727
728         /* Used by readdir */
729         __u64              op_offset;
730
731         /* Used by readdir */
732         __u32                   op_max_pages;
733
734         /* used to transfer info between the stacks of MD client
735          * see enum op_cli_flags
736          */
737         enum md_cli_flags       op_cli_flags;
738
739         /* File object data version for HSM release, on client */
740         __u64                   op_data_version;
741         struct lustre_handle    op_lease_handle;
742
743         /* default stripe offset */
744         __u32                   op_default_stripe_offset;
745 };
746
747 struct md_callback {
748         int (*md_blocking_ast)(struct ldlm_lock *lock,
749                                struct ldlm_lock_desc *desc,
750                                void *data, int flag);
751 };
752
753 struct md_enqueue_info;
754 /* metadata stat-ahead */
755
756 struct md_enqueue_info {
757         struct md_op_data       mi_data;
758         struct lookup_intent    mi_it;
759         struct lustre_handle    mi_lockh;
760         struct inode       *mi_dir;
761         int (*mi_cb)(struct ptlrpc_request *req,
762                      struct md_enqueue_info *minfo, int rc);
763         void                    *mi_cbdata;
764 };
765
766 struct obd_ops {
767         struct module *owner;
768         int (*iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
769                          void *karg, void __user *uarg);
770         int (*get_info)(const struct lu_env *env, struct obd_export *,
771                         __u32 keylen, void *key, __u32 *vallen, void *val);
772         int (*set_info_async)(const struct lu_env *, struct obd_export *,
773                               __u32 keylen, void *key,
774                               __u32 vallen, void *val,
775                               struct ptlrpc_request_set *set);
776         int (*setup)(struct obd_device *dev, struct lustre_cfg *cfg);
777         int (*precleanup)(struct obd_device *dev);
778         int (*cleanup)(struct obd_device *dev);
779         int (*process_config)(struct obd_device *dev, u32 len, void *data);
780         int (*postrecov)(struct obd_device *dev);
781         int (*add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
782                         int priority);
783         int (*del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
784         /* connect to the target device with given connection
785          * data. @ocd->ocd_connect_flags is modified to reflect flags actually
786          * granted by the target, which are guaranteed to be a subset of flags
787          * asked for. If @ocd == NULL, use default parameters.
788          */
789         int (*connect)(const struct lu_env *env,
790                        struct obd_export **exp, struct obd_device *src,
791                        struct obd_uuid *cluuid, struct obd_connect_data *ocd,
792                        void *localdata);
793         int (*reconnect)(const struct lu_env *env,
794                          struct obd_export *exp, struct obd_device *src,
795                          struct obd_uuid *cluuid,
796                          struct obd_connect_data *ocd,
797                          void *localdata);
798         int (*disconnect)(struct obd_export *exp);
799
800         /* Initialize/finalize fids infrastructure. */
801         int (*fid_init)(struct obd_device *obd,
802                         struct obd_export *exp, enum lu_cli_type type);
803         int (*fid_fini)(struct obd_device *obd);
804
805         /* Allocate new fid according to passed @hint. */
806         int (*fid_alloc)(const struct lu_env *env, struct obd_export *exp,
807                          struct lu_fid *fid, struct md_op_data *op_data);
808
809         /*
810          * Object with @fid is getting deleted, we may want to do something
811          * about this.
812          */
813         int (*statfs)(const struct lu_env *, struct obd_export *exp,
814                       struct obd_statfs *osfs, __u64 max_age, __u32 flags);
815         int (*statfs_async)(struct obd_export *exp, struct obd_info *oinfo,
816                             __u64 max_age, struct ptlrpc_request_set *set);
817         int (*create)(const struct lu_env *env, struct obd_export *exp,
818                       struct obdo *oa);
819         int (*destroy)(const struct lu_env *env, struct obd_export *exp,
820                        struct obdo *oa);
821         int (*setattr)(const struct lu_env *, struct obd_export *exp,
822                        struct obdo *oa);
823         int (*getattr)(const struct lu_env *env, struct obd_export *exp,
824                        struct obdo *oa);
825         int (*preprw)(const struct lu_env *env, int cmd,
826                       struct obd_export *exp, struct obdo *oa, int objcount,
827                       struct obd_ioobj *obj, struct niobuf_remote *remote,
828                       int *nr_pages, struct niobuf_local *local);
829         int (*commitrw)(const struct lu_env *env, int cmd,
830                         struct obd_export *exp, struct obdo *oa,
831                         int objcount, struct obd_ioobj *obj,
832                         struct niobuf_remote *remote, int pages,
833                         struct niobuf_local *local, int rc);
834         int (*init_export)(struct obd_export *exp);
835         int (*destroy_export)(struct obd_export *exp);
836
837         /* metadata-only methods */
838         int (*import_event)(struct obd_device *, struct obd_import *,
839                             enum obd_import_event);
840
841         int (*notify)(struct obd_device *obd, struct obd_device *watched,
842                       enum obd_notify_event ev, void *data);
843
844         int (*health_check)(const struct lu_env *env, struct obd_device *);
845         struct obd_uuid *(*get_uuid)(struct obd_export *exp);
846
847         /* quota methods */
848         int (*quotactl)(struct obd_device *, struct obd_export *,
849                         struct obd_quotactl *);
850
851         /* pools methods */
852         int (*pool_new)(struct obd_device *obd, char *poolname);
853         int (*pool_del)(struct obd_device *obd, char *poolname);
854         int (*pool_add)(struct obd_device *obd, char *poolname,
855                         char *ostname);
856         int (*pool_rem)(struct obd_device *obd, char *poolname,
857                         char *ostname);
858         void (*getref)(struct obd_device *obd);
859         void (*putref)(struct obd_device *obd);
860         /*
861          * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
862          * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
863          * Also, add a wrapper function in include/linux/obd_class.h.
864          */
865 };
866
867 /* lmv structures */
868 struct lustre_md {
869         struct mdt_body  *body;
870         struct lu_buf            layout;
871         struct lmv_stripe_md    *lmv;
872 #ifdef CONFIG_FS_POSIX_ACL
873         struct posix_acl        *posix_acl;
874 #endif
875         struct mdt_remote_perm  *remote_perm;
876 };
877
878 struct md_open_data {
879         struct obd_client_handle *mod_och;
880         struct ptlrpc_request    *mod_open_req;
881         struct ptlrpc_request    *mod_close_req;
882         atomic_t                  mod_refcount;
883         bool                      mod_is_create;
884 };
885
886 struct obd_client_handle {
887         struct lustre_handle     och_fh;
888         struct lu_fid            och_fid;
889         struct md_open_data     *och_mod;
890         struct lustre_handle     och_lease_handle; /* open lock for lease */
891         __u32                    och_magic;
892         int                      och_flags;
893 };
894
895 #define OBD_CLIENT_HANDLE_MAGIC 0xd15ea5ed
896
897 struct lookup_intent;
898 struct cl_attr;
899
900 struct md_ops {
901         int (*getstatus)(struct obd_export *, struct lu_fid *);
902         int (*null_inode)(struct obd_export *, const struct lu_fid *);
903         int (*close)(struct obd_export *, struct md_op_data *,
904                      struct md_open_data *, struct ptlrpc_request **);
905         int (*create)(struct obd_export *, struct md_op_data *,
906                       const void *, size_t, umode_t, uid_t, gid_t,
907                       cfs_cap_t, __u64, struct ptlrpc_request **);
908         int (*enqueue)(struct obd_export *, struct ldlm_enqueue_info *,
909                        const union ldlm_policy_data *,
910                        struct lookup_intent *, struct md_op_data *,
911                        struct lustre_handle *, __u64);
912         int (*getattr)(struct obd_export *, struct md_op_data *,
913                        struct ptlrpc_request **);
914         int (*getattr_name)(struct obd_export *, struct md_op_data *,
915                             struct ptlrpc_request **);
916         int (*intent_lock)(struct obd_export *, struct md_op_data *,
917                            struct lookup_intent *,
918                            struct ptlrpc_request **,
919                            ldlm_blocking_callback, __u64);
920         int (*link)(struct obd_export *, struct md_op_data *,
921                     struct ptlrpc_request **);
922         int (*rename)(struct obd_export *, struct md_op_data *,
923                       const char *, size_t, const char *, size_t,
924                       struct ptlrpc_request **);
925         int (*setattr)(struct obd_export *, struct md_op_data *, void *,
926                        size_t, struct ptlrpc_request **);
927         int (*sync)(struct obd_export *, const struct lu_fid *,
928                     struct ptlrpc_request **);
929         int (*read_page)(struct obd_export *, struct md_op_data *,
930                          struct md_callback *cb_op, __u64 hash_offset,
931                          struct page **ppage);
932         int (*unlink)(struct obd_export *, struct md_op_data *,
933                       struct ptlrpc_request **);
934
935         int (*setxattr)(struct obd_export *, const struct lu_fid *,
936                         u64, const char *, const char *, int, int, int, __u32,
937                         struct ptlrpc_request **);
938
939         int (*getxattr)(struct obd_export *, const struct lu_fid *,
940                         u64, const char *, const char *, int, int, int,
941                         struct ptlrpc_request **);
942
943         int (*init_ea_size)(struct obd_export *, u32, u32);
944
945         int (*get_lustre_md)(struct obd_export *, struct ptlrpc_request *,
946                              struct obd_export *, struct obd_export *,
947                              struct lustre_md *);
948
949         int (*free_lustre_md)(struct obd_export *, struct lustre_md *);
950
951         int (*merge_attr)(struct obd_export *,
952                           const struct lmv_stripe_md *lsm,
953                           struct cl_attr *attr, ldlm_blocking_callback);
954
955         int (*set_open_replay_data)(struct obd_export *,
956                                     struct obd_client_handle *,
957                                     struct lookup_intent *);
958         int (*clear_open_replay_data)(struct obd_export *,
959                                       struct obd_client_handle *);
960         int (*set_lock_data)(struct obd_export *, const struct lustre_handle *,
961                              void *, __u64 *);
962
963         enum ldlm_mode (*lock_match)(struct obd_export *, __u64,
964                                      const struct lu_fid *, enum ldlm_type,
965                                      union ldlm_policy_data *, enum ldlm_mode,
966                                      struct lustre_handle *);
967
968         int (*cancel_unused)(struct obd_export *, const struct lu_fid *,
969                              union ldlm_policy_data *, enum ldlm_mode,
970                              enum ldlm_cancel_flags flags, void *opaque);
971
972         int (*get_fid_from_lsm)(struct obd_export *,
973                                 const struct lmv_stripe_md *,
974                                 const char *name, int namelen,
975                                 struct lu_fid *fid);
976
977         int (*intent_getattr_async)(struct obd_export *,
978                                     struct md_enqueue_info *,
979                                     struct ldlm_enqueue_info *);
980
981         int (*revalidate_lock)(struct obd_export *, struct lookup_intent *,
982                                struct lu_fid *, __u64 *bits);
983
984         int (*unpackmd)(struct obd_export *exp, struct lmv_stripe_md **plsm,
985                         const union lmv_mds_md *lmv, size_t lmv_size);
986         /*
987          * NOTE: If adding ops, add another LPROCFS_MD_OP_INIT() line to
988          * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
989          * wrapper function in include/linux/obd_class.h.
990          */
991 };
992
993 static inline struct md_open_data *obd_mod_alloc(void)
994 {
995         struct md_open_data *mod;
996
997         mod = kzalloc(sizeof(*mod), GFP_NOFS);
998         if (!mod)
999                 return NULL;
1000         atomic_set(&mod->mod_refcount, 1);
1001         return mod;
1002 }
1003
1004 #define obd_mod_get(mod) atomic_inc(&(mod)->mod_refcount)
1005 #define obd_mod_put(mod)                                        \
1006 ({                                                            \
1007         if (atomic_dec_and_test(&(mod)->mod_refcount)) {          \
1008                 if ((mod)->mod_open_req)                          \
1009                         ptlrpc_req_finished((mod)->mod_open_req);   \
1010                 kfree(mod);                           \
1011         }                                                      \
1012 })
1013
1014 void obdo_from_inode(struct obdo *dst, struct inode *src, u32 valid);
1015 void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent);
1016
1017 /* return 1 if client should be resend request */
1018 static inline int client_should_resend(int resend, struct client_obd *cli)
1019 {
1020         return atomic_read(&cli->cl_resends) ?
1021                atomic_read(&cli->cl_resends) > resend : 1;
1022 }
1023
1024 /**
1025  * Return device name for this device
1026  *
1027  * XXX: lu_device is declared before obd_device, while a pointer pointing
1028  * back to obd_device in lu_device, so this helper function defines here
1029  * instead of in lu_object.h
1030  */
1031 static inline const char *lu_dev_name(const struct lu_device *lu_dev)
1032 {
1033         return lu_dev->ld_obd->obd_name;
1034 }
1035
1036 static inline bool filename_is_volatile(const char *name, size_t namelen,
1037                                         int *idx)
1038 {
1039         const char      *start;
1040         char            *end;
1041
1042         if (strncmp(name, LUSTRE_VOLATILE_HDR, LUSTRE_VOLATILE_HDR_LEN) != 0)
1043                 return false;
1044
1045         /* caller does not care of idx */
1046         if (!idx)
1047                 return true;
1048
1049         /* volatile file, the MDT can be set from name */
1050         /* name format is LUSTRE_VOLATILE_HDR:[idx]: */
1051         /* if no MDT is specified, use std way */
1052         if (namelen < LUSTRE_VOLATILE_HDR_LEN + 2)
1053                 goto bad_format;
1054         /* test for no MDT idx case */
1055         if ((*(name + LUSTRE_VOLATILE_HDR_LEN) == ':') &&
1056             (*(name + LUSTRE_VOLATILE_HDR_LEN + 1) == ':')) {
1057                 *idx = -1;
1058                 return true;
1059         }
1060         /* we have an idx, read it */
1061         start = name + LUSTRE_VOLATILE_HDR_LEN + 1;
1062         *idx = simple_strtoul(start, &end, 0);
1063         /* error cases:
1064          * no digit, no trailing :, negative value
1065          */
1066         if (((*idx == 0) && (end == start)) ||
1067             (*end != ':') || (*idx < 0))
1068                 goto bad_format;
1069
1070         return true;
1071 bad_format:
1072         /* bad format of mdt idx, we cannot return an error
1073          * to caller so we use hash algo
1074          */
1075         CERROR("Bad volatile file name format: %s\n",
1076                name + LUSTRE_VOLATILE_HDR_LEN);
1077         return false;
1078 }
1079
1080 static inline int cli_brw_size(struct obd_device *obd)
1081 {
1082         return obd->u.cli.cl_max_pages_per_rpc << PAGE_SHIFT;
1083 }
1084
1085 /*
1086  * when RPC size or the max RPCs in flight is increased, the max dirty pages
1087  * of the client should be increased accordingly to avoid sending fragmented
1088  * RPCs over the network when the client runs out of the maximum dirty space
1089  * when so many RPCs are being generated.
1090  */
1091 static inline void client_adjust_max_dirty(struct client_obd *cli)
1092 {
1093         /* initializing */
1094         if (cli->cl_dirty_max_pages <= 0)
1095                 cli->cl_dirty_max_pages =
1096                         (OSC_MAX_DIRTY_DEFAULT * 1024 * 1024) >> PAGE_SHIFT;
1097         else {
1098                 unsigned long dirty_max = cli->cl_max_rpcs_in_flight *
1099                                           cli->cl_max_pages_per_rpc;
1100
1101                 if (dirty_max > cli->cl_dirty_max_pages)
1102                         cli->cl_dirty_max_pages = dirty_max;
1103         }
1104
1105         if (cli->cl_dirty_max_pages > totalram_pages / 8)
1106                 cli->cl_dirty_max_pages = totalram_pages / 8;
1107 }
1108
1109 #endif /* __OBD_H */