mirror of
https://github.com/clearlinux/kvmtool.git
synced 2026-09-04 20:51:28 +00:00
kvm tools: Organize net parameters into struct
Move network configuration parameters into a struct. The amount of network parameters will be rather large, so better do it early. Signed-off-by: Sasha Levin <levinsasha928@gmail.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
@@ -2,6 +2,12 @@
|
||||
#define KVM__VIRTIO_NET_H
|
||||
|
||||
struct kvm;
|
||||
void virtio_net__init(struct kvm *self, const char *host_ip_addr);
|
||||
|
||||
struct virtio_net_parameters {
|
||||
struct kvm *self;
|
||||
const char *host_ip;
|
||||
};
|
||||
|
||||
void virtio_net__init(const struct virtio_net_parameters *params);
|
||||
|
||||
#endif /* KVM__VIRTIO_NET_H */
|
||||
|
||||
@@ -212,6 +212,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
|
||||
static char real_cmdline[2048];
|
||||
int exit_code = 0;
|
||||
int i;
|
||||
struct virtio_net_parameters net_params;
|
||||
|
||||
signal(SIGALRM, handle_sigalrm);
|
||||
signal(SIGQUIT, handle_sigquit);
|
||||
@@ -310,8 +311,13 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
|
||||
if (!network)
|
||||
network = DEFAULT_NETWORK;
|
||||
|
||||
if (!strncmp(network, "virtio", 6))
|
||||
virtio_net__init(kvm, host_ip_addr);
|
||||
if (!strncmp(network, "virtio", 6)) {
|
||||
net_params = (struct virtio_net_parameters) {
|
||||
.host_ip = host_ip_addr,
|
||||
.self = kvm
|
||||
};
|
||||
virtio_net__init(&net_params);
|
||||
}
|
||||
|
||||
kvm__start_timer(kvm);
|
||||
|
||||
|
||||
+5
-5
@@ -276,7 +276,7 @@ static struct pci_device_header virtio_net_pci_device = {
|
||||
.irq_line = VIRTIO_NET_IRQ,
|
||||
};
|
||||
|
||||
static void virtio_net__tap_init(const char *host_ip_addr)
|
||||
static void virtio_net__tap_init(const struct virtio_net_parameters *params)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
int sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
@@ -301,7 +301,7 @@ static void virtio_net__tap_init(const char *host_ip_addr)
|
||||
|
||||
strncpy(ifr.ifr_name, net_device.tap_name, sizeof(net_device.tap_name));
|
||||
|
||||
sin.sin_addr.s_addr = inet_addr(host_ip_addr);
|
||||
sin.sin_addr.s_addr = inet_addr(params->host_ip);
|
||||
memcpy(&(ifr.ifr_addr), &sin, sizeof(ifr.ifr_addr));
|
||||
ifr.ifr_addr.sa_family = AF_INET;
|
||||
|
||||
@@ -330,11 +330,11 @@ static void virtio_net__io_thread_init(struct kvm *self)
|
||||
pthread_create(&net_device.io_tx_thread, NULL, virtio_net_tx_thread, (void *)self);
|
||||
}
|
||||
|
||||
void virtio_net__init(struct kvm *self, const char *host_ip_addr)
|
||||
void virtio_net__init(const struct virtio_net_parameters *params)
|
||||
{
|
||||
pci__register(&virtio_net_pci_device, PCI_VIRTIO_NET_DEVNUM);
|
||||
ioport__register(IOPORT_VIRTIO_NET, &virtio_net_io_ops, IOPORT_VIRTIO_NET_SIZE);
|
||||
|
||||
virtio_net__tap_init(host_ip_addr);
|
||||
virtio_net__io_thread_init(self);
|
||||
virtio_net__tap_init(params);
|
||||
virtio_net__io_thread_init(params->self);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user