enable hot adding cpu/mem

Signed-off-by: Lai Jiangshan <jiangshanlai@gmail.com>
This commit is contained in:
Lai Jiangshan
2016-01-28 15:48:43 +08:00
parent e6cffd9add
commit 1ce35da941
6 changed files with 280 additions and 63 deletions
+2
View File
@@ -1154,6 +1154,8 @@ static int hyper_channel_handle(struct hyper_event *de, uint32_t len)
pod->type = type;
switch (type) {
case STARTPOD:
online_cpu();
online_memory();
ret = hyper_start_pod((char *)buf->data + 8, len - 8);
hyper_print_uptime();
break;
+72
View File
@@ -140,6 +140,78 @@ int hyper_mkdir(char *hyper_path)
return 0;
}
void online_cpu(void)
{
DIR *dir = opendir("/sys/devices/system/cpu");
if (dir == NULL) {
fprintf(stderr, "open dir /sys/devices/system/cpu failed\n");
return;
}
printf("online_cpu()\n");
for (;;) {
int num;
int ret;
char path[256];
int fd;
struct dirent *entry = readdir(dir);
if (entry == NULL)
break;
if (entry->d_type != DT_DIR)
continue;
ret = sscanf(entry->d_name, "cpu%d", &num);
if (ret < 1 || num == 0) /* skip none cpu%d and cpu0 */
continue;
sprintf(path, "/sys/devices/system/cpu/%s/online", entry->d_name);
fd = open(path, O_RDWR);
if (fd < 0) {
fprintf(stderr, "open %s failed\n", path);
continue;
}
printf("try to online %s\n", entry->d_name);
ret = write(fd, "1", sizeof("1"));
printf("online %s result: %s\n", entry->d_name, ret == 2 ? "success" : "failed");
close(fd);
}
closedir(dir);
}
void online_memory(void)
{
DIR *dir = opendir("/sys/devices/system/memory");
if (dir == NULL) {
fprintf(stderr, "open dir /sys/devices/system/memory failed\n");
return;
}
printf("online_memory()\n");
for (;;) {
int num;
int ret;
char path[256];
int fd;
struct dirent *entry = readdir(dir);
if (entry == NULL)
break;
if (entry->d_type != DT_DIR)
continue;
ret = sscanf(entry->d_name, "memory%d", &num);
if (ret < 1 || num == 0) /* skip none memory%d and memory0 */
continue;
sprintf(path, "/sys/devices/system/memory/%s/online", entry->d_name);
fd = open(path, O_RDWR);
if (fd < 0) {
fprintf(stderr, "open %s failed\n", path);
continue;
}
printf("try to online %s\n", entry->d_name);
ret = write(fd, "1", sizeof("1"));
printf("online %s result: %s\n", entry->d_name, ret == 2 ? "success" : "failed");
close(fd);
}
closedir(dir);
}
#if WITH_VBOX
#include <termios.h>
+2
View File
@@ -18,6 +18,8 @@ char *read_cmdline(void);
int hyper_setup_env(struct env *envs, int num);
int hyper_find_sd(char *prefix, char *addr, char **dev);
int hyper_list_dir(char *path);
void online_cpu(void);
void online_memory(void);
int hyper_mkdir(char *path);
int hyper_open_channel(char *channel, int mode);
int hyper_open_serial_dev(char *tty);