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, 2014, 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/spinlock.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_handles.h>
54 #include <lustre_intent.h>
55 #include <lustre_capa.h>
58 #define MAX_OBD_DEVICES 8192
66 struct lov_oinfo { /* per-stripe data structure */
67 struct ost_id loi_oi; /* object ID/Sequence on the target OST */
68 int loi_ost_idx; /* OST stripe index in lov_tgt_desc->tgts */
69 int loi_ost_gen; /* generation of this loi_ost_idx */
71 unsigned long loi_kms_valid:1;
72 __u64 loi_kms; /* known minimum size */
73 struct ost_lvb loi_lvb;
74 struct osc_async_rc loi_ar;
77 static inline void loi_kms_set(struct lov_oinfo *oinfo, __u64 kms)
80 oinfo->loi_kms_valid = 1;
83 static inline void loi_init(struct lov_oinfo *loi)
87 /* If we are unable to get the maximum object size from the OST in
88 * ocd_maxbytes using OBD_CONNECT_MAXBYTES, then we fall back to using
89 * the old maximum object size from ext3. */
90 #define LUSTRE_EXT3_STRIPE_MAXBYTES 0x1fffffff000ULL
92 struct lov_stripe_md {
95 pid_t lsm_lock_owner; /* debugging */
97 /* maximum possible file size, might change as OSTs status changes,
98 * e.g. disconnected, deactivated */
100 struct ost_id lsm_oi;
102 __u32 lsm_stripe_size;
103 __u32 lsm_pattern; /* RAID0, RAID1, released, ... */
104 __u16 lsm_stripe_count;
105 __u16 lsm_layout_gen;
106 char lsm_pool_name[LOV_MAXPOOLNAME + 1];
107 struct lov_oinfo *lsm_oinfo[0];
110 static inline bool lsm_is_released(struct lov_stripe_md *lsm)
112 return !!(lsm->lsm_pattern & LOV_PATTERN_F_RELEASED);
115 static inline bool lsm_has_objects(struct lov_stripe_md *lsm)
119 if (lsm_is_released(lsm))
124 static inline int lov_stripe_md_size(unsigned int stripe_count)
126 struct lov_stripe_md lsm;
128 return sizeof(lsm) + stripe_count * sizeof(lsm.lsm_oinfo[0]);
133 typedef int (*obd_enqueue_update_f)(void *cookie, int rc);
135 /* obd info for a particular level (lov, osc). */
137 /* OBD_STATFS_* flags */
139 /* statfs data specific for every OSC, if needed at all. */
140 struct obd_statfs *oi_osfs;
141 /* An update callback which is called to update some data on upper
142 * level. E.g. it is used for update lsm->lsm_oinfo at every received
143 * request in osc level for enqueue requests. It is also possible to
144 * update some caller data from LOV layer if needed. */
145 obd_enqueue_update_f oi_cb_up;
149 struct list_head typ_chain;
150 struct obd_ops *typ_dt_ops;
151 struct md_ops *typ_md_ops;
152 struct proc_dir_entry *typ_procroot;
153 struct proc_dir_entry *typ_procsym;
154 __u32 typ_sym_filter;
157 struct lu_device_type *typ_lu;
158 spinlock_t obd_type_lock;
168 struct timeout_item {
169 enum timeout_event ti_event;
170 cfs_time_t ti_timeout;
173 struct list_head ti_obd_list;
174 struct list_head ti_chain;
177 #define OBD_MAX_RIF_DEFAULT 8
178 #define OBD_MAX_RIF_MAX 512
179 #define OSC_MAX_RIF_MAX 256
180 #define OSC_MAX_DIRTY_DEFAULT (OBD_MAX_RIF_DEFAULT * 4)
181 #define OSC_MAX_DIRTY_MB_MAX 2048 /* arbitrary, but < MAX_LONG bytes */
182 #define OSC_DEFAULT_RESENDS 10
184 /* possible values for fo_sync_lock_cancel */
186 NEVER_SYNC_ON_CANCEL = 0,
187 BLOCKING_SYNC_ON_CANCEL = 1,
188 ALWAYS_SYNC_ON_CANCEL = 2,
189 NUM_SYNC_ON_CANCEL_STATES
193 * Limit reply buffer size for striping data to one x86_64 page. This
194 * value is chosen to fit the striping data for common use cases while
195 * staying well below the limit at which the buffer must be backed by
196 * vmalloc(). Excessive use of vmalloc() may cause spinlock contention
199 #define OBD_MAX_DEFAULT_EA_SIZE 4096
204 struct rw_semaphore cl_sem;
205 struct obd_uuid cl_target_uuid;
206 struct obd_import *cl_import; /* ptlrpc connection state */
207 size_t cl_conn_count;
209 /* Cache maximum and default values for easize. This is
210 * strictly a performance optimization to minimize calls to
211 * obd_size_diskmd(). The default values are used to calculate the
212 * initial size of a request buffer. The ptlrpc layer will resize the
213 * buffer as needed to accommodate a larger reply from the
214 * server. The default values should be small enough to avoid wasted
215 * memory and excessive use of vmalloc(), yet large enough to avoid
216 * reallocating the buffer in the common use case. */
218 /* Default EA size for striping attributes. It is initialized at
219 * mount-time based on the default stripe width of the filesystem,
220 * then it tracks the largest observed EA size advertised by
221 * the MDT, up to a maximum value of OBD_MAX_DEFAULT_EA_SIZE. */
222 __u32 cl_default_mds_easize;
224 /* Maximum possible EA size computed at mount-time based on
225 * the number of OSTs in the filesystem. May be increased at
226 * run-time if a larger observed size is advertised by the MDT. */
227 __u32 cl_max_mds_easize;
229 enum lustre_sec_part cl_sp_me;
230 enum lustre_sec_part cl_sp_to;
231 struct sptlrpc_flavor cl_flvr_mgc; /* fixed flavor of mgc->mgs */
233 /* the grant values are protected by loi_list_lock below */
234 unsigned long cl_dirty_pages; /* all _dirty_ in pages */
235 unsigned long cl_dirty_max_pages; /* allowed w/o rpc */
236 unsigned long cl_dirty_transit; /* dirty synchronous */
237 unsigned long cl_avail_grant; /* bytes of credit for ost */
238 unsigned long cl_lost_grant; /* lost credits (trunc) */
240 /* since we allocate grant by blocks, we don't know how many grant will
241 * be used to add a page into cache. As a solution, we reserve maximum
242 * grant before trying to dirty a page and unreserve the rest.
243 * See osc_{reserve|unreserve}_grant for details. */
244 long cl_reserved_grant;
245 struct list_head cl_cache_waiters; /* waiting for cache/grant */
246 cfs_time_t cl_next_shrink_grant; /* jiffies */
247 struct list_head cl_grant_shrink_list; /* Timeout event list */
248 int cl_grant_shrink_interval; /* seconds */
250 /* A chunk is an optimal size used by osc_extent to determine
251 * the extent size. A chunk is max(PAGE_CACHE_SIZE, OST block size) */
253 unsigned int cl_extent_tax; /* extent overhead, by bytes */
255 /* keep track of objects that have lois that contain pages which
256 * have been queued for async brw. this lock also protects the
257 * lists of osc_client_pages that hang off of the loi */
259 * ->cl_loi_list_lock protects consistency of
260 * ->cl_loi_{ready,read,write}_list. ->ap_make_ready() and
261 * ->ap_completion() call-backs are executed under this lock. As we
262 * cannot guarantee that these call-backs never block on all platforms
263 * (as a matter of fact they do block on Mac OS X), type of
264 * ->cl_loi_list_lock is platform dependent: it's a spin-lock on Linux
265 * and blocking mutex on Mac OS X. (Alternative is to make this lock
266 * blocking everywhere, but we don't want to slow down fast-path of
267 * our main platform.)
269 * NB by Jinshan: though field names are still _loi_, but actually
270 * osc_object{}s are in the list.
272 spinlock_t cl_loi_list_lock;
273 struct list_head cl_loi_ready_list;
274 struct list_head cl_loi_hp_ready_list;
275 struct list_head cl_loi_write_list;
276 struct list_head cl_loi_read_list;
277 __u32 cl_r_in_flight;
278 __u32 cl_w_in_flight;
279 /* just a sum of the loi/lop pending numbers to be exported by /proc */
280 atomic_t cl_pending_w_pages;
281 atomic_t cl_pending_r_pages;
282 __u32 cl_max_pages_per_rpc;
283 __u32 cl_max_rpcs_in_flight;
284 struct obd_histogram cl_read_rpc_hist;
285 struct obd_histogram cl_write_rpc_hist;
286 struct obd_histogram cl_read_page_hist;
287 struct obd_histogram cl_write_page_hist;
288 struct obd_histogram cl_read_offset_hist;
289 struct obd_histogram cl_write_offset_hist;
291 /* lru for osc caching pages */
292 struct cl_client_cache *cl_cache;
293 struct list_head cl_lru_osc; /* member of cl_cache->ccc_lru */
294 atomic_long_t *cl_lru_left;
295 atomic_long_t cl_lru_busy;
296 atomic_long_t cl_lru_in_list;
297 atomic_long_t cl_unstable_count;
298 struct list_head cl_lru_list; /* lru page list */
299 spinlock_t cl_lru_list_lock; /* page list protector */
300 atomic_t cl_lru_shrinkers;
302 /* number of in flight destroy rpcs is limited to max_rpcs_in_flight */
303 atomic_t cl_destroy_in_flight;
304 wait_queue_head_t cl_destroy_waitq;
306 struct mdc_rpc_lock *cl_rpc_lock;
307 struct mdc_rpc_lock *cl_close_lock;
309 /* modify rpcs in flight
310 * currently used for metadata only */
311 spinlock_t cl_mod_rpcs_lock;
312 __u16 cl_max_mod_rpcs_in_flight;
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 /* sequence manager */
332 struct lu_client_seq *cl_seq;
334 atomic_t cl_resends; /* resend count */
336 /* ptlrpc work for writeback in ptlrpcd context */
337 void *cl_writeback_work;
339 /* hash tables for osc_quota_info */
340 cfs_hash_t *cl_quota_hash[MAXQUOTAS];
342 #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
349 struct echo_client_obd {
350 struct obd_export *ec_exp; /* the local connection to osc/lov */
352 struct list_head ec_objects;
353 struct list_head ec_locks;
357 /* Generic subset of OSTs */
359 __u32 *op_array; /* array of index of
361 unsigned int op_count; /* number of OSTs in the array */
362 unsigned int op_size; /* allocated size of lp_array */
363 struct rw_semaphore op_rw_sem; /* to protect ost_pool use */
366 /* allow statfs data caching for 1 second */
367 #define OBD_STATFS_CACHE_SECONDS 1
369 struct lov_tgt_desc {
370 struct list_head ltd_kill;
371 struct obd_uuid ltd_uuid;
372 struct obd_device *ltd_obd;
373 struct obd_export *ltd_exp;
375 __u32 ltd_index; /* index in lov_obd->tgts */
376 unsigned long ltd_active:1,/* is this target up for requests */
377 ltd_activate:1,/* should target be activated */
378 ltd_reap:1; /* should this target be deleted */
382 struct lov_desc desc;
383 struct lov_tgt_desc **lov_tgts; /* sparse array */
384 struct ost_pool lov_packed; /* all OSTs in a packed
386 struct mutex lov_lock;
387 struct obd_connect_data lov_ocd;
388 struct proc_dir_entry *targets_proc_entry;
389 atomic_t lov_refcount;
390 __u32 lov_death_row; /* tgts scheduled to be deleted */
391 __u32 lov_tgt_size; /* size of tgts array */
394 cfs_hash_t *lov_pools_hash_body; /* used for key access */
395 struct list_head lov_pool_list; /* used for sequential access */
396 struct proc_dir_entry *lov_pool_proc_entry;
397 enum lustre_sec_part lov_sp_me;
399 /* Cached LRU and unstable data from upper layer */
400 struct cl_client_cache *lov_cache;
402 struct rw_semaphore lov_notify_lock;
405 struct lmv_tgt_desc {
406 struct obd_uuid ltd_uuid;
407 struct obd_export *ltd_exp;
409 struct mutex ltd_fid_mutex;
410 unsigned long ltd_active:1; /* target up for requests */
413 enum placement_policy {
414 PLACEMENT_CHAR_POLICY = 0,
415 PLACEMENT_NID_POLICY = 1,
416 PLACEMENT_INVAL_POLICY = 2,
420 typedef enum placement_policy placement_policy_t;
424 struct lu_client_fld lmv_fld;
426 placement_policy_t lmv_placement;
427 struct lmv_desc desc;
428 struct obd_uuid cluuid;
429 struct obd_export *exp;
430 struct proc_dir_entry *targets_proc_entry;
432 struct mutex lmv_init_mutex;
437 __u32 tgts_size; /* size of tgts array */
438 struct lmv_tgt_desc **tgts;
440 struct obd_connect_data conn_data;
443 struct niobuf_local {
444 __u64 lnb_file_offset;
445 __u32 lnb_page_offset;
448 struct page *lnb_page;
453 #define LUSTRE_FLD_NAME "fld"
454 #define LUSTRE_SEQ_NAME "seq"
456 #define LUSTRE_MDD_NAME "mdd"
457 #define LUSTRE_OSD_LDISKFS_NAME "osd-ldiskfs"
458 #define LUSTRE_OSD_ZFS_NAME "osd-zfs"
459 #define LUSTRE_VVP_NAME "vvp"
460 #define LUSTRE_LMV_NAME "lmv"
461 #define LUSTRE_SLP_NAME "slp"
462 #define LUSTRE_LOD_NAME "lod"
463 #define LUSTRE_OSP_NAME "osp"
464 #define LUSTRE_LWP_NAME "lwp"
466 /* obd device type names */
467 /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */
468 #define LUSTRE_MDS_NAME "mds"
469 #define LUSTRE_MDT_NAME "mdt"
470 #define LUSTRE_MDC_NAME "mdc"
471 #define LUSTRE_OSS_NAME "ost" /* FIXME change name to oss */
472 #define LUSTRE_OST_NAME "obdfilter" /* FIXME change name to ost */
473 #define LUSTRE_OSC_NAME "osc"
474 #define LUSTRE_LOV_NAME "lov"
475 #define LUSTRE_MGS_NAME "mgs"
476 #define LUSTRE_MGC_NAME "mgc"
478 #define LUSTRE_ECHO_NAME "obdecho"
479 #define LUSTRE_ECHO_CLIENT_NAME "echo_client"
480 #define LUSTRE_QMT_NAME "qmt"
482 /* Constant obd names (post-rename) */
483 #define LUSTRE_MDS_OBDNAME "MDS"
484 #define LUSTRE_OSS_OBDNAME "OSS"
485 #define LUSTRE_MGS_OBDNAME "MGS"
486 #define LUSTRE_MGC_OBDNAME "MGC"
489 * Events signalled through obd_notify() upcall-chain.
491 enum obd_notify_event {
494 /* Device connect start */
496 /* Device activated */
498 /* Device deactivated */
500 /* Device disconnected */
502 /* Connect data for import were changed */
505 OBD_NOTIFY_SYNC_NONBLOCK,
507 /* Configuration event */
509 /* Administratively deactivate/activate event */
510 OBD_NOTIFY_DEACTIVATE,
514 /* bit-mask flags for config events */
516 CONFIG_LOG = 0x1, /* finished processing config log */
517 CONFIG_SYNC = 0x2, /* mdt synced 1 ost */
518 CONFIG_TARGET = 0x4 /* one target is added */
522 * Data structure used to pass obd_notify()-event to non-obd listeners (llite
523 * and liblustre being main examples).
525 struct obd_notify_upcall {
526 int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
527 enum obd_notify_event ev, void *owner, void *data);
528 /* Opaque datum supplied by upper layer listener */
532 struct target_recovery_data {
533 svc_handler_t trd_recovery_handler;
534 pid_t trd_processing_task;
535 struct completion trd_starting;
536 struct completion trd_finishing;
539 struct obd_llog_group {
540 struct llog_ctxt *olg_ctxts[LLOG_MAX_CTXTS];
541 wait_queue_head_t olg_waitq;
543 struct mutex olg_cat_processing;
546 /* corresponds to one of the obd's */
547 #define OBD_DEVICE_MAGIC 0XAB5CD6EF
550 struct obd_type *obd_type;
553 /* common and UUID name of this device */
554 char obd_name[MAX_OBD_NAME];
555 struct obd_uuid obd_uuid;
557 struct lu_device *obd_lu_dev;
559 /* bitfield modification is protected by obd_dev_lock */
561 obd_attached:1, /* finished attach */
562 obd_set_up:1, /* finished setup */
563 obd_recovering:1, /* there are recoverable clients */
564 obd_abort_recovery:1, /* recovery expired */
565 obd_version_recov:1, /* obd uses version checking */
566 obd_replayable:1, /* recovery is enabled;
568 obd_no_transno:1, /* no committed-transno notification */
569 obd_no_recov:1, /* fail instead of retry messages */
570 obd_stopping:1, /* started cleanup */
571 obd_starting:1, /* started setup */
572 obd_force:1, /* cleanup with > 0 obd refcount */
573 obd_fail:1, /* cleanup with failover */
574 obd_no_conn:1, /* deny new connections */
575 obd_inactive:1, /* device active/inactive
576 * (for /proc/status only!!) */
577 obd_no_ir:1, /* no imperative recovery. */
578 obd_process_conf:1, /* device is processing mgs config */
579 obd_uses_nid_stats:1; /* maintain per-client OBD stats */
581 /* use separate field as it is set in interrupt to don't mess with
582 * protection of other bits using _bh lock */
583 unsigned long obd_recovery_expired:1;
584 /* uuid-export hash body */
585 cfs_hash_t *obd_uuid_hash;
586 /* nid-export hash body */
587 cfs_hash_t *obd_nid_hash;
589 cfs_hash_t *obd_nid_stats_hash;
590 struct list_head obd_nid_stats;
591 atomic_t obd_refcount;
592 struct list_head obd_exports;
593 struct list_head obd_unlinked_exports;
594 struct list_head obd_delayed_exports;
595 struct list_head obd_lwp_list;
597 spinlock_t obd_nid_lock;
598 struct ldlm_namespace *obd_namespace;
599 struct ptlrpc_client obd_ldlm_client; /* XXX OST/MDS only */
600 /* a spinlock is OK for what we do now, may need a semaphore later */
601 spinlock_t obd_dev_lock; /* protect OBD bitfield above */
602 struct mutex obd_dev_mutex;
603 __u64 obd_last_committed;
604 spinlock_t obd_osfs_lock;
605 struct obd_statfs obd_osfs; /* locked by obd_osfs_lock */
607 struct lvfs_run_ctxt obd_lvfs_ctxt;
608 struct obd_llog_group obd_olg; /* default llog group */
609 struct obd_device *obd_observer;
610 struct rw_semaphore obd_observer_link_sem;
611 struct obd_notify_upcall obd_upcall;
612 struct obd_export *obd_self_export;
613 struct obd_export *obd_lwp_export;
614 /* list of exports in LRU order, for ping evictor, with obd_dev_lock */
615 struct list_head obd_exports_timed;
616 time_t obd_eviction_timer; /* for ping evictor */
618 int obd_max_recoverable_clients;
619 atomic_t obd_connected_clients;
620 int obd_stale_clients;
621 /* this lock protects all recovery list_heads, timer and
622 * obd_next_recovery_transno value */
623 spinlock_t obd_recovery_task_lock;
624 __u64 obd_next_recovery_transno;
625 int obd_replayed_requests;
626 int obd_requests_queued_for_recovery;
627 wait_queue_head_t obd_next_transno_waitq;
628 /* protected by obd_recovery_task_lock */
629 struct timer_list obd_recovery_timer;
631 time_t obd_recovery_start;
632 /* seconds, for lprocfs_status */
633 time_t obd_recovery_end;
634 int obd_recovery_time_hard;
635 int obd_recovery_timeout;
636 int obd_recovery_ir_factor;
638 /* new recovery stuff from CMD2 */
639 struct target_recovery_data obd_recovery_data;
640 int obd_replayed_locks;
641 atomic_t obd_req_replay_clients;
642 atomic_t obd_lock_replay_clients;
643 /* all lists are protected by obd_recovery_task_lock */
644 struct list_head obd_req_replay_queue;
645 struct list_head obd_lock_replay_queue;
646 struct list_head obd_final_req_queue;
649 #ifdef HAVE_SERVER_SUPPORT
650 struct obd_device_target obt;
651 struct filter_obd filter;
653 struct echo_obd echo;
655 struct client_obd cli;
656 struct echo_client_obd echo_client;
660 /* Fields used by LProcFS */
661 unsigned int obd_cntr_base;
662 struct lprocfs_stats *obd_stats;
664 unsigned int obd_md_cntr_base;
665 struct lprocfs_stats *obd_md_stats;
667 struct proc_dir_entry *obd_proc_entry;
668 struct proc_dir_entry *obd_proc_exports_entry;
669 struct proc_dir_entry *obd_svc_procroot;
670 struct lprocfs_stats *obd_svc_stats;
671 struct lprocfs_vars *obd_vars;
672 atomic_t obd_evict_inprogress;
673 wait_queue_head_t obd_evict_inprogress_waitq;
674 struct list_head obd_evict_list; /* protected with pet_lock */
677 * Ldlm pool part. Save last calculated SLV and Limit.
679 rwlock_t obd_pool_lock;
684 * A list of outstanding class_incref()'s against this obd. For
687 struct lu_ref obd_reference;
689 int obd_conn_inprogress;
692 enum obd_cleanup_stage {
693 /* Special case hack for MDS LOVs */
695 /* can be directly mapped to .ldto_device_fini() */
699 /* get/set_info keys */
700 #define KEY_ASYNC "async"
701 #define KEY_CAPA_KEY "capa_key"
702 #define KEY_CHANGELOG_CLEAR "changelog_clear"
703 #define KEY_FID2PATH "fid2path"
704 #define KEY_CHECKSUM "checksum"
705 #define KEY_CLEAR_FS "clear_fs"
706 #define KEY_CONN_DATA "conn_data"
707 #define KEY_EVICT_BY_NID "evict_by_nid"
708 #define KEY_FIEMAP "fiemap"
709 #define KEY_FLUSH_CTX "flush_ctx"
710 #define KEY_GRANT_SHRINK "grant_shrink"
711 #define KEY_HSM_COPYTOOL_SEND "hsm_send"
712 #define KEY_INIT_RECOV_BACKUP "init_recov_bk"
713 #define KEY_INTERMDS "inter_mds"
714 #define KEY_LAST_ID "last_id"
715 #define KEY_LAST_FID "last_fid"
716 #define KEY_MAX_EASIZE "max_easize"
717 #define KEY_DEFAULT_EASIZE "default_easize"
718 #define KEY_MGSSEC "mgssec"
719 #define KEY_READ_ONLY "read-only"
720 #define KEY_REGISTER_TARGET "register_target"
721 #define KEY_SET_FS "set_fs"
722 #define KEY_TGT_COUNT "tgt_count"
723 /* KEY_SET_INFO in lustre_idl.h */
724 #define KEY_SPTLRPC_CONF "sptlrpc_conf"
726 #define KEY_CACHE_SET "cache_set"
727 #define KEY_CACHE_LRU_SHRINK "cache_lru_shrink"
728 #define KEY_OSP_CONNECTED "osp_connected"
732 /* /!\ must be coherent with include/linux/namei.h on patched kernel */
733 #define IT_OPEN (1 << 0)
734 #define IT_CREAT (1 << 1)
735 #define IT_READDIR (1 << 2)
736 #define IT_GETATTR (1 << 3)
737 #define IT_LOOKUP (1 << 4)
738 #define IT_UNLINK (1 << 5)
739 #define IT_TRUNC (1 << 6)
740 #define IT_GETXATTR (1 << 7)
741 #define IT_EXEC (1 << 8)
742 #define IT_PIN (1 << 9)
743 #define IT_LAYOUT (1 << 10)
744 #define IT_QUOTA_DQACQ (1 << 11)
745 #define IT_QUOTA_CONN (1 << 12)
746 #define IT_SETXATTR (1 << 13)
748 static inline int it_to_lock_mode(struct lookup_intent *it)
750 /* CREAT needs to be tested before open (both could be set) */
751 if (it->it_op & IT_CREAT)
753 else if (it->it_op & (IT_GETATTR | IT_OPEN | IT_LOOKUP |
756 else if (it->it_op & IT_READDIR)
758 else if (it->it_op & IT_GETXATTR)
760 else if (it->it_op & IT_SETXATTR)
763 LASSERTF(0, "Invalid it_op: %d\n", it->it_op);
768 MF_MDC_CANCEL_FID1 = 1 << 0,
769 MF_MDC_CANCEL_FID2 = 1 << 1,
770 MF_MDC_CANCEL_FID3 = 1 << 2,
771 MF_MDC_CANCEL_FID4 = 1 << 3,
772 MF_GET_MDT_IDX = 1 << 4,
776 CLI_SET_MEA = 1 << 0,
777 CLI_RM_ENTRY = 1 << 1,
780 CLI_MIGRATE = 1 << 4,
784 struct lu_fid op_fid1; /* operation fid1 (usualy parent) */
785 struct lu_fid op_fid2; /* operation fid2 (usualy child) */
786 struct lu_fid op_fid3; /* 2 extra fids to find conflicting */
787 struct lu_fid op_fid4; /* to the operation locks. */
788 u32 op_mds; /* what mds server open will go to */
789 struct lustre_handle op_handle;
794 struct lmv_stripe_md *op_mea1;
795 struct lmv_stripe_md *op_mea2;
796 __u32 op_suppgids[2];
803 /* iattr fields and blocks. */
804 struct iattr op_attr;
805 loff_t op_attr_blocks;
806 unsigned int op_attr_flags; /* LUSTRE_{SYNC,..}_FL */
807 __u64 op_valid; /* OBD_MD_* */
809 enum md_op_flags op_flags;
812 struct obd_capa *op_capa1;
813 struct obd_capa *op_capa2;
815 /* Various operation flags. */
816 enum mds_op_bias op_bias;
818 /* Used by readdir */
819 unsigned int op_max_pages;
821 /* used to transfer info between the stacks of MD client
822 * see enum op_cli_flags */
823 enum md_cli_flags op_cli_flags;
825 /* File object data version for HSM release, on client */
826 __u64 op_data_version;
827 struct lustre_handle op_lease_handle;
829 /* default stripe offset */
830 __u32 op_default_stripe_offset;
834 int (*md_blocking_ast)(struct ldlm_lock *lock,
835 struct ldlm_lock_desc *desc,
836 void *data, int flag);
839 struct md_enqueue_info;
840 /* metadata stat-ahead */
841 typedef int (* md_enqueue_cb_t)(struct ptlrpc_request *req,
842 struct md_enqueue_info *minfo,
845 struct md_enqueue_info {
846 struct md_op_data mi_data;
847 struct lookup_intent mi_it;
848 struct lustre_handle mi_lockh;
849 struct inode *mi_dir;
850 md_enqueue_cb_t mi_cb;
855 struct module *o_owner;
856 int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
857 void *karg, void __user *uarg);
858 int (*o_get_info)(const struct lu_env *env, struct obd_export *,
859 __u32 keylen, void *key, __u32 *vallen, void *val);
860 int (*o_set_info_async)(const struct lu_env *, struct obd_export *,
861 __u32 keylen, void *key,
862 __u32 vallen, void *val,
863 struct ptlrpc_request_set *set);
864 int (*o_setup) (struct obd_device *dev, struct lustre_cfg *cfg);
865 int (*o_precleanup)(struct obd_device *dev,
866 enum obd_cleanup_stage cleanup_stage);
867 int (*o_cleanup)(struct obd_device *dev);
868 int (*o_process_config)(struct obd_device *dev, size_t len, void *data);
869 int (*o_postrecov)(struct obd_device *dev);
870 int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
872 int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
873 /* connect to the target device with given connection
874 * data. @ocd->ocd_connect_flags is modified to reflect flags actually
875 * granted by the target, which are guaranteed to be a subset of flags
876 * asked for. If @ocd == NULL, use default parameters. */
877 int (*o_connect)(const struct lu_env *env,
878 struct obd_export **exp, struct obd_device *src,
879 struct obd_uuid *cluuid, struct obd_connect_data *ocd,
881 int (*o_reconnect)(const struct lu_env *env,
882 struct obd_export *exp, struct obd_device *src,
883 struct obd_uuid *cluuid,
884 struct obd_connect_data *ocd,
886 int (*o_disconnect)(struct obd_export *exp);
888 /* Initialize/finalize fids infrastructure. */
889 int (*o_fid_init)(struct obd_device *obd,
890 struct obd_export *exp, enum lu_cli_type type);
891 int (*o_fid_fini)(struct obd_device *obd);
893 /* Allocate new fid according to passed @hint. */
894 int (*o_fid_alloc)(const struct lu_env *env, struct obd_export *exp,
895 struct lu_fid *fid, struct md_op_data *op_data);
898 * Object with @fid is getting deleted, we may want to do something
901 int (*o_statfs)(const struct lu_env *, struct obd_export *exp,
902 struct obd_statfs *osfs, __u64 max_age, __u32 flags);
903 int (*o_statfs_async)(struct obd_export *exp, struct obd_info *oinfo,
904 __u64 max_age, struct ptlrpc_request_set *set);
905 int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
906 struct lov_stripe_md *mem_src);
907 int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
908 struct lov_mds_md *disk_src, int disk_len);
909 int (*o_create)(const struct lu_env *env, struct obd_export *exp,
911 int (*o_destroy)(const struct lu_env *env, struct obd_export *exp,
913 int (*o_setattr)(const struct lu_env *, struct obd_export *exp,
915 int (*o_getattr)(const struct lu_env *env, struct obd_export *exp,
917 int (*o_preprw)(const struct lu_env *env, int cmd,
918 struct obd_export *exp, struct obdo *oa, int objcount,
919 struct obd_ioobj *obj, struct niobuf_remote *remote,
920 int *nr_pages, struct niobuf_local *local);
921 int (*o_commitrw)(const struct lu_env *env, int cmd,
922 struct obd_export *exp, struct obdo *oa,
923 int objcount, struct obd_ioobj *obj,
924 struct niobuf_remote *remote, int pages,
925 struct niobuf_local *local, int rc);
926 int (*o_init_export)(struct obd_export *exp);
927 int (*o_destroy_export)(struct obd_export *exp);
929 int (*o_import_event)(struct obd_device *, struct obd_import *,
930 enum obd_import_event);
932 int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
933 enum obd_notify_event ev, void *data);
935 int (*o_health_check)(const struct lu_env *env, struct obd_device *);
936 struct obd_uuid *(*o_get_uuid) (struct obd_export *exp);
939 int (*o_quotactl)(struct obd_device *, struct obd_export *,
940 struct obd_quotactl *);
942 int (*o_ping)(const struct lu_env *, struct obd_export *exp);
945 int (*o_pool_new)(struct obd_device *obd, char *poolname);
946 int (*o_pool_del)(struct obd_device *obd, char *poolname);
947 int (*o_pool_add)(struct obd_device *obd, char *poolname,
949 int (*o_pool_rem)(struct obd_device *obd, char *poolname,
951 void (*o_getref)(struct obd_device *obd);
952 void (*o_putref)(struct obd_device *obd);
954 * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
955 * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
956 * Also, add a wrapper function in include/linux/obd_class.h. */
961 struct mdt_body *body;
962 struct lov_stripe_md *lsm;
963 struct lmv_stripe_md *lmv;
964 #ifdef CONFIG_FS_POSIX_ACL
965 struct posix_acl *posix_acl;
967 struct mdt_remote_perm *remote_perm;
968 struct obd_capa *mds_capa;
969 struct obd_capa *oss_capa;
972 struct md_open_data {
973 struct obd_client_handle *mod_och;
974 struct ptlrpc_request *mod_open_req;
975 struct ptlrpc_request *mod_close_req;
976 atomic_t mod_refcount;
980 struct obd_client_handle {
981 struct lustre_handle och_fh;
982 struct lu_fid och_fid;
983 struct md_open_data *och_mod;
984 struct lustre_handle och_lease_handle; /* open lock for lease */
989 #define OBD_CLIENT_HANDLE_MAGIC 0xd15ea5ed
991 struct lookup_intent;
995 /* Every operation from MD_STATS_FIRST_OP up to and including
996 * MD_STATS_LAST_OP will be counted by EXP_MD_OP_INCREMENT()
997 * and will appear in /proc/fs/lustre/{lmv,mdc}/.../md_stats.
998 * Operations after MD_STATS_LAST_OP are excluded from stats.
999 * There are a few reasons for doing this: we prune the 17
1000 * counters which will be of minimal use in understanding
1001 * metadata utilization, we save memory by allocating 15
1002 * instead of 32 counters, we save cycles by not counting.
1004 * MD_STATS_FIRST_OP must be the first member of md_ops.
1006 #define MD_STATS_FIRST_OP m_close
1007 int (*m_close)(struct obd_export *, struct md_op_data *,
1008 struct md_open_data *, struct ptlrpc_request **);
1010 int (*m_create)(struct obd_export *, struct md_op_data *,
1011 const void *, size_t, umode_t, uid_t, gid_t,
1012 cfs_cap_t, __u64, struct ptlrpc_request **);
1014 int (*m_enqueue)(struct obd_export *, struct ldlm_enqueue_info *,
1015 const union ldlm_policy_data *,
1016 struct lookup_intent *, struct md_op_data *,
1017 struct lustre_handle *, __u64);
1019 int (*m_getattr)(struct obd_export *, struct md_op_data *,
1020 struct ptlrpc_request **);
1022 int (*m_intent_lock)(struct obd_export *, struct md_op_data *,
1023 struct lookup_intent *,
1024 struct ptlrpc_request **,
1025 ldlm_blocking_callback, __u64);
1027 int (*m_link)(struct obd_export *, struct md_op_data *,
1028 struct ptlrpc_request **);
1030 int (*m_rename)(struct obd_export *, struct md_op_data *,
1031 const char *, size_t, const char *, size_t,
1032 struct ptlrpc_request **);
1034 int (*m_setattr)(struct obd_export *, struct md_op_data *, void *,
1035 size_t , struct ptlrpc_request **);
1037 int (*m_fsync)(struct obd_export *, const struct lu_fid *,
1038 struct obd_capa *, struct ptlrpc_request **);
1040 int (*m_read_page)(struct obd_export *, struct md_op_data *,
1041 struct md_callback *cb_op, __u64 hash_offset,
1042 struct page **ppage);
1044 int (*m_unlink)(struct obd_export *, struct md_op_data *,
1045 struct ptlrpc_request **);
1047 int (*m_setxattr)(struct obd_export *, const struct lu_fid *,
1048 struct obd_capa *, u64, const char *,
1049 const char *, int, int, int, __u32,
1050 struct ptlrpc_request **);
1052 int (*m_getxattr)(struct obd_export *, const struct lu_fid *,
1053 struct obd_capa *, u64, const char *,
1054 const char *, int, int, int,
1055 struct ptlrpc_request **);
1057 int (*m_intent_getattr_async)(struct obd_export *,
1058 struct md_enqueue_info *,
1059 struct ldlm_enqueue_info *);
1061 int (*m_revalidate_lock)(struct obd_export *, struct lookup_intent *,
1062 struct lu_fid *, __u64 *bits);
1064 #define MD_STATS_LAST_OP m_revalidate_lock
1066 int (*m_getstatus)(struct obd_export *, struct lu_fid *,
1067 struct obd_capa **);
1069 int (*m_null_inode)(struct obd_export *, const struct lu_fid *);
1071 int (*m_find_cbdata)(struct obd_export *, const struct lu_fid *,
1072 ldlm_iterator_t, void *);
1074 int (*m_getattr_name)(struct obd_export *, struct md_op_data *,
1075 struct ptlrpc_request **);
1077 int (*m_init_ea_size)(struct obd_export *, __u32, __u32);
1079 int (*m_get_lustre_md)(struct obd_export *, struct ptlrpc_request *,
1080 struct obd_export *, struct obd_export *,
1081 struct lustre_md *);
1083 int (*m_free_lustre_md)(struct obd_export *, struct lustre_md *);
1085 int (*m_merge_attr)(struct obd_export *,
1086 const struct lmv_stripe_md *lsm,
1087 struct cl_attr *attr, ldlm_blocking_callback);
1089 int (*m_set_open_replay_data)(struct obd_export *,
1090 struct obd_client_handle *,
1091 struct lookup_intent *);
1093 int (*m_clear_open_replay_data)(struct obd_export *,
1094 struct obd_client_handle *);
1096 int (*m_set_lock_data)(struct obd_export *, __u64 *, void *, __u64 *);
1098 ldlm_mode_t (*m_lock_match)(struct obd_export *, __u64,
1099 const struct lu_fid *, ldlm_type_t,
1100 ldlm_policy_data_t *, ldlm_mode_t,
1101 struct lustre_handle *);
1103 int (*m_cancel_unused)(struct obd_export *, const struct lu_fid *,
1104 ldlm_policy_data_t *, ldlm_mode_t,
1105 ldlm_cancel_flags_t flags, void *opaque);
1107 int (*m_renew_capa)(struct obd_export *, struct obd_capa *oc,
1108 renew_capa_cb_t cb);
1110 int (*m_unpack_capa)(struct obd_export *, struct ptlrpc_request *,
1111 const struct req_msg_field *, struct obd_capa **);
1113 int (*m_get_remote_perm)(struct obd_export *, const struct lu_fid *,
1114 struct obd_capa *, __u32,
1115 struct ptlrpc_request **);
1117 int (*m_get_fid_from_lsm)(struct obd_export *,
1118 const struct lmv_stripe_md *,
1119 const char *name, int namelen,
1120 struct lu_fid *fid);
1123 struct lsm_operations {
1124 void (*lsm_free)(struct lov_stripe_md *);
1125 void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *,
1126 loff_t *, loff_t *);
1127 void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *,
1128 loff_t *, loff_t *);
1129 int (*lsm_lmm_verify) (struct lov_mds_md *lmm, int lmm_bytes,
1130 __u16 *stripe_count);
1131 int (*lsm_unpackmd) (struct lov_obd *lov, struct lov_stripe_md *lsm,
1132 struct lov_mds_md *lmm);
1135 extern const struct lsm_operations lsm_v1_ops;
1136 extern const struct lsm_operations lsm_v3_ops;
1137 static inline const struct lsm_operations *lsm_op_find(u32 magic)
1145 CERROR("Cannot recognize lsm_magic %08x\n", magic);
1150 static inline struct md_open_data *obd_mod_alloc(void)
1152 struct md_open_data *mod;
1156 atomic_set(&mod->mod_refcount, 1);
1160 #define obd_mod_get(mod) atomic_inc(&(mod)->mod_refcount)
1161 #define obd_mod_put(mod) \
1163 if (atomic_dec_and_test(&(mod)->mod_refcount)) { \
1164 if ((mod)->mod_open_req) \
1165 ptlrpc_req_finished((mod)->mod_open_req); \
1166 OBD_FREE_PTR(mod); \
1170 void obdo_from_inode(struct obdo *dst, struct inode *src, u64 valid);
1171 void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent);
1173 /* return 1 if client should be resend request */
1174 static inline int client_should_resend(int resend, struct client_obd *cli)
1176 return atomic_read(&cli->cl_resends) ?
1177 atomic_read(&cli->cl_resends) > resend : 1;
1181 * Return device name for this device
1183 * XXX: lu_device is declared before obd_device, while a pointer pointing
1184 * back to obd_device in lu_device, so this helper function defines here
1185 * instead of in lu_object.h
1187 static inline const char *lu_dev_name(const struct lu_device *lu_dev)
1189 return lu_dev->ld_obd->obd_name;
1192 static inline bool filename_is_volatile(const char *name, size_t namelen,
1198 if (strncmp(name, LUSTRE_VOLATILE_HDR, LUSTRE_VOLATILE_HDR_LEN) != 0)
1201 /* caller does not care of idx */
1205 /* volatile file, the MDT can be set from name */
1206 /* name format is LUSTRE_VOLATILE_HDR:[idx]: */
1207 /* if no MDT is specified, use std way */
1208 if (namelen < LUSTRE_VOLATILE_HDR_LEN + 2)
1210 /* test for no MDT idx case */
1211 if ((*(name + LUSTRE_VOLATILE_HDR_LEN) == ':') &&
1212 (*(name + LUSTRE_VOLATILE_HDR_LEN + 1) == ':')) {
1216 /* we have an idx, read it */
1217 start = name + LUSTRE_VOLATILE_HDR_LEN + 1;
1218 *idx = simple_strtoul(start, &end, 16);
1220 * no digit, no trailing :, negative value
1222 if (((*idx == 0) && (end == start)) ||
1223 (*end != ':') || (*idx < 0))
1228 /* bad format of mdt idx, we cannot return an error
1229 * to caller so we use hash algo */
1230 CERROR("Bad volatile file name format: %s\n",
1231 name + LUSTRE_VOLATILE_HDR_LEN);
1235 static inline int cli_brw_size(struct obd_device *obd)
1237 LASSERT(obd != NULL);
1238 return obd->u.cli.cl_max_pages_per_rpc << PAGE_CACHE_SHIFT;
1241 /* when RPC size or the max RPCs in flight is increased, the max dirty pages
1242 * of the client should be increased accordingly to avoid sending fragmented
1243 * RPCs over the network when the client runs out of the maximum dirty space
1244 * when so many RPCs are being generated.
1246 static inline void client_adjust_max_dirty(struct client_obd *cli)
1249 if (cli->cl_dirty_max_pages <= 0)
1250 cli->cl_dirty_max_pages = (OSC_MAX_DIRTY_DEFAULT * 1024 * 1024)
1251 >> PAGE_CACHE_SHIFT;
1253 unsigned long dirty_max = cli->cl_max_rpcs_in_flight *
1254 cli->cl_max_pages_per_rpc;
1256 if (dirty_max > cli->cl_dirty_max_pages)
1257 cli->cl_dirty_max_pages = dirty_max;
1260 if (cli->cl_dirty_max_pages > totalram_pages / 8)
1261 cli->cl_dirty_max_pages = totalram_pages / 8;
1264 #endif /* __OBD_H */