Whamcloud - gitweb
add layers initialization here. MDT as top device will init/fini other devices.
[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/mds/handler.c
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  *
14  *   This file is part of the Lustre file system, http://www.lustre.org
15  *   Lustre is a trademark of Cluster File Systems, Inc.
16  *
17  *   You may have signed or agreed to another license before downloading
18  *   this software.  If so, you are bound by the terms and conditions
19  *   of that agreement, and the following does not apply to you.  See the
20  *   LICENSE file included with this distribution for more information.
21  *
22  *   If you did not agree to a different license, then this copy of Lustre
23  *   is open source software; you can redistribute it and/or modify it
24  *   under the terms of version 2 of the GNU General Public License as
25  *   published by the Free Software Foundation.
26  *
27  *   In either case, Lustre is distributed in the hope that it will be
28  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
29  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30  *   license text for more details.
31  */
32
33 #ifndef _MDT_INTERNAL_H
34 #define _MDT_INTERNAL_H
35
36 #if defined(__KERNEL__)
37
38 /*
39  * struct ptlrpc_client
40  */
41 #include <linux/lustre_net.h>
42 #include <linux/obd.h>
43 /*
44  * struct obd_connect_data
45  * struct lustre_handle
46  */
47 #include <linux/lustre_idl.h>
48 #include <linux/md_object.h>
49 #include <linux/lustre_fid.h>
50
51 struct ptlrpc_service_conf {
52         int psc_nbufs;
53         int psc_bufsize;
54         int psc_max_req_size;
55         int psc_max_reply_size;
56         int psc_req_portal;
57         int psc_rep_portal;
58         int psc_watchdog_timeout; /* in ms */
59         int psc_num_threads;
60 };
61
62 struct mdt_device {
63         /* super-class */
64         struct md_device           mdt_md_dev;
65         struct ptlrpc_service     *mdt_service;
66         struct ptlrpc_service     *mdt_fld_service;
67         struct ptlrpc_service_conf mdt_service_conf;
68         /* DLM name-space for meta-data locks maintained by this server */
69         struct ldlm_namespace     *mdt_namespace;
70         /* ptlrpc handle for MDS->client connections (for lock ASTs). */
71         struct ptlrpc_client       mdt_ldlm_client;
72         /* underlying device */
73         struct md_device          *mdt_child;
74         /*
75          * Device flags, taken from enum mdt_flags. No locking (so far) is
76          * necessary.
77          */
78         unsigned long              mdt_flags;
79
80         /* Seq management related stuff */
81         struct lu_seq_mgr         *mdt_seq_mgr;
82 };
83
84 static inline struct md_device_operations *mdt_child_ops(struct mdt_device * m)
85 {
86         LASSERT(m->mdt_child);
87         return m->mdt_child->md_ops;
88 }
89
90 enum mdt_flags {
91         /*
92          * This mdt works with legacy clients with different resource name
93          * encoding (pre-fid, etc.).
94          */
95         MDT_CL_COMPAT_RESNAME = 1 << 0,
96 };
97
98 struct mdt_object {
99         struct lu_object_header mot_header;
100         struct md_object        mot_obj;
101 };
102
103 static inline struct md_object *mdt_object_child(struct mdt_object *o)
104 {
105         return lu2md(lu_object_next(&o->mot_obj.mo_lu));
106 }
107
108 static inline struct mdt_object *lu2mdt_obj(struct lu_object *o)
109 {
110         return (container_of(lu2md(o),struct mdt_object, mot_obj));
111 }
112
113 struct mdt_lock_handle {
114         struct lustre_handle    mlh_lh;
115         ldlm_mode_t             mlh_mode;
116 };
117
118 void mdt_lock_handle_init(struct mdt_lock_handle *lh);
119 void mdt_lock_handle_fini(struct mdt_lock_handle *lh);
120
121 int md_device_init(struct md_device *md, struct lu_device_type *t);
122 void md_device_fini(struct md_device *md);
123
124 enum {
125         MDT_REP_BUF_NR_MAX = 8
126 };
127
128 enum {
129         MDT_LH_PARENT,
130         MDT_LH_CHILD,
131         MDT_LH_NR
132 };
133
134 /*
135  * Common data shared by mdt-level handlers. This is allocated per-thread to
136  * reduce stack consumption.
137  */
138 struct mdt_thread_info {
139         struct lu_context     *mti_ctxt;
140         struct mdt_device     *mti_mdt;
141         /*
142          * number of buffers in reply message.
143          */
144         int                    mti_rep_buf_nr;
145         /*
146          * sizes of reply buffers.
147          */
148         int                    mti_rep_buf_size[MDT_REP_BUF_NR_MAX];
149         /*
150          * Body for "habeo corpus" operations.
151          */
152         struct mdt_body       *mti_body;
153         /*
154          * Lock request for "habeo clavis" operations.
155          */
156         struct ldlm_request   *mti_dlm_req;
157         /*
158          * Host object. This is released at the end of mdt_handler().
159          */
160         struct mdt_object     *mti_object;
161         /*
162          * Additional fail id that can be set by handler. Passed to
163          * target_send_reply().
164          */
165         int                    mti_fail_id;
166         /*
167          * A couple of lock handles.
168          */
169         struct mdt_lock_handle mti_lh[MDT_LH_NR];
170
171 };
172
173 int fid_lock(struct ldlm_namespace *, const struct lu_fid *,
174              struct lustre_handle *, ldlm_mode_t,
175              ldlm_policy_data_t *);
176
177 void fid_unlock(struct ldlm_namespace *, const struct lu_fid *,
178                 struct lustre_handle *, ldlm_mode_t);
179
180 struct mdt_object *mdt_object_find(struct lu_context *, struct mdt_device *,
181                                    struct lu_fid *);
182 void mdt_object_put(struct lu_context *ctxt, struct mdt_object *);
183
184 struct lu_fid *mdt_object_fid(struct mdt_object *);
185
186 int mdt_object_lock(struct ldlm_namespace *, struct mdt_object *,
187                     struct mdt_lock_handle *, __u64);
188
189 void mdt_object_unlock(struct ldlm_namespace *, struct mdt_object *,
190                        struct mdt_lock_handle *);
191
192 struct mdt_object *mdt_object_find_lock(struct lu_context *, struct mdt_device *,
193                                         struct lu_fid *,
194                                         struct mdt_lock_handle *, __u64);
195 #endif /* __KERNEL__ */
196 #endif /* _MDT_H */