__thread struct kvm_cpu *current_kvm_cpu;
static int kvm_run_wrapper;
-extern int debug_iodelay;
bool do_debug_print = false;
KVM_RUN_SANDBOX,
};
-void kvm_run_set_wrapper_sandbox(void)
-{
- kvm_run_wrapper = KVM_RUN_SANDBOX;
-}
-
static int img_name_parser(const struct option *opt, const char *arg, int unset)
{
char path[PATH_MAX];
- const char *cur;
struct stat st;
- char *sep;
+ struct kvm *kvm = opt->ptr;
if (stat(arg, &st) == 0 &&
S_ISDIR(st.st_mode)) {
return 0;
}
- if (kvm->cfg.image_count >= MAX_DISK_IMAGES)
- die("Currently only 4 images are supported");
-
- kvm->cfg.disk_image[kvm->cfg.image_count].filename = arg;
- cur = arg;
-
- if (strncmp(arg, "scsi:", 5) == 0) {
- sep = strstr(arg, ":");
- if (sep)
- kvm->cfg.disk_image[kvm->cfg.image_count].wwpn = sep + 1;
- sep = strstr(sep + 1, ":");
- if (sep) {
- *sep = 0;
- kvm->cfg.disk_image[kvm->cfg.image_count].tpgt = sep + 1;
- }
- cur = sep + 1;
- }
-
- do {
- sep = strstr(cur, ",");
- if (sep) {
- if (strncmp(sep + 1, "ro", 2) == 0)
- kvm->cfg.disk_image[kvm->cfg.image_count].readonly = true;
- else if (strncmp(sep + 1, "direct", 6) == 0)
- kvm->cfg.disk_image[kvm->cfg.image_count].direct = true;
- *sep = 0;
- cur = sep + 1;
- }
- } while (sep);
-
- kvm->cfg.image_count++;
+ return disk_img_name_parser(opt, arg, unset);
+}
- return 0;
+void kvm_run_set_wrapper_sandbox(void)
+{
+ kvm_run_wrapper = KVM_RUN_SANDBOX;
}
static int virtio_9p_rootdir_parser(const struct option *opt, const char *arg, int unset)
return 0;
}
-#define BUILD_OPTIONS(name, cfg) \
+#define BUILD_OPTIONS(name, cfg, kvm) \
struct option name[] = { \
OPT_GROUP("Basic options:"), \
OPT_STRING('\0', "name", &(cfg)->guest_name, "guest name", \
shmem_parser, NULL), \
OPT_CALLBACK('d', "disk", kvm, "image or rootfs_dir", "Disk \
image or rootfs directory", img_name_parser, \
- NULL), \
+ kvm), \
OPT_BOOLEAN('\0', "balloon", &(cfg)->balloon, "Enable virtio \
balloon"), \
OPT_BOOLEAN('\0', "vnc", &(cfg)->vnc, "Enable VNC framebuffer"),\
"Enable ioport debugging"), \
OPT_BOOLEAN('\0', "debug-mmio", &(cfg)->mmio_debug, \
"Enable MMIO debugging"), \
- OPT_INTEGER('\0', "debug-iodelay", &debug_iodelay, \
+ OPT_INTEGER('\0', "debug-iodelay", &(cfg)->debug_iodelay, \
"Delay IO by millisecond"), \
OPT_END() \
};
void kvm_run_help(void)
{
- BUILD_OPTIONS(options, &kvm->cfg);
+ BUILD_OPTIONS(options, &kvm->cfg, kvm);
usage_with_options(run_usage, options);
}
kvm->cfg.custom_rootfs_name = "default";
while (argc != 0) {
- BUILD_OPTIONS(options, &kvm->cfg);
+ BUILD_OPTIONS(options, &kvm->cfg, kvm);
argc = parse_options(argc, argv, options, run_usage,
PARSE_OPT_STOP_AT_NON_OPTION |
PARSE_OPT_KEEP_DASHDASH);
}
+ kvm->nr_disks = kvm->cfg.image_count;
+
if (!kvm->cfg.kernel_filename)
kvm->cfg.kernel_filename = find_kernel();
strlcat(real_cmdline, " root=/dev/vda rw ", sizeof(real_cmdline));
}
- if (kvm->cfg.image_count) {
- kvm->nr_disks = kvm->cfg.image_count;
- kvm->disks = disk_image__open_all((struct disk_image_params *)&kvm->cfg.disk_image, kvm->cfg.image_count);
- if (IS_ERR(kvm->disks)) {
- r = PTR_ERR(kvm->disks);
- pr_err("disk_image__open_all() failed with error %ld\n",
- PTR_ERR(kvm->disks));
- goto fail;
- }
+ r = disk_image__init(kvm);
+ if (r < 0) {
+ pr_err("disk_image__init() failed with error %d\n", r);
+ goto fail;
}
printf(" # %s run -k %s -m %Lu -c %d --name %s\n", KVM_BINARY_NAME,
if (r < 0)
pr_warning("virtio_rng__exit() failed with error %d\n", r);
- r = disk_image__close_all(kvm->disks, kvm->cfg.image_count);
+ r = disk_image__exit(kvm);
if (r < 0)
- pr_warning("disk_image__close_all() failed with error %d\n", r);
+ pr_warning("disk_image__exit() failed with error %d\n", r);
r = serial8250__exit(kvm);
if (r < 0)
#include "kvm/disk-image.h"
#include "kvm/qcow.h"
#include "kvm/virtio-blk.h"
+#include "kvm/kvm.h"
#include <linux/err.h>
#include <sys/eventfd.h>
int debug_iodelay;
+static int disk_image__close(struct disk_image *disk);
+
+int disk_img_name_parser(const struct option *opt, const char *arg, int unset)
+{
+ const char *cur;
+ char *sep;
+ struct kvm *kvm = opt->ptr;
+
+ if (kvm->cfg.image_count >= MAX_DISK_IMAGES)
+ die("Currently only 4 images are supported");
+
+ kvm->cfg.disk_image[kvm->cfg.image_count].filename = arg;
+ cur = arg;
+
+ if (strncmp(arg, "scsi:", 5) == 0) {
+ sep = strstr(arg, ":");
+ if (sep)
+ kvm->cfg.disk_image[kvm->cfg.image_count].wwpn = sep + 1;
+ sep = strstr(sep + 1, ":");
+ if (sep) {
+ *sep = 0;
+ kvm->cfg.disk_image[kvm->cfg.image_count].tpgt = sep + 1;
+ }
+ cur = sep + 1;
+ }
+
+ do {
+ sep = strstr(cur, ",");
+ if (sep) {
+ if (strncmp(sep + 1, "ro", 2) == 0)
+ kvm->cfg.disk_image[kvm->cfg.image_count].readonly = true;
+ else if (strncmp(sep + 1, "direct", 6) == 0)
+ kvm->cfg.disk_image[kvm->cfg.image_count].direct = true;
+ *sep = 0;
+ cur = sep + 1;
+ }
+ } while (sep);
+
+ kvm->cfg.image_count++;
+
+ return 0;
+}
+
#ifdef CONFIG_HAS_AIO
static void *disk_image__thread(void *param)
{
return disk;
}
-struct disk_image *disk_image__open(const char *filename, bool readonly, bool direct)
+static struct disk_image *disk_image__open(const char *filename, bool readonly, bool direct)
{
struct disk_image *disk;
struct stat st;
return ERR_PTR(-ENOSYS);
}
-struct disk_image **disk_image__open_all(struct disk_image_params *params, int count)
+static struct disk_image **disk_image__open_all(struct kvm *kvm)
{
struct disk_image **disks;
const char *filename;
bool direct;
void *err;
int i;
+ struct disk_image_params *params = (struct disk_image_params *)&kvm->cfg.disk_image;
+ int count = kvm->cfg.image_count;
if (!count)
return ERR_PTR(-EINVAL);
err = disks[i];
goto error;
}
+ disks[i]->debug_iodelay = kvm->cfg.debug_iodelay;
}
return disks;
return fsync(disk->fd);
}
-int disk_image__close(struct disk_image *disk)
+static int disk_image__close(struct disk_image *disk)
{
/* If there was no disk image then there's nothing to do: */
if (!disk)
return 0;
}
-int disk_image__close_all(struct disk_image **disks, int count)
+static int disk_image__close_all(struct disk_image **disks, int count)
{
while (count)
disk_image__close(disks[--count]);
{
disk->disk_req_cb = disk_req_cb;
}
+
+int disk_image__init(struct kvm *kvm)
+{
+ if (kvm->cfg.image_count) {
+ kvm->disks = disk_image__open_all(kvm);
+ if (IS_ERR(kvm->disks))
+ return PTR_ERR(kvm->disks);
+ }
+
+ return 0;
+}
+
+int disk_image__exit(struct kvm *kvm)
+{
+ return disk_image__close_all(kvm->disks, kvm->nr_disks);
+}
#include "kvm/read-write.h"
#include "kvm/util.h"
+#include "kvm/parse-options.h"
#include <linux/types.h>
#include <linux/fs.h> /* for BLKGETSIZE64 */
#endif
const char *wwpn;
const char *tpgt;
+ int debug_iodelay;
};
-struct disk_image *disk_image__open(const char *filename, bool readonly, bool direct);
-struct disk_image **disk_image__open_all(struct disk_image_params *params, int count);
+int disk_img_name_parser(const struct option *opt, const char *arg, int unset);
+int disk_image__init(struct kvm *kvm);
+int disk_image__exit(struct kvm *kvm);
struct disk_image *disk_image__new(int fd, u64 size, struct disk_image_operations *ops, int mmap);
-int disk_image__close(struct disk_image *disk);
-int disk_image__close_all(struct disk_image **disks, int count);
int disk_image__flush(struct disk_image *disk);
ssize_t disk_image__read(struct disk_image *disk, u64 sector, const struct iovec *iov,
int iovcount, void *param);