2 #include <netinet/in.h>
3 #include <sys/socket.h>
6 #include <portals/api-support.h> /* needed for ptpctl.h */
7 #include <portals/ptlctl.h> /* needed for parse_dump */
10 #include <liblustre.h>
11 #include <linux/obd.h>
12 #include <linux/obd_class.h>
13 #include <procbridge.h>
15 #define LIBLUSTRE_TEST 1
16 #include "../utils/lctl.c"
18 struct ldlm_namespace;
22 void *inter_module_get(char *arg)
24 if (!strcmp(arg, "tcpnal_ni"))
26 else if (!strcmp(arg, "ldlm_cli_cancel_unused"))
27 return ldlm_cli_cancel_unused;
28 else if (!strcmp(arg, "ldlm_namespace_cleanup"))
29 return ldlm_namespace_cleanup;
30 else if (!strcmp(arg, "ldlm_replay_locks"))
31 return ldlm_replay_locks;
36 /* XXX move to proper place */
37 char *portals_nid2str(int nal, ptl_nid_t nid, char *str)
43 sprintf(str, "%u:%d.%d.%d.%d", (__u32)(nid >> 32),
51 sprintf(str, "%u:%u", (__u32)(nid >> 32), (__u32)nid);
59 ptl_handle_ni_t tcpnal_ni;
69 struct task_struct *current;
71 struct obd_class_user_state ocus;
73 /* portals interfaces */
75 kportal_get_ni (int nal)
87 kportal_put_ni (int nal)
93 kportal_nal_cmd(struct portals_cfg *pcfg)
96 __u32 nal = pcfg->pcfg_nal;
102 if (nal > 0 && nal <= NAL_MAX_NR && nal_cmd[nal].nch_handler) {
103 CDEBUG(D_IOCTL, "calling handler nal: %d, cmd: %d\n", nal,
105 rc = nal_cmd[nal].nch_handler(pcfg, nal_cmd[nal].nch_private);
110 CERROR("empty function!!!\n");
115 int init_current(int argc, char **argv)
117 current = malloc(sizeof(*current));
118 strncpy(current->comm, argv[0], sizeof(current->comm));
119 current->pid = getpid();
123 ptl_nid_t tcpnal_mynid;
125 int init_lib_portals()
130 rc = PtlNIInit(procbridge_interface, 0, 0, 0, &tcpnal_ni);
132 CERROR("ksocknal: PtlNIInit failed: error %d\n", rc);
136 PtlNIDebug(tcpnal_ni, ~0);
140 extern int class_handle_ioctl(struct obd_class_user_state *ocus, unsigned int cmd, unsigned long arg);
143 int lib_ioctl_nalcmd(int dev_id, int opc, void * ptr)
145 struct portal_ioctl_data *ptldata;
147 if (opc == IOC_PORTAL_NAL_CMD) {
148 ptldata = (struct portal_ioctl_data *) ptr;
150 if (ptldata->ioc_nal_cmd == NAL_CMD_REGISTER_MYNID) {
151 tcpnal_mynid = ptldata->ioc_nid;
152 printf("mynid: %u.%u.%u.%u\n",
153 (unsigned)(tcpnal_mynid>>24) & 0xFF,
154 (unsigned)(tcpnal_mynid>>16) & 0xFF,
155 (unsigned)(tcpnal_mynid>>8) & 0xFF,
156 (unsigned)(tcpnal_mynid) & 0xFF);
163 int lib_ioctl(int dev_id, int opc, void * ptr)
166 if (dev_id == OBD_DEV_ID) {
167 class_handle_ioctl(&ocus, opc, (unsigned long)ptr);
169 /* you _may_ need to call obd_ioctl_unpack or some
170 other verification function if you want to use ioc
173 printf ("processing ioctl cmd: %x buf len: %d\n",
180 int liblustre_ioctl(int dev_id, int opc, void *ptr)
186 fprintf(stderr, "Unexpected device id %d\n", dev_id);
191 rc = class_handle_ioctl(&ocus, opc, (unsigned long)ptr);
198 extern int time_ptlwait1;
199 extern int time_ptlwait2;
200 extern int time_ptlselect;
201 int main(int argc, char **argv)
206 printf("Usage: %s [config_file]\n", argv[0]);
211 config_file = argv[1];
215 config_file = "/tmp/DUMP_FILE";
219 INIT_LIST_HEAD(&ocus.ocus_conns);
222 portal_subsystem_debug = 0;
224 parse_dump(config_file, lib_ioctl_nalcmd);
226 if (init_current(argc, argv) ||
227 init_obdclass() || init_lib_portals() ||
233 echo_client_init()) {
238 parse_dump(config_file, lib_ioctl);
240 set_ioc_handler(liblustre_ioctl);
243 portal_subsystem_debug = -1;
245 return lctl_main(argc, argv);