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#ifndef __OBD_H
34#define __OBD_H
35
36#include <linux/spinlock.h>
37
38#include "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
50struct osc_async_rc {
51 int ar_rc;
52 int ar_force_sync;
53 __u64 ar_min_xid;
54};
55
56struct lov_oinfo {
57 struct ost_id loi_oi;
58 int loi_ost_idx;
59 int loi_ost_gen;
60
61 unsigned long loi_kms_valid:1;
62 __u64 loi_kms;
63 struct ost_lvb loi_lvb;
64 struct osc_async_rc loi_ar;
65};
66
67static 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
73static inline void loi_init(struct lov_oinfo *loi)
74{
75}
76
77struct lov_stripe_md;
78struct obd_info;
79
80int lov_read_and_clear_async_rc(struct cl_object *clob);
81
82typedef int (*obd_enqueue_update_f)(void *cookie, int rc);
83
84
85struct obd_info {
86
87 __u64 oi_flags;
88
89 struct lov_stripe_md *oi_md;
90
91 struct obd_statfs *oi_osfs;
92
93
94
95
96
97 obd_enqueue_update_f oi_cb_up;
98};
99
100struct 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
112struct brw_page {
113 u64 off;
114 struct page *pg;
115 unsigned int count;
116 u32 flag;
117};
118
119struct 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
133#define OSC_DEFAULT_RESENDS 10
134
135
136enum {
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
143enum obd_cl_sem_lock_class {
144 OBD_CLI_SEM_NORMAL,
145 OBD_CLI_SEM_MGC,
146 OBD_CLI_SEM_MDCOSC,
147};
148
149
150
151
152
153
154
155
156#define OBD_MAX_DEFAULT_EA_SIZE 4096
157
158struct mdc_rpc_lock;
159struct obd_import;
160struct client_obd {
161 struct rw_semaphore cl_sem;
162 struct obd_uuid cl_target_uuid;
163 struct obd_import *cl_import;
164 size_t cl_conn_count;
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181 u32 cl_default_mds_easize;
182
183
184
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;
191
192
193 unsigned long cl_dirty_pages;
194 unsigned long cl_dirty_max_pages;
195 unsigned long cl_dirty_transit;
196 unsigned long cl_avail_grant;
197 unsigned long cl_lost_grant;
198
199
200
201
202
203
204 long cl_reserved_grant;
205 struct list_head cl_cache_waiters;
206 unsigned long cl_next_shrink_grant;
207 struct list_head cl_grant_shrink_list;
208 int cl_grant_shrink_interval;
209
210
211
212
213 int cl_chunkbits;
214 unsigned int cl_extent_tax;
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
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
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
254 struct cl_client_cache *cl_cache;
255
256 struct list_head cl_lru_osc;
257
258
259
260
261 atomic_long_t *cl_lru_left;
262
263
264
265
266 atomic_long_t cl_lru_busy;
267
268 atomic_long_t cl_lru_in_list;
269
270
271
272 atomic_t cl_lru_shrinkers;
273
274 time64_t cl_lru_last_used;
275
276
277
278
279
280 u64 cl_lru_reclaim;
281
282 struct list_head cl_lru_list;
283
284 spinlock_t cl_lru_list_lock;
285
286
287
288
289 atomic_long_t cl_unstable_count;
290
291 struct list_head cl_shrink_list;
292
293
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
300
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
311 atomic_t cl_mgc_refcount;
312 struct obd_export *cl_mgc_mgsexp;
313
314
315 unsigned int cl_checksum:1;
316
317 __u32 cl_supp_cksum_types;
318
319 enum cksum_type cl_cksum_type;
320
321
322 struct osc_async_rc cl_ar;
323
324
325 struct lu_client_seq *cl_seq;
326
327 atomic_t cl_resends;
328
329
330 void *cl_writeback_work;
331 void *cl_lru_work;
332
333 struct cfs_hash *cl_quota_hash[MAXQUOTAS];
334};
335
336#define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
337
338struct obd_id_info {
339 __u32 idx;
340 u64 *data;
341};
342
343struct echo_client_obd {
344 struct obd_export *ec_exp;
345 spinlock_t ec_lock;
346 struct list_head ec_objects;
347 struct list_head ec_locks;
348 __u64 ec_unique;
349};
350
351
352struct ost_pool {
353 __u32 *op_array;
354 unsigned int op_count;
355 unsigned int op_size;
356 struct rw_semaphore op_rw_sem;
357};
358
359
360#define OBD_STATFS_CACHE_SECONDS 1
361
362struct 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;
369 unsigned long ltd_active:1,
370 ltd_activate:1,
371 ltd_reap:1;
372};
373
374struct lov_obd {
375 struct lov_desc desc;
376 struct lov_tgt_desc **lov_tgts;
377 struct ost_pool lov_packed;
378 struct mutex lov_lock;
379 struct obd_connect_data lov_ocd;
380 atomic_t lov_refcount;
381 __u32 lov_death_row;
382 __u32 lov_tgt_size;
383 int lov_connects;
384 int lov_pool_count;
385 struct cfs_hash *lov_pools_hash_body;
386 struct list_head lov_pool_list;
387 struct dentry *lov_pool_debugfs_entry;
388 enum lustre_sec_part lov_sp_me;
389
390
391 struct cl_client_cache *lov_cache;
392
393 struct rw_semaphore lov_notify_lock;
394
395 struct kobject *lov_tgts_kobj;
396};
397
398struct 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;
404};
405
406struct lmv_obd {
407 int refcount;
408 struct lu_client_fld lmv_fld;
409 spinlock_t lmv_lock;
410 struct lmv_desc desc;
411 struct obd_uuid cluuid;
412 struct obd_export *exp;
413
414 struct mutex lmv_init_mutex;
415 int connected;
416 int max_easize;
417 int max_def_easize;
418
419 u32 tgts_size;
420 struct lmv_tgt_desc **tgts;
421
422 struct obd_connect_data conn_data;
423 struct kobject *lmv_tgts_kobj;
424};
425
426struct niobuf_local {
427 __u64 lnb_file_offset;
428 __u32 lnb_page_offset;
429 __u32 lnb_len;
430 __u32 lnb_flags;
431 int lnb_rc;
432 struct page *lnb_page;
433 void *lnb_data;
434};
435
436#define LUSTRE_FLD_NAME "fld"
437#define LUSTRE_SEQ_NAME "seq"
438
439#define LUSTRE_MDD_NAME "mdd"
440#define LUSTRE_OSD_LDISKFS_NAME "osd-ldiskfs"
441#define LUSTRE_OSD_ZFS_NAME "osd-zfs"
442#define LUSTRE_VVP_NAME "vvp"
443#define LUSTRE_LMV_NAME "lmv"
444#define LUSTRE_SLP_NAME "slp"
445#define LUSTRE_LOD_NAME "lod"
446#define LUSTRE_OSP_NAME "osp"
447#define LUSTRE_LWP_NAME "lwp"
448
449
450
451#define LUSTRE_MDS_NAME "mds"
452#define LUSTRE_MDT_NAME "mdt"
453#define LUSTRE_MDC_NAME "mdc"
454#define LUSTRE_OSS_NAME "ost"
455#define LUSTRE_OST_NAME "obdfilter"
456#define LUSTRE_OSC_NAME "osc"
457#define LUSTRE_LOV_NAME "lov"
458#define LUSTRE_MGS_NAME "mgs"
459#define LUSTRE_MGC_NAME "mgc"
460
461#define LUSTRE_ECHO_NAME "obdecho"
462#define LUSTRE_ECHO_CLIENT_NAME "echo_client"
463#define LUSTRE_QMT_NAME "qmt"
464
465
466#define LUSTRE_MDS_OBDNAME "MDS"
467#define LUSTRE_OSS_OBDNAME "OSS"
468#define LUSTRE_MGS_OBDNAME "MGS"
469#define LUSTRE_MGC_OBDNAME "MGC"
470
471
472#define N_LOCAL_TEMP_PAGE 0x10000000
473
474
475
476
477enum obd_notify_event {
478
479 OBD_NOTIFY_CONNECT,
480
481 OBD_NOTIFY_ACTIVE,
482
483 OBD_NOTIFY_INACTIVE,
484
485 OBD_NOTIFY_OCD,
486
487 OBD_NOTIFY_SYNC_NONBLOCK,
488 OBD_NOTIFY_SYNC,
489
490 OBD_NOTIFY_CONFIG,
491
492 OBD_NOTIFY_DEACTIVATE,
493 OBD_NOTIFY_ACTIVATE
494};
495
496
497
498
499
500struct obd_notify_upcall {
501 int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
502 enum obd_notify_event ev, void *owner, void *data);
503
504 void *onu_owner;
505};
506
507struct target_recovery_data {
508 svc_handler_t trd_recovery_handler;
509 pid_t trd_processing_task;
510 struct completion trd_starting;
511 struct completion trd_finishing;
512};
513
514struct obd_llog_group {
515 struct llog_ctxt *olg_ctxts[LLOG_MAX_CTXTS];
516 wait_queue_head_t olg_waitq;
517 spinlock_t olg_lock;
518 struct mutex olg_cat_processing;
519};
520
521
522#define OBD_DEVICE_MAGIC 0XAB5CD6EF
523
524struct lvfs_run_ctxt {
525 struct dt_device *dt;
526};
527
528struct obd_device {
529 struct obd_type *obd_type;
530 u32 obd_magic;
531 int obd_minor;
532 struct lu_device *obd_lu_dev;
533
534
535 struct obd_uuid obd_uuid;
536 char obd_name[MAX_OBD_NAME];
537
538
539 unsigned long obd_attached:1,
540 obd_set_up:1,
541 obd_version_recov:1,
542 obd_replayable:1,
543 obd_no_transno:1,
544 obd_no_recov:1,
545 obd_stopping:1,
546 obd_starting:1,
547 obd_force:1,
548 obd_fail:1,
549 obd_no_conn:1,
550 obd_inactive:1,
551
552
553 obd_no_ir:1,
554 obd_process_conf:1;
555
556
557
558 unsigned long obd_recovery_expired:1;
559
560 struct cfs_hash *obd_uuid_hash;
561 wait_queue_head_t obd_refcount_waitq;
562 struct list_head obd_exports;
563 struct list_head obd_unlinked_exports;
564 struct list_head obd_delayed_exports;
565 atomic_t obd_refcount;
566 int obd_num_exports;
567 spinlock_t obd_nid_lock;
568 struct ldlm_namespace *obd_namespace;
569 struct ptlrpc_client obd_ldlm_client;
570
571 spinlock_t obd_dev_lock;
572 spinlock_t obd_osfs_lock;
573 struct obd_statfs obd_osfs;
574 __u64 obd_osfs_age;
575 u64 obd_last_committed;
576 struct mutex obd_dev_mutex;
577 struct lvfs_run_ctxt obd_lvfs_ctxt;
578 struct obd_llog_group obd_olg;
579 struct obd_device *obd_observer;
580 struct rw_semaphore obd_observer_link_sem;
581 struct obd_notify_upcall obd_upcall;
582 struct obd_export *obd_self_export;
583
584 union {
585 struct client_obd cli;
586 struct echo_client_obd echo_client;
587 struct lov_obd lov;
588 struct lmv_obd lmv;
589 } u;
590
591
592 struct lprocfs_stats *obd_stats;
593 unsigned int obd_cntr_base;
594
595 struct lprocfs_stats *md_stats;
596 unsigned int md_cntr_base;
597
598 struct dentry *obd_debugfs_entry;
599 struct dentry *obd_svc_debugfs_entry;
600 struct lprocfs_stats *obd_svc_stats;
601 atomic_t obd_evict_inprogress;
602 wait_queue_head_t obd_evict_inprogress_waitq;
603 struct list_head obd_evict_list;
604
605
606
607
608 rwlock_t obd_pool_lock;
609 u64 obd_pool_slv;
610 int obd_pool_limit;
611
612 int obd_conn_inprogress;
613
614
615
616
617
618 struct lu_ref obd_reference;
619
620 struct kobject obd_kobj;
621 struct completion obd_kobj_unregister;
622};
623
624
625#define KEY_ASYNC "async"
626#define KEY_CHANGELOG_CLEAR "changelog_clear"
627#define KEY_FID2PATH "fid2path"
628#define KEY_CHECKSUM "checksum"
629#define KEY_CLEAR_FS "clear_fs"
630#define KEY_CONN_DATA "conn_data"
631#define KEY_EVICT_BY_NID "evict_by_nid"
632#define KEY_FIEMAP "fiemap"
633#define KEY_FLUSH_CTX "flush_ctx"
634#define KEY_GRANT_SHRINK "grant_shrink"
635#define KEY_HSM_COPYTOOL_SEND "hsm_send"
636#define KEY_INIT_RECOV_BACKUP "init_recov_bk"
637#define KEY_INTERMDS "inter_mds"
638#define KEY_LAST_ID "last_id"
639#define KEY_LAST_FID "last_fid"
640#define KEY_MAX_EASIZE "max_easize"
641#define KEY_DEFAULT_EASIZE "default_easize"
642#define KEY_MGSSEC "mgssec"
643#define KEY_READ_ONLY "read-only"
644#define KEY_REGISTER_TARGET "register_target"
645#define KEY_SET_FS "set_fs"
646#define KEY_TGT_COUNT "tgt_count"
647
648#define KEY_SPTLRPC_CONF "sptlrpc_conf"
649
650#define KEY_CACHE_SET "cache_set"
651#define KEY_CACHE_LRU_SHRINK "cache_lru_shrink"
652
653struct lu_context;
654
655static inline int it_to_lock_mode(struct lookup_intent *it)
656{
657
658 if (it->it_op & IT_CREAT)
659 return LCK_CW;
660 else if (it->it_op & (IT_GETATTR | IT_OPEN | IT_LOOKUP |
661 IT_LAYOUT))
662 return LCK_CR;
663 else if (it->it_op & IT_READDIR)
664 return LCK_PR;
665 else if (it->it_op & IT_GETXATTR)
666 return LCK_PR;
667 else if (it->it_op & IT_SETXATTR)
668 return LCK_PW;
669
670 LASSERTF(0, "Invalid it_op: %d\n", it->it_op);
671 return -EINVAL;
672}
673
674enum md_op_flags {
675 MF_MDC_CANCEL_FID1 = BIT(0),
676 MF_MDC_CANCEL_FID2 = BIT(1),
677 MF_MDC_CANCEL_FID3 = BIT(2),
678 MF_MDC_CANCEL_FID4 = BIT(3),
679 MF_GET_MDT_IDX = BIT(4),
680};
681
682enum md_cli_flags {
683 CLI_SET_MEA = BIT(0),
684 CLI_RM_ENTRY = BIT(1),
685 CLI_HASH64 = BIT(2),
686 CLI_API32 = BIT(3),
687 CLI_MIGRATE = BIT(4),
688};
689
690struct md_op_data {
691 struct lu_fid op_fid1;
692 struct lu_fid op_fid2;
693 struct lu_fid op_fid3;
694 struct lu_fid op_fid4;
695 u32 op_mds;
696 struct lustre_handle op_handle;
697 s64 op_mod_time;
698 const char *op_name;
699 size_t op_namelen;
700 __u32 op_mode;
701 struct lmv_stripe_md *op_mea1;
702 struct lmv_stripe_md *op_mea2;
703 __u32 op_suppgids[2];
704 __u32 op_fsuid;
705 __u32 op_fsgid;
706 cfs_cap_t op_cap;
707 void *op_data;
708 size_t op_data_size;
709
710
711 struct iattr op_attr;
712 unsigned int op_attr_flags;
713 __u64 op_valid;
714 loff_t op_attr_blocks;
715
716 __u32 op_flags;
717
718
719 enum mds_op_bias op_bias;
720
721
722 __u64 op_offset;
723
724
725 __u32 op_max_pages;
726
727
728
729
730 enum md_cli_flags op_cli_flags;
731
732
733 __u64 op_data_version;
734 struct lustre_handle op_lease_handle;
735
736
737 __u32 op_default_stripe_offset;
738};
739
740struct md_callback {
741 int (*md_blocking_ast)(struct ldlm_lock *lock,
742 struct ldlm_lock_desc *desc,
743 void *data, int flag);
744};
745
746struct md_enqueue_info;
747
748
749struct md_enqueue_info {
750 struct md_op_data mi_data;
751 struct lookup_intent mi_it;
752 struct lustre_handle mi_lockh;
753 struct inode *mi_dir;
754 struct ldlm_enqueue_info mi_einfo;
755 int (*mi_cb)(struct ptlrpc_request *req,
756 struct md_enqueue_info *minfo, int rc);
757 void *mi_cbdata;
758};
759
760struct obd_ops {
761 struct module *owner;
762 int (*iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
763 void *karg, void __user *uarg);
764 int (*get_info)(const struct lu_env *env, struct obd_export *,
765 __u32 keylen, void *key, __u32 *vallen, void *val);
766 int (*set_info_async)(const struct lu_env *, struct obd_export *,
767 __u32 keylen, void *key,
768 __u32 vallen, void *val,
769 struct ptlrpc_request_set *set);
770 int (*setup)(struct obd_device *dev, struct lustre_cfg *cfg);
771 int (*precleanup)(struct obd_device *dev);
772 int (*cleanup)(struct obd_device *dev);
773 int (*process_config)(struct obd_device *dev, u32 len, void *data);
774 int (*postrecov)(struct obd_device *dev);
775 int (*add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
776 int priority);
777 int (*del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
778
779
780
781
782
783 int (*connect)(const struct lu_env *env,
784 struct obd_export **exp, struct obd_device *src,
785 struct obd_uuid *cluuid, struct obd_connect_data *ocd,
786 void *localdata);
787 int (*reconnect)(const struct lu_env *env,
788 struct obd_export *exp, struct obd_device *src,
789 struct obd_uuid *cluuid,
790 struct obd_connect_data *ocd,
791 void *localdata);
792 int (*disconnect)(struct obd_export *exp);
793
794
795 int (*fid_init)(struct obd_device *obd,
796 struct obd_export *exp, enum lu_cli_type type);
797 int (*fid_fini)(struct obd_device *obd);
798
799
800 int (*fid_alloc)(const struct lu_env *env, struct obd_export *exp,
801 struct lu_fid *fid, struct md_op_data *op_data);
802
803
804
805
806
807 int (*statfs)(const struct lu_env *, struct obd_export *exp,
808 struct obd_statfs *osfs, __u64 max_age, __u32 flags);
809 int (*statfs_async)(struct obd_export *exp, struct obd_info *oinfo,
810 __u64 max_age, struct ptlrpc_request_set *set);
811 int (*create)(const struct lu_env *env, struct obd_export *exp,
812 struct obdo *oa);
813 int (*destroy)(const struct lu_env *env, struct obd_export *exp,
814 struct obdo *oa);
815 int (*setattr)(const struct lu_env *, struct obd_export *exp,
816 struct obdo *oa);
817 int (*getattr)(const struct lu_env *env, struct obd_export *exp,
818 struct obdo *oa);
819 int (*preprw)(const struct lu_env *env, int cmd,
820 struct obd_export *exp, struct obdo *oa, int objcount,
821 struct obd_ioobj *obj, struct niobuf_remote *remote,
822 int *nr_pages, struct niobuf_local *local);
823 int (*commitrw)(const struct lu_env *env, int cmd,
824 struct obd_export *exp, struct obdo *oa,
825 int objcount, struct obd_ioobj *obj,
826 struct niobuf_remote *remote, int pages,
827 struct niobuf_local *local, int rc);
828 int (*init_export)(struct obd_export *exp);
829 int (*destroy_export)(struct obd_export *exp);
830
831
832 int (*import_event)(struct obd_device *, struct obd_import *,
833 enum obd_import_event);
834
835 int (*notify)(struct obd_device *obd, struct obd_device *watched,
836 enum obd_notify_event ev, void *data);
837
838 int (*health_check)(const struct lu_env *env, struct obd_device *);
839 struct obd_uuid *(*get_uuid)(struct obd_export *exp);
840
841
842 int (*quotactl)(struct obd_device *, struct obd_export *,
843 struct obd_quotactl *);
844
845
846 int (*pool_new)(struct obd_device *obd, char *poolname);
847 int (*pool_del)(struct obd_device *obd, char *poolname);
848 int (*pool_add)(struct obd_device *obd, char *poolname,
849 char *ostname);
850 int (*pool_rem)(struct obd_device *obd, char *poolname,
851 char *ostname);
852 void (*getref)(struct obd_device *obd);
853 void (*putref)(struct obd_device *obd);
854
855
856
857
858
859};
860
861
862struct lustre_md {
863 struct mdt_body *body;
864 struct lu_buf layout;
865 struct lmv_stripe_md *lmv;
866#ifdef CONFIG_FS_POSIX_ACL
867 struct posix_acl *posix_acl;
868#endif
869 struct mdt_remote_perm *remote_perm;
870};
871
872struct md_open_data {
873 struct obd_client_handle *mod_och;
874 struct ptlrpc_request *mod_open_req;
875 struct ptlrpc_request *mod_close_req;
876 atomic_t mod_refcount;
877 bool mod_is_create;
878};
879
880struct obd_client_handle {
881 struct lustre_handle och_fh;
882 struct lu_fid och_fid;
883 struct md_open_data *och_mod;
884 struct lustre_handle och_lease_handle;
885 __u32 och_magic;
886 fmode_t och_flags;
887};
888
889#define OBD_CLIENT_HANDLE_MAGIC 0xd15ea5ed
890
891struct lookup_intent;
892struct cl_attr;
893
894struct md_ops {
895 int (*getstatus)(struct obd_export *, struct lu_fid *);
896 int (*null_inode)(struct obd_export *, const struct lu_fid *);
897 int (*close)(struct obd_export *, struct md_op_data *,
898 struct md_open_data *, struct ptlrpc_request **);
899 int (*create)(struct obd_export *, struct md_op_data *,
900 const void *, size_t, umode_t, uid_t, gid_t,
901 cfs_cap_t, __u64, struct ptlrpc_request **);
902 int (*enqueue)(struct obd_export *, struct ldlm_enqueue_info *,
903 const union ldlm_policy_data *,
904 struct lookup_intent *, struct md_op_data *,
905 struct lustre_handle *, __u64);
906 int (*getattr)(struct obd_export *, struct md_op_data *,
907 struct ptlrpc_request **);
908 int (*getattr_name)(struct obd_export *, struct md_op_data *,
909 struct ptlrpc_request **);
910 int (*intent_lock)(struct obd_export *, struct md_op_data *,
911 struct lookup_intent *,
912 struct ptlrpc_request **,
913 ldlm_blocking_callback, __u64);
914 int (*link)(struct obd_export *, struct md_op_data *,
915 struct ptlrpc_request **);
916 int (*rename)(struct obd_export *, struct md_op_data *,
917 const char *, size_t, const char *, size_t,
918 struct ptlrpc_request **);
919 int (*setattr)(struct obd_export *, struct md_op_data *, void *,
920 size_t, struct ptlrpc_request **);
921 int (*sync)(struct obd_export *, const struct lu_fid *,
922 struct ptlrpc_request **);
923 int (*read_page)(struct obd_export *, struct md_op_data *,
924 struct md_callback *cb_op, __u64 hash_offset,
925 struct page **ppage);
926 int (*unlink)(struct obd_export *, struct md_op_data *,
927 struct ptlrpc_request **);
928
929 int (*setxattr)(struct obd_export *, const struct lu_fid *,
930 u64, const char *, const char *, int, int, int, __u32,
931 struct ptlrpc_request **);
932
933 int (*getxattr)(struct obd_export *, const struct lu_fid *,
934 u64, const char *, const char *, int, int, int,
935 struct ptlrpc_request **);
936
937 int (*init_ea_size)(struct obd_export *, u32, u32);
938
939 int (*get_lustre_md)(struct obd_export *, struct ptlrpc_request *,
940 struct obd_export *, struct obd_export *,
941 struct lustre_md *);
942
943 int (*free_lustre_md)(struct obd_export *, struct lustre_md *);
944
945 int (*merge_attr)(struct obd_export *,
946 const struct lmv_stripe_md *lsm,
947 struct cl_attr *attr, ldlm_blocking_callback);
948
949 int (*set_open_replay_data)(struct obd_export *,
950 struct obd_client_handle *,
951 struct lookup_intent *);
952 int (*clear_open_replay_data)(struct obd_export *,
953 struct obd_client_handle *);
954 int (*set_lock_data)(struct obd_export *, const struct lustre_handle *,
955 void *, __u64 *);
956
957 enum ldlm_mode (*lock_match)(struct obd_export *, __u64,
958 const struct lu_fid *, enum ldlm_type,
959 union ldlm_policy_data *, enum ldlm_mode,
960 struct lustre_handle *);
961
962 int (*cancel_unused)(struct obd_export *, const struct lu_fid *,
963 union ldlm_policy_data *, enum ldlm_mode,
964 enum ldlm_cancel_flags flags, void *opaque);
965
966 int (*get_fid_from_lsm)(struct obd_export *,
967 const struct lmv_stripe_md *,
968 const char *name, int namelen,
969 struct lu_fid *fid);
970
971 int (*intent_getattr_async)(struct obd_export *,
972 struct md_enqueue_info *);
973
974 int (*revalidate_lock)(struct obd_export *, struct lookup_intent *,
975 struct lu_fid *, __u64 *bits);
976
977 int (*unpackmd)(struct obd_export *exp, struct lmv_stripe_md **plsm,
978 const union lmv_mds_md *lmv, size_t lmv_size);
979
980
981
982
983
984};
985
986static inline struct md_open_data *obd_mod_alloc(void)
987{
988 struct md_open_data *mod;
989
990 mod = kzalloc(sizeof(*mod), GFP_NOFS);
991 if (!mod)
992 return NULL;
993 atomic_set(&mod->mod_refcount, 1);
994 return mod;
995}
996
997#define obd_mod_get(mod) atomic_inc(&(mod)->mod_refcount)
998#define obd_mod_put(mod) \
999({ \
1000 if (atomic_dec_and_test(&(mod)->mod_refcount)) { \
1001 if ((mod)->mod_open_req) \
1002 ptlrpc_req_finished((mod)->mod_open_req); \
1003 kfree(mod); \
1004 } \
1005})
1006
1007void obdo_from_inode(struct obdo *dst, struct inode *src, u32 valid);
1008void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent);
1009
1010
1011static inline int client_should_resend(int resend, struct client_obd *cli)
1012{
1013 return atomic_read(&cli->cl_resends) ?
1014 atomic_read(&cli->cl_resends) > resend : 1;
1015}
1016
1017
1018
1019
1020
1021
1022
1023
1024static inline const char *lu_dev_name(const struct lu_device *lu_dev)
1025{
1026 return lu_dev->ld_obd->obd_name;
1027}
1028
1029static inline bool filename_is_volatile(const char *name, size_t namelen,
1030 int *idx)
1031{
1032 const char *start;
1033 char *end;
1034
1035 if (strncmp(name, LUSTRE_VOLATILE_HDR, LUSTRE_VOLATILE_HDR_LEN) != 0)
1036 return false;
1037
1038
1039 if (!idx)
1040 return true;
1041
1042
1043
1044
1045 if (namelen < LUSTRE_VOLATILE_HDR_LEN + 2)
1046 goto bad_format;
1047
1048 if ((*(name + LUSTRE_VOLATILE_HDR_LEN) == ':') &&
1049 (*(name + LUSTRE_VOLATILE_HDR_LEN + 1) == ':')) {
1050 *idx = -1;
1051 return true;
1052 }
1053
1054 start = name + LUSTRE_VOLATILE_HDR_LEN + 1;
1055 *idx = simple_strtoul(start, &end, 0);
1056
1057
1058
1059 if (((*idx == 0) && (end == start)) ||
1060 (*end != ':') || (*idx < 0))
1061 goto bad_format;
1062
1063 return true;
1064bad_format:
1065
1066
1067
1068 CERROR("Bad volatile file name format: %s\n",
1069 name + LUSTRE_VOLATILE_HDR_LEN);
1070 return false;
1071}
1072
1073static inline int cli_brw_size(struct obd_device *obd)
1074{
1075 return obd->u.cli.cl_max_pages_per_rpc << PAGE_SHIFT;
1076}
1077
1078
1079
1080
1081
1082
1083
1084static inline void client_adjust_max_dirty(struct client_obd *cli)
1085{
1086
1087 if (cli->cl_dirty_max_pages <= 0)
1088 cli->cl_dirty_max_pages =
1089 (OSC_MAX_DIRTY_DEFAULT * 1024 * 1024) >> PAGE_SHIFT;
1090 else {
1091 unsigned long dirty_max = cli->cl_max_rpcs_in_flight *
1092 cli->cl_max_pages_per_rpc;
1093
1094 if (dirty_max > cli->cl_dirty_max_pages)
1095 cli->cl_dirty_max_pages = dirty_max;
1096 }
1097
1098 if (cli->cl_dirty_max_pages > totalram_pages / 8)
1099 cli->cl_dirty_max_pages = totalram_pages / 8;
1100}
1101
1102#endif
1103