1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre Light Super operations
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.
27 #include <sys/types.h>
28 #include <sys/queue.h>
30 #include <netinet/in.h>
31 #include <sys/socket.h>
32 #include <arpa/inet.h>
40 #include <portals/api-support.h> /* needed for ptpctl.h */
41 #include <portals/ptlctl.h> /* needed for parse_dump */
42 #include <procbridge.h>
44 #include "llite_lib.h"
47 ptl_handle_ni_t tcpnal_ni;
48 struct task_struct *current;
49 struct obd_class_user_state ocus;
51 /* portals interfaces */
53 kportal_get_ni (int nal)
65 kportal_put_ni (int nal)
70 struct ldlm_namespace;
74 void *inter_module_get(char *arg)
76 if (!strcmp(arg, "tcpnal_ni"))
78 else if (!strcmp(arg, "ldlm_cli_cancel_unused"))
79 return ldlm_cli_cancel_unused;
80 else if (!strcmp(arg, "ldlm_namespace_cleanup"))
81 return ldlm_namespace_cleanup;
82 else if (!strcmp(arg, "ldlm_replay_locks"))
83 return ldlm_replay_locks;
88 /* XXX move to proper place */
89 char *portals_nid2str(int nal, ptl_nid_t nid, char *str)
95 sprintf(str, "%u:%d.%d.%d.%d", (__u32)(nid >> 32),
103 sprintf(str, "%u:%u", (__u32)(nid >> 32), (__u32)nid);
111 void init_current(char *comm)
113 current = malloc(sizeof(*current));
114 current->fs = malloc(sizeof(*current->fs));
115 current->fs->umask = umask(0777);
116 umask(current->fs->umask);
117 strncpy(current->comm, comm, sizeof(current->comm));
118 current->pid = getpid();
121 current->cap_effective = -1;
122 memset(¤t->pending, 0, sizeof(current->pending));
126 void generate_random_uuid(unsigned char uuid_out[16])
128 int *arr = (int*)uuid_out;
131 for (i = 0; i < sizeof(uuid_out)/sizeof(int); i++)
135 ptl_nid_t tcpnal_mynid;
137 int init_lib_portals()
143 rc = PtlNIInit(procbridge_interface, 0, 0, 0, &tcpnal_ni);
145 CERROR("ksocknal: PtlNIInit failed: error %d\n", rc);
149 PtlNIDebug(tcpnal_ni, ~0);
154 kportal_nal_cmd(struct portals_cfg *pcfg)
156 /* handle portals command if we want */
160 extern int class_handle_ioctl(struct obd_class_user_state *ocus, unsigned int cmd, unsigned long arg);
162 int lib_ioctl_nalcmd(int dev_id, int opc, void * ptr)
164 struct portal_ioctl_data *ptldata;
166 if (opc == IOC_PORTAL_NAL_CMD) {
167 ptldata = (struct portal_ioctl_data *) ptr;
169 if (ptldata->ioc_nal_cmd == NAL_CMD_REGISTER_MYNID) {
170 tcpnal_mynid = ptldata->ioc_nid;
171 printf("mynid: %u.%u.%u.%u\n",
172 (unsigned)(tcpnal_mynid>>24) & 0xFF,
173 (unsigned)(tcpnal_mynid>>16) & 0xFF,
174 (unsigned)(tcpnal_mynid>>8) & 0xFF,
175 (unsigned)(tcpnal_mynid) & 0xFF);
182 int lib_ioctl(int dev_id, int opc, void * ptr)
186 if (dev_id == OBD_DEV_ID) {
187 struct obd_ioctl_data *ioc = ptr;
190 ioc->ioc_plen1 = ioc->ioc_inllen1;
191 ioc->ioc_pbuf1 = ioc->ioc_bulk;
194 rc = class_handle_ioctl(&ocus, opc, (unsigned long)ptr);
196 printf ("proccssing ioctl cmd: %x, rc %d\n", opc, rc);
204 int lllib_init(char *dumpfile)
206 INIT_LIST_HEAD(&ocus.ocus_conns);
209 /* this parse only get my nid from config file
210 * before initialize portals
212 if (parse_dump(dumpfile, lib_ioctl_nalcmd))
215 /* XXX need setup mynid before tcpnal initialize */
216 tcpnal_mynid = ((uint64_t)getpid() << 32) | time(0);
217 printf("set tcpnal mynid: %016llx\n", tcpnal_mynid);
220 init_current("dummy");
221 if (init_obdclass() ||
222 init_lib_portals() ||
230 if (!g_zconf && parse_dump(dumpfile, lib_ioctl))
233 return _sysio_fssw_register("llite", &llu_fssw_ops);
237 static void llu_check_request()
239 liblustre_wait_event(0);
243 int liblustre_process_log(struct config_llog_instance *cfg)
245 struct lustre_cfg lcfg;
246 char *peer = "MDS_PEER_UUID";
247 struct obd_device *obd;
248 struct lustre_handle mdc_conn = {0, };
249 struct obd_export *exp;
250 char *name = "mdc_dev";
252 struct obd_uuid mdc_uuid;
253 struct llog_ctxt *ctxt;
255 int nal, err, rc = 0;
258 generate_random_uuid(uuid);
259 class_uuid_unparse(uuid, &mdc_uuid);
261 if (ptl_parse_nid(&nid, g_zconf_mdsnid)) {
262 CERROR("Can't parse NID %s\n", g_zconf_mdsnid);
265 nal = ptl_name2nal("tcp");
267 CERROR("Can't parse NAL tcp\n");
270 LCFG_INIT(lcfg, LCFG_ADD_UUID, NULL);
272 lcfg.lcfg_inllen1 = strlen(peer) + 1;
273 lcfg.lcfg_inlbuf1 = peer;
275 err = class_process_config(&lcfg);
279 LCFG_INIT(lcfg, LCFG_ATTACH, name);
280 lcfg.lcfg_inlbuf1 = "mdc";
281 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
282 lcfg.lcfg_inlbuf2 = mdc_uuid.uuid;
283 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
284 err = class_process_config(&lcfg);
286 GOTO(out_del_uuid, err);
288 LCFG_INIT(lcfg, LCFG_SETUP, name);
289 lcfg.lcfg_inlbuf1 = g_zconf_mdsname;
290 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
291 lcfg.lcfg_inlbuf2 = peer;
292 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
293 err = class_process_config(&lcfg);
295 GOTO(out_detach, err);
297 obd = class_name2obd(name);
299 GOTO(out_cleanup, err = -EINVAL);
301 err = obd_connect(&mdc_conn, obd, &mdc_uuid);
303 CERROR("cannot connect to %s: rc = %d\n",
304 g_zconf_mdsname, err);
305 GOTO(out_cleanup, err);
308 exp = class_conn2export(&mdc_conn);
310 ctxt = exp->exp_obd->obd_llog_ctxt[LLOG_CONFIG_REPL_CTXT];
311 rc = class_config_parse_llog(ctxt, g_zconf_profile, cfg);
313 CERROR("class_config_parse_llog failed: rc = %d\n", rc);
316 err = obd_disconnect(exp, 0);
319 LCFG_INIT(lcfg, LCFG_CLEANUP, name);
320 err = class_process_config(&lcfg);
325 LCFG_INIT(lcfg, LCFG_DETACH, name);
326 err = class_process_config(&lcfg);
331 LCFG_INIT(lcfg, LCFG_DEL_UUID, name);
332 lcfg.lcfg_inllen1 = strlen(peer) + 1;
333 lcfg.lcfg_inlbuf1 = peer;
334 err = class_process_config(&lcfg);
343 static void sighandler_USR1(int signum)
348 /* parse host:/mdsname/profile string */
349 int ll_parse_mount_target(const char *target, char **mdsnid,
350 char **mdsname, char **profile)
352 static char buf[256];
356 strncpy(buf, target, 255);
358 if ((s = strchr(buf, ':'))) {
365 if ((s = strchr(*mdsname, '/'))) {
376 #define ENV_LUSTRE_MNTPNT "LIBLUSTRE_MOUNT_POINT"
377 #define ENV_LUSTRE_MNTTGT "LIBLUSTRE_MOUNT_TARGET"
378 #define ENV_LUSTRE_DUMPFILE "LIBLUSTRE_DUMPFILE"
380 extern int _sysio_native_init();
382 /* global variables */
383 int g_zconf = 0; /* zeroconf or dumpfile */
384 char *g_zconf_mdsname = NULL; /* mdsname, for zeroconf */
385 char *g_zconf_mdsnid = NULL; /* mdsnid, for zeroconf */
386 char *g_zconf_profile = NULL; /* profile, for zeroconf */
389 void __liblustre_setup_(void)
391 char *lustre_path = NULL;
393 char *dumpfile = NULL;
394 char *root_driver = "native";
395 char *lustre_driver = "llite";
396 char *root_path = "/";
397 unsigned mntflgs = 0;
403 signal(SIGUSR1, sighandler_USR1);
405 lustre_path = getenv(ENV_LUSTRE_MNTPNT);
407 lustre_path = "/mnt/lustre";
410 target = getenv(ENV_LUSTRE_MNTTGT);
412 dumpfile = getenv(ENV_LUSTRE_DUMPFILE);
414 CERROR("Neither mount target, nor dumpfile\n");
418 printf("LibLustre: mount point %s, dumpfile %s\n",
419 lustre_path, dumpfile);
421 if (ll_parse_mount_target(target,
425 CERROR("mal-formed target %s \n", target);
429 printf("LibLustre: mount point %s, target %s\n",
430 lustre_path, target);
433 if (_sysio_init() != 0) {
434 perror("init sysio");
438 /* cygwin don't need native driver */
440 _sysio_native_init();
443 err = _sysio_mount_root(root_path, root_driver, mntflgs, NULL);
451 portal_subsystem_debug = 0;
453 err = lllib_init(dumpfile);
455 perror("init llite driver");
459 err = mount("/", lustre_path, lustre_driver, mntflgs, NULL);
462 perror(lustre_driver);
467 __sysio_hook_sys_enter = llu_check_request;
468 __sysio_hook_sys_leave = NULL;
472 void __liblustre_cleanup_(void)