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>
29 #include <sys/queue.h>
41 /* both sys/queue.h (libsysio require it) and portals/lists.h have definition
42 * of 'LIST_HEAD'. undef it to suppress warnings
45 #include <portals/ptlctl.h>
48 #include "llite_lib.h"
50 static int lllib_init(void)
52 liblustre_set_nal_nid();
54 if (liblustre_init_current("dummy") ||
63 return _sysio_fssw_register("llite", &llu_fssw_ops);
67 #define LIBLUSTRE_NAL_NAME "tcp"
68 #elif defined REDSTORM
69 #define LIBLUSTRE_NAL_NAME "cray_qk_ernal"
71 #define LIBLUSTRE_NAL_NAME "cray_pb_ernal"
74 int liblustre_process_log(struct config_llog_instance *cfg, int allow_recov)
76 struct lustre_cfg lcfg;
77 char *peer = "MDS_PEER_UUID";
78 struct obd_device *obd;
79 struct lustre_handle mdc_conn = {0, };
80 struct obd_export *exp;
81 char *name = "mdc_dev";
83 struct obd_uuid mdc_uuid;
84 struct llog_ctxt *ctxt;
89 generate_random_uuid(uuid);
90 class_uuid_unparse(uuid, &mdc_uuid);
92 if (ptl_parse_nid(&nid, g_zconf_mdsnid)) {
93 CERROR("Can't parse NID %s\n", g_zconf_mdsnid);
97 nal = ptl_name2nal(LIBLUSTRE_NAL_NAME);
99 CERROR("Can't parse NAL %s\n", LIBLUSTRE_NAL_NAME);
102 LCFG_INIT(lcfg, LCFG_ADD_UUID, NULL);
104 lcfg.lcfg_inllen1 = strlen(peer) + 1;
105 lcfg.lcfg_inlbuf1 = peer;
107 err = class_process_config(&lcfg);
111 LCFG_INIT(lcfg, LCFG_ATTACH, name);
112 lcfg.lcfg_inlbuf1 = "mdc";
113 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
114 lcfg.lcfg_inlbuf2 = mdc_uuid.uuid;
115 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
116 err = class_process_config(&lcfg);
118 GOTO(out_del_uuid, err);
120 LCFG_INIT(lcfg, LCFG_SETUP, name);
121 lcfg.lcfg_inlbuf1 = g_zconf_mdsname;
122 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
123 lcfg.lcfg_inlbuf2 = peer;
124 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
125 err = class_process_config(&lcfg);
127 GOTO(out_detach, err);
129 obd = class_name2obd(name);
131 GOTO(out_cleanup, err = -EINVAL);
133 /* Disable initial recovery on this import */
134 err = obd_set_info(obd->obd_self_export,
135 strlen("initial_recov"), "initial_recov",
136 sizeof(allow_recov), &allow_recov);
138 err = obd_connect(&mdc_conn, obd, &mdc_uuid, 0);
140 CERROR("cannot connect to %s: rc = %d\n",
141 g_zconf_mdsname, err);
142 GOTO(out_cleanup, err);
145 exp = class_conn2export(&mdc_conn);
147 ctxt = exp->exp_obd->obd_llog_ctxt[LLOG_CONFIG_REPL_CTXT];
148 rc = class_config_process_llog(ctxt, g_zconf_profile, cfg);
150 CERROR("class_config_parse_llog failed: rc = %d\n", rc);
153 err = obd_disconnect(exp, 0);
156 LCFG_INIT(lcfg, LCFG_CLEANUP, name);
157 err = class_process_config(&lcfg);
162 LCFG_INIT(lcfg, LCFG_DETACH, name);
163 err = class_process_config(&lcfg);
168 LCFG_INIT(lcfg, LCFG_DEL_UUID, name);
169 lcfg.lcfg_inllen1 = strlen(peer) + 1;
170 lcfg.lcfg_inlbuf1 = peer;
171 err = class_process_config(&lcfg);
180 /* parse host:/mdsname/profile string */
181 int ll_parse_mount_target(const char *target, char **mdsnid,
182 char **mdsname, char **profile)
184 static char buf[256];
188 strncpy(buf, target, 255);
190 if ((s = strchr(buf, ':'))) {
197 if ((s = strchr(*mdsname, '/'))) {
208 * early liblustre init
209 * called from C startup in catamount apps, before main()
211 * The following is a skeleton sysio startup sequence,
212 * as implemented in C startup (skipping error handling).
213 * In this framework none of these calls need be made here
214 * or in the apps themselves. The NAMESPACE_STRING specifying
215 * the initial set of fs ops (creates, mounts, etc.) is passed
216 * as an environment variable.
219 * _sysio_incore_init();
220 * _sysio_native_init();
221 * _sysio_lustre_init();
222 * _sysio_boot(NAMESPACE_STRING);
224 * the name _sysio_lustre_init() follows the naming convention
225 * established in other fs drivers from libsysio:
226 * _sysio_incore_init(), _sysio_native_init()
228 * _sysio_lustre_init() must be called before _sysio_boot()
229 * to enable libsysio's processing of namespace init strings containing
230 * lustre filesystem operations
232 int _sysio_lustre_init(void)
238 portal_subsystem_debug = -1;
241 liblustre_init_random();
245 perror("init llite driver");
251 #define ENV_LUSTRE_MNTPNT "LIBLUSTRE_MOUNT_POINT"
252 #define ENV_LUSTRE_MNTTGT "LIBLUSTRE_MOUNT_TARGET"
253 #define ENV_LUSTRE_TIMEOUT "LIBLUSTRE_TIMEOUT"
254 #define ENV_LUSTRE_DUMPFILE "LIBLUSTRE_DUMPFILE"
255 #define ENV_LUSTRE_DEBUG_MASK "LIBLUSTRE_DEBUG_MASK"
256 #define ENV_LUSTRE_DEBUG_SUBSYS "LIBLUSTRE_DEBUG_SUBSYS"
258 extern int _sysio_native_init();
259 extern unsigned int obd_timeout;
261 static char *lustre_path = NULL;
263 /* global variables */
264 char *g_zconf_mdsname = NULL; /* mdsname, for zeroconf */
265 char *g_zconf_mdsnid = NULL; /* mdsnid, for zeroconf */
266 char *g_zconf_profile = NULL; /* profile, for zeroconf */
269 void __liblustre_setup_(void)
272 char *timeout = NULL;
273 char *debug_mask = NULL;
274 char *debug_subsys = NULL;
275 char *root_driver = "native";
276 char *lustre_driver = "llite";
277 char *root_path = "/";
278 unsigned mntflgs = 0;
281 lustre_path = getenv(ENV_LUSTRE_MNTPNT);
283 lustre_path = "/mnt/lustre";
287 target = getenv(ENV_LUSTRE_MNTTGT);
289 printf("LibLustre: no mount target specified\n");
292 if (ll_parse_mount_target(target,
296 CERROR("mal-formed target %s \n", target);
299 if (!g_zconf_mdsnid || !g_zconf_mdsname || !g_zconf_profile) {
300 printf("Liblustre: invalid target %s\n", target);
303 printf("LibLustre: mount point %s, target %s\n",
304 lustre_path, target);
306 timeout = getenv(ENV_LUSTRE_TIMEOUT);
308 obd_timeout = (unsigned int) strtol(timeout, NULL, 0);
309 printf("LibLustre: set obd timeout as %u seconds\n",
314 debug_mask = getenv(ENV_LUSTRE_DEBUG_MASK);
316 portal_debug = (unsigned int) strtol(debug_mask, NULL, 0);
318 debug_subsys = getenv(ENV_LUSTRE_DEBUG_SUBSYS);
320 portal_subsystem_debug =
321 (unsigned int) strtol(debug_subsys, NULL, 0);
324 /* initialize libsysio & mount rootfs */
326 perror("init sysio");
329 _sysio_native_init();
331 err = _sysio_mount_root(root_path, root_driver, mntflgs, NULL);
337 if (_sysio_lustre_init())
341 err = mount("/", lustre_path, lustre_driver, mntflgs, NULL);
344 perror(lustre_driver);
349 void __liblustre_cleanup_(void)
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 delima lead to another hack in
364 * libsysio/src/file_hack.c FIXME
367 cleanup_lib_portals();