aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2011-05-05 16:39:47 +0300
committerMichael S. Tsirkin <mst@redhat.com>2011-05-05 16:39:47 +0300
commit5300f1a5487f67f0bde8ee1081b799108668cb1d (patch)
tree5274ff496f2665487736a4eec23bf76601e4da44 /block.c
parent8d4c78e7c8adf0a4440a8de92738b3820fc8215a (diff)
parentd2d979c628e4b2c4a3cb71a31841875795c79043 (diff)
Merge remote branch 'origin/master' into pci
Conflicts: exec.c
Diffstat (limited to 'block.c')
-rw-r--r--block.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/block.c b/block.c
index c8e2f97614..f731c7afbf 100644
--- a/block.c
+++ b/block.c
@@ -697,14 +697,22 @@ void bdrv_close_all(void)
}
}
+/* make a BlockDriverState anonymous by removing from bdrv_state list.
+ Also, NULL terminate the device_name to prevent double remove */
+void bdrv_make_anon(BlockDriverState *bs)
+{
+ if (bs->device_name[0] != '\0') {
+ QTAILQ_REMOVE(&bdrv_states, bs, list);
+ }
+ bs->device_name[0] = '\0';
+}
+
void bdrv_delete(BlockDriverState *bs)
{
assert(!bs->peer);
/* remove from list, if necessary */
- if (bs->device_name[0] != '\0') {
- QTAILQ_REMOVE(&bdrv_states, bs, list);
- }
+ bdrv_make_anon(bs);
bdrv_close(bs);
if (bs->file != NULL) {
@@ -1153,14 +1161,12 @@ int64_t bdrv_getlength(BlockDriverState *bs)
if (!drv)
return -ENOMEDIUM;
- /* Fixed size devices use the total_sectors value for speed instead of
- issuing a length query (like lseek) on each call. Also, legacy block
- drivers don't provide a bdrv_getlength function and must use
- total_sectors. */
- if (!bs->growable || !drv->bdrv_getlength) {
- return bs->total_sectors * BDRV_SECTOR_SIZE;
+ if (bs->growable || bs->removable) {
+ if (drv->bdrv_getlength) {
+ return drv->bdrv_getlength(bs);
+ }
}
- return drv->bdrv_getlength(bs);
+ return bs->total_sectors * BDRV_SECTOR_SIZE;
}
/* return 0 as number of sectors if no device present or error */
@@ -2809,6 +2815,8 @@ void bdrv_set_locked(BlockDriverState *bs, int locked)
{
BlockDriver *drv = bs->drv;
+ trace_bdrv_set_locked(bs, locked);
+
bs->locked = locked;
if (drv && drv->bdrv_set_locked) {
drv->bdrv_set_locked(bs, locked);