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.
24 #define DEBUG_SUBSYSTEM S_LLITE
30 #include <sys/types.h>
31 #include <sys/queue.h>
39 #include <netinet/in.h>
40 #include <sys/socket.h>
41 #include <arpa/inet.h>
43 #include <portals/api-support.h> /* needed for ptpctl.h */
44 #include <portals/ptlctl.h> /* needed for parse_dump */
46 #include "llite_lib.h"
49 ptl_handle_ni_t tcpnal_ni;
50 struct task_struct *current;
51 struct obd_class_user_state ocus;
53 /* portals interfaces */
55 kportal_get_ni (int nal)
61 kportal_put_ni (int nal)
66 struct ldlm_namespace;
70 extern int ldlm_cli_cancel_unused(struct ldlm_namespace *ns, struct ldlm_res_id *res_id, int flags);
71 extern int ldlm_namespace_cleanup(struct ldlm_namespace *ns, int local_only);
72 extern int ldlm_replay_locks(struct obd_import *imp);
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 void init_current(char *comm)
90 current = malloc(sizeof(*current));
91 current->fs = malloc(sizeof(*current->fs));
92 current->fs->umask = umask(0777);
93 umask(current->fs->umask);
94 strncpy(current->comm, comm, sizeof(current->comm));
95 current->pid = getpid();
98 current->cap_effective = 0;
99 memset(¤t->pending, 0, sizeof(current->pending));
102 ptl_nid_t tcpnal_mynid;
104 int init_lib_portals()
109 rc = PtlNIInit(procbridge_interface, 0, 0, 0, &tcpnal_ni);
111 CERROR("ksocknal: PtlNIInit failed: error %d\n", rc);
115 PtlNIDebug(tcpnal_ni, ~0);
119 extern int class_handle_ioctl(struct obd_class_user_state *ocus, unsigned int cmd, unsigned long arg);
121 struct mount_option_s mount_option = {NULL, NULL};
123 /* FIXME simple arg parser FIXME */
124 void parse_mount_options(void *arg)
127 struct obd_ioctl_data *data;
128 char *ptr, *comma, *eq, **tgt, *v;
131 if (obd_ioctl_getdata(&buf, &len, arg)) {
132 CERROR("OBD ioctl: data error\n");
135 data = (struct obd_ioctl_data *)buf;
136 ptr = data->ioc_inlbuf1;
137 printf("mount option: %s\n", ptr);
140 eq = strchr(ptr, '=');
145 if (!strcmp("osc", ptr))
146 tgt = &mount_option.osc_uuid;
147 else if (!strcmp("mdc", ptr))
148 tgt = &mount_option.mdc_uuid;
150 printf("Unknown mount option %s\n", ptr);
155 comma = strchr(v, ',');
162 *tgt = malloc(strlen(v)+1);
167 obd_ioctl_freedata(buf, len);
170 int lib_ioctl(int dev_id, int opc, void * ptr)
174 if (dev_id == OBD_DEV_ID) {
175 struct obd_ioctl_data *ioc = ptr;
177 if (opc == OBD_IOC_MOUNTOPT) {
178 parse_mount_options(ptr);
182 rc = class_handle_ioctl(&ocus, opc, (unsigned long)ptr);
184 /* you _may_ need to call obd_ioctl_unpack or some
185 other verification function if you want to use ioc
187 printf ("processing ioctl cmd: %x buf len: %d, rc %d\n",
188 opc, ioc->ioc_len, rc);
196 int lllib_init(char *arg)
198 tcpnal_mynid = ntohl(inet_addr(arg));
199 INIT_LIST_HEAD(&ocus.ocus_conns);
201 init_current("dummy");
202 if (init_obdclass() ||
203 init_lib_portals() ||
211 if (parse_dump("/tmp/DUMP_FILE", lib_ioctl))
214 return _sysio_fssw_register("llite", &llu_fssw_ops);
218 void generate_random_uuid(unsigned char uuid_out[16])
220 int *arr = (int*)uuid_out;
223 for (i = 0; i < sizeof(uuid_out)/sizeof(int); i++)