Commit 43835ac9 authored by Sasha Levin's avatar Sasha Levin Committed by Will Deacon
Browse files

kvm tools: Rename 'self' variables



Give proper names to vars named 'self'.

Signed-off-by: default avatarSasha Levin <levinsasha928@gmail.com>
Signed-off-by: default avatarPekka Enberg <penberg@kernel.org>
parent ed036f03
......@@ -70,7 +70,7 @@ static struct serial8250_device devices[] = {
static int sysrq_pending;
static void serial8250__sysrq(struct kvm *self, struct serial8250_device *dev)
static void serial8250__sysrq(struct kvm *kvm, struct serial8250_device *dev)
{
switch (sysrq_pending) {
case SYSRQ_PENDING_BREAK:
......@@ -87,7 +87,7 @@ static void serial8250__sysrq(struct kvm *self, struct serial8250_device *dev)
}
}
static void serial8250__receive(struct kvm *self, struct serial8250_device *dev)
static void serial8250__receive(struct kvm *kvm, struct serial8250_device *dev)
{
int c;
......@@ -95,7 +95,7 @@ static void serial8250__receive(struct kvm *self, struct serial8250_device *dev)
return;
if (sysrq_pending) {
serial8250__sysrq(self, dev);
serial8250__sysrq(kvm, dev);
return;
}
......@@ -114,13 +114,13 @@ static void serial8250__receive(struct kvm *self, struct serial8250_device *dev)
/*
* Interrupts are injected for ttyS0 only.
*/
void serial8250__inject_interrupt(struct kvm *self)
void serial8250__inject_interrupt(struct kvm *kvm)
{
struct serial8250_device *dev = &devices[0];
mutex_lock(&dev->mutex);
serial8250__receive(self, dev);
serial8250__receive(kvm, dev);
if (dev->ier & UART_IER_RDI && dev->lsr & UART_LSR_DR)
dev->iir = UART_IIR_RDI;
......@@ -130,14 +130,14 @@ void serial8250__inject_interrupt(struct kvm *self)
dev->iir = UART_IIR_NO_INT;
if (dev->iir != UART_IIR_NO_INT) {
kvm__irq_line(self, dev->irq, 0);
kvm__irq_line(self, dev->irq, 1);
kvm__irq_line(kvm, dev->irq, 0);
kvm__irq_line(kvm, dev->irq, 1);
}
mutex_unlock(&dev->mutex);
}
void serial8250__inject_sysrq(struct kvm *self)
void serial8250__inject_sysrq(struct kvm *kvm)
{
sysrq_pending = SYSRQ_PENDING_BREAK;
}
......@@ -155,7 +155,7 @@ static struct serial8250_device *find_device(u16 port)
return NULL;
}
static bool serial8250_out(struct kvm *self, u16 port, void *data, int size, u32 count)
static bool serial8250_out(struct kvm *kvm, u16 port, void *data, int size, u32 count)
{
struct serial8250_device *dev;
u16 offset;
......@@ -243,7 +243,7 @@ out_unlock:
return ret;
}
static bool serial8250_in(struct kvm *self, u16 port, void *data, int size, u32 count)
static bool serial8250_in(struct kvm *kvm, u16 port, void *data, int size, u32 count)
{
struct serial8250_device *dev;
u16 offset;
......
......@@ -32,19 +32,19 @@ static void filter_cpuid(struct kvm_cpuid2 *kvm_cpuid)
}
}
void kvm_cpu__setup_cpuid(struct kvm_cpu *self)
void kvm_cpu__setup_cpuid(struct kvm_cpu *vcpu)
{
struct kvm_cpuid2 *kvm_cpuid;
kvm_cpuid = calloc(1, sizeof(*kvm_cpuid) + MAX_KVM_CPUID_ENTRIES * sizeof(*kvm_cpuid->entries));
kvm_cpuid->nent = MAX_KVM_CPUID_ENTRIES;
if (ioctl(self->kvm->sys_fd, KVM_GET_SUPPORTED_CPUID, kvm_cpuid) < 0)
if (ioctl(vcpu->kvm->sys_fd, KVM_GET_SUPPORTED_CPUID, kvm_cpuid) < 0)
die_perror("KVM_GET_SUPPORTED_CPUID failed");
filter_cpuid(kvm_cpuid);
if (ioctl(self->vcpu_fd, KVM_SET_CPUID2, kvm_cpuid) < 0)
if (ioctl(vcpu->vcpu_fd, KVM_SET_CPUID2, kvm_cpuid) < 0)
die_perror("KVM_SET_CPUID2 failed");
free(kvm_cpuid);
......
......@@ -19,74 +19,74 @@
struct disk_image *disk_image__new(int fd, u64 size, struct disk_image_operations *ops)
{
struct disk_image *self;
struct disk_image *disk;
self = malloc(sizeof *self);
if (!self)
disk = malloc(sizeof *disk);
if (!disk)
return NULL;
self->fd = fd;
self->size = size;
self->ops = ops;
return self;
disk->fd = fd;
disk->size = size;
disk->ops = ops;
return disk;
}
struct disk_image *disk_image__new_readonly(int fd, u64 size, struct disk_image_operations *ops)
{
struct disk_image *self;
struct disk_image *disk;
self = disk_image__new(fd, size, ops);
if (!self)
disk = disk_image__new(fd, size, ops);
if (!disk)
return NULL;
self->priv = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_NORESERVE, fd, 0);
if (self->priv == MAP_FAILED)
disk->priv = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_NORESERVE, fd, 0);
if (disk->priv == MAP_FAILED)
die("mmap() failed");
return self;
return disk;
}
static ssize_t raw_image__read_sector_iov(struct disk_image *self, u64 sector, const struct iovec *iov, int iovcount)
static ssize_t raw_image__read_sector_iov(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount)
{
u64 offset = sector << SECTOR_SHIFT;
return preadv_in_full(self->fd, iov, iovcount, offset);
return preadv_in_full(disk->fd, iov, iovcount, offset);
}
static ssize_t raw_image__write_sector_iov(struct disk_image *self, u64 sector, const struct iovec *iov, int iovcount)
static ssize_t raw_image__write_sector_iov(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount)
{
u64 offset = sector << SECTOR_SHIFT;
return pwritev_in_full(self->fd, iov, iovcount, offset);
return pwritev_in_full(disk->fd, iov, iovcount, offset);
}
static int raw_image__read_sector_ro_mmap(struct disk_image *self, u64 sector, void *dst, u32 dst_len)
static int raw_image__read_sector_ro_mmap(struct disk_image *disk, u64 sector, void *dst, u32 dst_len)
{
u64 offset = sector << SECTOR_SHIFT;
if (offset + dst_len > self->size)
if (offset + dst_len > disk->size)
return -1;
memcpy(dst, self->priv + offset, dst_len);
memcpy(dst, disk->priv + offset, dst_len);
return 0;
}
static int raw_image__write_sector_ro_mmap(struct disk_image *self, u64 sector, void *src, u32 src_len)
static int raw_image__write_sector_ro_mmap(struct disk_image *disk, u64 sector, void *src, u32 src_len)
{
u64 offset = sector << SECTOR_SHIFT;
if (offset + src_len > self->size)
if (offset + src_len > disk->size)
return -1;
memcpy(self->priv + offset, src, src_len);
memcpy(disk->priv + offset, src, src_len);
return 0;
}
static void raw_image__close_ro_mmap(struct disk_image *self)
static void raw_image__close_ro_mmap(struct disk_image *disk)
{
if (self->priv != MAP_FAILED)
munmap(self->priv, self->size);
if (disk->priv != MAP_FAILED)
munmap(disk->priv, disk->size);
}
static struct disk_image_operations raw_image_ops = {
......@@ -130,7 +130,7 @@ static struct disk_image *blkdev__probe(const char *filename, struct stat *st)
struct disk_image *disk_image__open(const char *filename, bool readonly)
{
struct disk_image *self;
struct disk_image *disk;
struct stat st;
int fd;
......@@ -144,13 +144,13 @@ struct disk_image *disk_image__open(const char *filename, bool readonly)
if (fd < 0)
return NULL;
self = qcow_probe(fd);
if (self)
return self;
disk = qcow_probe(fd);
if (disk)
return disk;
self = raw_image__probe(fd, &st, readonly);
if (self)
return self;
disk = raw_image__probe(fd, &st, readonly);
if (disk)
return disk;
if (close(fd) < 0)
warning("close() failed");
......@@ -158,17 +158,17 @@ struct disk_image *disk_image__open(const char *filename, bool readonly)
return NULL;
}
void disk_image__close(struct disk_image *self)
void disk_image__close(struct disk_image *disk)
{
/* If there was no disk image then there's nothing to do: */
if (!self)
if (!disk)
return;
if (self->ops->close)
self->ops->close(self);
if (disk->ops->close)
disk->ops->close(disk);
if (close(self->fd) < 0)
if (close(disk->fd) < 0)
warning("close() failed");
free(self);
free(disk);
}
......@@ -11,11 +11,11 @@
struct disk_image;
struct disk_image_operations {
int (*read_sector)(struct disk_image *self, u64 sector, void *dst, u32 dst_len);
int (*write_sector)(struct disk_image *self, u64 sector, void *src, u32 src_len);
ssize_t (*read_sector_iov)(struct disk_image *self, u64 sector, const struct iovec *iov, int iovcount);
ssize_t (*write_sector_iov)(struct disk_image *self, u64 sector, const struct iovec *iov, int iovcount);
void (*close)(struct disk_image *self);
int (*read_sector)(struct disk_image *disk, u64 sector, void *dst, u32 dst_len);
int (*write_sector)(struct disk_image *disk, u64 sector, void *src, u32 src_len);
ssize_t (*read_sector_iov)(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount);
ssize_t (*write_sector_iov)(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount);
void (*close)(struct disk_image *disk);
};
struct disk_image {
......@@ -28,25 +28,25 @@ struct disk_image {
struct disk_image *disk_image__open(const char *filename, bool readonly);
struct disk_image *disk_image__new(int fd, u64 size, struct disk_image_operations *ops);
struct disk_image *disk_image__new_readonly(int fd, u64 size, struct disk_image_operations *ops);
void disk_image__close(struct disk_image *self);
void disk_image__close(struct disk_image *disk);
static inline int disk_image__read_sector(struct disk_image *self, u64 sector, void *dst, u32 dst_len)
static inline int disk_image__read_sector(struct disk_image *disk, u64 sector, void *dst, u32 dst_len)
{
return self->ops->read_sector(self, sector, dst, dst_len);
return disk->ops->read_sector(disk, sector, dst, dst_len);
}
static inline int disk_image__write_sector(struct disk_image *self, u64 sector, void *src, u32 src_len)
static inline int disk_image__write_sector(struct disk_image *disk, u64 sector, void *src, u32 src_len)
{
return self->ops->write_sector(self, sector, src, src_len);
return disk->ops->write_sector(disk, sector, src, src_len);
}
static inline ssize_t disk_image__read_sector_iov(struct disk_image *self, u64 sector, const struct iovec *iov, int iovcount)
static inline ssize_t disk_image__read_sector_iov(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount)
{
if (self->ops->read_sector_iov)
return self->ops->read_sector_iov(self, sector, iov, iovcount);
if (disk->ops->read_sector_iov)
return disk->ops->read_sector_iov(disk, sector, iov, iovcount);
while (iovcount--) {
self->ops->read_sector(self, sector, iov->iov_base, iov->iov_len);
disk->ops->read_sector(disk, sector, iov->iov_base, iov->iov_len);
sector += iov->iov_len >> SECTOR_SHIFT;
iov++;
}
......@@ -54,13 +54,13 @@ static inline ssize_t disk_image__read_sector_iov(struct disk_image *self, u64 s
return sector << SECTOR_SHIFT;
}
static inline ssize_t disk_image__write_sector_iov(struct disk_image *self, u64 sector, const struct iovec *iov, int iovcount)
static inline ssize_t disk_image__write_sector_iov(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount)
{
if (self->ops->write_sector_iov)
return self->ops->write_sector_iov(self, sector, iov, iovcount);
if (disk->ops->write_sector_iov)
return disk->ops->write_sector_iov(disk, sector, iov, iovcount);
while (iovcount--) {
self->ops->write_sector(self, sector, iov->iov_base, iov->iov_len);
disk->ops->write_sector(disk, sector, iov->iov_base, iov->iov_len);
sector += iov->iov_len >> SECTOR_SHIFT;
iov++;
}
......
......@@ -19,8 +19,8 @@ struct interrupt_table {
struct real_intr_desc entries[REAL_INTR_VECTORS];
};
void interrupt_table__copy(struct interrupt_table *self, void *dst, unsigned int size);
void interrupt_table__setup(struct interrupt_table *self, struct real_intr_desc *entry);
void interrupt_table__set(struct interrupt_table *self, struct real_intr_desc *entry, unsigned int num);
void interrupt_table__copy(struct interrupt_table *itable, void *dst, unsigned int size);
void interrupt_table__setup(struct interrupt_table *itable, struct real_intr_desc *entry);
void interrupt_table__set(struct interrupt_table *itable, struct real_intr_desc *entry, unsigned int num);
#endif /* KVM__INTERRUPT_H */
......@@ -19,8 +19,8 @@
struct kvm;
struct ioport_operations {
bool (*io_in)(struct kvm *self, u16 port, void *data, int size, u32 count);
bool (*io_out)(struct kvm *self, u16 port, void *data, int size, u32 count);
bool (*io_in)(struct kvm *kvm, u16 port, void *data, int size, u32 count);
bool (*io_out)(struct kvm *kvm, u16 port, void *data, int size, u32 count);
};
void ioport__setup_legacy(void);
......
......@@ -24,15 +24,15 @@ struct kvm_cpu {
};
struct kvm_cpu *kvm_cpu__init(struct kvm *kvm, unsigned long cpu_id);
void kvm_cpu__delete(struct kvm_cpu *self);
void kvm_cpu__reset_vcpu(struct kvm_cpu *self);
void kvm_cpu__setup_cpuid(struct kvm_cpu *self);
void kvm_cpu__enable_singlestep(struct kvm_cpu *self);
void kvm_cpu__run(struct kvm_cpu *self);
void kvm_cpu__delete(struct kvm_cpu *vcpu);
void kvm_cpu__reset_vcpu(struct kvm_cpu *vcpu);
void kvm_cpu__setup_cpuid(struct kvm_cpu *vcpu);
void kvm_cpu__enable_singlestep(struct kvm_cpu *vcpu);
void kvm_cpu__run(struct kvm_cpu *vcpu);
int kvm_cpu__start(struct kvm_cpu *cpu);
void kvm_cpu__show_code(struct kvm_cpu *self);
void kvm_cpu__show_registers(struct kvm_cpu *self);
void kvm_cpu__show_page_tables(struct kvm_cpu *self);
void kvm_cpu__show_code(struct kvm_cpu *vcpu);
void kvm_cpu__show_registers(struct kvm_cpu *vcpu);
void kvm_cpu__show_page_tables(struct kvm_cpu *vcpu);
#endif /* KVM__KVM_CPU_H */
......@@ -31,28 +31,28 @@ struct kvm {
};
struct kvm *kvm__init(const char *kvm_dev, unsigned long ram_size);
int kvm__max_cpus(struct kvm *self);
void kvm__init_ram(struct kvm *self);
void kvm__delete(struct kvm *self);
int kvm__max_cpus(struct kvm *kvm);
void kvm__init_ram(struct kvm *kvm);
void kvm__delete(struct kvm *kvm);
bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename,
const char *initrd_filename, const char *kernel_cmdline);
void kvm__setup_bios(struct kvm *self);
void kvm__start_timer(struct kvm *self);
void kvm__stop_timer(struct kvm *self);
void kvm__irq_line(struct kvm *self, int irq, int level);
bool kvm__emulate_io(struct kvm *self, u16 port, void *data, int direction, int size, u32 count);
bool kvm__emulate_mmio(struct kvm *self, u64 phys_addr, u8 *data, u32 len, u8 is_write);
void kvm__setup_bios(struct kvm *kvm);
void kvm__start_timer(struct kvm *kvm);
void kvm__stop_timer(struct kvm *kvm);
void kvm__irq_line(struct kvm *kvm, int irq, int level);
bool kvm__emulate_io(struct kvm *kvm, u16 port, void *data, int direction, int size, u32 count);
bool kvm__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len, u8 is_write);
/*
* Debugging
*/
void kvm__dump_mem(struct kvm *self, unsigned long addr, unsigned long size);
void kvm__dump_mem(struct kvm *kvm, unsigned long addr, unsigned long size);
extern const char *kvm_exit_reasons[];
static inline bool host_ptr_in_ram(struct kvm *self, void *p)
static inline bool host_ptr_in_ram(struct kvm *kvm, void *p)
{
return self->ram_start <= p && p < (self->ram_start + self->ram_size);
return kvm->ram_start <= p && p < (kvm->ram_start + kvm->ram_size);
}
static inline u32 segment_to_flat(u16 selector, u16 offset)
......@@ -60,16 +60,16 @@ static inline u32 segment_to_flat(u16 selector, u16 offset)
return ((u32)selector << 4) + (u32) offset;
}
static inline void *guest_flat_to_host(struct kvm *self, unsigned long offset)
static inline void *guest_flat_to_host(struct kvm *kvm, unsigned long offset)
{
return self->ram_start + offset;
return kvm->ram_start + offset;
}
static inline void *guest_real_to_host(struct kvm *self, u16 selector, u16 offset)
static inline void *guest_real_to_host(struct kvm *kvm, u16 selector, u16 offset)
{
unsigned long flat = segment_to_flat(selector, offset);
return guest_flat_to_host(self, flat);
return guest_flat_to_host(kvm, flat);
}
#endif /* KVM__KVM_H */
......@@ -5,6 +5,6 @@
struct kvm;
void virtio_blk__init(struct kvm *self, struct disk_image *disk);
void virtio_blk__init(struct kvm *kvm, struct disk_image *disk);
#endif /* KVM__BLK_VIRTIO_H */
......@@ -3,7 +3,7 @@
struct kvm;
void virtio_console__init(struct kvm *self);
void virtio_console__inject_interrupt(struct kvm *self);
void virtio_console__init(struct kvm *kvm);
void virtio_console__inject_interrupt(struct kvm *kvm);
#endif /* KVM__CONSOLE_VIRTIO_H */
......@@ -4,7 +4,7 @@
struct kvm;
struct virtio_net_parameters {
struct kvm *self;
struct kvm *kvm;
const char *host_ip;
char guest_mac[6];
const char *script;
......
......@@ -4,24 +4,24 @@
#include <string.h>
void interrupt_table__copy(struct interrupt_table *self, void *dst, unsigned int size)
void interrupt_table__copy(struct interrupt_table *itable, void *dst, unsigned int size)
{
if (size < sizeof(self->entries))
if (size < sizeof(itable->entries))
die("An attempt to overwrite host memory");
memcpy(dst, self->entries, sizeof(self->entries));
memcpy(dst, itable->entries, sizeof(itable->entries));
}
void interrupt_table__setup(struct interrupt_table *self, struct real_intr_desc *entry)
void interrupt_table__setup(struct interrupt_table *itable, struct real_intr_desc *entry)
{
unsigned int i;
for (i = 0; i < REAL_INTR_VECTORS; i++)
self->entries[i] = *entry;
itable->entries[i] = *entry;
}
void interrupt_table__set(struct interrupt_table *self, struct real_intr_desc *entry, unsigned int num)
void interrupt_table__set(struct interrupt_table *itable, struct real_intr_desc *entry, unsigned int num)
{
if (num < REAL_INTR_VECTORS)
self->entries[num] = *entry;
itable->entries[num] = *entry;
}
......@@ -13,7 +13,7 @@
bool ioport_debug;
static bool debug_io_out(struct kvm *self, u16 port, void *data, int size, u32 count)
static bool debug_io_out(struct kvm *kvm, u16 port, void *data, int size, u32 count)
{
exit(EXIT_SUCCESS);
}
......@@ -22,12 +22,12 @@ static struct ioport_operations debug_ops = {
.io_out = debug_io_out,
};
static bool dummy_io_in(struct kvm *self, u16 port, void *data, int size, u32 count)
static bool dummy_io_in(struct kvm *kvm, u16 port, void *data, int size, u32 count)
{
return true;
}
static bool dummy_io_out(struct kvm *self, u16 port, void *data, int size, u32 count)
static bool dummy_io_out(struct kvm *kvm, u16 port, void *data, int size, u32 count)
{
return true;
}
......@@ -64,7 +64,7 @@ static void ioport_error(u16 port, void *data, int direction, int size, u32 coun
fprintf(stderr, "IO error: %s port=%x, size=%d, count=%u\n", to_direction(direction), port, size, count);
}
bool kvm__emulate_io(struct kvm *self, u16 port, void *data, int direction, int size, u32 count)
bool kvm__emulate_io(struct kvm *kvm, u16 port, void *data, int direction, int size, u32 count)
{
struct ioport_operations *ops = ioport_ops[port];
bool ret;
......@@ -76,14 +76,14 @@ bool kvm__emulate_io(struct kvm *self, u16 port, void *data, int direction, int
if (!ops->io_in)
goto error;
ret = ops->io_in(self, port, data, size, count);
ret = ops->io_in(kvm, port, data, size, count);
if (!ret)
goto error;
} else {
if (!ops->io_out)
goto error;
ret = ops->io_out(self, port, data, size, count);
ret = ops->io_out(kvm, port, data, size, count);
if (!ret)
goto error;
}
......
......@@ -12,12 +12,12 @@
#include <errno.h>
#include <stdio.h>
static inline bool is_in_protected_mode(struct kvm_cpu *self)
static inline bool is_in_protected_mode(struct kvm_cpu *vcpu)
{
return self->sregs.cr0 & 0x01;
return vcpu->sregs.cr0 & 0x01;
}
static inline u64 ip_to_flat(struct kvm_cpu *self, u64 ip)
static inline u64 ip_to_flat(struct kvm_cpu *vcpu, u64 ip)
{
u64 cs;
......@@ -25,10 +25,10 @@ static inline u64 ip_to_flat(struct kvm_cpu *self, u64 ip)
* NOTE! We should take code segment base address into account here.
* Luckily it's usually zero because Linux uses flat memory model.
*/
if (is_in_protected_mode(self))
if (is_in_protected_mode(vcpu))
return ip;
cs = self->sregs.cs.selector;
cs = vcpu->sregs.cs.selector;
return ip + (cs << 4);
}
......@@ -43,159 +43,159 @@ static inline u32 selector_to_base(u16 selector)
static struct kvm_cpu *kvm_cpu__new(struct kvm *kvm)
{
struct kvm_cpu *self;
struct kvm_cpu *vcpu;
self = calloc(1, sizeof *self);
if (!self)
vcpu = calloc(1, sizeof *vcpu);
if (!vcpu)
return NULL;
self->kvm = kvm;
vcpu->kvm = kvm;
return self;
return vcpu;
}
void kvm_cpu__delete(struct kvm_cpu *self)
void kvm_cpu__delete(struct kvm_cpu *vcpu)
{
if (self->msrs)
free(self->msrs);
if (vcpu->msrs)