1 /* -*- MODE: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/fld/fld_handler.c
5 * FLD (Fids Location Database)
7 * Copyright (C) 2006 Cluster File Systems, Inc.
8 * Author: WangDi <wangdi@clusterfs.com>
9 * Yury Umanets <umka@clusterfs.com>
11 * This file is part of the Lustre file system, http://www.lustre.org
12 * Lustre is a trademark of Cluster File Systems, Inc.
14 * You may have signed or agreed to another license before downloading
15 * this software. If so, you are bound by the terms and conditions
16 * of that agreement, and the following does not apply to you. See the
17 * LICENSE file included with this distribution for more information.
19 * If you did not agree to a different license, then this copy of Lustre
20 * is open source software; you can redistribute it and/or modify it
21 * under the terms of version 2 of the GNU General Public License as
22 * published by the Free Software Foundation.
24 * In either case, Lustre is distributed in the hope that it will be
25 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
26 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * license text for more details.
30 # define EXPORT_SYMTAB
32 #define DEBUG_SUBSYSTEM S_FLD
35 # include <libcfs/libcfs.h>
36 # include <linux/module.h>
37 # include <linux/jbd.h>
38 # include <asm/div64.h>
39 #else /* __KERNEL__ */
40 # include <liblustre.h>
41 # include <libcfs/list.h>
45 #include <obd_class.h>
46 #include <lustre_ver.h>
47 #include <obd_support.h>
48 #include <lprocfs_status.h>
50 #include <dt_object.h>
51 #include <md_object.h>
52 #include <lustre_req_layout.h>
53 #include <lustre_fld.h>
54 #include "fld_internal.h"
57 struct fld_cache_info *fld_cache = NULL;
59 static int fld_init(void)
64 fld_cache = fld_cache_init(FLD_HTABLE_SIZE);
65 if (IS_ERR(fld_cache))
66 rc = PTR_ERR(fld_cache);
74 static void fld_fini(void)
77 if (fld_cache != NULL) {
78 fld_cache_fini(fld_cache);
84 static int __init fld_mod_init(void)
90 static void __exit fld_mod_exit(void)
96 /* insert index entry and update cache */
98 fld_server_create(struct lu_server_fld *fld,
99 const struct lu_context *ctx,
100 __u64 seq, mdsno_t mds)
105 rc = fld_index_create(fld, ctx, seq, mds);
107 /* do not return result of calling fld_cache_insert()
108 * here. First of all because it may return -EEXISTS. Another
109 * reason is that, we do not want to stop proceeding because of
110 * cache errors. --umka */
111 fld_cache_insert(fld_cache, seq, mds);
116 /* delete index entry and update cache */
118 fld_server_delete(struct lu_server_fld *fld,
119 const struct lu_context *ctx,
123 fld_cache_delete(fld_cache, seq);
124 RETURN(fld_index_delete(fld, ctx, seq));
127 /* lookup in cache first and then issue index lookup */
129 fld_server_lookup(struct lu_server_fld *fld,
130 const struct lu_context *ctx,
131 __u64 seq, mdsno_t *mds)
133 struct fld_cache_entry *flde;
137 /* lookup it in the cache first */
138 flde = fld_cache_lookup(fld_cache, seq);
140 *mds = flde->fce_mds;
144 rc = fld_index_lookup(fld, ctx, seq, mds);
149 fld_server_handle(struct lu_server_fld *fld,
150 const struct lu_context *ctx,
151 __u32 opc, struct md_fld *mf)
158 rc = fld_server_create(fld, ctx,
159 mf->mf_seq, mf->mf_mds);
162 rc = fld_server_delete(fld, ctx, mf->mf_seq);
165 rc = fld_server_lookup(fld, ctx,
166 mf->mf_seq, &mf->mf_mds);
177 fld_req_handle0(const struct lu_context *ctx,
178 struct lu_server_fld *fld,
179 struct ptlrpc_request *req)
181 int rep_buf_size[3] = { 0, };
182 struct req_capsule pill;
189 req_capsule_init(&pill, req, RCL_SERVER,
192 req_capsule_set(&pill, &RQF_FLD_QUERY);
193 req_capsule_pack(&pill);
195 opc = req_capsule_client_get(&pill, &RMF_FLD_OPC);
197 in = req_capsule_client_get(&pill, &RMF_FLD_MDFLD);
199 CERROR("cannot unpack fld request\n");
200 GOTO(out_pill, rc = -EPROTO);
202 out = req_capsule_server_get(&pill, &RMF_FLD_MDFLD);
204 CERROR("cannot allocate fld response\n");
205 GOTO(out_pill, rc = -EPROTO);
208 rc = fld_server_handle(fld, ctx, *opc, out);
210 CERROR("cannot unpack FLD operation\n");
215 req_capsule_fini(&pill);
219 static int fld_req_handle(struct ptlrpc_request *req)
221 int fail = OBD_FAIL_FLD_ALL_REPLY_NET;
222 const struct lu_context *ctx;
223 struct lu_site *site;
227 OBD_FAIL_RETURN(OBD_FAIL_FLD_ALL_REPLY_NET | OBD_FAIL_ONCE, 0);
229 ctx = req->rq_svc_thread->t_ctx;
230 LASSERT(ctx != NULL);
231 LASSERT(ctx->lc_thread == req->rq_svc_thread);
232 if (req->rq_reqmsg->opc == FLD_QUERY) {
233 if (req->rq_export != NULL) {
234 site = req->rq_export->exp_obd->obd_lu_dev->ld_site;
235 LASSERT(site != NULL);
236 rc = fld_req_handle0(ctx, site->ls_fld, req);
238 CERROR("Unconnected request\n");
239 req->rq_status = -ENOTCONN;
240 GOTO(out, rc = -ENOTCONN);
243 CERROR("Wrong opcode: %d\n", req->rq_reqmsg->opc);
244 req->rq_status = -ENOTSUPP;
245 rc = ptlrpc_error(req);
251 target_send_reply(req, rc, fail);
257 fld_server_proc_init(struct lu_server_fld *fld)
262 fld->fld_proc_dir = lprocfs_register(fld->fld_name,
265 if (IS_ERR(fld->fld_proc_dir)) {
266 CERROR("LProcFS failed in fld-init\n");
267 rc = PTR_ERR(fld->fld_proc_dir);
271 fld->fld_proc_entry = lprocfs_register("services",
274 if (IS_ERR(fld->fld_proc_entry)) {
275 CERROR("LProcFS failed in fld-init\n");
276 rc = PTR_ERR(fld->fld_proc_entry);
280 rc = lprocfs_add_vars(fld->fld_proc_dir,
281 fld_server_proc_list, fld);
283 CERROR("can't init FLD proc, rc %d\n", rc);
290 lprocfs_remove(fld->fld_proc_dir);
292 fld->fld_proc_dir = NULL;
293 fld->fld_proc_entry = NULL;
298 fld_server_proc_fini(struct lu_server_fld *fld)
301 if (fld->fld_proc_entry) {
302 lprocfs_remove(fld->fld_proc_entry);
303 fld->fld_proc_entry = NULL;
306 if (fld->fld_proc_dir) {
307 lprocfs_remove(fld->fld_proc_dir);
308 fld->fld_proc_dir = NULL;
315 fld_server_init(struct lu_server_fld *fld,
316 const struct lu_context *ctx,
318 struct dt_device *dt)
321 struct ptlrpc_service_conf fld_conf = {
322 .psc_nbufs = MDS_NBUFS,
323 .psc_bufsize = MDS_BUFSIZE,
324 .psc_max_req_size = MDS_MAXREQSIZE,
325 .psc_max_reply_size = MDS_MAXREPSIZE,
326 .psc_req_portal = FLD_REQUEST_PORTAL,
327 .psc_rep_portal = MDC_REPLY_PORTAL,
328 .psc_watchdog_timeout = FLD_SERVICE_WATCHDOG_TIMEOUT,
329 .psc_num_threads = FLD_NUM_THREADS
334 lu_device_get(&dt->dd_lu_dev);
336 snprintf(fld->fld_name, sizeof(fld->fld_name),
337 "%s-%s", LUSTRE_FLD_NAME, uuid);
339 rc = fld_index_init(fld, ctx);
344 rc = fld_server_proc_init(fld);
350 ptlrpc_init_svc_conf(&fld_conf, fld_req_handle,
352 fld->fld_proc_entry, NULL);
353 if (fld->fld_service != NULL)
354 rc = ptlrpc_start_threads(NULL, fld->fld_service,
362 fld_server_fini(fld, ctx);
364 CDEBUG(D_INFO|D_WARNING, "Server FLD\n");
367 EXPORT_SYMBOL(fld_server_init);
370 fld_server_fini(struct lu_server_fld *fld,
371 const struct lu_context *ctx)
376 fld_server_proc_fini(fld);
379 if (fld->fld_service != NULL) {
380 ptlrpc_unregister_service(fld->fld_service);
381 fld->fld_service = NULL;
384 if (fld->fld_dt != NULL) {
385 lu_device_put(&fld->fld_dt->dd_lu_dev);
386 fld_index_fini(fld, ctx);
389 CDEBUG(D_INFO|D_WARNING, "Server FLD\n");
392 EXPORT_SYMBOL(fld_server_fini);
394 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
395 MODULE_DESCRIPTION("Lustre FLD");
396 MODULE_LICENSE("GPL");
398 cfs_module(mdd, "0.0.4", fld_mod_init, fld_mod_exit);