1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2002 Cluster File Systems, Inc. <info@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #define DEBUG_SUBSYSTEM S_CMOBD
24 #include <linux/version.h>
25 #include <linux/init.h>
26 #include <linux/obd_support.h>
27 #include <linux/lustre_lib.h>
28 #include <linux/lustre_net.h>
29 #include <linux/lustre_idl.h>
30 #include <linux/obd_class.h>
31 #include <linux/lustre_mds.h>
32 #include <linux/lustre_cmobd.h>
33 #include <linux/lprocfs_status.h>
34 #include <linux/obd_lov.h>
36 #include "cmobd_internal.h"
38 static int cmobd_attach(struct obd_device *obd, obd_count len, void *data)
40 struct lprocfs_static_vars lvars;
42 lprocfs_init_vars(cmobd, &lvars);
43 return lprocfs_obd_attach(obd, lvars.obd_vars);
46 static int cmobd_detach(struct obd_device *obd)
48 return lprocfs_obd_detach(obd);
51 static void cmobd_find_master_client_obd(struct obd_device *obd,
52 struct obd_uuid *uuid)
54 struct cache_manager_obd *cmobd = &obd->u.cmobd;
56 cmobd->cm_master_obd = class_find_client_obd(NULL, OBD_LOV_DEVICENAME,
58 if (cmobd->cm_master_obd == NULL)
59 cmobd->cm_master_obd = class_find_client_obd(NULL,
64 static int cmobd_setup(struct obd_device *obd, obd_count len, void *buf)
66 struct cache_manager_obd *cmobd = &obd->u.cmobd;
67 struct lustre_cfg* lcfg = buf;
68 struct obd_uuid master_uuid, cache_uuid;
69 struct lustre_handle conn = { 0 };
73 if (lcfg->lcfg_inllen1 < 1 || !lcfg->lcfg_inlbuf1) {
74 CERROR("CMOBD setup requires master uuid\n");
77 if (lcfg->lcfg_inllen2 < 1 || !lcfg->lcfg_inlbuf2) {
78 CERROR("CMOBD setup requires cache uuid\n");
82 obd_str2uuid(&master_uuid, lcfg->lcfg_inlbuf1);
83 obd_str2uuid(&cache_uuid, lcfg->lcfg_inlbuf2);
85 cmobd_find_master_client_obd(obd, &master_uuid);
86 if (cmobd->cm_master_obd == NULL) {
87 CERROR("Can't find master obd %s\n", &master_uuid.uuid[0]);
90 cmobd->cm_cache_obd = class_uuid2obd(&cache_uuid);
91 if (cmobd->cm_cache_obd == NULL) {
92 CERROR("Can't find cache obd %s\n", &cache_uuid.uuid[0]);
96 /* master lov connects to master ost here */
97 rc = obd_connect(&conn, cmobd->cm_master_obd, &obd->obd_uuid);
100 cmobd->cm_master_exp = class_conn2export(&conn);
102 memset(&conn, 0, sizeof(conn));
103 rc = class_connect(&conn, cmobd->cm_cache_obd, &obd->obd_uuid);
105 GOTO(put_master, rc);
106 cmobd->cm_cache_exp = class_conn2export(&conn);
107 if (!strcmp(cmobd->cm_master_obd->obd_type->typ_name,
108 OBD_LOV_DEVICENAME)){
109 /* for master osc remove the recovery flag of oscc */
110 rc = obd_set_info(cmobd->cm_master_exp, strlen("unrecovery"),
111 "unrecovery", 0, NULL);
113 GOTO(put_master, rc);
115 rc = cmobd_init_write_srv(obd);
120 /*FIXME later temp fix here
121 *Assumation:cache mds only have one ost*/
122 cmobd->cm_master_obd->u.cli.cl_max_mds_easize =
125 /* start n threads for write replay */
128 class_disconnect(cmobd->cm_cache_exp, 0);
130 obd_disconnect(cmobd->cm_master_exp, 0);
134 static int cmobd_cleanup(struct obd_device *obd, int flags)
136 struct cache_manager_obd *cmobd = &obd->u.cmobd;
139 if (!strcmp(cmobd->cm_master_obd->obd_type->typ_name,
140 OBD_LOV_DEVICENAME)) {
141 cmobd_cleanup_write_srv(obd);
143 class_disconnect(cmobd->cm_cache_exp, 0);
144 obd_disconnect(cmobd->cm_master_exp, 0);
149 static int cmobd_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
150 void *karg, void *uarg)
152 struct obd_device *obd = exp->exp_obd;
157 case OBD_IOC_CMOBD_SYNC: /* trigger reintegration */
158 rc = cmobd_reintegrate(obd);
161 CERROR("unrecognized ioctl %#x\n", cmd);
169 static struct obd_ops cmobd_ops = {
170 o_owner: THIS_MODULE,
171 o_attach: cmobd_attach,
172 o_detach: cmobd_detach,
173 o_setup: cmobd_setup,
174 o_cleanup: cmobd_cleanup,
175 o_iocontrol: cmobd_iocontrol,
178 kmem_cache_t *cmobd_extent_slab;
180 static int __init cmobd_init(void)
182 struct lprocfs_static_vars lvars;
186 printk(KERN_INFO "Lustre: Cache Manager OBD driver; info@clusterfs.com\n");
188 lprocfs_init_vars(cmobd, &lvars);
189 rc = class_register_type(&cmobd_ops, NULL, lvars.module_vars,
193 cmobd_extent_slab = kmem_cache_create("cmobd_extents",
194 sizeof(struct cmobd_extent_info), 0,
195 SLAB_HWCACHE_ALIGN, NULL, NULL);
196 if (cmobd_extent_slab == NULL) {
197 class_unregister_type(LUSTRE_CMOBD_NAME);
203 static void /*__exit*/ cmobd_exit(void)
205 class_unregister_type(LUSTRE_CMOBD_NAME);
206 if (kmem_cache_destroy(cmobd_extent_slab) != 0)
207 CERROR("couldn't free cmobd extent slab\n");
210 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
211 MODULE_DESCRIPTION("Lustre Cache Manager OBD driver");
212 MODULE_LICENSE("GPL");
214 module_init(cmobd_init);
215 module_exit(cmobd_exit);