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>
43 #define ENV_LUSTRE_MNTPNT "LIBLUSTRE_MOUNT_POINT"
44 #define ENV_LUSTRE_MNTTGT "LIBLUSTRE_MOUNT_TARGET"
45 #define ENV_LUSTRE_TIMEOUT "LIBLUSTRE_TIMEOUT"
46 #define ENV_LUSTRE_DUMPFILE "LIBLUSTRE_DUMPFILE"
47 #define ENV_LUSTRE_DEBUG_MASK "LIBLUSTRE_DEBUG_MASK"
48 #define ENV_LUSTRE_DEBUG_SUBSYS "LIBLUSTRE_DEBUG_SUBSYS"
49 #define ENV_LUSTRE_NAL_NAME "LIBLUSTRE_NAL_NAME"
55 /* both sys/queue.h (libsysio require it) and portals/lists.h have definition
56 * of 'LIST_HEAD'. undef it to suppress warnings
59 #include <portals/ptlctl.h>
62 #include "llite_lib.h"
64 static int lllib_init(void)
66 liblustre_set_nal_nid();
68 if (liblustre_init_current("dummy") ||
77 return _sysio_fssw_register("llite", &llu_fssw_ops);
81 #define LIBLUSTRE_NAL_NAME "tcp"
82 #elif defined REDSTORM
83 #define LIBLUSTRE_NAL_NAME "cray_qk_ernal"
85 #define LIBLUSTRE_NAL_NAME "cray_pb_ernal"
88 int liblustre_process_log(struct config_llog_instance *cfg, int allow_recov)
90 struct lustre_cfg lcfg;
91 char *peer = "MDS_PEER_UUID";
92 struct obd_device *obd;
93 struct lustre_handle mdc_conn = {0, };
94 struct obd_export *exp;
95 char *name = "mdc_dev";
97 struct obd_uuid mdc_uuid;
98 struct llog_ctxt *ctxt;
100 int nal, err, rc = 0;
104 generate_random_uuid(uuid);
105 class_uuid_unparse(uuid, &mdc_uuid);
107 if (ptl_parse_nid(&nid, g_zconf_mdsnid)) {
108 CERROR("Can't parse NID %s\n", g_zconf_mdsnid);
112 nal_name = getenv(ENV_LUSTRE_NAL_NAME);
115 nal = ptl_name2nal(nal_name);
117 CERROR("Can't parse NAL %s\n", nal_name);
120 LCFG_INIT(lcfg, LCFG_ADD_UUID, name);
122 lcfg.lcfg_inllen1 = strlen(peer) + 1;
123 lcfg.lcfg_inlbuf1 = peer;
125 err = class_process_config(&lcfg);
129 LCFG_INIT(lcfg, LCFG_ATTACH, name);
130 lcfg.lcfg_inlbuf1 = "mdc";
131 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
132 lcfg.lcfg_inlbuf2 = mdc_uuid.uuid;
133 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
134 err = class_process_config(&lcfg);
136 GOTO(out_del_uuid, err);
138 LCFG_INIT(lcfg, LCFG_SETUP, name);
139 lcfg.lcfg_inlbuf1 = g_zconf_mdsname;
140 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
141 lcfg.lcfg_inlbuf2 = peer;
142 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
143 err = class_process_config(&lcfg);
145 GOTO(out_detach, err);
147 obd = class_name2obd(name);
149 GOTO(out_cleanup, err = -EINVAL);
151 /* Disable initial recovery on this import */
152 err = obd_set_info(obd->obd_self_export,
153 strlen("initial_recov"), "initial_recov",
154 sizeof(allow_recov), &allow_recov);
156 err = obd_connect(&mdc_conn, obd, &mdc_uuid, NULL, 0);
158 CERROR("cannot connect to %s: rc = %d\n",
159 g_zconf_mdsname, err);
160 GOTO(out_cleanup, err);
163 exp = class_conn2export(&mdc_conn);
165 ctxt = exp->exp_obd->obd_llog_ctxt[LLOG_CONFIG_REPL_CTXT];
166 rc = class_config_process_llog(ctxt, g_zconf_profile, cfg);
168 CERROR("class_config_process_llog failed: rc = %d\n", rc);
170 err = obd_disconnect(exp, 0);
173 LCFG_INIT(lcfg, LCFG_CLEANUP, name);
174 err = class_process_config(&lcfg);
179 LCFG_INIT(lcfg, LCFG_DETACH, name);
180 err = class_process_config(&lcfg);
185 LCFG_INIT(lcfg, LCFG_DEL_UUID, name);
186 lcfg.lcfg_inllen1 = strlen(peer) + 1;
187 lcfg.lcfg_inlbuf1 = peer;
188 err = class_process_config(&lcfg);
197 /* parse host:/mdsname/profile string */
198 int ll_parse_mount_target(const char *target, char **mdsnid,
199 char **mdsname, char **profile)
201 static char buf[256];
205 strncpy(buf, target, 255);
207 if ((s = strchr(buf, ':'))) {
214 if ((s = strchr(*mdsname, '/'))) {
225 * early liblustre init
226 * called from C startup in catamount apps, before main()
228 * The following is a skeleton sysio startup sequence,
229 * as implemented in C startup (skipping error handling).
230 * In this framework none of these calls need be made here
231 * or in the apps themselves. The NAMESPACE_STRING specifying
232 * the initial set of fs ops (creates, mounts, etc.) is passed
233 * as an environment variable.
236 * _sysio_incore_init();
237 * _sysio_native_init();
238 * _sysio_lustre_init();
239 * _sysio_boot(NAMESPACE_STRING);
241 * the name _sysio_lustre_init() follows the naming convention
242 * established in other fs drivers from libsysio:
243 * _sysio_incore_init(), _sysio_native_init()
245 * _sysio_lustre_init() must be called before _sysio_boot()
246 * to enable libsysio's processing of namespace init strings containing
247 * lustre filesystem operations
249 int _sysio_lustre_init(void)
255 portal_subsystem_debug = -1;
258 liblustre_init_random();
262 perror("init llite driver");
267 extern int _sysio_native_init();
268 extern unsigned int obd_timeout;
270 char *lustre_path = NULL;
272 /* global variables */
273 char *g_zconf_mdsname = NULL; /* mdsname, for zeroconf */
274 char *g_zconf_mdsnid = NULL; /* mdsnid, for zeroconf */
275 char *g_zconf_profile = NULL; /* profile, for zeroconf */
278 void __liblustre_setup_(void)
281 char *timeout = NULL;
282 char *debug_mask = NULL;
283 char *debug_subsys = NULL;
284 char *root_driver = "native";
285 char *lustre_driver = "llite";
286 char *root_path = "/";
287 unsigned mntflgs = 0;
290 lustre_path = getenv(ENV_LUSTRE_MNTPNT);
292 lustre_path = "/mnt/lustre";
296 target = getenv(ENV_LUSTRE_MNTTGT);
298 printf("LibLustre: no mount target specified\n");
301 if (ll_parse_mount_target(target,
305 CERROR("mal-formed target %s \n", target);
308 if (!g_zconf_mdsnid || !g_zconf_mdsname || !g_zconf_profile) {
309 printf("Liblustre: invalid target %s\n", target);
312 printf("LibLustre: mount point %s, target %s\n",
313 lustre_path, target);
315 timeout = getenv(ENV_LUSTRE_TIMEOUT);
317 obd_timeout = (unsigned int) strtol(timeout, NULL, 0);
318 printf("LibLustre: set obd timeout as %u seconds\n",
323 debug_mask = getenv(ENV_LUSTRE_DEBUG_MASK);
325 portal_debug = (unsigned int) strtol(debug_mask, NULL, 0);
327 debug_subsys = getenv(ENV_LUSTRE_DEBUG_SUBSYS);
329 portal_subsystem_debug =
330 (unsigned int) strtol(debug_subsys, NULL, 0);
334 /* initialize libsysio & mount rootfs */
336 perror("init sysio");
339 _sysio_native_init();
341 err = _sysio_mount_root(root_path, root_driver, mntflgs, NULL);
347 if (_sysio_lustre_init())
349 #endif /* INIT_SYSIO */
351 err = mount("/", lustre_path, lustre_driver, mntflgs, NULL);
354 perror(lustre_driver);
359 void __liblustre_cleanup_(void)
361 /* user app might chdir to a lustre directory, and leave busy pnode
362 * during finaly libsysio cleanup. here we chdir back to "/".
363 * but it can't fix the situation that liblustre is mounted
370 /* we can't call umount here, because libsysio will not cleanup
371 * opening files for us. _sysio_shutdown() will cleanup fds at
372 * first but which will also close the sockets we need for umount
373 * liblutre. this delima lead to another hack in
374 * libsysio/src/file_hack.c FIXME
378 cleanup_lib_portals();
382 * don't do any libsysio or low level portals cleanups
383 * platform framework does it
385 cleanup_lib_portals();