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 static int __init fld_mod_init(void)
59 /* nothing to init seems */
63 static void __exit fld_mod_exit(void)
65 /* nothing to fini seems */
69 /* insert index entry and update cache */
70 int fld_server_create(struct lu_server_fld *fld,
71 const struct lu_context *ctx,
72 seqno_t seq, mdsno_t mds)
75 RETURN(fld_index_create(fld, ctx, seq, mds));
77 EXPORT_SYMBOL(fld_server_create);
79 /* delete index entry */
80 int fld_server_delete(struct lu_server_fld *fld,
81 const struct lu_context *ctx,
85 RETURN(fld_index_delete(fld, ctx, seq));
87 EXPORT_SYMBOL(fld_server_delete);
89 /* issue on-disk index lookup */
90 int fld_server_lookup(struct lu_server_fld *fld,
91 const struct lu_context *ctx,
92 seqno_t seq, mdsno_t *mds)
95 RETURN(fld_index_lookup(fld, ctx, seq, mds));
97 EXPORT_SYMBOL(fld_server_lookup);
99 static int fld_server_handle(struct lu_server_fld *fld,
100 const struct lu_context *ctx,
101 __u32 opc, struct md_fld *mf)
108 rc = fld_server_create(fld, ctx,
109 mf->mf_seq, mf->mf_mds);
112 rc = fld_server_delete(fld, ctx, mf->mf_seq);
115 rc = fld_server_lookup(fld, ctx,
116 mf->mf_seq, &mf->mf_mds);
126 static int fld_req_handle0(const struct lu_context *ctx,
127 struct lu_server_fld *fld,
128 struct ptlrpc_request *req)
130 int rep_buf_size[3] = { -1, -1 };
131 struct req_capsule pill;
138 req_capsule_init(&pill, req, RCL_SERVER, rep_buf_size);
140 req_capsule_set(&pill, &RQF_FLD_QUERY);
141 req_capsule_pack(&pill);
143 opc = req_capsule_client_get(&pill, &RMF_FLD_OPC);
145 in = req_capsule_client_get(&pill, &RMF_FLD_MDFLD);
147 CERROR("cannot unpack fld request\n");
148 GOTO(out_pill, rc = -EPROTO);
150 out = req_capsule_server_get(&pill, &RMF_FLD_MDFLD);
152 CERROR("cannot allocate fld response\n");
153 GOTO(out_pill, rc = -EPROTO);
156 rc = fld_server_handle(fld, ctx, *opc, out);
158 CERROR("cannot unpack FLD operation\n");
163 req_capsule_fini(&pill);
167 static int fld_req_handle(struct ptlrpc_request *req)
169 int fail = OBD_FAIL_FLD_ALL_REPLY_NET;
170 const struct lu_context *ctx;
171 struct lu_site *site;
175 OBD_FAIL_RETURN(OBD_FAIL_FLD_ALL_REPLY_NET | OBD_FAIL_ONCE, 0);
177 ctx = req->rq_svc_thread->t_ctx;
178 LASSERT(ctx != NULL);
179 LASSERT(ctx->lc_thread == req->rq_svc_thread);
180 if (req->rq_reqmsg->opc == FLD_QUERY) {
181 if (req->rq_export != NULL) {
182 site = req->rq_export->exp_obd->obd_lu_dev->ld_site;
183 LASSERT(site != NULL);
184 rc = fld_req_handle0(ctx, site->ls_server_fld, req);
186 CERROR("Unconnected request\n");
187 req->rq_status = -ENOTCONN;
188 GOTO(out, rc = -ENOTCONN);
191 CERROR("Wrong opcode: %d\n", req->rq_reqmsg->opc);
192 req->rq_status = -ENOTSUPP;
193 rc = ptlrpc_error(req);
199 target_send_reply(req, rc, fail);
204 * Returns true, if fid is local to this server node.
206 * WARNING: this function is *not* guaranteed to return false if fid is
207 * remote: it makes an educated conservative guess only.
209 * fid_is_local() is supposed to be used in assertion checks only.
211 int fid_is_local(struct lu_site *site, const struct lu_fid *fid)
215 result = 1; /* conservatively assume fid is local */
216 if (site->ls_client_fld != NULL) {
220 rc = fld_cache_lookup(site->ls_client_fld->fld_cache,
223 result = (mds == site->ls_node_id);
227 EXPORT_SYMBOL(fid_is_local);
230 static int fld_server_proc_init(struct lu_server_fld *fld)
235 fld->fld_proc_dir = lprocfs_register(fld->fld_name,
238 if (IS_ERR(fld->fld_proc_dir)) {
239 CERROR("LProcFS failed in fld-init\n");
240 rc = PTR_ERR(fld->fld_proc_dir);
244 fld->fld_proc_entry = lprocfs_register("services",
247 if (IS_ERR(fld->fld_proc_entry)) {
248 CERROR("LProcFS failed in fld-init\n");
249 rc = PTR_ERR(fld->fld_proc_entry);
253 rc = lprocfs_add_vars(fld->fld_proc_dir,
254 fld_server_proc_list, fld);
256 CERROR("can't init FLD proc, rc %d\n", rc);
263 lprocfs_remove(fld->fld_proc_entry);
265 lprocfs_remove(fld->fld_proc_dir);
267 fld->fld_proc_dir = NULL;
268 fld->fld_proc_entry = NULL;
272 static void fld_server_proc_fini(struct lu_server_fld *fld)
275 if (fld->fld_proc_entry) {
276 lprocfs_remove(fld->fld_proc_entry);
277 fld->fld_proc_entry = NULL;
280 if (fld->fld_proc_dir) {
281 lprocfs_remove(fld->fld_proc_dir);
282 fld->fld_proc_dir = NULL;
288 int fld_server_init(struct lu_server_fld *fld,
289 const struct lu_context *ctx,
290 struct dt_device *dt,
294 struct ptlrpc_service_conf fld_conf = {
295 .psc_nbufs = MDS_NBUFS,
296 .psc_bufsize = MDS_BUFSIZE,
297 .psc_max_req_size = FLD_MAXREQSIZE,
298 .psc_max_reply_size = FLD_MAXREPSIZE,
299 .psc_req_portal = FLD_REQUEST_PORTAL,
300 .psc_rep_portal = MDC_REPLY_PORTAL,
301 .psc_watchdog_timeout = FLD_SERVICE_WATCHDOG_TIMEOUT,
302 .psc_num_threads = FLD_NUM_THREADS,
303 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
308 lu_device_get(&dt->dd_lu_dev);
310 snprintf(fld->fld_name, sizeof(fld->fld_name),
311 "%s-srv-%s", LUSTRE_FLD_NAME, uuid);
313 rc = fld_index_init(fld, ctx);
318 rc = fld_server_proc_init(fld);
324 ptlrpc_init_svc_conf(&fld_conf, fld_req_handle,
326 fld->fld_proc_entry, NULL);
327 if (fld->fld_service != NULL)
328 rc = ptlrpc_start_threads(NULL, fld->fld_service,
336 fld_server_fini(fld, ctx);
338 CDEBUG(D_INFO|D_WARNING, "Server FLD\n");
341 EXPORT_SYMBOL(fld_server_init);
343 void fld_server_fini(struct lu_server_fld *fld,
344 const struct lu_context *ctx)
349 fld_server_proc_fini(fld);
352 if (fld->fld_service != NULL) {
353 ptlrpc_unregister_service(fld->fld_service);
354 fld->fld_service = NULL;
357 if (fld->fld_dt != NULL) {
358 lu_device_put(&fld->fld_dt->dd_lu_dev);
359 fld_index_fini(fld, ctx);
364 EXPORT_SYMBOL(fld_server_fini);
366 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
367 MODULE_DESCRIPTION("Lustre FLD");
368 MODULE_LICENSE("GPL");
370 cfs_module(mdd, "0.1.0", fld_mod_init, fld_mod_exit);