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_bufs bufs;
91 struct lustre_cfg *lcfg;
93 char *peer = "MDS_PEER_UUID";
94 struct obd_device *obd;
95 struct lustre_handle mdc_conn = {0, };
96 struct obd_export *exp;
97 char *name = "mdc_dev";
99 struct obd_uuid mdc_uuid;
100 struct llog_ctxt *ctxt;
102 int nal, err, rc = 0;
106 generate_random_uuid(uuid);
107 class_uuid_unparse(uuid, &mdc_uuid);
109 if (ptl_parse_nid(&nid, g_zconf_mdsnid)) {
110 CERROR("Can't parse NID %s\n", g_zconf_mdsnid);
114 nal_name = getenv(ENV_LUSTRE_NAL_NAME);
117 nal = ptl_name2nal(nal_name);
119 CERROR("Can't parse NAL %s\n", nal_name);
122 lustre_cfg_bufs_reset(&bufs, NULL);
123 lustre_cfg_bufs_set_string(&bufs, 1, peer);
124 lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs);
125 lcfg->lcfg_nid = nid;
126 lcfg->lcfg_nal = nal;
127 err = class_process_config(&lcfg);
128 lustre_cfg_free(lcfg);
132 lustre_cfg_bufs_reset(&bufs, name);
133 lustre_cfg_bufs_set_string(&bufs, 1, LUSTRE_MDC_NAME);
134 lustre_cfg_bufs_set_string(&bufs, 2, mdc_uuid.uuid);
135 lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
136 err = class_process_config(&lcfg);
137 lustre_cfg_free(lcfg);
139 GOTO(out_del_uuid, err);
141 lustre_cfg_bufs_reset(&bufs, name);
142 lustre_cfg_bufs_set_string(&bufs, 1, g_zconf_mdsname);
143 lustre_cfg_bufs_set_string(&bufs, 2, peer);
144 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
145 err = class_process_config(&lcfg);
146 lustre_cfg_free(lcfg);
148 GOTO(out_detach, err);
150 obd = class_name2obd(name);
152 GOTO(out_cleanup, err = -EINVAL);
154 /* Disable initial recovery on this import */
155 err = obd_set_info(obd->obd_self_export,
156 strlen("initial_recov"), "initial_recov",
157 sizeof(allow_recov), &allow_recov);
159 err = obd_connect(&mdc_conn, obd, &mdc_uuid, NULL, 0);
161 CERROR("cannot connect to %s: rc = %d\n",
162 g_zconf_mdsname, err);
163 GOTO(out_cleanup, err);
166 exp = class_conn2export(&mdc_conn);
168 ctxt = exp->exp_obd->obd_llog_ctxt[LLOG_CONFIG_REPL_CTXT];
169 rc = class_config_process_llog(ctxt, g_zconf_profile, cfg);
171 CERROR("class_config_process_llog failed: rc = %d\n", rc);
173 err = obd_disconnect(exp, 0);
176 lustre_cfg_bufs_reset(&bufs, name);
177 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
178 err = class_process_config(&lcfg);
179 lustre_cfg_free(lcfg);
184 lustre_cfg_bufs_reset(&bufs, name);
185 lcfg = lustre_cfg_new(LCFG_DETACH, &bufs);
186 err = class_process_config(&lcfg);
187 lustre_cfg_free(lcfg);
192 lustre_cfg_bufs_reset(&bufs, name);
193 lustre_cfg_bufs_set_string(&bufs, 1, peer);
194 lcfg = lustre_cfg_new(LCFG_DEL_UUID, &bufs);
195 err = class_process_config(lcfg);
196 lustre_cfg_free(lcfg);
204 /* parse host:/mdsname/profile string */
205 int ll_parse_mount_target(const char *target, char **mdsnid,
206 char **mdsname, char **profile)
208 static char buf[256];
212 strncpy(buf, target, 255);
214 if ((s = strchr(buf, ':'))) {
221 if ((s = strchr(*mdsname, '/'))) {
232 * early liblustre init
233 * called from C startup in catamount apps, before main()
235 * The following is a skeleton sysio startup sequence,
236 * as implemented in C startup (skipping error handling).
237 * In this framework none of these calls need be made here
238 * or in the apps themselves. The NAMESPACE_STRING specifying
239 * the initial set of fs ops (creates, mounts, etc.) is passed
240 * as an environment variable.
243 * _sysio_incore_init();
244 * _sysio_native_init();
245 * _sysio_lustre_init();
246 * _sysio_boot(NAMESPACE_STRING);
248 * the name _sysio_lustre_init() follows the naming convention
249 * established in other fs drivers from libsysio:
250 * _sysio_incore_init(), _sysio_native_init()
252 * _sysio_lustre_init() must be called before _sysio_boot()
253 * to enable libsysio's processing of namespace init strings containing
254 * lustre filesystem operations
256 int _sysio_lustre_init(void)
262 portal_subsystem_debug = -1;
265 liblustre_init_random();
269 perror("init llite driver");
274 extern int _sysio_native_init();
275 extern unsigned int obd_timeout;
277 char *lustre_path = NULL;
279 /* global variables */
280 char *g_zconf_mdsname = NULL; /* mdsname, for zeroconf */
281 char *g_zconf_mdsnid = NULL; /* mdsnid, for zeroconf */
282 char *g_zconf_profile = NULL; /* profile, for zeroconf */
285 void __liblustre_setup_(void)
288 char *timeout = NULL;
289 char *debug_mask = NULL;
290 char *debug_subsys = NULL;
291 char *root_driver = "native";
292 char *lustre_driver = "llite";
293 char *root_path = "/";
294 unsigned mntflgs = 0;
297 lustre_path = getenv(ENV_LUSTRE_MNTPNT);
299 lustre_path = "/mnt/lustre";
303 target = getenv(ENV_LUSTRE_MNTTGT);
305 printf("LibLustre: no mount target specified\n");
308 if (ll_parse_mount_target(target,
312 CERROR("mal-formed target %s \n", target);
315 if (!g_zconf_mdsnid || !g_zconf_mdsname || !g_zconf_profile) {
316 printf("Liblustre: invalid target %s\n", target);
319 printf("LibLustre: mount point %s, target %s\n",
320 lustre_path, target);
322 timeout = getenv(ENV_LUSTRE_TIMEOUT);
324 obd_timeout = (unsigned int) strtol(timeout, NULL, 0);
325 printf("LibLustre: set obd timeout as %u seconds\n",
330 debug_mask = getenv(ENV_LUSTRE_DEBUG_MASK);
332 portal_debug = (unsigned int) strtol(debug_mask, NULL, 0);
334 debug_subsys = getenv(ENV_LUSTRE_DEBUG_SUBSYS);
336 portal_subsystem_debug =
337 (unsigned int) strtol(debug_subsys, NULL, 0);
341 /* initialize libsysio & mount rootfs */
343 perror("init sysio");
346 _sysio_native_init();
348 err = _sysio_mount_root(root_path, root_driver, mntflgs, NULL);
354 if (_sysio_lustre_init())
356 #endif /* INIT_SYSIO */
358 err = mount("/", lustre_path, lustre_driver, mntflgs, NULL);
361 perror(lustre_driver);
366 void __liblustre_cleanup_(void)
368 /* user app might chdir to a lustre directory, and leave busy pnode
369 * during finaly libsysio cleanup. here we chdir back to "/".
370 * but it can't fix the situation that liblustre is mounted
377 /* we can't call umount here, because libsysio will not cleanup
378 * opening files for us. _sysio_shutdown() will cleanup fds at
379 * first but which will also close the sockets we need for umount
380 * liblutre. this delima lead to another hack in
381 * libsysio/src/file_hack.c FIXME
385 cleanup_lib_portals();
389 * don't do any libsysio or low level portals cleanups
390 * platform framework does it
392 cleanup_lib_portals();