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] = { 0, };
131 struct req_capsule pill;
138 req_capsule_init(&pill, req, RCL_SERVER,
141 req_capsule_set(&pill, &RQF_FLD_QUERY);
142 req_capsule_pack(&pill);
144 opc = req_capsule_client_get(&pill, &RMF_FLD_OPC);
146 in = req_capsule_client_get(&pill, &RMF_FLD_MDFLD);
148 CERROR("cannot unpack fld request\n");
149 GOTO(out_pill, rc = -EPROTO);
151 out = req_capsule_server_get(&pill, &RMF_FLD_MDFLD);
153 CERROR("cannot allocate fld response\n");
154 GOTO(out_pill, rc = -EPROTO);
157 rc = fld_server_handle(fld, ctx, *opc, out);
159 CERROR("cannot unpack FLD operation\n");
164 req_capsule_fini(&pill);
168 static int fld_req_handle(struct ptlrpc_request *req)
170 int fail = OBD_FAIL_FLD_ALL_REPLY_NET;
171 const struct lu_context *ctx;
172 struct lu_site *site;
176 OBD_FAIL_RETURN(OBD_FAIL_FLD_ALL_REPLY_NET | OBD_FAIL_ONCE, 0);
178 ctx = req->rq_svc_thread->t_ctx;
179 LASSERT(ctx != NULL);
180 LASSERT(ctx->lc_thread == req->rq_svc_thread);
181 if (req->rq_reqmsg->opc == FLD_QUERY) {
182 if (req->rq_export != NULL) {
183 site = req->rq_export->exp_obd->obd_lu_dev->ld_site;
184 LASSERT(site != NULL);
185 rc = fld_req_handle0(ctx, site->ls_server_fld, req);
187 CERROR("Unconnected request\n");
188 req->rq_status = -ENOTCONN;
189 GOTO(out, rc = -ENOTCONN);
192 CERROR("Wrong opcode: %d\n", req->rq_reqmsg->opc);
193 req->rq_status = -ENOTSUPP;
194 rc = ptlrpc_error(req);
200 target_send_reply(req, rc, fail);
205 * Returns true, if fid is local to this server node.
207 * WARNING: this function is *not* guaranteed to return false if fid is
208 * remote: it makes an educated conservative guess only.
210 * fid_is_local() is supposed to be used in assertion checks only.
212 int fid_is_local(struct lu_site *site, const struct lu_fid *fid)
216 result = 1; /* conservatively assume fid is local */
217 if (site->ls_client_fld != NULL) {
221 rc = fld_cache_lookup(site->ls_client_fld->fld_cache,
224 result = (mds == site->ls_node_id);
228 EXPORT_SYMBOL(fid_is_local);
231 static int fld_server_proc_init(struct lu_server_fld *fld)
236 fld->fld_proc_dir = lprocfs_register(fld->fld_name,
239 if (IS_ERR(fld->fld_proc_dir)) {
240 CERROR("LProcFS failed in fld-init\n");
241 rc = PTR_ERR(fld->fld_proc_dir);
245 fld->fld_proc_entry = lprocfs_register("services",
248 if (IS_ERR(fld->fld_proc_entry)) {
249 CERROR("LProcFS failed in fld-init\n");
250 rc = PTR_ERR(fld->fld_proc_entry);
254 rc = lprocfs_add_vars(fld->fld_proc_dir,
255 fld_server_proc_list, fld);
257 CERROR("can't init FLD proc, rc %d\n", rc);
264 lprocfs_remove(fld->fld_proc_entry);
266 lprocfs_remove(fld->fld_proc_dir);
268 fld->fld_proc_dir = NULL;
269 fld->fld_proc_entry = NULL;
273 static void fld_server_proc_fini(struct lu_server_fld *fld)
276 if (fld->fld_proc_entry) {
277 lprocfs_remove(fld->fld_proc_entry);
278 fld->fld_proc_entry = NULL;
281 if (fld->fld_proc_dir) {
282 lprocfs_remove(fld->fld_proc_dir);
283 fld->fld_proc_dir = NULL;
289 int fld_server_init(struct lu_server_fld *fld,
290 const struct lu_context *ctx,
291 struct dt_device *dt,
295 struct ptlrpc_service_conf fld_conf = {
296 .psc_nbufs = MDS_NBUFS,
297 .psc_bufsize = MDS_BUFSIZE,
298 .psc_max_req_size = FLD_MAXREQSIZE,
299 .psc_max_reply_size = FLD_MAXREPSIZE,
300 .psc_req_portal = FLD_REQUEST_PORTAL,
301 .psc_rep_portal = MDC_REPLY_PORTAL,
302 .psc_watchdog_timeout = FLD_SERVICE_WATCHDOG_TIMEOUT,
303 .psc_num_threads = FLD_NUM_THREADS,
304 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
309 lu_device_get(&dt->dd_lu_dev);
311 snprintf(fld->fld_name, sizeof(fld->fld_name),
312 "%s-srv-%s", LUSTRE_FLD_NAME, uuid);
314 rc = fld_index_init(fld, ctx);
319 rc = fld_server_proc_init(fld);
325 ptlrpc_init_svc_conf(&fld_conf, fld_req_handle,
327 fld->fld_proc_entry, NULL);
328 if (fld->fld_service != NULL)
329 rc = ptlrpc_start_threads(NULL, fld->fld_service,
337 fld_server_fini(fld, ctx);
339 CDEBUG(D_INFO|D_WARNING, "Server FLD\n");
342 EXPORT_SYMBOL(fld_server_init);
344 void fld_server_fini(struct lu_server_fld *fld,
345 const struct lu_context *ctx)
350 fld_server_proc_fini(fld);
353 if (fld->fld_service != NULL) {
354 ptlrpc_unregister_service(fld->fld_service);
355 fld->fld_service = NULL;
358 if (fld->fld_dt != NULL) {
359 lu_device_put(&fld->fld_dt->dd_lu_dev);
360 fld_index_fini(fld, ctx);
365 EXPORT_SYMBOL(fld_server_fini);
367 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
368 MODULE_DESCRIPTION("Lustre FLD");
369 MODULE_LICENSE("GPL");
371 cfs_module(mdd, "0.1.0", fld_mod_init, fld_mod_exit);