static boolean_t dlpi_walk_cb(const char *name, void *arg) { NOTE(ARGUNUSED(arg)) dlpi_handle_t dlh; link_t *link; int rc; dlpi_info_t info; boolean_t keep; size_t len; rc = dlpi_open(name, &dlh, DLPI_PASSIVE|DLPI_NATIVE); if (rc != DLPI_SUCCESS) { DMSG(D_NET, "dlpi_open(%s) failed: %s; skipping.", name, dlpi_strerror(rc)); return (B_TRUE); } rc = dlpi_info(dlh, &info, 0); if (rc != DLPI_SUCCESS) { DMSG(D_NET, "dlpi_info(%s) failed: %s; skipping.", name, dlpi_strerror(rc)); dlpi_close(dlh); return (B_TRUE); } keep = !!(info.di_mactype == DL_ETHER); DMSG(D_NET, "found link %s, mactype = %s (%d)%s.", name, dlpi_mactype(info.di_mactype), info.di_mactype, (keep) ? "" : "; discarding"); dlpi_close(dlh); if (!keep) return (B_TRUE); VERIFY((link = link_alloc(name)) != NULL); list_insert_tail(&links, (void *)link); num_links++; if ((len = strlen(name)) > link_max_len) link_max_len = len; return (B_TRUE); }
int gpuvm_link(void *hostptr, size_t nbytes, unsigned idev, void *devbuf, int flags) { //fprintf(stderr, "linking\n"); // check arguments if(!hostptr) { fprintf(stderr, "gpuvm_link: hostptr is NULL\n"); return GPUVM_ENULL; } if(nbytes == 0) { fprintf(stderr, "gpuvm_link: nbytes is zero\n"); return GPUVM_EARG; } if(idev >= ndevs_g) { fprintf(stderr, "gpuvm_link: invalid device number\n"); return GPUVM_EARG; } if((flags & ~GPUVM_API) != GPUVM_ON_HOST && (flags & ~GPUVM_API) != GPUVM_ON_DEVICE) { fprintf(stderr, "gpuvm_link: invalid flags\n"); return GPUVM_EARG; } if(!devbuf) { fprintf(stderr, "gpuvm_link: device buffer cannot be null\n"); return GPUVM_ENULL; } // lock writer data structure if(lock_writer()) return GPUVM_ERROR; // find an array intersecting specified range host_array_t *host_array = 0; if(host_array_find(&host_array, hostptr, nbytes)) { //fprintf(stderr, "gpuvm_link: intersecting range already registered with GPUVM\n"); //fprintf(stderr, "ptr=%p, nbytes=%zd, rangeptr=%p, rangenbytes=%zd\n", // hostptr, nbytes, host_array->range.ptr, host_array->range.nbytes); unlock_writer(); return GPUVM_ERANGE; } //fprintf(stderr, "host array search finished\n"); if(host_array) { if(host_array->links[idev]) { //fprintf(stderr, "gpuvm_link: link on specified device already exists\n"); unlock_writer(); return GPUVM_ELINK; } if(flags & GPUVM_ON_DEVICE) { //fprintf(stderr, "gpuvm_link: on-device linking of a registered " // "array is not allowed\n"); unlock_writer(); return GPUVM_ETWICE; } } // allocate an array if not found host_array_t *new_host_array = 0; int err = 0; if(!host_array) { err = host_array_alloc(&new_host_array, hostptr, nbytes, flags & GPUVM_ON_DEVICE ? idev : -1); //fprintf(stderr, "new host array allocated\n"); if(err) { unlock_writer(); return err; } host_array = new_host_array; } else { //fprintf(stderr, "using old host array\n"); } // create a link with an array (and assign it into the array) link_t *link = 0; err = link_alloc(&link, devbuf, idev, host_array); //fprintf(stderr, "new link allocated\n"); if(err) { host_array_free(new_host_array); unlock_writer(); return err; } if(unlock_writer()) return GPUVM_ERROR; //fprintf(stderr, "hostptr %p registered with libgpuvm\n", hostptr); return 0; } // gpuvm_link