Whamcloud - gitweb
929f4aaf74a2b351dad03c0ae26a07a3c8153fa5
[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         struct ptlrpc_service     *mdt_setattr_service;
106         /* DLM name-space for meta-data locks maintained by this server */
107         struct ldlm_namespace     *mdt_namespace;
108         /* ptlrpc handle for MDS->client connections (for lock ASTs). */
109         struct ptlrpc_client      *mdt_ldlm_client;
110         /* underlying device */
111         struct md_device          *mdt_child;
112         struct dt_device          *mdt_bottom;
113         /*
114          * Options bit-fields.
115          */
116         struct {
117                 signed int         mo_user_xattr :1;
118                 signed int         mo_acl        :1;
119                 signed int         mo_compat_resname:1;
120         } mdt_opts;
121         
122         /* lock to pretect epoch and write count
123          * because we need not allocate memory, spinlock is fast.
124          */
125         spinlock_t                 mdt_epoch_lock;
126         __u64                      mdt_io_epoch;
127
128         /* Transaction related stuff here */
129         spinlock_t                 mdt_transno_lock;
130         __u64                      mdt_last_transno;
131         __u64                      mdt_last_committed;
132
133         /* transaction callbacks */
134         struct dt_txn_callback     mdt_txn_cb;
135         /* last_rcvd file */
136         struct dt_object          *mdt_last_rcvd;
137
138         /* these values should be updated from lov if necessary.
139          * or should be placed somewhere else. */
140         int                        mdt_max_mdsize;
141         int                        mdt_max_cookiesize;
142         __u64                      mdt_mount_count;
143
144         struct mdt_server_data     mdt_msd;
145         unsigned long              mdt_client_bitmap[(LR_MAX_CLIENTS >> 3) / sizeof(long)];
146 };
147
148 /*XXX copied from mds_internal.h */
149 #define MDT_SERVICE_WATCHDOG_TIMEOUT (obd_timeout * 1000)
150 #define MDT_ROCOMPAT_SUPP       (OBD_ROCOMPAT_LOVOBJID)
151 #define MDT_INCOMPAT_SUPP       (OBD_INCOMPAT_MDT | OBD_INCOMPAT_COMMON_LR)
152
153 struct mdt_object {
154         struct lu_object_header mot_header;
155         struct md_object        mot_obj;
156         __u64                   mot_io_epoch;
157         atomic_t                mot_writecount;
158 };
159
160 struct mdt_lock_handle {
161         struct lustre_handle    mlh_lh;
162         ldlm_mode_t             mlh_mode;
163 };
164
165 enum {
166         MDT_REP_BUF_NR_MAX = 8
167 };
168
169 enum {
170         MDT_LH_PARENT,
171         MDT_LH_CHILD,
172         MDT_LH_OLD,
173         MDT_LH_NEW,
174         MDT_LH_NR
175 };
176
177 struct mdt_reint_record {
178         mdt_reint_t          rr_opcode;
179         const struct lu_fid *rr_fid1;
180         const struct lu_fid *rr_fid2;
181         const char          *rr_name;
182         const char          *rr_tgt;
183         int                  rr_eadatalen;
184         const void          *rr_eadata;
185         int                  rr_logcookielen;
186         const struct llog_cookie  *rr_logcookies;
187
188 };
189
190 enum {
191         MDT_NONEED_TANSNO = (1 << 0) /*Do not need transno for this req*/
192 };
193 /*
194  * Common data shared by mdt-level handlers. This is allocated per-thread to
195  * reduce stack consumption.
196  */
197 struct mdt_thread_info {
198         const struct lu_context   *mti_ctxt;
199         struct mdt_device         *mti_mdt;
200         /*
201          * number of buffers in reply message.
202          */
203         int                        mti_rep_buf_nr;
204         /*
205          * sizes of reply buffers.
206          */
207         int                        mti_rep_buf_size[MDT_REP_BUF_NR_MAX];
208         /*
209          * Body for "habeo corpus" operations.
210          */
211         const struct mdt_body     *mti_body;
212         /*
213          * Lock request for "habeo clavis" operations.
214          */
215         const struct ldlm_request *mti_dlm_req;
216         /*
217          * Host object. This is released at the end of mdt_handler().
218          */
219         struct mdt_object         *mti_object;
220         /*
221          * Object attributes.
222          */
223         struct md_attr             mti_attr;
224         /*
225          * reint record. contains information for reint operations.
226          */
227         struct mdt_reint_record    mti_rr;
228         /*
229          * Additional fail id that can be set by handler. Passed to
230          * target_send_reply().
231          */
232         int                        mti_fail_id;
233         /*
234          * A couple of lock handles.
235          */
236         struct mdt_lock_handle     mti_lh[MDT_LH_NR];
237         /*
238          * for req-layout interface.
239          */
240         struct req_capsule         mti_pill;
241         /*
242          * buffer for mdt_statfs().
243          *
244          * XXX this is probably huge overkill, because statfs is not that
245          * frequent.
246          */
247
248         struct kstatfs             mti_sfs;
249
250         /* temporary stuff used by thread */
251         struct lu_fid              mti_tmp_fid1;
252         struct lu_fid              mti_tmp_fid2;
253         ldlm_policy_data_t         mti_policy;
254         struct ldlm_res_id         mti_res_id;
255         union {
256                 struct obd_uuid    uuid;
257                 char               ns_name[48];
258         } mti_u;
259         /* transaction number of current request */
260         __u64                      mti_transno;
261         __u32                      mti_trans_flags;
262         
263         /* readdir hint structure */
264         struct lu_rdpg             mti_rdpg;
265 };
266 /*
267  * Info allocated per-transaction.
268  */
269 struct mdt_txn_info {
270         __u64  txi_transno;
271 };
272
273 static inline struct md_device_operations *mdt_child_ops(struct mdt_device * m)
274 {
275         LASSERT(m->mdt_child);
276         return m->mdt_child->md_ops;
277 }
278
279 static inline struct md_object *mdt_object_child(struct mdt_object *o)
280 {
281         return lu2md(lu_object_next(&o->mot_obj.mo_lu));
282 }
283
284 static inline struct ptlrpc_request *mdt_info_req(struct mdt_thread_info *info)
285 {
286          return info->mti_pill.rc_req;
287 }
288
289 static inline void mdt_object_get(const struct lu_context *ctxt,
290                                   struct mdt_object *o)
291 {
292         lu_object_get(&o->mot_obj.mo_lu);
293 }
294
295 static inline void mdt_object_put(const struct lu_context *ctxt,
296                                   struct mdt_object *o)
297 {
298         lu_object_put(ctxt, &o->mot_obj.mo_lu);
299 }
300
301 static inline const struct lu_fid *mdt_object_fid(struct mdt_object *o)
302 {
303         return lu_object_fid(&o->mot_obj.mo_lu);
304 }
305
306 int mdt_object_lock(struct mdt_thread_info *,
307                     struct mdt_object *,
308                     struct mdt_lock_handle *,
309                     __u64);
310
311 void mdt_object_unlock(struct mdt_thread_info *,
312                        struct mdt_object *,
313                        struct mdt_lock_handle *,
314                        int decref);
315
316 struct mdt_object *mdt_object_find(const struct lu_context *,
317                                    struct mdt_device *,
318                                    const struct lu_fid *);
319 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *,
320                                         const struct lu_fid *,
321                                         struct mdt_lock_handle *,
322                                         __u64);
323 void mdt_object_unlock_put(struct mdt_thread_info *,
324                            struct mdt_object *,
325                            struct mdt_lock_handle *,
326                            int decref);
327
328 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op);
329 int mdt_reint_rec(struct mdt_thread_info *);
330 void mdt_pack_attr2body(struct mdt_body *b, const struct lu_attr *attr,
331                         const struct lu_fid *fid);
332
333 int mdt_getxattr(struct mdt_thread_info *info);
334 int mdt_setxattr(struct mdt_thread_info *info);
335
336 void mdt_lock_handle_init(struct mdt_lock_handle *lh);
337 void mdt_lock_handle_fini(struct mdt_lock_handle *lh);
338
339
340 int mdt_object_exists(const struct lu_context *ctx,
341                       const struct lu_object *o);
342
343 int mdt_fs_setup(const struct lu_context *ctxt,
344                  struct mdt_device *mdt);
345
346 void mdt_fs_cleanup(const struct lu_context *ctxt,
347                     struct mdt_device *mdt);
348
349 int mdt_client_free(const struct lu_context *ctxt,
350                     struct mdt_device *mdt,
351                     struct mdt_export_data *med);
352
353 int mdt_update_server_data(const struct lu_context *ctxt,
354                            struct mdt_device *mdt,
355                            int sync);
356
357 int mdt_client_add(const struct lu_context *ctxt,
358                    struct mdt_device *mdt,
359                    struct mdt_export_data *med,
360                    int cl_idx);
361
362 int mdt_pin(struct mdt_thread_info* info);
363
364 int mdt_lock_new_child(struct mdt_thread_info *info,
365                        struct mdt_object *o,
366                        struct mdt_lock_handle *child_lockh);
367
368 int mdt_reint_open(struct mdt_thread_info *info);
369
370 void mdt_mfd_close(const struct lu_context *ctxt, struct mdt_device *mdt,
371                    struct mdt_file_data *mfd);
372
373 int mdt_close(struct mdt_thread_info *info);
374
375 int mdt_done_writing(struct mdt_thread_info *info);
376 void mdt_shrink_reply(struct mdt_thread_info *info);
377 int mdt_handle_last_unlink(struct mdt_thread_info *, struct mdt_object *,
378                            const struct md_attr *);
379
380 void mdt_dump_lmm(int level, struct lov_mds_md *lmm);
381
382 extern struct lu_context_key       mdt_thread_key;
383 /* debug issues helper starts here*/
384 #define MDT_FAIL_CHECK(id)                                              \
385 ({                                                                      \
386         if (OBD_FAIL_CHECK(id))                                         \
387                 CERROR(LUSTRE_MDT0_NAME": " #id " test failed\n");      \
388         OBD_FAIL_CHECK(id);                                             \
389 })
390
391 #endif /* __KERNEL__ */
392 #endif /* _MDT_H */