1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/mdt/mdt_internal.h
5 * Lustre Metadata Target (mdt) request handler
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>
15 * This file is part of the Lustre file system, http://www.lustre.org
16 * Lustre is a trademark of Cluster File Systems, Inc.
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.
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.
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.
34 #ifndef _MDT_INTERNAL_H
35 #define _MDT_INTERNAL_H
37 #if defined(__KERNEL__)
40 * struct ptlrpc_client
42 #include <lustre_net.h>
45 * struct obd_connect_data
46 * struct lustre_handle
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>
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 /* for MDS_CLOSE requests */
66 __u64 mcd_last_close_transno; /* last completed transaction ID */
67 __u64 mcd_last_close_xid; /* xid for the last transaction */
68 __u32 mcd_last_close_result; /* result from last RPC */
69 __u8 mcd_padding[LR_CLIENT_SIZE - 84];
72 static inline __u64 mcd_last_transno(struct mdt_client_data *mcd)
74 return (le64_to_cpu(mcd->mcd_last_transno) >
75 le64_to_cpu(mcd->mcd_last_close_transno) ?
76 le64_to_cpu(mcd->mcd_last_transno) :
77 le64_to_cpu(mcd->mcd_last_close_transno));
80 static inline __u64 mcd_last_xid(struct mdt_client_data *mcd)
82 return (le64_to_cpu(mcd->mcd_last_xid) >
83 le64_to_cpu(mcd->mcd_last_close_xid) ?
84 le64_to_cpu(mcd->mcd_last_xid) :
85 le64_to_cpu(mcd->mcd_last_close_xid));
88 /* copied from lr_server_data.
89 * mds data stored at the head of last_rcvd file. In le32 order. */
90 struct mdt_server_data {
91 __u8 msd_uuid[40]; /* server UUID */
92 __u64 msd_unused; /* was fsd_last_objid - don't use for now */
93 __u64 msd_last_transno; /* last completed transaction ID */
94 __u64 msd_mount_count; /* incarnation number */
95 __u32 msd_feature_compat; /* compatible feature flags */
96 __u32 msd_feature_rocompat;/* read-only compatible feature flags */
97 __u32 msd_feature_incompat;/* incompatible feature flags */
98 __u32 msd_server_size; /* size of server data area */
99 __u32 msd_client_start; /* start of per-client data area */
100 __u16 msd_client_size; /* size of per-client data area */
101 __u16 msd_subdir_count; /* number of subdirectories for objects */
102 __u64 msd_catalog_oid; /* recovery catalog object id */
103 __u32 msd_catalog_ogen; /* recovery catalog inode generation */
104 __u8 msd_peeruuid[40]; /* UUID of MDS associated with this OST */
105 __u32 msd_ost_index; /* index number of OST in LOV */
106 __u32 msd_mdt_index; /* index number of MDT in LMV */
107 __u8 msd_padding[LR_SERVER_SIZE - 148];
111 /* file data for open files on MDS */
112 struct mdt_file_data {
113 struct portals_handle mfd_handle; /* must be first */
114 struct list_head mfd_list; /* protected by med_open_lock */
115 __u64 mfd_xid; /* xid of the open request */
116 int mfd_mode; /* open mode provided by client */
117 struct mdt_object *mfd_object; /* point to opened object */
122 struct md_device mdt_md_dev;
123 struct ptlrpc_service *mdt_service;
124 struct ptlrpc_service *mdt_readpage_service;
125 struct ptlrpc_service *mdt_setattr_service;
126 /* DLM name-space for meta-data locks maintained by this server */
127 struct ldlm_namespace *mdt_namespace;
128 /* ptlrpc handle for MDS->client connections (for lock ASTs). */
129 struct ptlrpc_client *mdt_ldlm_client;
130 /* underlying device */
131 struct md_device *mdt_child;
132 struct dt_device *mdt_bottom;
134 * Options bit-fields.
137 signed int mo_user_xattr :1;
138 signed int mo_acl :1;
139 signed int mo_compat_resname:1;
142 /* lock to pretect epoch and write count
144 spinlock_t mdt_epoch_lock;
147 /* Transaction related stuff here */
148 spinlock_t mdt_transno_lock;
149 __u64 mdt_last_transno;
151 /* transaction callbacks */
152 struct dt_txn_callback mdt_txn_cb;
154 struct dt_object *mdt_last_rcvd;
156 /* these values should be updated from lov if necessary.
157 * or should be placed somewhere else. */
159 int mdt_max_cookiesize;
160 __u64 mdt_mount_count;
162 struct mdt_server_data mdt_msd;
163 unsigned long mdt_client_bitmap[(LR_MAX_CLIENTS >> 3) / sizeof(long)];
166 /*XXX copied from mds_internal.h */
167 #define MDT_SERVICE_WATCHDOG_TIMEOUT (obd_timeout * 1000)
168 #define MDT_ROCOMPAT_SUPP (OBD_ROCOMPAT_LOVOBJID)
169 #define MDT_INCOMPAT_SUPP (OBD_INCOMPAT_MDT | OBD_INCOMPAT_COMMON_LR)
172 struct lu_object_header mot_header;
173 struct md_object mot_obj;
178 struct mdt_lock_handle {
179 struct lustre_handle mlh_lh;
180 ldlm_mode_t mlh_mode;
184 MDT_REP_BUF_NR_MAX = 8
195 struct mdt_reint_record {
196 mdt_reint_t rr_opcode;
197 const struct lu_fid *rr_fid1;
198 const struct lu_fid *rr_fid2;
202 const void *rr_eadata;
204 const struct llog_cookie *rr_logcookies;
208 enum mdt_reint_flag {
209 MRF_SETATTR_LOCKED = 1 << 0,
213 MDT_NONEED_TRANSNO = (1 << 0) /*Do not need transno for this req*/
216 * Common data shared by mdt-level handlers. This is allocated per-thread to
217 * reduce stack consumption.
219 struct mdt_thread_info {
220 const struct lu_context *mti_ctxt;
221 struct mdt_device *mti_mdt;
223 * number of buffers in reply message.
227 * sizes of reply buffers.
229 int mti_rep_buf_size[MDT_REP_BUF_NR_MAX];
231 * Body for "habeo corpus" operations.
233 const struct mdt_body *mti_body;
235 * Lock request for "habeo clavis" operations.
237 const struct ldlm_request *mti_dlm_req;
239 * Host object. This is released at the end of mdt_handler().
241 struct mdt_object *mti_object;
245 struct md_attr mti_attr;
247 * Create specification
249 struct md_create_spec mti_spec;
251 * reint record. contains information for reint operations.
253 struct mdt_reint_record mti_rr;
255 * Additional fail id that can be set by handler. Passed to
256 * target_send_reply().
260 * A couple of lock handles.
262 struct mdt_lock_handle mti_lh[MDT_LH_NR];
264 * for req-layout interface.
266 struct req_capsule mti_pill;
268 * buffer for mdt_statfs().
270 * XXX this is probably huge overkill, because statfs is not that
274 struct kstatfs mti_sfs;
276 /* temporary stuff used by thread */
277 struct lu_fid mti_tmp_fid1;
278 struct lu_fid mti_tmp_fid2;
279 ldlm_policy_data_t mti_policy;
280 struct ldlm_res_id mti_res_id;
282 struct obd_uuid uuid;
285 /* transaction number of current request */
287 __u32 mti_trans_flags;
289 /* readdir hint structure */
290 struct lu_rdpg mti_rdpg;
293 * Info allocated per-transaction.
295 struct mdt_txn_info {
299 static inline struct md_device_operations *mdt_child_ops(struct mdt_device * m)
301 LASSERT(m->mdt_child);
302 return m->mdt_child->md_ops;
305 static inline struct md_object *mdt_object_child(struct mdt_object *o)
307 return lu2md(lu_object_next(&o->mot_obj.mo_lu));
310 static inline struct ptlrpc_request *mdt_info_req(struct mdt_thread_info *info)
312 return info->mti_pill.rc_req;
315 static inline void mdt_object_get(const struct lu_context *ctxt,
316 struct mdt_object *o)
318 lu_object_get(&o->mot_obj.mo_lu);
321 static inline void mdt_object_put(const struct lu_context *ctxt,
322 struct mdt_object *o)
324 lu_object_put(ctxt, &o->mot_obj.mo_lu);
327 static inline const struct lu_fid *mdt_object_fid(struct mdt_object *o)
329 return lu_object_fid(&o->mot_obj.mo_lu);
332 int mdt_object_lock(struct mdt_thread_info *,
334 struct mdt_lock_handle *,
337 void mdt_object_unlock(struct mdt_thread_info *,
339 struct mdt_lock_handle *,
342 struct mdt_object *mdt_object_find(const struct lu_context *,
344 const struct lu_fid *);
345 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *,
346 const struct lu_fid *,
347 struct mdt_lock_handle *,
349 void mdt_object_unlock_put(struct mdt_thread_info *,
351 struct mdt_lock_handle *,
354 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op);
355 int mdt_reint_rec(struct mdt_thread_info *);
356 void mdt_pack_attr2body(struct mdt_body *b, const struct lu_attr *attr,
357 const struct lu_fid *fid);
359 int mdt_getxattr(struct mdt_thread_info *info);
360 int mdt_setxattr(struct mdt_thread_info *info);
362 void mdt_lock_handle_init(struct mdt_lock_handle *lh);
363 void mdt_lock_handle_fini(struct mdt_lock_handle *lh);
365 void mdt_reconstruct(struct mdt_thread_info *);
367 int mdt_fs_setup(const struct lu_context *, struct mdt_device *);
368 void mdt_fs_cleanup(const struct lu_context *, struct mdt_device *);
370 int mdt_client_free(const struct lu_context *ctxt,
371 struct mdt_device *mdt,
372 struct mdt_export_data *med);
373 int mdt_client_add(const struct lu_context *ctxt,
374 struct mdt_device *mdt,
375 struct mdt_export_data *med,
378 int mdt_pin(struct mdt_thread_info* info);
380 int mdt_lock_new_child(struct mdt_thread_info *info,
381 struct mdt_object *o,
382 struct mdt_lock_handle *child_lockh);
384 int mdt_open(struct mdt_thread_info *info);
386 void mdt_mfd_close(const struct lu_context *ctxt, struct mdt_device *mdt,
387 struct mdt_file_data *mfd, struct md_attr *ma);
389 int mdt_close(struct mdt_thread_info *info);
391 int mdt_done_writing(struct mdt_thread_info *info);
392 void mdt_shrink_reply(struct mdt_thread_info *info, int offset);
393 int mdt_handle_last_unlink(struct mdt_thread_info *, struct mdt_object *,
394 const struct md_attr *);
396 void mdt_dump_lmm(int level, struct lov_mds_md *lmm);
398 extern struct lu_context_key mdt_thread_key;
399 /* debug issues helper starts here*/
400 static inline void mdt_fail_write(const struct lu_context *ctx,
401 const struct dt_device *dd, int id)
403 if (OBD_FAIL_CHECK(id)) {
404 CERROR(LUSTRE_MDT0_NAME": obd_fail_loc=%x, fail write ops\n",
406 dd->dd_ops->dt_ro_set(ctx, dd);
407 /* We set FAIL_ONCE because we never "un-fail" a device */
408 obd_fail_loc |= OBD_FAILED | OBD_FAIL_ONCE;
412 #define MDT_FAIL_CHECK(id) \
414 if (OBD_FAIL_CHECK(id)) \
415 CERROR(LUSTRE_MDT0_NAME": " #id " test failed\n"); \
416 OBD_FAIL_CHECK(id); \
419 #define MDT_FAIL_CHECK_ONCE(id) \
421 if (OBD_FAIL_CHECK(id)) { \
422 CERROR(LUSTRE_MDT0_NAME": *** obd_fail_loc=%x ***\n", id); \
423 obd_fail_loc |= OBD_FAILED; \
424 if ((id) & OBD_FAIL_ONCE) \
425 obd_fail_loc |= OBD_FAIL_ONCE; \
431 #define MDT_FAIL_RETURN(id, ret) \
433 if (MDT_FAIL_CHECK_ONCE(id)) { \
438 #endif /* __KERNEL__ */