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, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
40 #if defined(__linux__)
41 #include <linux/obd.h>
42 #elif defined(__APPLE__)
43 #include <darwin/obd.h>
44 #elif defined(__WINNT__)
45 #include <winnt/obd.h>
47 #error Unsupported operating system.
50 #define IOC_OSC_TYPE 'h'
51 #define IOC_OSC_MIN_NR 20
52 #define IOC_OSC_SET_ACTIVE _IOWR(IOC_OSC_TYPE, 21, struct obd_device *)
53 #define IOC_OSC_MAX_NR 50
55 #define IOC_MDC_TYPE 'i'
56 #define IOC_MDC_MIN_NR 20
57 #define IOC_MDC_MAX_NR 50
59 #include <lustre/lustre_idl.h>
60 #include <lustre_lib.h>
61 #include <libcfs/bitmap.h>
62 #ifdef HAVE_SERVER_SUPPORT
63 # include <lu_target.h>
64 # include <obd_target.h>
67 #include <lustre_export.h>
68 #include <lustre_fid.h>
69 #include <lustre_fld.h>
70 #include <lustre_capa.h>
72 #define MAX_OBD_DEVICES 8192
80 struct lov_oinfo { /* per-stripe data structure */
81 struct ost_id loi_oi; /* object ID/Sequence on the target OST */
82 int loi_ost_idx; /* OST stripe index in lov_tgt_desc->tgts */
83 int loi_ost_gen; /* generation of this loi_ost_idx */
85 unsigned long loi_kms_valid:1;
86 __u64 loi_kms; /* known minimum size */
87 struct ost_lvb loi_lvb;
88 struct osc_async_rc loi_ar;
91 static inline void loi_kms_set(struct lov_oinfo *oinfo, __u64 kms)
94 oinfo->loi_kms_valid = 1;
97 static inline void loi_init(struct lov_oinfo *loi)
101 struct lov_stripe_md {
102 cfs_atomic_t lsm_refc;
104 pid_t lsm_lock_owner; /* debugging */
106 /* maximum possible file size, might change as OSTs status changes,
107 * e.g. disconnected, deactivated */
110 /* Public members. */
111 struct ost_id lw_object_oi; /* lov object id/seq */
113 /* LOV-private members start here -- only for use in lov/. */
115 __u32 lw_stripe_size; /* size of the stripe */
116 __u32 lw_pattern; /* striping pattern (RAID0, RAID1) */
117 __u16 lw_stripe_count; /* number of objects being striped over */
118 __u16 lw_layout_gen; /* generation of the layout */
119 char lw_pool_name[LOV_MAXPOOLNAME]; /* pool name */
122 struct lov_oinfo *lsm_oinfo[0];
125 #define lsm_oi lsm_wire.lw_object_oi
126 #define lsm_magic lsm_wire.lw_magic
127 #define lsm_layout_gen lsm_wire.lw_layout_gen
128 #define lsm_stripe_size lsm_wire.lw_stripe_size
129 #define lsm_pattern lsm_wire.lw_pattern
130 #define lsm_stripe_count lsm_wire.lw_stripe_count
131 #define lsm_pool_name lsm_wire.lw_pool_name
133 static inline bool lsm_is_released(struct lov_stripe_md *lsm)
135 return !!(lsm->lsm_pattern & LOV_PATTERN_F_RELEASED);
138 static inline bool lsm_has_objects(struct lov_stripe_md *lsm)
142 if (lsm_is_released(lsm))
149 typedef int (*obd_enqueue_update_f)(void *cookie, int rc);
151 /* obd info for a particular level (lov, osc). */
153 /* Lock policy. It keeps an extent which is specific for a particular
154 * OSC. (e.g. lov_prep_enqueue_set initialises extent of the policy,
155 * and osc_enqueue passes it into ldlm_lock_match & ldlm_cli_enqueue. */
156 ldlm_policy_data_t oi_policy;
157 /* Flags used for set request specific flags:
158 - while lock handling, the flags obtained on the enqueue
159 request are set here.
160 - while stats, the flags used for control delay/resend.
161 - while setattr, the flags used for distinguish punch operation
164 /* Lock handle specific for every OSC lock. */
165 struct lustre_handle *oi_lockh;
166 /* lsm data specific for every OSC. */
167 struct lov_stripe_md *oi_md;
168 /* obdo data specific for every OSC, if needed at all. */
170 /* statfs data specific for every OSC, if needed at all. */
171 struct obd_statfs *oi_osfs;
172 /* An update callback which is called to update some data on upper
173 * level. E.g. it is used for update lsm->lsm_oinfo at every recieved
174 * request in osc level for enqueue requests. It is also possible to
175 * update some caller data from LOV layer if needed. */
176 obd_enqueue_update_f oi_cb_up;
177 /* oss capability, its type is obd_capa in client to avoid copy.
178 * in contrary its type is lustre_capa in OSS. */
180 /* transfer jobid from ost_sync() to filter_sync()... */
184 /* compare all relevant fields. */
185 static inline int lov_stripe_md_cmp(struct lov_stripe_md *m1,
186 struct lov_stripe_md *m2)
189 * ->lsm_wire contains padding, but it should be zeroed out during
192 return memcmp(&m1->lsm_wire, &m2->lsm_wire, sizeof m1->lsm_wire);
195 static inline int lov_lum_lsm_cmp(struct lov_user_md *lum,
196 struct lov_stripe_md *lsm)
198 if (lsm->lsm_magic != lum->lmm_magic)
200 if ((lsm->lsm_stripe_count != 0) && (lum->lmm_stripe_count != 0) &&
201 (lsm->lsm_stripe_count != lum->lmm_stripe_count))
203 if ((lsm->lsm_stripe_size != 0) && (lum->lmm_stripe_size != 0) &&
204 (lsm->lsm_stripe_size != lum->lmm_stripe_size))
206 if ((lsm->lsm_pattern != 0) && (lum->lmm_pattern != 0) &&
207 (lsm->lsm_pattern != lum->lmm_pattern))
209 if ((lsm->lsm_magic == LOV_MAGIC_V3) &&
210 (strncmp(lsm->lsm_pool_name,
211 ((struct lov_user_md_v3 *)lum)->lmm_pool_name,
212 LOV_MAXPOOLNAME) != 0))
217 static inline int lov_lum_swab_if_needed(struct lov_user_md_v3 *lumv3,
219 struct lov_user_md *lum)
221 if (lum && copy_from_user(lumv3, lum, sizeof(struct lov_user_md_v1)))
224 *lmm_magic = lumv3->lmm_magic;
226 if (*lmm_magic == __swab32(LOV_USER_MAGIC_V1)) {
227 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lumv3);
228 *lmm_magic = LOV_USER_MAGIC_V1;
229 } else if (*lmm_magic == LOV_USER_MAGIC_V3) {
230 if (lum && copy_from_user(lumv3, lum, sizeof(*lumv3)))
232 } else if (*lmm_magic == __swab32(LOV_USER_MAGIC_V3)) {
233 if (lum && copy_from_user(lumv3, lum, sizeof(*lumv3)))
235 lustre_swab_lov_user_md_v3(lumv3);
236 *lmm_magic = LOV_USER_MAGIC_V3;
237 } else if (*lmm_magic != LOV_USER_MAGIC_V1) {
239 "bad userland LOV MAGIC: %#08x != %#08x nor %#08x\n",
240 *lmm_magic, LOV_USER_MAGIC_V1, LOV_USER_MAGIC_V3);
246 void lov_stripe_lock(struct lov_stripe_md *md);
247 void lov_stripe_unlock(struct lov_stripe_md *md);
250 cfs_list_t typ_chain;
251 struct obd_ops *typ_dt_ops;
252 struct md_ops *typ_md_ops;
253 cfs_proc_dir_entry_t *typ_procroot;
256 struct lu_device_type *typ_lu;
257 spinlock_t obd_type_lock;
269 LLOG_CONFIG_ORIG_CTXT = 0,
270 LLOG_CONFIG_REPL_CTXT,
271 LLOG_MDS_OST_ORIG_CTXT,
272 LLOG_MDS_OST_REPL_CTXT,
279 LLOG_LOVEA_ORIG_CTXT,
280 LLOG_LOVEA_REPL_CTXT,
281 LLOG_CHANGELOG_ORIG_CTXT, /**< changelog generation on mdd */
282 LLOG_CHANGELOG_REPL_CTXT, /**< changelog access on clients */
283 LLOG_CHANGELOG_USER_ORIG_CTXT, /**< for multiple changelog consumers */
287 struct timeout_item {
288 enum timeout_event ti_event;
289 cfs_time_t ti_timeout;
292 cfs_list_t ti_obd_list;
296 #define OSC_MAX_RIF_DEFAULT 8
297 #define MDS_OSC_MAX_RIF_DEFAULT 50
298 #define OSC_MAX_RIF_MAX 256
299 #define OSC_MAX_DIRTY_DEFAULT (OSC_MAX_RIF_DEFAULT * 4)
300 #define OSC_MAX_DIRTY_MB_MAX 2048 /* arbitrary, but < MAX_LONG bytes */
301 #define OSC_DEFAULT_RESENDS 10
303 /* possible values for fo_sync_lock_cancel */
305 NEVER_SYNC_ON_CANCEL = 0,
306 BLOCKING_SYNC_ON_CANCEL = 1,
307 ALWAYS_SYNC_ON_CANCEL = 2,
308 NUM_SYNC_ON_CANCEL_STATES
311 #define MDC_MAX_RIF_DEFAULT 8
312 #define MDC_MAX_RIF_MAX 512
317 struct rw_semaphore cl_sem;
318 struct obd_uuid cl_target_uuid;
319 struct obd_import *cl_import; /* ptlrpc connection state */
321 /* max_mds_easize is purely a performance thing so we don't have to
322 * call obd_size_diskmd() all the time. */
323 int cl_default_mds_easize;
324 int cl_max_mds_easize;
325 int cl_max_mds_cookiesize;
327 enum lustre_sec_part cl_sp_me;
328 enum lustre_sec_part cl_sp_to;
329 struct sptlrpc_flavor cl_flvr_mgc; /* fixed flavor of mgc->mgs */
331 /* the grant values are protected by loi_list_lock below */
332 long cl_dirty; /* all _dirty_ in bytes */
333 long cl_dirty_max; /* allowed w/o rpc */
334 long cl_dirty_transit; /* dirty synchronous */
335 long cl_avail_grant; /* bytes of credit for ost */
336 long cl_lost_grant; /* lost credits (trunc) */
338 /* since we allocate grant by blocks, we don't know how many grant will
339 * be used to add a page into cache. As a solution, we reserve maximum
340 * grant before trying to dirty a page and unreserve the rest.
341 * See osc_{reserve|unreserve}_grant for details. */
342 long cl_reserved_grant;
343 cfs_list_t cl_cache_waiters; /* waiting for cache/grant */
344 cfs_time_t cl_next_shrink_grant; /* jiffies */
345 cfs_list_t cl_grant_shrink_list; /* Timeout event list */
346 int cl_grant_shrink_interval; /* seconds */
348 /* A chunk is an optimal size used by osc_extent to determine
349 * the extent size. A chunk is max(PAGE_CACHE_SIZE, OST block size) */
352 int cl_extent_tax; /* extent overhead, by bytes */
354 /* keep track of objects that have lois that contain pages which
355 * have been queued for async brw. this lock also protects the
356 * lists of osc_client_pages that hang off of the loi */
358 * ->cl_loi_list_lock protects consistency of
359 * ->cl_loi_{ready,read,write}_list. ->ap_make_ready() and
360 * ->ap_completion() call-backs are executed under this lock. As we
361 * cannot guarantee that these call-backs never block on all platforms
362 * (as a matter of fact they do block on Mac OS X), type of
363 * ->cl_loi_list_lock is platform dependent: it's a spin-lock on Linux
364 * and blocking mutex on Mac OS X. (Alternative is to make this lock
365 * blocking everywhere, but we don't want to slow down fast-path of
366 * our main platform.)
368 * Exact type of ->cl_loi_list_lock is defined in arch/obd.h together
369 * with client_obd_list_{un,}lock() and
370 * client_obd_list_lock_{init,done}() functions.
372 * NB by Jinshan: though field names are still _loi_, but actually
373 * osc_object{}s are in the list.
375 client_obd_lock_t cl_loi_list_lock;
376 cfs_list_t cl_loi_ready_list;
377 cfs_list_t cl_loi_hp_ready_list;
378 cfs_list_t cl_loi_write_list;
379 cfs_list_t cl_loi_read_list;
382 /* just a sum of the loi/lop pending numbers to be exported by /proc */
383 cfs_atomic_t cl_pending_w_pages;
384 cfs_atomic_t cl_pending_r_pages;
385 __u32 cl_max_pages_per_rpc;
386 int cl_max_rpcs_in_flight;
387 struct obd_histogram cl_read_rpc_hist;
388 struct obd_histogram cl_write_rpc_hist;
389 struct obd_histogram cl_read_page_hist;
390 struct obd_histogram cl_write_page_hist;
391 struct obd_histogram cl_read_offset_hist;
392 struct obd_histogram cl_write_offset_hist;
394 /* lru for osc caching pages */
395 struct cl_client_cache *cl_cache;
396 cfs_list_t cl_lru_osc; /* member of cl_cache->ccc_lru */
397 cfs_atomic_t *cl_lru_left;
398 cfs_atomic_t cl_lru_busy;
399 cfs_atomic_t cl_lru_shrinkers;
400 cfs_atomic_t cl_lru_in_list;
401 cfs_list_t cl_lru_list; /* lru page list */
402 client_obd_lock_t cl_lru_list_lock; /* page list protector */
404 /* number of in flight destroy rpcs is limited to max_rpcs_in_flight */
405 cfs_atomic_t cl_destroy_in_flight;
406 cfs_waitq_t cl_destroy_waitq;
408 struct mdc_rpc_lock *cl_rpc_lock;
409 struct mdc_rpc_lock *cl_close_lock;
412 struct semaphore cl_mgc_sem;
413 struct vfsmount *cl_mgc_vfsmnt;
414 struct dentry *cl_mgc_configs_dir;
415 cfs_atomic_t cl_mgc_refcount;
416 struct obd_export *cl_mgc_mgsexp;
418 /* checksumming for data sent over the network */
419 unsigned int cl_checksum:1; /* 0 = disabled, 1 = enabled */
420 /* supported checksum types that are worked out at connect time */
421 __u32 cl_supp_cksum_types;
422 /* checksum algorithm to be used */
423 cksum_type_t cl_cksum_type;
425 /* also protected by the poorly named _loi_list_lock lock above */
426 struct osc_async_rc cl_ar;
428 /* used by quotacheck when the servers are older than 2.4 */
429 int cl_qchk_stat; /* quotacheck stat of the peer */
430 #define CL_NOT_QUOTACHECKED 1 /* client->cl_qchk_stat init value */
431 #if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 7, 50, 0)
432 #warning "please consider removing quotacheck compatibility code"
435 /* sequence manager */
436 struct lu_client_seq *cl_seq;
438 cfs_atomic_t cl_resends; /* resend count */
440 /* ptlrpc work for writeback in ptlrpcd context */
441 void *cl_writeback_work;
442 /* hash tables for osc_quota_info */
443 cfs_hash_t *cl_quota_hash[MAXQUOTAS];
445 #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
452 struct echo_client_obd {
453 struct obd_export *ec_exp; /* the local connection to osc/lov */
455 cfs_list_t ec_objects;
462 struct obd_uuid lqo_uuid; /* ptlrpc's c_remote_uuid */
463 cfs_list_t lqo_oss_list; /* link to lov_qos */
464 __u64 lqo_bavail; /* total bytes avail on OSS */
465 __u64 lqo_penalty; /* current penalty */
466 __u64 lqo_penalty_per_obj;/* penalty decrease every obj*/
467 time_t lqo_used; /* last used time, seconds */
468 __u32 lqo_ost_count; /* number of osts on this oss */
472 struct lov_qos_oss *ltq_oss; /* oss info */
473 __u64 ltq_penalty; /* current penalty */
474 __u64 ltq_penalty_per_obj; /* penalty decrease every obj*/
475 __u64 ltq_weight; /* net weighting */
476 time_t ltq_used; /* last used time, seconds */
477 unsigned int ltq_usable:1; /* usable for striping */
480 /* Generic subset of OSTs */
482 __u32 *op_array; /* array of index of
484 unsigned int op_count; /* number of OSTs in the array */
485 unsigned int op_size; /* allocated size of lp_array */
486 struct rw_semaphore op_rw_sem; /* to protect ost_pool use */
489 /* Round-robin allocator data */
491 __u32 lqr_start_idx; /* start index of new inode */
492 __u32 lqr_offset_idx; /* aliasing for start_idx */
493 int lqr_start_count; /* reseed counter */
494 struct ost_pool lqr_pool; /* round-robin optimized list */
495 unsigned long lqr_dirty:1; /* recalc round-robin list */
498 /* allow statfs data caching for 1 second */
499 #define OBD_STATFS_CACHE_SECONDS 1
501 struct lov_statfs_data {
502 struct obd_info lsd_oi;
503 struct obd_statfs lsd_statfs;
505 /* Stripe placement optimization */
507 cfs_list_t lq_oss_list; /* list of OSSs that targets use */
508 struct rw_semaphore lq_rw_sem;
509 __u32 lq_active_oss_count;
510 unsigned int lq_prio_free; /* priority for free space */
511 unsigned int lq_threshold_rr;/* priority for rr */
512 struct lov_qos_rr lq_rr; /* round robin qos data */
513 unsigned long lq_dirty:1, /* recalc qos data */
514 lq_same_space:1,/* the ost's all have approx.
515 the same space avail */
516 lq_reset:1, /* zero current penalties */
517 lq_statfs_in_progress:1; /* statfs op in
519 /* qos statfs data */
520 struct lov_statfs_data *lq_statfs_data;
521 cfs_waitq_t lq_statfs_waitq; /* waitqueue to notify statfs
522 * requests completion */
525 struct lov_tgt_desc {
527 struct obd_uuid ltd_uuid;
528 struct obd_device *ltd_obd;
529 struct obd_export *ltd_exp;
530 struct ltd_qos ltd_qos; /* qos info per target */
532 __u32 ltd_index; /* index in lov_obd->tgts */
533 unsigned long ltd_active:1,/* is this target up for requests */
534 ltd_activate:1,/* should target be activated */
535 ltd_reap:1; /* should this target be deleted */
539 #define pool_tgt_size(_p) _p->pool_obds.op_size
540 #define pool_tgt_count(_p) _p->pool_obds.op_count
541 #define pool_tgt_array(_p) _p->pool_obds.op_array
542 #define pool_tgt_rw_sem(_p) _p->pool_obds.op_rw_sem
545 char pool_name[LOV_MAXPOOLNAME + 1]; /* name of pool */
546 struct ost_pool pool_obds; /* pool members */
547 cfs_atomic_t pool_refcount; /* pool ref. counter */
548 struct lov_qos_rr pool_rr; /* round robin qos */
549 cfs_hlist_node_t pool_hash; /* access by poolname */
550 cfs_list_t pool_list; /* serial access */
551 cfs_proc_dir_entry_t *pool_proc_entry; /* file in /proc */
552 struct obd_device *pool_lobd; /* obd of the lov/lod to which
553 * this pool belongs */
557 struct lov_desc desc;
558 struct lov_tgt_desc **lov_tgts; /* sparse array */
559 struct ost_pool lov_packed; /* all OSTs in a packed
561 struct mutex lov_lock;
562 struct obd_connect_data lov_ocd;
563 cfs_atomic_t lov_refcount;
564 __u32 lov_tgt_count; /* how many OBD's */
565 __u32 lov_active_tgt_count; /* how many active */
566 __u32 lov_death_row;/* tgts scheduled to be deleted */
567 __u32 lov_tgt_size; /* size of tgts array */
570 cfs_hash_t *lov_pools_hash_body; /* used for key access */
571 cfs_list_t lov_pool_list; /* used for sequential access */
572 cfs_proc_dir_entry_t *lov_pool_proc_entry;
573 enum lustre_sec_part lov_sp_me;
575 /* Cached LRU pages from upper layer */
578 struct rw_semaphore lov_notify_lock;
581 struct lmv_tgt_desc {
582 struct obd_uuid ltd_uuid;
583 struct obd_export *ltd_exp;
585 struct mutex ltd_fid_mutex;
586 unsigned long ltd_active:1; /* target up for requests */
589 enum placement_policy {
590 PLACEMENT_CHAR_POLICY = 0,
591 PLACEMENT_NID_POLICY = 1,
592 PLACEMENT_INVAL_POLICY = 2,
596 typedef enum placement_policy placement_policy_t;
600 struct lu_client_fld lmv_fld;
602 placement_policy_t lmv_placement;
603 struct lmv_desc desc;
604 struct obd_uuid cluuid;
605 struct obd_export *exp;
607 struct mutex init_mutex;
614 int tgts_size; /* size of tgts array */
615 struct lmv_tgt_desc **tgts;
617 struct obd_connect_data conn_data;
620 struct niobuf_local {
621 __u64 lnb_file_offset;
622 __u32 lnb_page_offset;
626 struct dentry *dentry;
631 #define LUSTRE_FLD_NAME "fld"
632 #define LUSTRE_SEQ_NAME "seq"
634 #define LUSTRE_MDD_NAME "mdd"
635 #define LUSTRE_OSD_LDISKFS_NAME "osd-ldiskfs"
636 #define LUSTRE_OSD_ZFS_NAME "osd-zfs"
637 #define LUSTRE_VVP_NAME "vvp"
638 #define LUSTRE_LMV_NAME "lmv"
639 #define LUSTRE_SLP_NAME "slp"
640 #define LUSTRE_LOD_NAME "lod"
641 #define LUSTRE_OSP_NAME "osp"
642 #define LUSTRE_LWP_NAME "lwp"
644 /* obd device type names */
645 /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */
646 #define LUSTRE_MDS_NAME "mds"
647 #define LUSTRE_MDT_NAME "mdt"
648 #define LUSTRE_MDC_NAME "mdc"
649 #define LUSTRE_OSS_NAME "ost" /* FIXME change name to oss */
650 #define LUSTRE_OST_NAME "obdfilter" /* FIXME change name to ost */
651 #define LUSTRE_OSC_NAME "osc"
652 #define LUSTRE_LOV_NAME "lov"
653 #define LUSTRE_MGS_NAME "mgs"
654 #define LUSTRE_MGC_NAME "mgc"
656 #define LUSTRE_ECHO_NAME "obdecho"
657 #define LUSTRE_ECHO_CLIENT_NAME "echo_client"
658 #define LUSTRE_QMT_NAME "qmt"
660 /* Constant obd names (post-rename) */
661 #define LUSTRE_MDS_OBDNAME "MDS"
662 #define LUSTRE_OSS_OBDNAME "OSS"
663 #define LUSTRE_MGS_OBDNAME "MGS"
664 #define LUSTRE_MGC_OBDNAME "MGC"
666 static inline int is_osp_on_mdt(char *name)
670 ptr = strrchr(name, '-');
672 CERROR("%s is not a obdname\n", name);
676 /* 1.8 OSC/OSP name on MDT is fsname-OSTxxxx-osc */
677 if (strncmp(ptr + 1, "osc", 3) == 0)
680 if (strncmp(ptr + 1, "MDT", 3) != 0)
683 while (*(--ptr) != '-' && ptr != name);
688 if (strncmp(ptr + 1, LUSTRE_OSP_NAME, strlen(LUSTRE_OSP_NAME)) != 0 &&
689 strncmp(ptr + 1, LUSTRE_OSC_NAME, strlen(LUSTRE_OSC_NAME)) != 0)
695 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
696 #define N_LOCAL_TEMP_PAGE 0x10000000
698 struct obd_trans_info {
701 /* Only used on the server side for tracking acks. */
702 struct oti_req_ack_lock {
703 struct lustre_handle lock;
707 struct llog_cookie oti_onecookie;
708 struct llog_cookie *oti_logcookies;
710 /** synchronous write is needed */
711 unsigned long oti_sync_write:1;
713 /* initial thread handling transaction */
714 struct ptlrpc_thread * oti_thread;
717 __u64 oti_pre_version;
721 struct obd_uuid *oti_ost_uuid;
724 static inline void oti_init(struct obd_trans_info *oti,
725 struct ptlrpc_request *req)
729 memset(oti, 0, sizeof(*oti));
734 oti->oti_xid = req->rq_xid;
735 /** VBR: take versions from request */
736 if (req->rq_reqmsg != NULL &&
737 lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
738 __u64 *pre_version = lustre_msg_get_versions(req->rq_reqmsg);
739 oti->oti_pre_version = pre_version ? pre_version[0] : 0;
740 oti->oti_transno = lustre_msg_get_transno(req->rq_reqmsg);
743 /** called from mds_create_objects */
744 if (req->rq_repmsg != NULL)
745 oti->oti_transno = lustre_msg_get_transno(req->rq_repmsg);
746 oti->oti_thread = req->rq_svc_thread;
747 if (req->rq_reqmsg != NULL)
748 oti->oti_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg);
751 static inline void oti_alloc_cookies(struct obd_trans_info *oti,int num_cookies)
756 if (num_cookies == 1)
757 oti->oti_logcookies = &oti->oti_onecookie;
759 OBD_ALLOC_LARGE(oti->oti_logcookies,
760 num_cookies * sizeof(oti->oti_onecookie));
762 oti->oti_numcookies = num_cookies;
765 static inline void oti_free_cookies(struct obd_trans_info *oti)
767 if (!oti || !oti->oti_logcookies)
770 if (oti->oti_logcookies == &oti->oti_onecookie)
771 LASSERT(oti->oti_numcookies == 1);
773 OBD_FREE_LARGE(oti->oti_logcookies,
774 oti->oti_numcookies*sizeof(oti->oti_onecookie));
775 oti->oti_logcookies = NULL;
776 oti->oti_numcookies = 0;
780 * Events signalled through obd_notify() upcall-chain.
782 enum obd_notify_event {
785 /* Device connect start */
787 /* Device activated */
789 /* Device deactivated */
791 /* Device disconnected */
793 /* Connect data for import were changed */
796 OBD_NOTIFY_SYNC_NONBLOCK,
798 /* Configuration event */
800 /* Administratively deactivate/activate event */
801 OBD_NOTIFY_DEACTIVATE,
805 /* bit-mask flags for config events */
807 CONFIG_LOG = 0x1, /* finished processing config log */
808 CONFIG_SYNC = 0x2, /* mdt synced 1 ost */
809 CONFIG_TARGET = 0x4 /* one target is added */
813 * Data structure used to pass obd_notify()-event to non-obd listeners (llite
814 * and liblustre being main examples).
816 struct obd_notify_upcall {
817 int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
818 enum obd_notify_event ev, void *owner, void *data);
819 /* Opaque datum supplied by upper layer listener */
823 struct target_recovery_data {
824 svc_handler_t trd_recovery_handler;
825 pid_t trd_processing_task;
826 struct completion trd_starting;
827 struct completion trd_finishing;
830 struct obd_llog_group {
832 struct llog_ctxt *olg_ctxts[LLOG_MAX_CTXTS];
833 cfs_waitq_t olg_waitq;
835 struct mutex olg_cat_processing;
838 /* corresponds to one of the obd's */
839 #define OBD_DEVICE_MAGIC 0XAB5CD6EF
840 #define OBD_DEV_BY_DEVNAME 0xffffd0de
843 struct obd_type *obd_type;
846 /* common and UUID name of this device */
847 char obd_name[MAX_OBD_NAME];
848 struct obd_uuid obd_uuid;
850 struct lu_device *obd_lu_dev;
853 /* bitfield modification is protected by obd_dev_lock */
854 unsigned long obd_attached:1, /* finished attach */
855 obd_set_up:1, /* finished setup */
856 obd_recovering:1, /* there are recoverable clients */
857 obd_abort_recovery:1,/* recovery expired */
858 obd_version_recov:1, /* obd uses version checking */
859 obd_replayable:1, /* recovery is enabled; inform clients */
860 obd_no_transno:1, /* no committed-transno notification */
861 obd_no_recov:1, /* fail instead of retry messages */
862 obd_stopping:1, /* started cleanup */
863 obd_starting:1, /* started setup */
864 obd_force:1, /* cleanup with > 0 obd refcount */
865 obd_fail:1, /* cleanup with failover */
866 obd_async_recov:1, /* allow asynchronous orphan cleanup */
867 obd_no_conn:1, /* deny new connections */
868 obd_inactive:1, /* device active/inactive
869 * (for /proc/status only!!) */
870 obd_no_ir:1, /* no imperative recovery. */
871 obd_process_conf:1; /* device is processing mgs config */
872 /* use separate field as it is set in interrupt to don't mess with
873 * protection of other bits using _bh lock */
874 unsigned long obd_recovery_expired:1;
875 /* uuid-export hash body */
876 cfs_hash_t *obd_uuid_hash;
877 /* nid-export hash body */
878 cfs_hash_t *obd_nid_hash;
880 cfs_hash_t *obd_nid_stats_hash;
881 cfs_list_t obd_nid_stats;
882 cfs_atomic_t obd_refcount;
883 cfs_waitq_t obd_refcount_waitq;
884 cfs_list_t obd_exports;
885 cfs_list_t obd_unlinked_exports;
886 cfs_list_t obd_delayed_exports;
888 spinlock_t obd_nid_lock;
889 struct ldlm_namespace *obd_namespace;
890 struct ptlrpc_client obd_ldlm_client; /* XXX OST/MDS only */
891 /* a spinlock is OK for what we do now, may need a semaphore later */
892 spinlock_t obd_dev_lock; /* protect OBD bitfield above */
893 struct mutex obd_dev_mutex;
894 __u64 obd_last_committed;
895 struct fsfilt_operations *obd_fsops;
896 spinlock_t obd_osfs_lock;
897 struct obd_statfs obd_osfs; /* locked by obd_osfs_lock */
899 struct lvfs_run_ctxt obd_lvfs_ctxt;
900 struct obd_llog_group obd_olg; /* default llog group */
901 struct obd_device *obd_observer;
902 struct rw_semaphore obd_observer_link_sem;
903 struct obd_notify_upcall obd_upcall;
904 struct obd_export *obd_self_export;
905 /* list of exports in LRU order, for ping evictor, with obd_dev_lock */
906 cfs_list_t obd_exports_timed;
907 time_t obd_eviction_timer; /* for ping evictor */
909 int obd_max_recoverable_clients;
910 cfs_atomic_t obd_connected_clients;
911 int obd_stale_clients;
912 int obd_delayed_clients;
913 /* this lock protects all recovery list_heads, timer and
914 * obd_next_recovery_transno value */
915 spinlock_t obd_recovery_task_lock;
916 __u64 obd_next_recovery_transno;
917 int obd_replayed_requests;
918 int obd_requests_queued_for_recovery;
919 cfs_waitq_t obd_next_transno_waitq;
920 /* protected by obd_recovery_task_lock */
921 cfs_timer_t obd_recovery_timer;
922 time_t obd_recovery_start; /* seconds */
923 time_t obd_recovery_end; /* seconds, for lprocfs_status */
924 int obd_recovery_time_hard;
925 int obd_recovery_timeout;
926 int obd_recovery_ir_factor;
928 /* new recovery stuff from CMD2 */
929 struct target_recovery_data obd_recovery_data;
930 int obd_replayed_locks;
931 cfs_atomic_t obd_req_replay_clients;
932 cfs_atomic_t obd_lock_replay_clients;
933 /* all lists are protected by obd_recovery_task_lock */
934 cfs_list_t obd_req_replay_queue;
935 cfs_list_t obd_lock_replay_queue;
936 cfs_list_t obd_final_req_queue;
937 int obd_recovery_stage;
940 #ifdef HAVE_SERVER_SUPPORT
941 struct obd_device_target obt;
942 struct filter_obd filter;
944 struct echo_obd echo;
946 struct client_obd cli;
947 struct echo_client_obd echo_client;
951 /* Fields used by LProcFS */
952 unsigned int obd_cntr_base;
953 struct lprocfs_stats *obd_stats;
955 unsigned int md_cntr_base;
956 struct lprocfs_stats *md_stats;
958 cfs_proc_dir_entry_t *obd_proc_entry;
959 cfs_proc_dir_entry_t *obd_proc_exports_entry;
960 cfs_proc_dir_entry_t *obd_svc_procroot;
961 struct lprocfs_stats *obd_svc_stats;
962 cfs_atomic_t obd_evict_inprogress;
963 cfs_waitq_t obd_evict_inprogress_waitq;
964 cfs_list_t obd_evict_list; /* protected with pet_lock */
967 * Ldlm pool part. Save last calculated SLV and Limit.
969 rwlock_t obd_pool_lock;
974 * A list of outstanding class_incref()'s against this obd. For
977 struct lu_ref obd_reference;
979 int obd_conn_inprogress;
982 #define OBD_LLOG_FL_SENDNOW 0x0001
983 #define OBD_LLOG_FL_EXIT 0x0002
985 enum obd_cleanup_stage {
986 /* Special case hack for MDS LOVs */
988 /* can be directly mapped to .ldto_device_fini() */
992 /* get/set_info keys */
993 #define KEY_ASYNC "async"
994 #define KEY_BLOCKSIZE_BITS "blocksize_bits"
995 #define KEY_BLOCKSIZE "blocksize"
996 #define KEY_CAPA_KEY "capa_key"
997 #define KEY_CHANGELOG_CLEAR "changelog_clear"
998 #define KEY_FID2PATH "fid2path"
999 #define KEY_CHECKSUM "checksum"
1000 #define KEY_CLEAR_FS "clear_fs"
1001 #define KEY_CONN_DATA "conn_data"
1002 #define KEY_EVICT_BY_NID "evict_by_nid"
1003 #define KEY_FIEMAP "fiemap"
1004 #define KEY_FLUSH_CTX "flush_ctx"
1005 #define KEY_GRANT_SHRINK "grant_shrink"
1006 #define KEY_HSM_COPYTOOL_SEND "hsm_send"
1007 #define KEY_INIT_RECOV_BACKUP "init_recov_bk"
1008 #define KEY_INIT_RECOV "initial_recov"
1009 #define KEY_INTERMDS "inter_mds"
1010 #define KEY_LAST_ID "last_id"
1011 #define KEY_LAST_FID "last_fid"
1012 #define KEY_LOCK_TO_STRIPE "lock_to_stripe"
1013 #define KEY_LOVDESC "lovdesc"
1014 #define KEY_LOV_IDX "lov_idx"
1015 #define KEY_MAX_EASIZE "max_easize"
1016 #define KEY_MDS_CONN "mds_conn"
1017 #define KEY_MGSSEC "mgssec"
1018 #define KEY_NEXT_ID "next_id"
1019 #define KEY_READ_ONLY "read-only"
1020 #define KEY_REGISTER_TARGET "register_target"
1021 #define KEY_SET_FS "set_fs"
1022 #define KEY_TGT_COUNT "tgt_count"
1023 /* KEY_SET_INFO in lustre_idl.h */
1024 #define KEY_SPTLRPC_CONF "sptlrpc_conf"
1025 #define KEY_CONNECT_FLAG "connect_flags"
1026 #define KEY_SYNC_LOCK_CANCEL "sync_lock_cancel"
1028 #define KEY_CACHE_SET "cache_set"
1029 #define KEY_CACHE_LRU_SHRINK "cache_lru_shrink"
1030 #define KEY_CHANGELOG_INDEX "changelog_index"
1034 /* /!\ must be coherent with include/linux/namei.h on patched kernel */
1035 #define IT_OPEN (1 << 0)
1036 #define IT_CREAT (1 << 1)
1037 #define IT_READDIR (1 << 2)
1038 #define IT_GETATTR (1 << 3)
1039 #define IT_LOOKUP (1 << 4)
1040 #define IT_UNLINK (1 << 5)
1041 #define IT_TRUNC (1 << 6)
1042 #define IT_GETXATTR (1 << 7)
1043 #define IT_EXEC (1 << 8)
1044 #define IT_PIN (1 << 9)
1045 #define IT_LAYOUT (1 << 10)
1046 #define IT_QUOTA_DQACQ (1 << 11)
1047 #define IT_QUOTA_CONN (1 << 12)
1049 static inline int it_to_lock_mode(struct lookup_intent *it)
1051 /* CREAT needs to be tested before open (both could be set) */
1052 if (it->it_op & IT_CREAT)
1054 else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_LOOKUP |
1058 LASSERTF(0, "Invalid it_op: %d\n", it->it_op);
1063 struct lu_fid op_fid1; /* operation fid1 (usualy parent) */
1064 struct lu_fid op_fid2; /* operation fid2 (usualy child) */
1065 struct lu_fid op_fid3; /* 2 extra fids to find conflicting */
1066 struct lu_fid op_fid4; /* to the operation locks. */
1067 mdsno_t op_mds; /* what mds server open will go to */
1068 struct lustre_handle op_handle;
1069 obd_time op_mod_time;
1070 const char *op_name;
1073 struct lmv_stripe_md *op_mea1;
1074 struct lmv_stripe_md *op_mea2;
1075 __u32 op_suppgids[2];
1081 /* iattr fields and blocks. */
1082 struct iattr op_attr;
1084 unsigned int op_attr_flags;
1087 loff_t op_attr_blocks;
1089 /* Size-on-MDS epoch and flags. */
1094 struct obd_capa *op_capa1;
1095 struct obd_capa *op_capa2;
1097 /* Various operation flags. */
1100 /* Operation type */
1103 /* Used by readdir */
1106 /* Used by readdir */
1109 /* used to transfer info between the stacks of MD client
1110 * see enum op_cli_flags */
1115 CLI_SET_MEA = 1 << 0,
1116 CLI_RM_ENTRY = 1 << 1,
1119 struct md_enqueue_info;
1120 /* metadata stat-ahead */
1121 typedef int (* md_enqueue_cb_t)(struct ptlrpc_request *req,
1122 struct md_enqueue_info *minfo,
1125 struct md_enqueue_info {
1126 struct md_op_data mi_data;
1127 struct lookup_intent mi_it;
1128 struct lustre_handle mi_lockh;
1129 struct inode *mi_dir;
1130 md_enqueue_cb_t mi_cb;
1132 unsigned int mi_generation;
1136 cfs_module_t *o_owner;
1137 int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
1138 void *karg, void *uarg);
1139 int (*o_get_info)(const struct lu_env *env, struct obd_export *,
1140 __u32 keylen, void *key, __u32 *vallen, void *val,
1141 struct lov_stripe_md *lsm);
1142 int (*o_set_info_async)(const struct lu_env *, struct obd_export *,
1143 __u32 keylen, void *key,
1144 __u32 vallen, void *val,
1145 struct ptlrpc_request_set *set);
1146 int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
1147 int (*o_detach)(struct obd_device *dev);
1148 int (*o_setup) (struct obd_device *dev, struct lustre_cfg *cfg);
1149 int (*o_precleanup)(struct obd_device *dev,
1150 enum obd_cleanup_stage cleanup_stage);
1151 int (*o_cleanup)(struct obd_device *dev);
1152 int (*o_process_config)(struct obd_device *dev, obd_count len,
1154 int (*o_postrecov)(struct obd_device *dev);
1155 int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
1157 int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
1158 /* connect to the target device with given connection
1159 * data. @ocd->ocd_connect_flags is modified to reflect flags actually
1160 * granted by the target, which are guaranteed to be a subset of flags
1161 * asked for. If @ocd == NULL, use default parameters. */
1162 int (*o_connect)(const struct lu_env *env,
1163 struct obd_export **exp, struct obd_device *src,
1164 struct obd_uuid *cluuid, struct obd_connect_data *ocd,
1166 int (*o_reconnect)(const struct lu_env *env,
1167 struct obd_export *exp, struct obd_device *src,
1168 struct obd_uuid *cluuid,
1169 struct obd_connect_data *ocd,
1171 int (*o_disconnect)(struct obd_export *exp);
1173 /* Initialize/finalize fids infrastructure. */
1174 int (*o_fid_init)(struct obd_device *obd,
1175 struct obd_export *exp, enum lu_cli_type type);
1176 int (*o_fid_fini)(struct obd_device *obd);
1178 /* Allocate new fid according to passed @hint. */
1179 int (*o_fid_alloc)(struct obd_export *exp, struct lu_fid *fid,
1180 struct md_op_data *op_data);
1183 * Object with @fid is getting deleted, we may want to do something
1186 int (*o_statfs)(const struct lu_env *, struct obd_export *exp,
1187 struct obd_statfs *osfs, __u64 max_age, __u32 flags);
1188 int (*o_statfs_async)(struct obd_export *exp, struct obd_info *oinfo,
1189 __u64 max_age, struct ptlrpc_request_set *set);
1190 int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
1191 struct lov_stripe_md *mem_src);
1192 int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
1193 struct lov_mds_md *disk_src, int disk_len);
1194 int (*o_preallocate)(struct lustre_handle *, obd_count *req,
1196 /* FIXME: add fid capability support for create & destroy! */
1197 int (*o_precreate)(struct obd_export *exp);
1198 int (*o_create)(const struct lu_env *env, struct obd_export *exp,
1199 struct obdo *oa, struct lov_stripe_md **ea,
1200 struct obd_trans_info *oti);
1201 int (*o_create_async)(struct obd_export *exp, struct obd_info *oinfo,
1202 struct lov_stripe_md **ea,
1203 struct obd_trans_info *oti);
1204 int (*o_destroy)(const struct lu_env *env, struct obd_export *exp,
1205 struct obdo *oa, struct lov_stripe_md *ea,
1206 struct obd_trans_info *oti, struct obd_export *md_exp,
1208 int (*o_setattr)(const struct lu_env *, struct obd_export *exp,
1209 struct obd_info *oinfo, struct obd_trans_info *oti);
1210 int (*o_setattr_async)(struct obd_export *exp, struct obd_info *oinfo,
1211 struct obd_trans_info *oti,
1212 struct ptlrpc_request_set *rqset);
1213 int (*o_getattr)(const struct lu_env *env, struct obd_export *exp,
1214 struct obd_info *oinfo);
1215 int (*o_getattr_async)(struct obd_export *exp, struct obd_info *oinfo,
1216 struct ptlrpc_request_set *set);
1217 int (*o_brw)(int rw, struct obd_export *exp, struct obd_info *oinfo,
1218 obd_count oa_bufs, struct brw_page *pgarr,
1219 struct obd_trans_info *oti);
1220 int (*o_merge_lvb)(struct obd_export *exp, struct lov_stripe_md *lsm,
1221 struct ost_lvb *lvb, int kms_only);
1222 int (*o_adjust_kms)(struct obd_export *exp, struct lov_stripe_md *lsm,
1223 obd_off size, int shrink);
1224 int (*o_punch)(const struct lu_env *, struct obd_export *exp,
1225 struct obd_info *oinfo, struct obd_trans_info *oti,
1226 struct ptlrpc_request_set *rqset);
1227 int (*o_sync)(const struct lu_env *env, struct obd_export *exp,
1228 struct obd_info *oinfo, obd_size start, obd_size end,
1229 struct ptlrpc_request_set *set);
1230 int (*o_migrate)(struct lustre_handle *conn, struct lov_stripe_md *dst,
1231 struct lov_stripe_md *src, obd_size start,
1232 obd_size end, struct obd_trans_info *oti);
1233 int (*o_copy)(struct lustre_handle *dstconn, struct lov_stripe_md *dst,
1234 struct lustre_handle *srconn, struct lov_stripe_md *src,
1235 obd_size start, obd_size end, struct obd_trans_info *);
1236 int (*o_iterate)(struct lustre_handle *conn,
1237 int (*)(obd_id, obd_seq, void *),
1238 obd_id *startid, obd_seq seq, void *data);
1239 int (*o_preprw)(const struct lu_env *env, int cmd,
1240 struct obd_export *exp, struct obdo *oa, int objcount,
1241 struct obd_ioobj *obj, struct niobuf_remote *remote,
1242 int *nr_pages, struct niobuf_local *local,
1243 struct obd_trans_info *oti, struct lustre_capa *capa);
1244 int (*o_commitrw)(const struct lu_env *env, int cmd,
1245 struct obd_export *exp, struct obdo *oa,
1246 int objcount, struct obd_ioobj *obj,
1247 struct niobuf_remote *remote, int pages,
1248 struct niobuf_local *local,
1249 struct obd_trans_info *oti, int rc);
1250 int (*o_enqueue)(struct obd_export *, struct obd_info *oinfo,
1251 struct ldlm_enqueue_info *einfo,
1252 struct ptlrpc_request_set *rqset);
1253 int (*o_change_cbdata)(struct obd_export *, struct lov_stripe_md *,
1254 ldlm_iterator_t it, void *data);
1255 int (*o_find_cbdata)(struct obd_export *, struct lov_stripe_md *,
1256 ldlm_iterator_t it, void *data);
1257 int (*o_cancel)(struct obd_export *, struct lov_stripe_md *md,
1258 __u32 mode, struct lustre_handle *);
1259 int (*o_cancel_unused)(struct obd_export *, struct lov_stripe_md *,
1260 ldlm_cancel_flags_t flags, void *opaque);
1261 int (*o_init_export)(struct obd_export *exp);
1262 int (*o_destroy_export)(struct obd_export *exp);
1263 int (*o_extent_calc)(struct obd_export *, struct lov_stripe_md *,
1264 int cmd, obd_off *);
1266 /* llog related obd_methods */
1267 int (*o_llog_init)(struct obd_device *obd, struct obd_llog_group *grp,
1268 struct obd_device *disk_obd, int *idx);
1269 int (*o_llog_finish)(struct obd_device *obd, int count);
1270 int (*o_llog_connect)(struct obd_export *, struct llogd_conn_body *);
1272 /* metadata-only methods */
1273 int (*o_pin)(struct obd_export *, const struct lu_fid *fid,
1274 struct obd_capa *, struct obd_client_handle *, int flag);
1275 int (*o_unpin)(struct obd_export *, struct obd_client_handle *, int);
1277 int (*o_import_event)(struct obd_device *, struct obd_import *,
1278 enum obd_import_event);
1280 int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
1281 enum obd_notify_event ev, void *data);
1283 int (*o_health_check)(const struct lu_env *env, struct obd_device *);
1284 struct obd_uuid *(*o_get_uuid) (struct obd_export *exp);
1287 int (*o_quotacheck)(struct obd_device *, struct obd_export *,
1288 struct obd_quotactl *);
1289 int (*o_quotactl)(struct obd_device *, struct obd_export *,
1290 struct obd_quotactl *);
1292 int (*o_ping)(const struct lu_env *, struct obd_export *exp);
1295 int (*o_pool_new)(struct obd_device *obd, char *poolname);
1296 int (*o_pool_del)(struct obd_device *obd, char *poolname);
1297 int (*o_pool_add)(struct obd_device *obd, char *poolname,
1299 int (*o_pool_rem)(struct obd_device *obd, char *poolname,
1301 void (*o_getref)(struct obd_device *obd);
1302 void (*o_putref)(struct obd_device *obd);
1304 * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
1305 * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
1306 * Also, add a wrapper function in include/linux/obd_class.h. */
1310 LUSTRE_OPC_MKDIR = (1 << 0),
1311 LUSTRE_OPC_SYMLINK = (1 << 1),
1312 LUSTRE_OPC_MKNOD = (1 << 2),
1313 LUSTRE_OPC_CREATE = (1 << 3),
1314 LUSTRE_OPC_ANY = (1 << 4)
1317 /* lmv structures */
1318 #define MEA_MAGIC_LAST_CHAR 0xb2221ca1
1319 #define MEA_MAGIC_ALL_CHARS 0xb222a11c
1320 #define MEA_MAGIC_HASH_SEGMENT 0xb222a11b
1322 #define MAX_HASH_SIZE_32 0x7fffffffUL
1323 #define MAX_HASH_SIZE 0x7fffffffffffffffULL
1324 #define MAX_HASH_HIGHEST_BIT 0x1000000000000000ULL
1327 struct mdt_body *body;
1328 struct lov_stripe_md *lsm;
1329 struct lmv_stripe_md *mea;
1330 #ifdef CONFIG_FS_POSIX_ACL
1331 struct posix_acl *posix_acl;
1333 struct mdt_remote_perm *remote_perm;
1334 struct obd_capa *mds_capa;
1335 struct obd_capa *oss_capa;
1338 struct md_open_data {
1339 struct obd_client_handle *mod_och;
1340 struct ptlrpc_request *mod_open_req;
1341 struct ptlrpc_request *mod_close_req;
1342 cfs_atomic_t mod_refcount;
1345 struct lookup_intent;
1348 int (*m_getstatus)(struct obd_export *, struct lu_fid *,
1349 struct obd_capa **);
1350 int (*m_null_inode)(struct obd_export *, const struct lu_fid *);
1351 int (*m_find_cbdata)(struct obd_export *, const struct lu_fid *,
1352 ldlm_iterator_t, void *);
1353 int (*m_close)(struct obd_export *, struct md_op_data *,
1354 struct md_open_data *, struct ptlrpc_request **);
1355 int (*m_create)(struct obd_export *, struct md_op_data *,
1356 const void *, int, int, __u32, __u32, cfs_cap_t,
1357 __u64, struct ptlrpc_request **);
1358 int (*m_done_writing)(struct obd_export *, struct md_op_data *,
1359 struct md_open_data *);
1360 int (*m_enqueue)(struct obd_export *, struct ldlm_enqueue_info *,
1361 struct lookup_intent *, struct md_op_data *,
1362 struct lustre_handle *, void *, int,
1363 struct ptlrpc_request **, __u64);
1364 int (*m_getattr)(struct obd_export *, struct md_op_data *,
1365 struct ptlrpc_request **);
1366 int (*m_getattr_name)(struct obd_export *, struct md_op_data *,
1367 struct ptlrpc_request **);
1368 int (*m_intent_lock)(struct obd_export *, struct md_op_data *,
1369 void *, int, struct lookup_intent *, int,
1370 struct ptlrpc_request **,
1371 ldlm_blocking_callback, __u64);
1372 int (*m_link)(struct obd_export *, struct md_op_data *,
1373 struct ptlrpc_request **);
1374 int (*m_rename)(struct obd_export *, struct md_op_data *,
1375 const char *, int, const char *, int,
1376 struct ptlrpc_request **);
1377 int (*m_is_subdir)(struct obd_export *, const struct lu_fid *,
1378 const struct lu_fid *,
1379 struct ptlrpc_request **);
1380 int (*m_setattr)(struct obd_export *, struct md_op_data *, void *,
1381 int , void *, int, struct ptlrpc_request **,
1382 struct md_open_data **mod);
1383 int (*m_sync)(struct obd_export *, const struct lu_fid *,
1384 struct obd_capa *, struct ptlrpc_request **);
1385 int (*m_readpage)(struct obd_export *, struct md_op_data *,
1386 struct page **, struct ptlrpc_request **);
1388 int (*m_unlink)(struct obd_export *, struct md_op_data *,
1389 struct ptlrpc_request **);
1391 int (*m_setxattr)(struct obd_export *, const struct lu_fid *,
1392 struct obd_capa *, obd_valid, const char *,
1393 const char *, int, int, int, __u32,
1394 struct ptlrpc_request **);
1396 int (*m_getxattr)(struct obd_export *, const struct lu_fid *,
1397 struct obd_capa *, obd_valid, const char *,
1398 const char *, int, int, int,
1399 struct ptlrpc_request **);
1401 int (*m_init_ea_size)(struct obd_export *, int, int, int);
1403 int (*m_get_lustre_md)(struct obd_export *, struct ptlrpc_request *,
1404 struct obd_export *, struct obd_export *,
1405 struct lustre_md *);
1407 int (*m_free_lustre_md)(struct obd_export *, struct lustre_md *);
1409 int (*m_set_open_replay_data)(struct obd_export *,
1410 struct obd_client_handle *,
1411 struct ptlrpc_request *);
1412 int (*m_clear_open_replay_data)(struct obd_export *,
1413 struct obd_client_handle *);
1414 int (*m_set_lock_data)(struct obd_export *, __u64 *, void *, __u64 *);
1416 ldlm_mode_t (*m_lock_match)(struct obd_export *, __u64,
1417 const struct lu_fid *, ldlm_type_t,
1418 ldlm_policy_data_t *, ldlm_mode_t,
1419 struct lustre_handle *);
1421 int (*m_cancel_unused)(struct obd_export *, const struct lu_fid *,
1422 ldlm_policy_data_t *, ldlm_mode_t,
1423 ldlm_cancel_flags_t flags, void *opaque);
1424 int (*m_renew_capa)(struct obd_export *, struct obd_capa *oc,
1425 renew_capa_cb_t cb);
1426 int (*m_unpack_capa)(struct obd_export *, struct ptlrpc_request *,
1427 const struct req_msg_field *, struct obd_capa **);
1429 int (*m_get_remote_perm)(struct obd_export *, const struct lu_fid *,
1430 struct obd_capa *, __u32,
1431 struct ptlrpc_request **);
1433 int (*m_intent_getattr_async)(struct obd_export *,
1434 struct md_enqueue_info *,
1435 struct ldlm_enqueue_info *);
1437 int (*m_revalidate_lock)(struct obd_export *, struct lookup_intent *,
1438 struct lu_fid *, __u64 *bits);
1441 * NOTE: If adding ops, add another LPROCFS_MD_OP_INIT() line to
1442 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
1443 * wrapper function in include/linux/obd_class.h.
1447 struct lsm_operations {
1448 void (*lsm_free)(struct lov_stripe_md *);
1449 int (*lsm_destroy)(struct lov_stripe_md *, struct obdo *oa,
1450 struct obd_export *md_exp);
1451 void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *, obd_off *,
1453 void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *, obd_off *,
1455 int (*lsm_lmm_verify) (struct lov_mds_md *lmm, int lmm_bytes,
1456 __u16 *stripe_count);
1457 int (*lsm_unpackmd) (struct lov_obd *lov, struct lov_stripe_md *lsm,
1458 struct lov_mds_md *lmm);
1461 extern const struct lsm_operations lsm_v1_ops;
1462 extern const struct lsm_operations lsm_v3_ops;
1463 static inline const struct lsm_operations *lsm_op_find(int magic)
1471 CERROR("Cannot recognize lsm_magic %08x\n", magic);
1476 /* Requests for obd_extent_calc() */
1477 #define OBD_CALC_STRIPE_START 1
1478 #define OBD_CALC_STRIPE_END 2
1480 static inline struct lustre_capa *oinfo_capa(struct obd_info *oinfo)
1482 return oinfo->oi_capa;
1485 static inline struct md_open_data *obd_mod_alloc(void)
1487 struct md_open_data *mod;
1491 cfs_atomic_set(&mod->mod_refcount, 1);
1495 #define obd_mod_get(mod) cfs_atomic_inc(&(mod)->mod_refcount)
1496 #define obd_mod_put(mod) \
1498 if (cfs_atomic_dec_and_test(&(mod)->mod_refcount)) { \
1499 if ((mod)->mod_open_req) \
1500 ptlrpc_req_finished((mod)->mod_open_req); \
1501 OBD_FREE_PTR(mod); \
1505 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
1506 void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent);
1508 /* return 1 if client should be resend request */
1509 static inline int client_should_resend(int resend, struct client_obd *cli)
1511 return cfs_atomic_read(&cli->cl_resends) ?
1512 cfs_atomic_read(&cli->cl_resends) > resend : 1;
1516 * Return device name for this device
1518 * XXX: lu_device is declared before obd_device, while a pointer pointing
1519 * back to obd_device in lu_device, so this helper function defines here
1520 * instead of in lu_object.h
1522 static inline const char *lu_dev_name(const struct lu_device *lu_dev)
1524 return lu_dev->ld_obd->obd_name;
1527 static inline bool filename_is_volatile(const char *name, int namelen, int *idx)
1532 if (strncmp(name, LUSTRE_VOLATILE_HDR, LUSTRE_VOLATILE_HDR_LEN) != 0)
1535 /* caller does not care of idx */
1539 /* volatile file, the MDT can be set from name */
1540 /* name format is LUSTRE_VOLATILE_HDR:[idx]: */
1541 /* if no MDT is specified, use std way */
1542 if (namelen < LUSTRE_VOLATILE_HDR_LEN + 2)
1544 /* test for no MDT idx case */
1545 if ((*(name + LUSTRE_VOLATILE_HDR_LEN) == ':') &&
1546 (*(name + LUSTRE_VOLATILE_HDR_LEN + 1) == ':')) {
1550 /* we have an idx, read it */
1551 start = name + LUSTRE_VOLATILE_HDR_LEN + 1;
1552 *idx = strtoul(start, &end, 0);
1554 * no digit, no trailing :, negative value
1556 if (((*idx == 0) && (end == start)) ||
1557 (*end != ':') || (*idx < 0))
1562 /* bad format of mdt idx, we cannot return an error
1563 * to caller so we use hash algo */
1564 CERROR("Bad volatile file name format: %s\n",
1565 name + LUSTRE_VOLATILE_HDR_LEN);
1569 static inline int cli_brw_size(struct obd_device *obd)
1571 LASSERT(obd != NULL);
1572 return obd->u.cli.cl_max_pages_per_rpc << PAGE_CACHE_SHIFT;
1575 #endif /* __OBD_H */