| 855 | } |
| 856 | |
| 857 | static int |
| 858 | mp_request_async(const char *dst, struct rte_mp_msg *req, |
| 859 | struct async_request_param *param, const struct timespec *ts) |
| 860 | { |
| 861 | struct rte_mp_msg *reply_msg; |
| 862 | struct pending_request *pending_req, *exist; |
| 863 | int ret = -1; |
| 864 | |
| 865 | pending_req = calloc(1, sizeof(*pending_req)); |
| 866 | reply_msg = calloc(1, sizeof(*reply_msg)); |
| 867 | if (pending_req == NULL || reply_msg == NULL) { |
| 868 | RTE_LOG(ERR, EAL, "Could not allocate space for sync request\n"); |
| 869 | rte_errno = ENOMEM; |
| 870 | ret = -1; |
| 871 | goto fail; |
| 872 | } |
| 873 | |
| 874 | pending_req->type = REQUEST_TYPE_ASYNC; |
| 875 | strlcpy(pending_req->dst, dst, sizeof(pending_req->dst)); |
| 876 | pending_req->request = req; |
| 877 | pending_req->reply = reply_msg; |
| 878 | pending_req->async.param = param; |
| 879 | |
| 880 | /* queue already locked by caller */ |
| 881 | |
| 882 | exist = find_pending_request(dst, req->name); |
| 883 | if (exist) { |
| 884 | RTE_LOG(ERR, EAL, "A pending request %s:%s\n", dst, req->name); |
| 885 | rte_errno = EEXIST; |
| 886 | ret = -1; |
| 887 | goto fail; |
| 888 | } |
| 889 | |
| 890 | ret = send_msg(dst, req, MP_REQ); |
| 891 | if (ret < 0) { |
| 892 | RTE_LOG(ERR, EAL, "Fail to send request %s:%s\n", |
| 893 | dst, req->name); |
| 894 | ret = -1; |
| 895 | goto fail; |
| 896 | } else if (ret == 0) { |
| 897 | ret = 0; |
| 898 | goto fail; |
| 899 | } |
| 900 | param->user_reply.nb_sent++; |
| 901 | |
| 902 | /* if alarm set fails, we simply ignore the reply */ |
| 903 | if (rte_eal_alarm_set(ts->tv_sec * 1000000 + ts->tv_nsec / 1000, |
| 904 | async_reply_handle, pending_req) < 0) { |
| 905 | RTE_LOG(ERR, EAL, "Fail to set alarm for request %s:%s\n", |
| 906 | dst, req->name); |
| 907 | ret = -1; |
| 908 | goto fail; |
| 909 | } |
| 910 | TAILQ_INSERT_TAIL(&pending_requests.requests, pending_req, next); |
| 911 | |
| 912 | return 0; |
| 913 | fail: |
| 914 | free(pending_req); |
no test coverage detected