staging: lustre: remove top level ccflags variable
[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
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 *
24 * GPL HEADER END
25 */
26/*
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
29 *
30 * Copyright (c) 2011, 2012, Intel Corporation.
31 */
32/*
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
35 */
36
37#ifndef __OBD_H
38#define __OBD_H
39
40#include <linux/obd.h>
41
42#define IOC_OSC_TYPE 'h'
43#define IOC_OSC_MIN_NR 20
44#define IOC_OSC_SET_ACTIVE _IOWR(IOC_OSC_TYPE, 21, struct obd_device *)
45#define IOC_OSC_MAX_NR 50
46
47#define IOC_MDC_TYPE 'i'
48#define IOC_MDC_MIN_NR 20
49#define IOC_MDC_MAX_NR 50
50
51#include <lustre/lustre_idl.h>
46fd3c61 52#include <lustre_lib.h>
9fdaf8c0 53#include "../../include/linux/libcfs/bitmap.h"
d7e09d03 54#include <lu_ref.h>
d7e09d03 55#include <lustre_export.h>
56f4c5a8 56#include <lustre_fid.h>
d7e09d03
PT
57#include <lustre_fld.h>
58#include <lustre_capa.h>
59
d7e09d03
PT
60#define MAX_OBD_DEVICES 8192
61
62struct osc_async_rc {
63 int ar_rc;
64 int ar_force_sync;
65 __u64 ar_min_xid;
66};
67
68struct lov_oinfo { /* per-stripe data structure */
69 struct ost_id loi_oi; /* object ID/Sequence on the target OST */
70 int loi_ost_idx; /* OST stripe index in lov_tgt_desc->tgts */
71 int loi_ost_gen; /* generation of this loi_ost_idx */
72
73 unsigned long loi_kms_valid:1;
74 __u64 loi_kms; /* known minimum size */
75 struct ost_lvb loi_lvb;
76 struct osc_async_rc loi_ar;
77};
78
79static inline void loi_kms_set(struct lov_oinfo *oinfo, __u64 kms)
80{
81 oinfo->loi_kms = kms;
82 oinfo->loi_kms_valid = 1;
83}
84
85static inline void loi_init(struct lov_oinfo *loi)
86{
87}
88
89struct lov_stripe_md {
90 atomic_t lsm_refc;
91 spinlock_t lsm_lock;
92 pid_t lsm_lock_owner; /* debugging */
93
94 /* maximum possible file size, might change as OSTs status changes,
95 * e.g. disconnected, deactivated */
96 __u64 lsm_maxbytes;
97 struct {
98 /* Public members. */
99 struct ost_id lw_object_oi; /* lov object id/seq */
100
101 /* LOV-private members start here -- only for use in lov/. */
102 __u32 lw_magic;
103 __u32 lw_stripe_size; /* size of the stripe */
104 __u32 lw_pattern; /* striping pattern (RAID0, RAID1) */
105 __u16 lw_stripe_count; /* number of objects being striped over */
106 __u16 lw_layout_gen; /* generation of the layout */
107 char lw_pool_name[LOV_MAXPOOLNAME]; /* pool name */
108 } lsm_wire;
109
110 struct lov_oinfo *lsm_oinfo[0];
111};
112
113#define lsm_oi lsm_wire.lw_object_oi
114#define lsm_magic lsm_wire.lw_magic
115#define lsm_layout_gen lsm_wire.lw_layout_gen
116#define lsm_stripe_size lsm_wire.lw_stripe_size
117#define lsm_pattern lsm_wire.lw_pattern
118#define lsm_stripe_count lsm_wire.lw_stripe_count
119#define lsm_pool_name lsm_wire.lw_pool_name
120
5dd16419
JX
121static inline bool lsm_is_released(struct lov_stripe_md *lsm)
122{
123 return !!(lsm->lsm_pattern & LOV_PATTERN_F_RELEASED);
124}
125
126static inline bool lsm_has_objects(struct lov_stripe_md *lsm)
127{
128 if (lsm == NULL)
129 return false;
130 if (lsm_is_released(lsm))
131 return false;
132 return true;
133}
134
081b7265
JH
135static inline int lov_stripe_md_size(unsigned int stripe_count)
136{
137 struct lov_stripe_md lsm;
138
139 return sizeof(lsm) + stripe_count * sizeof(lsm.lsm_oinfo[0]);
140}
141
d7e09d03
PT
142struct obd_info;
143
144typedef int (*obd_enqueue_update_f)(void *cookie, int rc);
145
146/* obd info for a particular level (lov, osc). */
147struct obd_info {
148 /* Lock policy. It keeps an extent which is specific for a particular
149 * OSC. (e.g. lov_prep_enqueue_set initialises extent of the policy,
150 * and osc_enqueue passes it into ldlm_lock_match & ldlm_cli_enqueue. */
151 ldlm_policy_data_t oi_policy;
152 /* Flags used for set request specific flags:
153 - while lock handling, the flags obtained on the enqueue
154 request are set here.
155 - while stats, the flags used for control delay/resend.
156 - while setattr, the flags used for distinguish punch operation
157 */
158 __u64 oi_flags;
159 /* Lock handle specific for every OSC lock. */
160 struct lustre_handle *oi_lockh;
161 /* lsm data specific for every OSC. */
162 struct lov_stripe_md *oi_md;
163 /* obdo data specific for every OSC, if needed at all. */
164 struct obdo *oi_oa;
165 /* statfs data specific for every OSC, if needed at all. */
166 struct obd_statfs *oi_osfs;
167 /* An update callback which is called to update some data on upper
17891183 168 * level. E.g. it is used for update lsm->lsm_oinfo at every received
d7e09d03
PT
169 * request in osc level for enqueue requests. It is also possible to
170 * update some caller data from LOV layer if needed. */
171 obd_enqueue_update_f oi_cb_up;
172 /* oss capability, its type is obd_capa in client to avoid copy.
173 * in contrary its type is lustre_capa in OSS. */
174 void *oi_capa;
175 /* transfer jobid from ost_sync() to filter_sync()... */
176 char *oi_jobid;
177};
178
179/* compare all relevant fields. */
180static inline int lov_stripe_md_cmp(struct lov_stripe_md *m1,
181 struct lov_stripe_md *m2)
182{
183 /*
184 * ->lsm_wire contains padding, but it should be zeroed out during
185 * allocation.
186 */
ec83e611 187 return memcmp(&m1->lsm_wire, &m2->lsm_wire, sizeof(m1->lsm_wire));
d7e09d03
PT
188}
189
190static inline int lov_lum_lsm_cmp(struct lov_user_md *lum,
191 struct lov_stripe_md *lsm)
192{
193 if (lsm->lsm_magic != lum->lmm_magic)
194 return 1;
195 if ((lsm->lsm_stripe_count != 0) && (lum->lmm_stripe_count != 0) &&
196 (lsm->lsm_stripe_count != lum->lmm_stripe_count))
197 return 2;
198 if ((lsm->lsm_stripe_size != 0) && (lum->lmm_stripe_size != 0) &&
199 (lsm->lsm_stripe_size != lum->lmm_stripe_size))
200 return 3;
201 if ((lsm->lsm_pattern != 0) && (lum->lmm_pattern != 0) &&
202 (lsm->lsm_pattern != lum->lmm_pattern))
203 return 4;
204 if ((lsm->lsm_magic == LOV_MAGIC_V3) &&
205 (strncmp(lsm->lsm_pool_name,
206 ((struct lov_user_md_v3 *)lum)->lmm_pool_name,
207 LOV_MAXPOOLNAME) != 0))
208 return 5;
209 return 0;
210}
211
212static inline int lov_lum_swab_if_needed(struct lov_user_md_v3 *lumv3,
213 int *lmm_magic,
214 struct lov_user_md *lum)
215{
216 if (lum && copy_from_user(lumv3, lum,sizeof(struct lov_user_md_v1)))
217 return -EFAULT;
218
219 *lmm_magic = lumv3->lmm_magic;
220
221 if (*lmm_magic == __swab32(LOV_USER_MAGIC_V1)) {
222 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lumv3);
223 *lmm_magic = LOV_USER_MAGIC_V1;
224 } else if (*lmm_magic == LOV_USER_MAGIC_V3) {
225 if (lum && copy_from_user(lumv3, lum, sizeof(*lumv3)))
226 return -EFAULT;
227 } else if (*lmm_magic == __swab32(LOV_USER_MAGIC_V3)) {
228 if (lum && copy_from_user(lumv3, lum, sizeof(*lumv3)))
229 return -EFAULT;
230 lustre_swab_lov_user_md_v3(lumv3);
231 *lmm_magic = LOV_USER_MAGIC_V3;
232 } else if (*lmm_magic != LOV_USER_MAGIC_V1) {
233 CDEBUG(D_IOCTL,
234 "bad userland LOV MAGIC: %#08x != %#08x nor %#08x\n",
235 *lmm_magic, LOV_USER_MAGIC_V1, LOV_USER_MAGIC_V3);
236 return -EINVAL;
237 }
238 return 0;
239}
240
241void lov_stripe_lock(struct lov_stripe_md *md);
242void lov_stripe_unlock(struct lov_stripe_md *md);
243
244struct obd_type {
245 struct list_head typ_chain;
246 struct obd_ops *typ_dt_ops;
247 struct md_ops *typ_md_ops;
b59fe845 248 struct proc_dir_entry *typ_procroot;
d7e09d03
PT
249 char *typ_name;
250 int typ_refcnt;
251 struct lu_device_type *typ_lu;
252 spinlock_t obd_type_lock;
253};
254
255struct brw_page {
256 obd_off off;
257 struct page *pg;
258 int count;
259 obd_flag flag;
260};
261
d7e09d03
PT
262/* llog contexts */
263enum llog_ctxt_id {
264 LLOG_CONFIG_ORIG_CTXT = 0,
265 LLOG_CONFIG_REPL_CTXT,
266 LLOG_MDS_OST_ORIG_CTXT,
267 LLOG_MDS_OST_REPL_CTXT,
268 LLOG_SIZE_ORIG_CTXT,
269 LLOG_SIZE_REPL_CTXT,
270 LLOG_RD1_ORIG_CTXT,
271 LLOG_RD1_REPL_CTXT,
272 LLOG_TEST_ORIG_CTXT,
273 LLOG_TEST_REPL_CTXT,
274 LLOG_LOVEA_ORIG_CTXT,
275 LLOG_LOVEA_REPL_CTXT,
99a92265 276 LLOG_CHANGELOG_ORIG_CTXT, /**< changelog generation on mdd */
277 LLOG_CHANGELOG_REPL_CTXT, /**< changelog access on clients */
278 LLOG_CHANGELOG_USER_ORIG_CTXT, /**< for multiple changelog consumers */
279 LLOG_AGENT_ORIG_CTXT, /**< agent requests generation on cdt */
d7e09d03
PT
280 LLOG_MAX_CTXTS
281};
282
d7e09d03
PT
283struct timeout_item {
284 enum timeout_event ti_event;
285 cfs_time_t ti_timeout;
286 timeout_cb_t ti_cb;
287 void *ti_cb_data;
288 struct list_head ti_obd_list;
289 struct list_head ti_chain;
290};
291
292#define OSC_MAX_RIF_DEFAULT 8
293#define MDS_OSC_MAX_RIF_DEFAULT 50
294#define OSC_MAX_RIF_MAX 256
295#define OSC_MAX_DIRTY_DEFAULT (OSC_MAX_RIF_DEFAULT * 4)
296#define OSC_MAX_DIRTY_MB_MAX 2048 /* arbitrary, but < MAX_LONG bytes */
297#define OSC_DEFAULT_RESENDS 10
298
299/* possible values for fo_sync_lock_cancel */
300enum {
301 NEVER_SYNC_ON_CANCEL = 0,
302 BLOCKING_SYNC_ON_CANCEL = 1,
303 ALWAYS_SYNC_ON_CANCEL = 2,
304 NUM_SYNC_ON_CANCEL_STATES
305};
306
307#define MDC_MAX_RIF_DEFAULT 8
308#define MDC_MAX_RIF_MAX 512
309
310struct mdc_rpc_lock;
311struct obd_import;
312struct client_obd {
313 struct rw_semaphore cl_sem;
314 struct obd_uuid cl_target_uuid;
315 struct obd_import *cl_import; /* ptlrpc connection state */
316 int cl_conn_count;
317 /* max_mds_easize is purely a performance thing so we don't have to
318 * call obd_size_diskmd() all the time. */
44779340
BB
319 int cl_default_mds_easize;
320 int cl_max_mds_easize;
321 int cl_default_mds_cookiesize;
322 int cl_max_mds_cookiesize;
d7e09d03
PT
323
324 enum lustre_sec_part cl_sp_me;
325 enum lustre_sec_part cl_sp_to;
326 struct sptlrpc_flavor cl_flvr_mgc; /* fixed flavor of mgc->mgs */
327
328 /* the grant values are protected by loi_list_lock below */
329 long cl_dirty; /* all _dirty_ in bytes */
330 long cl_dirty_max; /* allowed w/o rpc */
331 long cl_dirty_transit; /* dirty synchronous */
332 long cl_avail_grant; /* bytes of credit for ost */
333 long cl_lost_grant; /* lost credits (trunc) */
334
335 /* since we allocate grant by blocks, we don't know how many grant will
336 * be used to add a page into cache. As a solution, we reserve maximum
337 * grant before trying to dirty a page and unreserve the rest.
338 * See osc_{reserve|unreserve}_grant for details. */
339 long cl_reserved_grant;
340 struct list_head cl_cache_waiters; /* waiting for cache/grant */
341 cfs_time_t cl_next_shrink_grant; /* jiffies */
342 struct list_head cl_grant_shrink_list; /* Timeout event list */
343 int cl_grant_shrink_interval; /* seconds */
344
345 /* A chunk is an optimal size used by osc_extent to determine
346 * the extent size. A chunk is max(PAGE_CACHE_SIZE, OST block size) */
347 int cl_chunkbits;
348 int cl_chunk;
349 int cl_extent_tax; /* extent overhead, by bytes */
350
351 /* keep track of objects that have lois that contain pages which
352 * have been queued for async brw. this lock also protects the
353 * lists of osc_client_pages that hang off of the loi */
354 /*
355 * ->cl_loi_list_lock protects consistency of
356 * ->cl_loi_{ready,read,write}_list. ->ap_make_ready() and
357 * ->ap_completion() call-backs are executed under this lock. As we
358 * cannot guarantee that these call-backs never block on all platforms
359 * (as a matter of fact they do block on Mac OS X), type of
360 * ->cl_loi_list_lock is platform dependent: it's a spin-lock on Linux
361 * and blocking mutex on Mac OS X. (Alternative is to make this lock
362 * blocking everywhere, but we don't want to slow down fast-path of
363 * our main platform.)
364 *
365 * Exact type of ->cl_loi_list_lock is defined in arch/obd.h together
366 * with client_obd_list_{un,}lock() and
367 * client_obd_list_lock_{init,done}() functions.
368 *
369 * NB by Jinshan: though field names are still _loi_, but actually
370 * osc_object{}s are in the list.
371 */
372 client_obd_lock_t cl_loi_list_lock;
373 struct list_head cl_loi_ready_list;
374 struct list_head cl_loi_hp_ready_list;
375 struct list_head cl_loi_write_list;
376 struct list_head cl_loi_read_list;
377 int cl_r_in_flight;
378 int cl_w_in_flight;
379 /* just a sum of the loi/lop pending numbers to be exported by /proc */
380 atomic_t cl_pending_w_pages;
381 atomic_t cl_pending_r_pages;
382 __u32 cl_max_pages_per_rpc;
383 int cl_max_rpcs_in_flight;
384 struct obd_histogram cl_read_rpc_hist;
385 struct obd_histogram cl_write_rpc_hist;
386 struct obd_histogram cl_read_page_hist;
387 struct obd_histogram cl_write_page_hist;
388 struct obd_histogram cl_read_offset_hist;
389 struct obd_histogram cl_write_offset_hist;
390
391 /* lru for osc caching pages */
392 struct cl_client_cache *cl_cache;
393 struct list_head cl_lru_osc; /* member of cl_cache->ccc_lru */
394 atomic_t *cl_lru_left;
395 atomic_t cl_lru_busy;
396 atomic_t cl_lru_shrinkers;
397 atomic_t cl_lru_in_list;
398 struct list_head cl_lru_list; /* lru page list */
399 client_obd_lock_t cl_lru_list_lock; /* page list protector */
400
401 /* number of in flight destroy rpcs is limited to max_rpcs_in_flight */
402 atomic_t cl_destroy_in_flight;
403 wait_queue_head_t cl_destroy_waitq;
404
405 struct mdc_rpc_lock *cl_rpc_lock;
406 struct mdc_rpc_lock *cl_close_lock;
407
408 /* mgc datastruct */
6246dab1 409 struct mutex cl_mgc_mutex;
aa4e3c8a
MP
410 struct local_oid_storage *cl_mgc_los;
411 struct dt_object *cl_mgc_configs_dir;
d7e09d03
PT
412 atomic_t cl_mgc_refcount;
413 struct obd_export *cl_mgc_mgsexp;
414
415 /* checksumming for data sent over the network */
416 unsigned int cl_checksum:1; /* 0 = disabled, 1 = enabled */
417 /* supported checksum types that are worked out at connect time */
418 __u32 cl_supp_cksum_types;
419 /* checksum algorithm to be used */
420 cksum_type_t cl_cksum_type;
421
422 /* also protected by the poorly named _loi_list_lock lock above */
423 struct osc_async_rc cl_ar;
424
425 /* used by quotacheck when the servers are older than 2.4 */
426 int cl_qchk_stat; /* quotacheck stat of the peer */
427#define CL_NOT_QUOTACHECKED 1 /* client->cl_qchk_stat init value */
428#if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 7, 50, 0)
429#warning "please consider removing quotacheck compatibility code"
430#endif
431
432 /* sequence manager */
433 struct lu_client_seq *cl_seq;
434
435 atomic_t cl_resends; /* resend count */
436
437 /* ptlrpc work for writeback in ptlrpcd context */
438 void *cl_writeback_work;
439 /* hash tables for osc_quota_info */
6da6eabe 440 struct cfs_hash *cl_quota_hash[MAXQUOTAS];
d7e09d03
PT
441};
442#define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
443
444struct obd_id_info {
445 __u32 idx;
446 obd_id *data;
447};
448
d7e09d03
PT
449struct echo_client_obd {
450 struct obd_export *ec_exp; /* the local connection to osc/lov */
451 spinlock_t ec_lock;
452 struct list_head ec_objects;
453 struct list_head ec_locks;
454 int ec_nstripes;
455 __u64 ec_unique;
456};
457
458struct lov_qos_oss {
459 struct obd_uuid lqo_uuid; /* ptlrpc's c_remote_uuid */
460 struct list_head lqo_oss_list; /* link to lov_qos */
461 __u64 lqo_bavail; /* total bytes avail on OSS */
462 __u64 lqo_penalty; /* current penalty */
463 __u64 lqo_penalty_per_obj;/* penalty decrease every obj*/
464 time_t lqo_used; /* last used time, seconds */
465 __u32 lqo_ost_count; /* number of osts on this oss */
466};
467
468struct ltd_qos {
469 struct lov_qos_oss *ltq_oss; /* oss info */
470 __u64 ltq_penalty; /* current penalty */
471 __u64 ltq_penalty_per_obj; /* penalty decrease every obj*/
472 __u64 ltq_weight; /* net weighting */
473 time_t ltq_used; /* last used time, seconds */
474 unsigned int ltq_usable:1; /* usable for striping */
475};
476
477/* Generic subset of OSTs */
478struct ost_pool {
479 __u32 *op_array; /* array of index of
480 lov_obd->lov_tgts */
481 unsigned int op_count; /* number of OSTs in the array */
482 unsigned int op_size; /* allocated size of lp_array */
483 struct rw_semaphore op_rw_sem; /* to protect ost_pool use */
484};
485
486/* Round-robin allocator data */
487struct lov_qos_rr {
488 __u32 lqr_start_idx; /* start index of new inode */
489 __u32 lqr_offset_idx; /* aliasing for start_idx */
490 int lqr_start_count; /* reseed counter */
491 struct ost_pool lqr_pool; /* round-robin optimized list */
492 unsigned long lqr_dirty:1; /* recalc round-robin list */
493};
494
495/* allow statfs data caching for 1 second */
496#define OBD_STATFS_CACHE_SECONDS 1
497
498struct lov_statfs_data {
499 struct obd_info lsd_oi;
500 struct obd_statfs lsd_statfs;
501};
502/* Stripe placement optimization */
503struct lov_qos {
504 struct list_head lq_oss_list; /* list of OSSs that targets use */
505 struct rw_semaphore lq_rw_sem;
506 __u32 lq_active_oss_count;
507 unsigned int lq_prio_free; /* priority for free space */
508 unsigned int lq_threshold_rr;/* priority for rr */
509 struct lov_qos_rr lq_rr; /* round robin qos data */
510 unsigned long lq_dirty:1, /* recalc qos data */
511 lq_same_space:1,/* the ost's all have approx.
512 the same space avail */
513 lq_reset:1, /* zero current penalties */
514 lq_statfs_in_progress:1; /* statfs op in
515 progress */
516 /* qos statfs data */
517 struct lov_statfs_data *lq_statfs_data;
518 wait_queue_head_t lq_statfs_waitq; /* waitqueue to notify statfs
519 * requests completion */
520};
521
522struct lov_tgt_desc {
523 struct list_head ltd_kill;
524 struct obd_uuid ltd_uuid;
525 struct obd_device *ltd_obd;
526 struct obd_export *ltd_exp;
527 struct ltd_qos ltd_qos; /* qos info per target */
528 __u32 ltd_gen;
529 __u32 ltd_index; /* index in lov_obd->tgts */
530 unsigned long ltd_active:1,/* is this target up for requests */
531 ltd_activate:1,/* should target be activated */
532 ltd_reap:1; /* should this target be deleted */
533};
534
535/* Pool metadata */
536#define pool_tgt_size(_p) _p->pool_obds.op_size
537#define pool_tgt_count(_p) _p->pool_obds.op_count
538#define pool_tgt_array(_p) _p->pool_obds.op_array
539#define pool_tgt_rw_sem(_p) _p->pool_obds.op_rw_sem
540
541struct pool_desc {
542 char pool_name[LOV_MAXPOOLNAME + 1]; /* name of pool */
543 struct ost_pool pool_obds; /* pool members */
544 atomic_t pool_refcount; /* pool ref. counter */
545 struct lov_qos_rr pool_rr; /* round robin qos */
546 struct hlist_node pool_hash; /* access by poolname */
547 struct list_head pool_list; /* serial access */
b59fe845 548 struct proc_dir_entry *pool_proc_entry; /* file in /proc */
d7e09d03
PT
549 struct obd_device *pool_lobd; /* obd of the lov/lod to which
550 * this pool belongs */
551};
552
553struct lov_obd {
554 struct lov_desc desc;
555 struct lov_tgt_desc **lov_tgts; /* sparse array */
556 struct ost_pool lov_packed; /* all OSTs in a packed
557 array */
558 struct mutex lov_lock;
559 struct obd_connect_data lov_ocd;
560 atomic_t lov_refcount;
561 __u32 lov_tgt_count; /* how many OBD's */
562 __u32 lov_active_tgt_count; /* how many active */
563 __u32 lov_death_row;/* tgts scheduled to be deleted */
564 __u32 lov_tgt_size; /* size of tgts array */
565 int lov_connects;
566 int lov_pool_count;
6da6eabe 567 struct cfs_hash *lov_pools_hash_body; /* used for key access */
d7e09d03 568 struct list_head lov_pool_list; /* used for sequential access */
b59fe845 569 struct proc_dir_entry *lov_pool_proc_entry;
d7e09d03
PT
570 enum lustre_sec_part lov_sp_me;
571
c52f69c5 572 /* Cached LRU pages from upper layer */
d7e09d03
PT
573 void *lov_cache;
574
575 struct rw_semaphore lov_notify_lock;
576};
577
578struct lmv_tgt_desc {
579 struct obd_uuid ltd_uuid;
580 struct obd_export *ltd_exp;
581 int ltd_idx;
582 struct mutex ltd_fid_mutex;
583 unsigned long ltd_active:1; /* target up for requests */
584};
585
586enum placement_policy {
587 PLACEMENT_CHAR_POLICY = 0,
588 PLACEMENT_NID_POLICY = 1,
589 PLACEMENT_INVAL_POLICY = 2,
590 PLACEMENT_MAX_POLICY
591};
592
593typedef enum placement_policy placement_policy_t;
594
595struct lmv_obd {
596 int refcount;
597 struct lu_client_fld lmv_fld;
598 spinlock_t lmv_lock;
599 placement_policy_t lmv_placement;
600 struct lmv_desc desc;
601 struct obd_uuid cluuid;
602 struct obd_export *exp;
603
604 struct mutex init_mutex;
605 int connected;
606 int max_easize;
607 int max_def_easize;
608 int max_cookiesize;
44779340 609 int max_def_cookiesize;
d7e09d03
PT
610 int server_timeout;
611
612 int tgts_size; /* size of tgts array */
613 struct lmv_tgt_desc **tgts;
614
615 struct obd_connect_data conn_data;
616};
617
618struct niobuf_local {
619 __u64 lnb_file_offset;
620 __u32 lnb_page_offset;
621 __u32 len;
622 __u32 flags;
623 struct page *page;
624 struct dentry *dentry;
625 int lnb_grant_used;
626 int rc;
627};
628
629#define LUSTRE_FLD_NAME "fld"
630#define LUSTRE_SEQ_NAME "seq"
631
632#define LUSTRE_MDD_NAME "mdd"
633#define LUSTRE_OSD_LDISKFS_NAME "osd-ldiskfs"
634#define LUSTRE_OSD_ZFS_NAME "osd-zfs"
635#define LUSTRE_VVP_NAME "vvp"
636#define LUSTRE_LMV_NAME "lmv"
637#define LUSTRE_SLP_NAME "slp"
638#define LUSTRE_LOD_NAME "lod"
639#define LUSTRE_OSP_NAME "osp"
640#define LUSTRE_LWP_NAME "lwp"
641
642/* obd device type names */
643 /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */
644#define LUSTRE_MDS_NAME "mds"
645#define LUSTRE_MDT_NAME "mdt"
646#define LUSTRE_MDC_NAME "mdc"
647#define LUSTRE_OSS_NAME "ost" /* FIXME change name to oss */
648#define LUSTRE_OST_NAME "obdfilter" /* FIXME change name to ost */
649#define LUSTRE_OSC_NAME "osc"
650#define LUSTRE_LOV_NAME "lov"
651#define LUSTRE_MGS_NAME "mgs"
652#define LUSTRE_MGC_NAME "mgc"
653
654#define LUSTRE_ECHO_NAME "obdecho"
655#define LUSTRE_ECHO_CLIENT_NAME "echo_client"
656#define LUSTRE_QMT_NAME "qmt"
657
658/* Constant obd names (post-rename) */
659#define LUSTRE_MDS_OBDNAME "MDS"
660#define LUSTRE_OSS_OBDNAME "OSS"
661#define LUSTRE_MGS_OBDNAME "MGS"
662#define LUSTRE_MGC_OBDNAME "MGC"
663
664static inline int is_osp_on_mdt(char *name)
665{
666 char *ptr;
667
668 ptr = strrchr(name, '-');
669 if (ptr == NULL) {
670 CERROR("%s is not a obdname\n", name);
671 return 0;
672 }
673
674 /* 1.8 OSC/OSP name on MDT is fsname-OSTxxxx-osc */
675 if (strncmp(ptr + 1, "osc", 3) == 0)
676 return 1;
677
678 if (strncmp(ptr + 1, "MDT", 3) != 0)
679 return 0;
680
681 while (*(--ptr) != '-' && ptr != name);
682
683 if (ptr == name)
684 return 0;
685
686 if (strncmp(ptr + 1, LUSTRE_OSP_NAME, strlen(LUSTRE_OSP_NAME)) != 0 &&
687 strncmp(ptr + 1, LUSTRE_OSC_NAME, strlen(LUSTRE_OSC_NAME)) != 0)
688 return 0;
689
690 return 1;
691}
692
693/* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
694#define N_LOCAL_TEMP_PAGE 0x10000000
695
696struct obd_trans_info {
697 __u64 oti_transno;
698 __u64 oti_xid;
699 /* Only used on the server side for tracking acks. */
700 struct oti_req_ack_lock {
701 struct lustre_handle lock;
702 __u32 mode;
703 } oti_ack_locks[4];
704 void *oti_handle;
705 struct llog_cookie oti_onecookie;
706 struct llog_cookie *oti_logcookies;
707 int oti_numcookies;
708 /** synchronous write is needed */
709 unsigned long oti_sync_write:1;
710
711 /* initial thread handling transaction */
712 struct ptlrpc_thread * oti_thread;
713 __u32 oti_conn_cnt;
714 /** VBR: versions */
715 __u64 oti_pre_version;
716 /** JobID */
717 char *oti_jobid;
718
719 struct obd_uuid *oti_ost_uuid;
720};
721
722static inline void oti_init(struct obd_trans_info *oti,
723 struct ptlrpc_request *req)
724{
725 if (oti == NULL)
726 return;
727 memset(oti, 0, sizeof(*oti));
728
729 if (req == NULL)
730 return;
731
732 oti->oti_xid = req->rq_xid;
733 /** VBR: take versions from request */
734 if (req->rq_reqmsg != NULL &&
735 lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
736 __u64 *pre_version = lustre_msg_get_versions(req->rq_reqmsg);
737 oti->oti_pre_version = pre_version ? pre_version[0] : 0;
738 oti->oti_transno = lustre_msg_get_transno(req->rq_reqmsg);
739 }
740
741 /** called from mds_create_objects */
742 if (req->rq_repmsg != NULL)
743 oti->oti_transno = lustre_msg_get_transno(req->rq_repmsg);
744 oti->oti_thread = req->rq_svc_thread;
745 if (req->rq_reqmsg != NULL)
746 oti->oti_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg);
747}
748
749static inline void oti_alloc_cookies(struct obd_trans_info *oti,int num_cookies)
750{
751 if (!oti)
752 return;
753
754 if (num_cookies == 1)
755 oti->oti_logcookies = &oti->oti_onecookie;
756 else
757 OBD_ALLOC_LARGE(oti->oti_logcookies,
758 num_cookies * sizeof(oti->oti_onecookie));
759
760 oti->oti_numcookies = num_cookies;
761}
762
763static inline void oti_free_cookies(struct obd_trans_info *oti)
764{
765 if (!oti || !oti->oti_logcookies)
766 return;
767
768 if (oti->oti_logcookies == &oti->oti_onecookie)
769 LASSERT(oti->oti_numcookies == 1);
770 else
771 OBD_FREE_LARGE(oti->oti_logcookies,
772 oti->oti_numcookies*sizeof(oti->oti_onecookie));
773 oti->oti_logcookies = NULL;
774 oti->oti_numcookies = 0;
775}
776
777/*
778 * Events signalled through obd_notify() upcall-chain.
779 */
780enum obd_notify_event {
781 /* target added */
782 OBD_NOTIFY_CREATE,
783 /* Device connect start */
784 OBD_NOTIFY_CONNECT,
785 /* Device activated */
786 OBD_NOTIFY_ACTIVE,
787 /* Device deactivated */
788 OBD_NOTIFY_INACTIVE,
789 /* Device disconnected */
790 OBD_NOTIFY_DISCON,
791 /* Connect data for import were changed */
792 OBD_NOTIFY_OCD,
793 /* Sync request */
794 OBD_NOTIFY_SYNC_NONBLOCK,
795 OBD_NOTIFY_SYNC,
796 /* Configuration event */
797 OBD_NOTIFY_CONFIG,
798 /* Administratively deactivate/activate event */
799 OBD_NOTIFY_DEACTIVATE,
800 OBD_NOTIFY_ACTIVATE
801};
802
d7e09d03
PT
803/*
804 * Data structure used to pass obd_notify()-event to non-obd listeners (llite
805 * and liblustre being main examples).
806 */
807struct obd_notify_upcall {
808 int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
809 enum obd_notify_event ev, void *owner, void *data);
810 /* Opaque datum supplied by upper layer listener */
811 void *onu_owner;
812};
813
814struct target_recovery_data {
815 svc_handler_t trd_recovery_handler;
816 pid_t trd_processing_task;
817 struct completion trd_starting;
818 struct completion trd_finishing;
819};
820
821struct obd_llog_group {
822 int olg_seq;
823 struct llog_ctxt *olg_ctxts[LLOG_MAX_CTXTS];
824 wait_queue_head_t olg_waitq;
825 spinlock_t olg_lock;
826 struct mutex olg_cat_processing;
827};
828
829/* corresponds to one of the obd's */
830#define OBD_DEVICE_MAGIC 0XAB5CD6EF
831#define OBD_DEV_BY_DEVNAME 0xffffd0de
832
833struct obd_device {
834 struct obd_type *obd_type;
835 __u32 obd_magic;
836
837 /* common and UUID name of this device */
838 char obd_name[MAX_OBD_NAME];
839 struct obd_uuid obd_uuid;
840
841 struct lu_device *obd_lu_dev;
842
843 int obd_minor;
844 /* bitfield modification is protected by obd_dev_lock */
845 unsigned long obd_attached:1, /* finished attach */
846 obd_set_up:1, /* finished setup */
847 obd_recovering:1, /* there are recoverable clients */
848 obd_abort_recovery:1,/* recovery expired */
849 obd_version_recov:1, /* obd uses version checking */
850 obd_replayable:1, /* recovery is enabled; inform clients */
851 obd_no_transno:1, /* no committed-transno notification */
852 obd_no_recov:1, /* fail instead of retry messages */
853 obd_stopping:1, /* started cleanup */
854 obd_starting:1, /* started setup */
855 obd_force:1, /* cleanup with > 0 obd refcount */
856 obd_fail:1, /* cleanup with failover */
857 obd_async_recov:1, /* allow asynchronous orphan cleanup */
858 obd_no_conn:1, /* deny new connections */
859 obd_inactive:1, /* device active/inactive
860 * (for /proc/status only!!) */
861 obd_no_ir:1, /* no imperative recovery. */
862 obd_process_conf:1; /* device is processing mgs config */
863 /* use separate field as it is set in interrupt to don't mess with
864 * protection of other bits using _bh lock */
865 unsigned long obd_recovery_expired:1;
866 /* uuid-export hash body */
6da6eabe 867 struct cfs_hash *obd_uuid_hash;
d7e09d03 868 /* nid-export hash body */
6da6eabe 869 struct cfs_hash *obd_nid_hash;
d7e09d03 870 /* nid stats body */
6da6eabe 871 struct cfs_hash *obd_nid_stats_hash;
d7e09d03
PT
872 struct list_head obd_nid_stats;
873 atomic_t obd_refcount;
874 wait_queue_head_t obd_refcount_waitq;
875 struct list_head obd_exports;
876 struct list_head obd_unlinked_exports;
877 struct list_head obd_delayed_exports;
878 int obd_num_exports;
879 spinlock_t obd_nid_lock;
880 struct ldlm_namespace *obd_namespace;
881 struct ptlrpc_client obd_ldlm_client; /* XXX OST/MDS only */
882 /* a spinlock is OK for what we do now, may need a semaphore later */
883 spinlock_t obd_dev_lock; /* protect OBD bitfield above */
884 struct mutex obd_dev_mutex;
885 __u64 obd_last_committed;
886 struct fsfilt_operations *obd_fsops;
887 spinlock_t obd_osfs_lock;
888 struct obd_statfs obd_osfs; /* locked by obd_osfs_lock */
889 __u64 obd_osfs_age;
890 struct lvfs_run_ctxt obd_lvfs_ctxt;
891 struct obd_llog_group obd_olg; /* default llog group */
892 struct obd_device *obd_observer;
893 struct rw_semaphore obd_observer_link_sem;
894 struct obd_notify_upcall obd_upcall;
895 struct obd_export *obd_self_export;
896 /* list of exports in LRU order, for ping evictor, with obd_dev_lock */
897 struct list_head obd_exports_timed;
898 time_t obd_eviction_timer; /* for ping evictor */
899
900 int obd_max_recoverable_clients;
901 atomic_t obd_connected_clients;
902 int obd_stale_clients;
903 int obd_delayed_clients;
904 /* this lock protects all recovery list_heads, timer and
905 * obd_next_recovery_transno value */
906 spinlock_t obd_recovery_task_lock;
907 __u64 obd_next_recovery_transno;
908 int obd_replayed_requests;
909 int obd_requests_queued_for_recovery;
910 wait_queue_head_t obd_next_transno_waitq;
911 /* protected by obd_recovery_task_lock */
54319351 912 struct timer_list obd_recovery_timer;
d7e09d03
PT
913 time_t obd_recovery_start; /* seconds */
914 time_t obd_recovery_end; /* seconds, for lprocfs_status */
915 int obd_recovery_time_hard;
916 int obd_recovery_timeout;
917 int obd_recovery_ir_factor;
918
919 /* new recovery stuff from CMD2 */
920 struct target_recovery_data obd_recovery_data;
921 int obd_replayed_locks;
922 atomic_t obd_req_replay_clients;
923 atomic_t obd_lock_replay_clients;
924 /* all lists are protected by obd_recovery_task_lock */
925 struct list_head obd_req_replay_queue;
926 struct list_head obd_lock_replay_queue;
927 struct list_head obd_final_req_queue;
928 int obd_recovery_stage;
929
930 union {
d7e09d03 931 struct client_obd cli;
d7e09d03 932 struct echo_client_obd echo_client;
d7e09d03
PT
933 struct lov_obd lov;
934 struct lmv_obd lmv;
935 } u;
936 /* Fields used by LProcFS */
937 unsigned int obd_cntr_base;
938 struct lprocfs_stats *obd_stats;
939
940 unsigned int md_cntr_base;
941 struct lprocfs_stats *md_stats;
942
b59fe845 943 struct proc_dir_entry *obd_proc_entry;
73bb1da6 944 void *obd_proc_private; /* type private PDEs */
b59fe845
GKH
945 struct proc_dir_entry *obd_proc_exports_entry;
946 struct proc_dir_entry *obd_svc_procroot;
d7e09d03
PT
947 struct lprocfs_stats *obd_svc_stats;
948 atomic_t obd_evict_inprogress;
949 wait_queue_head_t obd_evict_inprogress_waitq;
950 struct list_head obd_evict_list; /* protected with pet_lock */
951
952 /**
953 * Ldlm pool part. Save last calculated SLV and Limit.
954 */
955 rwlock_t obd_pool_lock;
956 int obd_pool_limit;
957 __u64 obd_pool_slv;
958
959 /**
960 * A list of outstanding class_incref()'s against this obd. For
961 * debugging.
962 */
963 struct lu_ref obd_reference;
964
965 int obd_conn_inprogress;
966};
967
968#define OBD_LLOG_FL_SENDNOW 0x0001
969#define OBD_LLOG_FL_EXIT 0x0002
970
971enum obd_cleanup_stage {
972/* Special case hack for MDS LOVs */
973 OBD_CLEANUP_EARLY,
974/* can be directly mapped to .ldto_device_fini() */
975 OBD_CLEANUP_EXPORTS,
976};
977
978/* get/set_info keys */
979#define KEY_ASYNC "async"
980#define KEY_BLOCKSIZE_BITS "blocksize_bits"
981#define KEY_BLOCKSIZE "blocksize"
982#define KEY_CAPA_KEY "capa_key"
983#define KEY_CHANGELOG_CLEAR "changelog_clear"
984#define KEY_FID2PATH "fid2path"
985#define KEY_CHECKSUM "checksum"
986#define KEY_CLEAR_FS "clear_fs"
987#define KEY_CONN_DATA "conn_data"
988#define KEY_EVICT_BY_NID "evict_by_nid"
989#define KEY_FIEMAP "fiemap"
990#define KEY_FLUSH_CTX "flush_ctx"
991#define KEY_GRANT_SHRINK "grant_shrink"
992#define KEY_HSM_COPYTOOL_SEND "hsm_send"
993#define KEY_INIT_RECOV_BACKUP "init_recov_bk"
994#define KEY_INIT_RECOV "initial_recov"
995#define KEY_INTERMDS "inter_mds"
996#define KEY_LAST_ID "last_id"
997#define KEY_LAST_FID "last_fid"
998#define KEY_LOCK_TO_STRIPE "lock_to_stripe"
999#define KEY_LOVDESC "lovdesc"
1000#define KEY_LOV_IDX "lov_idx"
44779340
BB
1001#define KEY_MAX_EASIZE "max_easize"
1002#define KEY_DEFAULT_EASIZE "default_easize"
1003#define KEY_MAX_COOKIESIZE "max_cookiesize"
1004#define KEY_DEFAULT_COOKIESIZE "default_cookiesize"
d7e09d03
PT
1005#define KEY_MDS_CONN "mds_conn"
1006#define KEY_MGSSEC "mgssec"
1007#define KEY_NEXT_ID "next_id"
1008#define KEY_READ_ONLY "read-only"
1009#define KEY_REGISTER_TARGET "register_target"
1010#define KEY_SET_FS "set_fs"
1011#define KEY_TGT_COUNT "tgt_count"
1012/* KEY_SET_INFO in lustre_idl.h */
1013#define KEY_SPTLRPC_CONF "sptlrpc_conf"
1014#define KEY_CONNECT_FLAG "connect_flags"
1015#define KEY_SYNC_LOCK_CANCEL "sync_lock_cancel"
1016
1017#define KEY_CACHE_SET "cache_set"
1018#define KEY_CACHE_LRU_SHRINK "cache_lru_shrink"
1019#define KEY_CHANGELOG_INDEX "changelog_index"
1020
1021struct lu_context;
1022
1023/* /!\ must be coherent with include/linux/namei.h on patched kernel */
1024#define IT_OPEN (1 << 0)
1025#define IT_CREAT (1 << 1)
1026#define IT_READDIR (1 << 2)
1027#define IT_GETATTR (1 << 3)
1028#define IT_LOOKUP (1 << 4)
1029#define IT_UNLINK (1 << 5)
1030#define IT_TRUNC (1 << 6)
1031#define IT_GETXATTR (1 << 7)
1032#define IT_EXEC (1 << 8)
1033#define IT_PIN (1 << 9)
1034#define IT_LAYOUT (1 << 10)
1035#define IT_QUOTA_DQACQ (1 << 11)
1036#define IT_QUOTA_CONN (1 << 12)
7fc1f831 1037#define IT_SETXATTR (1 << 13)
d7e09d03
PT
1038
1039static inline int it_to_lock_mode(struct lookup_intent *it)
1040{
1041 /* CREAT needs to be tested before open (both could be set) */
1042 if (it->it_op & IT_CREAT)
1043 return LCK_CW;
1044 else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_LOOKUP |
1045 IT_LAYOUT))
1046 return LCK_CR;
7fc1f831
AP
1047 else if (it->it_op & IT_GETXATTR)
1048 return LCK_PR;
1049 else if (it->it_op & IT_SETXATTR)
1050 return LCK_PW;
d7e09d03
PT
1051
1052 LASSERTF(0, "Invalid it_op: %d\n", it->it_op);
1053 return -EINVAL;
1054}
1055
1056struct md_op_data {
17891183
MI
1057 struct lu_fid op_fid1; /* operation fid1 (usually parent) */
1058 struct lu_fid op_fid2; /* operation fid2 (usually child) */
d7e09d03
PT
1059 struct lu_fid op_fid3; /* 2 extra fids to find conflicting */
1060 struct lu_fid op_fid4; /* to the operation locks. */
1061 mdsno_t op_mds; /* what mds server open will go to */
1062 struct lustre_handle op_handle;
1063 obd_time op_mod_time;
1064 const char *op_name;
1065 int op_namelen;
1066 __u32 op_mode;
1067 struct lmv_stripe_md *op_mea1;
1068 struct lmv_stripe_md *op_mea2;
1069 __u32 op_suppgids[2];
1070 __u32 op_fsuid;
1071 __u32 op_fsgid;
1072 cfs_cap_t op_cap;
1073 void *op_data;
1074
1075 /* iattr fields and blocks. */
1076 struct iattr op_attr;
1077 unsigned int op_attr_flags;
1078 __u64 op_valid;
1079 loff_t op_attr_blocks;
1080
1081 /* Size-on-MDS epoch and flags. */
1082 __u64 op_ioepoch;
1083 __u32 op_flags;
1084
1085 /* Capa fields */
1086 struct obd_capa *op_capa1;
1087 struct obd_capa *op_capa2;
1088
1089 /* Various operation flags. */
48d23e61 1090 enum mds_op_bias op_bias;
d7e09d03
PT
1091
1092 /* Operation type */
1093 __u32 op_opc;
1094
1095 /* Used by readdir */
1096 __u64 op_offset;
1097
1098 /* Used by readdir */
1099 __u32 op_npages;
1100
1101 /* used to transfer info between the stacks of MD client
1102 * see enum op_cli_flags */
1103 __u32 op_cli_flags;
48d23e61
JX
1104
1105 /* File object data version for HSM release, on client */
1106 __u64 op_data_version;
1107 struct lustre_handle op_lease_handle;
d7e09d03
PT
1108};
1109
1110enum op_cli_flags {
1111 CLI_SET_MEA = 1 << 0,
1112 CLI_RM_ENTRY = 1 << 1,
1113};
1114
1115struct md_enqueue_info;
1116/* metadata stat-ahead */
1117typedef int (* md_enqueue_cb_t)(struct ptlrpc_request *req,
1118 struct md_enqueue_info *minfo,
1119 int rc);
1120
d7e09d03
PT
1121struct md_enqueue_info {
1122 struct md_op_data mi_data;
1123 struct lookup_intent mi_it;
1124 struct lustre_handle mi_lockh;
1125 struct inode *mi_dir;
1126 md_enqueue_cb_t mi_cb;
1127 __u64 mi_cbdata;
1128 unsigned int mi_generation;
1129};
1130
1131struct obd_ops {
c34d9cd8 1132 struct module *o_owner;
d7e09d03
PT
1133 int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
1134 void *karg, void *uarg);
1135 int (*o_get_info)(const struct lu_env *env, struct obd_export *,
1136 __u32 keylen, void *key, __u32 *vallen, void *val,
1137 struct lov_stripe_md *lsm);
1138 int (*o_set_info_async)(const struct lu_env *, struct obd_export *,
1139 __u32 keylen, void *key,
1140 __u32 vallen, void *val,
1141 struct ptlrpc_request_set *set);
1142 int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
1143 int (*o_detach)(struct obd_device *dev);
1144 int (*o_setup) (struct obd_device *dev, struct lustre_cfg *cfg);
1145 int (*o_precleanup)(struct obd_device *dev,
1146 enum obd_cleanup_stage cleanup_stage);
1147 int (*o_cleanup)(struct obd_device *dev);
1148 int (*o_process_config)(struct obd_device *dev, obd_count len,
1149 void *data);
1150 int (*o_postrecov)(struct obd_device *dev);
1151 int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
1152 int priority);
1153 int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
1154 /* connect to the target device with given connection
1155 * data. @ocd->ocd_connect_flags is modified to reflect flags actually
1156 * granted by the target, which are guaranteed to be a subset of flags
1157 * asked for. If @ocd == NULL, use default parameters. */
1158 int (*o_connect)(const struct lu_env *env,
1159 struct obd_export **exp, struct obd_device *src,
1160 struct obd_uuid *cluuid, struct obd_connect_data *ocd,
1161 void *localdata);
1162 int (*o_reconnect)(const struct lu_env *env,
1163 struct obd_export *exp, struct obd_device *src,
1164 struct obd_uuid *cluuid,
1165 struct obd_connect_data *ocd,
1166 void *localdata);
1167 int (*o_disconnect)(struct obd_export *exp);
1168
1169 /* Initialize/finalize fids infrastructure. */
1170 int (*o_fid_init)(struct obd_device *obd,
1171 struct obd_export *exp, enum lu_cli_type type);
1172 int (*o_fid_fini)(struct obd_device *obd);
1173
1174 /* Allocate new fid according to passed @hint. */
1175 int (*o_fid_alloc)(struct obd_export *exp, struct lu_fid *fid,
1176 struct md_op_data *op_data);
1177
1178 /*
1179 * Object with @fid is getting deleted, we may want to do something
1180 * about this.
1181 */
1182 int (*o_statfs)(const struct lu_env *, struct obd_export *exp,
1183 struct obd_statfs *osfs, __u64 max_age, __u32 flags);
1184 int (*o_statfs_async)(struct obd_export *exp, struct obd_info *oinfo,
1185 __u64 max_age, struct ptlrpc_request_set *set);
1186 int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
1187 struct lov_stripe_md *mem_src);
1188 int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
1189 struct lov_mds_md *disk_src, int disk_len);
1190 int (*o_preallocate)(struct lustre_handle *, obd_count *req,
1191 obd_id *ids);
1192 /* FIXME: add fid capability support for create & destroy! */
1193 int (*o_precreate)(struct obd_export *exp);
1194 int (*o_create)(const struct lu_env *env, struct obd_export *exp,
1195 struct obdo *oa, struct lov_stripe_md **ea,
1196 struct obd_trans_info *oti);
1197 int (*o_create_async)(struct obd_export *exp, struct obd_info *oinfo,
1198 struct lov_stripe_md **ea,
1199 struct obd_trans_info *oti);
1200 int (*o_destroy)(const struct lu_env *env, struct obd_export *exp,
1201 struct obdo *oa, struct lov_stripe_md *ea,
1202 struct obd_trans_info *oti, struct obd_export *md_exp,
1203 void *capa);
1204 int (*o_setattr)(const struct lu_env *, struct obd_export *exp,
1205 struct obd_info *oinfo, struct obd_trans_info *oti);
1206 int (*o_setattr_async)(struct obd_export *exp, struct obd_info *oinfo,
1207 struct obd_trans_info *oti,
1208 struct ptlrpc_request_set *rqset);
1209 int (*o_getattr)(const struct lu_env *env, struct obd_export *exp,
1210 struct obd_info *oinfo);
1211 int (*o_getattr_async)(struct obd_export *exp, struct obd_info *oinfo,
1212 struct ptlrpc_request_set *set);
1213 int (*o_brw)(int rw, struct obd_export *exp, struct obd_info *oinfo,
1214 obd_count oa_bufs, struct brw_page *pgarr,
1215 struct obd_trans_info *oti);
1216 int (*o_merge_lvb)(struct obd_export *exp, struct lov_stripe_md *lsm,
1217 struct ost_lvb *lvb, int kms_only);
1218 int (*o_adjust_kms)(struct obd_export *exp, struct lov_stripe_md *lsm,
1219 obd_off size, int shrink);
1220 int (*o_punch)(const struct lu_env *, struct obd_export *exp,
1221 struct obd_info *oinfo, struct obd_trans_info *oti,
1222 struct ptlrpc_request_set *rqset);
1223 int (*o_sync)(const struct lu_env *env, struct obd_export *exp,
1224 struct obd_info *oinfo, obd_size start, obd_size end,
1225 struct ptlrpc_request_set *set);
1226 int (*o_migrate)(struct lustre_handle *conn, struct lov_stripe_md *dst,
1227 struct lov_stripe_md *src, obd_size start,
1228 obd_size end, struct obd_trans_info *oti);
1229 int (*o_copy)(struct lustre_handle *dstconn, struct lov_stripe_md *dst,
1230 struct lustre_handle *srconn, struct lov_stripe_md *src,
1231 obd_size start, obd_size end, struct obd_trans_info *);
1232 int (*o_iterate)(struct lustre_handle *conn,
1233 int (*)(obd_id, obd_seq, void *),
1234 obd_id *startid, obd_seq seq, void *data);
1235 int (*o_preprw)(const struct lu_env *env, int cmd,
1236 struct obd_export *exp, struct obdo *oa, int objcount,
1237 struct obd_ioobj *obj, struct niobuf_remote *remote,
1238 int *nr_pages, struct niobuf_local *local,
1239 struct obd_trans_info *oti, struct lustre_capa *capa);
1240 int (*o_commitrw)(const struct lu_env *env, int cmd,
1241 struct obd_export *exp, struct obdo *oa,
1242 int objcount, struct obd_ioobj *obj,
1243 struct niobuf_remote *remote, int pages,
1244 struct niobuf_local *local,
1245 struct obd_trans_info *oti, int rc);
1246 int (*o_enqueue)(struct obd_export *, struct obd_info *oinfo,
1247 struct ldlm_enqueue_info *einfo,
1248 struct ptlrpc_request_set *rqset);
1249 int (*o_change_cbdata)(struct obd_export *, struct lov_stripe_md *,
1250 ldlm_iterator_t it, void *data);
1251 int (*o_find_cbdata)(struct obd_export *, struct lov_stripe_md *,
1252 ldlm_iterator_t it, void *data);
1253 int (*o_cancel)(struct obd_export *, struct lov_stripe_md *md,
1254 __u32 mode, struct lustre_handle *);
1255 int (*o_cancel_unused)(struct obd_export *, struct lov_stripe_md *,
1256 ldlm_cancel_flags_t flags, void *opaque);
1257 int (*o_init_export)(struct obd_export *exp);
1258 int (*o_destroy_export)(struct obd_export *exp);
1259 int (*o_extent_calc)(struct obd_export *, struct lov_stripe_md *,
1260 int cmd, obd_off *);
1261
1262 /* llog related obd_methods */
1263 int (*o_llog_init)(struct obd_device *obd, struct obd_llog_group *grp,
1264 struct obd_device *disk_obd, int *idx);
1265 int (*o_llog_finish)(struct obd_device *obd, int count);
1266 int (*o_llog_connect)(struct obd_export *, struct llogd_conn_body *);
1267
1268 /* metadata-only methods */
1269 int (*o_pin)(struct obd_export *, const struct lu_fid *fid,
1270 struct obd_capa *, struct obd_client_handle *, int flag);
1271 int (*o_unpin)(struct obd_export *, struct obd_client_handle *, int);
1272
1273 int (*o_import_event)(struct obd_device *, struct obd_import *,
1274 enum obd_import_event);
1275
1276 int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
1277 enum obd_notify_event ev, void *data);
1278
1279 int (*o_health_check)(const struct lu_env *env, struct obd_device *);
1280 struct obd_uuid *(*o_get_uuid) (struct obd_export *exp);
1281
1282 /* quota methods */
1283 int (*o_quotacheck)(struct obd_device *, struct obd_export *,
1284 struct obd_quotactl *);
1285 int (*o_quotactl)(struct obd_device *, struct obd_export *,
1286 struct obd_quotactl *);
1287
1288 int (*o_ping)(const struct lu_env *, struct obd_export *exp);
1289
1290 /* pools methods */
1291 int (*o_pool_new)(struct obd_device *obd, char *poolname);
1292 int (*o_pool_del)(struct obd_device *obd, char *poolname);
1293 int (*o_pool_add)(struct obd_device *obd, char *poolname,
1294 char *ostname);
1295 int (*o_pool_rem)(struct obd_device *obd, char *poolname,
1296 char *ostname);
1297 void (*o_getref)(struct obd_device *obd);
1298 void (*o_putref)(struct obd_device *obd);
1299 /*
1300 * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
1301 * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
1302 * Also, add a wrapper function in include/linux/obd_class.h. */
1303};
1304
1305enum {
1306 LUSTRE_OPC_MKDIR = (1 << 0),
1307 LUSTRE_OPC_SYMLINK = (1 << 1),
1308 LUSTRE_OPC_MKNOD = (1 << 2),
1309 LUSTRE_OPC_CREATE = (1 << 3),
1310 LUSTRE_OPC_ANY = (1 << 4)
1311};
1312
1313/* lmv structures */
1314#define MEA_MAGIC_LAST_CHAR 0xb2221ca1
1315#define MEA_MAGIC_ALL_CHARS 0xb222a11c
1316#define MEA_MAGIC_HASH_SEGMENT 0xb222a11b
1317
1318#define MAX_HASH_SIZE_32 0x7fffffffUL
1319#define MAX_HASH_SIZE 0x7fffffffffffffffULL
1320#define MAX_HASH_HIGHEST_BIT 0x1000000000000000ULL
1321
1322struct lustre_md {
1323 struct mdt_body *body;
1324 struct lov_stripe_md *lsm;
1325 struct lmv_stripe_md *mea;
1326#ifdef CONFIG_FS_POSIX_ACL
1327 struct posix_acl *posix_acl;
1328#endif
1329 struct mdt_remote_perm *remote_perm;
1330 struct obd_capa *mds_capa;
1331 struct obd_capa *oss_capa;
1332};
1333
1334struct md_open_data {
1335 struct obd_client_handle *mod_och;
1336 struct ptlrpc_request *mod_open_req;
1337 struct ptlrpc_request *mod_close_req;
63d42578
HZ
1338 atomic_t mod_refcount;
1339 bool mod_is_create;
d7e09d03
PT
1340};
1341
1342struct lookup_intent;
1343
1344struct md_ops {
1345 int (*m_getstatus)(struct obd_export *, struct lu_fid *,
1346 struct obd_capa **);
1347 int (*m_null_inode)(struct obd_export *, const struct lu_fid *);
1348 int (*m_find_cbdata)(struct obd_export *, const struct lu_fid *,
1349 ldlm_iterator_t, void *);
1350 int (*m_close)(struct obd_export *, struct md_op_data *,
1351 struct md_open_data *, struct ptlrpc_request **);
1352 int (*m_create)(struct obd_export *, struct md_op_data *,
1353 const void *, int, int, __u32, __u32, cfs_cap_t,
1354 __u64, struct ptlrpc_request **);
1355 int (*m_done_writing)(struct obd_export *, struct md_op_data *,
1356 struct md_open_data *);
1357 int (*m_enqueue)(struct obd_export *, struct ldlm_enqueue_info *,
1358 struct lookup_intent *, struct md_op_data *,
1359 struct lustre_handle *, void *, int,
1360 struct ptlrpc_request **, __u64);
1361 int (*m_getattr)(struct obd_export *, struct md_op_data *,
1362 struct ptlrpc_request **);
1363 int (*m_getattr_name)(struct obd_export *, struct md_op_data *,
1364 struct ptlrpc_request **);
1365 int (*m_intent_lock)(struct obd_export *, struct md_op_data *,
1366 void *, int, struct lookup_intent *, int,
1367 struct ptlrpc_request **,
1368 ldlm_blocking_callback, __u64);
1369 int (*m_link)(struct obd_export *, struct md_op_data *,
1370 struct ptlrpc_request **);
1371 int (*m_rename)(struct obd_export *, struct md_op_data *,
1372 const char *, int, const char *, int,
1373 struct ptlrpc_request **);
1374 int (*m_is_subdir)(struct obd_export *, const struct lu_fid *,
1375 const struct lu_fid *,
1376 struct ptlrpc_request **);
1377 int (*m_setattr)(struct obd_export *, struct md_op_data *, void *,
1378 int , void *, int, struct ptlrpc_request **,
1379 struct md_open_data **mod);
1380 int (*m_sync)(struct obd_export *, const struct lu_fid *,
1381 struct obd_capa *, struct ptlrpc_request **);
1382 int (*m_readpage)(struct obd_export *, struct md_op_data *,
1383 struct page **, struct ptlrpc_request **);
1384
1385 int (*m_unlink)(struct obd_export *, struct md_op_data *,
1386 struct ptlrpc_request **);
1387
1388 int (*m_setxattr)(struct obd_export *, const struct lu_fid *,
1389 struct obd_capa *, obd_valid, const char *,
1390 const char *, int, int, int, __u32,
1391 struct ptlrpc_request **);
1392
1393 int (*m_getxattr)(struct obd_export *, const struct lu_fid *,
1394 struct obd_capa *, obd_valid, const char *,
1395 const char *, int, int, int,
1396 struct ptlrpc_request **);
1397
44779340 1398 int (*m_init_ea_size)(struct obd_export *, int, int, int, int);
d7e09d03
PT
1399
1400 int (*m_get_lustre_md)(struct obd_export *, struct ptlrpc_request *,
1401 struct obd_export *, struct obd_export *,
1402 struct lustre_md *);
1403
1404 int (*m_free_lustre_md)(struct obd_export *, struct lustre_md *);
1405
1406 int (*m_set_open_replay_data)(struct obd_export *,
1407 struct obd_client_handle *,
63d42578 1408 struct lookup_intent *);
d7e09d03
PT
1409 int (*m_clear_open_replay_data)(struct obd_export *,
1410 struct obd_client_handle *);
1411 int (*m_set_lock_data)(struct obd_export *, __u64 *, void *, __u64 *);
1412
1413 ldlm_mode_t (*m_lock_match)(struct obd_export *, __u64,
1414 const struct lu_fid *, ldlm_type_t,
1415 ldlm_policy_data_t *, ldlm_mode_t,
1416 struct lustre_handle *);
1417
1418 int (*m_cancel_unused)(struct obd_export *, const struct lu_fid *,
1419 ldlm_policy_data_t *, ldlm_mode_t,
1420 ldlm_cancel_flags_t flags, void *opaque);
1421 int (*m_renew_capa)(struct obd_export *, struct obd_capa *oc,
1422 renew_capa_cb_t cb);
1423 int (*m_unpack_capa)(struct obd_export *, struct ptlrpc_request *,
1424 const struct req_msg_field *, struct obd_capa **);
1425
1426 int (*m_get_remote_perm)(struct obd_export *, const struct lu_fid *,
1427 struct obd_capa *, __u32,
1428 struct ptlrpc_request **);
1429
1430 int (*m_intent_getattr_async)(struct obd_export *,
1431 struct md_enqueue_info *,
1432 struct ldlm_enqueue_info *);
1433
1434 int (*m_revalidate_lock)(struct obd_export *, struct lookup_intent *,
1435 struct lu_fid *, __u64 *bits);
1436
1437 /*
1438 * NOTE: If adding ops, add another LPROCFS_MD_OP_INIT() line to
1439 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
1440 * wrapper function in include/linux/obd_class.h.
1441 */
1442};
1443
1444struct lsm_operations {
1445 void (*lsm_free)(struct lov_stripe_md *);
1446 int (*lsm_destroy)(struct lov_stripe_md *, struct obdo *oa,
1447 struct obd_export *md_exp);
1448 void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *, obd_off *,
1449 obd_off *);
1450 void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *, obd_off *,
1451 obd_off *);
1452 int (*lsm_lmm_verify) (struct lov_mds_md *lmm, int lmm_bytes,
1453 __u16 *stripe_count);
1454 int (*lsm_unpackmd) (struct lov_obd *lov, struct lov_stripe_md *lsm,
1455 struct lov_mds_md *lmm);
1456};
1457
1458extern const struct lsm_operations lsm_v1_ops;
1459extern const struct lsm_operations lsm_v3_ops;
1460static inline const struct lsm_operations *lsm_op_find(int magic)
1461{
1462 switch(magic) {
1463 case LOV_MAGIC_V1:
1464 return &lsm_v1_ops;
1465 case LOV_MAGIC_V3:
1466 return &lsm_v3_ops;
1467 default:
1468 CERROR("Cannot recognize lsm_magic %08x\n", magic);
1469 return NULL;
1470 }
1471}
1472
1473/* Requests for obd_extent_calc() */
1474#define OBD_CALC_STRIPE_START 1
1475#define OBD_CALC_STRIPE_END 2
1476
1477static inline struct lustre_capa *oinfo_capa(struct obd_info *oinfo)
1478{
1479 return oinfo->oi_capa;
1480}
1481
1482static inline struct md_open_data *obd_mod_alloc(void)
1483{
1484 struct md_open_data *mod;
1485 OBD_ALLOC_PTR(mod);
1486 if (mod == NULL)
1487 return NULL;
1488 atomic_set(&mod->mod_refcount, 1);
1489 return mod;
1490}
1491
1492#define obd_mod_get(mod) atomic_inc(&(mod)->mod_refcount)
1493#define obd_mod_put(mod) \
1494({ \
1495 if (atomic_dec_and_test(&(mod)->mod_refcount)) { \
1496 if ((mod)->mod_open_req) \
1497 ptlrpc_req_finished((mod)->mod_open_req); \
1498 OBD_FREE_PTR(mod); \
1499 } \
1500})
1501
1502void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
1503void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent);
1504
1505/* return 1 if client should be resend request */
1506static inline int client_should_resend(int resend, struct client_obd *cli)
1507{
1508 return atomic_read(&cli->cl_resends) ?
1509 atomic_read(&cli->cl_resends) > resend : 1;
1510}
1511
1512/**
1513 * Return device name for this device
1514 *
1515 * XXX: lu_device is declared before obd_device, while a pointer pointing
1516 * back to obd_device in lu_device, so this helper function defines here
1517 * instead of in lu_object.h
1518 */
1519static inline const char *lu_dev_name(const struct lu_device *lu_dev)
1520{
1521 return lu_dev->ld_obd->obd_name;
1522}
1523
1524static inline bool filename_is_volatile(const char *name, int namelen, int *idx)
1525{
1526 const char *start;
1527 char *end;
1528
1529 if (strncmp(name, LUSTRE_VOLATILE_HDR, LUSTRE_VOLATILE_HDR_LEN) != 0)
1530 return false;
1531
1532 /* caller does not care of idx */
1533 if (idx == NULL)
1534 return true;
1535
1536 /* volatile file, the MDT can be set from name */
1537 /* name format is LUSTRE_VOLATILE_HDR:[idx]: */
1538 /* if no MDT is specified, use std way */
1539 if (namelen < LUSTRE_VOLATILE_HDR_LEN + 2)
1540 goto bad_format;
1541 /* test for no MDT idx case */
1542 if ((*(name + LUSTRE_VOLATILE_HDR_LEN) == ':') &&
1543 (*(name + LUSTRE_VOLATILE_HDR_LEN + 1) == ':')) {
1544 *idx = -1;
1545 return true;
1546 }
1547 /* we have an idx, read it */
1548 start = name + LUSTRE_VOLATILE_HDR_LEN + 1;
1549 *idx = strtoul(start, &end, 0);
1550 /* error cases:
1551 * no digit, no trailing :, negative value
1552 */
1553 if (((*idx == 0) && (end == start)) ||
1554 (*end != ':') || (*idx < 0))
1555 goto bad_format;
1556
1557 return true;
1558bad_format:
1559 /* bad format of mdt idx, we cannot return an error
1560 * to caller so we use hash algo */
1561 CERROR("Bad volatile file name format: %s\n",
1562 name + LUSTRE_VOLATILE_HDR_LEN);
1563 return false;
1564}
1565
1566static inline int cli_brw_size(struct obd_device *obd)
1567{
1568 LASSERT(obd != NULL);
1569 return obd->u.cli.cl_max_pages_per_rpc << PAGE_CACHE_SHIFT;
1570}
1571
1572#endif /* __OBD_H */
This page took 0.435287 seconds and 5 git commands to generate.