Lines Matching full:msg

31 static void vfio_user_recycle(VFIOUserProxy *proxy, VFIOUserMsg *msg);
62 static ssize_t vfio_user_send_qio(VFIOUserProxy *proxy, VFIOUserMsg *msg, in vfio_user_send_qio() argument
65 VFIOUserFDs *fds = msg->fds; in vfio_user_send_qio()
67 .iov_base = msg->hdr, in vfio_user_send_qio()
68 .iov_len = msg->hdr->size, in vfio_user_send_qio()
82 vfio_user_set_error(msg->hdr, EIO); in vfio_user_send_qio()
85 trace_vfio_user_send_write(msg->hdr->id, ret); in vfio_user_send_qio()
93 VFIOUserMsg *msg; in vfio_user_getmsg() local
95 msg = QTAILQ_FIRST(&proxy->free); in vfio_user_getmsg()
96 if (msg != NULL) { in vfio_user_getmsg()
97 QTAILQ_REMOVE(&proxy->free, msg, next); in vfio_user_getmsg()
99 msg = g_malloc0(sizeof(*msg)); in vfio_user_getmsg()
100 qemu_cond_init(&msg->cv); in vfio_user_getmsg()
103 msg->hdr = hdr; in vfio_user_getmsg()
104 msg->fds = fds; in vfio_user_getmsg()
105 return msg; in vfio_user_getmsg()
111 static void vfio_user_recycle(VFIOUserProxy *proxy, VFIOUserMsg *msg) in vfio_user_recycle() argument
113 if (msg->type == VFIO_MSG_NONE) { in vfio_user_recycle()
114 error_printf("vfio_user_recycle - freeing free msg\n"); in vfio_user_recycle()
118 /* free msg buffer if no one is waiting to consume the reply */ in vfio_user_recycle()
119 if (msg->type == VFIO_MSG_NOWAIT || msg->type == VFIO_MSG_ASYNC) { in vfio_user_recycle()
120 g_free(msg->hdr); in vfio_user_recycle()
121 if (msg->fds != NULL) { in vfio_user_recycle()
122 g_free(msg->fds); in vfio_user_recycle()
126 msg->type = VFIO_MSG_NONE; in vfio_user_recycle()
127 msg->hdr = NULL; in vfio_user_recycle()
128 msg->fds = NULL; in vfio_user_recycle()
129 msg->complete = false; in vfio_user_recycle()
130 msg->pending = false; in vfio_user_recycle()
131 QTAILQ_INSERT_HEAD(&proxy->free, msg, next); in vfio_user_recycle()
150 static void vfio_user_process(VFIOUserProxy *proxy, VFIOUserMsg *msg, in vfio_user_process() argument
161 msg->complete = true; in vfio_user_process()
162 if (msg->type == VFIO_MSG_WAIT) { in vfio_user_process()
163 qemu_cond_signal(&msg->cv); in vfio_user_process()
165 if (msg->hdr->flags & VFIO_USER_ERROR) { in vfio_user_process()
168 msg->hdr->command, in vfio_user_process()
169 strerror(msg->hdr->error_reply)); in vfio_user_process()
171 /* youngest nowait msg has been ack'd */ in vfio_user_process()
172 if (proxy->last_nowait == msg) { in vfio_user_process()
175 vfio_user_recycle(proxy, msg); in vfio_user_process()
178 QTAILQ_INSERT_TAIL(&proxy->incoming, msg, next); in vfio_user_process()
188 VFIOUserMsg *msg = proxy->part_recv; in vfio_user_complete() local
194 data = (char *)msg->hdr + (msg->hdr->size - msgleft); in vfio_user_complete()
206 trace_vfio_user_recv_read(msg->hdr->id, ret); in vfio_user_complete()
217 isreply = (msg->hdr->flags & VFIO_USER_TYPE) == VFIO_USER_REPLY; in vfio_user_complete()
218 vfio_user_process(proxy, msg, isreply); in vfio_user_complete()
232 VFIOUserMsg *msg = NULL; in vfio_user_recv_one() local
260 /* else fall into reading another msg */ in vfio_user_recv_one()
308 QTAILQ_FOREACH(msg, &proxy->pending, next) { in vfio_user_recv_one()
309 if (hdr.id == msg->id) { in vfio_user_recv_one()
313 if (msg == NULL) { in vfio_user_recv_one()
317 QTAILQ_REMOVE(&proxy->pending, msg, next); in vfio_user_recv_one()
323 if (msg->fds == NULL || msg->fds->recv_fds < numfds) { in vfio_user_recv_one()
327 msg->fds->recv_fds = numfds; in vfio_user_recv_one()
328 memcpy(msg->fds->fds, fdp, numfds * sizeof(int)); in vfio_user_recv_one()
343 if (hdr.size > msg->rsize) { in vfio_user_recv_one()
347 *msg->hdr = hdr; in vfio_user_recv_one()
348 data = (char *)msg->hdr + sizeof(hdr); in vfio_user_recv_one()
357 msg = vfio_user_getmsg(proxy, (VFIOUserHdr *)buf, reqfds); in vfio_user_recv_one()
358 msg->type = VFIO_MSG_REQ; in vfio_user_recv_one()
370 proxy->part_recv = msg; in vfio_user_recv_one()
384 vfio_user_process(proxy, msg, isreply); in vfio_user_recv_one()
404 if (isreply && msg != NULL) { in vfio_user_recv_one()
406 vfio_user_set_error(msg->hdr, EINVAL); in vfio_user_recv_one()
407 msg->complete = true; in vfio_user_recv_one()
408 qemu_cond_signal(&msg->cv); in vfio_user_recv_one()
439 VFIOUserMsg *msg; in vfio_user_send_one() local
442 msg = QTAILQ_FIRST(&proxy->outgoing); in vfio_user_send_one()
443 ret = vfio_user_send_qio(proxy, msg, errp); in vfio_user_send_one()
448 QTAILQ_REMOVE(&proxy->outgoing, msg, next); in vfio_user_send_one()
450 if (msg->type == VFIO_MSG_ASYNC) { in vfio_user_send_one()
451 vfio_user_recycle(proxy, msg); in vfio_user_send_one()
453 QTAILQ_INSERT_TAIL(&proxy->pending, msg, next); in vfio_user_send_one()
454 msg->pending = true; in vfio_user_send_one()
513 * request(opaque, msg)
515 * and 'msg' is the inbound message.
527 VFIOUserMsg *msg, *m1; in vfio_user_request() local
532 QTAILQ_FOREACH_SAFE(msg, &proxy->incoming, next, m1) { in vfio_user_request()
533 QTAILQ_REMOVE(&proxy->incoming, msg, next); in vfio_user_request()
534 QTAILQ_INSERT_TAIL(&new, msg, next); in vfio_user_request()
540 QTAILQ_FOREACH_SAFE(msg, &new, next, m1) { in vfio_user_request()
541 QTAILQ_REMOVE(&new, msg, next); in vfio_user_request()
542 trace_vfio_user_recv_request(msg->hdr->command); in vfio_user_request()
543 proxy->request(proxy->req_arg, msg); in vfio_user_request()
544 QTAILQ_INSERT_HEAD(&free, msg, next); in vfio_user_request()
549 QTAILQ_FOREACH_SAFE(msg, &free, next, m1) { in vfio_user_request()
550 vfio_user_recycle(proxy, msg); in vfio_user_request()
584 static bool vfio_user_send_queued(VFIOUserProxy *proxy, VFIOUserMsg *msg, in vfio_user_send_queued() argument
591 ((msg->hdr->flags & VFIO_USER_TYPE) == VFIO_USER_REQUEST)) { in vfio_user_send_queued()
599 QTAILQ_INSERT_TAIL(&proxy->outgoing, msg, next); in vfio_user_send_queued()
610 ret = vfio_user_send_qio(proxy, msg, errp); in vfio_user_send_queued()
614 QTAILQ_INSERT_HEAD(&proxy->outgoing, msg, next); in vfio_user_send_queued()
628 if (msg->type == VFIO_MSG_ASYNC) { in vfio_user_send_queued()
629 vfio_user_recycle(proxy, msg); in vfio_user_send_queued()
631 QTAILQ_INSERT_TAIL(&proxy->pending, msg, next); in vfio_user_send_queued()
632 msg->pending = true; in vfio_user_send_queued()
650 VFIOUserMsg *msg; in vfio_user_send_nowait() local
654 msg = vfio_user_getmsg(proxy, hdr, fds); in vfio_user_send_nowait()
655 msg->id = hdr->id; in vfio_user_send_nowait()
656 msg->rsize = rsize ? rsize : hdr->size; in vfio_user_send_nowait()
657 msg->type = VFIO_MSG_NOWAIT; in vfio_user_send_nowait()
661 vfio_user_recycle(proxy, msg); in vfio_user_send_nowait()
665 if (!vfio_user_send_queued(proxy, msg, errp)) { in vfio_user_send_nowait()
666 vfio_user_recycle(proxy, msg); in vfio_user_send_nowait()
670 proxy->last_nowait = msg; in vfio_user_send_nowait()
684 VFIOUserMsg *msg; in vfio_user_send_wait() local
694 msg = vfio_user_getmsg(proxy, hdr, fds); in vfio_user_send_wait()
695 msg->id = hdr->id; in vfio_user_send_wait()
696 msg->rsize = rsize ? rsize : hdr->size; in vfio_user_send_wait()
697 msg->type = VFIO_MSG_WAIT; in vfio_user_send_wait()
699 ok = vfio_user_send_queued(proxy, msg, errp); in vfio_user_send_wait()
702 while (!msg->complete) { in vfio_user_send_wait()
703 if (!qemu_cond_timedwait(&msg->cv, &proxy->lock, in vfio_user_send_wait()
707 list = msg->pending ? &proxy->pending : &proxy->outgoing; in vfio_user_send_wait()
708 QTAILQ_REMOVE(list, msg, next); in vfio_user_send_wait()
717 vfio_user_recycle(proxy, msg); in vfio_user_send_wait()
725 * async send - msg can be queued, but will be freed when sent
735 VFIOUserMsg *msg; in vfio_user_send_async() local
739 msg = vfio_user_getmsg(proxy, hdr, fds); in vfio_user_send_async()
740 msg->id = hdr->id; in vfio_user_send_async()
741 msg->rsize = 0; in vfio_user_send_async()
742 msg->type = VFIO_MSG_ASYNC; in vfio_user_send_async()
746 vfio_user_recycle(proxy, msg); in vfio_user_send_async()
750 if (!vfio_user_send_queued(proxy, msg, errp)) { in vfio_user_send_async()
751 vfio_user_recycle(proxy, msg); in vfio_user_send_async()
760 VFIOUserMsg *msg; in vfio_user_wait_reqs() local
772 msg = proxy->last_nowait; in vfio_user_wait_reqs()
773 msg->type = VFIO_MSG_WAIT; in vfio_user_wait_reqs()
775 while (!msg->complete) { in vfio_user_wait_reqs()
776 if (!qemu_cond_timedwait(&msg->cv, &proxy->lock, in vfio_user_wait_reqs()
780 list = msg->pending ? &proxy->pending : &proxy->outgoing; in vfio_user_wait_reqs()
781 QTAILQ_REMOVE(list, msg, next); in vfio_user_wait_reqs()
787 if (msg->hdr->flags & VFIO_USER_ERROR) { in vfio_user_wait_reqs()
789 error_printf("request: command %x error %s\n", msg->hdr->command, in vfio_user_wait_reqs()
790 strerror(msg->hdr->error_reply)); in vfio_user_wait_reqs()
796 msg->type = VFIO_MSG_NOWAIT; in vfio_user_wait_reqs()
797 vfio_user_recycle(proxy, msg); in vfio_user_wait_reqs()
850 void vfio_user_putfds(VFIOUserMsg *msg) in vfio_user_putfds() argument
852 VFIOUserFDs *fds = msg->fds; in vfio_user_putfds()
859 msg->fds = NULL; in vfio_user_putfds()
929 void (*handler)(void *opaque, VFIOUserMsg *msg), in vfio_user_set_handler() argument
1310 VFIOUserMsg *msg; in vfio_user_flush_multi() local
1319 msg = vfio_user_getmsg(proxy, &wm->hdr, NULL); in vfio_user_flush_multi()
1320 msg->id = wm->hdr.id; in vfio_user_flush_multi()
1321 msg->rsize = 0; in vfio_user_flush_multi()
1322 msg->type = VFIO_MSG_ASYNC; in vfio_user_flush_multi()
1325 if (!vfio_user_send_queued(proxy, msg, &local_err)) { in vfio_user_flush_multi()
1327 vfio_user_recycle(proxy, msg); in vfio_user_flush_multi()