static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg, int *fds, int fd_num) { CharDriverState *chr = dev->opaque; int size = VHOST_USER_HDR_SIZE + msg->size; if (fd_num) { qemu_chr_fe_set_msgfds(chr, fds, fd_num); } return qemu_chr_fe_write_all(chr, (const uint8_t *) msg, size) == size ? 0 : -1; }
/* most non-init callers ignore the error */ static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg, int *fds, int fd_num) { CharDriverState *chr = dev->opaque; int size = VHOST_USER_HDR_SIZE + msg->size; /* * For non-vring specific requests, like VHOST_USER_SET_MEM_TABLE, * we just need send it once in the first time. For later such * request, we just ignore it. */ if (vhost_user_one_time_request(msg->request) && dev->vq_index != 0) { return 0; } if (fd_num) { qemu_chr_fe_set_msgfds(chr, fds, fd_num); } return qemu_chr_fe_write_all(chr, (const uint8_t *) msg, size) == size ? 0 : -1; }
static int tpm_emulator_prepare_data_fd(TPMEmulator *tpm_emu) { ptm_res res; Error *err = NULL; int fds[2] = { -1, -1 }; if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) { error_report("tpm-emulator: Failed to create socketpair"); return -1; } qemu_chr_fe_set_msgfds(&tpm_emu->ctrl_chr, fds + 1, 1); if (tpm_emulator_ctrlcmd(tpm_emu, CMD_SET_DATAFD, &res, 0, sizeof(res)) < 0 || res != 0) { error_report("tpm-emulator: Failed to send CMD_SET_DATAFD: %s", strerror(errno)); goto err_exit; } tpm_emu->data_ioc = QIO_CHANNEL(qio_channel_socket_new_fd(fds[0], &err)); if (err) { error_prepend(&err, "tpm-emulator: Failed to create io channel: "); error_report_err(err); goto err_exit; } closesocket(fds[1]); return 0; err_exit: closesocket(fds[0]); closesocket(fds[1]); return -1; }