[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re:[Qemu-devel] [PATCH v2] vhost-vsock: report QMP eventwhensetrunning
From: |
ning.bo9 |
Subject: |
Re:[Qemu-devel] [PATCH v2] vhost-vsock: report QMP eventwhensetrunning |
Date: |
Fri, 20 Dec 2019 10:38:12 +0800 (CST) |
> > There will be an additional problem if do this:
> > Who decides which port the `runtime` should listen?
>
> Let the host kernel automatically assign a port using VMADDR_PORT_ANY.
> It works like this:
>
> struct sockaddr_vm svm = {
> .svm_family = AF_VSOCK,
> .svm_port = VMADDR_PORT_ANY,
> .svm_cid = VMADDR_CID_ANY,
> };
>
> int fd = socket(AF_VSOCK, SOCK_STREAM, 0);
> ...
> if (bind(fd, (const struct sockaddr )&svm, sizeof(svm)) < 0) {
> ...
> }
>
> socklen_t socklen = sizeof(svm);
> if (getsockname(fd, (struct sockaddr *)&svm, &socklen) < 0) {
> ...
> }
>
> printf("cid %u port %u\n", svm.svm_cid, svm.svm_port);
>
> > Consider the worst case:
> > The ports selected by two `runtime` running in parallel always conflict,
> > and this case is unavoidable, even if we can reduce the possibility of
> > conflicts through algorithms.
> > Because we don't have a daemon that can allocate unique port to `runtime`.
>
> The kernel assigns unique ports and only fails if the entire port
> namespace is exhausted. The port namespace is 32-bits so this is not a
> real-world concern.
>
> Does this information clarify how the runtime can connect to the guest
> agent without loops or delays?
Thank you very much. I will do as you instructed above