+static int set_routes(struct lustre_mount_data *lmd) {
+ struct portals_cfg pcfg;
+ struct portal_ioctl_data data;
+ int i, j, route_exists, rc, err = 0;
+
+ register_ioc_dev(PORTALS_DEV_ID, PORTALS_DEV_PATH);
+
+ for (i = 0; i < route_index; i++) {
+
+ /* Check for existing routes so as not to add duplicates */
+ for (j = 0; ; j++) {
+ PCFG_INIT(pcfg, NAL_CMD_GET_ROUTE);
+ pcfg.pcfg_nal = ROUTER;
+ pcfg.pcfg_count = j;
+
+ PORTAL_IOC_INIT(data);
+ data.ioc_pbuf1 = (char*)&pcfg;
+ data.ioc_plen1 = sizeof(pcfg);
+ data.ioc_nid = pcfg.pcfg_nid;
+
+ rc = l_ioctl(PORTALS_DEV_ID, IOC_PORTAL_NAL_CMD, &data);
+ if (rc != 0) {
+ route_exists = 0;
+ break;
+ }
+
+ if ((pcfg.pcfg_gw_nal == lmd->lmd_nal) &&
+ (pcfg.pcfg_nid == routes[i].gw) &&
+ (pcfg.pcfg_nid2 == routes[i].lo) &&
+ (pcfg.pcfg_nid3 == routes[i].hi)) {
+ route_exists = 1;
+ break;
+ }
+ }
+
+ if (route_exists)
+ continue;
+
+ PCFG_INIT(pcfg, NAL_CMD_ADD_ROUTE);
+ pcfg.pcfg_nid = routes[i].gw;
+ pcfg.pcfg_nal = ROUTER;
+ pcfg.pcfg_gw_nal = lmd->lmd_nal;
+ pcfg.pcfg_nid2 = MIN(routes[i].lo, routes[i].hi);
+ pcfg.pcfg_nid3 = MAX(routes[i].lo, routes[i].hi);
+
+ PORTAL_IOC_INIT(data);
+ data.ioc_pbuf1 = (char*)&pcfg;
+ data.ioc_plen1 = sizeof(pcfg);
+ data.ioc_nid = pcfg.pcfg_nid;
+
+ rc = l_ioctl(PORTALS_DEV_ID, IOC_PORTAL_NAL_CMD, &data);
+ if (rc != 0) {
+ fprintf(stderr, "%s: Unable to add route "
+ "0x%llx : 0x%llx - 0x%llx\n[%d] %s\n",
+ progname, routes[i].gw, routes[i].lo,
+ routes[i].hi, errno, strerror(errno));
+ err = -1;
+ break;
+ }
+ }
+
+ unregister_ioc_dev(PORTALS_DEV_ID);
+ return err;
+}
+
+void usage(FILE *out)