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, 2003 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>
31 #include <netinet/in.h>
32 #include <sys/socket.h>
33 #include <arpa/inet.h>
41 /* both sys/queue.h (libsysio require it) and portals/lists.h have definition
42 * of 'LIST_HEAD'. undef it to suppress warnings
46 #include <portals/ptlctl.h> /* needed for parse_dump */
47 #include <procbridge.h>
49 #include "llite_lib.h"
51 unsigned int portal_subsystem_debug = ~0 - (S_PORTALS | S_QSWNAL | S_SOCKNAL |
54 ptl_handle_ni_t tcpnal_ni;
55 struct task_struct *current;
57 /* portals interfaces */
59 struct ldlm_namespace;
63 void *inter_module_get(char *arg)
65 if (!strcmp(arg, "tcpnal_ni"))
67 else if (!strcmp(arg, "ldlm_cli_cancel_unused"))
68 return ldlm_cli_cancel_unused;
69 else if (!strcmp(arg, "ldlm_namespace_cleanup"))
70 return ldlm_namespace_cleanup;
71 else if (!strcmp(arg, "ldlm_replay_locks"))
72 return ldlm_replay_locks;
77 /* XXX move to proper place */
78 char *portals_nid2str(int nal, ptl_nid_t nid, char *str)
84 snprintf(str, PTL_NALFMT_SIZE - 1, "%u:%u.%u.%u.%u",
85 (__u32)(nid >> 32), HIPQUAD(nid));
91 snprintf(str, PTL_NALFMT_SIZE - 1, "%u:%u",
92 (__u32)(nid >> 32), (__u32)nid);
95 snprintf(str, PTL_NALFMT_SIZE - 1, "?%d? %llx",
102 void init_current(char *comm)
104 current = malloc(sizeof(*current));
105 current->fs = malloc(sizeof(*current->fs));
106 current->fs->umask = umask(0777);
107 umask(current->fs->umask);
108 strncpy(current->comm, comm, sizeof(current->comm));
109 current->pid = getpid();
112 current->cap_effective = -1;
113 memset(¤t->pending, 0, sizeof(current->pending));
117 void generate_random_uuid(unsigned char uuid_out[16])
119 int *arr = (int*)uuid_out;
122 for (i = 0; i < sizeof(uuid_out)/sizeof(int); i++)
126 ptl_nid_t tcpnal_mynid;
128 int init_lib_portals()
134 rc = PtlInit(&max_interfaces);
136 CERROR("PtlInit failed: %d\n", rc);
143 libcfs_nal_cmd(struct portals_cfg *pcfg)
145 /* handle portals command if we want */
149 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
151 int lib_ioctl_nalcmd(int dev_id, unsigned int opc, void * ptr)
153 struct portal_ioctl_data *ptldata;
155 if (opc == IOC_PORTAL_NAL_CMD) {
156 ptldata = (struct portal_ioctl_data *) ptr;
158 if (ptldata->ioc_nal_cmd == NAL_CMD_REGISTER_MYNID) {
159 tcpnal_mynid = ptldata->ioc_nid;
160 printf("mynid: %u.%u.%u.%u\n",
161 (unsigned)(tcpnal_mynid>>24) & 0xFF,
162 (unsigned)(tcpnal_mynid>>16) & 0xFF,
163 (unsigned)(tcpnal_mynid>>8) & 0xFF,
164 (unsigned)(tcpnal_mynid) & 0xFF);
171 int lib_ioctl(int dev_id, unsigned int opc, void * ptr)
175 if (dev_id == OBD_DEV_ID) {
176 struct obd_ioctl_data *ioc = ptr;
179 ioc->ioc_plen1 = ioc->ioc_inllen1;
180 ioc->ioc_pbuf1 = ioc->ioc_bulk;
183 rc = class_handle_ioctl(opc, (unsigned long)ptr);
185 printf ("proccssing ioctl cmd: %x, rc %d\n", opc, rc);
193 int lllib_init(char *dumpfile)
196 /* this parse only get my nid from config file
197 * before initialize portals
199 if (parse_dump(dumpfile, lib_ioctl_nalcmd))
202 /* XXX need setup mynid before tcpnal initialize */
203 tcpnal_mynid = ((uint64_t)getpid() << 32) | time(0);
204 printf("LibLustre: TCPNAL NID: %016llx\n", tcpnal_mynid);
207 init_current("dummy");
208 if (init_obdclass() ||
209 init_lib_portals() ||
216 if (!g_zconf && parse_dump(dumpfile, lib_ioctl))
219 return _sysio_fssw_register("llite", &llu_fssw_ops);
223 static void llu_check_request()
225 liblustre_wait_event(0);
229 int liblustre_process_log(struct config_llog_instance *cfg, int allow_recov)
231 struct lustre_cfg lcfg;
232 char *peer = "MDS_PEER_UUID";
233 struct obd_device *obd;
234 struct lustre_handle mdc_conn = {0, };
235 struct obd_export *exp;
236 char *name = "mdc_dev";
238 struct obd_uuid mdc_uuid;
239 struct llog_ctxt *ctxt;
241 int nal, err, rc = 0;
244 generate_random_uuid(uuid);
245 class_uuid_unparse(uuid, &mdc_uuid);
247 if (ptl_parse_nid(&nid, g_zconf_mdsnid)) {
248 CERROR("Can't parse NID %s\n", g_zconf_mdsnid);
252 nal = ptl_name2nal("tcp");
254 CERROR("Can't parse NAL tcp\n");
257 LCFG_INIT(lcfg, LCFG_ADD_UUID, NULL);
259 lcfg.lcfg_inllen1 = strlen(peer) + 1;
260 lcfg.lcfg_inlbuf1 = peer;
262 err = class_process_config(&lcfg);
266 LCFG_INIT(lcfg, LCFG_ATTACH, name);
267 lcfg.lcfg_inlbuf1 = "mdc";
268 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
269 lcfg.lcfg_inlbuf2 = mdc_uuid.uuid;
270 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
271 err = class_process_config(&lcfg);
273 GOTO(out_del_uuid, err);
275 LCFG_INIT(lcfg, LCFG_SETUP, name);
276 lcfg.lcfg_inlbuf1 = g_zconf_mdsname;
277 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
278 lcfg.lcfg_inlbuf2 = peer;
279 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
280 err = class_process_config(&lcfg);
282 GOTO(out_detach, err);
284 obd = class_name2obd(name);
286 GOTO(out_cleanup, err = -EINVAL);
288 /* Disable initial recovery on this import */
289 err = obd_set_info(obd->obd_self_export,
290 strlen("initial_recov"), "initial_recov",
291 sizeof(allow_recov), &allow_recov);
293 err = obd_connect(&mdc_conn, obd, &mdc_uuid);
295 CERROR("cannot connect to %s: rc = %d\n",
296 g_zconf_mdsname, err);
297 GOTO(out_cleanup, err);
300 exp = class_conn2export(&mdc_conn);
302 ctxt = exp->exp_obd->obd_llog_ctxt[LLOG_CONFIG_REPL_CTXT];
303 rc = class_config_parse_llog(ctxt, g_zconf_profile, cfg);
305 CERROR("class_config_parse_llog failed: rc = %d\n", rc);
308 err = obd_disconnect(exp, 0);
311 LCFG_INIT(lcfg, LCFG_CLEANUP, name);
312 err = class_process_config(&lcfg);
317 LCFG_INIT(lcfg, LCFG_DETACH, name);
318 err = class_process_config(&lcfg);
323 LCFG_INIT(lcfg, LCFG_DEL_UUID, name);
324 lcfg.lcfg_inllen1 = strlen(peer) + 1;
325 lcfg.lcfg_inlbuf1 = peer;
326 err = class_process_config(&lcfg);
335 static void sighandler_USR1(int signum)
340 /* parse host:/mdsname/profile string */
341 int ll_parse_mount_target(const char *target, char **mdsnid,
342 char **mdsname, char **profile)
344 static char buf[256];
348 strncpy(buf, target, 255);
350 if ((s = strchr(buf, ':'))) {
357 if ((s = strchr(*mdsname, '/'))) {
368 #define ENV_LUSTRE_MNTPNT "LIBLUSTRE_MOUNT_POINT"
369 #define ENV_LUSTRE_MNTTGT "LIBLUSTRE_MOUNT_TARGET"
370 #define ENV_LUSTRE_TIMEOUT "LIBLUSTRE_TIMEOUT"
371 #define ENV_LUSTRE_DUMPFILE "LIBLUSTRE_DUMPFILE"
373 extern int _sysio_native_init();
375 extern unsigned int obd_timeout;
377 /* global variables */
378 int g_zconf = 0; /* zeroconf or dumpfile */
379 char *g_zconf_mdsname = NULL; /* mdsname, for zeroconf */
380 char *g_zconf_mdsnid = NULL; /* mdsnid, for zeroconf */
381 char *g_zconf_profile = NULL; /* profile, for zeroconf */
384 void __liblustre_setup_(void)
386 char *lustre_path = NULL;
388 char *timeout = NULL;
389 char *dumpfile = NULL;
390 char *root_driver = "native";
391 char *lustre_driver = "llite";
392 char *root_path = "/";
393 unsigned mntflgs = 0;
397 /* consider tha case of starting multiple liblustre instances
398 * at a same time on single node.
400 srand(time(NULL) + getpid());
402 signal(SIGUSR1, sighandler_USR1);
404 lustre_path = getenv(ENV_LUSTRE_MNTPNT);
406 lustre_path = "/mnt/lustre";
409 target = getenv(ENV_LUSTRE_MNTTGT);
411 dumpfile = getenv(ENV_LUSTRE_DUMPFILE);
413 CERROR("Neither mount target, nor dumpfile\n");
417 printf("LibLustre: mount point %s, dumpfile %s\n",
418 lustre_path, dumpfile);
420 if (ll_parse_mount_target(target,
424 CERROR("mal-formed target %s \n", target);
428 printf("LibLustre: mount point %s, target %s\n",
429 lustre_path, target);
432 timeout = getenv(ENV_LUSTRE_TIMEOUT);
434 obd_timeout = (unsigned int) atoi(timeout);
435 printf("LibLustre: set obd timeout as %u seconds\n",
439 if (_sysio_init() != 0) {
440 perror("init sysio");
444 /* cygwin don't need native driver */
446 _sysio_native_init();
449 err = _sysio_mount_root(root_path, root_driver, mntflgs, NULL);
457 portal_subsystem_debug = 0;
459 err = lllib_init(dumpfile);
461 perror("init llite driver");
465 err = mount("/", lustre_path, lustre_driver, mntflgs, NULL);
468 perror(lustre_driver);
473 __sysio_hook_sys_enter = llu_check_request;
474 __sysio_hook_sys_leave = NULL;
478 void __liblustre_cleanup_(void)