• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2015, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32 
33 #ifndef __OBD_H
34 #define __OBD_H
35 
36 #include <linux/spinlock.h>
37 
38 #include <uapi/linux/lustre/lustre_idl.h>
39 #include <lustre_lib.h>
40 #include <lu_ref.h>
41 #include <lustre_export.h>
42 #include <lustre_fid.h>
43 #include <lustre_fld.h>
44 #include <lustre_handles.h>
45 #include <lustre_intent.h>
46 #include <cl_object.h>
47 
48 #define MAX_OBD_DEVICES 8192
49 
50 struct osc_async_rc {
51 	int     ar_rc;
52 	int     ar_force_sync;
53 	__u64   ar_min_xid;
54 };
55 
56 struct lov_oinfo {		 /* per-stripe data structure */
57 	struct ost_id   loi_oi;    /* object ID/Sequence on the target OST */
58 	int loi_ost_idx;	   /* OST stripe index in lov_tgt_desc->tgts */
59 	int loi_ost_gen;	   /* generation of this loi_ost_idx */
60 
61 	unsigned long loi_kms_valid:1;
62 	__u64 loi_kms;	     /* known minimum size */
63 	struct ost_lvb loi_lvb;
64 	struct osc_async_rc     loi_ar;
65 };
66 
loi_kms_set(struct lov_oinfo * oinfo,__u64 kms)67 static inline void loi_kms_set(struct lov_oinfo *oinfo, __u64 kms)
68 {
69 	oinfo->loi_kms = kms;
70 	oinfo->loi_kms_valid = 1;
71 }
72 
loi_init(struct lov_oinfo * loi)73 static inline void loi_init(struct lov_oinfo *loi)
74 {
75 }
76 
77 struct lov_stripe_md;
78 struct obd_info;
79 
80 int lov_read_and_clear_async_rc(struct cl_object *clob);
81 
82 typedef int (*obd_enqueue_update_f)(void *cookie, int rc);
83 
84 /* obd info for a particular level (lov, osc). */
85 struct obd_info {
86 	/* OBD_STATFS_* flags */
87 	__u64		   oi_flags;
88 	/* lsm data specific for every OSC. */
89 	struct lov_stripe_md   *oi_md;
90 	/* statfs data specific for every OSC, if needed at all. */
91 	struct obd_statfs      *oi_osfs;
92 	/* An update callback which is called to update some data on upper
93 	 * level. E.g. it is used for update lsm->lsm_oinfo at every received
94 	 * request in osc level for enqueue requests. It is also possible to
95 	 * update some caller data from LOV layer if needed.
96 	 */
97 	obd_enqueue_update_f    oi_cb_up;
98 };
99 
100 struct obd_type {
101 	struct list_head typ_chain;
102 	struct obd_ops *typ_dt_ops;
103 	struct md_ops *typ_md_ops;
104 	struct dentry *typ_debugfs_entry;
105 	char *typ_name;
106 	int  typ_refcnt;
107 	struct lu_device_type *typ_lu;
108 	spinlock_t obd_type_lock;
109 	struct kobject *typ_kobj;
110 };
111 
112 struct brw_page {
113 	u64 off;
114 	struct page *pg;
115 	unsigned int count;
116 	u32 flag;
117 };
118 
119 struct timeout_item {
120 	enum timeout_event ti_event;
121 	unsigned long	 ti_timeout;
122 	timeout_cb_t       ti_cb;
123 	void	      *ti_cb_data;
124 	struct list_head	 ti_obd_list;
125 	struct list_head	 ti_chain;
126 };
127 
128 #define OBD_MAX_RIF_DEFAULT	8
129 #define OBD_MAX_RIF_MAX		512
130 #define OSC_MAX_RIF_MAX		256
131 #define OSC_MAX_DIRTY_DEFAULT	(OBD_MAX_RIF_DEFAULT * 4)
132 #define OSC_MAX_DIRTY_MB_MAX	2048	/* arbitrary, but < MAX_LONG bytes */
133 #define OSC_DEFAULT_RESENDS	10
134 
135 /* possible values for fo_sync_lock_cancel */
136 enum {
137 	NEVER_SYNC_ON_CANCEL = 0,
138 	BLOCKING_SYNC_ON_CANCEL = 1,
139 	ALWAYS_SYNC_ON_CANCEL = 2,
140 	NUM_SYNC_ON_CANCEL_STATES
141 };
142 
143 enum obd_cl_sem_lock_class {
144 	OBD_CLI_SEM_NORMAL,
145 	OBD_CLI_SEM_MGC,
146 	OBD_CLI_SEM_MDCOSC,
147 };
148 
149 /*
150  * Limit reply buffer size for striping data to one x86_64 page. This
151  * value is chosen to fit the striping data for common use cases while
152  * staying well below the limit at which the buffer must be backed by
153  * vmalloc(). Excessive use of vmalloc() may cause spinlock contention
154  * on the MDS.
155  */
156 #define OBD_MAX_DEFAULT_EA_SIZE		4096
157 
158 struct mdc_rpc_lock;
159 struct obd_import;
160 struct client_obd {
161 	struct rw_semaphore  cl_sem;
162 	struct obd_uuid	  cl_target_uuid;
163 	struct obd_import       *cl_import; /* ptlrpc connection state */
164 	size_t			 cl_conn_count;
165 	/*
166 	 * Cache maximum and default values for easize. This is
167 	 * strictly a performance optimization to minimize calls to
168 	 * obd_size_diskmd(). The default values are used to calculate the
169 	 * initial size of a request buffer. The ptlrpc layer will resize the
170 	 * buffer as needed to accommodate a larger reply from the
171 	 * server. The default values should be small enough to avoid wasted
172 	 * memory and excessive use of vmalloc(), yet large enough to avoid
173 	 * reallocating the buffer in the common use case.
174 	 */
175 	/*
176 	 * Default EA size for striping attributes. It is initialized at
177 	 * mount-time based on the default stripe width of the filesystem,
178 	 * then it tracks the largest observed EA size advertised by
179 	 * the MDT, up to a maximum value of OBD_MAX_DEFAULT_EA_SIZE.
180 	 */
181 	u32			 cl_default_mds_easize;
182 	/* Maximum possible EA size computed at mount-time based on
183 	 * the number of OSTs in the filesystem. May be increased at
184 	 * run-time if a larger observed size is advertised by the MDT.
185 	 */
186 	u32			 cl_max_mds_easize;
187 
188 	enum lustre_sec_part     cl_sp_me;
189 	enum lustre_sec_part     cl_sp_to;
190 	struct sptlrpc_flavor    cl_flvr_mgc;   /* fixed flavor of mgc->mgs */
191 
192 	/* the grant values are protected by loi_list_lock below */
193 	unsigned long		 cl_dirty_pages;	/* all _dirty_ in pages */
194 	unsigned long		 cl_dirty_max_pages;	/* allowed w/o rpc */
195 	unsigned long		 cl_dirty_transit;	/* dirty synchronous */
196 	unsigned long		 cl_avail_grant;	/* bytes of credit for ost */
197 	unsigned long		 cl_lost_grant;		/* lost credits (trunc) */
198 
199 	/* since we allocate grant by blocks, we don't know how many grant will
200 	 * be used to add a page into cache. As a solution, we reserve maximum
201 	 * grant before trying to dirty a page and unreserve the rest.
202 	 * See osc_{reserve|unreserve}_grant for details.
203 	 */
204 	long		 cl_reserved_grant;
205 	struct list_head cl_cache_waiters; /* waiting for cache/grant */
206 	unsigned long	 cl_next_shrink_grant;   /* jiffies */
207 	struct list_head cl_grant_shrink_list;  /* Timeout event list */
208 	int		 cl_grant_shrink_interval; /* seconds */
209 
210 	/* A chunk is an optimal size used by osc_extent to determine
211 	 * the extent size. A chunk is max(PAGE_SIZE, OST block size)
212 	 */
213 	int		  cl_chunkbits;
214 	unsigned int	  cl_extent_tax; /* extent overhead, by bytes */
215 
216 	/* keep track of objects that have lois that contain pages which
217 	 * have been queued for async brw.  this lock also protects the
218 	 * lists of osc_client_pages that hang off of the loi
219 	 */
220 	/*
221 	 * ->cl_loi_list_lock protects consistency of
222 	 * ->cl_loi_{ready,read,write}_list. ->ap_make_ready() and
223 	 * ->ap_completion() call-backs are executed under this lock. As we
224 	 * cannot guarantee that these call-backs never block on all platforms
225 	 * (as a matter of fact they do block on Mac OS X), type of
226 	 * ->cl_loi_list_lock is platform dependent: it's a spin-lock on Linux
227 	 * and blocking mutex on Mac OS X. (Alternative is to make this lock
228 	 * blocking everywhere, but we don't want to slow down fast-path of
229 	 * our main platform.)
230 	 *
231 	 * NB by Jinshan: though field names are still _loi_, but actually
232 	 * osc_object{}s are in the list.
233 	 */
234 	spinlock_t		       cl_loi_list_lock;
235 	struct list_head	       cl_loi_ready_list;
236 	struct list_head	       cl_loi_hp_ready_list;
237 	struct list_head	       cl_loi_write_list;
238 	struct list_head	       cl_loi_read_list;
239 	__u32			 cl_r_in_flight;
240 	__u32			 cl_w_in_flight;
241 	/* just a sum of the loi/lop pending numbers to be exported by sysfs */
242 	atomic_t	     cl_pending_w_pages;
243 	atomic_t	     cl_pending_r_pages;
244 	__u32			 cl_max_pages_per_rpc;
245 	__u32			 cl_max_rpcs_in_flight;
246 	struct obd_histogram     cl_read_rpc_hist;
247 	struct obd_histogram     cl_write_rpc_hist;
248 	struct obd_histogram     cl_read_page_hist;
249 	struct obd_histogram     cl_write_page_hist;
250 	struct obd_histogram     cl_read_offset_hist;
251 	struct obd_histogram     cl_write_offset_hist;
252 
253 	/* LRU for osc caching pages */
254 	struct cl_client_cache	*cl_cache;
255 	/** member of cl_cache->ccc_lru */
256 	struct list_head	 cl_lru_osc;
257 	/** # of available LRU slots left in the per-OSC cache.
258 	 * Available LRU slots are shared by all OSCs of the same file system,
259 	 * therefore this is a pointer to cl_client_cache::ccc_lru_left.
260 	 */
261 	atomic_long_t		*cl_lru_left;
262 	/** # of busy LRU pages. A page is considered busy if it's in writeback
263 	 * queue, or in transfer. Busy pages can't be discarded so they are not
264 	 * in LRU cache.
265 	 */
266 	atomic_long_t		 cl_lru_busy;
267 	/** # of LRU pages in the cache for this client_obd */
268 	atomic_long_t		 cl_lru_in_list;
269 	/** # of threads are shrinking LRU cache. To avoid contention, it's not
270 	 * allowed to have multiple threads shrinking LRU cache.
271 	 */
272 	atomic_t		 cl_lru_shrinkers;
273 	/** The time when this LRU cache was last used. */
274 	time64_t		 cl_lru_last_used;
275 	/** stats: how many reclaims have happened for this client_obd.
276 	 * reclaim and shrink - shrink is async, voluntarily rebalancing;
277 	 * reclaim is sync, initiated by IO thread when the LRU slots are
278 	 * in shortage.
279 	 */
280 	u64			 cl_lru_reclaim;
281 	/** List of LRU pages for this client_obd */
282 	struct list_head	 cl_lru_list;
283 	/** Lock for LRU page list */
284 	spinlock_t		 cl_lru_list_lock;
285 	/** # of unstable pages in this client_obd.
286 	 * An unstable page is a page state that WRITE RPC has finished but
287 	 * the transaction has NOT yet committed.
288 	 */
289 	atomic_long_t		 cl_unstable_count;
290 	/** Link to osc_shrinker_list */
291 	struct list_head	 cl_shrink_list;
292 
293 	/* number of in flight destroy rpcs is limited to max_rpcs_in_flight */
294 	atomic_t	     cl_destroy_in_flight;
295 	wait_queue_head_t	      cl_destroy_waitq;
296 
297 	struct mdc_rpc_lock     *cl_rpc_lock;
298 
299 	/* modify rpcs in flight
300 	 * currently used for metadata only
301 	 */
302 	spinlock_t		 cl_mod_rpcs_lock;
303 	u16			 cl_max_mod_rpcs_in_flight;
304 	u16			 cl_mod_rpcs_in_flight;
305 	u16			 cl_close_rpcs_in_flight;
306 	wait_queue_head_t	 cl_mod_rpcs_waitq;
307 	unsigned long		*cl_mod_tag_bitmap;
308 	struct obd_histogram	 cl_mod_rpcs_hist;
309 
310 	/* mgc datastruct */
311 	atomic_t	     cl_mgc_refcount;
312 	struct obd_export       *cl_mgc_mgsexp;
313 
314 	/* checksumming for data sent over the network */
315 	unsigned int	     cl_checksum:1; /* 0 = disabled, 1 = enabled */
316 	/* supported checksum types that are worked out at connect time */
317 	__u32		    cl_supp_cksum_types;
318 	/* checksum algorithm to be used */
319 	enum cksum_type	     cl_cksum_type;
320 
321 	/* also protected by the poorly named _loi_list_lock lock above */
322 	struct osc_async_rc      cl_ar;
323 
324 	/* sequence manager */
325 	struct lu_client_seq    *cl_seq;
326 
327 	atomic_t	     cl_resends; /* resend count */
328 
329 	/* ptlrpc work for writeback in ptlrpcd context */
330 	void		    *cl_writeback_work;
331 	void			*cl_lru_work;
332 	/* hash tables for osc_quota_info */
333 	struct cfs_hash	      *cl_quota_hash[MAXQUOTAS];
334 };
335 
336 #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
337 
338 struct obd_id_info {
339 	__u32   idx;
340 	u64	*data;
341 };
342 
343 struct echo_client_obd {
344 	struct obd_export	*ec_exp;   /* the local connection to osc/lov */
345 	spinlock_t		ec_lock;
346 	struct list_head	   ec_objects;
347 	struct list_head	   ec_locks;
348 	__u64		ec_unique;
349 };
350 
351 /* Generic subset of OSTs */
352 struct ost_pool {
353 	__u32	      *op_array;      /* array of index of lov_obd->lov_tgts */
354 	unsigned int	op_count;      /* number of OSTs in the array */
355 	unsigned int	op_size;       /* allocated size of lp_array */
356 	struct rw_semaphore op_rw_sem;     /* to protect ost_pool use */
357 };
358 
359 /* allow statfs data caching for 1 second */
360 #define OBD_STATFS_CACHE_SECONDS 1
361 
362 struct lov_tgt_desc {
363 	struct list_head	  ltd_kill;
364 	struct obd_uuid     ltd_uuid;
365 	struct obd_device  *ltd_obd;
366 	struct obd_export  *ltd_exp;
367 	__u32	       ltd_gen;
368 	__u32	       ltd_index;   /* index in lov_obd->tgts */
369 	unsigned long       ltd_active:1,/* is this target up for requests */
370 			    ltd_activate:1,/* should  target be activated */
371 			    ltd_reap:1;  /* should this target be deleted */
372 };
373 
374 struct lov_obd {
375 	struct lov_desc	 desc;
376 	struct lov_tgt_desc   **lov_tgts;	      /* sparse array */
377 	struct ost_pool	 lov_packed;	    /* all OSTs in a packed array */
378 	struct mutex		lov_lock;
379 	struct obd_connect_data lov_ocd;
380 	atomic_t	    lov_refcount;
381 	__u32		   lov_death_row;/* tgts scheduled to be deleted */
382 	__u32		   lov_tgt_size;   /* size of tgts array */
383 	int		     lov_connects;
384 	int		     lov_pool_count;
385 	struct cfs_hash	     *lov_pools_hash_body; /* used for key access */
386 	struct list_head	lov_pool_list; /* used for sequential access */
387 	struct dentry		*lov_pool_debugfs_entry;
388 	enum lustre_sec_part    lov_sp_me;
389 
390 	/* Cached LRU and unstable data from upper layer */
391 	struct cl_client_cache *lov_cache;
392 
393 	struct rw_semaphore     lov_notify_lock;
394 
395 	struct kobject		*lov_tgts_kobj;
396 };
397 
398 struct lmv_tgt_desc {
399 	struct obd_uuid		ltd_uuid;
400 	struct obd_export	*ltd_exp;
401 	u32			ltd_idx;
402 	struct mutex		ltd_fid_mutex;
403 	unsigned long		ltd_active:1; /* target up for requests */
404 };
405 
406 struct lmv_obd {
407 	struct lu_client_fld	lmv_fld;
408 	spinlock_t		lmv_lock;
409 	struct lmv_desc		desc;
410 	struct obd_uuid		cluuid;
411 
412 	struct mutex		lmv_init_mutex;
413 	int			connected;
414 	int			max_easize;
415 	int			max_def_easize;
416 
417 	u32			tgts_size; /* size of tgts array */
418 	struct lmv_tgt_desc	**tgts;
419 
420 	struct obd_connect_data	conn_data;
421 	struct kobject		*lmv_tgts_kobj;
422 };
423 
424 struct niobuf_local {
425 	__u64		lnb_file_offset;
426 	__u32		lnb_page_offset;
427 	__u32		lnb_len;
428 	__u32		lnb_flags;
429 	int		lnb_rc;
430 	struct page	*lnb_page;
431 	void		*lnb_data;
432 };
433 
434 #define LUSTRE_FLD_NAME	 "fld"
435 #define LUSTRE_SEQ_NAME	 "seq"
436 
437 #define LUSTRE_MDD_NAME	 "mdd"
438 #define LUSTRE_OSD_LDISKFS_NAME	"osd-ldiskfs"
439 #define LUSTRE_OSD_ZFS_NAME     "osd-zfs"
440 #define LUSTRE_VVP_NAME	 "vvp"
441 #define LUSTRE_LMV_NAME	 "lmv"
442 #define LUSTRE_SLP_NAME	 "slp"
443 #define LUSTRE_LOD_NAME		"lod"
444 #define LUSTRE_OSP_NAME		"osp"
445 #define LUSTRE_LWP_NAME		"lwp"
446 
447 /* obd device type names */
448  /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */
449 #define LUSTRE_MDS_NAME	 "mds"
450 #define LUSTRE_MDT_NAME	 "mdt"
451 #define LUSTRE_MDC_NAME	 "mdc"
452 #define LUSTRE_OSS_NAME	 "ost"       /* FIXME change name to oss */
453 #define LUSTRE_OST_NAME	 "obdfilter" /* FIXME change name to ost */
454 #define LUSTRE_OSC_NAME	 "osc"
455 #define LUSTRE_LOV_NAME	 "lov"
456 #define LUSTRE_MGS_NAME	 "mgs"
457 #define LUSTRE_MGC_NAME	 "mgc"
458 
459 #define LUSTRE_ECHO_NAME	"obdecho"
460 #define LUSTRE_ECHO_CLIENT_NAME "echo_client"
461 #define LUSTRE_QMT_NAME	 "qmt"
462 
463 /* Constant obd names (post-rename) */
464 #define LUSTRE_MDS_OBDNAME "MDS"
465 #define LUSTRE_OSS_OBDNAME "OSS"
466 #define LUSTRE_MGS_OBDNAME "MGS"
467 #define LUSTRE_MGC_OBDNAME "MGC"
468 
469 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
470 #define N_LOCAL_TEMP_PAGE 0x10000000
471 
472 /*
473  * Events signalled through obd_notify() upcall-chain.
474  */
475 enum obd_notify_event {
476 	/* Device connect start */
477 	OBD_NOTIFY_CONNECT,
478 	/* Device activated */
479 	OBD_NOTIFY_ACTIVE,
480 	/* Device deactivated */
481 	OBD_NOTIFY_INACTIVE,
482 	/* Connect data for import were changed */
483 	OBD_NOTIFY_OCD,
484 	/* Sync request */
485 	OBD_NOTIFY_SYNC_NONBLOCK,
486 	OBD_NOTIFY_SYNC,
487 	/* Configuration event */
488 	OBD_NOTIFY_CONFIG,
489 	/* Administratively deactivate/activate event */
490 	OBD_NOTIFY_DEACTIVATE,
491 	OBD_NOTIFY_ACTIVATE
492 };
493 
494 /*
495  * Data structure used to pass obd_notify()-event to non-obd listeners (llite
496  * being main example).
497  */
498 struct obd_notify_upcall {
499 	int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
500 			  enum obd_notify_event ev, void *owner, void *data);
501 	/* Opaque datum supplied by upper layer listener */
502 	void *onu_owner;
503 };
504 
505 struct target_recovery_data {
506 	svc_handler_t		trd_recovery_handler;
507 	pid_t			trd_processing_task;
508 	struct completion	trd_starting;
509 	struct completion	trd_finishing;
510 };
511 
512 struct obd_llog_group {
513 	struct llog_ctxt  *olg_ctxts[LLOG_MAX_CTXTS];
514 	wait_queue_head_t	olg_waitq;
515 	spinlock_t	   olg_lock;
516 	struct mutex	   olg_cat_processing;
517 };
518 
519 /* corresponds to one of the obd's */
520 #define OBD_DEVICE_MAGIC	0XAB5CD6EF
521 
522 struct lvfs_run_ctxt {
523 	struct dt_device *dt;
524 };
525 
526 struct obd_device {
527 	struct obd_type	*obd_type;
528 	u32			 obd_magic; /* OBD_DEVICE_MAGIC */
529 	int			 obd_minor; /* device number: lctl dl */
530 	struct lu_device	*obd_lu_dev;
531 
532 	/* common and UUID name of this device */
533 	struct obd_uuid		 obd_uuid;
534 	char			 obd_name[MAX_OBD_NAME];
535 
536 	/* bitfield modification is protected by obd_dev_lock */
537 	unsigned long obd_attached:1,      /* finished attach */
538 		      obd_set_up:1,	/* finished setup */
539 		      obd_version_recov:1, /* obd uses version checking */
540 		      obd_replayable:1,/* recovery is enabled; inform clients */
541 		      obd_no_transno:1,  /* no committed-transno notification */
542 		      obd_no_recov:1,      /* fail instead of retry messages */
543 		      obd_stopping:1,      /* started cleanup */
544 		      obd_starting:1,      /* started setup */
545 		      obd_force:1,	 /* cleanup with > 0 obd refcount */
546 		      obd_fail:1,	 /* cleanup with failover */
547 		      obd_no_conn:1,       /* deny new connections */
548 		      obd_inactive:1,      /* device active/inactive
549 					    * (for sysfs status only!!)
550 					    */
551 		      obd_no_ir:1,	 /* no imperative recovery. */
552 		      obd_process_conf:1;  /* device is processing mgs config */
553 	/* use separate field as it is set in interrupt to don't mess with
554 	 * protection of other bits using _bh lock
555 	 */
556 	unsigned long obd_recovery_expired:1;
557 	/* uuid-export hash body */
558 	struct cfs_hash	     *obd_uuid_hash;
559 	wait_queue_head_t	     obd_refcount_waitq;
560 	struct list_head	      obd_exports;
561 	struct list_head	      obd_unlinked_exports;
562 	struct list_head	      obd_delayed_exports;
563 	atomic_t			obd_refcount;
564 	int		     obd_num_exports;
565 	spinlock_t		obd_nid_lock;
566 	struct ldlm_namespace  *obd_namespace;
567 	struct ptlrpc_client	obd_ldlm_client; /* XXX OST/MDS only */
568 	/* a spinlock is OK for what we do now, may need a semaphore later */
569 	spinlock_t		obd_dev_lock; /* protect OBD bitfield above */
570 	spinlock_t		obd_osfs_lock;
571 	struct obd_statfs	obd_osfs;       /* locked by obd_osfs_lock */
572 	__u64			obd_osfs_age;
573 	u64			obd_last_committed;
574 	struct mutex		obd_dev_mutex;
575 	struct lvfs_run_ctxt	obd_lvfs_ctxt;
576 	struct obd_llog_group	obd_olg;	/* default llog group */
577 	struct obd_device	*obd_observer;
578 	struct rw_semaphore	obd_observer_link_sem;
579 	struct obd_notify_upcall obd_upcall;
580 	struct obd_export       *obd_self_export;
581 
582 	union {
583 		struct client_obd cli;
584 		struct echo_client_obd echo_client;
585 		struct lov_obd lov;
586 		struct lmv_obd lmv;
587 	} u;
588 
589 	/* Fields used by LProcFS */
590 	struct lprocfs_stats	*obd_stats;
591 	unsigned int		 obd_cntr_base;
592 
593 	struct lprocfs_stats	*md_stats;
594 	unsigned int		 md_cntr_base;
595 
596 	struct dentry		*obd_debugfs_entry;
597 	struct dentry		*obd_svc_debugfs_entry;
598 	struct lprocfs_stats  *obd_svc_stats;
599 	atomic_t	   obd_evict_inprogress;
600 	wait_queue_head_t	    obd_evict_inprogress_waitq;
601 	struct list_head	obd_evict_list; /* protected with pet_lock */
602 
603 	/**
604 	 * Ldlm pool part. Save last calculated SLV and Limit.
605 	 */
606 	rwlock_t		 obd_pool_lock;
607 	u64			 obd_pool_slv;
608 	int			 obd_pool_limit;
609 
610 	int			 obd_conn_inprogress;
611 
612 	/**
613 	 * A list of outstanding class_incref()'s against this obd. For
614 	 * debugging.
615 	 */
616 	struct lu_ref	  obd_reference;
617 
618 	struct kobject		obd_kobj; /* sysfs object */
619 	struct completion	obd_kobj_unregister;
620 };
621 
622 /* get/set_info keys */
623 #define KEY_ASYNC	       "async"
624 #define KEY_CHANGELOG_CLEAR     "changelog_clear"
625 #define KEY_FID2PATH	    "fid2path"
626 #define KEY_CHECKSUM	    "checksum"
627 #define KEY_CLEAR_FS	    "clear_fs"
628 #define KEY_CONN_DATA	   "conn_data"
629 #define KEY_EVICT_BY_NID	"evict_by_nid"
630 #define KEY_FIEMAP	      "fiemap"
631 #define KEY_FLUSH_CTX	   "flush_ctx"
632 #define KEY_GRANT_SHRINK	"grant_shrink"
633 #define KEY_HSM_COPYTOOL_SEND   "hsm_send"
634 #define KEY_INIT_RECOV_BACKUP   "init_recov_bk"
635 #define KEY_INTERMDS	    "inter_mds"
636 #define KEY_LAST_ID	     "last_id"
637 #define KEY_LAST_FID		"last_fid"
638 #define KEY_MAX_EASIZE		"max_easize"
639 #define KEY_DEFAULT_EASIZE	"default_easize"
640 #define KEY_MGSSEC	      "mgssec"
641 #define KEY_READ_ONLY	   "read-only"
642 #define KEY_REGISTER_TARGET     "register_target"
643 #define KEY_SET_FS	      "set_fs"
644 #define KEY_TGT_COUNT	   "tgt_count"
645 /*      KEY_SET_INFO in lustre_idl.h */
646 #define KEY_SPTLRPC_CONF	"sptlrpc_conf"
647 
648 #define KEY_CACHE_SET		"cache_set"
649 #define KEY_CACHE_LRU_SHRINK	"cache_lru_shrink"
650 
651 struct lu_context;
652 
it_to_lock_mode(struct lookup_intent * it)653 static inline int it_to_lock_mode(struct lookup_intent *it)
654 {
655 	/* CREAT needs to be tested before open (both could be set) */
656 	if (it->it_op & IT_CREAT)
657 		return LCK_CW;
658 	else if (it->it_op & (IT_GETATTR | IT_OPEN | IT_LOOKUP |
659 			      IT_LAYOUT))
660 		return LCK_CR;
661 	else if (it->it_op & IT_READDIR)
662 		return LCK_PR;
663 	else if (it->it_op &  IT_GETXATTR)
664 		return LCK_PR;
665 	else if (it->it_op &  IT_SETXATTR)
666 		return LCK_PW;
667 
668 	LASSERTF(0, "Invalid it_op: %d\n", it->it_op);
669 	return -EINVAL;
670 }
671 
672 enum md_op_flags {
673 	MF_MDC_CANCEL_FID1	= BIT(0),
674 	MF_MDC_CANCEL_FID2      = BIT(1),
675 	MF_MDC_CANCEL_FID3      = BIT(2),
676 	MF_MDC_CANCEL_FID4      = BIT(3),
677 	MF_GET_MDT_IDX          = BIT(4),
678 };
679 
680 enum md_cli_flags {
681 	CLI_SET_MEA	= BIT(0),
682 	CLI_RM_ENTRY	= BIT(1),
683 	CLI_HASH64	= BIT(2),
684 	CLI_API32	= BIT(3),
685 	CLI_MIGRATE	= BIT(4),
686 };
687 
688 struct md_op_data {
689 	struct lu_fid	   op_fid1; /* operation fid1 (usually parent) */
690 	struct lu_fid	   op_fid2; /* operation fid2 (usually child) */
691 	struct lu_fid	   op_fid3; /* 2 extra fids to find conflicting */
692 	struct lu_fid	   op_fid4; /* to the operation locks. */
693 	u32			op_mds;  /* what mds server open will go to */
694 	struct lustre_handle    op_handle;
695 	s64			op_mod_time;
696 	const char	     *op_name;
697 	size_t			op_namelen;
698 	__u32		   op_mode;
699 	struct lmv_stripe_md   *op_mea1;
700 	struct lmv_stripe_md   *op_mea2;
701 	__u32		   op_suppgids[2];
702 	__u32		   op_fsuid;
703 	__u32		   op_fsgid;
704 	cfs_cap_t	       op_cap;
705 	void		   *op_data;
706 	size_t			op_data_size;
707 
708 	/* iattr fields and blocks. */
709 	struct iattr	    op_attr;
710 	unsigned int	    op_attr_flags;
711 	__u64		   op_valid;
712 	loff_t		  op_attr_blocks;
713 
714 	__u32		   op_flags;
715 
716 	/* Various operation flags. */
717 	enum mds_op_bias        op_bias;
718 
719 	/* Used by readdir */
720 	__u64		   op_offset;
721 
722 	/* Used by readdir */
723 	__u32			op_max_pages;
724 
725 	/* used to transfer info between the stacks of MD client
726 	 * see enum op_cli_flags
727 	 */
728 	enum md_cli_flags	op_cli_flags;
729 
730 	/* File object data version for HSM release, on client */
731 	__u64			op_data_version;
732 	struct lustre_handle	op_lease_handle;
733 
734 	/* default stripe offset */
735 	__u32			op_default_stripe_offset;
736 };
737 
738 struct md_callback {
739 	int (*md_blocking_ast)(struct ldlm_lock *lock,
740 			       struct ldlm_lock_desc *desc,
741 			       void *data, int flag);
742 };
743 
744 struct md_enqueue_info;
745 /* metadata stat-ahead */
746 
747 struct md_enqueue_info {
748 	struct md_op_data       mi_data;
749 	struct lookup_intent    mi_it;
750 	struct lustre_handle    mi_lockh;
751 	struct inode	   *mi_dir;
752 	struct ldlm_enqueue_info	mi_einfo;
753 	int (*mi_cb)(struct ptlrpc_request *req,
754 		     struct md_enqueue_info *minfo, int rc);
755 	void			*mi_cbdata;
756 };
757 
758 struct obd_ops {
759 	struct module *owner;
760 	int (*iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
761 			 void *karg, void __user *uarg);
762 	int (*get_info)(const struct lu_env *env, struct obd_export *,
763 			__u32 keylen, void *key, __u32 *vallen, void *val);
764 	int (*set_info_async)(const struct lu_env *, struct obd_export *,
765 			      __u32 keylen, void *key,
766 			      __u32 vallen, void *val,
767 			      struct ptlrpc_request_set *set);
768 	int (*setup)(struct obd_device *dev, struct lustre_cfg *cfg);
769 	int (*precleanup)(struct obd_device *dev);
770 	int (*cleanup)(struct obd_device *dev);
771 	int (*process_config)(struct obd_device *dev, u32 len, void *data);
772 	int (*postrecov)(struct obd_device *dev);
773 	int (*add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
774 			int priority);
775 	int (*del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
776 	/* connect to the target device with given connection
777 	 * data. @ocd->ocd_connect_flags is modified to reflect flags actually
778 	 * granted by the target, which are guaranteed to be a subset of flags
779 	 * asked for. If @ocd == NULL, use default parameters.
780 	 */
781 	int (*connect)(const struct lu_env *env,
782 		       struct obd_export **exp, struct obd_device *src,
783 		       struct obd_uuid *cluuid, struct obd_connect_data *ocd,
784 		       void *localdata);
785 	int (*reconnect)(const struct lu_env *env,
786 			 struct obd_export *exp, struct obd_device *src,
787 			 struct obd_uuid *cluuid,
788 			 struct obd_connect_data *ocd,
789 			 void *localdata);
790 	int (*disconnect)(struct obd_export *exp);
791 
792 	/* Initialize/finalize fids infrastructure. */
793 	int (*fid_init)(struct obd_device *obd,
794 			struct obd_export *exp, enum lu_cli_type type);
795 	int (*fid_fini)(struct obd_device *obd);
796 
797 	/* Allocate new fid according to passed @hint. */
798 	int (*fid_alloc)(const struct lu_env *env, struct obd_export *exp,
799 			 struct lu_fid *fid, struct md_op_data *op_data);
800 
801 	/*
802 	 * Object with @fid is getting deleted, we may want to do something
803 	 * about this.
804 	 */
805 	int (*statfs)(const struct lu_env *, struct obd_export *exp,
806 		      struct obd_statfs *osfs, __u64 max_age, __u32 flags);
807 	int (*statfs_async)(struct obd_export *exp, struct obd_info *oinfo,
808 			    __u64 max_age, struct ptlrpc_request_set *set);
809 	int (*create)(const struct lu_env *env, struct obd_export *exp,
810 		      struct obdo *oa);
811 	int (*destroy)(const struct lu_env *env, struct obd_export *exp,
812 		       struct obdo *oa);
813 	int (*setattr)(const struct lu_env *, struct obd_export *exp,
814 		       struct obdo *oa);
815 	int (*getattr)(const struct lu_env *env, struct obd_export *exp,
816 		       struct obdo *oa);
817 	int (*preprw)(const struct lu_env *env, int cmd,
818 		      struct obd_export *exp, struct obdo *oa, int objcount,
819 		      struct obd_ioobj *obj, struct niobuf_remote *remote,
820 		      int *nr_pages, struct niobuf_local *local);
821 	int (*commitrw)(const struct lu_env *env, int cmd,
822 			struct obd_export *exp, struct obdo *oa,
823 			int objcount, struct obd_ioobj *obj,
824 			struct niobuf_remote *remote, int pages,
825 			struct niobuf_local *local, int rc);
826 	int (*init_export)(struct obd_export *exp);
827 	int (*destroy_export)(struct obd_export *exp);
828 
829 	/* metadata-only methods */
830 	int (*import_event)(struct obd_device *, struct obd_import *,
831 			    enum obd_import_event);
832 
833 	int (*notify)(struct obd_device *obd, struct obd_device *watched,
834 		      enum obd_notify_event ev, void *data);
835 
836 	int (*health_check)(const struct lu_env *env, struct obd_device *);
837 	struct obd_uuid *(*get_uuid)(struct obd_export *exp);
838 
839 	/* quota methods */
840 	int (*quotactl)(struct obd_device *, struct obd_export *,
841 			struct obd_quotactl *);
842 
843 	/* pools methods */
844 	int (*pool_new)(struct obd_device *obd, char *poolname);
845 	int (*pool_del)(struct obd_device *obd, char *poolname);
846 	int (*pool_add)(struct obd_device *obd, char *poolname,
847 			char *ostname);
848 	int (*pool_rem)(struct obd_device *obd, char *poolname,
849 			char *ostname);
850 	void (*getref)(struct obd_device *obd);
851 	void (*putref)(struct obd_device *obd);
852 	/*
853 	 * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
854 	 * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
855 	 * Also, add a wrapper function in include/linux/obd_class.h.
856 	 */
857 };
858 
859 /* lmv structures */
860 struct lustre_md {
861 	struct mdt_body	 *body;
862 	struct lu_buf		 layout;
863 	struct lmv_stripe_md    *lmv;
864 #ifdef CONFIG_FS_POSIX_ACL
865 	struct posix_acl	*posix_acl;
866 #endif
867 	struct mdt_remote_perm  *remote_perm;
868 };
869 
870 struct md_open_data {
871 	struct obd_client_handle *mod_och;
872 	struct ptlrpc_request    *mod_open_req;
873 	struct ptlrpc_request    *mod_close_req;
874 	atomic_t		  mod_refcount;
875 	bool			  mod_is_create;
876 };
877 
878 struct obd_client_handle {
879 	struct lustre_handle	 och_fh;
880 	struct lu_fid		 och_fid;
881 	struct md_open_data	*och_mod;
882 	struct lustre_handle	 och_lease_handle; /* open lock for lease */
883 	__u32			 och_magic;
884 	fmode_t			 och_flags;
885 };
886 
887 #define OBD_CLIENT_HANDLE_MAGIC 0xd15ea5ed
888 
889 struct lookup_intent;
890 struct cl_attr;
891 
892 struct md_ops {
893 	int (*getstatus)(struct obd_export *, struct lu_fid *);
894 	int (*null_inode)(struct obd_export *, const struct lu_fid *);
895 	int (*close)(struct obd_export *, struct md_op_data *,
896 		     struct md_open_data *, struct ptlrpc_request **);
897 	int (*create)(struct obd_export *, struct md_op_data *,
898 		      const void *, size_t, umode_t, uid_t, gid_t,
899 		      cfs_cap_t, __u64, struct ptlrpc_request **);
900 	int (*enqueue)(struct obd_export *, struct ldlm_enqueue_info *,
901 		       const union ldlm_policy_data *,
902 		       struct lookup_intent *, struct md_op_data *,
903 		       struct lustre_handle *, __u64);
904 	int (*getattr)(struct obd_export *, struct md_op_data *,
905 		       struct ptlrpc_request **);
906 	int (*getattr_name)(struct obd_export *, struct md_op_data *,
907 			    struct ptlrpc_request **);
908 	int (*intent_lock)(struct obd_export *, struct md_op_data *,
909 			   struct lookup_intent *,
910 			   struct ptlrpc_request **,
911 			   ldlm_blocking_callback, __u64);
912 	int (*link)(struct obd_export *, struct md_op_data *,
913 		    struct ptlrpc_request **);
914 	int (*rename)(struct obd_export *, struct md_op_data *,
915 		      const char *, size_t, const char *, size_t,
916 		      struct ptlrpc_request **);
917 	int (*setattr)(struct obd_export *, struct md_op_data *, void *,
918 		       size_t, struct ptlrpc_request **);
919 	int (*sync)(struct obd_export *, const struct lu_fid *,
920 		    struct ptlrpc_request **);
921 	int (*read_page)(struct obd_export *, struct md_op_data *,
922 			 struct md_callback *cb_op, __u64 hash_offset,
923 			 struct page **ppage);
924 	int (*unlink)(struct obd_export *, struct md_op_data *,
925 		      struct ptlrpc_request **);
926 
927 	int (*setxattr)(struct obd_export *, const struct lu_fid *,
928 			u64, const char *, const char *, int, int, int, __u32,
929 			struct ptlrpc_request **);
930 
931 	int (*getxattr)(struct obd_export *, const struct lu_fid *,
932 			u64, const char *, const char *, int, int, int,
933 			struct ptlrpc_request **);
934 
935 	int (*init_ea_size)(struct obd_export *, u32, u32);
936 
937 	int (*get_lustre_md)(struct obd_export *, struct ptlrpc_request *,
938 			     struct obd_export *, struct obd_export *,
939 			     struct lustre_md *);
940 
941 	int (*free_lustre_md)(struct obd_export *, struct lustre_md *);
942 
943 	int (*merge_attr)(struct obd_export *,
944 			  const struct lmv_stripe_md *lsm,
945 			  struct cl_attr *attr, ldlm_blocking_callback);
946 
947 	int (*set_open_replay_data)(struct obd_export *,
948 				    struct obd_client_handle *,
949 				    struct lookup_intent *);
950 	int (*clear_open_replay_data)(struct obd_export *,
951 				      struct obd_client_handle *);
952 	int (*set_lock_data)(struct obd_export *, const struct lustre_handle *,
953 			     void *, __u64 *);
954 
955 	enum ldlm_mode (*lock_match)(struct obd_export *, __u64,
956 				     const struct lu_fid *, enum ldlm_type,
957 				     union ldlm_policy_data *, enum ldlm_mode,
958 				     struct lustre_handle *);
959 
960 	int (*cancel_unused)(struct obd_export *, const struct lu_fid *,
961 			     union ldlm_policy_data *, enum ldlm_mode,
962 			     enum ldlm_cancel_flags flags, void *opaque);
963 
964 	int (*get_fid_from_lsm)(struct obd_export *,
965 				const struct lmv_stripe_md *,
966 				const char *name, int namelen,
967 				struct lu_fid *fid);
968 
969 	int (*intent_getattr_async)(struct obd_export *,
970 				    struct md_enqueue_info *);
971 
972 	int (*revalidate_lock)(struct obd_export *, struct lookup_intent *,
973 			       struct lu_fid *, __u64 *bits);
974 
975 	int (*unpackmd)(struct obd_export *exp, struct lmv_stripe_md **plsm,
976 			const union lmv_mds_md *lmv, size_t lmv_size);
977 	/*
978 	 * NOTE: If adding ops, add another LPROCFS_MD_OP_INIT() line to
979 	 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
980 	 * wrapper function in include/linux/obd_class.h.
981 	 */
982 };
983 
obd_mod_alloc(void)984 static inline struct md_open_data *obd_mod_alloc(void)
985 {
986 	struct md_open_data *mod;
987 
988 	mod = kzalloc(sizeof(*mod), GFP_NOFS);
989 	if (!mod)
990 		return NULL;
991 	atomic_set(&mod->mod_refcount, 1);
992 	return mod;
993 }
994 
995 #define obd_mod_get(mod) atomic_inc(&(mod)->mod_refcount)
996 #define obd_mod_put(mod)					\
997 ({							      \
998 	if (atomic_dec_and_test(&(mod)->mod_refcount)) {	  \
999 		if ((mod)->mod_open_req)			  \
1000 			ptlrpc_req_finished((mod)->mod_open_req);   \
1001 		kfree(mod);			      \
1002 	}						       \
1003 })
1004 
1005 void obdo_from_inode(struct obdo *dst, struct inode *src, u32 valid);
1006 void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent);
1007 
1008 /* return 1 if client should be resend request */
client_should_resend(int resend,struct client_obd * cli)1009 static inline int client_should_resend(int resend, struct client_obd *cli)
1010 {
1011 	return atomic_read(&cli->cl_resends) ?
1012 	       atomic_read(&cli->cl_resends) > resend : 1;
1013 }
1014 
1015 /**
1016  * Return device name for this device
1017  *
1018  * XXX: lu_device is declared before obd_device, while a pointer pointing
1019  * back to obd_device in lu_device, so this helper function defines here
1020  * instead of in lu_object.h
1021  */
lu_dev_name(const struct lu_device * lu_dev)1022 static inline const char *lu_dev_name(const struct lu_device *lu_dev)
1023 {
1024 	return lu_dev->ld_obd->obd_name;
1025 }
1026 
filename_is_volatile(const char * name,size_t namelen,int * idx)1027 static inline bool filename_is_volatile(const char *name, size_t namelen,
1028 					int *idx)
1029 {
1030 	const char	*start;
1031 	char		*end;
1032 
1033 	if (strncmp(name, LUSTRE_VOLATILE_HDR, LUSTRE_VOLATILE_HDR_LEN) != 0)
1034 		return false;
1035 
1036 	/* caller does not care of idx */
1037 	if (!idx)
1038 		return true;
1039 
1040 	/* volatile file, the MDT can be set from name */
1041 	/* name format is LUSTRE_VOLATILE_HDR:[idx]: */
1042 	/* if no MDT is specified, use std way */
1043 	if (namelen < LUSTRE_VOLATILE_HDR_LEN + 2)
1044 		goto bad_format;
1045 	/* test for no MDT idx case */
1046 	if ((*(name + LUSTRE_VOLATILE_HDR_LEN) == ':') &&
1047 	    (*(name + LUSTRE_VOLATILE_HDR_LEN + 1) == ':')) {
1048 		*idx = -1;
1049 		return true;
1050 	}
1051 	/* we have an idx, read it */
1052 	start = name + LUSTRE_VOLATILE_HDR_LEN + 1;
1053 	*idx = simple_strtoul(start, &end, 0);
1054 	/* error cases:
1055 	 * no digit, no trailing :, negative value
1056 	 */
1057 	if (((*idx == 0) && (end == start)) ||
1058 	    (*end != ':') || (*idx < 0))
1059 		goto bad_format;
1060 
1061 	return true;
1062 bad_format:
1063 	/* bad format of mdt idx, we cannot return an error
1064 	 * to caller so we use hash algo
1065 	 */
1066 	CERROR("Bad volatile file name format: %s\n",
1067 	       name + LUSTRE_VOLATILE_HDR_LEN);
1068 	return false;
1069 }
1070 
cli_brw_size(struct obd_device * obd)1071 static inline int cli_brw_size(struct obd_device *obd)
1072 {
1073 	return obd->u.cli.cl_max_pages_per_rpc << PAGE_SHIFT;
1074 }
1075 
1076 /*
1077  * when RPC size or the max RPCs in flight is increased, the max dirty pages
1078  * of the client should be increased accordingly to avoid sending fragmented
1079  * RPCs over the network when the client runs out of the maximum dirty space
1080  * when so many RPCs are being generated.
1081  */
client_adjust_max_dirty(struct client_obd * cli)1082 static inline void client_adjust_max_dirty(struct client_obd *cli)
1083 {
1084 	/* initializing */
1085 	if (cli->cl_dirty_max_pages <= 0)
1086 		cli->cl_dirty_max_pages =
1087 			(OSC_MAX_DIRTY_DEFAULT * 1024 * 1024) >> PAGE_SHIFT;
1088 	else {
1089 		unsigned long dirty_max = cli->cl_max_rpcs_in_flight *
1090 					  cli->cl_max_pages_per_rpc;
1091 
1092 		if (dirty_max > cli->cl_dirty_max_pages)
1093 			cli->cl_dirty_max_pages = dirty_max;
1094 	}
1095 
1096 	if (cli->cl_dirty_max_pages > totalram_pages / 8)
1097 		cli->cl_dirty_max_pages = totalram_pages / 8;
1098 }
1099 
1100 #endif /* __OBD_H */
1101