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 # error "userspace should not include <obd.h>"
43 #if defined(__linux__)
44 #include <linux/obd.h>
45 #elif defined(__APPLE__)
46 #include <darwin/obd.h>
47 #elif defined(__WINNT__)
48 #include <winnt/obd.h>
50 #error Unsupported operating system.
53 #include <lustre/lustre_idl.h>
54 #include <lustre_lib.h>
55 #include <libcfs/bitmap.h>
56 #ifdef HAVE_SERVER_SUPPORT
57 # include <lu_target.h>
58 # include <obd_target.h>
61 #include <lustre_export.h>
62 #include <lustre_fid.h>
63 #include <lustre_fld.h>
64 #include <lustre_capa.h>
67 #define MAX_OBD_DEVICES 8192
75 struct lov_oinfo { /* per-stripe data structure */
76 struct ost_id loi_oi; /* object ID/Sequence on the target OST */
77 int loi_ost_idx; /* OST stripe index in lov_tgt_desc->tgts */
78 int loi_ost_gen; /* generation of this loi_ost_idx */
80 unsigned long loi_kms_valid:1;
81 __u64 loi_kms; /* known minimum size */
82 struct ost_lvb loi_lvb;
83 struct osc_async_rc loi_ar;
86 static inline void loi_kms_set(struct lov_oinfo *oinfo, __u64 kms)
89 oinfo->loi_kms_valid = 1;
92 static inline void loi_init(struct lov_oinfo *loi)
96 struct lov_stripe_md {
99 pid_t lsm_lock_owner; /* debugging */
101 /* maximum possible file size, might change as OSTs status changes,
102 * e.g. disconnected, deactivated */
105 /* Public members. */
106 struct ost_id lw_object_oi; /* lov object id/seq */
108 /* LOV-private members start here -- only for use in lov/. */
110 __u32 lw_stripe_size; /* size of the stripe */
111 __u32 lw_pattern; /* striping pattern (RAID0, RAID1) */
112 __u16 lw_stripe_count; /* number of objects being striped over */
113 __u16 lw_layout_gen; /* generation of the layout */
114 char lw_pool_name[LOV_MAXPOOLNAME]; /* pool name */
117 struct lov_oinfo *lsm_oinfo[0];
120 #define lsm_oi lsm_wire.lw_object_oi
121 #define lsm_magic lsm_wire.lw_magic
122 #define lsm_layout_gen lsm_wire.lw_layout_gen
123 #define lsm_stripe_size lsm_wire.lw_stripe_size
124 #define lsm_pattern lsm_wire.lw_pattern
125 #define lsm_stripe_count lsm_wire.lw_stripe_count
126 #define lsm_pool_name lsm_wire.lw_pool_name
128 static inline bool lsm_is_released(struct lov_stripe_md *lsm)
130 return !!(lsm->lsm_pattern & LOV_PATTERN_F_RELEASED);
133 static inline bool lsm_has_objects(struct lov_stripe_md *lsm)
137 if (lsm_is_released(lsm))
142 static inline int lov_stripe_md_size(unsigned int stripe_count)
144 struct lov_stripe_md lsm;
146 return sizeof(lsm) + stripe_count * sizeof(lsm.lsm_oinfo[0]);
151 typedef int (*obd_enqueue_update_f)(void *cookie, int rc);
153 /* obd info for a particular level (lov, osc). */
155 /* Lock policy. It keeps an extent which is specific for a particular
156 * OSC. (e.g. lov_prep_enqueue_set initialises extent of the policy,
157 * and osc_enqueue passes it into ldlm_lock_match & ldlm_cli_enqueue. */
158 ldlm_policy_data_t oi_policy;
159 /* Flags used for set request specific flags:
160 - while lock handling, the flags obtained on the enqueue
161 request are set here.
162 - while stats, the flags used for control delay/resend.
163 - while setattr, the flags used for distinguish punch operation
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. */
183 struct list_head typ_chain;
184 struct obd_ops *typ_dt_ops;
185 struct md_ops *typ_md_ops;
186 struct proc_dir_entry *typ_procroot;
187 struct proc_dir_entry *typ_procsym;
188 __u32 typ_sym_filter;
191 struct lu_device_type *typ_lu;
192 spinlock_t obd_type_lock;
202 struct timeout_item {
203 enum timeout_event ti_event;
204 cfs_time_t ti_timeout;
207 struct list_head ti_obd_list;
208 struct list_head ti_chain;
211 #define OBD_MAX_RIF_DEFAULT 8
212 #define OBD_MAX_RIF_MAX 512
213 #define OSC_MAX_RIF_MAX 256
214 #define OSC_MAX_DIRTY_DEFAULT (OBD_MAX_RIF_DEFAULT * 4)
215 #define OSC_MAX_DIRTY_MB_MAX 2048 /* arbitrary, but < MAX_LONG bytes */
216 #define OSC_DEFAULT_RESENDS 10
218 /* possible values for fo_sync_lock_cancel */
220 NEVER_SYNC_ON_CANCEL = 0,
221 BLOCKING_SYNC_ON_CANCEL = 1,
222 ALWAYS_SYNC_ON_CANCEL = 2,
223 NUM_SYNC_ON_CANCEL_STATES
229 struct rw_semaphore cl_sem;
230 struct obd_uuid cl_target_uuid;
231 struct obd_import *cl_import; /* ptlrpc connection state */
233 /* max_mds_easize is purely a performance thing so we don't have to
234 * call obd_size_diskmd() all the time. */
235 int cl_default_mds_easize;
236 int cl_max_mds_easize;
237 int cl_default_mds_cookiesize;
238 int cl_max_mds_cookiesize;
240 enum lustre_sec_part cl_sp_me;
241 enum lustre_sec_part cl_sp_to;
242 struct sptlrpc_flavor cl_flvr_mgc; /* fixed flavor of mgc->mgs */
244 /* the grant values are protected by loi_list_lock below */
245 long cl_dirty_pages; /* all _dirty_ in pages */
246 long cl_dirty_max_pages; /* allowed w/o rpc */
247 long cl_dirty_transit; /* dirty synchronous */
248 long cl_avail_grant; /* bytes of credit for ost */
249 long cl_lost_grant; /* lost credits (trunc) */
251 /* since we allocate grant by blocks, we don't know how many grant will
252 * be used to add a page into cache. As a solution, we reserve maximum
253 * grant before trying to dirty a page and unreserve the rest.
254 * See osc_{reserve|unreserve}_grant for details. */
255 long cl_reserved_grant;
256 struct list_head cl_cache_waiters; /* waiting for cache/grant */
257 cfs_time_t cl_next_shrink_grant; /* jiffies */
258 struct list_head cl_grant_shrink_list; /* Timeout event list */
259 int cl_grant_shrink_interval; /* seconds */
261 /* A chunk is an optimal size used by osc_extent to determine
262 * the extent size. A chunk is max(PAGE_CACHE_SIZE, OST block size) */
264 int cl_extent_tax; /* extent overhead, by bytes */
266 /* keep track of objects that have lois that contain pages which
267 * have been queued for async brw. this lock also protects the
268 * lists of osc_client_pages that hang off of the loi */
270 * ->cl_loi_list_lock protects consistency of
271 * ->cl_loi_{ready,read,write}_list. ->ap_make_ready() and
272 * ->ap_completion() call-backs are executed under this lock. As we
273 * cannot guarantee that these call-backs never block on all platforms
274 * (as a matter of fact they do block on Mac OS X), type of
275 * ->cl_loi_list_lock is platform dependent: it's a spin-lock on Linux
276 * and blocking mutex on Mac OS X. (Alternative is to make this lock
277 * blocking everywhere, but we don't want to slow down fast-path of
278 * our main platform.)
280 * Exact type of ->cl_loi_list_lock is defined in arch/obd.h together
281 * with client_obd_list_{un,}lock() and
282 * client_obd_list_lock_{init,done}() functions.
284 * NB by Jinshan: though field names are still _loi_, but actually
285 * osc_object{}s are in the list.
287 client_obd_lock_t cl_loi_list_lock;
288 struct list_head cl_loi_ready_list;
289 struct list_head cl_loi_hp_ready_list;
290 struct list_head cl_loi_write_list;
291 struct list_head cl_loi_read_list;
294 /* just a sum of the loi/lop pending numbers to be exported by /proc */
295 atomic_t cl_pending_w_pages;
296 atomic_t cl_pending_r_pages;
297 __u32 cl_max_pages_per_rpc;
298 int cl_max_rpcs_in_flight;
299 struct obd_histogram cl_read_rpc_hist;
300 struct obd_histogram cl_write_rpc_hist;
301 struct obd_histogram cl_read_page_hist;
302 struct obd_histogram cl_write_page_hist;
303 struct obd_histogram cl_read_offset_hist;
304 struct obd_histogram cl_write_offset_hist;
306 /* lru for osc caching pages */
307 struct cl_client_cache *cl_cache;
308 struct list_head cl_lru_osc; /* member of cl_cache->ccc_lru */
309 atomic_t *cl_lru_left;
310 atomic_t cl_lru_busy;
311 atomic_t cl_lru_shrinkers;
312 atomic_t cl_lru_in_list;
313 struct list_head cl_lru_list; /* lru page list */
314 client_obd_lock_t cl_lru_list_lock; /* page list protector */
315 atomic_t cl_unstable_count;
317 /* number of in flight destroy rpcs is limited to max_rpcs_in_flight */
318 atomic_t cl_destroy_in_flight;
319 wait_queue_head_t cl_destroy_waitq;
321 struct mdc_rpc_lock *cl_rpc_lock;
322 struct mdc_rpc_lock *cl_close_lock;
325 struct mutex cl_mgc_mutex;
326 struct local_oid_storage *cl_mgc_los;
327 struct dt_object *cl_mgc_configs_dir;
328 atomic_t cl_mgc_refcount;
329 struct obd_export *cl_mgc_mgsexp;
331 /* checksumming for data sent over the network */
332 unsigned int cl_checksum:1; /* 0 = disabled, 1 = enabled */
333 /* supported checksum types that are worked out at connect time */
334 __u32 cl_supp_cksum_types;
335 /* checksum algorithm to be used */
336 cksum_type_t cl_cksum_type;
338 /* also protected by the poorly named _loi_list_lock lock above */
339 struct osc_async_rc cl_ar;
341 /* used by quotacheck when the servers are older than 2.4 */
342 int cl_qchk_stat; /* quotacheck stat of the peer */
343 #define CL_NOT_QUOTACHECKED 1 /* client->cl_qchk_stat init value */
344 #if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 7, 50, 0)
345 #warning "please consider removing quotacheck compatibility code"
348 /* sequence manager */
349 struct lu_client_seq *cl_seq;
351 atomic_t cl_resends; /* resend count */
353 /* ptlrpc work for writeback in ptlrpcd context */
354 void *cl_writeback_work;
356 /* hash tables for osc_quota_info */
357 cfs_hash_t *cl_quota_hash[MAXQUOTAS];
359 #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
366 struct echo_client_obd {
367 struct obd_export *ec_exp; /* the local connection to osc/lov */
369 struct list_head ec_objects;
370 struct list_head ec_locks;
375 /* Generic subset of OSTs */
377 __u32 *op_array; /* array of index of
379 unsigned int op_count; /* number of OSTs in the array */
380 unsigned int op_size; /* allocated size of lp_array */
381 struct rw_semaphore op_rw_sem; /* to protect ost_pool use */
384 /* allow statfs data caching for 1 second */
385 #define OBD_STATFS_CACHE_SECONDS 1
387 struct lov_tgt_desc {
388 struct list_head ltd_kill;
389 struct obd_uuid ltd_uuid;
390 struct obd_device *ltd_obd;
391 struct obd_export *ltd_exp;
393 __u32 ltd_index; /* index in lov_obd->tgts */
394 unsigned long ltd_active:1,/* is this target up for requests */
395 ltd_activate:1,/* should target be activated */
396 ltd_reap:1; /* should this target be deleted */
400 struct lov_desc desc;
401 struct lov_tgt_desc **lov_tgts; /* sparse array */
402 struct ost_pool lov_packed; /* all OSTs in a packed
404 struct mutex lov_lock;
405 struct obd_connect_data lov_ocd;
406 struct proc_dir_entry *targets_proc_entry;
407 atomic_t lov_refcount;
408 __u32 lov_death_row; /* tgts scheduled to be deleted */
409 __u32 lov_tgt_size; /* size of tgts array */
412 cfs_hash_t *lov_pools_hash_body; /* used for key access */
413 struct list_head lov_pool_list; /* used for sequential access */
414 struct proc_dir_entry *lov_pool_proc_entry;
415 enum lustre_sec_part lov_sp_me;
417 /* Cached LRU and unstable data from upper layer */
420 struct rw_semaphore lov_notify_lock;
423 struct lmv_tgt_desc {
424 struct obd_uuid ltd_uuid;
425 struct obd_export *ltd_exp;
427 struct mutex ltd_fid_mutex;
428 unsigned long ltd_active:1; /* target up for requests */
431 enum placement_policy {
432 PLACEMENT_CHAR_POLICY = 0,
433 PLACEMENT_NID_POLICY = 1,
434 PLACEMENT_INVAL_POLICY = 2,
438 typedef enum placement_policy placement_policy_t;
442 struct lu_client_fld lmv_fld;
444 placement_policy_t lmv_placement;
445 struct lmv_desc desc;
446 struct obd_uuid cluuid;
447 struct obd_export *exp;
448 struct proc_dir_entry *targets_proc_entry;
450 struct mutex init_mutex;
455 int max_def_cookiesize;
458 int tgts_size; /* size of tgts array */
459 struct lmv_tgt_desc **tgts;
461 struct obd_connect_data conn_data;
464 struct niobuf_local {
465 __u64 lnb_file_offset;
466 __u32 lnb_page_offset;
469 struct page *lnb_page;
474 #define LUSTRE_FLD_NAME "fld"
475 #define LUSTRE_SEQ_NAME "seq"
477 #define LUSTRE_MDD_NAME "mdd"
478 #define LUSTRE_OSD_LDISKFS_NAME "osd-ldiskfs"
479 #define LUSTRE_OSD_ZFS_NAME "osd-zfs"
480 #define LUSTRE_VVP_NAME "vvp"
481 #define LUSTRE_LMV_NAME "lmv"
482 #define LUSTRE_SLP_NAME "slp"
483 #define LUSTRE_LOD_NAME "lod"
484 #define LUSTRE_OSP_NAME "osp"
485 #define LUSTRE_LWP_NAME "lwp"
487 /* obd device type names */
488 /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */
489 #define LUSTRE_MDS_NAME "mds"
490 #define LUSTRE_MDT_NAME "mdt"
491 #define LUSTRE_MDC_NAME "mdc"
492 #define LUSTRE_OSS_NAME "ost" /* FIXME change name to oss */
493 #define LUSTRE_OST_NAME "obdfilter" /* FIXME change name to ost */
494 #define LUSTRE_OSC_NAME "osc"
495 #define LUSTRE_LOV_NAME "lov"
496 #define LUSTRE_MGS_NAME "mgs"
497 #define LUSTRE_MGC_NAME "mgc"
499 #define LUSTRE_ECHO_NAME "obdecho"
500 #define LUSTRE_ECHO_CLIENT_NAME "echo_client"
501 #define LUSTRE_QMT_NAME "qmt"
503 /* Constant obd names (post-rename) */
504 #define LUSTRE_MDS_OBDNAME "MDS"
505 #define LUSTRE_OSS_OBDNAME "OSS"
506 #define LUSTRE_MGS_OBDNAME "MGS"
507 #define LUSTRE_MGC_OBDNAME "MGC"
509 struct obd_trans_info {
511 /* Only used on the server side for tracking acks. */
512 struct oti_req_ack_lock {
513 struct lustre_handle lock;
517 struct llog_cookie oti_onecookie;
518 struct llog_cookie *oti_logcookies;
521 __u64 oti_pre_version;
525 * Events signalled through obd_notify() upcall-chain.
527 enum obd_notify_event {
530 /* Device connect start */
532 /* Device activated */
534 /* Device deactivated */
536 /* Device disconnected */
538 /* Connect data for import were changed */
541 OBD_NOTIFY_SYNC_NONBLOCK,
543 /* Configuration event */
545 /* Administratively deactivate/activate event */
546 OBD_NOTIFY_DEACTIVATE,
550 /* bit-mask flags for config events */
552 CONFIG_LOG = 0x1, /* finished processing config log */
553 CONFIG_SYNC = 0x2, /* mdt synced 1 ost */
554 CONFIG_TARGET = 0x4 /* one target is added */
558 * Data structure used to pass obd_notify()-event to non-obd listeners (llite
559 * and liblustre being main examples).
561 struct obd_notify_upcall {
562 int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
563 enum obd_notify_event ev, void *owner, void *data);
564 /* Opaque datum supplied by upper layer listener */
568 struct target_recovery_data {
569 svc_handler_t trd_recovery_handler;
570 pid_t trd_processing_task;
571 struct completion trd_starting;
572 struct completion trd_finishing;
575 struct obd_llog_group {
576 struct llog_ctxt *olg_ctxts[LLOG_MAX_CTXTS];
577 wait_queue_head_t olg_waitq;
579 struct mutex olg_cat_processing;
582 /* corresponds to one of the obd's */
583 #define OBD_DEVICE_MAGIC 0XAB5CD6EF
586 struct obd_type *obd_type;
589 /* common and UUID name of this device */
590 char obd_name[MAX_OBD_NAME];
591 struct obd_uuid obd_uuid;
593 struct lu_device *obd_lu_dev;
595 /* bitfield modification is protected by obd_dev_lock */
597 obd_attached:1, /* finished attach */
598 obd_set_up:1, /* finished setup */
599 obd_recovering:1, /* there are recoverable clients */
600 obd_abort_recovery:1, /* recovery expired */
601 obd_version_recov:1, /* obd uses version checking */
602 obd_replayable:1, /* recovery is enabled;
604 obd_no_transno:1, /* no committed-transno notification */
605 obd_no_recov:1, /* fail instead of retry messages */
606 obd_stopping:1, /* started cleanup */
607 obd_starting:1, /* started setup */
608 obd_force:1, /* cleanup with > 0 obd refcount */
609 obd_fail:1, /* cleanup with failover */
610 obd_no_conn:1, /* deny new connections */
611 obd_inactive:1, /* device active/inactive
612 * (for /proc/status only!!) */
613 obd_no_ir:1, /* no imperative recovery. */
614 obd_process_conf:1, /* device is processing mgs config */
615 obd_uses_nid_stats:1; /* maintain per-client OBD stats */
617 /* use separate field as it is set in interrupt to don't mess with
618 * protection of other bits using _bh lock */
619 unsigned long obd_recovery_expired:1;
620 /* uuid-export hash body */
621 cfs_hash_t *obd_uuid_hash;
622 /* nid-export hash body */
623 cfs_hash_t *obd_nid_hash;
625 cfs_hash_t *obd_nid_stats_hash;
626 struct list_head obd_nid_stats;
627 atomic_t obd_refcount;
628 struct list_head obd_exports;
629 struct list_head obd_unlinked_exports;
630 struct list_head obd_delayed_exports;
631 struct list_head obd_lwp_list;
633 spinlock_t obd_nid_lock;
634 struct ldlm_namespace *obd_namespace;
635 struct ptlrpc_client obd_ldlm_client; /* XXX OST/MDS only */
636 /* a spinlock is OK for what we do now, may need a semaphore later */
637 spinlock_t obd_dev_lock; /* protect OBD bitfield above */
638 struct mutex obd_dev_mutex;
639 __u64 obd_last_committed;
640 spinlock_t obd_osfs_lock;
641 struct obd_statfs obd_osfs; /* locked by obd_osfs_lock */
643 struct lvfs_run_ctxt obd_lvfs_ctxt;
644 struct obd_llog_group obd_olg; /* default llog group */
645 struct obd_device *obd_observer;
646 struct rw_semaphore obd_observer_link_sem;
647 struct obd_notify_upcall obd_upcall;
648 struct obd_export *obd_self_export;
649 struct obd_export *obd_lwp_export;
650 /* list of exports in LRU order, for ping evictor, with obd_dev_lock */
651 struct list_head obd_exports_timed;
652 time_t obd_eviction_timer; /* for ping evictor */
654 int obd_max_recoverable_clients;
655 atomic_t obd_connected_clients;
656 int obd_stale_clients;
657 /* this lock protects all recovery list_heads, timer and
658 * obd_next_recovery_transno value */
659 spinlock_t obd_recovery_task_lock;
660 __u64 obd_next_recovery_transno;
661 int obd_replayed_requests;
662 int obd_requests_queued_for_recovery;
663 wait_queue_head_t obd_next_transno_waitq;
664 /* protected by obd_recovery_task_lock */
665 struct timer_list obd_recovery_timer;
667 time_t obd_recovery_start;
668 /* seconds, for lprocfs_status */
669 time_t obd_recovery_end;
670 int obd_recovery_time_hard;
671 int obd_recovery_timeout;
672 int obd_recovery_ir_factor;
674 /* new recovery stuff from CMD2 */
675 struct target_recovery_data obd_recovery_data;
676 int obd_replayed_locks;
677 atomic_t obd_req_replay_clients;
678 atomic_t obd_lock_replay_clients;
679 /* all lists are protected by obd_recovery_task_lock */
680 struct list_head obd_req_replay_queue;
681 struct list_head obd_lock_replay_queue;
682 struct list_head obd_final_req_queue;
685 #ifdef HAVE_SERVER_SUPPORT
686 struct obd_device_target obt;
687 struct filter_obd filter;
689 struct echo_obd echo;
691 struct client_obd cli;
692 struct echo_client_obd echo_client;
696 /* Fields used by LProcFS */
697 unsigned int obd_cntr_base;
698 struct lprocfs_stats *obd_stats;
700 unsigned int obd_md_cntr_base;
701 struct lprocfs_stats *obd_md_stats;
703 struct proc_dir_entry *obd_proc_entry;
704 struct proc_dir_entry *obd_proc_exports_entry;
705 struct proc_dir_entry *obd_svc_procroot;
706 struct lprocfs_stats *obd_svc_stats;
707 struct lprocfs_seq_vars *obd_vars;
708 atomic_t obd_evict_inprogress;
709 wait_queue_head_t obd_evict_inprogress_waitq;
710 struct list_head obd_evict_list; /* protected with pet_lock */
713 * Ldlm pool part. Save last calculated SLV and Limit.
715 rwlock_t obd_pool_lock;
720 * A list of outstanding class_incref()'s against this obd. For
723 struct lu_ref obd_reference;
725 int obd_conn_inprogress;
728 enum obd_cleanup_stage {
729 /* Special case hack for MDS LOVs */
731 /* can be directly mapped to .ldto_device_fini() */
735 /* get/set_info keys */
736 #define KEY_ASYNC "async"
737 #define KEY_CAPA_KEY "capa_key"
738 #define KEY_CHANGELOG_CLEAR "changelog_clear"
739 #define KEY_FID2PATH "fid2path"
740 #define KEY_CHECKSUM "checksum"
741 #define KEY_CLEAR_FS "clear_fs"
742 #define KEY_CONN_DATA "conn_data"
743 #define KEY_EVICT_BY_NID "evict_by_nid"
744 #define KEY_FIEMAP "fiemap"
745 #define KEY_FLUSH_CTX "flush_ctx"
746 #define KEY_GRANT_SHRINK "grant_shrink"
747 #define KEY_HSM_COPYTOOL_SEND "hsm_send"
748 #define KEY_INIT_RECOV_BACKUP "init_recov_bk"
749 #define KEY_INTERMDS "inter_mds"
750 #define KEY_LAST_ID "last_id"
751 #define KEY_LAST_FID "last_fid"
752 #define KEY_LOCK_TO_STRIPE "lock_to_stripe"
753 #define KEY_LOVDESC "lovdesc"
754 #define KEY_MAX_EASIZE "max_easize"
755 #define KEY_DEFAULT_EASIZE "default_easize"
756 #define KEY_MAX_COOKIESIZE "max_cookiesize"
757 #define KEY_DEFAULT_COOKIESIZE "default_cookiesize"
758 #define KEY_MDS_CONN "mds_conn"
759 #define KEY_MGSSEC "mgssec"
760 #define KEY_NEXT_ID "next_id"
761 #define KEY_READ_ONLY "read-only"
762 #define KEY_REGISTER_TARGET "register_target"
763 #define KEY_SET_FS "set_fs"
764 #define KEY_TGT_COUNT "tgt_count"
765 /* KEY_SET_INFO in lustre_idl.h */
766 #define KEY_SPTLRPC_CONF "sptlrpc_conf"
767 #define KEY_CONNECT_FLAG "connect_flags"
769 #define KEY_CACHE_SET "cache_set"
770 #define KEY_CACHE_LRU_SHRINK "cache_lru_shrink"
771 #define KEY_OSP_CONNECTED "osp_connected"
775 /* /!\ must be coherent with include/linux/namei.h on patched kernel */
776 #define IT_OPEN (1 << 0)
777 #define IT_CREAT (1 << 1)
778 #define IT_READDIR (1 << 2)
779 #define IT_GETATTR (1 << 3)
780 #define IT_LOOKUP (1 << 4)
781 #define IT_UNLINK (1 << 5)
782 #define IT_TRUNC (1 << 6)
783 #define IT_GETXATTR (1 << 7)
784 #define IT_EXEC (1 << 8)
785 #define IT_PIN (1 << 9)
786 #define IT_LAYOUT (1 << 10)
787 #define IT_QUOTA_DQACQ (1 << 11)
788 #define IT_QUOTA_CONN (1 << 12)
789 #define IT_SETXATTR (1 << 13)
791 static inline int it_to_lock_mode(struct lookup_intent *it)
793 /* CREAT needs to be tested before open (both could be set) */
794 if (it->it_op & IT_CREAT)
796 else if (it->it_op & (IT_GETATTR | IT_OPEN | IT_LOOKUP |
799 else if (it->it_op & IT_READDIR)
801 else if (it->it_op & IT_GETXATTR)
803 else if (it->it_op & IT_SETXATTR)
806 LASSERTF(0, "Invalid it_op: %d\n", it->it_op);
811 struct lu_fid op_fid1; /* operation fid1 (usualy parent) */
812 struct lu_fid op_fid2; /* operation fid2 (usualy child) */
813 struct lu_fid op_fid3; /* 2 extra fids to find conflicting */
814 struct lu_fid op_fid4; /* to the operation locks. */
815 mdsno_t op_mds; /* what mds server open will go to */
816 struct lustre_handle op_handle;
817 obd_time op_mod_time;
821 struct lmv_stripe_md *op_mea1;
822 struct lmv_stripe_md *op_mea2;
823 __u32 op_suppgids[2];
830 /* iattr fields and blocks. */
831 struct iattr op_attr;
833 loff_t op_attr_blocks;
835 /* Size-on-MDS epoch and flags. */
840 struct obd_capa *op_capa1;
841 struct obd_capa *op_capa2;
843 /* Various operation flags. */
844 enum mds_op_bias op_bias;
846 /* Used by readdir */
849 /* used to transfer info between the stacks of MD client
850 * see enum op_cli_flags */
853 /* File object data version for HSM release, on client */
854 __u64 op_data_version;
855 struct lustre_handle op_lease_handle;
858 #define op_stripe_offset op_ioepoch
859 #define op_max_pages op_valid
862 int (*md_blocking_ast)(struct ldlm_lock *lock,
863 struct ldlm_lock_desc *desc,
864 void *data, int flag);
867 struct md_enqueue_info;
868 /* metadata stat-ahead */
869 typedef int (* md_enqueue_cb_t)(struct ptlrpc_request *req,
870 struct md_enqueue_info *minfo,
873 struct md_enqueue_info {
874 struct md_op_data mi_data;
875 struct lookup_intent mi_it;
876 struct lustre_handle mi_lockh;
877 struct inode *mi_dir;
878 md_enqueue_cb_t mi_cb;
880 unsigned int mi_generation;
884 struct module *o_owner;
885 int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
886 void *karg, void *uarg);
887 int (*o_get_info)(const struct lu_env *env, struct obd_export *,
888 __u32 keylen, void *key, __u32 *vallen, void *val,
889 struct lov_stripe_md *lsm);
890 int (*o_set_info_async)(const struct lu_env *, struct obd_export *,
891 __u32 keylen, void *key,
892 __u32 vallen, void *val,
893 struct ptlrpc_request_set *set);
894 int (*o_setup) (struct obd_device *dev, struct lustre_cfg *cfg);
895 int (*o_precleanup)(struct obd_device *dev,
896 enum obd_cleanup_stage cleanup_stage);
897 int (*o_cleanup)(struct obd_device *dev);
898 int (*o_process_config)(struct obd_device *dev, obd_count len,
900 int (*o_postrecov)(struct obd_device *dev);
901 int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
903 int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
904 /* connect to the target device with given connection
905 * data. @ocd->ocd_connect_flags is modified to reflect flags actually
906 * granted by the target, which are guaranteed to be a subset of flags
907 * asked for. If @ocd == NULL, use default parameters. */
908 int (*o_connect)(const struct lu_env *env,
909 struct obd_export **exp, struct obd_device *src,
910 struct obd_uuid *cluuid, struct obd_connect_data *ocd,
912 int (*o_reconnect)(const struct lu_env *env,
913 struct obd_export *exp, struct obd_device *src,
914 struct obd_uuid *cluuid,
915 struct obd_connect_data *ocd,
917 int (*o_disconnect)(struct obd_export *exp);
919 /* Initialize/finalize fids infrastructure. */
920 int (*o_fid_init)(struct obd_device *obd,
921 struct obd_export *exp, enum lu_cli_type type);
922 int (*o_fid_fini)(struct obd_device *obd);
924 /* Allocate new fid according to passed @hint. */
925 int (*o_fid_alloc)(const struct lu_env *env, struct obd_export *exp,
926 struct lu_fid *fid, struct md_op_data *op_data);
929 * Object with @fid is getting deleted, we may want to do something
932 int (*o_statfs)(const struct lu_env *, struct obd_export *exp,
933 struct obd_statfs *osfs, __u64 max_age, __u32 flags);
934 int (*o_statfs_async)(struct obd_export *exp, struct obd_info *oinfo,
935 __u64 max_age, struct ptlrpc_request_set *set);
936 int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
937 struct lov_stripe_md *mem_src);
938 int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
939 struct lov_mds_md *disk_src, int disk_len);
940 int (*o_create)(const struct lu_env *env, struct obd_export *exp,
941 struct obdo *oa, struct lov_stripe_md **ea,
942 struct obd_trans_info *oti);
943 int (*o_destroy)(const struct lu_env *env, struct obd_export *exp,
944 struct obdo *oa, struct lov_stripe_md *ea,
945 struct obd_trans_info *oti, struct obd_export *md_exp,
947 int (*o_setattr)(const struct lu_env *, struct obd_export *exp,
948 struct obd_info *oinfo, struct obd_trans_info *oti);
949 int (*o_setattr_async)(struct obd_export *exp, struct obd_info *oinfo,
950 struct obd_trans_info *oti,
951 struct ptlrpc_request_set *rqset);
952 int (*o_getattr)(const struct lu_env *env, struct obd_export *exp,
953 struct obd_info *oinfo);
954 int (*o_getattr_async)(struct obd_export *exp, struct obd_info *oinfo,
955 struct ptlrpc_request_set *set);
956 int (*o_preprw)(const struct lu_env *env, int cmd,
957 struct obd_export *exp, struct obdo *oa, int objcount,
958 struct obd_ioobj *obj, struct niobuf_remote *remote,
959 int *nr_pages, struct niobuf_local *local,
960 struct obd_trans_info *oti, struct lustre_capa *capa);
961 int (*o_commitrw)(const struct lu_env *env, int cmd,
962 struct obd_export *exp, struct obdo *oa,
963 int objcount, struct obd_ioobj *obj,
964 struct niobuf_remote *remote, int pages,
965 struct niobuf_local *local,
966 struct obd_trans_info *oti, int rc);
967 int (*o_change_cbdata)(struct obd_export *, struct lov_stripe_md *,
968 ldlm_iterator_t it, void *data);
969 int (*o_find_cbdata)(struct obd_export *, struct lov_stripe_md *,
970 ldlm_iterator_t it, void *data);
971 int (*o_init_export)(struct obd_export *exp);
972 int (*o_destroy_export)(struct obd_export *exp);
974 /* llog related obd_methods */
975 int (*o_llog_init)(struct obd_device *obd, struct obd_llog_group *grp,
976 struct obd_device *disk_obd, int *idx);
977 int (*o_llog_finish)(struct obd_device *obd, int count);
979 int (*o_import_event)(struct obd_device *, struct obd_import *,
980 enum obd_import_event);
982 int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
983 enum obd_notify_event ev, void *data);
985 int (*o_health_check)(const struct lu_env *env, struct obd_device *);
986 struct obd_uuid *(*o_get_uuid) (struct obd_export *exp);
989 int (*o_quotacheck)(struct obd_device *, struct obd_export *,
990 struct obd_quotactl *);
991 int (*o_quotactl)(struct obd_device *, struct obd_export *,
992 struct obd_quotactl *);
994 int (*o_ping)(const struct lu_env *, struct obd_export *exp);
997 int (*o_pool_new)(struct obd_device *obd, char *poolname);
998 int (*o_pool_del)(struct obd_device *obd, char *poolname);
999 int (*o_pool_add)(struct obd_device *obd, char *poolname,
1001 int (*o_pool_rem)(struct obd_device *obd, char *poolname,
1003 void (*o_getref)(struct obd_device *obd);
1004 void (*o_putref)(struct obd_device *obd);
1006 * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
1007 * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
1008 * Also, add a wrapper function in include/linux/obd_class.h. */
1011 /* lmv structures */
1013 struct mdt_body *body;
1014 struct lov_stripe_md *lsm;
1015 struct lmv_stripe_md *lmv;
1016 #ifdef CONFIG_FS_POSIX_ACL
1017 struct posix_acl *posix_acl;
1019 struct mdt_remote_perm *remote_perm;
1020 struct obd_capa *mds_capa;
1021 struct obd_capa *oss_capa;
1024 struct md_open_data {
1025 struct obd_client_handle *mod_och;
1026 struct ptlrpc_request *mod_open_req;
1027 struct ptlrpc_request *mod_close_req;
1028 atomic_t mod_refcount;
1032 struct lookup_intent;
1036 /* Every operation from MD_STATS_FIRST_OP up to and including
1037 * MD_STATS_LAST_OP will be counted by EXP_MD_OP_INCREMENT()
1038 * and will appear in /proc/fs/lustre/{lmv,mdc}/.../md_stats.
1039 * Operations after MD_STATS_LAST_OP are excluded from stats.
1040 * There are a few reasons for doing this: we prune the 17
1041 * counters which will be of minimal use in understanding
1042 * metadata utilization, we save memory by allocating 15
1043 * instead of 32 counters, we save cycles by not counting.
1045 * MD_STATS_FIRST_OP must be the first member of md_ops.
1047 #define MD_STATS_FIRST_OP m_close
1048 int (*m_close)(struct obd_export *, struct md_op_data *,
1049 struct md_open_data *, struct ptlrpc_request **);
1051 int (*m_create)(struct obd_export *, struct md_op_data *,
1052 const void *, int, int, __u32, __u32, cfs_cap_t,
1053 __u64, struct ptlrpc_request **);
1055 int (*m_enqueue)(struct obd_export *, struct ldlm_enqueue_info *,
1056 const union ldlm_policy_data *,
1057 struct lookup_intent *, struct md_op_data *,
1058 struct lustre_handle *, __u64);
1060 int (*m_getattr)(struct obd_export *, struct md_op_data *,
1061 struct ptlrpc_request **);
1063 int (*m_intent_lock)(struct obd_export *, struct md_op_data *,
1064 struct lookup_intent *,
1065 struct ptlrpc_request **,
1066 ldlm_blocking_callback, __u64);
1068 int (*m_link)(struct obd_export *, struct md_op_data *,
1069 struct ptlrpc_request **);
1071 int (*m_rename)(struct obd_export *, struct md_op_data *,
1072 const char *, int, const char *, int,
1073 struct ptlrpc_request **);
1075 int (*m_setattr)(struct obd_export *, struct md_op_data *, void *,
1076 int , void *, int, struct ptlrpc_request **,
1077 struct md_open_data **mod);
1079 int (*m_fsync)(struct obd_export *, const struct lu_fid *,
1080 struct obd_capa *, struct ptlrpc_request **);
1082 int (*m_read_page)(struct obd_export *, struct md_op_data *,
1083 struct md_callback *cb_op, __u64 hash_offset,
1084 struct page **ppage);
1086 int (*m_unlink)(struct obd_export *, struct md_op_data *,
1087 struct ptlrpc_request **);
1089 int (*m_setxattr)(struct obd_export *, const struct lu_fid *,
1090 struct obd_capa *, obd_valid, const char *,
1091 const char *, int, int, int, __u32,
1092 struct ptlrpc_request **);
1094 int (*m_getxattr)(struct obd_export *, const struct lu_fid *,
1095 struct obd_capa *, obd_valid, const char *,
1096 const char *, int, int, int,
1097 struct ptlrpc_request **);
1099 int (*m_intent_getattr_async)(struct obd_export *,
1100 struct md_enqueue_info *,
1101 struct ldlm_enqueue_info *);
1103 int (*m_revalidate_lock)(struct obd_export *, struct lookup_intent *,
1104 struct lu_fid *, __u64 *bits);
1106 #define MD_STATS_LAST_OP m_revalidate_lock
1108 int (*m_getstatus)(struct obd_export *, struct lu_fid *,
1109 struct obd_capa **);
1111 int (*m_null_inode)(struct obd_export *, const struct lu_fid *);
1113 int (*m_find_cbdata)(struct obd_export *, const struct lu_fid *,
1114 ldlm_iterator_t, void *);
1116 int (*m_done_writing)(struct obd_export *, struct md_op_data *,
1117 struct md_open_data *);
1119 int (*m_getattr_name)(struct obd_export *, struct md_op_data *,
1120 struct ptlrpc_request **);
1122 int (*m_init_ea_size)(struct obd_export *, int, int, int, int);
1124 int (*m_get_lustre_md)(struct obd_export *, struct ptlrpc_request *,
1125 struct obd_export *, struct obd_export *,
1126 struct lustre_md *);
1128 int (*m_free_lustre_md)(struct obd_export *, struct lustre_md *);
1130 int (*m_merge_attr)(struct obd_export *,
1131 const struct lmv_stripe_md *lsm,
1132 struct cl_attr *attr);
1134 int (*m_update_lsm_md)(struct obd_export *, struct lmv_stripe_md *lsm,
1135 struct mdt_body *, ldlm_blocking_callback);
1137 int (*m_set_open_replay_data)(struct obd_export *,
1138 struct obd_client_handle *,
1139 struct lookup_intent *);
1141 int (*m_clear_open_replay_data)(struct obd_export *,
1142 struct obd_client_handle *);
1144 int (*m_set_lock_data)(struct obd_export *, __u64 *, void *, __u64 *);
1146 ldlm_mode_t (*m_lock_match)(struct obd_export *, __u64,
1147 const struct lu_fid *, ldlm_type_t,
1148 ldlm_policy_data_t *, ldlm_mode_t,
1149 struct lustre_handle *);
1151 int (*m_cancel_unused)(struct obd_export *, const struct lu_fid *,
1152 ldlm_policy_data_t *, ldlm_mode_t,
1153 ldlm_cancel_flags_t flags, void *opaque);
1155 int (*m_renew_capa)(struct obd_export *, struct obd_capa *oc,
1156 renew_capa_cb_t cb);
1158 int (*m_unpack_capa)(struct obd_export *, struct ptlrpc_request *,
1159 const struct req_msg_field *, struct obd_capa **);
1161 int (*m_get_remote_perm)(struct obd_export *, const struct lu_fid *,
1162 struct obd_capa *, __u32,
1163 struct ptlrpc_request **);
1165 int (*m_get_fid_from_lsm)(struct obd_export *,
1166 const struct lmv_stripe_md *,
1167 const char *name, int namelen,
1168 struct lu_fid *fid);
1171 struct lsm_operations {
1172 void (*lsm_free)(struct lov_stripe_md *);
1173 int (*lsm_destroy)(struct lov_stripe_md *, struct obdo *oa,
1174 struct obd_export *md_exp);
1175 void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *, obd_off *,
1177 void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *, obd_off *,
1179 int (*lsm_lmm_verify) (struct lov_mds_md *lmm, int lmm_bytes,
1180 __u16 *stripe_count);
1181 int (*lsm_unpackmd) (struct lov_obd *lov, struct lov_stripe_md *lsm,
1182 struct lov_mds_md *lmm);
1185 extern const struct lsm_operations lsm_v1_ops;
1186 extern const struct lsm_operations lsm_v3_ops;
1187 static inline const struct lsm_operations *lsm_op_find(int magic)
1195 CERROR("Cannot recognize lsm_magic %08x\n", magic);
1200 static inline struct md_open_data *obd_mod_alloc(void)
1202 struct md_open_data *mod;
1206 atomic_set(&mod->mod_refcount, 1);
1210 #define obd_mod_get(mod) atomic_inc(&(mod)->mod_refcount)
1211 #define obd_mod_put(mod) \
1213 if (atomic_dec_and_test(&(mod)->mod_refcount)) { \
1214 if ((mod)->mod_open_req) \
1215 ptlrpc_req_finished((mod)->mod_open_req); \
1216 OBD_FREE_PTR(mod); \
1220 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
1221 void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent);
1223 /* return 1 if client should be resend request */
1224 static inline int client_should_resend(int resend, struct client_obd *cli)
1226 return atomic_read(&cli->cl_resends) ?
1227 atomic_read(&cli->cl_resends) > resend : 1;
1231 * Return device name for this device
1233 * XXX: lu_device is declared before obd_device, while a pointer pointing
1234 * back to obd_device in lu_device, so this helper function defines here
1235 * instead of in lu_object.h
1237 static inline const char *lu_dev_name(const struct lu_device *lu_dev)
1239 return lu_dev->ld_obd->obd_name;
1242 static inline bool filename_is_volatile(const char *name, int namelen, int *idx)
1247 if (strncmp(name, LUSTRE_VOLATILE_HDR, LUSTRE_VOLATILE_HDR_LEN) != 0)
1250 /* caller does not care of idx */
1254 /* volatile file, the MDT can be set from name */
1255 /* name format is LUSTRE_VOLATILE_HDR:[idx]: */
1256 /* if no MDT is specified, use std way */
1257 if (namelen < LUSTRE_VOLATILE_HDR_LEN + 2)
1259 /* test for no MDT idx case */
1260 if ((*(name + LUSTRE_VOLATILE_HDR_LEN) == ':') &&
1261 (*(name + LUSTRE_VOLATILE_HDR_LEN + 1) == ':')) {
1265 /* we have an idx, read it */
1266 start = name + LUSTRE_VOLATILE_HDR_LEN + 1;
1267 *idx = strtoul(start, &end, 16);
1269 * no digit, no trailing :, negative value
1271 if (((*idx == 0) && (end == start)) ||
1272 (*end != ':') || (*idx < 0))
1277 /* bad format of mdt idx, we cannot return an error
1278 * to caller so we use hash algo */
1279 CERROR("Bad volatile file name format: %s\n",
1280 name + LUSTRE_VOLATILE_HDR_LEN);
1284 static inline int cli_brw_size(struct obd_device *obd)
1286 LASSERT(obd != NULL);
1287 return obd->u.cli.cl_max_pages_per_rpc << PAGE_CACHE_SHIFT;
1290 /* when RPC size or the max RPCs in flight is increased, the max dirty pages
1291 * of the client should be increased accordingly to avoid sending fragmented
1292 * RPCs over the network when the client runs out of the maximum dirty space
1293 * when so many RPCs are being generated.
1295 static inline void client_adjust_max_dirty(struct client_obd *cli)
1298 if (cli->cl_dirty_max_pages <= 0)
1299 cli->cl_dirty_max_pages = (OSC_MAX_DIRTY_DEFAULT * 1024 * 1024)
1300 >> PAGE_CACHE_SHIFT;
1302 long dirty_max = cli->cl_max_rpcs_in_flight *
1303 cli->cl_max_pages_per_rpc;
1305 if (dirty_max > cli->cl_dirty_max_pages)
1306 cli->cl_dirty_max_pages = dirty_max;
1309 if (cli->cl_dirty_max_pages > totalram_pages / 8)
1310 cli->cl_dirty_max_pages = totalram_pages / 8;
1313 #endif /* __OBD_H */