This repository was archived by the owner on Aug 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathaaf.c
More file actions
124 lines (102 loc) · 2.41 KB
/
Copy pathaaf.c
File metadata and controls
124 lines (102 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Copyright (c) 2021 Intel Corporation.
* All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <err.h>
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "vm_manager.h"
#include "guest.h"
#include "utils.h"
#include "aaf.h"
#define AAF_FILE_NAME "mixins.spec"
static const char *gpu_type[] = {
[AAF_GPU_TYPE_VIRTIO] = "gpu-type:virtio",
[AAF_GPU_TYPE_GVTG] = "gpu-type:gvtg",
[AAF_GPU_TYPE_GVTD] = "gpu-type:gvtd"
};
static const char *suspend_support[] = {
[AAF_SUSPEND_DISABLE] = "suspend:false",
[AAF_SUSPEND_ENABLE] = "suspend:true"
};
static const char *civ_flag_support[] = {
[AAF_CIV_DISABLE] = "civ_flag:false",
[AAF_CIV_ENABLE] = "civ_flag:true"
};
static char *aaf_file = NULL;
static const char *aaf_config_array[AAF_CONFIG_NUM] = { NULL };
int set_aaf_path(const char *path)
{
struct stat st;
size_t len;
if (!path) {
fprintf(stderr, "%s: Invalid input!\n", __func__);
return -1;
}
if (stat(path, &st) != 0) {
fprintf(stderr, "%s: cannot stat folder: %s, errno=%d\n", __func__, path, errno);
return -1;
}
len = strlen(path) + sizeof(AAF_FILE_NAME) + 1;
aaf_file = calloc(len, 1);
if (!aaf_file) {
fprintf(stderr, "%s: Failed to alloc memory!\n", __func__);
return -1;
}
snprintf(aaf_file, len, "%s/%s", path, AAF_FILE_NAME);
return 0;
}
int flush_aaf_config(void)
{
FILE *fp;
int i;
if (!aaf_file)
return 0;
fp = fopen(aaf_file, "w");
if (!fp) {
fprintf(stderr, "%s: Failed to open AAF file:%s\n", __func__, aaf_file);
return -1;
}
for (i=0; i < AAF_CONFIG_NUM; i++) {
if (aaf_config_array[i])
fprintf(fp, "%s\n", aaf_config_array[i]);
}
fclose(fp);
return 0;
}
int set_aaf_option(aaf_config_opt_t opt, unsigned int sub)
{
if (!aaf_file)
return 0;
switch (opt) {
case AAF_CONFIG_SUSPEND:
if (sub > AAF_SUSPEND_DISABLE)
return -1;
aaf_config_array[AAF_CONFIG_SUSPEND] = suspend_support[sub];
break;
case AAF_CONFIG_GPU_TYPE:
if (sub > AAF_GPU_TYPE_GVTD)
return -1;
aaf_config_array[AAF_CONFIG_GPU_TYPE] = gpu_type[sub];
break;
case AAF_CONFIG_CIV:
if (sub >AAF_CIV_DISABLE)
return -1;
aaf_config_array[AAF_CONFIG_CIV] = civ_flag_support[sub];
break;
default:
fprintf(stderr, "%s: Invalid AAF config option!\n", __func__);
break;
}
return 0;
}