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, 2015, 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 #define IOC_OSC_TYPE 'h'
43 #define IOC_OSC_MIN_NR 20
44 #define IOC_OSC_SET_ACTIVE _IOWR(IOC_OSC_TYPE, 21, struct obd_device *)
45 #define IOC_OSC_MAX_NR 50
47 #define IOC_MDC_TYPE 'i'
48 #define IOC_MDC_MIN_NR 20
49 #define IOC_MDC_MAX_NR 50
51 #include "lustre/lustre_idl.h"
52 #include "lustre_lib.h"
54 #include "lustre_export.h"
55 #include "lustre_fid.h"
56 #include "lustre_fld.h"
57 #include "lustre_intent.h"
59 #define MAX_OBD_DEVICES 8192
67 struct lov_oinfo
{ /* per-stripe data structure */
68 struct ost_id loi_oi
; /* object ID/Sequence on the target OST */
69 int loi_ost_idx
; /* OST stripe index in lov_tgt_desc->tgts */
70 int loi_ost_gen
; /* generation of this loi_ost_idx */
72 unsigned long loi_kms_valid
:1;
73 __u64 loi_kms
; /* known minimum size */
74 struct ost_lvb loi_lvb
;
75 struct osc_async_rc loi_ar
;
78 static inline void loi_kms_set(struct lov_oinfo
*oinfo
, __u64 kms
)
81 oinfo
->loi_kms_valid
= 1;
84 static inline void loi_init(struct lov_oinfo
*loi
)
88 struct lov_stripe_md
{
91 pid_t lsm_lock_owner
; /* debugging */
93 /* maximum possible file size, might change as OSTs status changes,
94 * e.g. disconnected, deactivated
99 struct ost_id lw_object_oi
; /* lov object id/seq */
101 /* LOV-private members start here -- only for use in lov/. */
103 __u32 lw_stripe_size
; /* size of the stripe */
104 __u32 lw_pattern
; /* striping pattern (RAID0, RAID1) */
105 __u16 lw_stripe_count
; /* number of objects being striped over */
106 __u16 lw_layout_gen
; /* generation of the layout */
107 char lw_pool_name
[LOV_MAXPOOLNAME
]; /* pool name */
110 struct lov_oinfo
*lsm_oinfo
[0];
113 #define lsm_oi lsm_wire.lw_object_oi
114 #define lsm_magic lsm_wire.lw_magic
115 #define lsm_layout_gen lsm_wire.lw_layout_gen
116 #define lsm_stripe_size lsm_wire.lw_stripe_size
117 #define lsm_pattern lsm_wire.lw_pattern
118 #define lsm_stripe_count lsm_wire.lw_stripe_count
119 #define lsm_pool_name lsm_wire.lw_pool_name
121 static inline bool lsm_is_released(struct lov_stripe_md
*lsm
)
123 return !!(lsm
->lsm_pattern
& LOV_PATTERN_F_RELEASED
);
126 static inline bool lsm_has_objects(struct lov_stripe_md
*lsm
)
130 if (lsm_is_released(lsm
))
135 static inline int lov_stripe_md_size(unsigned int stripe_count
)
137 struct lov_stripe_md lsm
;
139 return sizeof(lsm
) + stripe_count
* sizeof(lsm
.lsm_oinfo
[0]);
144 typedef int (*obd_enqueue_update_f
)(void *cookie
, int rc
);
146 /* obd info for a particular level (lov, osc). */
148 /* Flags used for set request specific flags:
149 - while lock handling, the flags obtained on the enqueue
150 request are set here.
151 - while stats, the flags used for control delay/resend.
152 - while setattr, the flags used for distinguish punch operation
155 /* lsm data specific for every OSC. */
156 struct lov_stripe_md
*oi_md
;
157 /* obdo data specific for every OSC, if needed at all. */
159 /* statfs data specific for every OSC, if needed at all. */
160 struct obd_statfs
*oi_osfs
;
161 /* An update callback which is called to update some data on upper
162 * level. E.g. it is used for update lsm->lsm_oinfo at every received
163 * request in osc level for enqueue requests. It is also possible to
164 * update some caller data from LOV layer if needed.
166 obd_enqueue_update_f oi_cb_up
;
170 struct list_head typ_chain
;
171 struct obd_ops
*typ_dt_ops
;
172 struct md_ops
*typ_md_ops
;
173 struct dentry
*typ_debugfs_entry
;
176 struct lu_device_type
*typ_lu
;
177 spinlock_t obd_type_lock
;
178 struct kobject
*typ_kobj
;
190 LLOG_CONFIG_ORIG_CTXT
= 0,
191 LLOG_CONFIG_REPL_CTXT
,
192 LLOG_MDS_OST_ORIG_CTXT
,
193 LLOG_MDS_OST_REPL_CTXT
,
200 LLOG_LOVEA_ORIG_CTXT
,
201 LLOG_LOVEA_REPL_CTXT
,
202 LLOG_CHANGELOG_ORIG_CTXT
, /**< changelog generation on mdd */
203 LLOG_CHANGELOG_REPL_CTXT
, /**< changelog access on clients */
204 LLOG_CHANGELOG_USER_ORIG_CTXT
, /**< for multiple changelog consumers */
205 LLOG_AGENT_ORIG_CTXT
, /**< agent requests generation on cdt */
209 struct timeout_item
{
210 enum timeout_event ti_event
;
211 unsigned long ti_timeout
;
214 struct list_head ti_obd_list
;
215 struct list_head ti_chain
;
218 #define OSC_MAX_RIF_DEFAULT 8
219 #define OSC_MAX_RIF_MAX 256
220 #define OSC_MAX_DIRTY_DEFAULT (OSC_MAX_RIF_DEFAULT * 4)
221 #define OSC_MAX_DIRTY_MB_MAX 2048 /* arbitrary, but < MAX_LONG bytes */
222 #define OSC_DEFAULT_RESENDS 10
224 /* possible values for fo_sync_lock_cancel */
226 NEVER_SYNC_ON_CANCEL
= 0,
227 BLOCKING_SYNC_ON_CANCEL
= 1,
228 ALWAYS_SYNC_ON_CANCEL
= 2,
229 NUM_SYNC_ON_CANCEL_STATES
232 #define MDC_MAX_RIF_DEFAULT 8
233 #define MDC_MAX_RIF_MAX 512
238 struct rw_semaphore cl_sem
;
239 struct obd_uuid cl_target_uuid
;
240 struct obd_import
*cl_import
; /* ptlrpc connection state */
242 /* max_mds_easize is purely a performance thing so we don't have to
243 * call obd_size_diskmd() all the time.
245 int cl_default_mds_easize
;
246 int cl_max_mds_easize
;
247 int cl_default_mds_cookiesize
;
248 int cl_max_mds_cookiesize
;
250 enum lustre_sec_part cl_sp_me
;
251 enum lustre_sec_part cl_sp_to
;
252 struct sptlrpc_flavor cl_flvr_mgc
; /* fixed flavor of mgc->mgs */
254 /* the grant values are protected by loi_list_lock below */
255 long cl_dirty
; /* all _dirty_ in bytes */
256 long cl_dirty_max
; /* allowed w/o rpc */
257 long cl_dirty_transit
; /* dirty synchronous */
258 long cl_avail_grant
; /* bytes of credit for ost */
259 long cl_lost_grant
; /* lost credits (trunc) */
261 /* since we allocate grant by blocks, we don't know how many grant will
262 * be used to add a page into cache. As a solution, we reserve maximum
263 * grant before trying to dirty a page and unreserve the rest.
264 * See osc_{reserve|unreserve}_grant for details.
266 long cl_reserved_grant
;
267 struct list_head cl_cache_waiters
; /* waiting for cache/grant */
268 unsigned long cl_next_shrink_grant
; /* jiffies */
269 struct list_head cl_grant_shrink_list
; /* Timeout event list */
270 int cl_grant_shrink_interval
; /* seconds */
272 /* A chunk is an optimal size used by osc_extent to determine
273 * the extent size. A chunk is max(PAGE_SIZE, OST block size)
277 int cl_extent_tax
; /* extent overhead, by bytes */
279 /* keep track of objects that have lois that contain pages which
280 * have been queued for async brw. this lock also protects the
281 * lists of osc_client_pages that hang off of the loi
284 * ->cl_loi_list_lock protects consistency of
285 * ->cl_loi_{ready,read,write}_list. ->ap_make_ready() and
286 * ->ap_completion() call-backs are executed under this lock. As we
287 * cannot guarantee that these call-backs never block on all platforms
288 * (as a matter of fact they do block on Mac OS X), type of
289 * ->cl_loi_list_lock is platform dependent: it's a spin-lock on Linux
290 * and blocking mutex on Mac OS X. (Alternative is to make this lock
291 * blocking everywhere, but we don't want to slow down fast-path of
292 * our main platform.)
294 * NB by Jinshan: though field names are still _loi_, but actually
295 * osc_object{}s are in the list.
297 spinlock_t cl_loi_list_lock
;
298 struct list_head cl_loi_ready_list
;
299 struct list_head cl_loi_hp_ready_list
;
300 struct list_head cl_loi_write_list
;
301 struct list_head cl_loi_read_list
;
304 /* just a sum of the loi/lop pending numbers to be exported by sysfs */
305 atomic_t cl_pending_w_pages
;
306 atomic_t cl_pending_r_pages
;
307 __u32 cl_max_pages_per_rpc
;
308 int cl_max_rpcs_in_flight
;
309 struct obd_histogram cl_read_rpc_hist
;
310 struct obd_histogram cl_write_rpc_hist
;
311 struct obd_histogram cl_read_page_hist
;
312 struct obd_histogram cl_write_page_hist
;
313 struct obd_histogram cl_read_offset_hist
;
314 struct obd_histogram cl_write_offset_hist
;
316 /* lru for osc caching pages */
317 struct cl_client_cache
*cl_cache
;
318 struct list_head cl_lru_osc
; /* member of cl_cache->ccc_lru */
319 atomic_t
*cl_lru_left
;
320 atomic_t cl_lru_busy
;
321 atomic_t cl_lru_shrinkers
;
322 atomic_t cl_lru_in_list
;
323 struct list_head cl_lru_list
; /* lru page list */
324 spinlock_t cl_lru_list_lock
; /* page list protector */
325 atomic_t cl_unstable_count
;
327 /* number of in flight destroy rpcs is limited to max_rpcs_in_flight */
328 atomic_t cl_destroy_in_flight
;
329 wait_queue_head_t cl_destroy_waitq
;
331 struct mdc_rpc_lock
*cl_rpc_lock
;
332 struct mdc_rpc_lock
*cl_close_lock
;
335 atomic_t cl_mgc_refcount
;
336 struct obd_export
*cl_mgc_mgsexp
;
338 /* checksumming for data sent over the network */
339 unsigned int cl_checksum
:1; /* 0 = disabled, 1 = enabled */
340 /* supported checksum types that are worked out at connect time */
341 __u32 cl_supp_cksum_types
;
342 /* checksum algorithm to be used */
343 enum cksum_type cl_cksum_type
;
345 /* also protected by the poorly named _loi_list_lock lock above */
346 struct osc_async_rc cl_ar
;
348 /* used by quotacheck when the servers are older than 2.4 */
349 int cl_qchk_stat
; /* quotacheck stat of the peer */
350 #define CL_NOT_QUOTACHECKED 1 /* client->cl_qchk_stat init value */
351 #if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 7, 50, 0)
352 #warning "please consider removing quotacheck compatibility code"
355 /* sequence manager */
356 struct lu_client_seq
*cl_seq
;
358 atomic_t cl_resends
; /* resend count */
360 /* ptlrpc work for writeback in ptlrpcd context */
361 void *cl_writeback_work
;
363 /* hash tables for osc_quota_info */
364 struct cfs_hash
*cl_quota_hash
[MAXQUOTAS
];
367 #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
374 struct echo_client_obd
{
375 struct obd_export
*ec_exp
; /* the local connection to osc/lov */
377 struct list_head ec_objects
;
378 struct list_head ec_locks
;
382 /* Generic subset of OSTs */
384 __u32
*op_array
; /* array of index of lov_obd->lov_tgts */
385 unsigned int op_count
; /* number of OSTs in the array */
386 unsigned int op_size
; /* allocated size of lp_array */
387 struct rw_semaphore op_rw_sem
; /* to protect ost_pool use */
390 /* allow statfs data caching for 1 second */
391 #define OBD_STATFS_CACHE_SECONDS 1
393 struct lov_tgt_desc
{
394 struct list_head ltd_kill
;
395 struct obd_uuid ltd_uuid
;
396 struct obd_device
*ltd_obd
;
397 struct obd_export
*ltd_exp
;
399 __u32 ltd_index
; /* index in lov_obd->tgts */
400 unsigned long ltd_active
:1,/* is this target up for requests */
401 ltd_activate
:1,/* should target be activated */
402 ltd_reap
:1; /* should this target be deleted */
406 struct lov_desc desc
;
407 struct lov_tgt_desc
**lov_tgts
; /* sparse array */
408 struct ost_pool lov_packed
; /* all OSTs in a packed array */
409 struct mutex lov_lock
;
410 struct obd_connect_data lov_ocd
;
411 atomic_t lov_refcount
;
412 __u32 lov_death_row
;/* tgts scheduled to be deleted */
413 __u32 lov_tgt_size
; /* size of tgts array */
416 struct cfs_hash
*lov_pools_hash_body
; /* used for key access */
417 struct list_head lov_pool_list
; /* used for sequential access */
418 struct dentry
*lov_pool_debugfs_entry
;
419 enum lustre_sec_part lov_sp_me
;
421 /* Cached LRU and unstable data from upper layer */
424 struct rw_semaphore lov_notify_lock
;
426 struct kobject
*lov_tgts_kobj
;
429 struct lmv_tgt_desc
{
430 struct obd_uuid ltd_uuid
;
431 struct obd_export
*ltd_exp
;
433 struct mutex ltd_fid_mutex
;
434 unsigned long ltd_active
:1; /* target up for requests */
437 enum placement_policy
{
438 PLACEMENT_CHAR_POLICY
= 0,
439 PLACEMENT_NID_POLICY
= 1,
440 PLACEMENT_INVAL_POLICY
= 2,
446 struct lu_client_fld lmv_fld
;
448 enum placement_policy lmv_placement
;
449 struct lmv_desc desc
;
450 struct obd_uuid cluuid
;
451 struct obd_export
*exp
;
453 struct mutex lmv_init_mutex
;
458 int max_def_cookiesize
;
461 int tgts_size
; /* size of tgts array */
462 struct lmv_tgt_desc
**tgts
;
464 struct obd_connect_data conn_data
;
465 struct kobject
*lmv_tgts_kobj
;
468 struct niobuf_local
{
469 __u64 lnb_file_offset
;
470 __u32 lnb_page_offset
;
474 struct dentry
*dentry
;
479 #define LUSTRE_FLD_NAME "fld"
480 #define LUSTRE_SEQ_NAME "seq"
482 #define LUSTRE_MDD_NAME "mdd"
483 #define LUSTRE_OSD_LDISKFS_NAME "osd-ldiskfs"
484 #define LUSTRE_OSD_ZFS_NAME "osd-zfs"
485 #define LUSTRE_VVP_NAME "vvp"
486 #define LUSTRE_LMV_NAME "lmv"
487 #define LUSTRE_SLP_NAME "slp"
488 #define LUSTRE_LOD_NAME "lod"
489 #define LUSTRE_OSP_NAME "osp"
490 #define LUSTRE_LWP_NAME "lwp"
492 /* obd device type names */
493 /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */
494 #define LUSTRE_MDS_NAME "mds"
495 #define LUSTRE_MDT_NAME "mdt"
496 #define LUSTRE_MDC_NAME "mdc"
497 #define LUSTRE_OSS_NAME "ost" /* FIXME change name to oss */
498 #define LUSTRE_OST_NAME "obdfilter" /* FIXME change name to ost */
499 #define LUSTRE_OSC_NAME "osc"
500 #define LUSTRE_LOV_NAME "lov"
501 #define LUSTRE_MGS_NAME "mgs"
502 #define LUSTRE_MGC_NAME "mgc"
504 #define LUSTRE_ECHO_NAME "obdecho"
505 #define LUSTRE_ECHO_CLIENT_NAME "echo_client"
506 #define LUSTRE_QMT_NAME "qmt"
508 /* Constant obd names (post-rename) */
509 #define LUSTRE_MDS_OBDNAME "MDS"
510 #define LUSTRE_OSS_OBDNAME "OSS"
511 #define LUSTRE_MGS_OBDNAME "MGS"
512 #define LUSTRE_MGC_OBDNAME "MGC"
514 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
515 #define N_LOCAL_TEMP_PAGE 0x10000000
517 struct obd_trans_info
{
520 /* Only used on the server side for tracking acks. */
521 struct oti_req_ack_lock
{
522 struct lustre_handle lock
;
526 struct llog_cookie oti_onecookie
;
527 struct llog_cookie
*oti_logcookies
;
529 /** synchronous write is needed */
530 unsigned long oti_sync_write
:1;
532 /* initial thread handling transaction */
533 struct ptlrpc_thread
*oti_thread
;
536 __u64 oti_pre_version
;
540 struct obd_uuid
*oti_ost_uuid
;
543 static inline void oti_alloc_cookies(struct obd_trans_info
*oti
,
549 if (num_cookies
== 1)
550 oti
->oti_logcookies
= &oti
->oti_onecookie
;
552 oti
->oti_logcookies
= libcfs_kvzalloc(num_cookies
* sizeof(oti
->oti_onecookie
),
555 oti
->oti_numcookies
= num_cookies
;
558 static inline void oti_free_cookies(struct obd_trans_info
*oti
)
560 if (!oti
|| !oti
->oti_logcookies
)
563 if (oti
->oti_logcookies
== &oti
->oti_onecookie
)
564 LASSERT(oti
->oti_numcookies
== 1);
566 kvfree(oti
->oti_logcookies
);
568 oti
->oti_logcookies
= NULL
;
569 oti
->oti_numcookies
= 0;
573 * Events signalled through obd_notify() upcall-chain.
575 enum obd_notify_event
{
578 /* Device connect start */
580 /* Device activated */
582 /* Device deactivated */
584 /* Device disconnected */
586 /* Connect data for import were changed */
589 OBD_NOTIFY_SYNC_NONBLOCK
,
591 /* Configuration event */
593 /* Administratively deactivate/activate event */
594 OBD_NOTIFY_DEACTIVATE
,
599 * Data structure used to pass obd_notify()-event to non-obd listeners (llite
600 * being main example).
602 struct obd_notify_upcall
{
603 int (*onu_upcall
)(struct obd_device
*host
, struct obd_device
*watched
,
604 enum obd_notify_event ev
, void *owner
, void *data
);
605 /* Opaque datum supplied by upper layer listener */
609 struct target_recovery_data
{
610 svc_handler_t trd_recovery_handler
;
611 pid_t trd_processing_task
;
612 struct completion trd_starting
;
613 struct completion trd_finishing
;
616 struct obd_llog_group
{
618 struct llog_ctxt
*olg_ctxts
[LLOG_MAX_CTXTS
];
619 wait_queue_head_t olg_waitq
;
621 struct mutex olg_cat_processing
;
624 /* corresponds to one of the obd's */
625 #define OBD_DEVICE_MAGIC 0XAB5CD6EF
626 #define OBD_DEV_BY_DEVNAME 0xffffd0de
628 struct lvfs_run_ctxt
{
629 struct dt_device
*dt
;
633 struct obd_type
*obd_type
;
636 /* common and UUID name of this device */
637 char obd_name
[MAX_OBD_NAME
];
638 struct obd_uuid obd_uuid
;
640 struct lu_device
*obd_lu_dev
;
643 /* bitfield modification is protected by obd_dev_lock */
644 unsigned long obd_attached
:1, /* finished attach */
645 obd_set_up
:1, /* finished setup */
646 obd_version_recov
:1, /* obd uses version checking */
647 obd_replayable
:1,/* recovery is enabled; inform clients */
648 obd_no_transno
:1, /* no committed-transno notification */
649 obd_no_recov
:1, /* fail instead of retry messages */
650 obd_stopping
:1, /* started cleanup */
651 obd_starting
:1, /* started setup */
652 obd_force
:1, /* cleanup with > 0 obd refcount */
653 obd_fail
:1, /* cleanup with failover */
654 obd_async_recov
:1, /* allow asynchronous orphan cleanup */
655 obd_no_conn
:1, /* deny new connections */
656 obd_inactive
:1, /* device active/inactive
657 * (for sysfs status only!!)
659 obd_no_ir
:1, /* no imperative recovery. */
660 obd_process_conf
:1; /* device is processing mgs config */
661 /* use separate field as it is set in interrupt to don't mess with
662 * protection of other bits using _bh lock
664 unsigned long obd_recovery_expired
:1;
665 /* uuid-export hash body */
666 struct cfs_hash
*obd_uuid_hash
;
667 atomic_t obd_refcount
;
668 wait_queue_head_t obd_refcount_waitq
;
669 struct list_head obd_exports
;
670 struct list_head obd_unlinked_exports
;
671 struct list_head obd_delayed_exports
;
673 spinlock_t obd_nid_lock
;
674 struct ldlm_namespace
*obd_namespace
;
675 struct ptlrpc_client obd_ldlm_client
; /* XXX OST/MDS only */
676 /* a spinlock is OK for what we do now, may need a semaphore later */
677 spinlock_t obd_dev_lock
; /* protect OBD bitfield above */
678 struct mutex obd_dev_mutex
;
679 __u64 obd_last_committed
;
680 spinlock_t obd_osfs_lock
;
681 struct obd_statfs obd_osfs
; /* locked by obd_osfs_lock */
683 struct lvfs_run_ctxt obd_lvfs_ctxt
;
684 struct obd_llog_group obd_olg
; /* default llog group */
685 struct obd_device
*obd_observer
;
686 struct rw_semaphore obd_observer_link_sem
;
687 struct obd_notify_upcall obd_upcall
;
688 struct obd_export
*obd_self_export
;
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 md_cntr_base
;
701 struct lprocfs_stats
*md_stats
;
703 struct dentry
*obd_debugfs_entry
;
704 struct dentry
*obd_svc_debugfs_entry
;
705 struct lprocfs_stats
*obd_svc_stats
;
706 atomic_t obd_evict_inprogress
;
707 wait_queue_head_t obd_evict_inprogress_waitq
;
708 struct list_head obd_evict_list
; /* protected with pet_lock */
711 * Ldlm pool part. Save last calculated SLV and Limit.
713 rwlock_t obd_pool_lock
;
718 * A list of outstanding class_incref()'s against this obd. For
721 struct lu_ref obd_reference
;
723 int obd_conn_inprogress
;
725 struct kobject obd_kobj
; /* sysfs object */
726 struct completion obd_kobj_unregister
;
729 #define OBD_LLOG_FL_SENDNOW 0x0001
730 #define OBD_LLOG_FL_EXIT 0x0002
732 enum obd_cleanup_stage
{
733 /* Special case hack for MDS LOVs */
735 /* can be directly mapped to .ldto_device_fini() */
739 /* get/set_info keys */
740 #define KEY_ASYNC "async"
741 #define KEY_BLOCKSIZE_BITS "blocksize_bits"
742 #define KEY_BLOCKSIZE "blocksize"
743 #define KEY_CHANGELOG_CLEAR "changelog_clear"
744 #define KEY_FID2PATH "fid2path"
745 #define KEY_CHECKSUM "checksum"
746 #define KEY_CLEAR_FS "clear_fs"
747 #define KEY_CONN_DATA "conn_data"
748 #define KEY_EVICT_BY_NID "evict_by_nid"
749 #define KEY_FIEMAP "fiemap"
750 #define KEY_FLUSH_CTX "flush_ctx"
751 #define KEY_GRANT_SHRINK "grant_shrink"
752 #define KEY_HSM_COPYTOOL_SEND "hsm_send"
753 #define KEY_INIT_RECOV_BACKUP "init_recov_bk"
754 #define KEY_INIT_RECOV "initial_recov"
755 #define KEY_INTERMDS "inter_mds"
756 #define KEY_LAST_ID "last_id"
757 #define KEY_LAST_FID "last_fid"
758 #define KEY_LOCK_TO_STRIPE "lock_to_stripe"
759 #define KEY_LOVDESC "lovdesc"
760 #define KEY_LOV_IDX "lov_idx"
761 #define KEY_MAX_EASIZE "max_easize"
762 #define KEY_DEFAULT_EASIZE "default_easize"
763 #define KEY_MDS_CONN "mds_conn"
764 #define KEY_MGSSEC "mgssec"
765 #define KEY_NEXT_ID "next_id"
766 #define KEY_READ_ONLY "read-only"
767 #define KEY_REGISTER_TARGET "register_target"
768 #define KEY_SET_FS "set_fs"
769 #define KEY_TGT_COUNT "tgt_count"
770 /* KEY_SET_INFO in lustre_idl.h */
771 #define KEY_SPTLRPC_CONF "sptlrpc_conf"
772 #define KEY_CONNECT_FLAG "connect_flags"
773 #define KEY_SYNC_LOCK_CANCEL "sync_lock_cancel"
775 #define KEY_CACHE_SET "cache_set"
776 #define KEY_CACHE_LRU_SHRINK "cache_lru_shrink"
777 #define KEY_CHANGELOG_INDEX "changelog_index"
781 /* /!\ must be coherent with include/linux/namei.h on patched kernel */
782 #define IT_OPEN (1 << 0)
783 #define IT_CREAT (1 << 1)
784 #define IT_READDIR (1 << 2)
785 #define IT_GETATTR (1 << 3)
786 #define IT_LOOKUP (1 << 4)
787 #define IT_UNLINK (1 << 5)
788 #define IT_TRUNC (1 << 6)
789 #define IT_GETXATTR (1 << 7)
790 #define IT_EXEC (1 << 8)
791 #define IT_PIN (1 << 9)
792 #define IT_LAYOUT (1 << 10)
793 #define IT_QUOTA_DQACQ (1 << 11)
794 #define IT_QUOTA_CONN (1 << 12)
795 #define IT_SETXATTR (1 << 13)
797 static inline int it_to_lock_mode(struct lookup_intent
*it
)
799 /* CREAT needs to be tested before open (both could be set) */
800 if (it
->it_op
& IT_CREAT
)
802 else if (it
->it_op
& (IT_READDIR
| IT_GETATTR
| IT_OPEN
| IT_LOOKUP
|
805 else if (it
->it_op
& IT_GETXATTR
)
807 else if (it
->it_op
& IT_SETXATTR
)
810 LASSERTF(0, "Invalid it_op: %d\n", it
->it_op
);
815 struct lu_fid op_fid1
; /* operation fid1 (usually parent) */
816 struct lu_fid op_fid2
; /* operation fid2 (usually child) */
817 struct lu_fid op_fid3
; /* 2 extra fids to find conflicting */
818 struct lu_fid op_fid4
; /* to the operation locks. */
819 u32 op_mds
; /* what mds server open will go to */
820 struct lustre_handle op_handle
;
825 struct lmv_stripe_md
*op_mea1
;
826 struct lmv_stripe_md
*op_mea2
;
827 __u32 op_suppgids
[2];
833 /* iattr fields and blocks. */
834 struct iattr op_attr
;
835 unsigned int op_attr_flags
;
837 loff_t op_attr_blocks
;
839 /* Size-on-MDS epoch and flags. */
843 /* Various operation flags. */
844 enum mds_op_bias op_bias
;
849 /* Used by readdir */
852 /* Used by readdir */
855 /* used to transfer info between the stacks of MD client
856 * see enum op_cli_flags
860 /* File object data version for HSM release, on client */
861 __u64 op_data_version
;
862 struct lustre_handle op_lease_handle
;
866 CLI_SET_MEA
= 1 << 0,
867 CLI_RM_ENTRY
= 1 << 1,
870 struct md_enqueue_info
;
871 /* metadata stat-ahead */
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 int (*mi_cb
)(struct ptlrpc_request
*req
,
879 struct md_enqueue_info
*minfo
, int rc
);
881 unsigned int mi_generation
;
885 struct module
*owner
;
886 int (*iocontrol
)(unsigned int cmd
, struct obd_export
*exp
, int len
,
887 void *karg
, void __user
*uarg
);
888 int (*get_info
)(const struct lu_env
*env
, struct obd_export
*,
889 __u32 keylen
, void *key
, __u32
*vallen
, void *val
,
890 struct lov_stripe_md
*lsm
);
891 int (*set_info_async
)(const struct lu_env
*, struct obd_export
*,
892 __u32 keylen
, void *key
,
893 __u32 vallen
, void *val
,
894 struct ptlrpc_request_set
*set
);
895 int (*attach
)(struct obd_device
*dev
, u32 len
, void *data
);
896 int (*detach
)(struct obd_device
*dev
);
897 int (*setup
)(struct obd_device
*dev
, struct lustre_cfg
*cfg
);
898 int (*precleanup
)(struct obd_device
*dev
,
899 enum obd_cleanup_stage cleanup_stage
);
900 int (*cleanup
)(struct obd_device
*dev
);
901 int (*process_config
)(struct obd_device
*dev
, u32 len
, void *data
);
902 int (*postrecov
)(struct obd_device
*dev
);
903 int (*add_conn
)(struct obd_import
*imp
, struct obd_uuid
*uuid
,
905 int (*del_conn
)(struct obd_import
*imp
, struct obd_uuid
*uuid
);
906 /* connect to the target device with given connection
907 * data. @ocd->ocd_connect_flags is modified to reflect flags actually
908 * granted by the target, which are guaranteed to be a subset of flags
909 * asked for. If @ocd == NULL, use default parameters.
911 int (*connect
)(const struct lu_env
*env
,
912 struct obd_export
**exp
, struct obd_device
*src
,
913 struct obd_uuid
*cluuid
, struct obd_connect_data
*ocd
,
915 int (*reconnect
)(const struct lu_env
*env
,
916 struct obd_export
*exp
, struct obd_device
*src
,
917 struct obd_uuid
*cluuid
,
918 struct obd_connect_data
*ocd
,
920 int (*disconnect
)(struct obd_export
*exp
);
922 /* Initialize/finalize fids infrastructure. */
923 int (*fid_init
)(struct obd_device
*obd
,
924 struct obd_export
*exp
, enum lu_cli_type type
);
925 int (*fid_fini
)(struct obd_device
*obd
);
927 /* Allocate new fid according to passed @hint. */
928 int (*fid_alloc
)(struct obd_export
*exp
, struct lu_fid
*fid
,
929 struct md_op_data
*op_data
);
932 * Object with @fid is getting deleted, we may want to do something
935 int (*statfs
)(const struct lu_env
*, struct obd_export
*exp
,
936 struct obd_statfs
*osfs
, __u64 max_age
, __u32 flags
);
937 int (*statfs_async
)(struct obd_export
*exp
, struct obd_info
*oinfo
,
938 __u64 max_age
, struct ptlrpc_request_set
*set
);
939 int (*packmd
)(struct obd_export
*exp
, struct lov_mds_md
**disk_tgt
,
940 struct lov_stripe_md
*mem_src
);
941 int (*unpackmd
)(struct obd_export
*exp
,
942 struct lov_stripe_md
**mem_tgt
,
943 struct lov_mds_md
*disk_src
, int disk_len
);
944 int (*preallocate
)(struct lustre_handle
*, u32
*req
, u64
*ids
);
945 int (*create
)(const struct lu_env
*env
, struct obd_export
*exp
,
946 struct obdo
*oa
, struct lov_stripe_md
**ea
,
947 struct obd_trans_info
*oti
);
948 int (*destroy
)(const struct lu_env
*env
, struct obd_export
*exp
,
949 struct obdo
*oa
, struct lov_stripe_md
*ea
,
950 struct obd_trans_info
*oti
, struct obd_export
*md_exp
);
951 int (*setattr
)(const struct lu_env
*, struct obd_export
*exp
,
952 struct obd_info
*oinfo
, struct obd_trans_info
*oti
);
953 int (*setattr_async
)(struct obd_export
*exp
, struct obd_info
*oinfo
,
954 struct obd_trans_info
*oti
,
955 struct ptlrpc_request_set
*rqset
);
956 int (*getattr
)(const struct lu_env
*env
, struct obd_export
*exp
,
957 struct obd_info
*oinfo
);
958 int (*getattr_async
)(struct obd_export
*exp
, struct obd_info
*oinfo
,
959 struct ptlrpc_request_set
*set
);
960 int (*adjust_kms
)(struct obd_export
*exp
, struct lov_stripe_md
*lsm
,
961 u64 size
, int shrink
);
962 int (*preprw
)(const struct lu_env
*env
, int cmd
,
963 struct obd_export
*exp
, struct obdo
*oa
, int objcount
,
964 struct obd_ioobj
*obj
, struct niobuf_remote
*remote
,
965 int *nr_pages
, struct niobuf_local
*local
,
966 struct obd_trans_info
*oti
);
967 int (*commitrw
)(const struct lu_env
*env
, int cmd
,
968 struct obd_export
*exp
, struct obdo
*oa
,
969 int objcount
, struct obd_ioobj
*obj
,
970 struct niobuf_remote
*remote
, int pages
,
971 struct niobuf_local
*local
,
972 struct obd_trans_info
*oti
, int rc
);
973 int (*find_cbdata
)(struct obd_export
*, struct lov_stripe_md
*,
974 ldlm_iterator_t it
, void *data
);
975 int (*init_export
)(struct obd_export
*exp
);
976 int (*destroy_export
)(struct obd_export
*exp
);
978 /* metadata-only methods */
979 int (*import_event
)(struct obd_device
*, struct obd_import
*,
980 enum obd_import_event
);
982 int (*notify
)(struct obd_device
*obd
, struct obd_device
*watched
,
983 enum obd_notify_event ev
, void *data
);
985 int (*health_check
)(const struct lu_env
*env
, struct obd_device
*);
986 struct obd_uuid
*(*get_uuid
)(struct obd_export
*exp
);
989 int (*quotacheck
)(struct obd_device
*, struct obd_export
*,
990 struct obd_quotactl
*);
991 int (*quotactl
)(struct obd_device
*, struct obd_export
*,
992 struct obd_quotactl
*);
995 int (*pool_new
)(struct obd_device
*obd
, char *poolname
);
996 int (*pool_del
)(struct obd_device
*obd
, char *poolname
);
997 int (*pool_add
)(struct obd_device
*obd
, char *poolname
,
999 int (*pool_rem
)(struct obd_device
*obd
, char *poolname
,
1001 void (*getref
)(struct obd_device
*obd
);
1002 void (*putref
)(struct obd_device
*obd
);
1004 * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
1005 * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
1006 * Also, add a wrapper function in include/linux/obd_class.h.
1011 LUSTRE_OPC_MKDIR
= (1 << 0),
1012 LUSTRE_OPC_SYMLINK
= (1 << 1),
1013 LUSTRE_OPC_MKNOD
= (1 << 2),
1014 LUSTRE_OPC_CREATE
= (1 << 3),
1015 LUSTRE_OPC_ANY
= (1 << 4)
1018 /* lmv structures */
1019 #define MEA_MAGIC_LAST_CHAR 0xb2221ca1
1020 #define MEA_MAGIC_ALL_CHARS 0xb222a11c
1021 #define MEA_MAGIC_HASH_SEGMENT 0xb222a11b
1023 #define MAX_HASH_SIZE_32 0x7fffffffUL
1024 #define MAX_HASH_SIZE 0x7fffffffffffffffULL
1025 #define MAX_HASH_HIGHEST_BIT 0x1000000000000000ULL
1028 struct mdt_body
*body
;
1029 struct lov_stripe_md
*lsm
;
1030 struct lmv_stripe_md
*mea
;
1031 #ifdef CONFIG_FS_POSIX_ACL
1032 struct posix_acl
*posix_acl
;
1034 struct mdt_remote_perm
*remote_perm
;
1037 struct md_open_data
{
1038 struct obd_client_handle
*mod_och
;
1039 struct ptlrpc_request
*mod_open_req
;
1040 struct ptlrpc_request
*mod_close_req
;
1041 atomic_t mod_refcount
;
1045 struct lookup_intent
;
1048 int (*getstatus
)(struct obd_export
*, struct lu_fid
*);
1049 int (*null_inode
)(struct obd_export
*, const struct lu_fid
*);
1050 int (*find_cbdata
)(struct obd_export
*, const struct lu_fid
*,
1051 ldlm_iterator_t
, void *);
1052 int (*close
)(struct obd_export
*, struct md_op_data
*,
1053 struct md_open_data
*, struct ptlrpc_request
**);
1054 int (*create
)(struct obd_export
*, struct md_op_data
*,
1055 const void *, int, int, __u32
, __u32
, cfs_cap_t
,
1056 __u64
, struct ptlrpc_request
**);
1057 int (*done_writing
)(struct obd_export
*, struct md_op_data
*,
1058 struct md_open_data
*);
1059 int (*enqueue
)(struct obd_export
*, struct ldlm_enqueue_info
*,
1060 struct lookup_intent
*, struct md_op_data
*,
1061 struct lustre_handle
*, void *, int,
1062 struct ptlrpc_request
**, __u64
);
1063 int (*getattr
)(struct obd_export
*, struct md_op_data
*,
1064 struct ptlrpc_request
**);
1065 int (*getattr_name
)(struct obd_export
*, struct md_op_data
*,
1066 struct ptlrpc_request
**);
1067 int (*intent_lock
)(struct obd_export
*, struct md_op_data
*,
1068 void *, int, struct lookup_intent
*, int,
1069 struct ptlrpc_request
**,
1070 ldlm_blocking_callback
, __u64
);
1071 int (*link
)(struct obd_export
*, struct md_op_data
*,
1072 struct ptlrpc_request
**);
1073 int (*rename
)(struct obd_export
*, struct md_op_data
*,
1074 const char *, int, const char *, int,
1075 struct ptlrpc_request
**);
1076 int (*is_subdir
)(struct obd_export
*, const struct lu_fid
*,
1077 const struct lu_fid
*,
1078 struct ptlrpc_request
**);
1079 int (*setattr
)(struct obd_export
*, struct md_op_data
*, void *,
1080 int, void *, int, struct ptlrpc_request
**,
1081 struct md_open_data
**mod
);
1082 int (*sync
)(struct obd_export
*, const struct lu_fid
*,
1083 struct ptlrpc_request
**);
1084 int (*readpage
)(struct obd_export
*, struct md_op_data
*,
1085 struct page
**, struct ptlrpc_request
**);
1087 int (*unlink
)(struct obd_export
*, struct md_op_data
*,
1088 struct ptlrpc_request
**);
1090 int (*setxattr
)(struct obd_export
*, const struct lu_fid
*,
1091 u64
, const char *, const char *, int, int, int, __u32
,
1092 struct ptlrpc_request
**);
1094 int (*getxattr
)(struct obd_export
*, const struct lu_fid
*,
1095 u64
, const char *, const char *, int, int, int,
1096 struct ptlrpc_request
**);
1098 int (*init_ea_size
)(struct obd_export
*, int, int, int, int);
1100 int (*get_lustre_md
)(struct obd_export
*, struct ptlrpc_request
*,
1101 struct obd_export
*, struct obd_export
*,
1102 struct lustre_md
*);
1104 int (*free_lustre_md
)(struct obd_export
*, struct lustre_md
*);
1106 int (*set_open_replay_data
)(struct obd_export
*,
1107 struct obd_client_handle
*,
1108 struct lookup_intent
*);
1109 int (*clear_open_replay_data
)(struct obd_export
*,
1110 struct obd_client_handle
*);
1111 int (*set_lock_data
)(struct obd_export
*, __u64
*, void *, __u64
*);
1113 enum ldlm_mode (*lock_match
)(struct obd_export
*, __u64
,
1114 const struct lu_fid
*, enum ldlm_type
,
1115 ldlm_policy_data_t
*, enum ldlm_mode
,
1116 struct lustre_handle
*);
1118 int (*cancel_unused
)(struct obd_export
*, const struct lu_fid
*,
1119 ldlm_policy_data_t
*, enum ldlm_mode
,
1120 enum ldlm_cancel_flags flags
, void *opaque
);
1122 int (*get_remote_perm
)(struct obd_export
*, const struct lu_fid
*,
1123 __u32
, struct ptlrpc_request
**);
1125 int (*intent_getattr_async
)(struct obd_export
*,
1126 struct md_enqueue_info
*,
1127 struct ldlm_enqueue_info
*);
1129 int (*revalidate_lock
)(struct obd_export
*, struct lookup_intent
*,
1130 struct lu_fid
*, __u64
*bits
);
1133 * NOTE: If adding ops, add another LPROCFS_MD_OP_INIT() line to
1134 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
1135 * wrapper function in include/linux/obd_class.h.
1139 struct lsm_operations
{
1140 void (*lsm_free
)(struct lov_stripe_md
*);
1141 int (*lsm_destroy
)(struct lov_stripe_md
*, struct obdo
*oa
,
1142 struct obd_export
*md_exp
);
1143 void (*lsm_stripe_by_index
)(struct lov_stripe_md
*, int *, u64
*,
1145 void (*lsm_stripe_by_offset
)(struct lov_stripe_md
*, int *, u64
*,
1147 int (*lsm_lmm_verify
)(struct lov_mds_md
*lmm
, int lmm_bytes
,
1148 __u16
*stripe_count
);
1149 int (*lsm_unpackmd
)(struct lov_obd
*lov
, struct lov_stripe_md
*lsm
,
1150 struct lov_mds_md
*lmm
);
1153 extern const struct lsm_operations lsm_v1_ops
;
1154 extern const struct lsm_operations lsm_v3_ops
;
1155 static inline const struct lsm_operations
*lsm_op_find(int magic
)
1163 CERROR("Cannot recognize lsm_magic %08x\n", magic
);
1168 /* Requests for obd_extent_calc() */
1169 #define OBD_CALC_STRIPE_START 1
1170 #define OBD_CALC_STRIPE_END 2
1172 static inline struct md_open_data
*obd_mod_alloc(void)
1174 struct md_open_data
*mod
;
1176 mod
= kzalloc(sizeof(*mod
), GFP_NOFS
);
1179 atomic_set(&mod
->mod_refcount
, 1);
1183 #define obd_mod_get(mod) atomic_inc(&(mod)->mod_refcount)
1184 #define obd_mod_put(mod) \
1186 if (atomic_dec_and_test(&(mod)->mod_refcount)) { \
1187 if ((mod)->mod_open_req) \
1188 ptlrpc_req_finished((mod)->mod_open_req); \
1193 void obdo_from_inode(struct obdo
*dst
, struct inode
*src
, u32 valid
);
1194 void obdo_set_parent_fid(struct obdo
*dst
, const struct lu_fid
*parent
);
1196 /* return 1 if client should be resend request */
1197 static inline int client_should_resend(int resend
, struct client_obd
*cli
)
1199 return atomic_read(&cli
->cl_resends
) ?
1200 atomic_read(&cli
->cl_resends
) > resend
: 1;
1204 * Return device name for this device
1206 * XXX: lu_device is declared before obd_device, while a pointer pointing
1207 * back to obd_device in lu_device, so this helper function defines here
1208 * instead of in lu_object.h
1210 static inline const char *lu_dev_name(const struct lu_device
*lu_dev
)
1212 return lu_dev
->ld_obd
->obd_name
;
1215 static inline bool filename_is_volatile(const char *name
, int namelen
, int *idx
)
1220 if (strncmp(name
, LUSTRE_VOLATILE_HDR
, LUSTRE_VOLATILE_HDR_LEN
) != 0)
1223 /* caller does not care of idx */
1227 /* volatile file, the MDT can be set from name */
1228 /* name format is LUSTRE_VOLATILE_HDR:[idx]: */
1229 /* if no MDT is specified, use std way */
1230 if (namelen
< LUSTRE_VOLATILE_HDR_LEN
+ 2)
1232 /* test for no MDT idx case */
1233 if ((*(name
+ LUSTRE_VOLATILE_HDR_LEN
) == ':') &&
1234 (*(name
+ LUSTRE_VOLATILE_HDR_LEN
+ 1) == ':')) {
1238 /* we have an idx, read it */
1239 start
= name
+ LUSTRE_VOLATILE_HDR_LEN
+ 1;
1240 *idx
= simple_strtoul(start
, &end
, 0);
1242 * no digit, no trailing :, negative value
1244 if (((*idx
== 0) && (end
== start
)) ||
1245 (*end
!= ':') || (*idx
< 0))
1250 /* bad format of mdt idx, we cannot return an error
1251 * to caller so we use hash algo
1253 CERROR("Bad volatile file name format: %s\n",
1254 name
+ LUSTRE_VOLATILE_HDR_LEN
);
1258 static inline int cli_brw_size(struct obd_device
*obd
)
1260 return obd
->u
.cli
.cl_max_pages_per_rpc
<< PAGE_SHIFT
;
1263 #endif /* __OBD_H */