4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
40 #include "linux/obd.h"
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
47 #define IOC_MDC_TYPE 'i'
48 #define IOC_MDC_MIN_NR 20
49 #define IOC_MDC_MAX_NR 50
51 #include "lustre/lustre_idl.h"
52 #include "lustre_lib.h"
54 #include "lustre_export.h"
55 #include "lustre_fid.h"
56 #include "lustre_fld.h"
57 #include "lustre_capa.h"
59 #define MAX_OBD_DEVICES 8192
67 struct lov_oinfo { /* per-stripe data structure */
68 struct ost_id loi_oi; /* object ID/Sequence on the target OST */
69 int loi_ost_idx; /* OST stripe index in lov_tgt_desc->tgts */
70 int loi_ost_gen; /* generation of this loi_ost_idx */
72 unsigned long loi_kms_valid:1;
73 __u64 loi_kms; /* known minimum size */
74 struct ost_lvb loi_lvb;
75 struct osc_async_rc loi_ar;
78 static inline void loi_kms_set(struct lov_oinfo *oinfo, __u64 kms)
81 oinfo->loi_kms_valid = 1;
84 static inline void loi_init(struct lov_oinfo *loi)
88 struct lov_stripe_md {
91 pid_t lsm_lock_owner; /* debugging */
93 /* maximum possible file size, might change as OSTs status changes,
94 * e.g. disconnected, deactivated */
98 struct ost_id lw_object_oi; /* lov object id/seq */
100 /* LOV-private members start here -- only for use in lov/. */
102 __u32 lw_stripe_size; /* size of the stripe */
103 __u32 lw_pattern; /* striping pattern (RAID0, RAID1) */
104 __u16 lw_stripe_count; /* number of objects being striped over */
105 __u16 lw_layout_gen; /* generation of the layout */
106 char lw_pool_name[LOV_MAXPOOLNAME]; /* pool name */
109 struct lov_oinfo *lsm_oinfo[0];
112 #define lsm_oi lsm_wire.lw_object_oi
113 #define lsm_magic lsm_wire.lw_magic
114 #define lsm_layout_gen lsm_wire.lw_layout_gen
115 #define lsm_stripe_size lsm_wire.lw_stripe_size
116 #define lsm_pattern lsm_wire.lw_pattern
117 #define lsm_stripe_count lsm_wire.lw_stripe_count
118 #define lsm_pool_name lsm_wire.lw_pool_name
120 static inline bool lsm_is_released(struct lov_stripe_md *lsm)
122 return !!(lsm->lsm_pattern & LOV_PATTERN_F_RELEASED);
125 static inline bool lsm_has_objects(struct lov_stripe_md *lsm)
129 if (lsm_is_released(lsm))
134 static inline int lov_stripe_md_size(unsigned int stripe_count)
136 struct lov_stripe_md lsm;
138 return sizeof(lsm) + stripe_count * sizeof(lsm.lsm_oinfo[0]);
143 typedef int (*obd_enqueue_update_f)(void *cookie, int rc);
145 /* obd info for a particular level (lov, osc). */
147 /* Flags used for set request specific flags:
148 - while lock handling, the flags obtained on the enqueue
149 request are set here.
150 - while stats, the flags used for control delay/resend.
151 - while setattr, the flags used for distinguish punch operation
154 /* lsm data specific for every OSC. */
155 struct lov_stripe_md *oi_md;
156 /* obdo data specific for every OSC, if needed at all. */
158 /* statfs data specific for every OSC, if needed at all. */
159 struct obd_statfs *oi_osfs;
160 /* An update callback which is called to update some data on upper
161 * level. E.g. it is used for update lsm->lsm_oinfo at every received
162 * request in osc level for enqueue requests. It is also possible to
163 * update some caller data from LOV layer if needed. */
164 obd_enqueue_update_f oi_cb_up;
165 /* oss capability, its type is obd_capa in client to avoid copy.
166 * in contrary its type is lustre_capa in OSS. */
170 /* compare all relevant fields. */
171 static inline int lov_stripe_md_cmp(struct lov_stripe_md *m1,
172 struct lov_stripe_md *m2)
175 * ->lsm_wire contains padding, but it should be zeroed out during
178 return memcmp(&m1->lsm_wire, &m2->lsm_wire, sizeof(m1->lsm_wire));
181 static inline int lov_lum_lsm_cmp(struct lov_user_md *lum,
182 struct lov_stripe_md *lsm)
184 if (lsm->lsm_magic != lum->lmm_magic)
186 if ((lsm->lsm_stripe_count != 0) && (lum->lmm_stripe_count != 0) &&
187 (lsm->lsm_stripe_count != lum->lmm_stripe_count))
189 if ((lsm->lsm_stripe_size != 0) && (lum->lmm_stripe_size != 0) &&
190 (lsm->lsm_stripe_size != lum->lmm_stripe_size))
192 if ((lsm->lsm_pattern != 0) && (lum->lmm_pattern != 0) &&
193 (lsm->lsm_pattern != lum->lmm_pattern))
195 if ((lsm->lsm_magic == LOV_MAGIC_V3) &&
196 (strncmp(lsm->lsm_pool_name,
197 ((struct lov_user_md_v3 *)lum)->lmm_pool_name,
198 LOV_MAXPOOLNAME) != 0))
203 static inline int lov_lum_swab_if_needed(struct lov_user_md_v3 *lumv3,
205 struct lov_user_md *lum)
207 if (lum && copy_from_user(lumv3, lum, sizeof(struct lov_user_md_v1)))
210 *lmm_magic = lumv3->lmm_magic;
212 if (*lmm_magic == __swab32(LOV_USER_MAGIC_V1)) {
213 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lumv3);
214 *lmm_magic = LOV_USER_MAGIC_V1;
215 } else if (*lmm_magic == LOV_USER_MAGIC_V3) {
216 if (lum && copy_from_user(lumv3, lum, sizeof(*lumv3)))
218 } else if (*lmm_magic == __swab32(LOV_USER_MAGIC_V3)) {
219 if (lum && copy_from_user(lumv3, lum, sizeof(*lumv3)))
221 lustre_swab_lov_user_md_v3(lumv3);
222 *lmm_magic = LOV_USER_MAGIC_V3;
223 } else if (*lmm_magic != LOV_USER_MAGIC_V1) {
225 "bad userland LOV MAGIC: %#08x != %#08x nor %#08x\n",
226 *lmm_magic, LOV_USER_MAGIC_V1, LOV_USER_MAGIC_V3);
232 void lov_stripe_lock(struct lov_stripe_md *md);
233 void lov_stripe_unlock(struct lov_stripe_md *md);
236 struct list_head typ_chain;
237 struct obd_ops *typ_dt_ops;
238 struct md_ops *typ_md_ops;
239 struct dentry *typ_debugfs_entry;
242 struct lu_device_type *typ_lu;
243 spinlock_t obd_type_lock;
244 struct kobject *typ_kobj;
256 LLOG_CONFIG_ORIG_CTXT = 0,
257 LLOG_CONFIG_REPL_CTXT,
258 LLOG_MDS_OST_ORIG_CTXT,
259 LLOG_MDS_OST_REPL_CTXT,
266 LLOG_LOVEA_ORIG_CTXT,
267 LLOG_LOVEA_REPL_CTXT,
268 LLOG_CHANGELOG_ORIG_CTXT, /**< changelog generation on mdd */
269 LLOG_CHANGELOG_REPL_CTXT, /**< changelog access on clients */
270 LLOG_CHANGELOG_USER_ORIG_CTXT, /**< for multiple changelog consumers */
271 LLOG_AGENT_ORIG_CTXT, /**< agent requests generation on cdt */
275 struct timeout_item {
276 enum timeout_event ti_event;
277 unsigned long ti_timeout;
280 struct list_head ti_obd_list;
281 struct list_head ti_chain;
284 #define OSC_MAX_RIF_DEFAULT 8
285 #define MDS_OSC_MAX_RIF_DEFAULT 50
286 #define OSC_MAX_RIF_MAX 256
287 #define OSC_MAX_DIRTY_DEFAULT (OSC_MAX_RIF_DEFAULT * 4)
288 #define OSC_MAX_DIRTY_MB_MAX 2048 /* arbitrary, but < MAX_LONG bytes */
289 #define OSC_DEFAULT_RESENDS 10
291 /* possible values for fo_sync_lock_cancel */
293 NEVER_SYNC_ON_CANCEL = 0,
294 BLOCKING_SYNC_ON_CANCEL = 1,
295 ALWAYS_SYNC_ON_CANCEL = 2,
296 NUM_SYNC_ON_CANCEL_STATES
299 #define MDC_MAX_RIF_DEFAULT 8
300 #define MDC_MAX_RIF_MAX 512
305 struct rw_semaphore cl_sem;
306 struct obd_uuid cl_target_uuid;
307 struct obd_import *cl_import; /* ptlrpc connection state */
309 /* max_mds_easize is purely a performance thing so we don't have to
310 * call obd_size_diskmd() all the time. */
311 int cl_default_mds_easize;
312 int cl_max_mds_easize;
313 int cl_default_mds_cookiesize;
314 int cl_max_mds_cookiesize;
316 enum lustre_sec_part cl_sp_me;
317 enum lustre_sec_part cl_sp_to;
318 struct sptlrpc_flavor cl_flvr_mgc; /* fixed flavor of mgc->mgs */
320 /* the grant values are protected by loi_list_lock below */
321 long cl_dirty; /* all _dirty_ in bytes */
322 long cl_dirty_max; /* allowed w/o rpc */
323 long cl_dirty_transit; /* dirty synchronous */
324 long cl_avail_grant; /* bytes of credit for ost */
325 long cl_lost_grant; /* lost credits (trunc) */
327 /* since we allocate grant by blocks, we don't know how many grant will
328 * be used to add a page into cache. As a solution, we reserve maximum
329 * grant before trying to dirty a page and unreserve the rest.
330 * See osc_{reserve|unreserve}_grant for details. */
331 long cl_reserved_grant;
332 struct list_head cl_cache_waiters; /* waiting for cache/grant */
333 unsigned long cl_next_shrink_grant; /* jiffies */
334 struct list_head cl_grant_shrink_list; /* Timeout event list */
335 int cl_grant_shrink_interval; /* seconds */
337 /* A chunk is an optimal size used by osc_extent to determine
338 * the extent size. A chunk is max(PAGE_CACHE_SIZE, OST block size) */
341 int cl_extent_tax; /* extent overhead, by bytes */
343 /* keep track of objects that have lois that contain pages which
344 * have been queued for async brw. this lock also protects the
345 * lists of osc_client_pages that hang off of the loi */
347 * ->cl_loi_list_lock protects consistency of
348 * ->cl_loi_{ready,read,write}_list. ->ap_make_ready() and
349 * ->ap_completion() call-backs are executed under this lock. As we
350 * cannot guarantee that these call-backs never block on all platforms
351 * (as a matter of fact they do block on Mac OS X), type of
352 * ->cl_loi_list_lock is platform dependent: it's a spin-lock on Linux
353 * and blocking mutex on Mac OS X. (Alternative is to make this lock
354 * blocking everywhere, but we don't want to slow down fast-path of
355 * our main platform.)
357 * Exact type of ->cl_loi_list_lock is defined in arch/obd.h together
358 * with client_obd_list_{un,}lock() and
359 * client_obd_list_lock_{init,done}() functions.
361 * NB by Jinshan: though field names are still _loi_, but actually
362 * osc_object{}s are in the list.
364 client_obd_lock_t cl_loi_list_lock;
365 struct list_head cl_loi_ready_list;
366 struct list_head cl_loi_hp_ready_list;
367 struct list_head cl_loi_write_list;
368 struct list_head cl_loi_read_list;
371 /* just a sum of the loi/lop pending numbers to be exported by /proc */
372 atomic_t cl_pending_w_pages;
373 atomic_t cl_pending_r_pages;
374 __u32 cl_max_pages_per_rpc;
375 int cl_max_rpcs_in_flight;
376 struct obd_histogram cl_read_rpc_hist;
377 struct obd_histogram cl_write_rpc_hist;
378 struct obd_histogram cl_read_page_hist;
379 struct obd_histogram cl_write_page_hist;
380 struct obd_histogram cl_read_offset_hist;
381 struct obd_histogram cl_write_offset_hist;
383 /* lru for osc caching pages */
384 struct cl_client_cache *cl_cache;
385 struct list_head cl_lru_osc; /* member of cl_cache->ccc_lru */
386 atomic_t *cl_lru_left;
387 atomic_t cl_lru_busy;
388 atomic_t cl_lru_shrinkers;
389 atomic_t cl_lru_in_list;
390 struct list_head cl_lru_list; /* lru page list */
391 client_obd_lock_t cl_lru_list_lock; /* page list protector */
393 /* number of in flight destroy rpcs is limited to max_rpcs_in_flight */
394 atomic_t cl_destroy_in_flight;
395 wait_queue_head_t cl_destroy_waitq;
397 struct mdc_rpc_lock *cl_rpc_lock;
398 struct mdc_rpc_lock *cl_close_lock;
401 struct mutex cl_mgc_mutex;
402 struct local_oid_storage *cl_mgc_los;
403 struct dt_object *cl_mgc_configs_dir;
404 atomic_t cl_mgc_refcount;
405 struct obd_export *cl_mgc_mgsexp;
407 /* checksumming for data sent over the network */
408 unsigned int cl_checksum:1; /* 0 = disabled, 1 = enabled */
409 /* supported checksum types that are worked out at connect time */
410 __u32 cl_supp_cksum_types;
411 /* checksum algorithm to be used */
412 cksum_type_t cl_cksum_type;
414 /* also protected by the poorly named _loi_list_lock lock above */
415 struct osc_async_rc cl_ar;
417 /* used by quotacheck when the servers are older than 2.4 */
418 int cl_qchk_stat; /* quotacheck stat of the peer */
419 #define CL_NOT_QUOTACHECKED 1 /* client->cl_qchk_stat init value */
420 #if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 7, 50, 0)
421 #warning "please consider removing quotacheck compatibility code"
424 /* sequence manager */
425 struct lu_client_seq *cl_seq;
427 atomic_t cl_resends; /* resend count */
429 /* ptlrpc work for writeback in ptlrpcd context */
430 void *cl_writeback_work;
431 /* hash tables for osc_quota_info */
432 struct cfs_hash *cl_quota_hash[MAXQUOTAS];
434 #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
441 struct echo_client_obd {
442 struct obd_export *ec_exp; /* the local connection to osc/lov */
444 struct list_head ec_objects;
445 struct list_head ec_locks;
450 /* Generic subset of OSTs */
452 __u32 *op_array; /* array of index of
454 unsigned int op_count; /* number of OSTs in the array */
455 unsigned int op_size; /* allocated size of lp_array */
456 struct rw_semaphore op_rw_sem; /* to protect ost_pool use */
459 /* Round-robin allocator data */
461 __u32 lqr_start_idx; /* start index of new inode */
462 __u32 lqr_offset_idx; /* aliasing for start_idx */
463 int lqr_start_count; /* reseed counter */
464 struct ost_pool lqr_pool; /* round-robin optimized list */
465 unsigned long lqr_dirty:1; /* recalc round-robin list */
468 /* allow statfs data caching for 1 second */
469 #define OBD_STATFS_CACHE_SECONDS 1
471 struct lov_statfs_data {
472 struct obd_info lsd_oi;
473 struct obd_statfs lsd_statfs;
475 /* Stripe placement optimization */
477 struct list_head lq_oss_list; /* list of OSSs that targets use */
478 struct rw_semaphore lq_rw_sem;
479 __u32 lq_active_oss_count;
480 unsigned int lq_prio_free; /* priority for free space */
481 unsigned int lq_threshold_rr;/* priority for rr */
482 struct lov_qos_rr lq_rr; /* round robin qos data */
483 unsigned long lq_dirty:1, /* recalc qos data */
484 lq_same_space:1,/* the ost's all have approx.
485 the same space avail */
486 lq_reset:1, /* zero current penalties */
487 lq_statfs_in_progress:1; /* statfs op in
489 /* qos statfs data */
490 struct lov_statfs_data *lq_statfs_data;
491 wait_queue_head_t lq_statfs_waitq; /* waitqueue to notify statfs
492 * requests completion */
495 struct lov_tgt_desc {
496 struct list_head ltd_kill;
497 struct obd_uuid ltd_uuid;
498 struct obd_device *ltd_obd;
499 struct obd_export *ltd_exp;
501 __u32 ltd_index; /* index in lov_obd->tgts */
502 unsigned long ltd_active:1,/* is this target up for requests */
503 ltd_activate:1,/* should target be activated */
504 ltd_reap:1; /* should this target be deleted */
508 #define pool_tgt_size(_p) _p->pool_obds.op_size
509 #define pool_tgt_count(_p) _p->pool_obds.op_count
510 #define pool_tgt_array(_p) _p->pool_obds.op_array
511 #define pool_tgt_rw_sem(_p) _p->pool_obds.op_rw_sem
514 char pool_name[LOV_MAXPOOLNAME + 1]; /* name of pool */
515 struct ost_pool pool_obds; /* pool members */
516 atomic_t pool_refcount; /* pool ref. counter */
517 struct lov_qos_rr pool_rr; /* round robin qos */
518 struct hlist_node pool_hash; /* access by poolname */
519 struct list_head pool_list; /* serial access */
520 struct dentry *pool_debugfs_entry; /* file in /proc */
521 struct obd_device *pool_lobd; /* obd of the lov/lod to which
522 * this pool belongs */
526 struct lov_desc desc;
527 struct lov_tgt_desc **lov_tgts; /* sparse array */
528 struct ost_pool lov_packed; /* all OSTs in a packed
530 struct mutex lov_lock;
531 struct obd_connect_data lov_ocd;
532 atomic_t lov_refcount;
533 __u32 lov_tgt_count; /* how many OBD's */
534 __u32 lov_active_tgt_count; /* how many active */
535 __u32 lov_death_row;/* tgts scheduled to be deleted */
536 __u32 lov_tgt_size; /* size of tgts array */
539 struct cfs_hash *lov_pools_hash_body; /* used for key access */
540 struct list_head lov_pool_list; /* used for sequential access */
541 struct dentry *lov_pool_debugfs_entry;
542 enum lustre_sec_part lov_sp_me;
544 /* Cached LRU pages from upper layer */
547 struct rw_semaphore lov_notify_lock;
549 struct kobject *lov_tgts_kobj;
552 struct lmv_tgt_desc {
553 struct obd_uuid ltd_uuid;
554 struct obd_export *ltd_exp;
556 struct mutex ltd_fid_mutex;
557 unsigned long ltd_active:1; /* target up for requests */
560 enum placement_policy {
561 PLACEMENT_CHAR_POLICY = 0,
562 PLACEMENT_NID_POLICY = 1,
563 PLACEMENT_INVAL_POLICY = 2,
569 struct lu_client_fld lmv_fld;
571 enum placement_policy lmv_placement;
572 struct lmv_desc desc;
573 struct obd_uuid cluuid;
574 struct obd_export *exp;
576 struct mutex init_mutex;
581 int max_def_cookiesize;
584 int tgts_size; /* size of tgts array */
585 struct lmv_tgt_desc **tgts;
587 struct obd_connect_data conn_data;
588 struct kobject *lmv_tgts_kobj;
591 struct niobuf_local {
592 __u64 lnb_file_offset;
593 __u32 lnb_page_offset;
597 struct dentry *dentry;
602 #define LUSTRE_FLD_NAME "fld"
603 #define LUSTRE_SEQ_NAME "seq"
605 #define LUSTRE_MDD_NAME "mdd"
606 #define LUSTRE_OSD_LDISKFS_NAME "osd-ldiskfs"
607 #define LUSTRE_OSD_ZFS_NAME "osd-zfs"
608 #define LUSTRE_VVP_NAME "vvp"
609 #define LUSTRE_LMV_NAME "lmv"
610 #define LUSTRE_SLP_NAME "slp"
611 #define LUSTRE_LOD_NAME "lod"
612 #define LUSTRE_OSP_NAME "osp"
613 #define LUSTRE_LWP_NAME "lwp"
615 /* obd device type names */
616 /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */
617 #define LUSTRE_MDS_NAME "mds"
618 #define LUSTRE_MDT_NAME "mdt"
619 #define LUSTRE_MDC_NAME "mdc"
620 #define LUSTRE_OSS_NAME "ost" /* FIXME change name to oss */
621 #define LUSTRE_OST_NAME "obdfilter" /* FIXME change name to ost */
622 #define LUSTRE_OSC_NAME "osc"
623 #define LUSTRE_LOV_NAME "lov"
624 #define LUSTRE_MGS_NAME "mgs"
625 #define LUSTRE_MGC_NAME "mgc"
627 #define LUSTRE_ECHO_NAME "obdecho"
628 #define LUSTRE_ECHO_CLIENT_NAME "echo_client"
629 #define LUSTRE_QMT_NAME "qmt"
631 /* Constant obd names (post-rename) */
632 #define LUSTRE_MDS_OBDNAME "MDS"
633 #define LUSTRE_OSS_OBDNAME "OSS"
634 #define LUSTRE_MGS_OBDNAME "MGS"
635 #define LUSTRE_MGC_OBDNAME "MGC"
637 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
638 #define N_LOCAL_TEMP_PAGE 0x10000000
640 struct obd_trans_info {
643 /* Only used on the server side for tracking acks. */
644 struct oti_req_ack_lock {
645 struct lustre_handle lock;
649 struct llog_cookie oti_onecookie;
650 struct llog_cookie *oti_logcookies;
652 /** synchronous write is needed */
653 unsigned long oti_sync_write:1;
655 /* initial thread handling transaction */
656 struct ptlrpc_thread *oti_thread;
659 __u64 oti_pre_version;
663 struct obd_uuid *oti_ost_uuid;
666 static inline void oti_init(struct obd_trans_info *oti,
667 struct ptlrpc_request *req)
671 memset(oti, 0, sizeof(*oti));
676 oti->oti_xid = req->rq_xid;
677 /** VBR: take versions from request */
678 if (req->rq_reqmsg != NULL &&
679 lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
680 __u64 *pre_version = lustre_msg_get_versions(req->rq_reqmsg);
682 oti->oti_pre_version = pre_version ? pre_version[0] : 0;
683 oti->oti_transno = lustre_msg_get_transno(req->rq_reqmsg);
686 /** called from mds_create_objects */
687 if (req->rq_repmsg != NULL)
688 oti->oti_transno = lustre_msg_get_transno(req->rq_repmsg);
689 oti->oti_thread = req->rq_svc_thread;
690 if (req->rq_reqmsg != NULL)
691 oti->oti_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg);
694 static inline void oti_alloc_cookies(struct obd_trans_info *oti,
700 if (num_cookies == 1)
701 oti->oti_logcookies = &oti->oti_onecookie;
703 oti->oti_logcookies = libcfs_kvzalloc(num_cookies * sizeof(oti->oti_onecookie),
706 oti->oti_numcookies = num_cookies;
709 static inline void oti_free_cookies(struct obd_trans_info *oti)
711 if (!oti || !oti->oti_logcookies)
714 if (oti->oti_logcookies == &oti->oti_onecookie)
715 LASSERT(oti->oti_numcookies == 1);
717 kvfree(oti->oti_logcookies);
719 oti->oti_logcookies = NULL;
720 oti->oti_numcookies = 0;
724 * Events signalled through obd_notify() upcall-chain.
726 enum obd_notify_event {
729 /* Device connect start */
731 /* Device activated */
733 /* Device deactivated */
735 /* Device disconnected */
737 /* Connect data for import were changed */
740 OBD_NOTIFY_SYNC_NONBLOCK,
742 /* Configuration event */
744 /* Administratively deactivate/activate event */
745 OBD_NOTIFY_DEACTIVATE,
750 * Data structure used to pass obd_notify()-event to non-obd listeners (llite
751 * and liblustre being main examples).
753 struct obd_notify_upcall {
754 int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
755 enum obd_notify_event ev, void *owner, void *data);
756 /* Opaque datum supplied by upper layer listener */
760 struct target_recovery_data {
761 svc_handler_t trd_recovery_handler;
762 pid_t trd_processing_task;
763 struct completion trd_starting;
764 struct completion trd_finishing;
767 struct obd_llog_group {
769 struct llog_ctxt *olg_ctxts[LLOG_MAX_CTXTS];
770 wait_queue_head_t olg_waitq;
772 struct mutex olg_cat_processing;
775 /* corresponds to one of the obd's */
776 #define OBD_DEVICE_MAGIC 0XAB5CD6EF
777 #define OBD_DEV_BY_DEVNAME 0xffffd0de
779 struct lvfs_run_ctxt {
780 struct dt_device *dt;
784 struct obd_type *obd_type;
787 /* common and UUID name of this device */
788 char obd_name[MAX_OBD_NAME];
789 struct obd_uuid obd_uuid;
791 struct lu_device *obd_lu_dev;
794 /* bitfield modification is protected by obd_dev_lock */
795 unsigned long obd_attached:1, /* finished attach */
796 obd_set_up:1, /* finished setup */
797 obd_recovering:1, /* there are recoverable clients */
798 obd_abort_recovery:1,/* recovery expired */
799 obd_version_recov:1, /* obd uses version checking */
800 obd_replayable:1, /* recovery is enabled; inform clients */
801 obd_no_transno:1, /* no committed-transno notification */
802 obd_no_recov:1, /* fail instead of retry messages */
803 obd_stopping:1, /* started cleanup */
804 obd_starting:1, /* started setup */
805 obd_force:1, /* cleanup with > 0 obd refcount */
806 obd_fail:1, /* cleanup with failover */
807 obd_async_recov:1, /* allow asynchronous orphan cleanup */
808 obd_no_conn:1, /* deny new connections */
809 obd_inactive:1, /* device active/inactive
810 * (for /proc/status only!!) */
811 obd_no_ir:1, /* no imperative recovery. */
812 obd_process_conf:1; /* device is processing mgs config */
813 /* use separate field as it is set in interrupt to don't mess with
814 * protection of other bits using _bh lock */
815 unsigned long obd_recovery_expired:1;
816 /* uuid-export hash body */
817 struct cfs_hash *obd_uuid_hash;
818 /* nid-export hash body */
819 struct cfs_hash *obd_nid_hash;
820 atomic_t obd_refcount;
821 wait_queue_head_t obd_refcount_waitq;
822 struct list_head obd_exports;
823 struct list_head obd_unlinked_exports;
824 struct list_head obd_delayed_exports;
826 spinlock_t obd_nid_lock;
827 struct ldlm_namespace *obd_namespace;
828 struct ptlrpc_client obd_ldlm_client; /* XXX OST/MDS only */
829 /* a spinlock is OK for what we do now, may need a semaphore later */
830 spinlock_t obd_dev_lock; /* protect OBD bitfield above */
831 struct mutex obd_dev_mutex;
832 __u64 obd_last_committed;
833 spinlock_t obd_osfs_lock;
834 struct obd_statfs obd_osfs; /* locked by obd_osfs_lock */
836 struct lvfs_run_ctxt obd_lvfs_ctxt;
837 struct obd_llog_group obd_olg; /* default llog group */
838 struct obd_device *obd_observer;
839 struct rw_semaphore obd_observer_link_sem;
840 struct obd_notify_upcall obd_upcall;
841 struct obd_export *obd_self_export;
842 /* list of exports in LRU order, for ping evictor, with obd_dev_lock */
843 struct list_head obd_exports_timed;
845 int obd_max_recoverable_clients;
846 atomic_t obd_connected_clients;
847 int obd_stale_clients;
848 int obd_delayed_clients;
849 /* this lock protects all recovery list_heads, timer and
850 * obd_next_recovery_transno value */
851 spinlock_t obd_recovery_task_lock;
852 __u64 obd_next_recovery_transno;
853 int obd_replayed_requests;
854 int obd_requests_queued_for_recovery;
855 wait_queue_head_t obd_next_transno_waitq;
856 /* protected by obd_recovery_task_lock */
857 int obd_recovery_timeout;
859 /* new recovery stuff from CMD2 */
860 struct target_recovery_data obd_recovery_data;
861 int obd_replayed_locks;
862 atomic_t obd_req_replay_clients;
863 atomic_t obd_lock_replay_clients;
864 /* all lists are protected by obd_recovery_task_lock */
865 struct list_head obd_req_replay_queue;
866 struct list_head obd_lock_replay_queue;
867 struct list_head obd_final_req_queue;
868 int obd_recovery_stage;
871 struct client_obd cli;
872 struct echo_client_obd echo_client;
876 /* Fields used by LProcFS */
877 unsigned int obd_cntr_base;
878 struct lprocfs_stats *obd_stats;
880 unsigned int md_cntr_base;
881 struct lprocfs_stats *md_stats;
883 struct dentry *obd_debugfs_entry;
884 struct dentry *obd_svc_debugfs_entry;
885 struct lprocfs_stats *obd_svc_stats;
886 atomic_t obd_evict_inprogress;
887 wait_queue_head_t obd_evict_inprogress_waitq;
888 struct list_head obd_evict_list; /* protected with pet_lock */
891 * Ldlm pool part. Save last calculated SLV and Limit.
893 rwlock_t obd_pool_lock;
898 * A list of outstanding class_incref()'s against this obd. For
901 struct lu_ref obd_reference;
903 int obd_conn_inprogress;
905 struct kobject obd_kobj; /* sysfs object */
906 struct completion obd_kobj_unregister;
909 #define OBD_LLOG_FL_SENDNOW 0x0001
910 #define OBD_LLOG_FL_EXIT 0x0002
912 enum obd_cleanup_stage {
913 /* Special case hack for MDS LOVs */
915 /* can be directly mapped to .ldto_device_fini() */
919 /* get/set_info keys */
920 #define KEY_ASYNC "async"
921 #define KEY_BLOCKSIZE_BITS "blocksize_bits"
922 #define KEY_BLOCKSIZE "blocksize"
923 #define KEY_CAPA_KEY "capa_key"
924 #define KEY_CHANGELOG_CLEAR "changelog_clear"
925 #define KEY_FID2PATH "fid2path"
926 #define KEY_CHECKSUM "checksum"
927 #define KEY_CLEAR_FS "clear_fs"
928 #define KEY_CONN_DATA "conn_data"
929 #define KEY_EVICT_BY_NID "evict_by_nid"
930 #define KEY_FIEMAP "fiemap"
931 #define KEY_FLUSH_CTX "flush_ctx"
932 #define KEY_GRANT_SHRINK "grant_shrink"
933 #define KEY_HSM_COPYTOOL_SEND "hsm_send"
934 #define KEY_INIT_RECOV_BACKUP "init_recov_bk"
935 #define KEY_INIT_RECOV "initial_recov"
936 #define KEY_INTERMDS "inter_mds"
937 #define KEY_LAST_ID "last_id"
938 #define KEY_LAST_FID "last_fid"
939 #define KEY_LOCK_TO_STRIPE "lock_to_stripe"
940 #define KEY_LOVDESC "lovdesc"
941 #define KEY_LOV_IDX "lov_idx"
942 #define KEY_MAX_EASIZE "max_easize"
943 #define KEY_DEFAULT_EASIZE "default_easize"
944 #define KEY_MAX_COOKIESIZE "max_cookiesize"
945 #define KEY_DEFAULT_COOKIESIZE "default_cookiesize"
946 #define KEY_MDS_CONN "mds_conn"
947 #define KEY_MGSSEC "mgssec"
948 #define KEY_NEXT_ID "next_id"
949 #define KEY_READ_ONLY "read-only"
950 #define KEY_REGISTER_TARGET "register_target"
951 #define KEY_SET_FS "set_fs"
952 #define KEY_TGT_COUNT "tgt_count"
953 /* KEY_SET_INFO in lustre_idl.h */
954 #define KEY_SPTLRPC_CONF "sptlrpc_conf"
955 #define KEY_CONNECT_FLAG "connect_flags"
956 #define KEY_SYNC_LOCK_CANCEL "sync_lock_cancel"
958 #define KEY_CACHE_SET "cache_set"
959 #define KEY_CACHE_LRU_SHRINK "cache_lru_shrink"
960 #define KEY_CHANGELOG_INDEX "changelog_index"
964 /* /!\ must be coherent with include/linux/namei.h on patched kernel */
965 #define IT_OPEN (1 << 0)
966 #define IT_CREAT (1 << 1)
967 #define IT_READDIR (1 << 2)
968 #define IT_GETATTR (1 << 3)
969 #define IT_LOOKUP (1 << 4)
970 #define IT_UNLINK (1 << 5)
971 #define IT_TRUNC (1 << 6)
972 #define IT_GETXATTR (1 << 7)
973 #define IT_EXEC (1 << 8)
974 #define IT_PIN (1 << 9)
975 #define IT_LAYOUT (1 << 10)
976 #define IT_QUOTA_DQACQ (1 << 11)
977 #define IT_QUOTA_CONN (1 << 12)
978 #define IT_SETXATTR (1 << 13)
980 static inline int it_to_lock_mode(struct lookup_intent *it)
982 /* CREAT needs to be tested before open (both could be set) */
983 if (it->it_op & IT_CREAT)
985 else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_LOOKUP |
988 else if (it->it_op & IT_GETXATTR)
990 else if (it->it_op & IT_SETXATTR)
993 LASSERTF(0, "Invalid it_op: %d\n", it->it_op);
998 struct lu_fid op_fid1; /* operation fid1 (usually parent) */
999 struct lu_fid op_fid2; /* operation fid2 (usually child) */
1000 struct lu_fid op_fid3; /* 2 extra fids to find conflicting */
1001 struct lu_fid op_fid4; /* to the operation locks. */
1002 u32 op_mds; /* what mds server open will go to */
1003 struct lustre_handle op_handle;
1005 const char *op_name;
1008 struct lmv_stripe_md *op_mea1;
1009 struct lmv_stripe_md *op_mea2;
1010 __u32 op_suppgids[2];
1016 /* iattr fields and blocks. */
1017 struct iattr op_attr;
1018 unsigned int op_attr_flags;
1020 loff_t op_attr_blocks;
1022 /* Size-on-MDS epoch and flags. */
1027 struct obd_capa *op_capa1;
1028 struct obd_capa *op_capa2;
1030 /* Various operation flags. */
1031 enum mds_op_bias op_bias;
1033 /* Operation type */
1036 /* Used by readdir */
1039 /* Used by readdir */
1042 /* used to transfer info between the stacks of MD client
1043 * see enum op_cli_flags */
1046 /* File object data version for HSM release, on client */
1047 __u64 op_data_version;
1048 struct lustre_handle op_lease_handle;
1052 CLI_SET_MEA = 1 << 0,
1053 CLI_RM_ENTRY = 1 << 1,
1056 struct md_enqueue_info;
1057 /* metadata stat-ahead */
1059 struct md_enqueue_info {
1060 struct md_op_data mi_data;
1061 struct lookup_intent mi_it;
1062 struct lustre_handle mi_lockh;
1063 struct inode *mi_dir;
1064 int (*mi_cb)(struct ptlrpc_request *req,
1065 struct md_enqueue_info *minfo, int rc);
1067 unsigned int mi_generation;
1071 struct module *o_owner;
1072 int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
1073 void *karg, void *uarg);
1074 int (*o_get_info)(const struct lu_env *env, struct obd_export *,
1075 __u32 keylen, void *key, __u32 *vallen, void *val,
1076 struct lov_stripe_md *lsm);
1077 int (*o_set_info_async)(const struct lu_env *, struct obd_export *,
1078 __u32 keylen, void *key,
1079 __u32 vallen, void *val,
1080 struct ptlrpc_request_set *set);
1081 int (*o_attach)(struct obd_device *dev, u32 len, void *data);
1082 int (*o_detach)(struct obd_device *dev);
1083 int (*o_setup)(struct obd_device *dev, struct lustre_cfg *cfg);
1084 int (*o_precleanup)(struct obd_device *dev,
1085 enum obd_cleanup_stage cleanup_stage);
1086 int (*o_cleanup)(struct obd_device *dev);
1087 int (*o_process_config)(struct obd_device *dev, u32 len, void *data);
1088 int (*o_postrecov)(struct obd_device *dev);
1089 int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
1091 int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
1092 /* connect to the target device with given connection
1093 * data. @ocd->ocd_connect_flags is modified to reflect flags actually
1094 * granted by the target, which are guaranteed to be a subset of flags
1095 * asked for. If @ocd == NULL, use default parameters. */
1096 int (*o_connect)(const struct lu_env *env,
1097 struct obd_export **exp, struct obd_device *src,
1098 struct obd_uuid *cluuid, struct obd_connect_data *ocd,
1100 int (*o_reconnect)(const struct lu_env *env,
1101 struct obd_export *exp, struct obd_device *src,
1102 struct obd_uuid *cluuid,
1103 struct obd_connect_data *ocd,
1105 int (*o_disconnect)(struct obd_export *exp);
1107 /* Initialize/finalize fids infrastructure. */
1108 int (*o_fid_init)(struct obd_device *obd,
1109 struct obd_export *exp, enum lu_cli_type type);
1110 int (*o_fid_fini)(struct obd_device *obd);
1112 /* Allocate new fid according to passed @hint. */
1113 int (*o_fid_alloc)(struct obd_export *exp, struct lu_fid *fid,
1114 struct md_op_data *op_data);
1117 * Object with @fid is getting deleted, we may want to do something
1120 int (*o_statfs)(const struct lu_env *, struct obd_export *exp,
1121 struct obd_statfs *osfs, __u64 max_age, __u32 flags);
1122 int (*o_statfs_async)(struct obd_export *exp, struct obd_info *oinfo,
1123 __u64 max_age, struct ptlrpc_request_set *set);
1124 int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
1125 struct lov_stripe_md *mem_src);
1126 int (*o_unpackmd)(struct obd_export *exp,
1127 struct lov_stripe_md **mem_tgt,
1128 struct lov_mds_md *disk_src, int disk_len);
1129 int (*o_preallocate)(struct lustre_handle *, u32 *req, u64 *ids);
1130 /* FIXME: add fid capability support for create & destroy! */
1131 int (*o_create)(const struct lu_env *env, struct obd_export *exp,
1132 struct obdo *oa, struct lov_stripe_md **ea,
1133 struct obd_trans_info *oti);
1134 int (*o_destroy)(const struct lu_env *env, struct obd_export *exp,
1135 struct obdo *oa, struct lov_stripe_md *ea,
1136 struct obd_trans_info *oti, struct obd_export *md_exp,
1138 int (*o_setattr)(const struct lu_env *, struct obd_export *exp,
1139 struct obd_info *oinfo, struct obd_trans_info *oti);
1140 int (*o_setattr_async)(struct obd_export *exp, struct obd_info *oinfo,
1141 struct obd_trans_info *oti,
1142 struct ptlrpc_request_set *rqset);
1143 int (*o_getattr)(const struct lu_env *env, struct obd_export *exp,
1144 struct obd_info *oinfo);
1145 int (*o_getattr_async)(struct obd_export *exp, struct obd_info *oinfo,
1146 struct ptlrpc_request_set *set);
1147 int (*o_adjust_kms)(struct obd_export *exp, struct lov_stripe_md *lsm,
1148 u64 size, int shrink);
1149 int (*o_preprw)(const struct lu_env *env, int cmd,
1150 struct obd_export *exp, struct obdo *oa, int objcount,
1151 struct obd_ioobj *obj, struct niobuf_remote *remote,
1152 int *nr_pages, struct niobuf_local *local,
1153 struct obd_trans_info *oti, struct lustre_capa *capa);
1154 int (*o_commitrw)(const struct lu_env *env, int cmd,
1155 struct obd_export *exp, struct obdo *oa,
1156 int objcount, struct obd_ioobj *obj,
1157 struct niobuf_remote *remote, int pages,
1158 struct niobuf_local *local,
1159 struct obd_trans_info *oti, int rc);
1160 int (*o_find_cbdata)(struct obd_export *, struct lov_stripe_md *,
1161 ldlm_iterator_t it, void *data);
1162 int (*o_init_export)(struct obd_export *exp);
1163 int (*o_destroy_export)(struct obd_export *exp);
1165 /* metadata-only methods */
1166 int (*o_import_event)(struct obd_device *, struct obd_import *,
1167 enum obd_import_event);
1169 int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
1170 enum obd_notify_event ev, void *data);
1172 int (*o_health_check)(const struct lu_env *env, struct obd_device *);
1173 struct obd_uuid *(*o_get_uuid)(struct obd_export *exp);
1176 int (*o_quotacheck)(struct obd_device *, struct obd_export *,
1177 struct obd_quotactl *);
1178 int (*o_quotactl)(struct obd_device *, struct obd_export *,
1179 struct obd_quotactl *);
1182 int (*o_pool_new)(struct obd_device *obd, char *poolname);
1183 int (*o_pool_del)(struct obd_device *obd, char *poolname);
1184 int (*o_pool_add)(struct obd_device *obd, char *poolname,
1186 int (*o_pool_rem)(struct obd_device *obd, char *poolname,
1188 void (*o_getref)(struct obd_device *obd);
1189 void (*o_putref)(struct obd_device *obd);
1191 * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
1192 * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
1193 * Also, add a wrapper function in include/linux/obd_class.h. */
1197 LUSTRE_OPC_MKDIR = (1 << 0),
1198 LUSTRE_OPC_SYMLINK = (1 << 1),
1199 LUSTRE_OPC_MKNOD = (1 << 2),
1200 LUSTRE_OPC_CREATE = (1 << 3),
1201 LUSTRE_OPC_ANY = (1 << 4)
1204 /* lmv structures */
1205 #define MEA_MAGIC_LAST_CHAR 0xb2221ca1
1206 #define MEA_MAGIC_ALL_CHARS 0xb222a11c
1207 #define MEA_MAGIC_HASH_SEGMENT 0xb222a11b
1209 #define MAX_HASH_SIZE_32 0x7fffffffUL
1210 #define MAX_HASH_SIZE 0x7fffffffffffffffULL
1211 #define MAX_HASH_HIGHEST_BIT 0x1000000000000000ULL
1214 struct mdt_body *body;
1215 struct lov_stripe_md *lsm;
1216 struct lmv_stripe_md *mea;
1217 #ifdef CONFIG_FS_POSIX_ACL
1218 struct posix_acl *posix_acl;
1220 struct mdt_remote_perm *remote_perm;
1221 struct obd_capa *mds_capa;
1222 struct obd_capa *oss_capa;
1225 struct md_open_data {
1226 struct obd_client_handle *mod_och;
1227 struct ptlrpc_request *mod_open_req;
1228 struct ptlrpc_request *mod_close_req;
1229 atomic_t mod_refcount;
1233 struct lookup_intent;
1236 int (*m_getstatus)(struct obd_export *, struct lu_fid *,
1237 struct obd_capa **);
1238 int (*m_null_inode)(struct obd_export *, const struct lu_fid *);
1239 int (*m_find_cbdata)(struct obd_export *, const struct lu_fid *,
1240 ldlm_iterator_t, void *);
1241 int (*m_close)(struct obd_export *, struct md_op_data *,
1242 struct md_open_data *, struct ptlrpc_request **);
1243 int (*m_create)(struct obd_export *, struct md_op_data *,
1244 const void *, int, int, __u32, __u32, cfs_cap_t,
1245 __u64, struct ptlrpc_request **);
1246 int (*m_done_writing)(struct obd_export *, struct md_op_data *,
1247 struct md_open_data *);
1248 int (*m_enqueue)(struct obd_export *, struct ldlm_enqueue_info *,
1249 struct lookup_intent *, struct md_op_data *,
1250 struct lustre_handle *, void *, int,
1251 struct ptlrpc_request **, __u64);
1252 int (*m_getattr)(struct obd_export *, struct md_op_data *,
1253 struct ptlrpc_request **);
1254 int (*m_getattr_name)(struct obd_export *, struct md_op_data *,
1255 struct ptlrpc_request **);
1256 int (*m_intent_lock)(struct obd_export *, struct md_op_data *,
1257 void *, int, struct lookup_intent *, int,
1258 struct ptlrpc_request **,
1259 ldlm_blocking_callback, __u64);
1260 int (*m_link)(struct obd_export *, struct md_op_data *,
1261 struct ptlrpc_request **);
1262 int (*m_rename)(struct obd_export *, struct md_op_data *,
1263 const char *, int, const char *, int,
1264 struct ptlrpc_request **);
1265 int (*m_is_subdir)(struct obd_export *, const struct lu_fid *,
1266 const struct lu_fid *,
1267 struct ptlrpc_request **);
1268 int (*m_setattr)(struct obd_export *, struct md_op_data *, void *,
1269 int, void *, int, struct ptlrpc_request **,
1270 struct md_open_data **mod);
1271 int (*m_sync)(struct obd_export *, const struct lu_fid *,
1272 struct obd_capa *, struct ptlrpc_request **);
1273 int (*m_readpage)(struct obd_export *, struct md_op_data *,
1274 struct page **, struct ptlrpc_request **);
1276 int (*m_unlink)(struct obd_export *, struct md_op_data *,
1277 struct ptlrpc_request **);
1279 int (*m_setxattr)(struct obd_export *, const struct lu_fid *,
1280 struct obd_capa *, u64, const char *,
1281 const char *, int, int, int, __u32,
1282 struct ptlrpc_request **);
1284 int (*m_getxattr)(struct obd_export *, const struct lu_fid *,
1285 struct obd_capa *, u64, const char *,
1286 const char *, int, int, int,
1287 struct ptlrpc_request **);
1289 int (*m_init_ea_size)(struct obd_export *, int, int, int, int);
1291 int (*m_get_lustre_md)(struct obd_export *, struct ptlrpc_request *,
1292 struct obd_export *, struct obd_export *,
1293 struct lustre_md *);
1295 int (*m_free_lustre_md)(struct obd_export *, struct lustre_md *);
1297 int (*m_set_open_replay_data)(struct obd_export *,
1298 struct obd_client_handle *,
1299 struct lookup_intent *);
1300 int (*m_clear_open_replay_data)(struct obd_export *,
1301 struct obd_client_handle *);
1302 int (*m_set_lock_data)(struct obd_export *, __u64 *, void *, __u64 *);
1304 ldlm_mode_t (*m_lock_match)(struct obd_export *, __u64,
1305 const struct lu_fid *, ldlm_type_t,
1306 ldlm_policy_data_t *, ldlm_mode_t,
1307 struct lustre_handle *);
1309 int (*m_cancel_unused)(struct obd_export *, const struct lu_fid *,
1310 ldlm_policy_data_t *, ldlm_mode_t,
1311 ldlm_cancel_flags_t flags, void *opaque);
1312 int (*m_renew_capa)(struct obd_export *, struct obd_capa *oc,
1313 renew_capa_cb_t cb);
1314 int (*m_unpack_capa)(struct obd_export *, struct ptlrpc_request *,
1315 const struct req_msg_field *, struct obd_capa **);
1317 int (*m_get_remote_perm)(struct obd_export *, const struct lu_fid *,
1318 struct obd_capa *, __u32,
1319 struct ptlrpc_request **);
1321 int (*m_intent_getattr_async)(struct obd_export *,
1322 struct md_enqueue_info *,
1323 struct ldlm_enqueue_info *);
1325 int (*m_revalidate_lock)(struct obd_export *, struct lookup_intent *,
1326 struct lu_fid *, __u64 *bits);
1329 * NOTE: If adding ops, add another LPROCFS_MD_OP_INIT() line to
1330 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
1331 * wrapper function in include/linux/obd_class.h.
1335 struct lsm_operations {
1336 void (*lsm_free)(struct lov_stripe_md *);
1337 int (*lsm_destroy)(struct lov_stripe_md *, struct obdo *oa,
1338 struct obd_export *md_exp);
1339 void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *, u64 *,
1341 void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *, u64 *,
1343 int (*lsm_lmm_verify)(struct lov_mds_md *lmm, int lmm_bytes,
1344 __u16 *stripe_count);
1345 int (*lsm_unpackmd)(struct lov_obd *lov, struct lov_stripe_md *lsm,
1346 struct lov_mds_md *lmm);
1349 extern const struct lsm_operations lsm_v1_ops;
1350 extern const struct lsm_operations lsm_v3_ops;
1351 static inline const struct lsm_operations *lsm_op_find(int magic)
1359 CERROR("Cannot recognize lsm_magic %08x\n", magic);
1364 /* Requests for obd_extent_calc() */
1365 #define OBD_CALC_STRIPE_START 1
1366 #define OBD_CALC_STRIPE_END 2
1368 static inline struct lustre_capa *oinfo_capa(struct obd_info *oinfo)
1370 return oinfo->oi_capa;
1373 static inline struct md_open_data *obd_mod_alloc(void)
1375 struct md_open_data *mod;
1377 mod = kzalloc(sizeof(*mod), GFP_NOFS);
1380 atomic_set(&mod->mod_refcount, 1);
1384 #define obd_mod_get(mod) atomic_inc(&(mod)->mod_refcount)
1385 #define obd_mod_put(mod) \
1387 if (atomic_dec_and_test(&(mod)->mod_refcount)) { \
1388 if ((mod)->mod_open_req) \
1389 ptlrpc_req_finished((mod)->mod_open_req); \
1394 void obdo_from_inode(struct obdo *dst, struct inode *src, u32 valid);
1395 void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent);
1397 /* return 1 if client should be resend request */
1398 static inline int client_should_resend(int resend, struct client_obd *cli)
1400 return atomic_read(&cli->cl_resends) ?
1401 atomic_read(&cli->cl_resends) > resend : 1;
1405 * Return device name for this device
1407 * XXX: lu_device is declared before obd_device, while a pointer pointing
1408 * back to obd_device in lu_device, so this helper function defines here
1409 * instead of in lu_object.h
1411 static inline const char *lu_dev_name(const struct lu_device *lu_dev)
1413 return lu_dev->ld_obd->obd_name;
1416 static inline bool filename_is_volatile(const char *name, int namelen, int *idx)
1421 if (strncmp(name, LUSTRE_VOLATILE_HDR, LUSTRE_VOLATILE_HDR_LEN) != 0)
1424 /* caller does not care of idx */
1428 /* volatile file, the MDT can be set from name */
1429 /* name format is LUSTRE_VOLATILE_HDR:[idx]: */
1430 /* if no MDT is specified, use std way */
1431 if (namelen < LUSTRE_VOLATILE_HDR_LEN + 2)
1433 /* test for no MDT idx case */
1434 if ((*(name + LUSTRE_VOLATILE_HDR_LEN) == ':') &&
1435 (*(name + LUSTRE_VOLATILE_HDR_LEN + 1) == ':')) {
1439 /* we have an idx, read it */
1440 start = name + LUSTRE_VOLATILE_HDR_LEN + 1;
1441 *idx = simple_strtoul(start, &end, 0);
1443 * no digit, no trailing :, negative value
1445 if (((*idx == 0) && (end == start)) ||
1446 (*end != ':') || (*idx < 0))
1451 /* bad format of mdt idx, we cannot return an error
1452 * to caller so we use hash algo */
1453 CERROR("Bad volatile file name format: %s\n",
1454 name + LUSTRE_VOLATILE_HDR_LEN);
1458 static inline int cli_brw_size(struct obd_device *obd)
1460 LASSERT(obd != NULL);
1461 return obd->u.cli.cl_max_pages_per_rpc << PAGE_CACHE_SHIFT;
1464 #endif /* __OBD_H */