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_ost.h>
36 #include <linux/obd_lmv.h>
38 #include "cm_internal.h"
40 static int cmobd_attach(struct obd_device *obd,
41 obd_count len, void *data)
43 struct lprocfs_static_vars lvars;
45 lprocfs_init_vars(cmobd, &lvars);
46 return lprocfs_obd_attach(obd, lvars.obd_vars);
49 static int cmobd_detach(struct obd_device *obd)
51 return lprocfs_obd_detach(obd);
54 static inline int cmobd_md_obd(struct obd_device *obd)
56 if (!strcmp(obd->obd_type->typ_name, OBD_MDC_DEVICENAME) ||
57 !strcmp(obd->obd_type->typ_name, OBD_LMV_DEVICENAME))
63 static inline int cmobd_dt_obd(struct obd_device *obd)
65 if (!strcmp(obd->obd_type->typ_name, OBD_LOV_DEVICENAME) ||
66 !strcmp(obd->obd_type->typ_name, OBD_OSC_DEVICENAME))
72 static void cmobd_init_ea_size(struct obd_device *obd)
74 int ost_count = 1, easize, cookiesize;
75 struct cm_obd *cmobd = &obd->u.cm;
79 * here we should also take into account that there is possible to have
82 easize = lov_mds_md_size(ost_count);
83 cookiesize = ost_count * sizeof(struct llog_cookie);
85 obd_init_ea_size(cmobd->master_exp, easize, cookiesize);
87 cmobd->master_exp->exp_obd->u.cli.cl_max_mds_easize = easize;
88 cmobd->master_exp->exp_obd->u.cli.cl_max_mds_cookiesize = cookiesize;
93 static char *types[] = {
94 OBD_LMV_DEVICENAME, OBD_MDC_DEVICENAME,
95 OBD_LOV_DEVICENAME, OBD_OSC_DEVICENAME
98 static struct obd_device *
99 cmobd_find_obd(struct obd_device *obd, struct obd_uuid *uuid)
101 struct obd_device *res;
105 CWARN("%s: looking for client obd %s\n",
106 obd->obd_uuid.uuid, uuid->uuid);
108 for (i = 0; i < sizeof(types); i++) {
109 res = class_find_client_obd(NULL, types[i],
117 static int cmobd_setup(struct obd_device *obd, obd_count len, void *buf)
119 struct obd_uuid master_uuid, cache_uuid;
120 struct lustre_handle conn = { 0 };
121 struct cm_obd *cmobd = &obd->u.cm;
122 struct lustre_cfg* lcfg = buf;
123 struct lustre_id mid, lid;
128 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
129 CERROR("%s: setup requires master device uuid\n",
134 if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1) {
135 CERROR("%s: setup requires cache device uuid\n",
140 obd_str2uuid(&master_uuid, lustre_cfg_string(lcfg, 1));
141 obd_str2uuid(&cache_uuid, lustre_cfg_string(lcfg, 2));
143 /* getting master obd */
144 cmobd->master_obd = cmobd_find_obd(obd, &master_uuid);
145 if (!cmobd->master_obd) {
146 CERROR("can't find master client obd by uuid %s\n",
151 /* getting cache obd */
152 cmobd->cache_obd = class_uuid2obd(&cache_uuid);
153 if (cmobd->cache_obd == NULL) {
154 CERROR("CMOBD: unable to find obd by uuid: %s\n",
159 /* connecting master */
160 memset(&conn, 0, sizeof(conn));
161 rc = obd_connect(&conn, cmobd->master_obd, &obd->obd_uuid,
162 NULL, OBD_OPT_REAL_CLIENT);
165 cmobd->master_exp = class_conn2export(&conn);
167 /* connecting cache */
168 memset(&conn, 0, sizeof(conn));
169 rc = class_connect(&conn, cmobd->cache_obd, &obd->obd_uuid);
171 GOTO(put_master, rc);
172 cmobd->cache_exp = class_conn2export(&conn);
174 if (cmobd_dt_obd(cmobd->master_exp->exp_obd)) {
175 /* for master dt device remove the recovery flag. */
176 rc = obd_set_info(cmobd->master_exp, strlen("unrecovery"),
177 "unrecovery", 0, NULL);
181 rc = cmobd_init_write_srv(obd);
185 cmobd_init_ea_size(obd);
186 cmobd->write_srv = NULL;
189 if (cmobd_md_obd(cmobd->master_exp->exp_obd)) {
191 * making sure, that both obds are ready. This is especially
192 * important in the case of using LMV as master.
194 rc = obd_getready(cmobd->master_exp);
196 CERROR("can't get %s obd ready.\n",
201 rc = obd_getready(cmobd->cache_exp);
203 CERROR("can't get %s obd ready.\n",
209 * requesting master obd to have its root inode store cookie to
210 * be able to save it to local root inode EA.
212 valsize = sizeof(struct lustre_id);
214 rc = obd_get_info(cmobd->master_exp, strlen("rootid"),
215 "rootid", &valsize, &mid);
217 CERROR("can't get rootid from master MDS %s, "
218 "err= %d.\n", master_uuid.uuid, rc);
223 * getting rootid from cache MDS. It is needed to update local
224 * (cache) root inode by rootid value from master obd.
226 rc = obd_get_info(cmobd->cache_exp, strlen("rootid"),
227 "rootid", &valsize, &lid);
229 CERROR("can't get rootid from local MDS %s, "
230 "err= %d.\n", cache_uuid.uuid, rc);
234 /* storing master MDS rootid to local root inode EA. */
235 CWARN("storing "DLID4" to local inode "DLID4".\n",
236 OLID4(&mid), OLID4(&lid));
238 rc = mds_update_mid(cmobd->cache_exp->exp_obd, &lid,
241 CERROR("can't update local root inode by ID "
242 "from master MDS %s, err = %d.\n",
243 master_uuid.uuid, rc);
250 class_disconnect(cmobd->cache_exp, 0);
252 obd_disconnect(cmobd->master_exp, 0);
256 static int cmobd_cleanup(struct obd_device *obd, int flags)
258 struct cm_obd *cmobd = &obd->u.cm;
262 if (cmobd->write_srv)
263 cmobd_cleanup_write_srv(obd);
265 rc = obd_disconnect(cmobd->master_exp, flags);
267 CERROR("error disconnecting master, err %d\n",
271 rc = class_disconnect(cmobd->cache_exp, flags);
273 CERROR("error disconnecting cache, err %d\n",
280 static int cmobd_iocontrol(unsigned int cmd, struct obd_export *exp,
281 int len, void *karg, void *uarg)
283 struct obd_device *obd = exp->exp_obd;
288 case OBD_IOC_CMOBD_SYNC: /* trigger reintegration */
289 rc = cmobd_reintegrate(obd);
292 CERROR("unrecognized ioctl %#x\n", cmd);
300 static struct obd_ops cmobd_ops = {
301 .o_owner = THIS_MODULE,
302 .o_attach = cmobd_attach,
303 .o_detach = cmobd_detach,
304 .o_setup = cmobd_setup,
305 .o_cleanup = cmobd_cleanup,
306 .o_iocontrol = cmobd_iocontrol,
309 kmem_cache_t *cmobd_extent_slab;
311 static int __init cmobd_init(void)
313 struct lprocfs_static_vars lvars;
317 printk(KERN_INFO "Lustre: Cache Manager OBD driver; info@clusterfs.com\n");
319 lprocfs_init_vars(cmobd, &lvars);
320 rc = class_register_type(&cmobd_ops, NULL, lvars.module_vars,
321 OBD_CMOBD_DEVICENAME);
324 cmobd_extent_slab = kmem_cache_create("cmobd_extents",
325 sizeof(struct cmobd_extent_info), 0,
326 SLAB_HWCACHE_ALIGN, NULL, NULL);
327 if (cmobd_extent_slab == NULL) {
328 class_unregister_type(OBD_CMOBD_DEVICENAME);
334 static void __exit cmobd_exit(void)
336 class_unregister_type(OBD_CMOBD_DEVICENAME);
337 if (kmem_cache_destroy(cmobd_extent_slab) != 0)
338 CERROR("couldn't free cmobd extent slab\n");
341 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
342 MODULE_DESCRIPTION("Lustre Cache Manager OBD driver");
343 MODULE_LICENSE("GPL");
345 module_init(cmobd_init);
346 module_exit(cmobd_exit);