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),
50 sprintf(str, "%u:%u", (__u32)(nid >> 32), (__u32)nid);
58 ptl_handle_ni_t tcpnal_ni;
68 struct task_struct *current;
70 struct obd_class_user_state ocus;
72 /* portals interfaces */
74 kportal_get_ni (int nal)
86 kportal_put_ni (int nal)
92 kportal_nal_cmd(struct portals_cfg *pcfg)
95 __u32 nal = pcfg->pcfg_nal;
101 if (nal > 0 && nal <= NAL_MAX_NR && nal_cmd[nal].nch_handler) {
102 CDEBUG(D_IOCTL, "calling handler nal: %d, cmd: %d\n", nal,
104 rc = nal_cmd[nal].nch_handler(pcfg, nal_cmd[nal].nch_private);
109 CERROR("empty function!!!\n");
114 int init_current(int argc, char **argv)
116 current = malloc(sizeof(*current));
117 strncpy(current->comm, argv[0], sizeof(current->comm));
118 current->pid = getpid();
122 ptl_nid_t tcpnal_mynid;
124 int init_lib_portals()
129 rc = PtlNIInit(procbridge_interface, 0, 0, 0, &tcpnal_ni);
131 CERROR("ksocknal: PtlNIInit failed: error %d\n", rc);
135 PtlNIDebug(tcpnal_ni, ~0);
139 extern int class_handle_ioctl(struct obd_class_user_state *ocus, unsigned int cmd, unsigned long arg);
142 int lib_ioctl_nalcmd(int dev_id, int opc, void * ptr)
144 struct portal_ioctl_data *ptldata;
146 if (opc == IOC_PORTAL_NAL_CMD) {
147 ptldata = (struct portal_ioctl_data *) ptr;
149 if (ptldata->ioc_nal_cmd == NAL_CMD_REGISTER_MYNID) {
150 tcpnal_mynid = ptldata->ioc_nid;
151 printf("mynid: %u.%u.%u.%u\n",
152 (unsigned)(tcpnal_mynid>>24) & 0xFF,
153 (unsigned)(tcpnal_mynid>>16) & 0xFF,
154 (unsigned)(tcpnal_mynid>>8) & 0xFF,
155 (unsigned)(tcpnal_mynid) & 0xFF);
162 int lib_ioctl(int dev_id, int opc, void * ptr)
165 if (dev_id == OBD_DEV_ID) {
166 class_handle_ioctl(&ocus, opc, (unsigned long)ptr);
168 /* you _may_ need to call obd_ioctl_unpack or some
169 other verification function if you want to use ioc
172 printf ("processing ioctl cmd: %x buf len: %d\n",
179 int liblustre_ioctl(int dev_id, int opc, void *ptr)
185 fprintf(stderr, "Unexpected device id %d\n", dev_id);
190 rc = class_handle_ioctl(&ocus, opc, (unsigned long)ptr);
197 extern int time_ptlwait1;
198 extern int time_ptlwait2;
199 extern int time_ptlselect;
200 int main(int argc, char **argv)
205 printf("Usage: %s [config_file]\n", argv[0]);
210 config_file = argv[1];
214 config_file = "/tmp/DUMP_FILE";
218 INIT_LIST_HEAD(&ocus.ocus_conns);
221 portal_subsystem_debug = 0;
223 parse_dump(config_file, lib_ioctl_nalcmd);
225 if (init_current(argc, argv) ||
226 init_obdclass() || init_lib_portals() ||
232 echo_client_init()) {
237 parse_dump(config_file, lib_ioctl);
239 set_ioc_handler(liblustre_ioctl);
242 portal_subsystem_debug = -1;
244 return lctl_main(argc, argv);