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 __u8 mcd_padding[LR_CLIENT_SIZE - 64];
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];
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 */
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;
113 * Options bit-fields.
116 signed int mo_user_xattr :1;
117 signed int mo_acl :1;
118 signed int mo_compat_resname:1;
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;
127 struct dt_object *mdt_last_rcvd;
129 /* these values should be updated from lov if necessary.
130 * or should be placed somewhere else. */
132 int mdt_max_cookiesize;
133 __u64 mdt_mount_count;
135 struct mdt_server_data mdt_msd;
136 unsigned long mdt_client_bitmap[(LR_MAX_CLIENTS >> 3) / sizeof(long)];
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)
145 struct lu_object_header mot_header;
146 struct md_object mot_obj;
149 struct mdt_lock_handle {
150 struct lustre_handle mlh_lh;
151 ldlm_mode_t mlh_mode;
155 MDT_REP_BUF_NR_MAX = 8
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;
173 const void *rr_eadata;
175 const struct llog_cookie *rr_logcookies;
180 #define XATTR_NAME_ACL_ACCESS "system.posix_acl_access"
181 #define XATTR_NAME_LOV "lov"
184 * Common data shared by mdt-level handlers. This is allocated per-thread to
185 * reduce stack consumption.
187 struct mdt_thread_info {
188 const struct lu_context *mti_ctxt;
189 struct mdt_device *mti_mdt;
191 * number of buffers in reply message.
195 * sizes of reply buffers.
197 int mti_rep_buf_size[MDT_REP_BUF_NR_MAX];
199 * Body for "habeo corpus" operations.
201 const struct mdt_body *mti_body;
203 * Lock request for "habeo clavis" operations.
205 const struct ldlm_request *mti_dlm_req;
207 * Host object. This is released at the end of mdt_handler().
209 struct mdt_object *mti_object;
213 struct lu_attr mti_attr;
215 * reint record. Containing information for reint operations.
217 struct mdt_reint_record mti_rr;
219 * Additional fail id that can be set by handler. Passed to
220 * target_send_reply().
224 * A couple of lock handles.
226 struct mdt_lock_handle mti_lh[MDT_LH_NR];
228 * for req-layout interface.
230 struct req_capsule mti_pill;
232 * buffer for mdt_statfs().
234 * XXX this is probably huge overkill, because statfs is not that
238 struct kstatfs mti_sfs;
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;
246 struct obd_uuid uuid;
251 * Info allocated per-transaction.
253 struct mdt_txn_info {
257 static inline struct md_device_operations *mdt_child_ops(struct mdt_device * m)
259 LASSERT(m->mdt_child);
260 return m->mdt_child->md_ops;
263 static inline struct md_object *mdt_object_child(struct mdt_object *o)
265 return lu2md(lu_object_next(&o->mot_obj.mo_lu));
268 static inline struct ptlrpc_request *mdt_info_req(struct mdt_thread_info *info)
270 return info->mti_pill.rc_req;
273 static inline void mdt_object_get(const struct lu_context *ctxt,
274 struct mdt_object *o)
276 lu_object_get(&o->mot_obj.mo_lu);
279 static inline void mdt_object_put(const struct lu_context *ctxt,
280 struct mdt_object *o)
282 lu_object_put(ctxt, &o->mot_obj.mo_lu);
285 static inline const struct lu_fid *mdt_object_fid(struct mdt_object *o)
287 return lu_object_fid(&o->mot_obj.mo_lu);
290 int mdt_object_lock(struct mdt_thread_info *,
292 struct mdt_lock_handle *,
295 void mdt_object_unlock(struct mdt_thread_info *,
297 struct mdt_lock_handle *);
299 struct mdt_object *mdt_object_find(const struct lu_context *,
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 *,
306 void mdt_object_unlock_put(struct mdt_thread_info *,
308 struct mdt_lock_handle *);
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);
315 int mdt_getxattr(struct mdt_thread_info *info);
316 int mdt_setxattr(struct mdt_thread_info *info);
318 void mdt_lock_handle_init(struct mdt_lock_handle *lh);
319 void mdt_lock_handle_fini(struct mdt_lock_handle *lh);
322 int mdt_object_exists(const struct lu_context *ctx,
323 const struct lu_object *o);
325 int mdt_fs_setup(const struct lu_context *ctxt,
326 struct mdt_device *mdt);
328 void mdt_fs_cleanup(const struct lu_context *ctxt,
329 struct mdt_device *mdt);
331 int mdt_client_free(const struct lu_context *ctxt,
332 struct mdt_device *mdt,
333 struct mdt_export_data *med);
335 int mdt_update_server_data(const struct lu_context *ctxt,
336 struct mdt_device *mdt,
339 int mdt_client_add(const struct lu_context *ctxt,
340 struct mdt_device *mdt,
341 struct mdt_export_data *med,
344 int mdt_pin(struct mdt_thread_info* info);
346 int mdt_lock_new_child(struct mdt_thread_info *info,
347 struct mdt_object *o,
348 struct mdt_lock_handle *child_lockh);
350 int mdt_reint_open(struct mdt_thread_info *info);
352 int mdt_mfd_close(const struct lu_context *ctxt,
353 struct mdt_file_data *mfd);
355 int mdt_close(struct mdt_thread_info *info);
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 *);
362 /* debug issues helper starts here*/
363 #define MDT_FAIL_CHECK(id) \
365 if (OBD_FAIL_CHECK(id)) \
366 CERROR(LUSTRE_MDT0_NAME": " #id " test failed\n"); \
367 OBD_FAIL_CHECK(id); \
370 #endif /* __KERNEL__ */