#include <stdio.h>
#include <stdlib.h>
-#include <sys/un.h>
#include <fcntl.h>
#include <unistd.h>
#include <inttypes.h>
#include <rte_memory.h>
#include <rte_mempool.h>
#include <rte_log.h>
-#include <rte_atomic.h>
#include <rte_spinlock.h>
#include <libvirt/libvirt.h>
#include "channel_manager.h"
-#include "channel_commands.h"
#include "channel_monitor.h"
#include "power_manager.h"
#define RTE_LOGTYPE_CHANNEL_MANAGER RTE_LOGTYPE_USER1
+struct libvirt_vm_info lvm_info[MAX_CLIENTS];
+
/* Global pointer to libvirt connection */
static virConnectPtr global_vir_conn_ptr;
virDomainPtr domainPtr;
virDomainInfo info;
rte_spinlock_t config_spinlock;
+ int allow_query;
LIST_ENTRY(virtual_machine_info) vms_info;
};
return 0;
}
-static void
-fifo_path(char *dst, unsigned int len)
+static int
+fifo_path(char *dst, unsigned int len, unsigned int id)
{
- snprintf(dst, len, "%sfifo", CHANNEL_MGR_SOCKET_PATH);
+ int cnt;
+
+ cnt = snprintf(dst, len, "%s%s%d", CHANNEL_MGR_SOCKET_PATH,
+ CHANNEL_MGR_FIFO_PATTERN_NAME, id);
+
+ if ((cnt < 0) || (cnt > (int)len - 1)) {
+ RTE_LOG(ERR, CHANNEL_MANAGER, "Could not create proper "
+ "string for fifo path\n");
+
+ return -1;
+ }
+
+ return 0;
}
static int
continue;
}
- snprintf(chan_info->channel_path,
+ if ((size_t)snprintf(chan_info->channel_path,
sizeof(chan_info->channel_path), "%s%s",
- CHANNEL_MGR_SOCKET_PATH, dir->d_name);
+ CHANNEL_MGR_SOCKET_PATH, dir->d_name)
+ >= sizeof(chan_info->channel_path)) {
+ RTE_LOG(ERR, CHANNEL_MANAGER, "Pathname too long for channel '%s%s'\n",
+ CHANNEL_MGR_SOCKET_PATH, dir->d_name);
+ rte_free(chan_info);
+ continue;
+ }
if (setup_channel_info(&vm_info, &chan_info, channel_num) < 0) {
rte_free(chan_info);
}
for (i = 0; i < len_channel_list; i++) {
-
if (channel_list[i] >= RTE_MAX_LCORE) {
RTE_LOG(INFO, CHANNEL_MANAGER, "Channel(%u) is out of range "
"0...%d\n", channel_list[i],
}
int
-add_host_channel(void)
+add_host_channels(void)
{
struct channel_info *chan_info;
char socket_path[PATH_MAX];
int num_channels_enabled = 0;
int ret;
+ struct core_info *ci;
+ struct channel_info *chan_infos[RTE_MAX_LCORE];
+ int i;
- fifo_path(socket_path, sizeof(socket_path));
+ for (i = 0; i < RTE_MAX_LCORE; i++)
+ chan_infos[i] = NULL;
- ret = mkfifo(socket_path, 0660);
- if ((errno != EEXIST) && (ret < 0)) {
- RTE_LOG(ERR, CHANNEL_MANAGER, "Cannot create fifo '%s' error: "
- "%s\n", socket_path, strerror(errno));
+ ci = get_core_info();
+ if (ci == NULL) {
+ RTE_LOG(ERR, CHANNEL_MANAGER, "Cannot allocate memory for core_info\n");
return 0;
}
- if (access(socket_path, F_OK) < 0) {
- RTE_LOG(ERR, CHANNEL_MANAGER, "Channel path '%s' error: "
- "%s\n", socket_path, strerror(errno));
- return 0;
- }
- chan_info = rte_malloc(NULL, sizeof(*chan_info), 0);
- if (chan_info == NULL) {
- RTE_LOG(ERR, CHANNEL_MANAGER, "Error allocating memory for "
- "channel '%s'\n", socket_path);
- return 0;
- }
- rte_strlcpy(chan_info->channel_path, socket_path, UNIX_PATH_MAX);
+ for (i = 0; i < ci->core_count; i++) {
+ if (rte_lcore_index(i) == -1)
+ continue;
- if (setup_host_channel_info(&chan_info, 0) < 0) {
- rte_free(chan_info);
- return 0;
+ if (ci->cd[i].global_enabled_cpus == 0)
+ continue;
+
+ ret = fifo_path(socket_path, sizeof(socket_path), i);
+ if (ret < 0)
+ goto error;
+
+ ret = mkfifo(socket_path, 0660);
+ RTE_LOG(DEBUG, CHANNEL_MANAGER, "TRY CREATE fifo '%s'\n",
+ socket_path);
+ if ((errno != EEXIST) && (ret < 0)) {
+ RTE_LOG(ERR, CHANNEL_MANAGER, "Cannot create fifo '%s' error: "
+ "%s\n", socket_path, strerror(errno));
+ goto error;
+ }
+ chan_info = rte_malloc(NULL, sizeof(*chan_info), 0);
+ if (chan_info == NULL) {
+ RTE_LOG(ERR, CHANNEL_MANAGER, "Error allocating memory for "
+ "channel '%s'\n", socket_path);
+ goto error;
+ }
+ chan_infos[i] = chan_info;
+ strlcpy(chan_info->channel_path, socket_path,
+ sizeof(chan_info->channel_path));
+
+ if (setup_host_channel_info(&chan_info, i) < 0) {
+ rte_free(chan_info);
+ chan_infos[i] = NULL;
+ goto error;
+ }
+ num_channels_enabled++;
}
- num_channels_enabled++;
return num_channels_enabled;
+error:
+ /* Clean up the channels opened before we hit an error. */
+ for (i = 0; i < ci->core_count; i++) {
+ if (chan_infos[i] != NULL) {
+ remove_channel_from_monitor(chan_infos[i]);
+ close(chan_infos[i]->fd);
+ rte_free(chan_infos[i]);
+ }
+ }
+ return 0;
}
int
channel_num++;
}
+ info->allow_query = vm_info->allow_query;
info->num_channels = channel_num;
info->num_vcpus = vm_info->info.nrVirtCpu;
rte_spinlock_unlock(&(vm_info->config_spinlock));
else
new_domain->status = CHANNEL_MGR_VM_ACTIVE;
+ new_domain->allow_query = 0;
rte_spinlock_init(&(new_domain->config_spinlock));
LIST_INSERT_HEAD(&vm_list_head, new_domain, vms_info);
return 0;
return 0;
}
+int
+set_query_status(char *vm_name,
+ bool allow_query)
+{
+ struct virtual_machine_info *vm_info;
+
+ vm_info = find_domain_by_name(vm_name);
+ if (vm_info == NULL) {
+ RTE_LOG(ERR, CHANNEL_MANAGER, "VM '%s' not found\n", vm_name);
+ return -1;
+ }
+ rte_spinlock_lock(&(vm_info->config_spinlock));
+ vm_info->allow_query = allow_query ? 1 : 0;
+ rte_spinlock_unlock(&(vm_info->config_spinlock));
+ return 0;
+}
+
static void
disconnect_hypervisor(void)
{