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