1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre Light common routines
6 * Copyright (c) 2002-2004 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <sys/types.h>
30 #include <sys/queue.h>
43 /* both sys/queue.h (libsysio require it) and portals/lists.h have definition
44 * of 'LIST_HEAD'. undef it to suppress warnings
47 #include <lnet/lnetctl.h> /* needed for parse_dump */
50 #include "llite_lib.h"
51 #include <linux/lustre_ver.h>
53 static int lllib_init(void)
55 if (liblustre_init_current("liblustre") ||
64 return _sysio_fssw_register("llite", &llu_fssw_ops);
67 int liblustre_process_log(struct config_llog_instance *cfg,
68 char *mdsnid, char *mdsname, char *profile,
71 struct lustre_cfg_bufs bufs;
72 struct lustre_cfg *lcfg;
73 char *peer = "MDS_PEER_UUID";
74 struct obd_device *obd;
75 struct lustre_handle mdc_conn = {0, };
76 struct obd_export *exp;
77 char *name = "mdc_dev";
79 struct obd_uuid mdc_uuid;
80 struct llog_ctxt *ctxt;
83 struct obd_connect_data *ocd = NULL;
86 generate_random_uuid(uuid);
87 class_uuid_unparse(uuid, &mdc_uuid);
89 nid = libcfs_str2nid(mdsnid);
90 if (nid == LNET_NID_ANY) {
91 CERROR("Can't parse NID %s\n", mdsnid);
95 lustre_cfg_bufs_reset(&bufs, NULL);
96 lustre_cfg_bufs_set_string(&bufs, 1, peer);
97 lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs);
99 rc = class_process_config(lcfg);
100 lustre_cfg_free(lcfg);
104 lustre_cfg_bufs_reset(&bufs, name);
105 lustre_cfg_bufs_set_string(&bufs, 1, LUSTRE_MDC_NAME);//FIXME connect to mgc
106 lustre_cfg_bufs_set_string(&bufs, 2, mdc_uuid.uuid);
107 lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
108 rc = class_process_config(lcfg);
109 lustre_cfg_free(lcfg);
111 GOTO(out_del_uuid, rc);
113 lustre_cfg_bufs_reset(&bufs, name);
114 lustre_cfg_bufs_set_string(&bufs, 1, mdsname);
115 lustre_cfg_bufs_set_string(&bufs, 2, peer);
116 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
117 rc = class_process_config(lcfg);
118 lustre_cfg_free(lcfg);
120 GOTO(out_detach, rc);
122 obd = class_name2obd(name);
124 GOTO(out_cleanup, rc = -EINVAL);
126 OBD_ALLOC(ocd, sizeof(*ocd));
128 GOTO(out_cleanup, rc = -ENOMEM);
130 ocd->ocd_version = LUSTRE_VERSION_CODE;
132 /* Disable initial recovery on this import */
133 rc = obd_set_info(obd->obd_self_export,
134 strlen(KEY_INIT_RECOV), KEY_INIT_RECOV,
135 sizeof(allow_recov), &allow_recov);
137 rc = obd_connect(&mdc_conn, obd, &mdc_uuid, ocd);
139 CERROR("cannot connect to %s: rc = %d\n", mdsname, rc);
140 GOTO(out_cleanup, rc);
143 exp = class_conn2export(&mdc_conn);
145 ctxt = exp->exp_obd->obd_llog_ctxt[LLOG_CONFIG_REPL_CTXT];
146 rc = class_config_parse_llog(ctxt, profile, cfg);
148 CERROR("class_config_parse_llog failed: rc = %d\n", rc);
151 /* We don't so much care about errors in cleaning up the config llog
152 * connection, as we have already read the config by this point. */
153 err = obd_disconnect(exp);
155 CERROR("obd_disconnect failed: rc = %d\n", err);
159 OBD_FREE(ocd, sizeof(*ocd));
161 lustre_cfg_bufs_reset(&bufs, name);
162 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
163 err = class_process_config(lcfg);
164 lustre_cfg_free(lcfg);
166 CERROR("mdc_cleanup failed: rc = %d\n", err);
169 lustre_cfg_bufs_reset(&bufs, name);
170 lcfg = lustre_cfg_new(LCFG_DETACH, &bufs);
171 err = class_process_config(lcfg);
172 lustre_cfg_free(lcfg);
174 CERROR("mdc_detach failed: rc = %d\n", err);
177 lustre_cfg_bufs_reset(&bufs, name);
178 lustre_cfg_bufs_set_string(&bufs, 1, peer);
179 lcfg = lustre_cfg_new(LCFG_DEL_UUID, &bufs);
180 err = class_process_config(lcfg);
182 CERROR("del MDC UUID failed: rc = %d\n", err);
183 lustre_cfg_free(lcfg);
189 /* parse host:/mdsname/profile string */
190 int ll_parse_mount_target(const char *target, char **mdsnid,
191 char **mdsname, char **profile)
193 static char buf[256];
197 strncpy(buf, target, 255);
199 if ((s = strchr(buf, ':'))) {
206 if ((s = strchr(*mdsname, '/'))) {
217 * early liblustre init
218 * called from C startup in catamount apps, before main()
220 * The following is a skeleton sysio startup sequence,
221 * as implemented in C startup (skipping error handling).
222 * In this framework none of these calls need be made here
223 * or in the apps themselves. The NAMESPACE_STRING specifying
224 * the initial set of fs ops (creates, mounts, etc.) is passed
225 * as an environment variable.
228 * _sysio_incore_init();
229 * _sysio_native_init();
230 * _sysio_lustre_init();
231 * _sysio_boot(NAMESPACE_STRING);
233 * the name _sysio_lustre_init() follows the naming convention
234 * established in other fs drivers from libsysio:
235 * _sysio_incore_init(), _sysio_native_init()
237 * _sysio_lustre_init() must be called before _sysio_boot()
238 * to enable libsysio's processing of namespace init strings containing
239 * lustre filesystem operations
241 int _sysio_lustre_init(void)
244 char *timeout = NULL;
245 char *debug_mask = NULL;
246 char *debug_subsys = NULL;
248 extern void __liblustre_cleanup_(void);
253 libcfs_subsystem_debug = -1;
256 liblustre_init_random();
260 perror("init llite driver");
263 timeout = getenv("LIBLUSTRE_TIMEOUT");
265 obd_timeout = (unsigned int) strtol(timeout, NULL, 0);
266 printf("LibLustre: set obd timeout as %u seconds\n",
271 debug_mask = getenv("LIBLUSTRE_DEBUG_MASK");
273 libcfs_debug = (unsigned int) strtol(debug_mask, NULL, 0);
275 debug_subsys = getenv("LIBLUSTRE_DEBUG_SUBSYS");
277 libcfs_subsystem_debug =
278 (unsigned int) strtol(debug_subsys, NULL, 0);
281 (void)atexit(__liblustre_cleanup_);
286 extern int _sysio_native_init();
287 extern unsigned int obd_timeout;
289 char *lustre_path = NULL;
291 void __liblustre_setup_(void)
294 char *root_driver = "native";
295 char *lustre_driver = "llite";
296 char *root_path = "/";
297 unsigned mntflgs = 0;
300 lustre_path = getenv("LIBLUSTRE_MOUNT_POINT");
302 lustre_path = "/mnt/lustre";
306 target = getenv("LIBLUSTRE_MOUNT_TARGET");
308 printf("LibLustre: no mount target specified\n");
311 printf("LibLustre: mount point %s, target %s\n",
312 lustre_path, target);
316 /* initialize libsysio & mount rootfs */
318 perror("init sysio");
321 _sysio_native_init();
323 err = _sysio_mount_root(root_path, root_driver, mntflgs, NULL);
325 fprintf(stderr, "sysio mount failed: %s\n", strerror(errno));
329 if (_sysio_lustre_init())
331 #endif /* INIT_SYSIO */
333 err = mount(target, lustre_path, lustre_driver, mntflgs, NULL);
335 fprintf(stderr, "Lustre mount failed: %s\n", strerror(errno));
340 void __liblustre_cleanup_(void)
343 /* guard against being called multiple times */
344 static int cleaned = 0;
351 /* user app might chdir to a lustre directory, and leave busy pnode
352 * during finaly libsysio cleanup. here we chdir back to "/".
353 * but it can't fix the situation that liblustre is mounted
360 /* we can't call umount here, because libsysio will not cleanup
361 * opening files for us. _sysio_shutdown() will cleanup fds at
362 * first but which will also close the sockets we need for umount
363 * liblutre. this dilema lead to another hack in
364 * libsysio/src/file_hack.c FIXME
368 cleanup_lib_portals();