Whamcloud - gitweb
Branch: b_new_cmd
[fs/lustre-release.git] / lustre / mdt / mdt.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4
5 #ifndef _MDT_H
6 #define _MDT_H
7
8 #if defined(__KERNEL__)
9
10 /*
11  * struct ptlrpc_client
12  */
13 #include <linux/lustre_net.h>
14 /*
15  * struct obd_connect_data
16  * struct lustre_handle
17  */
18 #include <linux/lustre_idl.h>
19
20 #include <linux/lu_object.h>
21
22 struct md_device_operations;
23
24 struct ptlrpc_service_conf {
25         int psc_nbufs;
26         int psc_bufsize;
27         int psc_max_req_size;
28         int psc_max_reply_size;
29         int psc_req_portal;
30         int psc_rep_portal;
31         int psc_watchdog_timeout; /* in ms */
32         int psc_num_threads;
33 };
34
35 struct md_object;
36
37 struct md_device {
38         struct lu_device             md_lu_dev;
39         struct md_device_operations *md_ops;
40 };
41
42 struct md_device_operations {
43         int (*mdo_root_get)(struct md_device *m, struct lu_fid *f);
44         int (*mdo_mkdir)(struct md_object *o, const char *name,
45                          struct md_object *child);
46 };
47
48 struct mdt_device {
49         /* super-class */
50         struct md_device           mdt_md_dev;
51         struct ptlrpc_service     *mdt_service;
52         struct ptlrpc_service_conf mdt_service_conf;
53         /* DLM name-space for meta-data locks maintained by this server */
54         struct ldlm_namespace     *mdt_namespace;
55         /* ptlrpc handle for MDS->client connections (for lock ASTs). */
56         struct ptlrpc_client       mdt_ldlm_client;
57         /* underlying device */
58         struct md_device          *mdt_child;
59 };
60
61 struct md_object {
62         struct lu_object mo_lu;
63 };
64
65 static inline int lu_device_is_md(struct lu_device *d)
66 {
67         return d->ld_type->ldt_tags & LU_DEVICE_MD;
68 }
69
70 static inline struct md_object *lu2md(struct lu_object *o)
71 {
72         LASSERT(lu_device_is_md(o->lo_dev));
73         return container_of(o, struct md_object, mo_lu);
74 }
75
76 static inline struct md_device *md_device_get(struct md_object *o)
77 {
78         LASSERT(lu_device_is_md(o->mo_lu.lo_dev));
79         return container_of(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
80 }
81
82 struct mdt_object {
83         struct lu_object_header mot_header;
84         struct md_object        mot_obj;
85 };
86
87 struct mdt_lock_handle {
88         struct lustre_handle    mlh_lh;
89         ldlm_mode_t             mlh_mode;
90         __u64                   mlh_part;
91 };
92
93 void mdt_lock_handle_init(struct mdt_lock_handle *lh);
94 void mdt_lock_handle_fini(struct mdt_lock_handle *lh);
95
96 struct mdd_object {
97         struct md_object  mod_obj;
98 };
99
100 struct osd_object {
101         struct lu_object  oo_lu;
102         struct dentry    *oo_dentry;
103 };
104
105 int md_device_init(struct md_device *md, struct lu_device_type *t);
106 void md_device_fini(struct md_device *md);
107
108 enum {
109         MDT_REP_BUF_NR_MAX = 8
110 };
111
112 enum {
113         MDT_LH_PARENT,
114         MDT_LH_CHILD,
115         MDT_LH_NR
116 };
117
118 /*
119  * Common data shared by mdt-level handlers. This is allocated per-thread to
120  * reduce stack consumption.
121  */
122 struct mdt_thread_info {
123         struct mdt_device     *mti_mdt;
124         /*
125          * number of buffers in reply message.
126          */
127         int                    mti_rep_buf_nr;
128         /*
129          * sizes of reply buffers.
130          */
131         int                    mti_rep_buf_size[MDT_REP_BUF_NR_MAX];
132         /*
133          * Body for "habeo corpus" operations.
134          */
135         struct mdt_body       *mti_body;
136         /*
137          * Host object. This is released at the end of mdt_handler().
138          */
139         struct mdt_object     *mti_object;
140         /*
141          * Additional fail id that can be set by handler. Passed to
142          * target_send_reply().
143          */
144         int                    mti_fail_id;
145         /*
146          * A couple of lock handles.
147          */
148         struct mdt_lock_handle mti_lh[MDT_LH_NR];
149
150 };
151
152 int fid_lock(struct ldlm_namespace *, const struct lu_fid *, 
153              struct lustre_handle *, ldlm_mode_t, __u64);
154              
155 void fid_unlock(struct ldlm_namespace *, const struct lu_fid *, 
156                 struct lustre_handle *, ldlm_mode_t);
157
158 #endif /* __KERNEL__ */
159 #endif /* _MDT_H */