diff mbox

[2/2] kvm tools: Use constants for commonly used mmap flags

Message ID 1305132777-9026-2-git-send-email-levinsasha928@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sasha Levin May 11, 2011, 4:52 p.m. UTC
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/disk-image.c       |    2 +-
 tools/kvm/include/kvm/util.h |    3 +++
 tools/kvm/kvm-cpu.c          |    2 +-
 tools/kvm/kvm.c              |    4 ++--
 4 files changed, 7 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/tools/kvm/disk-image.c b/tools/kvm/disk-image.c
index 0bda8db..bddbdb3 100644
--- a/tools/kvm/disk-image.c
+++ b/tools/kvm/disk-image.c
@@ -39,7 +39,7 @@  struct disk_image *disk_image__new_readonly(int fd, u64 size, struct disk_image_
 	if (!disk)
 		return NULL;
 
-	disk->priv = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_NORESERVE, fd, 0);
+	disk->priv = mmap(NULL, size, PROT_RW, MAP_PRIVATE | MAP_NORESERVE, fd, 0);
 	if (disk->priv == MAP_FAILED)
 		die("mmap() failed");
 	return disk;
diff --git a/tools/kvm/include/kvm/util.h b/tools/kvm/include/kvm/util.h
index fc222c3..5f4cbb9 100644
--- a/tools/kvm/include/kvm/util.h
+++ b/tools/kvm/include/kvm/util.h
@@ -29,6 +29,9 @@ 
 #endif
 #endif
 
+#define PROT_RW (PROT_READ|PROT_WRITE)
+#define MAP_ANON_NORESERVE (MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE)
+
 extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
 extern void die_perror(const char *s) NORETURN;
 extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c
index e69049d..8a27e02 100644
--- a/tools/kvm/kvm-cpu.c
+++ b/tools/kvm/kvm-cpu.c
@@ -81,7 +81,7 @@  struct kvm_cpu *kvm_cpu__init(struct kvm *kvm, unsigned long cpu_id)
 	if (mmap_size < 0)
 		die_perror("KVM_GET_VCPU_MMAP_SIZE ioctl");
 
-	vcpu->kvm_run = mmap(NULL, mmap_size, PROT_READ|PROT_WRITE, MAP_SHARED, vcpu->vcpu_fd, 0);
+	vcpu->kvm_run = mmap(NULL, mmap_size, PROT_RW, MAP_SHARED, vcpu->vcpu_fd, 0);
 	if (vcpu->kvm_run == MAP_FAILED)
 		die("unable to mmap vcpu fd");
 
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index fcb3d58..c69fcc4 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -267,9 +267,9 @@  struct kvm *kvm__init(const char *kvm_dev, unsigned long ram_size)
 	kvm->ram_size		= ram_size;
 
 	if (kvm->ram_size < KVM_32BIT_GAP_START) {
-		kvm->ram_start = mmap(NULL, ram_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
+		kvm->ram_start = mmap(NULL, ram_size, PROT_RW, MAP_ANON_NORESERVE, -1, 0);
 	} else {
-		kvm->ram_start = mmap(NULL, ram_size + KVM_32BIT_GAP_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
+		kvm->ram_start = mmap(NULL, ram_size + KVM_32BIT_GAP_SIZE, PROT_RW, MAP_ANON_NORESERVE, -1, 0);
 		if (kvm->ram_start != MAP_FAILED) {
 			/*
 			 * We mprotect the gap (see kvm__init_ram() for details) PROT_NONE so that