From 5176196c3233dcb80aacc719be6b6502bb1c972b Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Wed, 3 May 2017 00:35:36 +0800 Subject: block: Make bdrv_perm_names public It can be used outside of block.c for making user friendly messages. Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- include/block/block.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/block/block.h b/include/block/block.h index 862eb56fc7..9fa0f235a6 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -224,6 +224,8 @@ enum { BLK_PERM_ALL = 0x1f, }; +char *bdrv_perm_names(uint64_t perm); + /* disk I/O throttling */ void bdrv_init(void); void bdrv_init_with_whitelist(void); -- cgit v1.2.3 From 5a9347c6730ff6d68bba30b24f80cd90a6671a20 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Wed, 3 May 2017 00:35:37 +0800 Subject: block: Add, parse and store "force-share" option Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- include/block/block.h | 1 + include/block/block_int.h | 1 + 2 files changed, 2 insertions(+) (limited to 'include') diff --git a/include/block/block.h b/include/block/block.h index 9fa0f235a6..877fbb0d9a 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -109,6 +109,7 @@ typedef struct HDGeometry { #define BDRV_OPT_CACHE_NO_FLUSH "cache.no-flush" #define BDRV_OPT_READ_ONLY "read-only" #define BDRV_OPT_DISCARD "discard" +#define BDRV_OPT_FORCE_SHARE "force-share" #define BDRV_SECTOR_BITS 9 diff --git a/include/block/block_int.h b/include/block/block_int.h index 87739405d5..1b4d08e8df 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -518,6 +518,7 @@ struct BlockDriverState { bool valid_key; /* if true, a valid encryption key has been set */ bool sg; /* if true, the device is a /dev/sg* */ bool probed; /* if true, format was probed rather than specified */ + bool force_share; /* if true, always allow all shared permissions */ BlockDriver *drv; /* NULL means no media */ void *opaque; -- cgit v1.2.3 From 13461fdba6588540c99bf1e32275e421da22c396 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Wed, 3 May 2017 00:35:54 +0800 Subject: osdep: Add qemu_lock_fd and qemu_unlock_fd They are wrappers of POSIX fcntl "file private locking", with a convenient "try lock" wrapper implemented with F_OFD_GETLK. Signed-off-by: Fam Zheng Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- include/qemu/osdep.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 122ff06ff6..1c9f5e260c 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -341,6 +341,9 @@ int qemu_close(int fd); #ifndef _WIN32 int qemu_dup(int fd); #endif +int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive); +int qemu_unlock_fd(int fd, int64_t start, int64_t len); +int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive); #if defined(__HAIKU__) && defined(__i386__) #define FMT_pid "%ld" -- cgit v1.2.3 From 4417ab7adf1613799054be5afedf810fc2524ee8 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Thu, 4 May 2017 18:52:37 +0200 Subject: block: New BdrvChildRole.activate() for blk_resume_after_migration() Instead of manually calling blk_resume_after_migration() in migration code after doing bdrv_invalidate_cache_all(), integrate the BlockBackend activation with cache invalidation into a single function. This is achieved with a new callback in BdrvChildRole that is called by bdrv_invalidate_cache_all(). Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- include/block/block.h | 2 -- include/block/block_int.h | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/block/block.h b/include/block/block.h index 877fbb0d9a..80d51d8f12 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -369,8 +369,6 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp); void bdrv_invalidate_cache_all(Error **errp); int bdrv_inactivate_all(void); -void blk_resume_after_migration(Error **errp); - /* Ensure contents are flushed to disk. */ int bdrv_flush(BlockDriverState *bs); int coroutine_fn bdrv_co_flush(BlockDriverState *bs); diff --git a/include/block/block_int.h b/include/block/block_int.h index 1b4d08e8df..563792580c 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -473,6 +473,11 @@ struct BdrvChildRole { void (*drained_begin)(BdrvChild *child); void (*drained_end)(BdrvChild *child); + /* Notifies the parent that the child has been activated (e.g. when + * migration is completing) and it can start requesting permissions and + * doing I/O on it. */ + void (*activate)(BdrvChild *child, Error **errp); + void (*attach)(BdrvChild *child); void (*detach)(BdrvChild *child); }; -- cgit v1.2.3 From cfa1a5723f0fc8eb6563fb1d19c206fd5e40cd41 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Thu, 4 May 2017 18:52:38 +0200 Subject: block: Drop permissions when migration completes With image locking, permissions affect other qemu processes as well. We want to be sure that the destination can run, so let's drop permissions on the source when migration completes. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- include/block/block_int.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/block/block_int.h b/include/block/block_int.h index 563792580c..5750a448a6 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -473,10 +473,11 @@ struct BdrvChildRole { void (*drained_begin)(BdrvChild *child); void (*drained_end)(BdrvChild *child); - /* Notifies the parent that the child has been activated (e.g. when - * migration is completing) and it can start requesting permissions and - * doing I/O on it. */ + /* Notifies the parent that the child has been activated/inactivated (e.g. + * when migration is completing) and it can start/stop requesting + * permissions and doing I/O on it. */ void (*activate)(BdrvChild *child, Error **errp); + int (*inactivate)(BdrvChild *child); void (*attach)(BdrvChild *child); void (*detach)(BdrvChild *child); -- cgit v1.2.3 From 9c5e6594f15b7364624a3ad40306c396c93a2145 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Thu, 4 May 2017 18:52:40 +0200 Subject: block: Fix write/resize permissions for inactive images Format drivers for inactive nodes don't need write/resize permissions on their bs->file and can share write/resize with another VM (in fact, this is the whole point of keeping images inactive). Represent this fact in the op blocker system, so that image locking does the right thing without special-casing inactive images. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- include/block/block.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/block/block.h b/include/block/block.h index 80d51d8f12..90932b4709 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -435,6 +435,7 @@ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, int64_t sector_num, int nb_sectors, int *pnum); bool bdrv_is_read_only(BlockDriverState *bs); +bool bdrv_is_writable(BlockDriverState *bs); int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, Error **errp); int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp); bool bdrv_is_sg(BlockDriverState *bs); -- cgit v1.2.3 From 4c41cb4955effff3447bd07a09e0af9c6e0453e3 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Sat, 6 May 2017 19:05:43 -0500 Subject: block: Update comments on BDRV_BLOCK_* meanings We had some conflicting documentation: a nice 8-way table that described all possible combinations of DATA, ZERO, and OFFSET_VALID, contrasted with text that implied that OFFSET_VALID always meant raw data could be read directly. Furthermore, the text refers a lot to bs->file, even though the interface was updated back in 67a0fd2a to let the driver pass back a specific BDS (not necessarily bs->file). As the 8-way table is the intended semantics, simplify the rest of the text to get rid of the confusion. ALLOCATED is always set by the block layer for convenience (drivers do not have to worry about it). RAW is used only internally, but by more than the raw driver. Document these additional items on the driver callback. Suggested-by: Max Reitz Signed-off-by: Eric Blake Reviewed-by: Max Reitz Message-id: 20170507000552.20847-4-eblake@redhat.com Signed-off-by: Max Reitz --- include/block/block.h | 35 +++++++++++++++++++---------------- include/block/block_int.h | 7 +++++++ 2 files changed, 26 insertions(+), 16 deletions(-) (limited to 'include') diff --git a/include/block/block.h b/include/block/block.h index 90932b4709..9b355e92d8 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -121,29 +121,32 @@ typedef struct HDGeometry { #define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS) /* - * Allocation status flags - * BDRV_BLOCK_DATA: data is read from a file returned by bdrv_get_block_status. - * BDRV_BLOCK_ZERO: sectors read as zero - * BDRV_BLOCK_OFFSET_VALID: sector stored as raw data in a file returned by - * bdrv_get_block_status. + * Allocation status flags for bdrv_get_block_status() and friends. + * + * Public flags: + * BDRV_BLOCK_DATA: allocation for data at offset is tied to this layer + * BDRV_BLOCK_ZERO: offset reads as zero + * BDRV_BLOCK_OFFSET_VALID: an associated offset exists for accessing raw data * BDRV_BLOCK_ALLOCATED: the content of the block is determined by this - * layer (as opposed to the backing file) - * BDRV_BLOCK_RAW: used internally to indicate that the request - * was answered by the raw driver and that one - * should look in bs->file directly. + * layer (short for DATA || ZERO), set by block layer * - * If BDRV_BLOCK_OFFSET_VALID is set, bits 9-62 represent the offset in - * bs->file where sector data can be read from as raw data. + * Internal flag: + * BDRV_BLOCK_RAW: used internally to indicate that the request was + * answered by a passthrough driver such as raw and that the + * block layer should recompute the answer from bs->file. * - * DATA == 0 && ZERO == 0 means that data is read from backing_hd if present. + * If BDRV_BLOCK_OFFSET_VALID is set, bits 9-62 (BDRV_BLOCK_OFFSET_MASK) + * represent the offset in the returned BDS that is allocated for the + * corresponding raw data; however, whether that offset actually contains + * data also depends on BDRV_BLOCK_DATA and BDRV_BLOCK_ZERO, as follows: * * DATA ZERO OFFSET_VALID - * t t t sectors read as zero, bs->file is zero at offset - * t f t sectors read as valid from bs->file at offset - * f t t sectors preallocated, read as zero, bs->file not + * t t t sectors read as zero, returned file is zero at offset + * t f t sectors read as valid from file at offset + * f t t sectors preallocated, read as zero, returned file not * necessarily zero at offset * f f t sectors preallocated but read from backing_hd, - * bs->file contains garbage at offset + * returned file contains garbage at offset * t t f sectors preallocated, read as zero, unknown offset * t f f sectors read from unknown file or offset * f t f not allocated or unknown offset, read as zero diff --git a/include/block/block_int.h b/include/block/block_int.h index 5750a448a6..8d3724cce6 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -165,6 +165,13 @@ struct BlockDriver { int64_t offset, int count, BdrvRequestFlags flags); int coroutine_fn (*bdrv_co_pdiscard)(BlockDriverState *bs, int64_t offset, int count); + + /* + * Building block for bdrv_block_status[_above]. The driver should + * answer only according to the current layer, and should not + * set BDRV_BLOCK_ALLOCATED, but may set BDRV_BLOCK_RAW. See block.h + * for the meaning of _DATA, _ZERO, and _OFFSET_VALID. + */ int64_t coroutine_fn (*bdrv_co_get_block_status)(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum, BlockDriverState **file); -- cgit v1.2.3