Simplify the host and guest ids
BUG: 111000656
Change-Id: I54c612b38c10aa57839720db57d5d868271f0886
Test: Local build and boot on qemu-2.11+dfsg-1
(cherry picked from commit 522ce6108dbbc3f1e124977865b847530b285c30)
diff --git a/host/libs/ivserver/qemu_client.cc b/host/libs/ivserver/qemu_client.cc
index e3a5cde..c893f0f 100644
--- a/host/libs/ivserver/qemu_client.cc
+++ b/host/libs/ivserver/qemu_client.cc
@@ -65,7 +65,7 @@
// 3. The number -1, accompanied by the file descriptor for the shared
// memory.
- if (!SendSocketInfo(QemuFDMsg::kSharedMem, shmem.SharedMemFD())) {
+ if (!SendSocketInfo(kSharedMem, shmem.SharedMemFD())) {
LOG(ERROR) << "Failed to send Shared Memory socket: "
<< client_socket_->StrError();
return false;
@@ -79,7 +79,7 @@
// vectors, it closes the extra file descriptors. If it is configured
// for more, the extra vectors remain unconnected.
for (const auto region_data : shmem.Regions()) {
- if (!SendSocketInfo(QemuFDMsg::kHostSideHald, region_data.host_fd)) {
+ if (!SendSocketInfo(kHostID, region_data.host_fd)) {
LOG(ERROR) << "Failed to send Host Side FD for region "
<< region_data.device_name << ": " << client_socket_->StrError();
return false;
@@ -93,7 +93,7 @@
// the extra file descriptors. If it is configured for more, the
// extra vectors remain unconnected.
for (const auto region_data : shmem.Regions()) {
- if (!SendSocketInfo(QemuFDMsg::kGuestSideHal, region_data.guest_fd)) {
+ if (!SendSocketInfo(kGuestID, region_data.guest_fd)) {
LOG(ERROR) << "Failed to send Guest Side FD for region "
<< region_data.device_name << ": " << client_socket_->StrError();
return false;
@@ -104,7 +104,7 @@
return true;
}
-bool QemuClient::SendSocketInfo(QemuFDMsg message,
+bool QemuClient::SendSocketInfo(QemuConstants message,
const cvd::SharedFD& socket) {
struct iovec vec {
&message, sizeof(message)
diff --git a/host/libs/ivserver/qemu_client.h b/host/libs/ivserver/qemu_client.h
index 658b42c..2e0a7ee 100644
--- a/host/libs/ivserver/qemu_client.h
+++ b/host/libs/ivserver/qemu_client.h
@@ -37,28 +37,18 @@
private:
enum QemuConstants : int64_t {
kIvshMemProtocolVersion = 0,
+ // Marker for the shared memory file
+ kSharedMem = -1,
// HostID is in fact a Peer ID and can take multiple values, depending on
// how many subsystems we would like Guest to talk to.
- kHostBaseID = 0,
+ kHostID = 0,
// GuestID is a unique form of Peer ID (see above), that identifies newly
// created quest in IvSharedMem world.
- kGuestID = 1024
+ kGuestID = 1
};
- static_assert(QemuConstants::kHostBaseID < QemuConstants::kGuestID,
+ static_assert(QemuConstants::kHostID != QemuConstants::kGuestID,
"Guest and host should have different IDs");
- // Type of QEmu FD messages.
- // QEmu uses these messages to identify purpose of socket it is
- // receiving.
- enum class QemuFDMsg : int64_t {
- // Represents SharedMemory FD.
- kSharedMem = -1,
- // Represents primary (and currently only) FD that is owned and managed by
- // Host side.
- kHostSideHald = QemuConstants::kHostBaseID,
- // Represents FDs that are owned by Guest.
- kGuestSideHal = QemuConstants::kGuestID,
- };
cvd::SharedFD client_socket_;
@@ -70,7 +60,7 @@
bool PerformHandshake(const VSoCSharedMemory &shmem_fd);
// Send socket data to Qemu.
- bool SendSocketInfo(QemuFDMsg message, const cvd::SharedFD &socket);
+ bool SendSocketInfo(QemuConstants message, const cvd::SharedFD &socket);
QemuClient(const QemuClient &) = delete;
QemuClient &operator=(const QemuClient &) = delete;