- int rc, pfd;
- struct portal_ioctl_data data;
- struct portals_cfg pcfg;
- unsigned int nid = 0, len;
- char *name = NULL;
- int c;
-
-
-
- while ((c = getopt(argc, argv, "n:l")) != -1) {
- switch(c) {
- case('n'):
- name = optarg;
- break;
- case('l'):
- printf("Get local id not implemented yet!\n");
- exit(-1);
- default:
- printf("usage %s -n nodename [-p]\n", argv[0]);
- }
- }
-
- if (!name) {
- printf("usage %s -n nodename [-p]\n", argv[0]);
- exit(-1);
- }
-
-
-
-
- PCFG_INIT(pcfg, GMNAL_IOC_GET_GNID);
- pcfg.pcfg_nal = GMNAL;
-
- /*
- * set up the inputs
- */
- len = strlen(name) + 1;
- pcfg.pcfg_pbuf1 = malloc(len);
- strcpy(pcfg.pcfg_pbuf1, name);
- pcfg.pcfg_plen1 = len;
-
- /*
- * set up the outputs
- */
- pcfg.pcfg_pbuf2 = (void*)&nid;
- pcfg.pcfg_plen2 = sizeof(unsigned int*);
-
- pfd = open("/dev/portals", O_RDWR);
- if ( pfd < 0 ) {
- perror("opening portals device");
- free(pcfg.pcfg_pbuf1);
- exit(-1);
+ struct gm_port *gm_port;
+ int gm_port_id;
+ gm_status_t gm_status;
+ unsigned int local_id;
+ unsigned int global_id;
+
+ gm_status = gm_init();
+ if (gm_status != GM_SUCCESS) {
+ fprintf(stderr, "gm_init: %s\n", gm_strerror(gm_status));
+ return gm_status;
+ }
+
+ gm_port_id = 2;
+ gm_status = gm_open(&gm_port, GM_UNIT, gm_port_id, "gmnalnid",
+ GM_API_VERSION);
+ if (gm_status != GM_SUCCESS) {
+ int num_ports = gm_num_ports(gm_port);
+
+ /* Couldn't open port 2, try 4 ... num_ports */
+ for (gm_port_id = 4; gm_port_id < num_ports; gm_port_id++) {
+ gm_status = gm_open(&gm_port, GM_UNIT, gm_port_id,
+ "gmnalnid", GM_API_VERSION);
+ if (gm_status == GM_SUCCESS)
+ break;
+ }
+
+ if (gm_status != GM_SUCCESS) {
+ fprintf(stderr, "gm_open: %s\n",gm_strerror(gm_status));
+ goto out_0;
+ }
+ }
+
+ if (name == NULL) {
+ local_id = 1;
+ name = "<local>";
+ } else {
+ gm_status = gm_host_name_to_node_id_ex(gm_port, 1000000, name,
+ &local_id);
+ if (gm_status != GM_SUCCESS) {
+ fprintf(stderr, "gm_host_name_to_node_id_ex(%s): %s\n",
+ name, gm_strerror(gm_status));
+ goto out_1;
+ }