Skip to content

Commit 228345b

Browse files
committed
block: Support BDRV_REQ_WRITE_UNCHANGED in filters
Update the rest of the filter drivers to support BDRV_REQ_WRITE_UNCHANGED. They already forward write request flags to their children, so we just have to announce support for it. This patch does not cover the replication driver because that currently does not support flags at all, and because it just grabs the WRITE permission for its children when it can, so we should be fine just submitting the incoming WRITE_UNCHANGED requests as normal writes. It also does not cover format drivers for similar reasons. They all use bdrv_format_default_perms() as their .bdrv_child_perm() implementation so they just always grab the WRITE permission for their file children whenever possible. In addition, it often would be difficult to ascertain whether incoming unchanging writes end up as unchanging writes in their files. So we just leave them as normal potentially changing writes. Signed-off-by: Max Reitz <[email protected]> Reviewed-by: Stefan Hajnoczi <[email protected]> Reviewed-by: Alberto Garcia <[email protected]> Message-id: [email protected] Reviewed-by: Kevin Wolf <[email protected]> Signed-off-by: Max Reitz <[email protected]>
1 parent 1b1a920 commit 228345b

7 files changed

+28
-14
lines changed

block/blkdebug.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,11 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
398398
goto out;
399399
}
400400

401-
bs->supported_write_flags = BDRV_REQ_FUA &
402-
bs->file->bs->supported_write_flags;
403-
bs->supported_zero_flags = (BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP) &
404-
bs->file->bs->supported_zero_flags;
401+
bs->supported_write_flags = BDRV_REQ_WRITE_UNCHANGED |
402+
(BDRV_REQ_FUA & bs->file->bs->supported_write_flags);
403+
bs->supported_zero_flags = BDRV_REQ_WRITE_UNCHANGED |
404+
((BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP) &
405+
bs->file->bs->supported_zero_flags);
405406
ret = -EINVAL;
406407

407408
/* Set alignment overrides */

block/blkreplay.c

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags,
3535
goto fail;
3636
}
3737

38+
bs->supported_write_flags = BDRV_REQ_WRITE_UNCHANGED;
39+
bs->supported_zero_flags = BDRV_REQ_WRITE_UNCHANGED;
40+
3841
ret = 0;
3942
fail:
4043
return ret;

block/blkverify.c

+3
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,
141141
goto fail;
142142
}
143143

144+
bs->supported_write_flags = BDRV_REQ_WRITE_UNCHANGED;
145+
bs->supported_zero_flags = BDRV_REQ_WRITE_UNCHANGED;
146+
144147
ret = 0;
145148
fail:
146149
qemu_opts_del(opts);

block/copy-on-read.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ static int cor_open(BlockDriverState *bs, QDict *options, int flags,
3333
return -EINVAL;
3434
}
3535

36-
bs->supported_write_flags = BDRV_REQ_FUA &
37-
bs->file->bs->supported_write_flags;
36+
bs->supported_write_flags = BDRV_REQ_WRITE_UNCHANGED |
37+
(BDRV_REQ_FUA &
38+
bs->file->bs->supported_write_flags);
3839

39-
bs->supported_zero_flags = (BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP) &
40-
bs->file->bs->supported_zero_flags;
40+
bs->supported_zero_flags = BDRV_REQ_WRITE_UNCHANGED |
41+
((BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP) &
42+
bs->file->bs->supported_zero_flags);
4143

4244
return 0;
4345
}

block/mirror.c

+2
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,8 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs,
11341134
mirror_top_bs->implicit = true;
11351135
}
11361136
mirror_top_bs->total_sectors = bs->total_sectors;
1137+
mirror_top_bs->supported_write_flags = BDRV_REQ_WRITE_UNCHANGED;
1138+
mirror_top_bs->supported_zero_flags = BDRV_REQ_WRITE_UNCHANGED;
11371139
bdrv_set_aio_context(mirror_top_bs, bdrv_get_aio_context(bs));
11381140

11391141
/* bdrv_append takes ownership of the mirror_top_bs reference, need to keep

block/raw-format.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,11 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
415415
}
416416

417417
bs->sg = bs->file->bs->sg;
418-
bs->supported_write_flags = BDRV_REQ_FUA &
419-
bs->file->bs->supported_write_flags;
420-
bs->supported_zero_flags = (BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP) &
421-
bs->file->bs->supported_zero_flags;
418+
bs->supported_write_flags = BDRV_REQ_WRITE_UNCHANGED |
419+
(BDRV_REQ_FUA & bs->file->bs->supported_write_flags);
420+
bs->supported_zero_flags = BDRV_REQ_WRITE_UNCHANGED |
421+
((BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP) &
422+
bs->file->bs->supported_zero_flags);
422423

423424
if (bs->probed && !bdrv_is_read_only(bs)) {
424425
fprintf(stderr,

block/throttle.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ static int throttle_open(BlockDriverState *bs, QDict *options,
8181
if (!bs->file) {
8282
return -EINVAL;
8383
}
84-
bs->supported_write_flags = bs->file->bs->supported_write_flags;
85-
bs->supported_zero_flags = bs->file->bs->supported_zero_flags;
84+
bs->supported_write_flags = bs->file->bs->supported_write_flags |
85+
BDRV_REQ_WRITE_UNCHANGED;
86+
bs->supported_zero_flags = bs->file->bs->supported_zero_flags |
87+
BDRV_REQ_WRITE_UNCHANGED;
8688

8789
return throttle_configure_tgm(bs, tgm, options, errp);
8890
}

0 commit comments

Comments
 (0)