X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Fvm_power_manager%2Fchannel_manager.c;h=4ac21f02c1a9820773dd59e6225c8b4da46a5304;hb=9dbc4e21e752ca98e23205c3d1bac53e03e934b3;hp=084681747a3c2a650d6bc810308d0c6b70d4f97a;hpb=751227a08d92c36bc69a1d25416b223c50fd278a;p=dpdk.git diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c index 084681747a..4ac21f02c1 100644 --- a/examples/vm_power_manager/channel_manager.c +++ b/examples/vm_power_manager/channel_manager.c @@ -58,6 +58,7 @@ struct virtual_machine_info { virDomainPtr domainPtr; virDomainInfo info; rte_spinlock_t config_spinlock; + int allow_query; LIST_ENTRY(virtual_machine_info) vms_info; }; @@ -345,10 +346,22 @@ setup_channel_info(struct virtual_machine_info **vm_info_dptr, 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 @@ -362,8 +375,6 @@ setup_host_channel_info(struct channel_info **chan_info_dptr, chan_info->status = CHANNEL_MGR_CHANNEL_DISCONNECTED; chan_info->type = CHANNEL_TYPE_JSON; - fifo_path(chan_info->channel_path, sizeof(chan_info->channel_path)); - if (open_host_channel(chan_info) < 0) { RTE_LOG(ERR, CHANNEL_MANAGER, "Could not open host channel: " "'%s'\n", @@ -536,42 +547,70 @@ add_channels(const char *vm_name, unsigned *channel_list, } 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; - } - strlcpy(chan_info->channel_path, socket_path, - sizeof(chan_info->channel_path)); - if (setup_host_channel_info(&chan_info, 0) < 0) { - rte_free(chan_info); - return 0; + for (i = 0; i < ci->core_count; i++) { + 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 @@ -753,6 +792,7 @@ get_info_vm(const char *vm_name, struct vm_info *info) 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)); @@ -829,6 +869,7 @@ add_vm(const char *vm_name) 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; @@ -858,6 +899,23 @@ remove_vm(const char *vm_name) 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) {