diff options
author | Naphtali Sprei <nsprei@redhat.com> | 2009-10-26 16:25:16 +0200 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-11-09 08:43:01 -0600 |
commit | 59f2689d9082f2f631253c810f73cd22290144a9 (patch) | |
tree | feff1eaf42f55486ef2a9fb6573191dbc5001c83 /vl.c | |
parent | d191d12d5f479422e16ed1d12b0222547b29036a (diff) |
Added readonly flag to -drive command
This is a slightly revised patch for adding readonly flag to the -drive command.
Even though this patch is "stand-alone", it assumes a previous related patch (in Anthony staging tree), that passes
the readonly attribute of the drive to the guest OS, applied first.
This enables sharing same image between guests, with readonly access.
Implementaion mark the drive as read_only and changes the flags when actually opening the file.
The readonly attribute of a qcow also passed to it's base file.
For ide that cannot pass the readonly attribute to the guest OS, disallow the readonly flag.
Also, return error code from bdrv_truncate for readonly drive.
Signed-off-by: Naphtali Sprei <nsprei@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'vl.c')
-rw-r--r-- | vl.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -2001,6 +2001,7 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque, int index; int cache; int aio = 0; + int ro = 0; int bdrv_flags, onerror; const char *devaddr; DriveInfo *dinfo; @@ -2032,6 +2033,7 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque, secs = qemu_opt_get_number(opts, "secs", 0); snapshot = qemu_opt_get_bool(opts, "snapshot", 0); + ro = qemu_opt_get_bool(opts, "readonly", 0); file = qemu_opt_get(opts, "file"); serial = qemu_opt_get(opts, "serial"); @@ -2323,6 +2325,14 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque, bdrv_flags &= ~BDRV_O_NATIVE_AIO; } + if (ro == 1) { + if (type == IF_IDE) { + fprintf(stderr, "qemu: readonly flag not supported for drive with ide interface\n"); + return NULL; + } + (void)bdrv_set_read_only(dinfo->bdrv, 1); + } + if (bdrv_open2(dinfo->bdrv, file, bdrv_flags, drv) < 0) { fprintf(stderr, "qemu: could not open disk image %s: %s\n", file, strerror(errno)); |