Whamcloud - gitweb
b48ca6568309c5a9997f922aaa99bfed42a1fa9d
[fs/lustre-release.git] / lustre / mdt / mdt_internal.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  lustre/mdt/mdt_internal.h
5  *  Lustre Metadata Target (mdt) request handler
6  *
7  *  Copyright (c) 2006 Cluster File Systems, Inc.
8  *   Author: Peter Braam <braam@clusterfs.com>
9  *   Author: Andreas Dilger <adilger@clusterfs.com>
10  *   Author: Phil Schwan <phil@clusterfs.com>
11  *   Author: Mike Shaver <shaver@clusterfs.com>
12  *   Author: Nikita Danilov <nikita@clusterfs.com>
13  *   Author: Huang Hua <huanghua@clusterfs.com>
14  *
15  *   This file is part of the Lustre file system, http://www.lustre.org
16  *   Lustre is a trademark of Cluster File Systems, Inc.
17  *
18  *   You may have signed or agreed to another license before downloading
19  *   this software.  If so, you are bound by the terms and conditions
20  *   of that agreement, and the following does not apply to you.  See the
21  *   LICENSE file included with this distribution for more information.
22  *
23  *   If you did not agree to a different license, then this copy of Lustre
24  *   is open source software; you can redistribute it and/or modify it
25  *   under the terms of version 2 of the GNU General Public License as
26  *   published by the Free Software Foundation.
27  *
28  *   In either case, Lustre is distributed in the hope that it will be
29  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
30  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31  *   license text for more details.
32  */
33
34 #ifndef _MDT_INTERNAL_H
35 #define _MDT_INTERNAL_H
36
37 #if defined(__KERNEL__)
38
39 /*
40  * struct ptlrpc_client
41  */
42 #include <lustre_net.h>
43 #include <obd.h>
44 /*
45  * struct obd_connect_data
46  * struct lustre_handle
47  */
48 #include <lustre/lustre_idl.h>
49 #include <md_object.h>
50 #include <dt_object.h>
51 #include <lustre_fid.h>
52 #include <lustre_fld.h>
53 #include <lustre_req_layout.h>
54 /* LR_CLIENT_SIZE, etc. */
55 #include <lustre_disk.h>
56
57
58 /* Data stored per client in the last_rcvd file.  In le32 order. */
59 struct mdt_client_data {
60         __u8  mcd_uuid[40];     /* client UUID */
61         __u64 mcd_last_transno; /* last completed transaction ID */
62         __u64 mcd_last_xid;     /* xid for the last transaction */
63         __u32 mcd_last_result;  /* result from last RPC */
64         __u32 mcd_last_data;    /* per-op data (disposition for open &c.) */
65         __u8  mcd_padding[LR_CLIENT_SIZE - 64];
66 };
67
68 /* copied from lr_server_data.
69  * mds data stored at the head of last_rcvd file. In le32 order. */
70 struct mdt_server_data {
71         __u8  msd_uuid[40];        /* server UUID */
72         __u64 msd_unused;          /* was fsd_last_objid - don't use for now */
73         __u64 msd_last_transno;    /* last completed transaction ID */
74         __u64 msd_mount_count;     /* incarnation number */
75         __u32 msd_feature_compat;  /* compatible feature flags */
76         __u32 msd_feature_rocompat;/* read-only compatible feature flags */
77         __u32 msd_feature_incompat;/* incompatible feature flags */
78         __u32 msd_server_size;     /* size of server data area */
79         __u32 msd_client_start;    /* start of per-client data area */
80         __u16 msd_client_size;     /* size of per-client data area */
81         __u16 msd_subdir_count;    /* number of subdirectories for objects */
82         __u64 msd_catalog_oid;     /* recovery catalog object id */
83         __u32 msd_catalog_ogen;    /* recovery catalog inode generation */
84         __u8  msd_peeruuid[40];    /* UUID of MDS associated with this OST */
85         __u32 msd_ost_index;       /* index number of OST in LOV */
86         __u32 msd_mdt_index;       /* index number of MDT in LMV */
87         __u8  msd_padding[LR_SERVER_SIZE - 148];
88 };
89
90 struct mdt_object;
91 /* file data for open files on MDS */
92 struct mdt_file_data {
93         struct portals_handle mfd_handle; /* must be first */
94         struct list_head      mfd_list;   /* protected by med_open_lock */
95         __u64                 mfd_xid;    /* xid of the open request */
96         int                   mfd_mode;   /* open mode provided by client */
97         struct mdt_object    *mfd_object; /* point to opened object */
98 };
99
100 struct mdt_device {
101         /* super-class */
102         struct md_device           mdt_md_dev;
103         struct ptlrpc_service     *mdt_service;
104         struct ptlrpc_service     *mdt_readpage_service;
105         /* DLM name-space for meta-data locks maintained by this server */
106         struct ldlm_namespace     *mdt_namespace;
107         /* ptlrpc handle for MDS->client connections (for lock ASTs). */
108         struct ptlrpc_client      *mdt_ldlm_client;
109         /* underlying device */
110         struct md_device          *mdt_child;
111         struct dt_device          *mdt_bottom;
112         /*
113          * Options bit-fields.
114          */
115         struct {
116                 signed int         mo_user_xattr :1;
117                 signed int         mo_acl        :1;
118                 signed int         mo_compat_resname:1;
119         } mdt_opts;
120         /* Transaction related stuff here */
121         spinlock_t                 mdt_transno_lock;
122         __u64                      mdt_last_transno;
123         __u64                      mdt_last_committed;
124         /* transaction callbacks */
125         struct dt_txn_callback     mdt_txn_cb;
126         /* last_rcvd file */
127         struct dt_object          *mdt_last_rcvd;
128
129         /* these values should be updated from lov if necessary.
130          * or should be placed somewhere else. */
131         int                        mdt_max_mdsize;
132         int                        mdt_max_cookiesize;
133         __u64                      mdt_mount_count;     
134         
135         struct mdt_server_data     mdt_msd;
136         unsigned long              mdt_client_bitmap[(LR_MAX_CLIENTS >> 3) / sizeof(long)];
137 };
138
139 /*XXX copied from mds_internal.h */
140 #define MDT_SERVICE_WATCHDOG_TIMEOUT (obd_timeout * 1000)
141 #define MDT_ROCOMPAT_SUPP       (OBD_ROCOMPAT_LOVOBJID)
142 #define MDT_INCOMPAT_SUPP       (OBD_INCOMPAT_MDT | OBD_INCOMPAT_COMMON_LR)
143
144 struct mdt_object {
145         struct lu_object_header mot_header;
146         struct md_object        mot_obj;
147 };
148
149 struct mdt_lock_handle {
150         struct lustre_handle    mlh_lh;
151         ldlm_mode_t             mlh_mode;
152 };
153
154 enum {
155         MDT_REP_BUF_NR_MAX = 8
156 };
157
158 enum {
159         MDT_LH_PARENT,
160         MDT_LH_CHILD,
161         MDT_LH_OLD,
162         MDT_LH_NEW,
163         MDT_LH_NR
164 };
165
166 struct mdt_reint_record {
167         mdt_reint_t          rr_opcode;
168         const struct lu_fid *rr_fid1;
169         const struct lu_fid *rr_fid2;
170         const char          *rr_name;
171         const char          *rr_tgt;
172         int                  rr_eadatalen;
173         const void          *rr_eadata;
174         int                  rr_logcookielen;
175         const struct llog_cookie  *rr_logcookies;
176
177 };
178
179
180 #define XATTR_NAME_ACL_ACCESS   "system.posix_acl_access"
181 #define XATTR_NAME_LOV          "lov"
182
183 /*
184  * Common data shared by mdt-level handlers. This is allocated per-thread to
185  * reduce stack consumption.
186  */
187 struct mdt_thread_info {
188         const struct lu_context   *mti_ctxt;
189         struct mdt_device         *mti_mdt;
190         /*
191          * number of buffers in reply message.
192          */
193         int                        mti_rep_buf_nr;
194         /*
195          * sizes of reply buffers.
196          */
197         int                        mti_rep_buf_size[MDT_REP_BUF_NR_MAX];
198         /*
199          * Body for "habeo corpus" operations.
200          */
201         const struct mdt_body     *mti_body;
202         /*
203          * Lock request for "habeo clavis" operations.
204          */
205         const struct ldlm_request *mti_dlm_req;
206         /*
207          * Host object. This is released at the end of mdt_handler().
208          */
209         struct mdt_object         *mti_object;
210         /*
211          * Object attributes.
212          */
213         struct lu_attr             mti_attr;
214         /*
215          * reint record. Containing information for reint operations.
216          */
217         struct mdt_reint_record    mti_rr;
218         /*
219          * Additional fail id that can be set by handler. Passed to
220          * target_send_reply().
221          */
222         int                        mti_fail_id;
223         /*
224          * A couple of lock handles.
225          */
226         struct mdt_lock_handle     mti_lh[MDT_LH_NR];
227         /*
228          * for req-layout interface.
229          */
230         struct req_capsule         mti_pill;
231         /*
232          * buffer for mdt_statfs().
233          *
234          * XXX this is probably huge overkill, because statfs is not that
235          * frequent.
236          */
237
238         struct kstatfs             mti_sfs;
239
240         /* temporary stuff used by thread */
241         struct lu_fid              mti_tmp_fid1;
242         struct lu_fid              mti_tmp_fid2;
243         ldlm_policy_data_t         mti_policy;
244         struct ldlm_res_id         mti_res_id;
245         union {
246                 struct obd_uuid    uuid;
247                 char               ns_name[48];
248         } mti_u;
249 };
250 /*
251  * Info allocated per-transaction.
252  */
253 struct mdt_txn_info {
254         __u64  txi_transno;
255 };
256
257 static inline struct md_device_operations *mdt_child_ops(struct mdt_device * m)
258 {
259         LASSERT(m->mdt_child);
260         return m->mdt_child->md_ops;
261 }
262
263 static inline struct md_object *mdt_object_child(struct mdt_object *o)
264 {
265         return lu2md(lu_object_next(&o->mot_obj.mo_lu));
266 }
267
268 static inline struct ptlrpc_request *mdt_info_req(struct mdt_thread_info *info)
269 {
270          return info->mti_pill.rc_req;
271 }
272
273 static inline void mdt_object_get(const struct lu_context *ctxt, 
274                                   struct mdt_object *o)
275 {
276         lu_object_get(&o->mot_obj.mo_lu);
277 }
278
279 static inline void mdt_object_put(const struct lu_context *ctxt, 
280                                   struct mdt_object *o)
281 {
282         lu_object_put(ctxt, &o->mot_obj.mo_lu);
283 }
284
285 static inline const struct lu_fid *mdt_object_fid(struct mdt_object *o)
286 {
287         return lu_object_fid(&o->mot_obj.mo_lu);
288 }
289
290 int mdt_object_lock(struct mdt_thread_info *,
291                     struct mdt_object *,
292                     struct mdt_lock_handle *, 
293                     __u64);
294
295 void mdt_object_unlock(struct mdt_thread_info *, 
296                        struct mdt_object *,
297                        struct mdt_lock_handle *);
298
299 struct mdt_object *mdt_object_find(const struct lu_context *,
300                                    struct mdt_device *, 
301                                    const struct lu_fid *);
302 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *,
303                                         const struct lu_fid *,
304                                         struct mdt_lock_handle *,
305                                         __u64);
306 void mdt_object_unlock_put(struct mdt_thread_info *, 
307                            struct mdt_object *,
308                            struct mdt_lock_handle *);
309
310 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op);
311 int mdt_reint_rec(struct mdt_thread_info *);
312 void mdt_pack_attr2body(struct mdt_body *b, struct lu_attr *attr, 
313                         const struct lu_fid *fid);
314
315 int mdt_getxattr(struct mdt_thread_info *info);
316 int mdt_setxattr(struct mdt_thread_info *info);
317
318 void mdt_lock_handle_init(struct mdt_lock_handle *lh);
319 void mdt_lock_handle_fini(struct mdt_lock_handle *lh);
320
321
322 int mdt_object_exists(const struct lu_context *ctx,
323                       const struct lu_object *o);
324
325 int mdt_fs_setup(const struct lu_context *ctxt,
326                  struct mdt_device *mdt);
327
328 void mdt_fs_cleanup(const struct lu_context *ctxt,
329                     struct mdt_device *mdt);
330
331 int mdt_client_free(const struct lu_context *ctxt,
332                     struct mdt_device *mdt,
333                     struct mdt_export_data *med);
334
335 int mdt_update_server_data(const struct lu_context *ctxt,
336                            struct mdt_device *mdt,
337                            int sync);
338
339 int mdt_client_add(const struct lu_context *ctxt,
340                    struct mdt_device *mdt,
341                    struct mdt_export_data *med,
342                    int cl_idx);
343
344 int mdt_pin(struct mdt_thread_info* info);
345
346 int mdt_lock_new_child(struct mdt_thread_info *info, 
347                        struct mdt_object *o,
348                        struct mdt_lock_handle *child_lockh);
349
350 int mdt_reint_open(struct mdt_thread_info *info);
351
352 int mdt_mfd_close(const struct lu_context *ctxt,
353                   struct mdt_file_data *mfd);
354
355 int mdt_close(struct mdt_thread_info *info);
356
357 int mdt_done_writing(struct mdt_thread_info *info);
358 int mdt_handle_last_unlink(struct mdt_thread_info *, struct mdt_object *,
359                            const struct req_format *);
360
361
362 /* debug issues helper starts here*/
363 #define MDT_FAIL_CHECK(id)                                              \
364 ({                                                                      \
365         if (OBD_FAIL_CHECK(id))                                         \
366                 CERROR(LUSTRE_MDT0_NAME": " #id " test failed\n");      \
367         OBD_FAIL_CHECK(id);                                             \
368 })
369
370 #endif /* __KERNEL__ */
371 #endif /* _MDT_H */