static int util_wait_fd_close(struct fid *fid) { struct util_wait_fd *wait; struct ofi_wait_fd_entry *fd_entry; int ret; wait = container_of(fid, struct util_wait_fd, util_wait.wait_fid.fid); ret = fi_wait_cleanup(&wait->util_wait); if (ret) return ret; fastlock_acquire(&wait->lock); while (!dlist_empty(&wait->fd_list)) { dlist_pop_front(&wait->fd_list, struct ofi_wait_fd_entry, fd_entry, entry); fi_epoll_del(wait->epoll_fd, fd_entry->fd); free(fd_entry); } fastlock_release(&wait->lock); fi_epoll_del(wait->epoll_fd, wait->signal.fd[FI_READ_FD]); fd_signal_free(&wait->signal); fi_epoll_close(wait->epoll_fd); fastlock_destroy(&wait->lock); free(wait); return 0; }
int ofi_wait_fd_del(struct util_wait *wait, int fd) { int ret = 0; struct ofi_wait_fd_entry *fd_entry; struct dlist_entry *entry; struct util_wait_fd *wait_fd = container_of(wait, struct util_wait_fd, util_wait); fastlock_acquire(&wait_fd->lock); entry = dlist_find_first_match(&wait_fd->fd_list, ofi_wait_fd_match, &fd); if (!entry) { FI_INFO(wait->prov, FI_LOG_FABRIC, "Given fd (%d) not found in wait list - %p\n", fd, wait_fd); ret = -FI_EINVAL; goto out; } fd_entry = container_of(entry, struct ofi_wait_fd_entry, entry); if (ofi_atomic_dec32(&fd_entry->ref)) goto out; dlist_remove(&fd_entry->entry); fi_epoll_del(wait_fd->epoll_fd, fd_entry->fd); free(fd_entry); out: fastlock_release(&wait_fd->lock); return ret; }
void sock_conn_release_entry(struct sock_conn_map *map, struct sock_conn *conn) { fi_epoll_del(map->epoll_set, conn->sock_fd); ofi_close_socket(conn->sock_fd); conn->address_published = 0; conn->connected = 0; conn->sock_fd = -1; }
static int util_wait_fd_close(struct fid *fid) { struct util_wait_fd *wait; int ret; wait = container_of(fid, struct util_wait_fd, util_wait.wait_fid.fid); ret = fi_wait_cleanup(&wait->util_wait); if (ret) return ret; fi_epoll_del(wait->epoll_fd, wait->signal.fd[FI_READ_FD]); fd_signal_free(&wait->signal); fi_epoll_close(wait->epoll_fd); free(wait); return 0; }
static int udpx_ep_close(struct fid *fid) { struct udpx_ep *ep; struct util_wait_fd *wait; ep = container_of(fid, struct udpx_ep, util_ep.ep_fid.fid); if (ep->util_ep.rx_cq) { if (ep->util_ep.rx_cq->wait) { wait = container_of(ep->util_ep.rx_cq->wait, struct util_wait_fd, util_wait); fi_epoll_del(wait->epoll_fd, ep->sock); } fid_list_remove(&ep->util_ep.rx_cq->ep_list, &ep->util_ep.rx_cq->ep_list_lock, &ep->util_ep.ep_fid.fid); atomic_dec(&ep->util_ep.rx_cq->ref); }
int ofi_wait_fd_add(struct util_wait *wait, int fd, uint32_t events, ofi_wait_fd_try_func wait_try, void *arg, void *context) { struct ofi_wait_fd_entry *fd_entry; struct dlist_entry *entry; struct util_wait_fd *wait_fd = container_of(wait, struct util_wait_fd, util_wait); int ret = 0; fastlock_acquire(&wait_fd->lock); entry = dlist_find_first_match(&wait_fd->fd_list, ofi_wait_fd_match, &fd); if (entry) { FI_DBG(wait->prov, FI_LOG_EP_CTRL, "Given fd (%d) already added to wait list - %p \n", fd, wait_fd); fd_entry = container_of(entry, struct ofi_wait_fd_entry, entry); ofi_atomic_inc32(&fd_entry->ref); goto out; } ret = fi_epoll_add(wait_fd->epoll_fd, fd, events, context); if (ret) { FI_WARN(wait->prov, FI_LOG_FABRIC, "Unable to add fd to epoll\n"); goto out; } fd_entry = calloc(1, sizeof *fd_entry); if (!fd_entry) { ret = -FI_ENOMEM; fi_epoll_del(wait_fd->epoll_fd, fd); goto out; } fd_entry->fd = fd; fd_entry->wait_try = wait_try; fd_entry->arg = arg; ofi_atomic_initialize32(&fd_entry->ref, 1); dlist_insert_tail(&fd_entry->entry, &wait_fd->fd_list); out: fastlock_release(&wait_fd->lock); return ret; }
static int sock_ep_close(struct fid *fid) { struct sock_ep *sock_ep; char c = 0; switch (fid->fclass) { case FI_CLASS_EP: sock_ep = container_of(fid, struct sock_ep, ep.fid); break; case FI_CLASS_SEP: sock_ep = container_of(fid, struct sock_ep, ep.fid); break; default: return -FI_EINVAL; } if (sock_ep->is_alias) { ofi_atomic_dec32(&sock_ep->attr->ref); return 0; } if (ofi_atomic_get32(&sock_ep->attr->ref) || ofi_atomic_get32(&sock_ep->attr->num_rx_ctx) || ofi_atomic_get32(&sock_ep->attr->num_tx_ctx)) return -FI_EBUSY; if (sock_ep->attr->ep_type == FI_EP_MSG) { sock_ep->attr->cm.do_listen = 0; if (ofi_write_socket(sock_ep->attr->cm.signal_fds[0], &c, 1) != 1) SOCK_LOG_DBG("Failed to signal\n"); if (sock_ep->attr->cm.listener_thread && pthread_join(sock_ep->attr->cm.listener_thread, NULL)) { SOCK_LOG_ERROR("pthread join failed (%d)\n", ofi_syserr()); } ofi_close_socket(sock_ep->attr->cm.signal_fds[0]); ofi_close_socket(sock_ep->attr->cm.signal_fds[1]); } else { if (sock_ep->attr->av) ofi_atomic_dec32(&sock_ep->attr->av->ref); } if (sock_ep->attr->av) { fastlock_acquire(&sock_ep->attr->av->list_lock); fid_list_remove(&sock_ep->attr->av->ep_list, &sock_ep->attr->lock, &sock_ep->ep.fid); fastlock_release(&sock_ep->attr->av->list_lock); } pthread_mutex_lock(&sock_ep->attr->domain->pe->list_lock); if (sock_ep->attr->tx_shared) { fastlock_acquire(&sock_ep->attr->tx_ctx->lock); dlist_remove(&sock_ep->attr->tx_ctx_entry); fastlock_release(&sock_ep->attr->tx_ctx->lock); } if (sock_ep->attr->rx_shared) { fastlock_acquire(&sock_ep->attr->rx_ctx->lock); dlist_remove(&sock_ep->attr->rx_ctx_entry); fastlock_release(&sock_ep->attr->rx_ctx->lock); } pthread_mutex_unlock(&sock_ep->attr->domain->pe->list_lock); if (sock_ep->attr->conn_handle.do_listen) { fastlock_acquire(&sock_ep->attr->domain->conn_listener.signal_lock); fi_epoll_del(sock_ep->attr->domain->conn_listener.emap, sock_ep->attr->conn_handle.sock); fastlock_release(&sock_ep->attr->domain->conn_listener.signal_lock); ofi_close_socket(sock_ep->attr->conn_handle.sock); sock_ep->attr->conn_handle.do_listen = 0; } fastlock_destroy(&sock_ep->attr->cm.lock); if (sock_ep->attr->eq) { fastlock_acquire(&sock_ep->attr->eq->lock); sock_ep_clear_eq_list(&sock_ep->attr->eq->list, &sock_ep->ep); /* Any err_data if present would be freed by * sock_eq_clean_err_data_list when EQ is closed */ sock_ep_clear_eq_list(&sock_ep->attr->eq->err_list, &sock_ep->ep); fastlock_release(&sock_ep->attr->eq->lock); } if (sock_ep->attr->fclass != FI_CLASS_SEP) { if (!sock_ep->attr->tx_shared) sock_pe_remove_tx_ctx(sock_ep->attr->tx_array[0]); sock_tx_ctx_close(sock_ep->attr->tx_array[0]); sock_tx_ctx_free(sock_ep->attr->tx_array[0]); } if (sock_ep->attr->fclass != FI_CLASS_SEP) { if (!sock_ep->attr->rx_shared) sock_pe_remove_rx_ctx(sock_ep->attr->rx_array[0]); sock_rx_ctx_close(sock_ep->attr->rx_array[0]); sock_rx_ctx_free(sock_ep->attr->rx_array[0]); } free(sock_ep->attr->tx_array); free(sock_ep->attr->rx_array); if (sock_ep->attr->src_addr) free(sock_ep->attr->src_addr); if (sock_ep->attr->dest_addr) free(sock_ep->attr->dest_addr); fastlock_acquire(&sock_ep->attr->domain->pe->lock); ofi_idm_reset(&sock_ep->attr->av_idm); sock_conn_map_destroy(sock_ep->attr); fastlock_release(&sock_ep->attr->domain->pe->lock); ofi_atomic_dec32(&sock_ep->attr->domain->ref); fastlock_destroy(&sock_ep->attr->lock); free(sock_ep->attr); free(sock_ep); return 0; }