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 #include <linux/obd.h>
42 #include <lustre/lustre_idl.h>
43 #include <lustre_lib.h>
44 #include <libcfs/bitmap.h>
45 #ifdef HAVE_SERVER_SUPPORT
46 # include <lu_target.h>
47 # include <obd_target.h>
50 #include <lustre_export.h>
51 #include <lustre_fid.h>
52 #include <lustre_fld.h>
53 #include <lustre_intent.h>
54 #include <lustre_capa.h>
57 #define MAX_OBD_DEVICES 8192
65 struct lov_oinfo { /* per-stripe data structure */
66 struct ost_id loi_oi; /* object ID/Sequence on the target OST */
67 int loi_ost_idx; /* OST stripe index in lov_tgt_desc->tgts */
68 int loi_ost_gen; /* generation of this loi_ost_idx */
70 unsigned long loi_kms_valid:1;
71 __u64 loi_kms; /* known minimum size */
72 struct ost_lvb loi_lvb;
73 struct osc_async_rc loi_ar;
76 static inline void loi_kms_set(struct lov_oinfo *oinfo, __u64 kms)
79 oinfo->loi_kms_valid = 1;
82 static inline void loi_init(struct lov_oinfo *loi)
86 struct lov_stripe_md {
89 pid_t lsm_lock_owner; /* debugging */
91 /* maximum possible file size, might change as OSTs status changes,
92 * e.g. disconnected, deactivated */
96 struct ost_id lw_object_oi; /* lov object id/seq */
98 /* LOV-private members start here -- only for use in lov/. */
100 __u32 lw_stripe_size; /* size of the stripe */
101 __u32 lw_pattern; /* striping pattern (RAID0, RAID1) */
102 __u16 lw_stripe_count; /* number of objects being striped over */
103 __u16 lw_layout_gen; /* generation of the layout */
104 char lw_pool_name[LOV_MAXPOOLNAME]; /* pool name */
107 struct lov_oinfo *lsm_oinfo[0];
110 #define lsm_oi lsm_wire.lw_object_oi
111 #define lsm_magic lsm_wire.lw_magic
112 #define lsm_layout_gen lsm_wire.lw_layout_gen
113 #define lsm_stripe_size lsm_wire.lw_stripe_size
114 #define lsm_pattern lsm_wire.lw_pattern
115 #define lsm_stripe_count lsm_wire.lw_stripe_count
116 #define lsm_pool_name lsm_wire.lw_pool_name
118 static inline bool lsm_is_released(struct lov_stripe_md *lsm)
120 return !!(lsm->lsm_pattern & LOV_PATTERN_F_RELEASED);
123 static inline bool lsm_has_objects(struct lov_stripe_md *lsm)
127 if (lsm_is_released(lsm))
132 static inline int lov_stripe_md_size(unsigned int stripe_count)
134 struct lov_stripe_md lsm;
136 return sizeof(lsm) + stripe_count * sizeof(lsm.lsm_oinfo[0]);
141 typedef int (*obd_enqueue_update_f)(void *cookie, int rc);
143 /* obd info for a particular level (lov, osc). */
145 /* Lock policy. It keeps an extent which is specific for a particular
146 * OSC. (e.g. lov_prep_enqueue_set initialises extent of the policy,
147 * and osc_enqueue passes it into ldlm_lock_match & ldlm_cli_enqueue. */
148 ldlm_policy_data_t oi_policy;
149 /* Flags used for set request specific flags:
150 - while lock handling, the flags obtained on the enqueue
151 request are set here.
152 - while stats, the flags used for control delay/resend.
153 - while setattr, the flags used for distinguish punch operation
156 /* lsm data specific for every OSC. */
157 struct lov_stripe_md *oi_md;
158 /* obdo data specific for every OSC, if needed at all. */
160 /* statfs data specific for every OSC, if needed at all. */
161 struct obd_statfs *oi_osfs;
162 /* An update callback which is called to update some data on upper
163 * level. E.g. it is used for update lsm->lsm_oinfo at every recieved
164 * request in osc level for enqueue requests. It is also possible to
165 * update some caller data from LOV layer if needed. */
166 obd_enqueue_update_f oi_cb_up;
167 /* oss capability, its type is obd_capa in client to avoid copy.
168 * in contrary its type is lustre_capa in OSS. */
173 struct list_head typ_chain;
174 struct obd_ops *typ_dt_ops;
175 struct md_ops *typ_md_ops;
176 struct proc_dir_entry *typ_procroot;
177 struct proc_dir_entry *typ_procsym;
178 __u32 typ_sym_filter;
181 struct lu_device_type *typ_lu;
182 spinlock_t obd_type_lock;
192 struct timeout_item {
193 enum timeout_event ti_event;
194 cfs_time_t ti_timeout;
197 struct list_head ti_obd_list;
198 struct list_head ti_chain;
201 #define OBD_MAX_RIF_DEFAULT 8
202 #define OBD_MAX_RIF_MAX 512
203 #define OSC_MAX_RIF_MAX 256
204 #define OSC_MAX_DIRTY_DEFAULT (OBD_MAX_RIF_DEFAULT * 4)
205 #define OSC_MAX_DIRTY_MB_MAX 2048 /* arbitrary, but < MAX_LONG bytes */
206 #define OSC_DEFAULT_RESENDS 10
208 /* possible values for fo_sync_lock_cancel */
210 NEVER_SYNC_ON_CANCEL = 0,
211 BLOCKING_SYNC_ON_CANCEL = 1,
212 ALWAYS_SYNC_ON_CANCEL = 2,
213 NUM_SYNC_ON_CANCEL_STATES
219 struct rw_semaphore cl_sem;
220 struct obd_uuid cl_target_uuid;
221 struct obd_import *cl_import; /* ptlrpc connection state */
223 /* max_mds_easize is purely a performance thing so we don't have to
224 * call obd_size_diskmd() all the time. */
225 int cl_default_mds_easize;
226 int cl_max_mds_easize;
227 int cl_default_mds_cookiesize;
228 int cl_max_mds_cookiesize;
230 enum lustre_sec_part cl_sp_me;
231 enum lustre_sec_part cl_sp_to;
232 struct sptlrpc_flavor cl_flvr_mgc; /* fixed flavor of mgc->mgs */
234 /* the grant values are protected by loi_list_lock below */
235 unsigned long cl_dirty_pages; /* all _dirty_ in pages */
236 unsigned long cl_dirty_max_pages; /* allowed w/o rpc */
237 unsigned long cl_dirty_transit; /* dirty synchronous */
238 unsigned long cl_avail_grant; /* bytes of credit for ost */
239 unsigned long cl_lost_grant; /* lost credits (trunc) */
241 /* since we allocate grant by blocks, we don't know how many grant will
242 * be used to add a page into cache. As a solution, we reserve maximum
243 * grant before trying to dirty a page and unreserve the rest.
244 * See osc_{reserve|unreserve}_grant for details. */
245 long cl_reserved_grant;
246 struct list_head cl_cache_waiters; /* waiting for cache/grant */
247 cfs_time_t cl_next_shrink_grant; /* jiffies */
248 struct list_head cl_grant_shrink_list; /* Timeout event list */
249 int cl_grant_shrink_interval; /* seconds */
251 /* A chunk is an optimal size used by osc_extent to determine
252 * the extent size. A chunk is max(PAGE_CACHE_SIZE, OST block size) */
254 int cl_extent_tax; /* extent overhead, by bytes */
256 /* keep track of objects that have lois that contain pages which
257 * have been queued for async brw. this lock also protects the
258 * lists of osc_client_pages that hang off of the loi */
260 * ->cl_loi_list_lock protects consistency of
261 * ->cl_loi_{ready,read,write}_list. ->ap_make_ready() and
262 * ->ap_completion() call-backs are executed under this lock. As we
263 * cannot guarantee that these call-backs never block on all platforms
264 * (as a matter of fact they do block on Mac OS X), type of
265 * ->cl_loi_list_lock is platform dependent: it's a spin-lock on Linux
266 * and blocking mutex on Mac OS X. (Alternative is to make this lock
267 * blocking everywhere, but we don't want to slow down fast-path of
268 * our main platform.)
270 * Exact type of ->cl_loi_list_lock is defined in arch/obd.h together
271 * with client_obd_list_{un,}lock() and
272 * client_obd_list_lock_{init,done}() functions.
274 * NB by Jinshan: though field names are still _loi_, but actually
275 * osc_object{}s are in the list.
277 client_obd_lock_t cl_loi_list_lock;
278 struct list_head cl_loi_ready_list;
279 struct list_head cl_loi_hp_ready_list;
280 struct list_head cl_loi_write_list;
281 struct list_head cl_loi_read_list;
282 __u32 cl_r_in_flight;
283 __u32 cl_w_in_flight;
284 /* just a sum of the loi/lop pending numbers to be exported by /proc */
285 atomic_t cl_pending_w_pages;
286 atomic_t cl_pending_r_pages;
287 __u32 cl_max_pages_per_rpc;
288 __u32 cl_max_rpcs_in_flight;
289 struct obd_histogram cl_read_rpc_hist;
290 struct obd_histogram cl_write_rpc_hist;
291 struct obd_histogram cl_read_page_hist;
292 struct obd_histogram cl_write_page_hist;
293 struct obd_histogram cl_read_offset_hist;
294 struct obd_histogram cl_write_offset_hist;
296 /* lru for osc caching pages */
297 struct cl_client_cache *cl_cache;
298 struct list_head cl_lru_osc; /* member of cl_cache->ccc_lru */
299 atomic_t *cl_lru_left;
300 atomic_t cl_lru_busy;
301 atomic_t cl_lru_shrinkers;
302 atomic_t cl_lru_in_list;
303 struct list_head cl_lru_list; /* lru page list */
304 client_obd_lock_t cl_lru_list_lock; /* page list protector */
305 atomic_t cl_unstable_count;
307 /* number of in flight destroy rpcs is limited to max_rpcs_in_flight */
308 atomic_t cl_destroy_in_flight;
309 wait_queue_head_t cl_destroy_waitq;
311 struct mdc_rpc_lock *cl_rpc_lock;
312 struct mdc_rpc_lock *cl_close_lock;
315 struct mutex cl_mgc_mutex;
316 struct local_oid_storage *cl_mgc_los;
317 struct dt_object *cl_mgc_configs_dir;
318 atomic_t cl_mgc_refcount;
319 struct obd_export *cl_mgc_mgsexp;
321 /* checksumming for data sent over the network */
322 unsigned int cl_checksum:1; /* 0 = disabled, 1 = enabled */
323 /* supported checksum types that are worked out at connect time */
324 __u32 cl_supp_cksum_types;
325 /* checksum algorithm to be used */
326 cksum_type_t cl_cksum_type;
328 /* also protected by the poorly named _loi_list_lock lock above */
329 struct osc_async_rc cl_ar;
331 /* used by quotacheck when the servers are older than 2.4 */
332 int cl_qchk_stat; /* quotacheck stat of the peer */
333 #define CL_NOT_QUOTACHECKED 1 /* client->cl_qchk_stat init value */
334 #if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 7, 53, 0)
335 #warning "please consider removing quotacheck compatibility code"
338 /* sequence manager */
339 struct lu_client_seq *cl_seq;
341 atomic_t cl_resends; /* resend count */
343 /* ptlrpc work for writeback in ptlrpcd context */
344 void *cl_writeback_work;
346 /* hash tables for osc_quota_info */
347 cfs_hash_t *cl_quota_hash[MAXQUOTAS];
349 #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
356 struct echo_client_obd {
357 struct obd_export *ec_exp; /* the local connection to osc/lov */
359 struct list_head ec_objects;
360 struct list_head ec_locks;
365 /* Generic subset of OSTs */
367 __u32 *op_array; /* array of index of
369 unsigned int op_count; /* number of OSTs in the array */
370 unsigned int op_size; /* allocated size of lp_array */
371 struct rw_semaphore op_rw_sem; /* to protect ost_pool use */
374 /* allow statfs data caching for 1 second */
375 #define OBD_STATFS_CACHE_SECONDS 1
377 struct lov_tgt_desc {
378 struct list_head ltd_kill;
379 struct obd_uuid ltd_uuid;
380 struct obd_device *ltd_obd;
381 struct obd_export *ltd_exp;
383 __u32 ltd_index; /* index in lov_obd->tgts */
384 unsigned long ltd_active:1,/* is this target up for requests */
385 ltd_activate:1,/* should target be activated */
386 ltd_reap:1; /* should this target be deleted */
390 struct lov_desc desc;
391 struct lov_tgt_desc **lov_tgts; /* sparse array */
392 struct ost_pool lov_packed; /* all OSTs in a packed
394 struct mutex lov_lock;
395 struct obd_connect_data lov_ocd;
396 struct proc_dir_entry *targets_proc_entry;
397 atomic_t lov_refcount;
398 __u32 lov_death_row; /* tgts scheduled to be deleted */
399 __u32 lov_tgt_size; /* size of tgts array */
402 cfs_hash_t *lov_pools_hash_body; /* used for key access */
403 struct list_head lov_pool_list; /* used for sequential access */
404 struct proc_dir_entry *lov_pool_proc_entry;
405 enum lustre_sec_part lov_sp_me;
407 /* Cached LRU and unstable data from upper layer */
410 struct rw_semaphore lov_notify_lock;
413 struct lmv_tgt_desc {
414 struct obd_uuid ltd_uuid;
415 struct obd_export *ltd_exp;
417 struct mutex ltd_fid_mutex;
418 unsigned long ltd_active:1; /* target up for requests */
421 enum placement_policy {
422 PLACEMENT_CHAR_POLICY = 0,
423 PLACEMENT_NID_POLICY = 1,
424 PLACEMENT_INVAL_POLICY = 2,
428 typedef enum placement_policy placement_policy_t;
432 struct lu_client_fld lmv_fld;
434 placement_policy_t lmv_placement;
435 struct lmv_desc desc;
436 struct obd_uuid cluuid;
437 struct obd_export *exp;
438 struct proc_dir_entry *targets_proc_entry;
440 struct mutex init_mutex;
445 int max_def_cookiesize;
448 int tgts_size; /* size of tgts array */
449 struct lmv_tgt_desc **tgts;
451 struct obd_connect_data conn_data;
454 struct niobuf_local {
455 __u64 lnb_file_offset;
456 __u32 lnb_page_offset;
459 struct page *lnb_page;
464 #define LUSTRE_FLD_NAME "fld"
465 #define LUSTRE_SEQ_NAME "seq"
467 #define LUSTRE_MDD_NAME "mdd"
468 #define LUSTRE_OSD_LDISKFS_NAME "osd-ldiskfs"
469 #define LUSTRE_OSD_ZFS_NAME "osd-zfs"
470 #define LUSTRE_VVP_NAME "vvp"
471 #define LUSTRE_LMV_NAME "lmv"
472 #define LUSTRE_SLP_NAME "slp"
473 #define LUSTRE_LOD_NAME "lod"
474 #define LUSTRE_OSP_NAME "osp"
475 #define LUSTRE_LWP_NAME "lwp"
477 /* obd device type names */
478 /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */
479 #define LUSTRE_MDS_NAME "mds"
480 #define LUSTRE_MDT_NAME "mdt"
481 #define LUSTRE_MDC_NAME "mdc"
482 #define LUSTRE_OSS_NAME "ost" /* FIXME change name to oss */
483 #define LUSTRE_OST_NAME "obdfilter" /* FIXME change name to ost */
484 #define LUSTRE_OSC_NAME "osc"
485 #define LUSTRE_LOV_NAME "lov"
486 #define LUSTRE_MGS_NAME "mgs"
487 #define LUSTRE_MGC_NAME "mgc"
489 #define LUSTRE_ECHO_NAME "obdecho"
490 #define LUSTRE_ECHO_CLIENT_NAME "echo_client"
491 #define LUSTRE_QMT_NAME "qmt"
493 /* Constant obd names (post-rename) */
494 #define LUSTRE_MDS_OBDNAME "MDS"
495 #define LUSTRE_OSS_OBDNAME "OSS"
496 #define LUSTRE_MGS_OBDNAME "MGS"
497 #define LUSTRE_MGC_OBDNAME "MGC"
499 struct obd_trans_info {
501 /* Only used on the server side for tracking acks. */
502 struct oti_req_ack_lock {
503 struct lustre_handle lock;
507 struct llog_cookie oti_onecookie;
508 struct llog_cookie *oti_logcookies;
511 __u64 oti_pre_version;
515 * Events signalled through obd_notify() upcall-chain.
517 enum obd_notify_event {
520 /* Device connect start */
522 /* Device activated */
524 /* Device deactivated */
526 /* Device disconnected */
528 /* Connect data for import were changed */
531 OBD_NOTIFY_SYNC_NONBLOCK,
533 /* Configuration event */
535 /* Administratively deactivate/activate event */
536 OBD_NOTIFY_DEACTIVATE,
540 /* bit-mask flags for config events */
542 CONFIG_LOG = 0x1, /* finished processing config log */
543 CONFIG_SYNC = 0x2, /* mdt synced 1 ost */
544 CONFIG_TARGET = 0x4 /* one target is added */
548 * Data structure used to pass obd_notify()-event to non-obd listeners (llite
549 * and liblustre being main examples).
551 struct obd_notify_upcall {
552 int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
553 enum obd_notify_event ev, void *owner, void *data);
554 /* Opaque datum supplied by upper layer listener */
558 struct target_recovery_data {
559 svc_handler_t trd_recovery_handler;
560 pid_t trd_processing_task;
561 struct completion trd_starting;
562 struct completion trd_finishing;
565 struct obd_llog_group {
566 struct llog_ctxt *olg_ctxts[LLOG_MAX_CTXTS];
567 wait_queue_head_t olg_waitq;
569 struct mutex olg_cat_processing;
572 /* corresponds to one of the obd's */
573 #define OBD_DEVICE_MAGIC 0XAB5CD6EF
576 struct obd_type *obd_type;
579 /* common and UUID name of this device */
580 char obd_name[MAX_OBD_NAME];
581 struct obd_uuid obd_uuid;
583 struct lu_device *obd_lu_dev;
585 /* bitfield modification is protected by obd_dev_lock */
587 obd_attached:1, /* finished attach */
588 obd_set_up:1, /* finished setup */
589 obd_recovering:1, /* there are recoverable clients */
590 obd_abort_recovery:1, /* recovery expired */
591 obd_version_recov:1, /* obd uses version checking */
592 obd_replayable:1, /* recovery is enabled;
594 obd_no_transno:1, /* no committed-transno notification */
595 obd_no_recov:1, /* fail instead of retry messages */
596 obd_stopping:1, /* started cleanup */
597 obd_starting:1, /* started setup */
598 obd_force:1, /* cleanup with > 0 obd refcount */
599 obd_fail:1, /* cleanup with failover */
600 obd_no_conn:1, /* deny new connections */
601 obd_inactive:1, /* device active/inactive
602 * (for /proc/status only!!) */
603 obd_no_ir:1, /* no imperative recovery. */
604 obd_process_conf:1, /* device is processing mgs config */
605 obd_uses_nid_stats:1; /* maintain per-client OBD stats */
607 /* use separate field as it is set in interrupt to don't mess with
608 * protection of other bits using _bh lock */
609 unsigned long obd_recovery_expired:1;
610 /* uuid-export hash body */
611 cfs_hash_t *obd_uuid_hash;
612 /* nid-export hash body */
613 cfs_hash_t *obd_nid_hash;
615 cfs_hash_t *obd_nid_stats_hash;
616 struct list_head obd_nid_stats;
617 atomic_t obd_refcount;
618 struct list_head obd_exports;
619 struct list_head obd_unlinked_exports;
620 struct list_head obd_delayed_exports;
621 struct list_head obd_lwp_list;
623 spinlock_t obd_nid_lock;
624 struct ldlm_namespace *obd_namespace;
625 struct ptlrpc_client obd_ldlm_client; /* XXX OST/MDS only */
626 /* a spinlock is OK for what we do now, may need a semaphore later */
627 spinlock_t obd_dev_lock; /* protect OBD bitfield above */
628 struct mutex obd_dev_mutex;
629 __u64 obd_last_committed;
630 spinlock_t obd_osfs_lock;
631 struct obd_statfs obd_osfs; /* locked by obd_osfs_lock */
633 struct lvfs_run_ctxt obd_lvfs_ctxt;
634 struct obd_llog_group obd_olg; /* default llog group */
635 struct obd_device *obd_observer;
636 struct rw_semaphore obd_observer_link_sem;
637 struct obd_notify_upcall obd_upcall;
638 struct obd_export *obd_self_export;
639 struct obd_export *obd_lwp_export;
640 /* list of exports in LRU order, for ping evictor, with obd_dev_lock */
641 struct list_head obd_exports_timed;
642 time_t obd_eviction_timer; /* for ping evictor */
644 int obd_max_recoverable_clients;
645 atomic_t obd_connected_clients;
646 int obd_stale_clients;
647 /* this lock protects all recovery list_heads, timer and
648 * obd_next_recovery_transno value */
649 spinlock_t obd_recovery_task_lock;
650 __u64 obd_next_recovery_transno;
651 int obd_replayed_requests;
652 int obd_requests_queued_for_recovery;
653 wait_queue_head_t obd_next_transno_waitq;
654 /* protected by obd_recovery_task_lock */
655 struct timer_list obd_recovery_timer;
657 time_t obd_recovery_start;
658 /* seconds, for lprocfs_status */
659 time_t obd_recovery_end;
660 int obd_recovery_time_hard;
661 int obd_recovery_timeout;
662 int obd_recovery_ir_factor;
664 /* new recovery stuff from CMD2 */
665 struct target_recovery_data obd_recovery_data;
666 int obd_replayed_locks;
667 atomic_t obd_req_replay_clients;
668 atomic_t obd_lock_replay_clients;
669 /* all lists are protected by obd_recovery_task_lock */
670 struct list_head obd_req_replay_queue;
671 struct list_head obd_lock_replay_queue;
672 struct list_head obd_final_req_queue;
675 #ifdef HAVE_SERVER_SUPPORT
676 struct obd_device_target obt;
677 struct filter_obd filter;
679 struct echo_obd echo;
681 struct client_obd cli;
682 struct echo_client_obd echo_client;
686 /* Fields used by LProcFS */
687 unsigned int obd_cntr_base;
688 struct lprocfs_stats *obd_stats;
690 unsigned int obd_md_cntr_base;
691 struct lprocfs_stats *obd_md_stats;
693 struct proc_dir_entry *obd_proc_entry;
694 struct proc_dir_entry *obd_proc_exports_entry;
695 struct proc_dir_entry *obd_svc_procroot;
696 struct lprocfs_stats *obd_svc_stats;
697 struct lprocfs_seq_vars *obd_vars;
698 atomic_t obd_evict_inprogress;
699 wait_queue_head_t obd_evict_inprogress_waitq;
700 struct list_head obd_evict_list; /* protected with pet_lock */
703 * Ldlm pool part. Save last calculated SLV and Limit.
705 rwlock_t obd_pool_lock;
710 * A list of outstanding class_incref()'s against this obd. For
713 struct lu_ref obd_reference;
715 int obd_conn_inprogress;
718 enum obd_cleanup_stage {
719 /* Special case hack for MDS LOVs */
721 /* can be directly mapped to .ldto_device_fini() */
725 /* get/set_info keys */
726 #define KEY_ASYNC "async"
727 #define KEY_CAPA_KEY "capa_key"
728 #define KEY_CHANGELOG_CLEAR "changelog_clear"
729 #define KEY_FID2PATH "fid2path"
730 #define KEY_CHECKSUM "checksum"
731 #define KEY_CLEAR_FS "clear_fs"
732 #define KEY_CONN_DATA "conn_data"
733 #define KEY_EVICT_BY_NID "evict_by_nid"
734 #define KEY_FIEMAP "fiemap"
735 #define KEY_FLUSH_CTX "flush_ctx"
736 #define KEY_GRANT_SHRINK "grant_shrink"
737 #define KEY_HSM_COPYTOOL_SEND "hsm_send"
738 #define KEY_INIT_RECOV_BACKUP "init_recov_bk"
739 #define KEY_INTERMDS "inter_mds"
740 #define KEY_LAST_ID "last_id"
741 #define KEY_LAST_FID "last_fid"
742 #define KEY_LOCK_TO_STRIPE "lock_to_stripe"
743 #define KEY_LOVDESC "lovdesc"
744 #define KEY_MAX_EASIZE "max_easize"
745 #define KEY_DEFAULT_EASIZE "default_easize"
746 #define KEY_MAX_COOKIESIZE "max_cookiesize"
747 #define KEY_DEFAULT_COOKIESIZE "default_cookiesize"
748 #define KEY_MDS_CONN "mds_conn"
749 #define KEY_MGSSEC "mgssec"
750 #define KEY_NEXT_ID "next_id"
751 #define KEY_READ_ONLY "read-only"
752 #define KEY_REGISTER_TARGET "register_target"
753 #define KEY_SET_FS "set_fs"
754 #define KEY_TGT_COUNT "tgt_count"
755 /* KEY_SET_INFO in lustre_idl.h */
756 #define KEY_SPTLRPC_CONF "sptlrpc_conf"
757 #define KEY_CONNECT_FLAG "connect_flags"
759 #define KEY_CACHE_SET "cache_set"
760 #define KEY_CACHE_LRU_SHRINK "cache_lru_shrink"
761 #define KEY_OSP_CONNECTED "osp_connected"
765 /* /!\ must be coherent with include/linux/namei.h on patched kernel */
766 #define IT_OPEN (1 << 0)
767 #define IT_CREAT (1 << 1)
768 #define IT_READDIR (1 << 2)
769 #define IT_GETATTR (1 << 3)
770 #define IT_LOOKUP (1 << 4)
771 #define IT_UNLINK (1 << 5)
772 #define IT_TRUNC (1 << 6)
773 #define IT_GETXATTR (1 << 7)
774 #define IT_EXEC (1 << 8)
775 #define IT_PIN (1 << 9)
776 #define IT_LAYOUT (1 << 10)
777 #define IT_QUOTA_DQACQ (1 << 11)
778 #define IT_QUOTA_CONN (1 << 12)
779 #define IT_SETXATTR (1 << 13)
781 static inline int it_to_lock_mode(struct lookup_intent *it)
783 /* CREAT needs to be tested before open (both could be set) */
784 if (it->it_op & IT_CREAT)
786 else if (it->it_op & (IT_GETATTR | IT_OPEN | IT_LOOKUP |
789 else if (it->it_op & IT_READDIR)
791 else if (it->it_op & IT_GETXATTR)
793 else if (it->it_op & IT_SETXATTR)
796 LASSERTF(0, "Invalid it_op: %d\n", it->it_op);
801 struct lu_fid op_fid1; /* operation fid1 (usualy parent) */
802 struct lu_fid op_fid2; /* operation fid2 (usualy child) */
803 struct lu_fid op_fid3; /* 2 extra fids to find conflicting */
804 struct lu_fid op_fid4; /* to the operation locks. */
805 u32 op_mds; /* what mds server open will go to */
806 struct lustre_handle op_handle;
807 obd_time op_mod_time;
811 struct lmv_stripe_md *op_mea1;
812 struct lmv_stripe_md *op_mea2;
813 __u32 op_suppgids[2];
820 /* iattr fields and blocks. */
821 struct iattr op_attr;
823 loff_t op_attr_blocks;
825 /* Size-on-MDS epoch and flags. */
830 struct obd_capa *op_capa1;
831 struct obd_capa *op_capa2;
833 /* Various operation flags. */
834 enum mds_op_bias op_bias;
836 /* Used by readdir */
839 /* used to transfer info between the stacks of MD client
840 * see enum op_cli_flags */
843 /* File object data version for HSM release, on client */
844 __u64 op_data_version;
845 struct lustre_handle op_lease_handle;
848 #define op_stripe_offset op_ioepoch
849 #define op_max_pages op_valid
852 int (*md_blocking_ast)(struct ldlm_lock *lock,
853 struct ldlm_lock_desc *desc,
854 void *data, int flag);
857 struct md_enqueue_info;
858 /* metadata stat-ahead */
859 typedef int (* md_enqueue_cb_t)(struct ptlrpc_request *req,
860 struct md_enqueue_info *minfo,
863 struct md_enqueue_info {
864 struct md_op_data mi_data;
865 struct lookup_intent mi_it;
866 struct lustre_handle mi_lockh;
867 struct inode *mi_dir;
868 md_enqueue_cb_t mi_cb;
870 unsigned int mi_generation;
874 struct module *o_owner;
875 int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
876 void *karg, void *uarg);
877 int (*o_get_info)(const struct lu_env *env, struct obd_export *,
878 __u32 keylen, void *key, __u32 *vallen, void *val,
879 struct lov_stripe_md *lsm);
880 int (*o_set_info_async)(const struct lu_env *, struct obd_export *,
881 __u32 keylen, void *key,
882 __u32 vallen, void *val,
883 struct ptlrpc_request_set *set);
884 int (*o_setup) (struct obd_device *dev, struct lustre_cfg *cfg);
885 int (*o_precleanup)(struct obd_device *dev,
886 enum obd_cleanup_stage cleanup_stage);
887 int (*o_cleanup)(struct obd_device *dev);
888 int (*o_process_config)(struct obd_device *dev, obd_count len,
890 int (*o_postrecov)(struct obd_device *dev);
891 int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
893 int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
894 /* connect to the target device with given connection
895 * data. @ocd->ocd_connect_flags is modified to reflect flags actually
896 * granted by the target, which are guaranteed to be a subset of flags
897 * asked for. If @ocd == NULL, use default parameters. */
898 int (*o_connect)(const struct lu_env *env,
899 struct obd_export **exp, struct obd_device *src,
900 struct obd_uuid *cluuid, struct obd_connect_data *ocd,
902 int (*o_reconnect)(const struct lu_env *env,
903 struct obd_export *exp, struct obd_device *src,
904 struct obd_uuid *cluuid,
905 struct obd_connect_data *ocd,
907 int (*o_disconnect)(struct obd_export *exp);
909 /* Initialize/finalize fids infrastructure. */
910 int (*o_fid_init)(struct obd_device *obd,
911 struct obd_export *exp, enum lu_cli_type type);
912 int (*o_fid_fini)(struct obd_device *obd);
914 /* Allocate new fid according to passed @hint. */
915 int (*o_fid_alloc)(const struct lu_env *env, struct obd_export *exp,
916 struct lu_fid *fid, struct md_op_data *op_data);
919 * Object with @fid is getting deleted, we may want to do something
922 int (*o_statfs)(const struct lu_env *, struct obd_export *exp,
923 struct obd_statfs *osfs, __u64 max_age, __u32 flags);
924 int (*o_statfs_async)(struct obd_export *exp, struct obd_info *oinfo,
925 __u64 max_age, struct ptlrpc_request_set *set);
926 int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
927 struct lov_stripe_md *mem_src);
928 int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
929 struct lov_mds_md *disk_src, int disk_len);
930 int (*o_create)(const struct lu_env *env, struct obd_export *exp,
931 struct obdo *oa, struct lov_stripe_md **ea,
932 struct obd_trans_info *oti);
933 int (*o_destroy)(const struct lu_env *env, struct obd_export *exp,
934 struct obdo *oa, struct lov_stripe_md *ea,
935 struct obd_trans_info *oti, struct obd_export *md_exp,
937 int (*o_setattr)(const struct lu_env *, struct obd_export *exp,
938 struct obd_info *oinfo, struct obd_trans_info *oti);
939 int (*o_setattr_async)(struct obd_export *exp, struct obd_info *oinfo,
940 struct obd_trans_info *oti,
941 struct ptlrpc_request_set *rqset);
942 int (*o_getattr)(const struct lu_env *env, struct obd_export *exp,
943 struct obd_info *oinfo);
944 int (*o_getattr_async)(struct obd_export *exp, struct obd_info *oinfo,
945 struct ptlrpc_request_set *set);
946 int (*o_preprw)(const struct lu_env *env, int cmd,
947 struct obd_export *exp, struct obdo *oa, int objcount,
948 struct obd_ioobj *obj, struct niobuf_remote *remote,
949 int *nr_pages, struct niobuf_local *local,
950 struct obd_trans_info *oti, struct lustre_capa *capa);
951 int (*o_commitrw)(const struct lu_env *env, int cmd,
952 struct obd_export *exp, struct obdo *oa,
953 int objcount, struct obd_ioobj *obj,
954 struct niobuf_remote *remote, int pages,
955 struct niobuf_local *local,
956 struct obd_trans_info *oti, int rc);
957 int (*o_change_cbdata)(struct obd_export *, struct lov_stripe_md *,
958 ldlm_iterator_t it, void *data);
959 int (*o_find_cbdata)(struct obd_export *, struct lov_stripe_md *,
960 ldlm_iterator_t it, void *data);
961 int (*o_init_export)(struct obd_export *exp);
962 int (*o_destroy_export)(struct obd_export *exp);
964 /* llog related obd_methods */
965 int (*o_llog_init)(struct obd_device *obd, struct obd_llog_group *grp,
966 struct obd_device *disk_obd, int *idx);
967 int (*o_llog_finish)(struct obd_device *obd, int count);
969 int (*o_import_event)(struct obd_device *, struct obd_import *,
970 enum obd_import_event);
972 int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
973 enum obd_notify_event ev, void *data);
975 int (*o_health_check)(const struct lu_env *env, struct obd_device *);
976 struct obd_uuid *(*o_get_uuid) (struct obd_export *exp);
979 int (*o_quotacheck)(struct obd_device *, struct obd_export *,
980 struct obd_quotactl *);
981 int (*o_quotactl)(struct obd_device *, struct obd_export *,
982 struct obd_quotactl *);
984 int (*o_ping)(const struct lu_env *, struct obd_export *exp);
987 int (*o_pool_new)(struct obd_device *obd, char *poolname);
988 int (*o_pool_del)(struct obd_device *obd, char *poolname);
989 int (*o_pool_add)(struct obd_device *obd, char *poolname,
991 int (*o_pool_rem)(struct obd_device *obd, char *poolname,
993 void (*o_getref)(struct obd_device *obd);
994 void (*o_putref)(struct obd_device *obd);
996 * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
997 * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
998 * Also, add a wrapper function in include/linux/obd_class.h. */
1001 /* lmv structures */
1003 struct mdt_body *body;
1004 struct lov_stripe_md *lsm;
1005 struct lmv_stripe_md *lmv;
1006 #ifdef CONFIG_FS_POSIX_ACL
1007 struct posix_acl *posix_acl;
1009 struct mdt_remote_perm *remote_perm;
1010 struct obd_capa *mds_capa;
1011 struct obd_capa *oss_capa;
1014 struct md_open_data {
1015 struct obd_client_handle *mod_och;
1016 struct ptlrpc_request *mod_open_req;
1017 struct ptlrpc_request *mod_close_req;
1018 atomic_t mod_refcount;
1022 struct lookup_intent;
1026 /* Every operation from MD_STATS_FIRST_OP up to and including
1027 * MD_STATS_LAST_OP will be counted by EXP_MD_OP_INCREMENT()
1028 * and will appear in /proc/fs/lustre/{lmv,mdc}/.../md_stats.
1029 * Operations after MD_STATS_LAST_OP are excluded from stats.
1030 * There are a few reasons for doing this: we prune the 17
1031 * counters which will be of minimal use in understanding
1032 * metadata utilization, we save memory by allocating 15
1033 * instead of 32 counters, we save cycles by not counting.
1035 * MD_STATS_FIRST_OP must be the first member of md_ops.
1037 #define MD_STATS_FIRST_OP m_close
1038 int (*m_close)(struct obd_export *, struct md_op_data *,
1039 struct md_open_data *, struct ptlrpc_request **);
1041 int (*m_create)(struct obd_export *, struct md_op_data *,
1042 const void *, int, int, __u32, __u32, cfs_cap_t,
1043 __u64, struct ptlrpc_request **);
1045 int (*m_enqueue)(struct obd_export *, struct ldlm_enqueue_info *,
1046 const union ldlm_policy_data *,
1047 struct lookup_intent *, struct md_op_data *,
1048 struct lustre_handle *, __u64);
1050 int (*m_getattr)(struct obd_export *, struct md_op_data *,
1051 struct ptlrpc_request **);
1053 int (*m_intent_lock)(struct obd_export *, struct md_op_data *,
1054 struct lookup_intent *,
1055 struct ptlrpc_request **,
1056 ldlm_blocking_callback, __u64);
1058 int (*m_link)(struct obd_export *, struct md_op_data *,
1059 struct ptlrpc_request **);
1061 int (*m_rename)(struct obd_export *, struct md_op_data *,
1062 const char *, int, const char *, int,
1063 struct ptlrpc_request **);
1065 int (*m_setattr)(struct obd_export *, struct md_op_data *, void *,
1066 int , void *, int, struct ptlrpc_request **,
1067 struct md_open_data **mod);
1069 int (*m_fsync)(struct obd_export *, const struct lu_fid *,
1070 struct obd_capa *, struct ptlrpc_request **);
1072 int (*m_read_page)(struct obd_export *, struct md_op_data *,
1073 struct md_callback *cb_op, __u64 hash_offset,
1074 struct page **ppage);
1076 int (*m_unlink)(struct obd_export *, struct md_op_data *,
1077 struct ptlrpc_request **);
1079 int (*m_setxattr)(struct obd_export *, const struct lu_fid *,
1080 struct obd_capa *, obd_valid, const char *,
1081 const char *, int, int, int, __u32,
1082 struct ptlrpc_request **);
1084 int (*m_getxattr)(struct obd_export *, const struct lu_fid *,
1085 struct obd_capa *, obd_valid, const char *,
1086 const char *, int, int, int,
1087 struct ptlrpc_request **);
1089 int (*m_intent_getattr_async)(struct obd_export *,
1090 struct md_enqueue_info *,
1091 struct ldlm_enqueue_info *);
1093 int (*m_revalidate_lock)(struct obd_export *, struct lookup_intent *,
1094 struct lu_fid *, __u64 *bits);
1096 #define MD_STATS_LAST_OP m_revalidate_lock
1098 int (*m_getstatus)(struct obd_export *, struct lu_fid *,
1099 struct obd_capa **);
1101 int (*m_null_inode)(struct obd_export *, const struct lu_fid *);
1103 int (*m_find_cbdata)(struct obd_export *, const struct lu_fid *,
1104 ldlm_iterator_t, void *);
1106 int (*m_done_writing)(struct obd_export *, struct md_op_data *,
1107 struct md_open_data *);
1109 int (*m_getattr_name)(struct obd_export *, struct md_op_data *,
1110 struct ptlrpc_request **);
1112 int (*m_init_ea_size)(struct obd_export *, int, int, int, int);
1114 int (*m_get_lustre_md)(struct obd_export *, struct ptlrpc_request *,
1115 struct obd_export *, struct obd_export *,
1116 struct lustre_md *);
1118 int (*m_free_lustre_md)(struct obd_export *, struct lustre_md *);
1120 int (*m_merge_attr)(struct obd_export *,
1121 const struct lmv_stripe_md *lsm,
1122 struct cl_attr *attr);
1124 int (*m_update_lsm_md)(struct obd_export *, struct lmv_stripe_md *lsm,
1125 struct mdt_body *, ldlm_blocking_callback);
1127 int (*m_set_open_replay_data)(struct obd_export *,
1128 struct obd_client_handle *,
1129 struct lookup_intent *);
1131 int (*m_clear_open_replay_data)(struct obd_export *,
1132 struct obd_client_handle *);
1134 int (*m_set_lock_data)(struct obd_export *, __u64 *, void *, __u64 *);
1136 ldlm_mode_t (*m_lock_match)(struct obd_export *, __u64,
1137 const struct lu_fid *, ldlm_type_t,
1138 ldlm_policy_data_t *, ldlm_mode_t,
1139 struct lustre_handle *);
1141 int (*m_cancel_unused)(struct obd_export *, const struct lu_fid *,
1142 ldlm_policy_data_t *, ldlm_mode_t,
1143 ldlm_cancel_flags_t flags, void *opaque);
1145 int (*m_renew_capa)(struct obd_export *, struct obd_capa *oc,
1146 renew_capa_cb_t cb);
1148 int (*m_unpack_capa)(struct obd_export *, struct ptlrpc_request *,
1149 const struct req_msg_field *, struct obd_capa **);
1151 int (*m_get_remote_perm)(struct obd_export *, const struct lu_fid *,
1152 struct obd_capa *, __u32,
1153 struct ptlrpc_request **);
1155 int (*m_get_fid_from_lsm)(struct obd_export *,
1156 const struct lmv_stripe_md *,
1157 const char *name, int namelen,
1158 struct lu_fid *fid);
1161 struct lsm_operations {
1162 void (*lsm_free)(struct lov_stripe_md *);
1163 int (*lsm_destroy)(struct lov_stripe_md *, struct obdo *oa,
1164 struct obd_export *md_exp);
1165 void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *, obd_off *,
1167 void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *, obd_off *,
1169 int (*lsm_lmm_verify) (struct lov_mds_md *lmm, int lmm_bytes,
1170 __u16 *stripe_count);
1171 int (*lsm_unpackmd) (struct lov_obd *lov, struct lov_stripe_md *lsm,
1172 struct lov_mds_md *lmm);
1175 extern const struct lsm_operations lsm_v1_ops;
1176 extern const struct lsm_operations lsm_v3_ops;
1177 static inline const struct lsm_operations *lsm_op_find(int magic)
1185 CERROR("Cannot recognize lsm_magic %08x\n", magic);
1190 static inline struct md_open_data *obd_mod_alloc(void)
1192 struct md_open_data *mod;
1196 atomic_set(&mod->mod_refcount, 1);
1200 #define obd_mod_get(mod) atomic_inc(&(mod)->mod_refcount)
1201 #define obd_mod_put(mod) \
1203 if (atomic_dec_and_test(&(mod)->mod_refcount)) { \
1204 if ((mod)->mod_open_req) \
1205 ptlrpc_req_finished((mod)->mod_open_req); \
1206 OBD_FREE_PTR(mod); \
1210 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
1211 void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent);
1213 /* return 1 if client should be resend request */
1214 static inline int client_should_resend(int resend, struct client_obd *cli)
1216 return atomic_read(&cli->cl_resends) ?
1217 atomic_read(&cli->cl_resends) > resend : 1;
1221 * Return device name for this device
1223 * XXX: lu_device is declared before obd_device, while a pointer pointing
1224 * back to obd_device in lu_device, so this helper function defines here
1225 * instead of in lu_object.h
1227 static inline const char *lu_dev_name(const struct lu_device *lu_dev)
1229 return lu_dev->ld_obd->obd_name;
1232 static inline bool filename_is_volatile(const char *name, int namelen, int *idx)
1237 if (strncmp(name, LUSTRE_VOLATILE_HDR, LUSTRE_VOLATILE_HDR_LEN) != 0)
1240 /* caller does not care of idx */
1244 /* volatile file, the MDT can be set from name */
1245 /* name format is LUSTRE_VOLATILE_HDR:[idx]: */
1246 /* if no MDT is specified, use std way */
1247 if (namelen < LUSTRE_VOLATILE_HDR_LEN + 2)
1249 /* test for no MDT idx case */
1250 if ((*(name + LUSTRE_VOLATILE_HDR_LEN) == ':') &&
1251 (*(name + LUSTRE_VOLATILE_HDR_LEN + 1) == ':')) {
1255 /* we have an idx, read it */
1256 start = name + LUSTRE_VOLATILE_HDR_LEN + 1;
1257 *idx = strtoul(start, &end, 16);
1259 * no digit, no trailing :, negative value
1261 if (((*idx == 0) && (end == start)) ||
1262 (*end != ':') || (*idx < 0))
1267 /* bad format of mdt idx, we cannot return an error
1268 * to caller so we use hash algo */
1269 CERROR("Bad volatile file name format: %s\n",
1270 name + LUSTRE_VOLATILE_HDR_LEN);
1274 static inline int cli_brw_size(struct obd_device *obd)
1276 LASSERT(obd != NULL);
1277 return obd->u.cli.cl_max_pages_per_rpc << PAGE_CACHE_SHIFT;
1280 /* when RPC size or the max RPCs in flight is increased, the max dirty pages
1281 * of the client should be increased accordingly to avoid sending fragmented
1282 * RPCs over the network when the client runs out of the maximum dirty space
1283 * when so many RPCs are being generated.
1285 static inline void client_adjust_max_dirty(struct client_obd *cli)
1288 if (cli->cl_dirty_max_pages <= 0)
1289 cli->cl_dirty_max_pages = (OSC_MAX_DIRTY_DEFAULT * 1024 * 1024)
1290 >> PAGE_CACHE_SHIFT;
1292 unsigned long dirty_max = cli->cl_max_rpcs_in_flight *
1293 cli->cl_max_pages_per_rpc;
1295 if (dirty_max > cli->cl_dirty_max_pages)
1296 cli->cl_dirty_max_pages = dirty_max;
1299 if (cli->cl_dirty_max_pages > totalram_pages / 8)
1300 cli->cl_dirty_max_pages = totalram_pages / 8;
1303 #endif /* __OBD_H */