2017-10-31 08:07:16 +00:00
|
|
|
/*
|
2017-12-03 15:22:49 +00:00
|
|
|
Looking Glass - KVM FrameRelay (KVMFR) Client
|
2017-10-31 08:07:16 +00:00
|
|
|
Copyright (C) 2017 Geoffrey McRae <geoff@hostfission.com>
|
2017-12-11 17:30:47 +00:00
|
|
|
https://looking-glass.hostfission.com
|
2017-10-31 08:07:16 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
|
|
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
|
|
Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2017-10-19 05:00:57 +00:00
|
|
|
#include "ivshmem.h"
|
|
|
|
#include "debug.h"
|
|
|
|
|
2017-10-19 06:54:00 +00:00
|
|
|
#include <stdlib.h>
|
2017-10-19 05:00:57 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
2017-10-19 14:03:39 +00:00
|
|
|
#include <errno.h>
|
2017-10-19 05:00:57 +00:00
|
|
|
|
2017-10-19 06:06:42 +00:00
|
|
|
#include <sys/stat.h>
|
2017-10-19 05:00:57 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
|
2017-10-19 06:06:42 +00:00
|
|
|
#include <sys/mman.h>
|
|
|
|
|
2017-10-19 06:54:00 +00:00
|
|
|
#define MAX_IRQS 32
|
|
|
|
|
2017-10-19 06:06:42 +00:00
|
|
|
struct IVSHMEMServer
|
|
|
|
{
|
|
|
|
int64_t version;
|
|
|
|
int64_t clientID;
|
|
|
|
int sharedFD;
|
2017-10-19 06:54:00 +00:00
|
|
|
|
|
|
|
int irqs[MAX_IRQS];
|
|
|
|
int irqCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct IVSHMEMClient
|
|
|
|
{
|
|
|
|
uint16_t clientID;
|
|
|
|
|
|
|
|
int irqs[MAX_IRQS];
|
|
|
|
int irqCount;
|
|
|
|
|
|
|
|
struct IVSHMEMClient * last;
|
|
|
|
struct IVSHMEMClient * next;
|
2017-10-19 06:06:42 +00:00
|
|
|
};
|
|
|
|
|
2017-10-19 05:00:57 +00:00
|
|
|
struct IVSHMEM
|
|
|
|
{
|
2017-10-19 06:54:00 +00:00
|
|
|
bool connected;
|
2017-10-19 07:50:42 +00:00
|
|
|
bool shutdown;
|
2017-10-19 06:54:00 +00:00
|
|
|
int socket;
|
|
|
|
struct IVSHMEMServer server;
|
|
|
|
struct IVSHMEMClient * clients;
|
2017-10-19 06:06:42 +00:00
|
|
|
|
|
|
|
off_t mapSize;
|
2017-10-29 02:06:41 +00:00
|
|
|
void * map;
|
2017-10-19 05:00:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct IVSHMEM ivshmem =
|
|
|
|
{
|
|
|
|
.connected = false,
|
2017-10-19 07:50:42 +00:00
|
|
|
.shutdown = false,
|
2017-10-19 05:00:57 +00:00
|
|
|
.socket = -1
|
|
|
|
};
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// internal functions
|
|
|
|
|
|
|
|
void ivshmem_cleanup();
|
|
|
|
bool ivshmem_read(void * buffer, const ssize_t size);
|
2017-10-19 06:06:42 +00:00
|
|
|
bool ivshmem_read_msg(int64_t * index, int *fd);
|
2017-10-19 06:54:00 +00:00
|
|
|
struct IVSHMEMClient * ivshmem_get_client(uint16_t clientID);
|
|
|
|
void ivshmem_remove_client(struct IVSHMEMClient * client);
|
2017-10-19 05:00:57 +00:00
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
bool ivshmem_connect(const char * unix_socket)
|
|
|
|
{
|
2017-10-19 07:50:42 +00:00
|
|
|
ivshmem.shutdown = false;
|
2017-10-19 05:00:57 +00:00
|
|
|
ivshmem.socket = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
|
|
if (ivshmem.socket < 0)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("socket creation failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sockaddr_un addr;
|
|
|
|
addr.sun_family = AF_UNIX;
|
|
|
|
strncpy(addr.sun_path, unix_socket, sizeof(addr.sun_path));
|
|
|
|
|
|
|
|
if (connect(ivshmem.socket, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("socket connect failed");
|
|
|
|
ivshmem_cleanup();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ivshmem.connected = true;
|
|
|
|
|
2017-10-19 06:06:42 +00:00
|
|
|
if (!ivshmem_read(&ivshmem.server.version, sizeof(ivshmem.server.version)))
|
2017-10-19 05:00:57 +00:00
|
|
|
{
|
|
|
|
DEBUG_ERROR("read protocol version failed");
|
|
|
|
ivshmem_cleanup();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-19 06:06:42 +00:00
|
|
|
if (ivshmem.server.version != 0)
|
2017-10-19 05:00:57 +00:00
|
|
|
{
|
2017-10-19 06:06:42 +00:00
|
|
|
DEBUG_ERROR("unsupported protocol version %ld", ivshmem.server.version);
|
2017-10-19 05:00:57 +00:00
|
|
|
ivshmem_cleanup();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-19 06:06:42 +00:00
|
|
|
if (!ivshmem_read(&ivshmem.server.clientID, sizeof(ivshmem.server.clientID)))
|
2017-10-19 05:00:57 +00:00
|
|
|
{
|
|
|
|
DEBUG_ERROR("read client id failed");
|
|
|
|
ivshmem_cleanup();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-19 06:06:42 +00:00
|
|
|
DEBUG_PROTO("Protocol : %ld", ivshmem.server.version );
|
|
|
|
DEBUG_PROTO("Client ID: %ld", ivshmem.server.clientID);
|
|
|
|
|
|
|
|
if (!ivshmem_read_msg(NULL, &ivshmem.server.sharedFD))
|
2017-10-19 05:00:57 +00:00
|
|
|
{
|
2017-10-19 06:06:42 +00:00
|
|
|
DEBUG_ERROR("failed to read shared memory file descriptor");
|
2017-10-19 05:00:57 +00:00
|
|
|
ivshmem_cleanup();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-19 06:06:42 +00:00
|
|
|
struct stat stat;
|
|
|
|
if (fstat(ivshmem.server.sharedFD, &stat) != 0)
|
2017-10-19 05:00:57 +00:00
|
|
|
{
|
2017-10-19 06:06:42 +00:00
|
|
|
DEBUG_ERROR("failed to stat shared FD");
|
2017-10-19 05:00:57 +00:00
|
|
|
ivshmem_cleanup();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-19 06:06:42 +00:00
|
|
|
ivshmem.mapSize = stat.st_size;
|
|
|
|
|
|
|
|
DEBUG_INFO("RAM Size : %ld", ivshmem.mapSize);
|
|
|
|
ivshmem.map = mmap(
|
|
|
|
NULL,
|
|
|
|
stat.st_size,
|
|
|
|
PROT_READ | PROT_WRITE,
|
|
|
|
MAP_SHARED,
|
|
|
|
ivshmem.server.sharedFD,
|
|
|
|
0);
|
|
|
|
|
|
|
|
if (!ivshmem.map)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("failed to map memory");
|
|
|
|
ivshmem_cleanup();
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-19 05:00:57 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
void ivshmem_cleanup()
|
|
|
|
{
|
2017-10-19 06:54:00 +00:00
|
|
|
struct IVSHMEMClient * client, * next;
|
|
|
|
client = ivshmem.clients;
|
|
|
|
while(client)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < client->irqCount; ++i)
|
|
|
|
close(client->irqs[i]);
|
|
|
|
|
|
|
|
next = client->next;
|
|
|
|
free(client);
|
|
|
|
client = next;
|
|
|
|
}
|
|
|
|
ivshmem.clients = NULL;
|
|
|
|
|
|
|
|
for(int i = 0; i < ivshmem.server.irqCount; ++i)
|
|
|
|
close(ivshmem.server.irqs[i]);
|
|
|
|
ivshmem.server.irqCount = 0;
|
|
|
|
|
2017-10-19 06:06:42 +00:00
|
|
|
if (ivshmem.map)
|
|
|
|
munmap(ivshmem.map, ivshmem.mapSize);
|
|
|
|
ivshmem.map = NULL;
|
|
|
|
ivshmem.mapSize = 0;
|
|
|
|
|
2017-10-19 05:00:57 +00:00
|
|
|
if (ivshmem.socket >= 0)
|
|
|
|
{
|
2017-10-19 07:50:42 +00:00
|
|
|
ivshmem.shutdown = true;
|
|
|
|
shutdown(ivshmem.socket, SHUT_RDWR);
|
2017-10-19 05:00:57 +00:00
|
|
|
close(ivshmem.socket);
|
|
|
|
ivshmem.socket = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ivshmem.connected = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
2017-10-19 07:50:42 +00:00
|
|
|
void ivshmem_disconnect()
|
2017-10-19 05:00:57 +00:00
|
|
|
{
|
|
|
|
if (!ivshmem.connected)
|
|
|
|
{
|
|
|
|
DEBUG_WARN("socket not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ivshmem_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
bool ivshmem_read(void * buffer, const ssize_t size)
|
|
|
|
{
|
|
|
|
if (!ivshmem.connected)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t len = read(ivshmem.socket, buffer, size);
|
|
|
|
if (len != size)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("incomplete read");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2017-10-19 06:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
bool ivshmem_read_msg(int64_t * index, int * fd)
|
|
|
|
{
|
|
|
|
if (!ivshmem.connected)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct msghdr msg;
|
|
|
|
struct iovec iov[1];
|
|
|
|
union {
|
|
|
|
struct cmsghdr cmsg;
|
|
|
|
char control[CMSG_SPACE(sizeof(int))];
|
|
|
|
} msg_control;
|
|
|
|
|
|
|
|
int64_t tmp;
|
|
|
|
if (!index)
|
|
|
|
index = &tmp;
|
|
|
|
|
|
|
|
iov[0].iov_base = index;
|
|
|
|
iov[0].iov_len = sizeof(*index);
|
|
|
|
|
|
|
|
memset(&msg, 0, sizeof(msg));
|
|
|
|
msg.msg_iov = iov;
|
|
|
|
msg.msg_iovlen = 1;
|
|
|
|
msg.msg_control = &msg_control;
|
|
|
|
msg.msg_controllen = sizeof(msg_control);
|
|
|
|
|
|
|
|
int ret = recvmsg(ivshmem.socket, &msg, 0);
|
|
|
|
if (ret < sizeof(*index))
|
|
|
|
{
|
2017-10-19 07:50:42 +00:00
|
|
|
if (!ivshmem.shutdown)
|
|
|
|
DEBUG_ERROR("failed to read message\n");
|
2017-10-19 06:06:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
2017-10-19 07:50:42 +00:00
|
|
|
if (!ivshmem.shutdown)
|
|
|
|
DEBUG_ERROR("lost connetion to server\n");
|
2017-10-19 06:06:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fd)
|
|
|
|
return true;
|
|
|
|
|
2017-10-19 14:03:39 +00:00
|
|
|
*fd = -1;
|
2017-10-19 06:06:42 +00:00
|
|
|
struct cmsghdr *cmsg;
|
|
|
|
for(cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg))
|
|
|
|
{
|
|
|
|
if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)) ||
|
|
|
|
cmsg->cmsg_level != SOL_SOCKET ||
|
|
|
|
cmsg->cmsg_type != SCM_RIGHTS)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-10-26 04:18:57 +00:00
|
|
|
memcpy(fd, CMSG_DATA(cmsg), sizeof(int));
|
2017-10-19 06:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-19 14:03:39 +00:00
|
|
|
// ============================================================================
|
|
|
|
|
2017-10-19 07:50:42 +00:00
|
|
|
uint16_t ivshmem_get_id()
|
|
|
|
{
|
|
|
|
if (!ivshmem.connected)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("not connected");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ivshmem.server.clientID;
|
|
|
|
}
|
|
|
|
|
2017-10-19 06:06:42 +00:00
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
void * ivshmem_get_map()
|
|
|
|
{
|
|
|
|
if (!ivshmem.connected)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("not connected");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ivshmem.map)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("not mapped");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ivshmem.map;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
size_t ivshmem_get_map_size()
|
|
|
|
{
|
|
|
|
if (!ivshmem.connected)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("not connected");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ivshmem.map)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("not mapped");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ivshmem.mapSize;
|
2017-10-19 06:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
struct IVSHMEMClient * ivshmem_get_client(uint16_t clientID)
|
|
|
|
{
|
|
|
|
struct IVSHMEMClient * client = NULL;
|
|
|
|
|
|
|
|
if (ivshmem.clients == NULL)
|
|
|
|
{
|
|
|
|
client = (struct IVSHMEMClient *)malloc(sizeof(struct IVSHMEMClient));
|
|
|
|
client->clientID = clientID;
|
|
|
|
client->last = NULL;
|
|
|
|
client->next = NULL;
|
|
|
|
client->irqCount = 0;
|
|
|
|
ivshmem.clients = client;
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
|
|
|
client = ivshmem.clients;
|
|
|
|
while(client)
|
|
|
|
{
|
|
|
|
if (client->clientID == clientID)
|
|
|
|
return client;
|
|
|
|
client = client->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
client = (struct IVSHMEMClient *)malloc(sizeof(struct IVSHMEMClient));
|
|
|
|
client->clientID = clientID;
|
|
|
|
client->last = NULL;
|
|
|
|
client->next = ivshmem.clients;
|
|
|
|
client->irqCount = 0;
|
|
|
|
client->next->last = client;
|
|
|
|
ivshmem.clients = client;
|
|
|
|
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
void ivshmem_remove_client(struct IVSHMEMClient * client)
|
|
|
|
{
|
|
|
|
if (client->last)
|
|
|
|
client->last->next = client->next;
|
|
|
|
|
|
|
|
if (client->next)
|
|
|
|
client->next->last = client->last;
|
|
|
|
|
|
|
|
if (ivshmem.clients == client)
|
2017-10-29 02:06:41 +00:00
|
|
|
ivshmem.clients = client->next;
|
2017-10-19 06:54:00 +00:00
|
|
|
|
|
|
|
free(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
bool ivshmem_process()
|
|
|
|
{
|
|
|
|
int64_t index;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
if (!ivshmem_read_msg(&index, &fd))
|
|
|
|
{
|
2017-10-19 07:50:42 +00:00
|
|
|
if (!ivshmem.shutdown)
|
|
|
|
DEBUG_ERROR("failed to read message");
|
2017-10-19 06:54:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index == -1)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("invalid index -1");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index > 0xFFFF)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("invalid index > 0xFFFF");
|
2017-10-29 02:06:41 +00:00
|
|
|
return false;
|
2017-10-19 06:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (index == ivshmem.server.clientID)
|
|
|
|
{
|
|
|
|
if (fd == -1)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("server sent disconnect");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ivshmem.server.irqCount == MAX_IRQS)
|
|
|
|
{
|
|
|
|
DEBUG_WARN("maximum IRQs reached, closing extra");
|
|
|
|
close(fd);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ivshmem.server.irqs[ivshmem.server.irqCount++] = fd;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct IVSHMEMClient * client = ivshmem_get_client(index);
|
|
|
|
if (!client)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("failed to get/create client record");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fd == -1)
|
|
|
|
{
|
|
|
|
DEBUG_PROTO("remove client %u", client->clientID);
|
|
|
|
ivshmem_remove_client(client);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (client->irqCount == MAX_IRQS)
|
|
|
|
{
|
|
|
|
DEBUG_WARN("maximum client IRQs reached, closing extra");
|
|
|
|
close(fd);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
client->irqs[client->irqCount++] = fd;
|
|
|
|
return true;
|
2017-10-19 14:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
2017-12-05 10:50:24 +00:00
|
|
|
enum IVSHMEMWaitResult ivshmem_wait_irq(uint16_t vector, unsigned int timeout)
|
2017-10-19 14:03:39 +00:00
|
|
|
{
|
|
|
|
if (vector > ivshmem.server.irqCount - 1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int fd = ivshmem.server.irqs[vector];
|
|
|
|
fd_set fds;
|
|
|
|
FD_ZERO(&fds);
|
|
|
|
FD_SET(fd, &fds);
|
|
|
|
|
2017-12-05 10:50:24 +00:00
|
|
|
struct timeval tv;
|
2017-12-06 17:51:54 +00:00
|
|
|
tv.tv_sec = timeout / 1000000L;
|
|
|
|
tv.tv_usec = timeout % 1000000L;
|
2017-10-19 14:03:39 +00:00
|
|
|
|
|
|
|
while(true)
|
|
|
|
{
|
2017-12-05 10:50:24 +00:00
|
|
|
int ret = select(fd+1, &fds, NULL, NULL, &tv);
|
2017-10-19 14:03:39 +00:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
if (errno == EINTR)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
DEBUG_ERROR("select error");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
return IVSHMEM_WAIT_RESULT_TIMEOUT;
|
|
|
|
|
|
|
|
if (FD_ISSET(fd, &fds))
|
|
|
|
{
|
|
|
|
uint64_t kick;
|
2017-12-14 13:57:49 +00:00
|
|
|
int unused = read(fd, &kick, sizeof(kick));
|
|
|
|
(void)unused;
|
2017-10-19 14:03:39 +00:00
|
|
|
return IVSHMEM_WAIT_RESULT_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return IVSHMEM_WAIT_RESULT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
bool ivshmem_kick_irq(uint16_t clientID, uint16_t vector)
|
|
|
|
{
|
|
|
|
struct IVSHMEMClient * client = ivshmem_get_client(clientID);
|
|
|
|
if (!client)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("invalid client");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vector > client->irqCount - 1)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("invalid vector for client");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fd = client->irqs[vector];
|
|
|
|
uint64_t kick = ivshmem.server.clientID;
|
|
|
|
if (write(fd, &kick, sizeof(kick)) == sizeof(kick))
|
|
|
|
return true;
|
|
|
|
|
2017-10-29 02:06:41 +00:00
|
|
|
DEBUG_ERROR("failed to send kick");
|
2017-10-19 14:03:39 +00:00
|
|
|
return false;
|
2017-10-19 05:00:57 +00:00
|
|
|
}
|