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>
35 #include <linux/obd_lmv.h>
37 #include "cm_internal.h"
39 static int cmobd_attach(struct obd_device *obd,
40 obd_count len, void *data)
42 struct lprocfs_static_vars lvars;
44 lprocfs_init_vars(cmobd, &lvars);
45 return lprocfs_obd_attach(obd, lvars.obd_vars);
48 static int cmobd_detach(struct obd_device *obd)
50 return lprocfs_obd_detach(obd);
53 static inline int cmobd_lmv_obd(struct obd_device *obd)
55 if (!strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) ||
56 !strcmp(obd->obd_type->typ_name, OBD_LMV_DEVICENAME))
62 static inline int cmobd_lov_obd(struct obd_device *obd)
64 if (!strcmp(obd->obd_type->typ_name, OBD_LOV_DEVICENAME))
70 static void cmobd_init_ea_size(struct obd_device *obd)
72 int ost_count = 1, easize, cookiesize;
73 struct cm_obd *cmobd = &obd->u.cm;
77 * here we should also take into account that there is possible to have
80 easize = lov_mds_md_size(ost_count);
81 cookiesize = ost_count * sizeof(struct llog_cookie);
83 obd_init_ea_size(cmobd->master_exp, easize, cookiesize);
85 cmobd->master_exp->exp_obd->u.cli.cl_max_mds_easize = easize;
86 cmobd->master_exp->exp_obd->u.cli.cl_max_mds_cookiesize = cookiesize;
91 static struct obd_device *
92 find_master_obd(struct obd_device *obd, struct obd_uuid *uuid)
94 struct obd_device *master;
96 CWARN("%s: looking for client obd %s\n",
97 obd->obd_uuid.uuid, uuid->uuid);
99 master = class_find_client_obd(NULL, OBD_LOV_DEVICENAME,
104 master = class_find_client_obd(NULL, OBD_LMV_DEVICENAME,
109 return class_find_client_obd(NULL, LUSTRE_MDC_NAME,
113 static int cmobd_setup(struct obd_device *obd, obd_count len, void *buf)
115 struct obd_uuid master_uuid, cache_uuid;
116 struct lustre_handle conn = { 0 };
117 struct cm_obd *cmobd = &obd->u.cm;
118 struct lustre_cfg* lcfg = buf;
119 struct lustre_id mid, lid;
124 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
125 CERROR("%s: setup requires master device uuid\n",
130 if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1) {
131 CERROR("%s: setup requires cache device uuid\n",
136 obd_str2uuid(&master_uuid, lustre_cfg_string(lcfg, 1));
137 obd_str2uuid(&cache_uuid, lustre_cfg_string(lcfg, 2));
139 /* getting master obd */
140 cmobd->master_obd = find_master_obd(obd, &master_uuid);
141 if (!cmobd->master_obd) {
142 CERROR("can't find master obd by uuid %s\n",
147 /* getting cache obd */
148 cmobd->cache_obd = class_uuid2obd(&cache_uuid);
149 if (cmobd->cache_obd == NULL) {
150 CERROR("CMOBD: unable to find obd by uuid: %s\n",
155 /* connecting master */
156 memset(&conn, 0, sizeof(conn));
157 rc = obd_connect(&conn, cmobd->master_obd, &obd->obd_uuid,
158 NULL, OBD_OPT_REAL_CLIENT);
161 cmobd->master_exp = class_conn2export(&conn);
163 /* connecting cache */
164 memset(&conn, 0, sizeof(conn));
165 rc = class_connect(&conn, cmobd->cache_obd, &obd->obd_uuid);
167 GOTO(put_master, rc);
168 cmobd->cache_exp = class_conn2export(&conn);
170 if (cmobd_lov_obd(cmobd->master_exp->exp_obd)) {
171 /* for master osc remove the recovery flag. */
172 rc = obd_set_info(cmobd->master_exp, strlen("unrecovery"),
173 "unrecovery", 0, NULL);
177 rc = cmobd_init_write_srv(obd);
181 cmobd_init_ea_size(obd);
182 cmobd->write_srv = NULL;
185 if (cmobd_lmv_obd(cmobd->master_exp->exp_obd)) {
187 * making sure, that both obds are ready. This is especially
188 * important in the case of using LMV as master.
190 rc = obd_getready(cmobd->master_exp);
192 CERROR("can't get %s obd ready.\n",
197 rc = obd_getready(cmobd->cache_exp);
199 CERROR("can't get %s obd ready.\n",
205 * requesting master obd to have its root inode store cookie to
206 * be able to save it to local root inode EA.
208 valsize = sizeof(struct lustre_id);
210 rc = obd_get_info(cmobd->master_exp, strlen("rootid"),
211 "rootid", &valsize, &mid);
213 CERROR("can't get rootid from master MDS %s, "
214 "err= %d.\n", master_uuid.uuid, rc);
219 * getting rootid from cache MDS. It is needed to update local
220 * (cache) root inode by rootid value from master obd.
222 rc = obd_get_info(cmobd->cache_exp, strlen("rootid"),
223 "rootid", &valsize, &lid);
225 CERROR("can't get rootid from local MDS %s, "
226 "err= %d.\n", cache_uuid.uuid, rc);
230 /* storing master MDS rootid to local root inode EA. */
231 CWARN("storing "DLID4" to local inode "DLID4".\n",
232 OLID4(&mid), OLID4(&lid));
234 rc = mds_update_mid(cmobd->cache_exp->exp_obd, &lid,
237 CERROR("can't update local root inode by ID "
238 "from master MDS %s, err = %d.\n",
239 master_uuid.uuid, rc);
246 class_disconnect(cmobd->cache_exp, 0);
248 obd_disconnect(cmobd->master_exp, 0);
252 static int cmobd_cleanup(struct obd_device *obd, int flags)
254 struct cm_obd *cmobd = &obd->u.cm;
258 if (cmobd->write_srv)
259 cmobd_cleanup_write_srv(obd);
261 rc = obd_disconnect(cmobd->master_exp, flags);
263 CERROR("error disconnecting master, err %d\n",
267 rc = class_disconnect(cmobd->cache_exp, flags);
269 CERROR("error disconnecting cache, err %d\n",
276 static int cmobd_iocontrol(unsigned int cmd, struct obd_export *exp,
277 int len, void *karg, void *uarg)
279 struct obd_device *obd = exp->exp_obd;
284 case OBD_IOC_CMOBD_SYNC: /* trigger reintegration */
285 rc = cmobd_reintegrate(obd);
288 CERROR("unrecognized ioctl %#x\n", cmd);
296 static struct obd_ops cmobd_ops = {
297 .o_owner = THIS_MODULE,
298 .o_attach = cmobd_attach,
299 .o_detach = cmobd_detach,
300 .o_setup = cmobd_setup,
301 .o_cleanup = cmobd_cleanup,
302 .o_iocontrol = cmobd_iocontrol,
305 kmem_cache_t *cmobd_extent_slab;
307 static int __init cmobd_init(void)
309 struct lprocfs_static_vars lvars;
313 printk(KERN_INFO "Lustre: Cache Manager OBD driver; info@clusterfs.com\n");
315 lprocfs_init_vars(cmobd, &lvars);
316 rc = class_register_type(&cmobd_ops, NULL, lvars.module_vars,
320 cmobd_extent_slab = kmem_cache_create("cmobd_extents",
321 sizeof(struct cmobd_extent_info), 0,
322 SLAB_HWCACHE_ALIGN, NULL, NULL);
323 if (cmobd_extent_slab == NULL) {
324 class_unregister_type(LUSTRE_CMOBD_NAME);
330 static void __exit cmobd_exit(void)
332 class_unregister_type(LUSTRE_CMOBD_NAME);
333 if (kmem_cache_destroy(cmobd_extent_slab) != 0)
334 CERROR("couldn't free cmobd extent slab\n");
337 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
338 MODULE_DESCRIPTION("Lustre Cache Manager OBD driver");
339 MODULE_LICENSE("GPL");
341 module_init(cmobd_init);
342 module_exit(cmobd_exit);