Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 340e01248478ba8b78a6d4d1809b1eff > files > 740

kvm-83-270.el5_11.src.rpm

From ca207db62dadc1346a708423b3c8863b4c85657c Mon Sep 17 00:00:00 2001
From: Naphtali Sprei <nsprei@redhat.com>
Date: Thu, 15 Apr 2010 11:56:42 -0300
Subject: [PATCH 06/12] read-only: Added readonly option to drive's command line

RH-Author: Naphtali Sprei <nsprei@redhat.com>
Message-id: <1271332608-5243-6-git-send-email-nsprei@redhat.com>
Patchwork-id: 8653
O-Subject: [RHEL 5.6 kvm PATCH v4 05/11] read-only: Added readonly option to
	drive's command line
Bugzilla: 510630
RH-Acked-by: Christoph Hellwig <chellwig@redhat.com>
RH-Acked-by: Juan Quintela <quintela@redhat.com>
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>

Added readonly option to drive's command line and to monitor's drive_add command
Set flags for opening the file according to value
The read-only option supported/allowed only for devices that
can pass the read-only attribute to the Guest OS.

based on upstream commit: 59f2689d9082f2f631253c810f73cd22290144a9

Signed-off-by: Naphtali Sprei <nsprei@redhat.com>
---
 qemu/monitor.c |    2 +-
 qemu/vl.c      |   24 ++++++++++++++++++++----
 2 files changed, 21 insertions(+), 5 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 qemu/monitor.c |    2 +-
 qemu/vl.c      |   24 ++++++++++++++++++++----
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/qemu/monitor.c b/qemu/monitor.c
index e91c01e..4cfe2e4 100644
--- a/qemu/monitor.c
+++ b/qemu/monitor.c
@@ -1669,7 +1669,7 @@ static term_cmd_t term_cmds[] = {
                                          "[file=file][,if=type][,bus=n]\n"
                                         "[,unit=m][,media=d][index=i]\n"
                                         "[,cyls=c,heads=h,secs=s[,trans=t]]\n"
-                                        "[snapshot=on|off][,cache=on|off]",
+                                        "[snapshot=on|off][,cache=on|off][,readonly=on|off]",
                                         "add drive to PCI storage controller" },
     { "pci_add", "sss", pci_device_hot_add, "pci_addr=auto|[[<domain>:]<bus>:]<slot> nic|storage|host [[vlan=n][,macaddr=addr][,model=type]] [file=file][,if=type][,bus=nr]... [host=02:00.0[,name=string][,dma=none]", "hot-add PCI device" },
     { "pci_del", "s", pci_device_hot_remove, "pci_addr=[[<domain>:]<bus>:]<slot>", "hot remove PCI device" },
diff --git a/qemu/vl.c b/qemu/vl.c
index f78e835..e889c37 100644
--- a/qemu/vl.c
+++ b/qemu/vl.c
@@ -2398,14 +2398,14 @@ int drive_init(struct drive_opt *arg, int snapshot,
     int max_devs;
     int index;
     int cache;
-    int bdrv_flags, onerror;
+    int bdrv_flags, onerror, ro = 0;
     int drives_table_idx;
     char *str = arg->opt;
     static const char * const params[] = { "bus", "unit", "if", "index",
                                            "cyls", "heads", "secs", "trans",
                                            "media", "snapshot", "file",
                                            "cache", "format", "serial", "werror",
-                                           "boot", NULL };
+                                           "boot", "readonly", NULL };
 
     if (check_params(buf, sizeof(buf), params, str) < 0) {
          fprintf(stderr, "qemu: unknown parameter '%s' in '%s'\n",
@@ -2739,8 +2739,24 @@ int drive_init(struct drive_opt *arg, int snapshot,
     else if (cache == 3) /* not specified */
         bdrv_flags |= BDRV_O_CACHE_DEF;
 
-    /* temp: ask for read-write so stuff works as before */
-    bdrv_flags |= BDRV_O_RDWR;
+    ro = 0;
+    if (get_param_value(buf, sizeof(buf), "readonly", str)) {
+        if (!strcmp(buf, "off")) {
+            ro = 0;
+        } else if (!strcmp(buf, "on")) {
+            if (type != IF_SCSI && type != IF_VIRTIO && type != IF_FLOPPY) {
+                fprintf(stderr, "qemu: readonly flag not supported for drive of this interface\n");
+                return -1;
+            }
+            ro = 1;
+        } else {
+            fprintf(stderr, "qemu: '%s' invalid readonly option (valid values: [on|off] )\n", buf);
+            return -1;
+        }
+    }
+    if (!ro) {
+        bdrv_flags |= BDRV_O_RDWR;
+    }
 
     drives_table[drives_table_idx].drv = drv;
     drives_table[drives_table_idx].bdrv_flags = bdrv_flags;
-- 
1.7.0.3