Patchwork blockdev: preserve readonly and snapshot states across media changes

login
register
mail settings
Submitter Kevin Shanahan
Date Sept. 20, 2012, 11:20 p.m.
Message ID <20120920232022.GA13110@tuon.disenchant.local>
Download mbox | patch
Permalink /patch/185524/
State New
Headers show

Comments

Kevin Shanahan - Sept. 20, 2012, 11:20 p.m.
If readonly=on is given at device creation time, the ->readonly flag
needs to be set in the block driver state for this device so that
readonly-ness is preserved across media changes (qmp change command).
Similarly, to preserve the snapshot property requires ->open_flags to
be correct.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
---
 blockdev.c | 2 ++
 1 file changed, 2 insertions(+)
Kevin Wolf - Sept. 21, 2012, 7:11 a.m.
Am 21.09.2012 01:20, schrieb Kevin Shanahan:
> If readonly=on is given at device creation time, the ->readonly flag
> needs to be set in the block driver state for this device so that
> readonly-ness is preserved across media changes (qmp change command).
> Similarly, to preserve the snapshot property requires ->open_flags to
> be correct.
> 
> Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>

Thanks, applied to the block branch.

Kevin

Patch

diff --git a/blockdev.c b/blockdev.c
index 8669142..84f9a2e 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -526,6 +526,8 @@  DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
                      if_name[type], mediastr, unit_id);
     }
     dinfo->bdrv = bdrv_new(dinfo->id);
+    dinfo->bdrv->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
+    dinfo->bdrv->read_only = ro;
     dinfo->devaddr = devaddr;
     dinfo->type = type;
     dinfo->bus = bus_id;