diff mbox

[RESEND,22/50] blockdev: Check BB validity in drive-backup TA

Message ID 1422387983-32153-23-git-send-email-mreitz@redhat.com
State New
Headers show

Commit Message

Max Reitz Jan. 27, 2015, 7:45 p.m. UTC
In the drive-backup transaction, call blk_is_available() before using
blk_bs() to obtain the root BlockDriverState behind the BlockBackend.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 blockdev.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

Comments

Max Reitz Jan. 28, 2015, 4:27 p.m. UTC | #1
On 2015-01-27 at 18:44, Eric Blake wrote:
> On 01/27/2015 12:45 PM, Max Reitz wrote:
>> In the drive-backup transaction, call blk_is_available() before using
>> blk_bs() to obtain the root BlockDriverState behind the BlockBackend.
> Took me a while to figure that TA meant transaction in the subject.
> Either spell it out, or just drop 'TA' entirely (the shorter subject
> would still make sense).  (21/50 as well).

Well, the subject would then be the same as for 26. drive-backup is 
something different than the drive-backup transaction.

I don't really have a problem with using longer subjects lines, but vim 
tells me not to. :-( However, vim hasn't passed the turing test, so if 
you tell me to I'll ignore it.

Max

>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
>>   blockdev.c | 15 ++++++++++-----
>>   1 file changed, 10 insertions(+), 5 deletions(-)
> Reviewed-by: Eric Blake <eblake@redhat.com>
>
diff mbox

Patch

diff --git a/blockdev.c b/blockdev.c
index 012c603..5f7eef5 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1507,23 +1507,28 @@  typedef struct DriveBackupState {
 static void drive_backup_prepare(BlkTransactionState *common, Error **errp)
 {
     DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common);
-    BlockDriverState *bs;
+    BlockBackend *blk;
     DriveBackup *backup;
     Error *local_err = NULL;
 
     assert(common->action->kind == TRANSACTION_ACTION_KIND_DRIVE_BACKUP);
     backup = common->action->drive_backup;
 
-    bs = bdrv_find(backup->device);
-    if (!bs) {
+    blk = blk_by_name(backup->device);
+    if (!blk) {
         error_set(errp, QERR_DEVICE_NOT_FOUND, backup->device);
         return;
     }
 
     /* AioContext is released in .clean() */
-    state->aio_context = bdrv_get_aio_context(bs);
+    state->aio_context = blk_get_aio_context(blk);
     aio_context_acquire(state->aio_context);
 
+    if (!blk_is_available(blk)) {
+        error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, backup->device);
+        return;
+    }
+
     qmp_drive_backup(backup->device, backup->target,
                      backup->has_format, backup->format,
                      backup->sync,
@@ -1537,7 +1542,7 @@  static void drive_backup_prepare(BlkTransactionState *common, Error **errp)
         return;
     }
 
-    state->bs = bs;
+    state->bs = blk_bs(blk);
     state->job = state->bs->job;
 }