# HG changeset patch # User Jerone Young <[EMAIL PROTECTED]> # Date 1193998359 18000 # Node ID c66785783d56c9aa034de01a3519cf7f42a0f383 # Parent e3def9892f39527f216acbde2de4dad0e8501183 Move kvm_create_kernel_phys_mem to libkvm-x86.c
This patch moves kvm_create_kernel_phys_mem to x86 as this is the only arch that will be allocating memory for guest in the kernel (at least for older kvm versions). Signed-off-by: Jerone Young <[EMAIL PROTECTED]> diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h --- a/libkvm/kvm-x86.h +++ b/libkvm/kvm-x86.h @@ -5,6 +5,8 @@ */ #ifndef KVM_X86_H #define KVM_X86_H + +#include "kvm-common.h" /* FIXME: share this number with kvm */ /* FIXME: or dynamically alloc/realloc regions */ @@ -36,4 +38,7 @@ int kvm_arch_create(kvm_context_t kvm, u int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes, void **vm_mem); +void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start, + unsigned long len, int log, int writable); + #endif diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c --- a/libkvm/libkvm-x86.c +++ b/libkvm/libkvm-x86.c @@ -274,4 +274,36 @@ int kvm_arch_create(kvm_context_t kvm, u return 0; } - +void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start, + unsigned long len, int log, int writable) +{ + int r; + int prot = PROT_READ; + void *ptr; + struct kvm_memory_region memory = { + .memory_size = len, + .guest_phys_addr = phys_start, + .flags = log ? KVM_MEM_LOG_DIRTY_PAGES : 0, + }; + + memory.slot = get_free_slot(kvm); + r = ioctl(kvm->vm_fd, KVM_SET_MEMORY_REGION, &memory); + if (r == -1) { + fprintf(stderr, "create_kernel_phys_mem: %s", strerror(errno)); + return 0; + } + register_slot(memory.slot, memory.guest_phys_addr); + kvm_memory_region_save_params(kvm, &memory); + + if (writable) + prot |= PROT_WRITE; + + ptr = mmap(NULL, len, prot, MAP_SHARED, kvm->vm_fd, phys_start); + if (ptr == MAP_FAILED) { + fprintf(stderr, "create_kernel_phys_mem: %s", strerror(errno)); + return 0; + } + + return ptr; +} + diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -375,38 +375,6 @@ int kvm_create(kvm_context_t kvm, unsign return 0; } -void *kvm_create_kernel_phys_mem(kvm_context_t kvm, unsigned long phys_start, - unsigned long len, int log, int writable) -{ - int r; - int prot = PROT_READ; - void *ptr; - struct kvm_memory_region memory = { - .memory_size = len, - .guest_phys_addr = phys_start, - .flags = log ? KVM_MEM_LOG_DIRTY_PAGES : 0, - }; - - memory.slot = get_free_slot(kvm); - r = ioctl(kvm->vm_fd, KVM_SET_MEMORY_REGION, &memory); - if (r == -1) { - fprintf(stderr, "create_kernel_phys_mem: %s", strerror(errno)); - return 0; - } - register_slot(memory.slot, memory.guest_phys_addr); - kvm_memory_region_save_params(kvm, &memory); - - if (writable) - prot |= PROT_WRITE; - - ptr = mmap(NULL, len, prot, MAP_SHARED, kvm->vm_fd, phys_start); - if (ptr == MAP_FAILED) { - fprintf(stderr, "create_kernel_phys_mem: %s", strerror(errno)); - return 0; - } - - return ptr; -} #ifdef KVM_CAP_USER_MEMORY ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel