static int fi_ibv_eq_close(fid_t fid) { struct fi_ibv_eq *eq; struct fi_ibv_eq_entry *entry; eq = container_of(fid, struct fi_ibv_eq, eq_fid.fid); if (eq->channel) rdma_destroy_event_channel(eq->channel); close(eq->epfd); fastlock_acquire(&eq->lock); while(!dlistfd_empty(&eq->list_head)) { entry = container_of(eq->list_head.list.next, struct fi_ibv_eq_entry, item); dlistfd_remove(eq->list_head.list.next, &eq->list_head); free(entry); } dlistfd_head_free(&eq->list_head); fastlock_destroy(&eq->lock); free(eq); return 0; }
static int fi_ibv_eq_close(fid_t fid) { struct fi_ibv_eq *eq; struct fi_ibv_eq_entry *entry; eq = container_of(fid, struct fi_ibv_eq, eq_fid.fid); /* TODO: use util code, if possible, and add ref counting */ if (eq->channel) rdma_destroy_event_channel(eq->channel); close(eq->epfd); while (!dlistfd_empty(&eq->list_head)) { entry = container_of(eq->list_head.list.next, struct fi_ibv_eq_entry, item); dlistfd_remove(eq->list_head.list.next, &eq->list_head); free(entry); } dlistfd_head_free(&eq->list_head); fastlock_destroy(&eq->lock); free(eq); return 0; }
int fi_ibv_eq_open(struct fid_fabric *fabric, struct fi_eq_attr *attr, struct fid_eq **eq, void *context) { struct fi_ibv_eq *_eq; struct epoll_event event; int ret; _eq = calloc(1, sizeof *_eq); if (!_eq) return -ENOMEM; _eq->fab = container_of(fabric, struct fi_ibv_fabric, fabric_fid); fastlock_init(&_eq->lock); ret = dlistfd_head_init(&_eq->list_head); if (ret) { FI_INFO(&fi_ibv_prov, FI_LOG_EQ, "Unable to initialize dlistfd\n"); goto err1; } _eq->epfd = epoll_create1(0); if (_eq->epfd < 0) { ret = -errno; goto err2; } memset(&event, 0, sizeof(event)); event.events = EPOLLIN; if (epoll_ctl(_eq->epfd, EPOLL_CTL_ADD, _eq->list_head.signal.fd[FI_READ_FD], &event)) { ret = -errno; goto err3; } switch (attr->wait_obj) { case FI_WAIT_NONE: case FI_WAIT_UNSPEC: case FI_WAIT_FD: _eq->channel = rdma_create_event_channel(); if (!_eq->channel) { ret = -errno; goto err3; } ret = fi_fd_nonblock(_eq->channel->fd); if (ret) goto err4; if (epoll_ctl(_eq->epfd, EPOLL_CTL_ADD, _eq->channel->fd, &event)) { ret = -errno; goto err4; } break; default: ret = -FI_ENOSYS; goto err1; } _eq->flags = attr->flags; _eq->eq_fid.fid.fclass = FI_CLASS_EQ; _eq->eq_fid.fid.context = context; _eq->eq_fid.fid.ops = &fi_ibv_eq_fi_ops; _eq->eq_fid.ops = &fi_ibv_eq_ops; *eq = &_eq->eq_fid; return 0; err4: if (_eq->channel) rdma_destroy_event_channel(_eq->channel); err3: close(_eq->epfd); err2: dlistfd_head_free(&_eq->list_head); err1: fastlock_destroy(&_eq->lock); free(_eq); return ret; }