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