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, name);
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_process_llog failed: rc = %d\n", rc);
152 err = obd_disconnect(exp, 0);
155 LCFG_INIT(lcfg, LCFG_CLEANUP, name);
156 err = class_process_config(&lcfg);
161 LCFG_INIT(lcfg, LCFG_DETACH, name);
162 err = class_process_config(&lcfg);
167 LCFG_INIT(lcfg, LCFG_DEL_UUID, name);
168 lcfg.lcfg_inllen1 = strlen(peer) + 1;
169 lcfg.lcfg_inlbuf1 = peer;
170 err = class_process_config(&lcfg);
179 /* parse host:/mdsname/profile string */
180 int ll_parse_mount_target(const char *target, char **mdsnid,
181 char **mdsname, char **profile)
183 static char buf[256];
187 strncpy(buf, target, 255);
189 if ((s = strchr(buf, ':'))) {
196 if ((s = strchr(*mdsname, '/'))) {
207 * early liblustre init
208 * called from C startup in catamount apps, before main()
210 * The following is a skeleton sysio startup sequence,
211 * as implemented in C startup (skipping error handling).
212 * In this framework none of these calls need be made here
213 * or in the apps themselves. The NAMESPACE_STRING specifying
214 * the initial set of fs ops (creates, mounts, etc.) is passed
215 * as an environment variable.
218 * _sysio_incore_init();
219 * _sysio_native_init();
220 * _sysio_lustre_init();
221 * _sysio_boot(NAMESPACE_STRING);
223 * the name _sysio_lustre_init() follows the naming convention
224 * established in other fs drivers from libsysio:
225 * _sysio_incore_init(), _sysio_native_init()
227 * _sysio_lustre_init() must be called before _sysio_boot()
228 * to enable libsysio's processing of namespace init strings containing
229 * lustre filesystem operations
231 int _sysio_lustre_init(void)
237 portal_subsystem_debug = -1;
240 liblustre_init_random();
244 perror("init llite driver");
250 #define ENV_LUSTRE_MNTPNT "LIBLUSTRE_MOUNT_POINT"
251 #define ENV_LUSTRE_MNTTGT "LIBLUSTRE_MOUNT_TARGET"
252 #define ENV_LUSTRE_TIMEOUT "LIBLUSTRE_TIMEOUT"
253 #define ENV_LUSTRE_DUMPFILE "LIBLUSTRE_DUMPFILE"
254 #define ENV_LUSTRE_DEBUG_MASK "LIBLUSTRE_DEBUG_MASK"
255 #define ENV_LUSTRE_DEBUG_SUBSYS "LIBLUSTRE_DEBUG_SUBSYS"
257 extern int _sysio_native_init();
258 extern unsigned int obd_timeout;
260 static char *lustre_path = NULL;
262 /* global variables */
263 char *g_zconf_mdsname = NULL; /* mdsname, for zeroconf */
264 char *g_zconf_mdsnid = NULL; /* mdsnid, for zeroconf */
265 char *g_zconf_profile = NULL; /* profile, for zeroconf */
268 void __liblustre_setup_(void)
271 char *timeout = NULL;
272 char *debug_mask = NULL;
273 char *debug_subsys = NULL;
274 char *root_driver = "native";
275 char *lustre_driver = "llite";
276 char *root_path = "/";
277 unsigned mntflgs = 0;
280 lustre_path = getenv(ENV_LUSTRE_MNTPNT);
282 lustre_path = "/mnt/lustre";
286 target = getenv(ENV_LUSTRE_MNTTGT);
288 printf("LibLustre: no mount target specified\n");
291 if (ll_parse_mount_target(target,
295 CERROR("mal-formed target %s \n", target);
298 if (!g_zconf_mdsnid || !g_zconf_mdsname || !g_zconf_profile) {
299 printf("Liblustre: invalid target %s\n", target);
302 printf("LibLustre: mount point %s, target %s\n",
303 lustre_path, target);
305 timeout = getenv(ENV_LUSTRE_TIMEOUT);
307 obd_timeout = (unsigned int) strtol(timeout, NULL, 0);
308 printf("LibLustre: set obd timeout as %u seconds\n",
313 debug_mask = getenv(ENV_LUSTRE_DEBUG_MASK);
315 portal_debug = (unsigned int) strtol(debug_mask, NULL, 0);
317 debug_subsys = getenv(ENV_LUSTRE_DEBUG_SUBSYS);
319 portal_subsystem_debug =
320 (unsigned int) strtol(debug_subsys, NULL, 0);
323 /* initialize libsysio & mount rootfs */
325 perror("init sysio");
328 _sysio_native_init();
330 err = _sysio_mount_root(root_path, root_driver, mntflgs, NULL);
336 if (_sysio_lustre_init())
340 err = mount("/", lustre_path, lustre_driver, mntflgs, NULL);
343 perror(lustre_driver);
348 void __liblustre_cleanup_(void)
350 /* user app might chdir to a lustre directory, and leave busy pnode
351 * during finaly libsysio cleanup. here we chdir back to "/".
352 * but it can't fix the situation that liblustre is mounted
359 /* we can't call umount here, because libsysio will not cleanup
360 * opening files for us. _sysio_shutdown() will cleanup fds at
361 * first but which will also close the sockets we need for umount
362 * liblutre. this delima lead to another hack in
363 * libsysio/src/file_hack.c FIXME
366 cleanup_lib_portals();