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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
36 #include <linux/spinlock.h>
38 #include "lustre/lustre_idl.h"
39 #include "lustre_lib.h"
41 #include "lustre_export.h"
42 #include "lustre_fid.h"
43 #include "lustre_fld.h"
44 #include "lustre_intent.h"
46 #define MAX_OBD_DEVICES 8192
54 struct lov_oinfo { /* per-stripe data structure */
55 struct ost_id loi_oi; /* object ID/Sequence on the target OST */
56 int loi_ost_idx; /* OST stripe index in lov_tgt_desc->tgts */
57 int loi_ost_gen; /* generation of this loi_ost_idx */
59 unsigned long loi_kms_valid:1;
60 __u64 loi_kms; /* known minimum size */
61 struct ost_lvb loi_lvb;
62 struct osc_async_rc loi_ar;
65 static inline void loi_kms_set(struct lov_oinfo *oinfo, __u64 kms)
68 oinfo->loi_kms_valid = 1;
71 static inline void loi_init(struct lov_oinfo *loi)
75 struct lov_stripe_md {
78 pid_t lsm_lock_owner; /* debugging */
80 /* maximum possible file size, might change as OSTs status changes,
81 * e.g. disconnected, deactivated
86 struct ost_id lw_object_oi; /* lov object id/seq */
88 /* LOV-private members start here -- only for use in lov/. */
90 __u32 lw_stripe_size; /* size of the stripe */
91 __u32 lw_pattern; /* striping pattern (RAID0, RAID1) */
92 __u16 lw_stripe_count; /* number of objects being striped over */
93 __u16 lw_layout_gen; /* generation of the layout */
94 char lw_pool_name[LOV_MAXPOOLNAME]; /* pool name */
97 struct lov_oinfo *lsm_oinfo[0];
100 #define lsm_oi lsm_wire.lw_object_oi
101 #define lsm_magic lsm_wire.lw_magic
102 #define lsm_layout_gen lsm_wire.lw_layout_gen
103 #define lsm_stripe_size lsm_wire.lw_stripe_size
104 #define lsm_pattern lsm_wire.lw_pattern
105 #define lsm_stripe_count lsm_wire.lw_stripe_count
106 #define lsm_pool_name lsm_wire.lw_pool_name
108 static inline bool lsm_is_released(struct lov_stripe_md *lsm)
110 return !!(lsm->lsm_pattern & LOV_PATTERN_F_RELEASED);
113 static inline bool lsm_has_objects(struct lov_stripe_md *lsm)
117 if (lsm_is_released(lsm))
122 static inline int lov_stripe_md_size(unsigned int stripe_count)
124 struct lov_stripe_md lsm;
126 return sizeof(lsm) + stripe_count * sizeof(lsm.lsm_oinfo[0]);
131 typedef int (*obd_enqueue_update_f)(void *cookie, int rc);
133 /* obd info for a particular level (lov, osc). */
135 /* Flags used for set request specific flags:
136 - while lock handling, the flags obtained on the enqueue
137 request are set here.
138 - while stats, the flags used for control delay/resend.
139 - while setattr, the flags used for distinguish punch operation
142 /* lsm data specific for every OSC. */
143 struct lov_stripe_md *oi_md;
144 /* obdo data specific for every OSC, if needed at all. */
146 /* statfs data specific for every OSC, if needed at all. */
147 struct obd_statfs *oi_osfs;
148 /* An update callback which is called to update some data on upper
149 * level. E.g. it is used for update lsm->lsm_oinfo at every received
150 * request in osc level for enqueue requests. It is also possible to
151 * update some caller data from LOV layer if needed.
153 obd_enqueue_update_f oi_cb_up;
157 struct list_head typ_chain;
158 struct obd_ops *typ_dt_ops;
159 struct md_ops *typ_md_ops;
160 struct dentry *typ_debugfs_entry;
163 struct lu_device_type *typ_lu;
164 spinlock_t obd_type_lock;
165 struct kobject *typ_kobj;
177 LLOG_CONFIG_ORIG_CTXT = 0,
178 LLOG_CONFIG_REPL_CTXT,
179 LLOG_MDS_OST_ORIG_CTXT,
180 LLOG_MDS_OST_REPL_CTXT,
187 LLOG_LOVEA_ORIG_CTXT,
188 LLOG_LOVEA_REPL_CTXT,
189 LLOG_CHANGELOG_ORIG_CTXT, /**< changelog generation on mdd */
190 LLOG_CHANGELOG_REPL_CTXT, /**< changelog access on clients */
191 LLOG_CHANGELOG_USER_ORIG_CTXT, /**< for multiple changelog consumers */
192 LLOG_AGENT_ORIG_CTXT, /**< agent requests generation on cdt */
196 struct timeout_item {
197 enum timeout_event ti_event;
198 unsigned long ti_timeout;
201 struct list_head ti_obd_list;
202 struct list_head ti_chain;
205 #define OBD_MAX_RIF_DEFAULT 8
206 #define OBD_MAX_RIF_MAX 512
207 #define OSC_MAX_RIF_MAX 256
208 #define OSC_MAX_DIRTY_DEFAULT (OBD_MAX_RIF_DEFAULT * 4)
209 #define OSC_MAX_DIRTY_MB_MAX 2048 /* arbitrary, but < MAX_LONG bytes */
210 #define OSC_DEFAULT_RESENDS 10
212 /* possible values for fo_sync_lock_cancel */
214 NEVER_SYNC_ON_CANCEL = 0,
215 BLOCKING_SYNC_ON_CANCEL = 1,
216 ALWAYS_SYNC_ON_CANCEL = 2,
217 NUM_SYNC_ON_CANCEL_STATES
220 enum obd_cl_sem_lock_class {
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.
236 int cl_default_mds_easize;
237 int cl_max_mds_easize;
238 int cl_default_mds_cookiesize;
239 int cl_max_mds_cookiesize;
241 enum lustre_sec_part cl_sp_me;
242 enum lustre_sec_part cl_sp_to;
243 struct sptlrpc_flavor cl_flvr_mgc; /* fixed flavor of mgc->mgs */
245 /* the grant values are protected by loi_list_lock below */
246 long cl_dirty; /* all _dirty_ in bytes */
247 long cl_dirty_max; /* allowed w/o rpc */
248 long cl_dirty_transit; /* dirty synchronous */
249 long cl_avail_grant; /* bytes of credit for ost */
250 long cl_lost_grant; /* lost credits (trunc) */
252 /* since we allocate grant by blocks, we don't know how many grant will
253 * be used to add a page into cache. As a solution, we reserve maximum
254 * grant before trying to dirty a page and unreserve the rest.
255 * See osc_{reserve|unreserve}_grant for details.
257 long cl_reserved_grant;
258 struct list_head cl_cache_waiters; /* waiting for cache/grant */
259 unsigned long cl_next_shrink_grant; /* jiffies */
260 struct list_head cl_grant_shrink_list; /* Timeout event list */
261 int cl_grant_shrink_interval; /* seconds */
263 /* A chunk is an optimal size used by osc_extent to determine
264 * the extent size. A chunk is max(PAGE_SIZE, OST block size)
268 int cl_extent_tax; /* extent overhead, by bytes */
270 /* keep track of objects that have lois that contain pages which
271 * have been queued for async brw. this lock also protects the
272 * lists of osc_client_pages that hang off of the loi
275 * ->cl_loi_list_lock protects consistency of
276 * ->cl_loi_{ready,read,write}_list. ->ap_make_ready() and
277 * ->ap_completion() call-backs are executed under this lock. As we
278 * cannot guarantee that these call-backs never block on all platforms
279 * (as a matter of fact they do block on Mac OS X), type of
280 * ->cl_loi_list_lock is platform dependent: it's a spin-lock on Linux
281 * and blocking mutex on Mac OS X. (Alternative is to make this lock
282 * blocking everywhere, but we don't want to slow down fast-path of
283 * our main platform.)
285 * NB by Jinshan: though field names are still _loi_, but actually
286 * osc_object{}s are in the list.
288 spinlock_t cl_loi_list_lock;
289 struct list_head cl_loi_ready_list;
290 struct list_head cl_loi_hp_ready_list;
291 struct list_head cl_loi_write_list;
292 struct list_head cl_loi_read_list;
295 /* just a sum of the loi/lop pending numbers to be exported by sysfs */
296 atomic_t cl_pending_w_pages;
297 atomic_t cl_pending_r_pages;
298 __u32 cl_max_pages_per_rpc;
299 int cl_max_rpcs_in_flight;
300 struct obd_histogram cl_read_rpc_hist;
301 struct obd_histogram cl_write_rpc_hist;
302 struct obd_histogram cl_read_page_hist;
303 struct obd_histogram cl_write_page_hist;
304 struct obd_histogram cl_read_offset_hist;
305 struct obd_histogram cl_write_offset_hist;
307 /* lru for osc caching pages */
308 struct cl_client_cache *cl_cache;
309 struct list_head cl_lru_osc; /* member of cl_cache->ccc_lru */
310 atomic_t *cl_lru_left;
311 atomic_t cl_lru_busy;
312 atomic_t cl_lru_shrinkers;
313 atomic_t cl_lru_in_list;
314 struct list_head cl_lru_list; /* lru page list */
315 spinlock_t cl_lru_list_lock; /* page list protector */
316 atomic_t cl_unstable_count;
318 /* number of in flight destroy rpcs is limited to max_rpcs_in_flight */
319 atomic_t cl_destroy_in_flight;
320 wait_queue_head_t cl_destroy_waitq;
322 struct mdc_rpc_lock *cl_rpc_lock;
323 struct mdc_rpc_lock *cl_close_lock;
326 atomic_t cl_mgc_refcount;
327 struct obd_export *cl_mgc_mgsexp;
329 /* checksumming for data sent over the network */
330 unsigned int cl_checksum:1; /* 0 = disabled, 1 = enabled */
331 /* supported checksum types that are worked out at connect time */
332 __u32 cl_supp_cksum_types;
333 /* checksum algorithm to be used */
334 enum cksum_type cl_cksum_type;
336 /* also protected by the poorly named _loi_list_lock lock above */
337 struct osc_async_rc cl_ar;
339 /* used by quotacheck when the servers are older than 2.4 */
340 int cl_qchk_stat; /* quotacheck stat of the peer */
341 #define CL_NOT_QUOTACHECKED 1 /* client->cl_qchk_stat init value */
342 #if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 7, 50, 0)
343 #warning "please consider removing quotacheck compatibility code"
346 /* sequence manager */
347 struct lu_client_seq *cl_seq;
349 atomic_t cl_resends; /* resend count */
351 /* ptlrpc work for writeback in ptlrpcd context */
352 void *cl_writeback_work;
354 /* hash tables for osc_quota_info */
355 struct cfs_hash *cl_quota_hash[MAXQUOTAS];
358 #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
365 struct echo_client_obd {
366 struct obd_export *ec_exp; /* the local connection to osc/lov */
368 struct list_head ec_objects;
369 struct list_head ec_locks;
373 /* Generic subset of OSTs */
375 __u32 *op_array; /* array of index of lov_obd->lov_tgts */
376 unsigned int op_count; /* number of OSTs in the array */
377 unsigned int op_size; /* allocated size of lp_array */
378 struct rw_semaphore op_rw_sem; /* to protect ost_pool use */
381 /* allow statfs data caching for 1 second */
382 #define OBD_STATFS_CACHE_SECONDS 1
384 struct lov_tgt_desc {
385 struct list_head ltd_kill;
386 struct obd_uuid ltd_uuid;
387 struct obd_device *ltd_obd;
388 struct obd_export *ltd_exp;
390 __u32 ltd_index; /* index in lov_obd->tgts */
391 unsigned long ltd_active:1,/* is this target up for requests */
392 ltd_activate:1,/* should target be activated */
393 ltd_reap:1; /* should this target be deleted */
397 struct lov_desc desc;
398 struct lov_tgt_desc **lov_tgts; /* sparse array */
399 struct ost_pool lov_packed; /* all OSTs in a packed array */
400 struct mutex lov_lock;
401 struct obd_connect_data lov_ocd;
402 atomic_t lov_refcount;
403 __u32 lov_death_row;/* tgts scheduled to be deleted */
404 __u32 lov_tgt_size; /* size of tgts array */
407 struct cfs_hash *lov_pools_hash_body; /* used for key access */
408 struct list_head lov_pool_list; /* used for sequential access */
409 struct dentry *lov_pool_debugfs_entry;
410 enum lustre_sec_part lov_sp_me;
412 /* Cached LRU and unstable data from upper layer */
413 struct cl_client_cache *lov_cache;
415 struct rw_semaphore lov_notify_lock;
417 struct kobject *lov_tgts_kobj;
420 struct lmv_tgt_desc {
421 struct obd_uuid ltd_uuid;
422 struct obd_export *ltd_exp;
424 struct mutex ltd_fid_mutex;
425 unsigned long ltd_active:1; /* target up for requests */
428 enum placement_policy {
429 PLACEMENT_CHAR_POLICY = 0,
430 PLACEMENT_NID_POLICY = 1,
431 PLACEMENT_INVAL_POLICY = 2,
437 struct lu_client_fld lmv_fld;
439 enum placement_policy lmv_placement;
440 struct lmv_desc desc;
441 struct obd_uuid cluuid;
442 struct obd_export *exp;
444 struct mutex lmv_init_mutex;
449 int max_def_cookiesize;
452 int tgts_size; /* size of tgts array */
453 struct lmv_tgt_desc **tgts;
455 struct obd_connect_data conn_data;
456 struct kobject *lmv_tgts_kobj;
459 struct niobuf_local {
460 __u64 lnb_file_offset;
461 __u32 lnb_page_offset;
465 struct dentry *dentry;
470 #define LUSTRE_FLD_NAME "fld"
471 #define LUSTRE_SEQ_NAME "seq"
473 #define LUSTRE_MDD_NAME "mdd"
474 #define LUSTRE_OSD_LDISKFS_NAME "osd-ldiskfs"
475 #define LUSTRE_OSD_ZFS_NAME "osd-zfs"
476 #define LUSTRE_VVP_NAME "vvp"
477 #define LUSTRE_LMV_NAME "lmv"
478 #define LUSTRE_SLP_NAME "slp"
479 #define LUSTRE_LOD_NAME "lod"
480 #define LUSTRE_OSP_NAME "osp"
481 #define LUSTRE_LWP_NAME "lwp"
483 /* obd device type names */
484 /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */
485 #define LUSTRE_MDS_NAME "mds"
486 #define LUSTRE_MDT_NAME "mdt"
487 #define LUSTRE_MDC_NAME "mdc"
488 #define LUSTRE_OSS_NAME "ost" /* FIXME change name to oss */
489 #define LUSTRE_OST_NAME "obdfilter" /* FIXME change name to ost */
490 #define LUSTRE_OSC_NAME "osc"
491 #define LUSTRE_LOV_NAME "lov"
492 #define LUSTRE_MGS_NAME "mgs"
493 #define LUSTRE_MGC_NAME "mgc"
495 #define LUSTRE_ECHO_NAME "obdecho"
496 #define LUSTRE_ECHO_CLIENT_NAME "echo_client"
497 #define LUSTRE_QMT_NAME "qmt"
499 /* Constant obd names (post-rename) */
500 #define LUSTRE_MDS_OBDNAME "MDS"
501 #define LUSTRE_OSS_OBDNAME "OSS"
502 #define LUSTRE_MGS_OBDNAME "MGS"
503 #define LUSTRE_MGC_OBDNAME "MGC"
505 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
506 #define N_LOCAL_TEMP_PAGE 0x10000000
508 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;
520 /** synchronous write is needed */
521 unsigned long oti_sync_write:1;
523 /* initial thread handling transaction */
524 struct ptlrpc_thread *oti_thread;
527 __u64 oti_pre_version;
531 struct obd_uuid *oti_ost_uuid;
534 static inline void oti_alloc_cookies(struct obd_trans_info *oti,
540 if (num_cookies == 1)
541 oti->oti_logcookies = &oti->oti_onecookie;
543 oti->oti_logcookies = libcfs_kvzalloc(num_cookies * sizeof(oti->oti_onecookie),
546 oti->oti_numcookies = num_cookies;
549 static inline void oti_free_cookies(struct obd_trans_info *oti)
551 if (!oti || !oti->oti_logcookies)
554 if (oti->oti_logcookies == &oti->oti_onecookie)
555 LASSERT(oti->oti_numcookies == 1);
557 kvfree(oti->oti_logcookies);
559 oti->oti_logcookies = NULL;
560 oti->oti_numcookies = 0;
564 * Events signalled through obd_notify() upcall-chain.
566 enum obd_notify_event {
569 /* Device connect start */
571 /* Device activated */
573 /* Device deactivated */
575 /* Device disconnected */
577 /* Connect data for import were changed */
580 OBD_NOTIFY_SYNC_NONBLOCK,
582 /* Configuration event */
584 /* Administratively deactivate/activate event */
585 OBD_NOTIFY_DEACTIVATE,
590 * Data structure used to pass obd_notify()-event to non-obd listeners (llite
591 * being main example).
593 struct obd_notify_upcall {
594 int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
595 enum obd_notify_event ev, void *owner, void *data);
596 /* Opaque datum supplied by upper layer listener */
600 struct target_recovery_data {
601 svc_handler_t trd_recovery_handler;
602 pid_t trd_processing_task;
603 struct completion trd_starting;
604 struct completion trd_finishing;
607 struct obd_llog_group {
609 struct llog_ctxt *olg_ctxts[LLOG_MAX_CTXTS];
610 wait_queue_head_t olg_waitq;
612 struct mutex olg_cat_processing;
615 /* corresponds to one of the obd's */
616 #define OBD_DEVICE_MAGIC 0XAB5CD6EF
618 struct lvfs_run_ctxt {
619 struct dt_device *dt;
623 struct obd_type *obd_type;
626 /* common and UUID name of this device */
627 char obd_name[MAX_OBD_NAME];
628 struct obd_uuid obd_uuid;
630 struct lu_device *obd_lu_dev;
633 /* bitfield modification is protected by obd_dev_lock */
634 unsigned long obd_attached:1, /* finished attach */
635 obd_set_up:1, /* finished setup */
636 obd_version_recov:1, /* obd uses version checking */
637 obd_replayable:1,/* recovery is enabled; inform clients */
638 obd_no_transno:1, /* no committed-transno notification */
639 obd_no_recov:1, /* fail instead of retry messages */
640 obd_stopping:1, /* started cleanup */
641 obd_starting:1, /* started setup */
642 obd_force:1, /* cleanup with > 0 obd refcount */
643 obd_fail:1, /* cleanup with failover */
644 obd_async_recov:1, /* allow asynchronous orphan cleanup */
645 obd_no_conn:1, /* deny new connections */
646 obd_inactive:1, /* device active/inactive
647 * (for sysfs status only!!)
649 obd_no_ir:1, /* no imperative recovery. */
650 obd_process_conf:1; /* device is processing mgs config */
651 /* use separate field as it is set in interrupt to don't mess with
652 * protection of other bits using _bh lock
654 unsigned long obd_recovery_expired:1;
655 /* uuid-export hash body */
656 struct cfs_hash *obd_uuid_hash;
657 atomic_t obd_refcount;
658 wait_queue_head_t obd_refcount_waitq;
659 struct list_head obd_exports;
660 struct list_head obd_unlinked_exports;
661 struct list_head obd_delayed_exports;
663 spinlock_t obd_nid_lock;
664 struct ldlm_namespace *obd_namespace;
665 struct ptlrpc_client obd_ldlm_client; /* XXX OST/MDS only */
666 /* a spinlock is OK for what we do now, may need a semaphore later */
667 spinlock_t obd_dev_lock; /* protect OBD bitfield above */
668 struct mutex obd_dev_mutex;
669 __u64 obd_last_committed;
670 spinlock_t obd_osfs_lock;
671 struct obd_statfs obd_osfs; /* locked by obd_osfs_lock */
673 struct lvfs_run_ctxt obd_lvfs_ctxt;
674 struct obd_llog_group obd_olg; /* default llog group */
675 struct obd_device *obd_observer;
676 struct rw_semaphore obd_observer_link_sem;
677 struct obd_notify_upcall obd_upcall;
678 struct obd_export *obd_self_export;
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 md_cntr_base;
691 struct lprocfs_stats *md_stats;
693 struct dentry *obd_debugfs_entry;
694 struct dentry *obd_svc_debugfs_entry;
695 struct lprocfs_stats *obd_svc_stats;
696 atomic_t obd_evict_inprogress;
697 wait_queue_head_t obd_evict_inprogress_waitq;
698 struct list_head obd_evict_list; /* protected with pet_lock */
701 * Ldlm pool part. Save last calculated SLV and Limit.
703 rwlock_t obd_pool_lock;
708 * A list of outstanding class_incref()'s against this obd. For
711 struct lu_ref obd_reference;
713 int obd_conn_inprogress;
715 struct kobject obd_kobj; /* sysfs object */
716 struct completion obd_kobj_unregister;
719 #define OBD_LLOG_FL_SENDNOW 0x0001
720 #define OBD_LLOG_FL_EXIT 0x0002
722 enum obd_cleanup_stage {
723 /* Special case hack for MDS LOVs */
725 /* can be directly mapped to .ldto_device_fini() */
729 /* get/set_info keys */
730 #define KEY_ASYNC "async"
731 #define KEY_BLOCKSIZE_BITS "blocksize_bits"
732 #define KEY_BLOCKSIZE "blocksize"
733 #define KEY_CHANGELOG_CLEAR "changelog_clear"
734 #define KEY_FID2PATH "fid2path"
735 #define KEY_CHECKSUM "checksum"
736 #define KEY_CLEAR_FS "clear_fs"
737 #define KEY_CONN_DATA "conn_data"
738 #define KEY_EVICT_BY_NID "evict_by_nid"
739 #define KEY_FIEMAP "fiemap"
740 #define KEY_FLUSH_CTX "flush_ctx"
741 #define KEY_GRANT_SHRINK "grant_shrink"
742 #define KEY_HSM_COPYTOOL_SEND "hsm_send"
743 #define KEY_INIT_RECOV_BACKUP "init_recov_bk"
744 #define KEY_INIT_RECOV "initial_recov"
745 #define KEY_INTERMDS "inter_mds"
746 #define KEY_LAST_ID "last_id"
747 #define KEY_LAST_FID "last_fid"
748 #define KEY_LOCK_TO_STRIPE "lock_to_stripe"
749 #define KEY_LOVDESC "lovdesc"
750 #define KEY_LOV_IDX "lov_idx"
751 #define KEY_MAX_EASIZE "max_easize"
752 #define KEY_DEFAULT_EASIZE "default_easize"
753 #define KEY_MDS_CONN "mds_conn"
754 #define KEY_MGSSEC "mgssec"
755 #define KEY_NEXT_ID "next_id"
756 #define KEY_READ_ONLY "read-only"
757 #define KEY_REGISTER_TARGET "register_target"
758 #define KEY_SET_FS "set_fs"
759 #define KEY_TGT_COUNT "tgt_count"
760 /* KEY_SET_INFO in lustre_idl.h */
761 #define KEY_SPTLRPC_CONF "sptlrpc_conf"
762 #define KEY_CONNECT_FLAG "connect_flags"
763 #define KEY_SYNC_LOCK_CANCEL "sync_lock_cancel"
765 #define KEY_CACHE_SET "cache_set"
766 #define KEY_CACHE_LRU_SHRINK "cache_lru_shrink"
767 #define KEY_CHANGELOG_INDEX "changelog_index"
771 /* /!\ must be coherent with include/linux/namei.h on patched kernel */
772 #define IT_OPEN (1 << 0)
773 #define IT_CREAT (1 << 1)
774 #define IT_READDIR (1 << 2)
775 #define IT_GETATTR (1 << 3)
776 #define IT_LOOKUP (1 << 4)
777 #define IT_UNLINK (1 << 5)
778 #define IT_TRUNC (1 << 6)
779 #define IT_GETXATTR (1 << 7)
780 #define IT_EXEC (1 << 8)
781 #define IT_PIN (1 << 9)
782 #define IT_LAYOUT (1 << 10)
783 #define IT_QUOTA_DQACQ (1 << 11)
784 #define IT_QUOTA_CONN (1 << 12)
785 #define IT_SETXATTR (1 << 13)
787 static inline int it_to_lock_mode(struct lookup_intent *it)
789 /* CREAT needs to be tested before open (both could be set) */
790 if (it->it_op & IT_CREAT)
792 else if (it->it_op & (IT_GETATTR | IT_OPEN | IT_LOOKUP |
795 else if (it->it_op & IT_READDIR)
797 else if (it->it_op & IT_GETXATTR)
799 else if (it->it_op & IT_SETXATTR)
802 LASSERTF(0, "Invalid it_op: %d\n", it->it_op);
807 struct lu_fid op_fid1; /* operation fid1 (usually parent) */
808 struct lu_fid op_fid2; /* operation fid2 (usually child) */
809 struct lu_fid op_fid3; /* 2 extra fids to find conflicting */
810 struct lu_fid op_fid4; /* to the operation locks. */
811 u32 op_mds; /* what mds server open will go to */
812 struct lustre_handle op_handle;
817 struct lmv_stripe_md *op_mea1;
818 struct lmv_stripe_md *op_mea2;
819 __u32 op_suppgids[2];
825 /* iattr fields and blocks. */
826 struct iattr op_attr;
827 unsigned int op_attr_flags;
829 loff_t op_attr_blocks;
831 /* Size-on-MDS epoch and flags. */
835 /* Various operation flags. */
836 enum mds_op_bias op_bias;
838 /* Used by readdir */
841 /* Used by readdir */
844 /* used to transfer info between the stacks of MD client
845 * see enum op_cli_flags
849 /* File object data version for HSM release, on client */
850 __u64 op_data_version;
851 struct lustre_handle op_lease_handle;
855 CLI_SET_MEA = 1 << 0,
856 CLI_RM_ENTRY = 1 << 1,
859 CLI_MIGRATE = BIT(4),
862 struct md_enqueue_info;
863 /* metadata stat-ahead */
865 struct md_enqueue_info {
866 struct md_op_data mi_data;
867 struct lookup_intent mi_it;
868 struct lustre_handle mi_lockh;
869 struct inode *mi_dir;
870 int (*mi_cb)(struct ptlrpc_request *req,
871 struct md_enqueue_info *minfo, int rc);
873 unsigned int mi_generation;
877 struct module *owner;
878 int (*iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
879 void *karg, void __user *uarg);
880 int (*get_info)(const struct lu_env *env, struct obd_export *,
881 __u32 keylen, void *key, __u32 *vallen, void *val,
882 struct lov_stripe_md *lsm);
883 int (*set_info_async)(const struct lu_env *, struct obd_export *,
884 __u32 keylen, void *key,
885 __u32 vallen, void *val,
886 struct ptlrpc_request_set *set);
887 int (*attach)(struct obd_device *dev, u32 len, void *data);
888 int (*detach)(struct obd_device *dev);
889 int (*setup)(struct obd_device *dev, struct lustre_cfg *cfg);
890 int (*precleanup)(struct obd_device *dev,
891 enum obd_cleanup_stage cleanup_stage);
892 int (*cleanup)(struct obd_device *dev);
893 int (*process_config)(struct obd_device *dev, u32 len, void *data);
894 int (*postrecov)(struct obd_device *dev);
895 int (*add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
897 int (*del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
898 /* connect to the target device with given connection
899 * data. @ocd->ocd_connect_flags is modified to reflect flags actually
900 * granted by the target, which are guaranteed to be a subset of flags
901 * asked for. If @ocd == NULL, use default parameters.
903 int (*connect)(const struct lu_env *env,
904 struct obd_export **exp, struct obd_device *src,
905 struct obd_uuid *cluuid, struct obd_connect_data *ocd,
907 int (*reconnect)(const struct lu_env *env,
908 struct obd_export *exp, struct obd_device *src,
909 struct obd_uuid *cluuid,
910 struct obd_connect_data *ocd,
912 int (*disconnect)(struct obd_export *exp);
914 /* Initialize/finalize fids infrastructure. */
915 int (*fid_init)(struct obd_device *obd,
916 struct obd_export *exp, enum lu_cli_type type);
917 int (*fid_fini)(struct obd_device *obd);
919 /* Allocate new fid according to passed @hint. */
920 int (*fid_alloc)(struct obd_export *exp, struct lu_fid *fid,
921 struct md_op_data *op_data);
924 * Object with @fid is getting deleted, we may want to do something
927 int (*statfs)(const struct lu_env *, struct obd_export *exp,
928 struct obd_statfs *osfs, __u64 max_age, __u32 flags);
929 int (*statfs_async)(struct obd_export *exp, struct obd_info *oinfo,
930 __u64 max_age, struct ptlrpc_request_set *set);
931 int (*packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
932 struct lov_stripe_md *mem_src);
933 int (*unpackmd)(struct obd_export *exp,
934 struct lov_stripe_md **mem_tgt,
935 struct lov_mds_md *disk_src, int disk_len);
936 int (*preallocate)(struct lustre_handle *, u32 *req, u64 *ids);
937 int (*create)(const struct lu_env *env, struct obd_export *exp,
938 struct obdo *oa, struct lov_stripe_md **ea,
939 struct obd_trans_info *oti);
940 int (*destroy)(const struct lu_env *env, struct obd_export *exp,
941 struct obdo *oa, struct lov_stripe_md *ea,
942 struct obd_trans_info *oti, struct obd_export *md_exp);
943 int (*setattr)(const struct lu_env *, struct obd_export *exp,
944 struct obd_info *oinfo, struct obd_trans_info *oti);
945 int (*setattr_async)(struct obd_export *exp, struct obd_info *oinfo,
946 struct obd_trans_info *oti,
947 struct ptlrpc_request_set *rqset);
948 int (*getattr)(const struct lu_env *env, struct obd_export *exp,
949 struct obd_info *oinfo);
950 int (*getattr_async)(struct obd_export *exp, struct obd_info *oinfo,
951 struct ptlrpc_request_set *set);
952 int (*adjust_kms)(struct obd_export *exp, struct lov_stripe_md *lsm,
953 u64 size, int shrink);
954 int (*preprw)(const struct lu_env *env, int cmd,
955 struct obd_export *exp, struct obdo *oa, int objcount,
956 struct obd_ioobj *obj, struct niobuf_remote *remote,
957 int *nr_pages, struct niobuf_local *local,
958 struct obd_trans_info *oti);
959 int (*commitrw)(const struct lu_env *env, int cmd,
960 struct obd_export *exp, struct obdo *oa,
961 int objcount, struct obd_ioobj *obj,
962 struct niobuf_remote *remote, int pages,
963 struct niobuf_local *local,
964 struct obd_trans_info *oti, int rc);
965 int (*find_cbdata)(struct obd_export *, struct lov_stripe_md *,
966 ldlm_iterator_t it, void *data);
967 int (*init_export)(struct obd_export *exp);
968 int (*destroy_export)(struct obd_export *exp);
970 /* metadata-only methods */
971 int (*import_event)(struct obd_device *, struct obd_import *,
972 enum obd_import_event);
974 int (*notify)(struct obd_device *obd, struct obd_device *watched,
975 enum obd_notify_event ev, void *data);
977 int (*health_check)(const struct lu_env *env, struct obd_device *);
978 struct obd_uuid *(*get_uuid)(struct obd_export *exp);
981 int (*quotacheck)(struct obd_device *, struct obd_export *,
982 struct obd_quotactl *);
983 int (*quotactl)(struct obd_device *, struct obd_export *,
984 struct obd_quotactl *);
987 int (*pool_new)(struct obd_device *obd, char *poolname);
988 int (*pool_del)(struct obd_device *obd, char *poolname);
989 int (*pool_add)(struct obd_device *obd, char *poolname,
991 int (*pool_rem)(struct obd_device *obd, char *poolname,
993 void (*getref)(struct obd_device *obd);
994 void (*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.
1002 /* lmv structures */
1004 struct mdt_body *body;
1005 struct lov_stripe_md *lsm;
1006 struct lmv_stripe_md *lmv;
1007 #ifdef CONFIG_FS_POSIX_ACL
1008 struct posix_acl *posix_acl;
1010 struct mdt_remote_perm *remote_perm;
1013 struct md_open_data {
1014 struct obd_client_handle *mod_och;
1015 struct ptlrpc_request *mod_open_req;
1016 struct ptlrpc_request *mod_close_req;
1017 atomic_t mod_refcount;
1021 struct lookup_intent;
1025 int (*getstatus)(struct obd_export *, struct lu_fid *);
1026 int (*null_inode)(struct obd_export *, const struct lu_fid *);
1027 int (*find_cbdata)(struct obd_export *, const struct lu_fid *,
1028 ldlm_iterator_t, void *);
1029 int (*close)(struct obd_export *, struct md_op_data *,
1030 struct md_open_data *, struct ptlrpc_request **);
1031 int (*create)(struct obd_export *, struct md_op_data *,
1032 const void *, int, int, __u32, __u32, cfs_cap_t,
1033 __u64, struct ptlrpc_request **);
1034 int (*done_writing)(struct obd_export *, struct md_op_data *,
1035 struct md_open_data *);
1036 int (*enqueue)(struct obd_export *, struct ldlm_enqueue_info *,
1037 struct lookup_intent *, struct md_op_data *,
1038 struct lustre_handle *, void *, int,
1039 struct ptlrpc_request **, __u64);
1040 int (*getattr)(struct obd_export *, struct md_op_data *,
1041 struct ptlrpc_request **);
1042 int (*getattr_name)(struct obd_export *, struct md_op_data *,
1043 struct ptlrpc_request **);
1044 int (*intent_lock)(struct obd_export *, struct md_op_data *,
1045 void *, int, struct lookup_intent *, int,
1046 struct ptlrpc_request **,
1047 ldlm_blocking_callback, __u64);
1048 int (*link)(struct obd_export *, struct md_op_data *,
1049 struct ptlrpc_request **);
1050 int (*rename)(struct obd_export *, struct md_op_data *,
1051 const char *, int, const char *, int,
1052 struct ptlrpc_request **);
1053 int (*is_subdir)(struct obd_export *, const struct lu_fid *,
1054 const struct lu_fid *,
1055 struct ptlrpc_request **);
1056 int (*setattr)(struct obd_export *, struct md_op_data *, void *,
1057 int, void *, int, struct ptlrpc_request **,
1058 struct md_open_data **mod);
1059 int (*sync)(struct obd_export *, const struct lu_fid *,
1060 struct ptlrpc_request **);
1061 int (*readpage)(struct obd_export *, struct md_op_data *,
1062 struct page **, struct ptlrpc_request **);
1064 int (*unlink)(struct obd_export *, struct md_op_data *,
1065 struct ptlrpc_request **);
1067 int (*setxattr)(struct obd_export *, const struct lu_fid *,
1068 u64, const char *, const char *, int, int, int, __u32,
1069 struct ptlrpc_request **);
1071 int (*getxattr)(struct obd_export *, const struct lu_fid *,
1072 u64, const char *, const char *, int, int, int,
1073 struct ptlrpc_request **);
1075 int (*init_ea_size)(struct obd_export *, int, int, int, int);
1077 int (*get_lustre_md)(struct obd_export *, struct ptlrpc_request *,
1078 struct obd_export *, struct obd_export *,
1079 struct lustre_md *);
1081 int (*free_lustre_md)(struct obd_export *, struct lustre_md *);
1083 int (*merge_attr)(struct obd_export *,
1084 const struct lmv_stripe_md *lsm,
1085 struct cl_attr *attr);
1087 int (*update_lsm_md)(struct obd_export *, struct lmv_stripe_md *lsm,
1088 struct mdt_body *, ldlm_blocking_callback);
1090 int (*set_open_replay_data)(struct obd_export *,
1091 struct obd_client_handle *,
1092 struct lookup_intent *);
1093 int (*clear_open_replay_data)(struct obd_export *,
1094 struct obd_client_handle *);
1095 int (*set_lock_data)(struct obd_export *, __u64 *, void *, __u64 *);
1097 enum ldlm_mode (*lock_match)(struct obd_export *, __u64,
1098 const struct lu_fid *, enum ldlm_type,
1099 ldlm_policy_data_t *, enum ldlm_mode,
1100 struct lustre_handle *);
1102 int (*cancel_unused)(struct obd_export *, const struct lu_fid *,
1103 ldlm_policy_data_t *, enum ldlm_mode,
1104 enum ldlm_cancel_flags flags, void *opaque);
1106 int (*intent_getattr_async)(struct obd_export *,
1107 struct md_enqueue_info *,
1108 struct ldlm_enqueue_info *);
1110 int (*revalidate_lock)(struct obd_export *, struct lookup_intent *,
1111 struct lu_fid *, __u64 *bits);
1114 * NOTE: If adding ops, add another LPROCFS_MD_OP_INIT() line to
1115 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
1116 * wrapper function in include/linux/obd_class.h.
1120 struct lsm_operations {
1121 void (*lsm_free)(struct lov_stripe_md *);
1122 int (*lsm_destroy)(struct lov_stripe_md *, struct obdo *oa,
1123 struct obd_export *md_exp);
1124 void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *, u64 *,
1126 void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *, u64 *,
1128 int (*lsm_lmm_verify)(struct lov_mds_md *lmm, int lmm_bytes,
1129 __u16 *stripe_count);
1130 int (*lsm_unpackmd)(struct lov_obd *lov, struct lov_stripe_md *lsm,
1131 struct lov_mds_md *lmm);
1134 extern const struct lsm_operations lsm_v1_ops;
1135 extern const struct lsm_operations lsm_v3_ops;
1136 static inline const struct lsm_operations *lsm_op_find(int magic)
1144 CERROR("Cannot recognize lsm_magic %08x\n", magic);
1149 /* Requests for obd_extent_calc() */
1150 #define OBD_CALC_STRIPE_START 1
1151 #define OBD_CALC_STRIPE_END 2
1153 static inline struct md_open_data *obd_mod_alloc(void)
1155 struct md_open_data *mod;
1157 mod = kzalloc(sizeof(*mod), GFP_NOFS);
1160 atomic_set(&mod->mod_refcount, 1);
1164 #define obd_mod_get(mod) atomic_inc(&(mod)->mod_refcount)
1165 #define obd_mod_put(mod) \
1167 if (atomic_dec_and_test(&(mod)->mod_refcount)) { \
1168 if ((mod)->mod_open_req) \
1169 ptlrpc_req_finished((mod)->mod_open_req); \
1174 void obdo_from_inode(struct obdo *dst, struct inode *src, u32 valid);
1175 void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent);
1177 /* return 1 if client should be resend request */
1178 static inline int client_should_resend(int resend, struct client_obd *cli)
1180 return atomic_read(&cli->cl_resends) ?
1181 atomic_read(&cli->cl_resends) > resend : 1;
1185 * Return device name for this device
1187 * XXX: lu_device is declared before obd_device, while a pointer pointing
1188 * back to obd_device in lu_device, so this helper function defines here
1189 * instead of in lu_object.h
1191 static inline const char *lu_dev_name(const struct lu_device *lu_dev)
1193 return lu_dev->ld_obd->obd_name;
1196 static inline bool filename_is_volatile(const char *name, int namelen, int *idx)
1201 if (strncmp(name, LUSTRE_VOLATILE_HDR, LUSTRE_VOLATILE_HDR_LEN) != 0)
1204 /* caller does not care of idx */
1208 /* volatile file, the MDT can be set from name */
1209 /* name format is LUSTRE_VOLATILE_HDR:[idx]: */
1210 /* if no MDT is specified, use std way */
1211 if (namelen < LUSTRE_VOLATILE_HDR_LEN + 2)
1213 /* test for no MDT idx case */
1214 if ((*(name + LUSTRE_VOLATILE_HDR_LEN) == ':') &&
1215 (*(name + LUSTRE_VOLATILE_HDR_LEN + 1) == ':')) {
1219 /* we have an idx, read it */
1220 start = name + LUSTRE_VOLATILE_HDR_LEN + 1;
1221 *idx = simple_strtoul(start, &end, 0);
1223 * no digit, no trailing :, negative value
1225 if (((*idx == 0) && (end == start)) ||
1226 (*end != ':') || (*idx < 0))
1231 /* bad format of mdt idx, we cannot return an error
1232 * to caller so we use hash algo
1234 CERROR("Bad volatile file name format: %s\n",
1235 name + LUSTRE_VOLATILE_HDR_LEN);
1239 static inline int cli_brw_size(struct obd_device *obd)
1241 return obd->u.cli.cl_max_pages_per_rpc << PAGE_SHIFT;
1244 #endif /* __OBD_H */