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 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;
114 * Options bit-fields.
117 signed int mo_user_xattr :1;
118 signed int mo_acl :1;
119 signed int mo_compat_resname:1;
122 /* lock to pretect epoch and write count
123 * because we need not allocate memory, spinlock is fast.
125 spinlock_t mdt_epoch_lock;
128 /* Transaction related stuff here */
129 spinlock_t mdt_transno_lock;
130 __u64 mdt_last_transno;
131 __u64 mdt_last_committed;
133 /* transaction callbacks */
134 struct dt_txn_callback mdt_txn_cb;
136 struct dt_object *mdt_last_rcvd;
138 /* these values should be updated from lov if necessary.
139 * or should be placed somewhere else. */
141 int mdt_max_cookiesize;
142 __u64 mdt_mount_count;
144 struct mdt_server_data mdt_msd;
145 unsigned long mdt_client_bitmap[(LR_MAX_CLIENTS >> 3) / sizeof(long)];
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)
154 struct lu_object_header mot_header;
155 struct md_object mot_obj;
157 atomic_t mot_writecount;
160 struct mdt_lock_handle {
161 struct lustre_handle mlh_lh;
162 ldlm_mode_t mlh_mode;
166 MDT_REP_BUF_NR_MAX = 8
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;
184 const void *rr_eadata;
186 const struct llog_cookie *rr_logcookies;
191 MDT_NONEED_TANSNO = (1 << 0) /*Do not need transno for this req*/
194 * Common data shared by mdt-level handlers. This is allocated per-thread to
195 * reduce stack consumption.
197 struct mdt_thread_info {
198 const struct lu_context *mti_ctxt;
199 struct mdt_device *mti_mdt;
201 * number of buffers in reply message.
205 * sizes of reply buffers.
207 int mti_rep_buf_size[MDT_REP_BUF_NR_MAX];
209 * Body for "habeo corpus" operations.
211 const struct mdt_body *mti_body;
213 * Lock request for "habeo clavis" operations.
215 const struct ldlm_request *mti_dlm_req;
217 * Host object. This is released at the end of mdt_handler().
219 struct mdt_object *mti_object;
223 struct md_attr mti_attr;
225 * reint record. contains information for reint operations.
227 struct mdt_reint_record mti_rr;
229 * Additional fail id that can be set by handler. Passed to
230 * target_send_reply().
234 * A couple of lock handles.
236 struct mdt_lock_handle mti_lh[MDT_LH_NR];
238 * for req-layout interface.
240 struct req_capsule mti_pill;
242 * buffer for mdt_statfs().
244 * XXX this is probably huge overkill, because statfs is not that
248 struct kstatfs mti_sfs;
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;
256 struct obd_uuid uuid;
259 /* transaction number of current request */
261 __u32 mti_trans_flags;
263 /* readdir hint structure */
264 struct lu_rdpg mti_rdpg;
267 * Info allocated per-transaction.
269 struct mdt_txn_info {
273 static inline struct md_device_operations *mdt_child_ops(struct mdt_device * m)
275 LASSERT(m->mdt_child);
276 return m->mdt_child->md_ops;
279 static inline struct md_object *mdt_object_child(struct mdt_object *o)
281 return lu2md(lu_object_next(&o->mot_obj.mo_lu));
284 static inline struct ptlrpc_request *mdt_info_req(struct mdt_thread_info *info)
286 return info->mti_pill.rc_req;
289 static inline void mdt_object_get(const struct lu_context *ctxt,
290 struct mdt_object *o)
292 lu_object_get(&o->mot_obj.mo_lu);
295 static inline void mdt_object_put(const struct lu_context *ctxt,
296 struct mdt_object *o)
298 lu_object_put(ctxt, &o->mot_obj.mo_lu);
301 static inline const struct lu_fid *mdt_object_fid(struct mdt_object *o)
303 return lu_object_fid(&o->mot_obj.mo_lu);
306 int mdt_object_lock(struct mdt_thread_info *,
308 struct mdt_lock_handle *,
311 void mdt_object_unlock(struct mdt_thread_info *,
313 struct mdt_lock_handle *,
316 struct mdt_object *mdt_object_find(const struct lu_context *,
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 *,
323 void mdt_object_unlock_put(struct mdt_thread_info *,
325 struct mdt_lock_handle *,
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);
333 int mdt_getxattr(struct mdt_thread_info *info);
334 int mdt_setxattr(struct mdt_thread_info *info);
336 void mdt_lock_handle_init(struct mdt_lock_handle *lh);
337 void mdt_lock_handle_fini(struct mdt_lock_handle *lh);
340 int mdt_object_exists(const struct lu_context *ctx,
341 const struct lu_object *o);
343 int mdt_fs_setup(const struct lu_context *ctxt,
344 struct mdt_device *mdt);
346 void mdt_fs_cleanup(const struct lu_context *ctxt,
347 struct mdt_device *mdt);
349 int mdt_client_free(const struct lu_context *ctxt,
350 struct mdt_device *mdt,
351 struct mdt_export_data *med);
353 int mdt_update_server_data(const struct lu_context *ctxt,
354 struct mdt_device *mdt,
357 int mdt_client_add(const struct lu_context *ctxt,
358 struct mdt_device *mdt,
359 struct mdt_export_data *med,
362 int mdt_pin(struct mdt_thread_info* info);
364 int mdt_lock_new_child(struct mdt_thread_info *info,
365 struct mdt_object *o,
366 struct mdt_lock_handle *child_lockh);
368 int mdt_reint_open(struct mdt_thread_info *info);
370 void mdt_mfd_close(const struct lu_context *ctxt, struct mdt_device *mdt,
371 struct mdt_file_data *mfd);
373 int mdt_close(struct mdt_thread_info *info);
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 *);
380 void mdt_dump_lmm(int level, struct lov_mds_md *lmm);
382 extern struct lu_context_key mdt_thread_key;
383 /* debug issues helper starts here*/
384 #define MDT_FAIL_CHECK(id) \
386 if (OBD_FAIL_CHECK(id)) \
387 CERROR(LUSTRE_MDT0_NAME": " #id " test failed\n"); \
388 OBD_FAIL_CHECK(id); \
391 #endif /* __KERNEL__ */