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>
14 #include <linux/obd_ost.h>
16 #define LIBLUSTRE_TEST 1
17 #include "../utils/lctl.c"
19 struct ldlm_namespace;
23 unsigned int portal_subsystem_debug = ~0 - (S_PORTALS | S_NAL);
25 void *inter_module_get(char *arg)
27 if (!strcmp(arg, "ldlm_cli_cancel_unused"))
28 return ldlm_cli_cancel_unused;
29 else if (!strcmp(arg, "ldlm_namespace_cleanup"))
30 return ldlm_namespace_cleanup;
31 else if (!strcmp(arg, "ldlm_replay_locks"))
32 return ldlm_replay_locks;
37 /* XXX move to proper place */
39 char *portals_nid2str(int nal, ptl_nid_t nid, char *str)
45 snprintf(str, PTL_NALFMT_SIZE - 1, "%u:%u.%u.%u.%u",
46 (__u32)(nid >> 32), HIPQUAD(nid));
52 snprintf(str, PTL_NALFMT_SIZE - 1, "%u:%u",
53 (__u32)(nid >> 32), (__u32)nid);
56 snprintf(str, PTL_NALFMT_SIZE - 1, "?%d? %llx",
71 struct task_struct *current;
73 /* portals interfaces */
75 kportal_nal_cmd(struct portals_cfg *pcfg)
78 __u32 nal = pcfg->pcfg_nal;
84 if (nal > 0 && nal <= NAL_MAX_NR && nal_cmd[nal].nch_handler) {
85 CDEBUG(D_IOCTL, "calling handler nal: %d, cmd: %d\n", nal,
87 rc = nal_cmd[nal].nch_handler(pcfg, nal_cmd[nal].nch_private);
92 CERROR("empty function!!!\n");
97 int init_current(int argc, char **argv)
99 current = malloc(sizeof(*current));
100 strncpy(current->comm, argv[0], sizeof(current->comm));
101 current->pid = getpid();
105 ptl_nid_t tcpnal_mynid;
107 int init_lib_portals()
113 CERROR("PtlInit failed: error %d\n", rc);
117 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
119 int liblustre_ioctl(int dev_id, int opc, void *ptr)
125 fprintf(stderr, "Unexpected device id %d\n", dev_id);
130 rc = class_handle_ioctl(opc, (unsigned long)ptr);
137 static void generate_random_uuid(unsigned char uuid_out[16])
139 int *arr = (int*)uuid_out;
142 for (i = 0; i < sizeof(uuid_out)/sizeof(int); i++)
146 static char *echo_server_nid = NULL;
147 static char *echo_server_ostname = "obd1";
148 static char *osc_dev_name = "OSC_DEV_NAME";
149 static char *echo_dev_name = "ECHO_CLIENT_DEV_NAME";
151 static int connect_echo_client(void)
153 struct lustre_cfg *lcfg;
154 struct lustre_cfg_bufs bufs;
156 char *peer = "ECHO_PEER_NID";
157 class_uuid_t osc_uuid, echo_uuid;
158 struct obd_uuid osc_uuid_str, echo_uuid_str;
162 generate_random_uuid(osc_uuid);
163 class_uuid_unparse(osc_uuid, &osc_uuid_str);
164 generate_random_uuid(echo_uuid);
165 class_uuid_unparse(echo_uuid, &echo_uuid_str);
167 if (ptl_parse_nid(&nid, echo_server_nid)) {
168 CERROR("Can't parse NID %s\n", echo_server_nid);
171 nal = ptl_name2nal("tcp");
173 CERROR("Can't parse NAL tcp\n");
178 lustre_cfg_bufs_reset(&bufs, NULL);
179 lustre_cfg_bufs_set_string(&bufs, 1, peer);
180 lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs);
181 lcfg->lcfg_nid = nid;
182 lcfg->lcfg_nal = nal;
183 err = class_process_config(lcfg);
184 lustre_cfg_free(lcfg);
186 CERROR("failed add_uuid\n");
191 lustre_cfg_bufs_reset(&bufs, LUSTRE_OSC_NAME);
192 lustre_cfg_bufs_set_string(&bufs, 2, osc_uuid_str.uuid);
193 lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
194 err = class_process_config(lcfg);
195 lustre_cfg_free(lcfg);
197 CERROR("failed attach osc\n");
202 lustre_cfg_bufs_reset(&bufs, osc_dev_name);
203 lustre_cfg_bufs_set_string(&bufs, 1, echo_server_ostname);
204 lustre_cfg_bufs_set_string(&bufs, 2, peer);
205 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
206 err = class_process_config(lcfg);
207 lustre_cfg_free(lcfg);
209 CERROR("failed setup osc\n");
213 /* attach echo_client */
214 lustre_cfg_bufs_reset(&bufs, echo_dev_name);
215 lustre_cfg_bufs_set_string(&bufs, 1, "echo_client");
216 lustre_cfg_bufs_set_string(&bufs, 2, echo_uuid_str.uuid);
217 lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
218 err = class_process_config(lcfg);
219 lustre_cfg_free(lcfg);
221 CERROR("failed attach echo_client\n");
225 /* setup echo_client */
226 lustre_cfg_bufs_reset(&bufs, echo_dev_name);
227 lustre_cfg_bufs_set_string(&bufs, 1, osc_dev_name);
228 lustre_cfg_bufs_set_string(&bufs, 2, NULL);
229 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
230 err = class_process_config(lcfg);
231 lustre_cfg_free(lcfg);
233 CERROR("failed setup echo_client\n");
240 static int disconnect_echo_client(void)
242 struct lustre_cfg_bufs bufs;
243 struct lustre_cfg *lcfg = NULL;
247 /* cleanup echo_client */
248 lustre_cfg_bufs_reset(&bufs, echo_dev_name);
249 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
250 err = class_process_config(lcfg);
252 lustre_cfg_free(lcfg);
253 CERROR("failed cleanup echo_client\n");
257 /* detach echo_client */
258 lcfg->lcfg_command = LCFG_DETACH;
259 err = class_process_config(lcfg);
260 lustre_cfg_free(lcfg);
262 CERROR("failed detach echo_client\n");
267 lustre_cfg_bufs_reset(&bufs, osc_dev_name);
268 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
269 err = class_process_config(lcfg);
271 lustre_cfg_free(lcfg);
272 CERROR("failed cleanup osc device\n");
277 lcfg->lcfg_command = LCFG_DETACH;
278 err = class_process_config(lcfg);
279 lustre_cfg_free(lcfg);
281 CERROR("failed detach osc device\n");
288 static void usage(const char *s)
290 printf("Usage: %s -s ost_host_name [-n ost_name]\n", s);
291 printf(" ost_host_name: the host name of echo server\n");
292 printf(" ost_name: ost name, default is \"obd1\"\n");
295 extern int time_ptlwait1;
296 extern int time_ptlwait2;
297 extern int time_ptlselect;
299 int main(int argc, char **argv)
303 while ((c = getopt(argc, argv, "s:n:")) != -1) {
306 echo_server_nid = optarg;
309 echo_server_ostname = optarg;
320 if (!echo_server_nid) {
327 tcpnal_mynid = rand();
330 portal_subsystem_debug = 0;
333 if (init_current(argc, argv) ||
334 init_obdclass() || init_lib_portals() ||
340 echo_client_init()) {
345 rc = connect_echo_client();
349 set_ioc_handler(liblustre_ioctl);
351 rc = lctl_main(1, &argv[0]);
353 rc |= disconnect_echo_client();