1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37#ifndef __OBD_H
38#define __OBD_H
39
40#include "linux/obd.h"
41
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
46
47#define IOC_MDC_TYPE 'i'
48#define IOC_MDC_MIN_NR 20
49#define IOC_MDC_MAX_NR 50
50
51#include "lustre/lustre_idl.h"
52#include "lustre_lib.h"
53#include "lu_ref.h"
54#include "lustre_export.h"
55#include "lustre_fid.h"
56#include "lustre_fld.h"
57
58#define MAX_OBD_DEVICES 8192
59
60struct osc_async_rc {
61 int ar_rc;
62 int ar_force_sync;
63 __u64 ar_min_xid;
64};
65
66struct lov_oinfo {
67 struct ost_id loi_oi;
68 int loi_ost_idx;
69 int loi_ost_gen;
70
71 unsigned long loi_kms_valid:1;
72 __u64 loi_kms;
73 struct ost_lvb loi_lvb;
74 struct osc_async_rc loi_ar;
75};
76
77static inline void loi_kms_set(struct lov_oinfo *oinfo, __u64 kms)
78{
79 oinfo->loi_kms = kms;
80 oinfo->loi_kms_valid = 1;
81}
82
83static inline void loi_init(struct lov_oinfo *loi)
84{
85}
86
87struct lov_stripe_md {
88 atomic_t lsm_refc;
89 spinlock_t lsm_lock;
90 pid_t lsm_lock_owner;
91
92
93
94 __u64 lsm_maxbytes;
95 struct {
96
97 struct ost_id lw_object_oi;
98
99
100 __u32 lw_magic;
101 __u32 lw_stripe_size;
102 __u32 lw_pattern;
103 __u16 lw_stripe_count;
104 __u16 lw_layout_gen;
105 char lw_pool_name[LOV_MAXPOOLNAME];
106 } lsm_wire;
107
108 struct lov_oinfo *lsm_oinfo[0];
109};
110
111#define lsm_oi lsm_wire.lw_object_oi
112#define lsm_magic lsm_wire.lw_magic
113#define lsm_layout_gen lsm_wire.lw_layout_gen
114#define lsm_stripe_size lsm_wire.lw_stripe_size
115#define lsm_pattern lsm_wire.lw_pattern
116#define lsm_stripe_count lsm_wire.lw_stripe_count
117#define lsm_pool_name lsm_wire.lw_pool_name
118
119static inline bool lsm_is_released(struct lov_stripe_md *lsm)
120{
121 return !!(lsm->lsm_pattern & LOV_PATTERN_F_RELEASED);
122}
123
124static inline bool lsm_has_objects(struct lov_stripe_md *lsm)
125{
126 if (lsm == NULL)
127 return false;
128 if (lsm_is_released(lsm))
129 return false;
130 return true;
131}
132
133static inline int lov_stripe_md_size(unsigned int stripe_count)
134{
135 struct lov_stripe_md lsm;
136
137 return sizeof(lsm) + stripe_count * sizeof(lsm.lsm_oinfo[0]);
138}
139
140struct obd_info;
141
142typedef int (*obd_enqueue_update_f)(void *cookie, int rc);
143
144
145struct obd_info {
146
147
148
149
150
151
152 __u64 oi_flags;
153
154 struct lov_stripe_md *oi_md;
155
156 struct obdo *oi_oa;
157
158 struct obd_statfs *oi_osfs;
159
160
161
162
163 obd_enqueue_update_f oi_cb_up;
164};
165
166void lov_stripe_lock(struct lov_stripe_md *md);
167void lov_stripe_unlock(struct lov_stripe_md *md);
168
169struct obd_type {
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;
174 char *typ_name;
175 int typ_refcnt;
176 struct lu_device_type *typ_lu;
177 spinlock_t obd_type_lock;
178 struct kobject *typ_kobj;
179};
180
181struct brw_page {
182 u64 off;
183 struct page *pg;
184 int count;
185 u32 flag;
186};
187
188
189enum llog_ctxt_id {
190 LLOG_CONFIG_ORIG_CTXT = 0,
191 LLOG_CONFIG_REPL_CTXT,
192 LLOG_MDS_OST_ORIG_CTXT,
193 LLOG_MDS_OST_REPL_CTXT,
194 LLOG_SIZE_ORIG_CTXT,
195 LLOG_SIZE_REPL_CTXT,
196 LLOG_RD1_ORIG_CTXT,
197 LLOG_RD1_REPL_CTXT,
198 LLOG_TEST_ORIG_CTXT,
199 LLOG_TEST_REPL_CTXT,
200 LLOG_LOVEA_ORIG_CTXT,
201 LLOG_LOVEA_REPL_CTXT,
202 LLOG_CHANGELOG_ORIG_CTXT,
203 LLOG_CHANGELOG_REPL_CTXT,
204 LLOG_CHANGELOG_USER_ORIG_CTXT,
205 LLOG_AGENT_ORIG_CTXT,
206 LLOG_MAX_CTXTS
207};
208
209struct timeout_item {
210 enum timeout_event ti_event;
211 unsigned long ti_timeout;
212 timeout_cb_t ti_cb;
213 void *ti_cb_data;
214 struct list_head ti_obd_list;
215 struct list_head ti_chain;
216};
217
218#define OSC_MAX_RIF_DEFAULT 8
219#define MDS_OSC_MAX_RIF_DEFAULT 50
220#define OSC_MAX_RIF_MAX 256
221#define OSC_MAX_DIRTY_DEFAULT (OSC_MAX_RIF_DEFAULT * 4)
222#define OSC_MAX_DIRTY_MB_MAX 2048
223#define OSC_DEFAULT_RESENDS 10
224
225
226enum {
227 NEVER_SYNC_ON_CANCEL = 0,
228 BLOCKING_SYNC_ON_CANCEL = 1,
229 ALWAYS_SYNC_ON_CANCEL = 2,
230 NUM_SYNC_ON_CANCEL_STATES
231};
232
233#define MDC_MAX_RIF_DEFAULT 8
234#define MDC_MAX_RIF_MAX 512
235
236struct mdc_rpc_lock;
237struct obd_import;
238struct client_obd {
239 struct rw_semaphore cl_sem;
240 struct obd_uuid cl_target_uuid;
241 struct obd_import *cl_import;
242 int cl_conn_count;
243
244
245 int cl_default_mds_easize;
246 int cl_max_mds_easize;
247 int cl_default_mds_cookiesize;
248 int cl_max_mds_cookiesize;
249
250 enum lustre_sec_part cl_sp_me;
251 enum lustre_sec_part cl_sp_to;
252 struct sptlrpc_flavor cl_flvr_mgc;
253
254
255 long cl_dirty;
256 long cl_dirty_max;
257 long cl_dirty_transit;
258 long cl_avail_grant;
259 long cl_lost_grant;
260
261
262
263
264
265 long cl_reserved_grant;
266 struct list_head cl_cache_waiters;
267 unsigned long cl_next_shrink_grant;
268 struct list_head cl_grant_shrink_list;
269 int cl_grant_shrink_interval;
270
271
272
273 int cl_chunkbits;
274 int cl_chunk;
275 int cl_extent_tax;
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298 client_obd_lock_t cl_loi_list_lock;
299 struct list_head cl_loi_ready_list;
300 struct list_head cl_loi_hp_ready_list;
301 struct list_head cl_loi_write_list;
302 struct list_head cl_loi_read_list;
303 int cl_r_in_flight;
304 int cl_w_in_flight;
305
306 atomic_t cl_pending_w_pages;
307 atomic_t cl_pending_r_pages;
308 __u32 cl_max_pages_per_rpc;
309 int cl_max_rpcs_in_flight;
310 struct obd_histogram cl_read_rpc_hist;
311 struct obd_histogram cl_write_rpc_hist;
312 struct obd_histogram cl_read_page_hist;
313 struct obd_histogram cl_write_page_hist;
314 struct obd_histogram cl_read_offset_hist;
315 struct obd_histogram cl_write_offset_hist;
316
317
318 struct cl_client_cache *cl_cache;
319 struct list_head cl_lru_osc;
320 atomic_t *cl_lru_left;
321 atomic_t cl_lru_busy;
322 atomic_t cl_lru_shrinkers;
323 atomic_t cl_lru_in_list;
324 struct list_head cl_lru_list;
325 client_obd_lock_t cl_lru_list_lock;
326
327
328 atomic_t cl_destroy_in_flight;
329 wait_queue_head_t cl_destroy_waitq;
330
331 struct mdc_rpc_lock *cl_rpc_lock;
332 struct mdc_rpc_lock *cl_close_lock;
333
334
335 atomic_t cl_mgc_refcount;
336 struct obd_export *cl_mgc_mgsexp;
337
338
339 unsigned int cl_checksum:1;
340
341 __u32 cl_supp_cksum_types;
342
343 cksum_type_t cl_cksum_type;
344
345
346 struct osc_async_rc cl_ar;
347
348
349 int cl_qchk_stat;
350#define CL_NOT_QUOTACHECKED 1
351#if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 7, 50, 0)
352#warning "please consider removing quotacheck compatibility code"
353#endif
354
355
356 struct lu_client_seq *cl_seq;
357
358 atomic_t cl_resends;
359
360
361 void *cl_writeback_work;
362
363 struct cfs_hash *cl_quota_hash[MAXQUOTAS];
364};
365
366#define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
367
368struct obd_id_info {
369 __u32 idx;
370 u64 *data;
371};
372
373struct echo_client_obd {
374 struct obd_export *ec_exp;
375 spinlock_t ec_lock;
376 struct list_head ec_objects;
377 struct list_head ec_locks;
378 int ec_nstripes;
379 __u64 ec_unique;
380};
381
382
383struct ost_pool {
384 __u32 *op_array;
385
386 unsigned int op_count;
387 unsigned int op_size;
388 struct rw_semaphore op_rw_sem;
389};
390
391
392struct lov_qos_rr {
393 __u32 lqr_start_idx;
394 __u32 lqr_offset_idx;
395 int lqr_start_count;
396 struct ost_pool lqr_pool;
397 unsigned long lqr_dirty:1;
398};
399
400
401#define OBD_STATFS_CACHE_SECONDS 1
402
403struct lov_statfs_data {
404 struct obd_info lsd_oi;
405 struct obd_statfs lsd_statfs;
406};
407
408
409struct lov_qos {
410 struct list_head lq_oss_list;
411 struct rw_semaphore lq_rw_sem;
412 __u32 lq_active_oss_count;
413 unsigned int lq_prio_free;
414 unsigned int lq_threshold_rr;
415 struct lov_qos_rr lq_rr;
416 unsigned long lq_dirty:1,
417 lq_same_space:1,
418
419 lq_reset:1,
420 lq_statfs_in_progress:1;
421
422
423 struct lov_statfs_data *lq_statfs_data;
424 wait_queue_head_t lq_statfs_waitq;
425
426};
427
428struct lov_tgt_desc {
429 struct list_head ltd_kill;
430 struct obd_uuid ltd_uuid;
431 struct obd_device *ltd_obd;
432 struct obd_export *ltd_exp;
433 __u32 ltd_gen;
434 __u32 ltd_index;
435 unsigned long ltd_active:1,
436 ltd_activate:1,
437 ltd_reap:1;
438};
439
440
441#define pool_tgt_size(_p) _p->pool_obds.op_size
442#define pool_tgt_count(_p) _p->pool_obds.op_count
443#define pool_tgt_array(_p) _p->pool_obds.op_array
444#define pool_tgt_rw_sem(_p) _p->pool_obds.op_rw_sem
445
446struct pool_desc {
447 char pool_name[LOV_MAXPOOLNAME + 1];
448 struct ost_pool pool_obds;
449 atomic_t pool_refcount;
450 struct lov_qos_rr pool_rr;
451 struct hlist_node pool_hash;
452 struct list_head pool_list;
453 struct dentry *pool_debugfs_entry;
454 struct obd_device *pool_lobd;
455
456};
457
458struct lov_obd {
459 struct lov_desc desc;
460 struct lov_tgt_desc **lov_tgts;
461 struct ost_pool lov_packed;
462
463 struct mutex lov_lock;
464 struct obd_connect_data lov_ocd;
465 atomic_t lov_refcount;
466 __u32 lov_tgt_count;
467 __u32 lov_active_tgt_count;
468 __u32 lov_death_row;
469 __u32 lov_tgt_size;
470 int lov_connects;
471 int lov_pool_count;
472 struct cfs_hash *lov_pools_hash_body;
473 struct list_head lov_pool_list;
474 struct dentry *lov_pool_debugfs_entry;
475 enum lustre_sec_part lov_sp_me;
476
477
478 void *lov_cache;
479
480 struct rw_semaphore lov_notify_lock;
481
482 struct kobject *lov_tgts_kobj;
483};
484
485struct lmv_tgt_desc {
486 struct obd_uuid ltd_uuid;
487 struct obd_export *ltd_exp;
488 int ltd_idx;
489 struct mutex ltd_fid_mutex;
490 unsigned long ltd_active:1;
491};
492
493enum placement_policy {
494 PLACEMENT_CHAR_POLICY = 0,
495 PLACEMENT_NID_POLICY = 1,
496 PLACEMENT_INVAL_POLICY = 2,
497 PLACEMENT_MAX_POLICY
498};
499
500struct lmv_obd {
501 int refcount;
502 struct lu_client_fld lmv_fld;
503 spinlock_t lmv_lock;
504 enum placement_policy lmv_placement;
505 struct lmv_desc desc;
506 struct obd_uuid cluuid;
507 struct obd_export *exp;
508
509 struct mutex init_mutex;
510 int connected;
511 int max_easize;
512 int max_def_easize;
513 int max_cookiesize;
514 int max_def_cookiesize;
515 int server_timeout;
516
517 int tgts_size;
518 struct lmv_tgt_desc **tgts;
519
520 struct obd_connect_data conn_data;
521 struct kobject *lmv_tgts_kobj;
522};
523
524struct niobuf_local {
525 __u64 lnb_file_offset;
526 __u32 lnb_page_offset;
527 __u32 len;
528 __u32 flags;
529 struct page *page;
530 struct dentry *dentry;
531 int lnb_grant_used;
532 int rc;
533};
534
535#define LUSTRE_FLD_NAME "fld"
536#define LUSTRE_SEQ_NAME "seq"
537
538#define LUSTRE_MDD_NAME "mdd"
539#define LUSTRE_OSD_LDISKFS_NAME "osd-ldiskfs"
540#define LUSTRE_OSD_ZFS_NAME "osd-zfs"
541#define LUSTRE_VVP_NAME "vvp"
542#define LUSTRE_LMV_NAME "lmv"
543#define LUSTRE_SLP_NAME "slp"
544#define LUSTRE_LOD_NAME "lod"
545#define LUSTRE_OSP_NAME "osp"
546#define LUSTRE_LWP_NAME "lwp"
547
548
549
550#define LUSTRE_MDS_NAME "mds"
551#define LUSTRE_MDT_NAME "mdt"
552#define LUSTRE_MDC_NAME "mdc"
553#define LUSTRE_OSS_NAME "ost"
554#define LUSTRE_OST_NAME "obdfilter"
555#define LUSTRE_OSC_NAME "osc"
556#define LUSTRE_LOV_NAME "lov"
557#define LUSTRE_MGS_NAME "mgs"
558#define LUSTRE_MGC_NAME "mgc"
559
560#define LUSTRE_ECHO_NAME "obdecho"
561#define LUSTRE_ECHO_CLIENT_NAME "echo_client"
562#define LUSTRE_QMT_NAME "qmt"
563
564
565#define LUSTRE_MDS_OBDNAME "MDS"
566#define LUSTRE_OSS_OBDNAME "OSS"
567#define LUSTRE_MGS_OBDNAME "MGS"
568#define LUSTRE_MGC_OBDNAME "MGC"
569
570
571#define N_LOCAL_TEMP_PAGE 0x10000000
572
573struct obd_trans_info {
574 __u64 oti_transno;
575 __u64 oti_xid;
576
577 struct oti_req_ack_lock {
578 struct lustre_handle lock;
579 __u32 mode;
580 } oti_ack_locks[4];
581 void *oti_handle;
582 struct llog_cookie oti_onecookie;
583 struct llog_cookie *oti_logcookies;
584 int oti_numcookies;
585
586 unsigned long oti_sync_write:1;
587
588
589 struct ptlrpc_thread *oti_thread;
590 __u32 oti_conn_cnt;
591
592 __u64 oti_pre_version;
593
594 char *oti_jobid;
595
596 struct obd_uuid *oti_ost_uuid;
597};
598
599static inline void oti_init(struct obd_trans_info *oti,
600 struct ptlrpc_request *req)
601{
602 if (oti == NULL)
603 return;
604 memset(oti, 0, sizeof(*oti));
605
606 if (req == NULL)
607 return;
608
609 oti->oti_xid = req->rq_xid;
610
611 if (req->rq_reqmsg != NULL &&
612 lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
613 __u64 *pre_version = lustre_msg_get_versions(req->rq_reqmsg);
614
615 oti->oti_pre_version = pre_version ? pre_version[0] : 0;
616 oti->oti_transno = lustre_msg_get_transno(req->rq_reqmsg);
617 }
618
619
620 if (req->rq_repmsg != NULL)
621 oti->oti_transno = lustre_msg_get_transno(req->rq_repmsg);
622 oti->oti_thread = req->rq_svc_thread;
623 if (req->rq_reqmsg != NULL)
624 oti->oti_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg);
625}
626
627static inline void oti_alloc_cookies(struct obd_trans_info *oti,
628 int num_cookies)
629{
630 if (!oti)
631 return;
632
633 if (num_cookies == 1)
634 oti->oti_logcookies = &oti->oti_onecookie;
635 else
636 oti->oti_logcookies = libcfs_kvzalloc(num_cookies * sizeof(oti->oti_onecookie),
637 GFP_NOFS);
638
639 oti->oti_numcookies = num_cookies;
640}
641
642static inline void oti_free_cookies(struct obd_trans_info *oti)
643{
644 if (!oti || !oti->oti_logcookies)
645 return;
646
647 if (oti->oti_logcookies == &oti->oti_onecookie)
648 LASSERT(oti->oti_numcookies == 1);
649 else
650 kvfree(oti->oti_logcookies);
651
652 oti->oti_logcookies = NULL;
653 oti->oti_numcookies = 0;
654}
655
656
657
658
659enum obd_notify_event {
660
661 OBD_NOTIFY_CREATE,
662
663 OBD_NOTIFY_CONNECT,
664
665 OBD_NOTIFY_ACTIVE,
666
667 OBD_NOTIFY_INACTIVE,
668
669 OBD_NOTIFY_DISCON,
670
671 OBD_NOTIFY_OCD,
672
673 OBD_NOTIFY_SYNC_NONBLOCK,
674 OBD_NOTIFY_SYNC,
675
676 OBD_NOTIFY_CONFIG,
677
678 OBD_NOTIFY_DEACTIVATE,
679 OBD_NOTIFY_ACTIVATE
680};
681
682
683
684
685
686struct obd_notify_upcall {
687 int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
688 enum obd_notify_event ev, void *owner, void *data);
689
690 void *onu_owner;
691};
692
693struct target_recovery_data {
694 svc_handler_t trd_recovery_handler;
695 pid_t trd_processing_task;
696 struct completion trd_starting;
697 struct completion trd_finishing;
698};
699
700struct obd_llog_group {
701 int olg_seq;
702 struct llog_ctxt *olg_ctxts[LLOG_MAX_CTXTS];
703 wait_queue_head_t olg_waitq;
704 spinlock_t olg_lock;
705 struct mutex olg_cat_processing;
706};
707
708
709#define OBD_DEVICE_MAGIC 0XAB5CD6EF
710#define OBD_DEV_BY_DEVNAME 0xffffd0de
711
712struct lvfs_run_ctxt {
713 struct dt_device *dt;
714};
715
716struct obd_device {
717 struct obd_type *obd_type;
718 __u32 obd_magic;
719
720
721 char obd_name[MAX_OBD_NAME];
722 struct obd_uuid obd_uuid;
723
724 struct lu_device *obd_lu_dev;
725
726 int obd_minor;
727
728 unsigned long obd_attached:1,
729 obd_set_up:1,
730 obd_version_recov:1,
731 obd_replayable:1,
732 obd_no_transno:1,
733 obd_no_recov:1,
734 obd_stopping:1,
735 obd_starting:1,
736 obd_force:1,
737 obd_fail:1,
738 obd_async_recov:1,
739 obd_no_conn:1,
740 obd_inactive:1,
741
742 obd_no_ir:1,
743 obd_process_conf:1;
744
745
746 unsigned long obd_recovery_expired:1;
747
748 struct cfs_hash *obd_uuid_hash;
749 atomic_t obd_refcount;
750 wait_queue_head_t obd_refcount_waitq;
751 struct list_head obd_exports;
752 struct list_head obd_unlinked_exports;
753 struct list_head obd_delayed_exports;
754 int obd_num_exports;
755 spinlock_t obd_nid_lock;
756 struct ldlm_namespace *obd_namespace;
757 struct ptlrpc_client obd_ldlm_client;
758
759 spinlock_t obd_dev_lock;
760 struct mutex obd_dev_mutex;
761 __u64 obd_last_committed;
762 spinlock_t obd_osfs_lock;
763 struct obd_statfs obd_osfs;
764 __u64 obd_osfs_age;
765 struct lvfs_run_ctxt obd_lvfs_ctxt;
766 struct obd_llog_group obd_olg;
767 struct obd_device *obd_observer;
768 struct rw_semaphore obd_observer_link_sem;
769 struct obd_notify_upcall obd_upcall;
770 struct obd_export *obd_self_export;
771
772 union {
773 struct client_obd cli;
774 struct echo_client_obd echo_client;
775 struct lov_obd lov;
776 struct lmv_obd lmv;
777 } u;
778
779 unsigned int obd_cntr_base;
780 struct lprocfs_stats *obd_stats;
781
782 unsigned int md_cntr_base;
783 struct lprocfs_stats *md_stats;
784
785 struct dentry *obd_debugfs_entry;
786 struct dentry *obd_svc_debugfs_entry;
787 struct lprocfs_stats *obd_svc_stats;
788 atomic_t obd_evict_inprogress;
789 wait_queue_head_t obd_evict_inprogress_waitq;
790 struct list_head obd_evict_list;
791
792
793
794
795 rwlock_t obd_pool_lock;
796 int obd_pool_limit;
797 __u64 obd_pool_slv;
798
799
800
801
802
803 struct lu_ref obd_reference;
804
805 int obd_conn_inprogress;
806
807 struct kobject obd_kobj;
808 struct completion obd_kobj_unregister;
809};
810
811#define OBD_LLOG_FL_SENDNOW 0x0001
812#define OBD_LLOG_FL_EXIT 0x0002
813
814enum obd_cleanup_stage {
815
816 OBD_CLEANUP_EARLY,
817
818 OBD_CLEANUP_EXPORTS,
819};
820
821
822#define KEY_ASYNC "async"
823#define KEY_BLOCKSIZE_BITS "blocksize_bits"
824#define KEY_BLOCKSIZE "blocksize"
825#define KEY_CHANGELOG_CLEAR "changelog_clear"
826#define KEY_FID2PATH "fid2path"
827#define KEY_CHECKSUM "checksum"
828#define KEY_CLEAR_FS "clear_fs"
829#define KEY_CONN_DATA "conn_data"
830#define KEY_EVICT_BY_NID "evict_by_nid"
831#define KEY_FIEMAP "fiemap"
832#define KEY_FLUSH_CTX "flush_ctx"
833#define KEY_GRANT_SHRINK "grant_shrink"
834#define KEY_HSM_COPYTOOL_SEND "hsm_send"
835#define KEY_INIT_RECOV_BACKUP "init_recov_bk"
836#define KEY_INIT_RECOV "initial_recov"
837#define KEY_INTERMDS "inter_mds"
838#define KEY_LAST_ID "last_id"
839#define KEY_LAST_FID "last_fid"
840#define KEY_LOCK_TO_STRIPE "lock_to_stripe"
841#define KEY_LOVDESC "lovdesc"
842#define KEY_LOV_IDX "lov_idx"
843#define KEY_MAX_EASIZE "max_easize"
844#define KEY_DEFAULT_EASIZE "default_easize"
845#define KEY_MDS_CONN "mds_conn"
846#define KEY_MGSSEC "mgssec"
847#define KEY_NEXT_ID "next_id"
848#define KEY_READ_ONLY "read-only"
849#define KEY_REGISTER_TARGET "register_target"
850#define KEY_SET_FS "set_fs"
851#define KEY_TGT_COUNT "tgt_count"
852
853#define KEY_SPTLRPC_CONF "sptlrpc_conf"
854#define KEY_CONNECT_FLAG "connect_flags"
855#define KEY_SYNC_LOCK_CANCEL "sync_lock_cancel"
856
857#define KEY_CACHE_SET "cache_set"
858#define KEY_CACHE_LRU_SHRINK "cache_lru_shrink"
859#define KEY_CHANGELOG_INDEX "changelog_index"
860
861struct lu_context;
862
863
864#define IT_OPEN (1 << 0)
865#define IT_CREAT (1 << 1)
866#define IT_READDIR (1 << 2)
867#define IT_GETATTR (1 << 3)
868#define IT_LOOKUP (1 << 4)
869#define IT_UNLINK (1 << 5)
870#define IT_TRUNC (1 << 6)
871#define IT_GETXATTR (1 << 7)
872#define IT_EXEC (1 << 8)
873#define IT_PIN (1 << 9)
874#define IT_LAYOUT (1 << 10)
875#define IT_QUOTA_DQACQ (1 << 11)
876#define IT_QUOTA_CONN (1 << 12)
877#define IT_SETXATTR (1 << 13)
878
879static inline int it_to_lock_mode(struct lookup_intent *it)
880{
881
882 if (it->it_op & IT_CREAT)
883 return LCK_CW;
884 else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_LOOKUP |
885 IT_LAYOUT))
886 return LCK_CR;
887 else if (it->it_op & IT_GETXATTR)
888 return LCK_PR;
889 else if (it->it_op & IT_SETXATTR)
890 return LCK_PW;
891
892 LASSERTF(0, "Invalid it_op: %d\n", it->it_op);
893 return -EINVAL;
894}
895
896struct md_op_data {
897 struct lu_fid op_fid1;
898 struct lu_fid op_fid2;
899 struct lu_fid op_fid3;
900 struct lu_fid op_fid4;
901 u32 op_mds;
902 struct lustre_handle op_handle;
903 s64 op_mod_time;
904 const char *op_name;
905 int op_namelen;
906 __u32 op_mode;
907 struct lmv_stripe_md *op_mea1;
908 struct lmv_stripe_md *op_mea2;
909 __u32 op_suppgids[2];
910 __u32 op_fsuid;
911 __u32 op_fsgid;
912 cfs_cap_t op_cap;
913 void *op_data;
914
915
916 struct iattr op_attr;
917 unsigned int op_attr_flags;
918 __u64 op_valid;
919 loff_t op_attr_blocks;
920
921
922 __u64 op_ioepoch;
923 __u32 op_flags;
924
925
926 enum mds_op_bias op_bias;
927
928
929 __u32 op_opc;
930
931
932 __u64 op_offset;
933
934
935 __u32 op_npages;
936
937
938
939 __u32 op_cli_flags;
940
941
942 __u64 op_data_version;
943 struct lustre_handle op_lease_handle;
944};
945
946enum op_cli_flags {
947 CLI_SET_MEA = 1 << 0,
948 CLI_RM_ENTRY = 1 << 1,
949};
950
951struct md_enqueue_info;
952
953
954struct md_enqueue_info {
955 struct md_op_data mi_data;
956 struct lookup_intent mi_it;
957 struct lustre_handle mi_lockh;
958 struct inode *mi_dir;
959 int (*mi_cb)(struct ptlrpc_request *req,
960 struct md_enqueue_info *minfo, int rc);
961 __u64 mi_cbdata;
962 unsigned int mi_generation;
963};
964
965struct obd_ops {
966 struct module *o_owner;
967 int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
968 void *karg, void *uarg);
969 int (*o_get_info)(const struct lu_env *env, struct obd_export *,
970 __u32 keylen, void *key, __u32 *vallen, void *val,
971 struct lov_stripe_md *lsm);
972 int (*o_set_info_async)(const struct lu_env *, struct obd_export *,
973 __u32 keylen, void *key,
974 __u32 vallen, void *val,
975 struct ptlrpc_request_set *set);
976 int (*o_attach)(struct obd_device *dev, u32 len, void *data);
977 int (*o_detach)(struct obd_device *dev);
978 int (*o_setup)(struct obd_device *dev, struct lustre_cfg *cfg);
979 int (*o_precleanup)(struct obd_device *dev,
980 enum obd_cleanup_stage cleanup_stage);
981 int (*o_cleanup)(struct obd_device *dev);
982 int (*o_process_config)(struct obd_device *dev, u32 len, void *data);
983 int (*o_postrecov)(struct obd_device *dev);
984 int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
985 int priority);
986 int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
987
988
989
990
991 int (*o_connect)(const struct lu_env *env,
992 struct obd_export **exp, struct obd_device *src,
993 struct obd_uuid *cluuid, struct obd_connect_data *ocd,
994 void *localdata);
995 int (*o_reconnect)(const struct lu_env *env,
996 struct obd_export *exp, struct obd_device *src,
997 struct obd_uuid *cluuid,
998 struct obd_connect_data *ocd,
999 void *localdata);
1000 int (*o_disconnect)(struct obd_export *exp);
1001
1002
1003 int (*o_fid_init)(struct obd_device *obd,
1004 struct obd_export *exp, enum lu_cli_type type);
1005 int (*o_fid_fini)(struct obd_device *obd);
1006
1007
1008 int (*o_fid_alloc)(struct obd_export *exp, struct lu_fid *fid,
1009 struct md_op_data *op_data);
1010
1011
1012
1013
1014
1015 int (*o_statfs)(const struct lu_env *, struct obd_export *exp,
1016 struct obd_statfs *osfs, __u64 max_age, __u32 flags);
1017 int (*o_statfs_async)(struct obd_export *exp, struct obd_info *oinfo,
1018 __u64 max_age, struct ptlrpc_request_set *set);
1019 int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
1020 struct lov_stripe_md *mem_src);
1021 int (*o_unpackmd)(struct obd_export *exp,
1022 struct lov_stripe_md **mem_tgt,
1023 struct lov_mds_md *disk_src, int disk_len);
1024 int (*o_preallocate)(struct lustre_handle *, u32 *req, u64 *ids);
1025 int (*o_create)(const struct lu_env *env, struct obd_export *exp,
1026 struct obdo *oa, struct lov_stripe_md **ea,
1027 struct obd_trans_info *oti);
1028 int (*o_destroy)(const struct lu_env *env, struct obd_export *exp,
1029 struct obdo *oa, struct lov_stripe_md *ea,
1030 struct obd_trans_info *oti, struct obd_export *md_exp);
1031 int (*o_setattr)(const struct lu_env *, struct obd_export *exp,
1032 struct obd_info *oinfo, struct obd_trans_info *oti);
1033 int (*o_setattr_async)(struct obd_export *exp, struct obd_info *oinfo,
1034 struct obd_trans_info *oti,
1035 struct ptlrpc_request_set *rqset);
1036 int (*o_getattr)(const struct lu_env *env, struct obd_export *exp,
1037 struct obd_info *oinfo);
1038 int (*o_getattr_async)(struct obd_export *exp, struct obd_info *oinfo,
1039 struct ptlrpc_request_set *set);
1040 int (*o_adjust_kms)(struct obd_export *exp, struct lov_stripe_md *lsm,
1041 u64 size, int shrink);
1042 int (*o_preprw)(const struct lu_env *env, int cmd,
1043 struct obd_export *exp, struct obdo *oa, int objcount,
1044 struct obd_ioobj *obj, struct niobuf_remote *remote,
1045 int *nr_pages, struct niobuf_local *local,
1046 struct obd_trans_info *oti);
1047 int (*o_commitrw)(const struct lu_env *env, int cmd,
1048 struct obd_export *exp, struct obdo *oa,
1049 int objcount, struct obd_ioobj *obj,
1050 struct niobuf_remote *remote, int pages,
1051 struct niobuf_local *local,
1052 struct obd_trans_info *oti, int rc);
1053 int (*o_find_cbdata)(struct obd_export *, struct lov_stripe_md *,
1054 ldlm_iterator_t it, void *data);
1055 int (*o_init_export)(struct obd_export *exp);
1056 int (*o_destroy_export)(struct obd_export *exp);
1057
1058
1059 int (*o_import_event)(struct obd_device *, struct obd_import *,
1060 enum obd_import_event);
1061
1062 int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
1063 enum obd_notify_event ev, void *data);
1064
1065 int (*o_health_check)(const struct lu_env *env, struct obd_device *);
1066 struct obd_uuid *(*o_get_uuid)(struct obd_export *exp);
1067
1068
1069 int (*o_quotacheck)(struct obd_device *, struct obd_export *,
1070 struct obd_quotactl *);
1071 int (*o_quotactl)(struct obd_device *, struct obd_export *,
1072 struct obd_quotactl *);
1073
1074
1075 int (*o_pool_new)(struct obd_device *obd, char *poolname);
1076 int (*o_pool_del)(struct obd_device *obd, char *poolname);
1077 int (*o_pool_add)(struct obd_device *obd, char *poolname,
1078 char *ostname);
1079 int (*o_pool_rem)(struct obd_device *obd, char *poolname,
1080 char *ostname);
1081 void (*o_getref)(struct obd_device *obd);
1082 void (*o_putref)(struct obd_device *obd);
1083
1084
1085
1086
1087};
1088
1089enum {
1090 LUSTRE_OPC_MKDIR = (1 << 0),
1091 LUSTRE_OPC_SYMLINK = (1 << 1),
1092 LUSTRE_OPC_MKNOD = (1 << 2),
1093 LUSTRE_OPC_CREATE = (1 << 3),
1094 LUSTRE_OPC_ANY = (1 << 4)
1095};
1096
1097
1098#define MEA_MAGIC_LAST_CHAR 0xb2221ca1
1099#define MEA_MAGIC_ALL_CHARS 0xb222a11c
1100#define MEA_MAGIC_HASH_SEGMENT 0xb222a11b
1101
1102#define MAX_HASH_SIZE_32 0x7fffffffUL
1103#define MAX_HASH_SIZE 0x7fffffffffffffffULL
1104#define MAX_HASH_HIGHEST_BIT 0x1000000000000000ULL
1105
1106struct lustre_md {
1107 struct mdt_body *body;
1108 struct lov_stripe_md *lsm;
1109 struct lmv_stripe_md *mea;
1110#ifdef CONFIG_FS_POSIX_ACL
1111 struct posix_acl *posix_acl;
1112#endif
1113 struct mdt_remote_perm *remote_perm;
1114};
1115
1116struct md_open_data {
1117 struct obd_client_handle *mod_och;
1118 struct ptlrpc_request *mod_open_req;
1119 struct ptlrpc_request *mod_close_req;
1120 atomic_t mod_refcount;
1121 bool mod_is_create;
1122};
1123
1124struct lookup_intent;
1125
1126struct md_ops {
1127 int (*m_getstatus)(struct obd_export *, struct lu_fid *);
1128 int (*m_null_inode)(struct obd_export *, const struct lu_fid *);
1129 int (*m_find_cbdata)(struct obd_export *, const struct lu_fid *,
1130 ldlm_iterator_t, void *);
1131 int (*m_close)(struct obd_export *, struct md_op_data *,
1132 struct md_open_data *, struct ptlrpc_request **);
1133 int (*m_create)(struct obd_export *, struct md_op_data *,
1134 const void *, int, int, __u32, __u32, cfs_cap_t,
1135 __u64, struct ptlrpc_request **);
1136 int (*m_done_writing)(struct obd_export *, struct md_op_data *,
1137 struct md_open_data *);
1138 int (*m_enqueue)(struct obd_export *, struct ldlm_enqueue_info *,
1139 struct lookup_intent *, struct md_op_data *,
1140 struct lustre_handle *, void *, int,
1141 struct ptlrpc_request **, __u64);
1142 int (*m_getattr)(struct obd_export *, struct md_op_data *,
1143 struct ptlrpc_request **);
1144 int (*m_getattr_name)(struct obd_export *, struct md_op_data *,
1145 struct ptlrpc_request **);
1146 int (*m_intent_lock)(struct obd_export *, struct md_op_data *,
1147 void *, int, struct lookup_intent *, int,
1148 struct ptlrpc_request **,
1149 ldlm_blocking_callback, __u64);
1150 int (*m_link)(struct obd_export *, struct md_op_data *,
1151 struct ptlrpc_request **);
1152 int (*m_rename)(struct obd_export *, struct md_op_data *,
1153 const char *, int, const char *, int,
1154 struct ptlrpc_request **);
1155 int (*m_is_subdir)(struct obd_export *, const struct lu_fid *,
1156 const struct lu_fid *,
1157 struct ptlrpc_request **);
1158 int (*m_setattr)(struct obd_export *, struct md_op_data *, void *,
1159 int, void *, int, struct ptlrpc_request **,
1160 struct md_open_data **mod);
1161 int (*m_sync)(struct obd_export *, const struct lu_fid *,
1162 struct ptlrpc_request **);
1163 int (*m_readpage)(struct obd_export *, struct md_op_data *,
1164 struct page **, struct ptlrpc_request **);
1165
1166 int (*m_unlink)(struct obd_export *, struct md_op_data *,
1167 struct ptlrpc_request **);
1168
1169 int (*m_setxattr)(struct obd_export *, const struct lu_fid *,
1170 u64, const char *, const char *, int, int, int, __u32,
1171 struct ptlrpc_request **);
1172
1173 int (*m_getxattr)(struct obd_export *, const struct lu_fid *,
1174 u64, const char *, const char *, int, int, int,
1175 struct ptlrpc_request **);
1176
1177 int (*m_init_ea_size)(struct obd_export *, int, int, int, int);
1178
1179 int (*m_get_lustre_md)(struct obd_export *, struct ptlrpc_request *,
1180 struct obd_export *, struct obd_export *,
1181 struct lustre_md *);
1182
1183 int (*m_free_lustre_md)(struct obd_export *, struct lustre_md *);
1184
1185 int (*m_set_open_replay_data)(struct obd_export *,
1186 struct obd_client_handle *,
1187 struct lookup_intent *);
1188 int (*m_clear_open_replay_data)(struct obd_export *,
1189 struct obd_client_handle *);
1190 int (*m_set_lock_data)(struct obd_export *, __u64 *, void *, __u64 *);
1191
1192 ldlm_mode_t (*m_lock_match)(struct obd_export *, __u64,
1193 const struct lu_fid *, ldlm_type_t,
1194 ldlm_policy_data_t *, ldlm_mode_t,
1195 struct lustre_handle *);
1196
1197 int (*m_cancel_unused)(struct obd_export *, const struct lu_fid *,
1198 ldlm_policy_data_t *, ldlm_mode_t,
1199 ldlm_cancel_flags_t flags, void *opaque);
1200
1201 int (*m_get_remote_perm)(struct obd_export *, const struct lu_fid *,
1202 __u32, struct ptlrpc_request **);
1203
1204 int (*m_intent_getattr_async)(struct obd_export *,
1205 struct md_enqueue_info *,
1206 struct ldlm_enqueue_info *);
1207
1208 int (*m_revalidate_lock)(struct obd_export *, struct lookup_intent *,
1209 struct lu_fid *, __u64 *bits);
1210
1211
1212
1213
1214
1215
1216};
1217
1218struct lsm_operations {
1219 void (*lsm_free)(struct lov_stripe_md *);
1220 int (*lsm_destroy)(struct lov_stripe_md *, struct obdo *oa,
1221 struct obd_export *md_exp);
1222 void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *, u64 *,
1223 u64 *);
1224 void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *, u64 *,
1225 u64 *);
1226 int (*lsm_lmm_verify)(struct lov_mds_md *lmm, int lmm_bytes,
1227 __u16 *stripe_count);
1228 int (*lsm_unpackmd)(struct lov_obd *lov, struct lov_stripe_md *lsm,
1229 struct lov_mds_md *lmm);
1230};
1231
1232extern const struct lsm_operations lsm_v1_ops;
1233extern const struct lsm_operations lsm_v3_ops;
1234static inline const struct lsm_operations *lsm_op_find(int magic)
1235{
1236 switch (magic) {
1237 case LOV_MAGIC_V1:
1238 return &lsm_v1_ops;
1239 case LOV_MAGIC_V3:
1240 return &lsm_v3_ops;
1241 default:
1242 CERROR("Cannot recognize lsm_magic %08x\n", magic);
1243 return NULL;
1244 }
1245}
1246
1247
1248#define OBD_CALC_STRIPE_START 1
1249#define OBD_CALC_STRIPE_END 2
1250
1251static inline struct md_open_data *obd_mod_alloc(void)
1252{
1253 struct md_open_data *mod;
1254
1255 mod = kzalloc(sizeof(*mod), GFP_NOFS);
1256 if (mod == NULL)
1257 return NULL;
1258 atomic_set(&mod->mod_refcount, 1);
1259 return mod;
1260}
1261
1262#define obd_mod_get(mod) atomic_inc(&(mod)->mod_refcount)
1263#define obd_mod_put(mod) \
1264({ \
1265 if (atomic_dec_and_test(&(mod)->mod_refcount)) { \
1266 if ((mod)->mod_open_req) \
1267 ptlrpc_req_finished((mod)->mod_open_req); \
1268 kfree(mod); \
1269 } \
1270})
1271
1272void obdo_from_inode(struct obdo *dst, struct inode *src, u32 valid);
1273void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent);
1274
1275
1276static inline int client_should_resend(int resend, struct client_obd *cli)
1277{
1278 return atomic_read(&cli->cl_resends) ?
1279 atomic_read(&cli->cl_resends) > resend : 1;
1280}
1281
1282
1283
1284
1285
1286
1287
1288
1289static inline const char *lu_dev_name(const struct lu_device *lu_dev)
1290{
1291 return lu_dev->ld_obd->obd_name;
1292}
1293
1294static inline bool filename_is_volatile(const char *name, int namelen, int *idx)
1295{
1296 const char *start;
1297 char *end;
1298
1299 if (strncmp(name, LUSTRE_VOLATILE_HDR, LUSTRE_VOLATILE_HDR_LEN) != 0)
1300 return false;
1301
1302
1303 if (idx == NULL)
1304 return true;
1305
1306
1307
1308
1309 if (namelen < LUSTRE_VOLATILE_HDR_LEN + 2)
1310 goto bad_format;
1311
1312 if ((*(name + LUSTRE_VOLATILE_HDR_LEN) == ':') &&
1313 (*(name + LUSTRE_VOLATILE_HDR_LEN + 1) == ':')) {
1314 *idx = -1;
1315 return true;
1316 }
1317
1318 start = name + LUSTRE_VOLATILE_HDR_LEN + 1;
1319 *idx = simple_strtoul(start, &end, 0);
1320
1321
1322
1323 if (((*idx == 0) && (end == start)) ||
1324 (*end != ':') || (*idx < 0))
1325 goto bad_format;
1326
1327 return true;
1328bad_format:
1329
1330
1331 CERROR("Bad volatile file name format: %s\n",
1332 name + LUSTRE_VOLATILE_HDR_LEN);
1333 return false;
1334}
1335
1336static inline int cli_brw_size(struct obd_device *obd)
1337{
1338 LASSERT(obd != NULL);
1339 return obd->u.cli.cl_max_pages_per_rpc << PAGE_CACHE_SHIFT;
1340}
1341
1342#endif
1343