Re: [PATCH v4 06/25] include/block/block_int: split header into I/O and global state API
On 16.11.21 11:24, Emanuele Giuseppe Esposito wrote: On 12/11/2021 13:17, Hanna Reitz wrote: On 25.10.21 12:17, Emanuele Giuseppe Esposito wrote: Similarly to the previous patch, split block_int.h in block_int-io.h and block_int-global-state.h block_int-common.h contains the structures shared between the two headers, and the functions that can't be categorized as I/O or global state. Assertions are added in the next patch. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Stefan Hajnoczi --- blockdev.c | 5 + include/block/block_int-common.h | 1164 +++ include/block/block_int-global-state.h | 319 + include/block/block_int-io.h | 163 +++ include/block/block_int.h | 1478 +--- 5 files changed, 1654 insertions(+), 1475 deletions(-) create mode 100644 include/block/block_int-common.h create mode 100644 include/block/block_int-global-state.h create mode 100644 include/block/block_int-io.h [...] diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h new file mode 100644 index 00..79a3d801d2 --- /dev/null +++ b/include/block/block_int-common.h [...] +struct BlockDriver { [...] + /** + * Try to get @bs's logical and physical block size. + * On success, store them in @bsz and return zero. + * On failure, return negative errno. + */ + /* I/O API, even though if it's a filter jumps on parent */ I don’t understand this... + int (*bdrv_probe_blocksizes)(BlockDriverState *bs, BlockSizes *bsz); + /** + * Try to get @bs's geometry (cyls, heads, sectors) + * On success, store them in @geo and return 0. + * On failure return -errno. + * Only drivers that want to override guest geometry implement this + * callback; see hd_geometry_guess(). + */ + /* I/O API, even though if it's a filter jumps on parent */ ...or this comment. bdrv_probe_blocksizes() and bdrv_probe_geometry() are in block-global-state.h, so why are these methods part of the I/O API? (And I’m afraid I can’t parse “even though if it’s a filter jumps on parent”.) Ok this is weird. This comment should not have been there, please ignore it. It was just a note for myself while I was doing one the the many pass to split all these functions. This is not I/O and as you probably have already seen, I did not put in I/O. Also patch 19 takes care of the function pointers in BlockDriver, not this (but you discovered it already). Apologies. Not a problem, things like this happen. Just makes you wonder as a reviewer. :) Hanna
Re: [PATCH v4 06/25] include/block/block_int: split header into I/O and global state API
On 12/11/2021 13:17, Hanna Reitz wrote: On 25.10.21 12:17, Emanuele Giuseppe Esposito wrote: Similarly to the previous patch, split block_int.h in block_int-io.h and block_int-global-state.h block_int-common.h contains the structures shared between the two headers, and the functions that can't be categorized as I/O or global state. Assertions are added in the next patch. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Stefan Hajnoczi --- blockdev.c | 5 + include/block/block_int-common.h | 1164 +++ include/block/block_int-global-state.h | 319 + include/block/block_int-io.h | 163 +++ include/block/block_int.h | 1478 +--- 5 files changed, 1654 insertions(+), 1475 deletions(-) create mode 100644 include/block/block_int-common.h create mode 100644 include/block/block_int-global-state.h create mode 100644 include/block/block_int-io.h [...] diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h new file mode 100644 index 00..79a3d801d2 --- /dev/null +++ b/include/block/block_int-common.h [...] +struct BlockDriver { [...] + /** + * Try to get @bs's logical and physical block size. + * On success, store them in @bsz and return zero. + * On failure, return negative errno. + */ + /* I/O API, even though if it's a filter jumps on parent */ I don’t understand this... + int (*bdrv_probe_blocksizes)(BlockDriverState *bs, BlockSizes *bsz); + /** + * Try to get @bs's geometry (cyls, heads, sectors) + * On success, store them in @geo and return 0. + * On failure return -errno. + * Only drivers that want to override guest geometry implement this + * callback; see hd_geometry_guess(). + */ + /* I/O API, even though if it's a filter jumps on parent */ ...or this comment. bdrv_probe_blocksizes() and bdrv_probe_geometry() are in block-global-state.h, so why are these methods part of the I/O API? (And I’m afraid I can’t parse “even though if it’s a filter jumps on parent”.) Ok this is weird. This comment should not have been there, please ignore it. It was just a note for myself while I was doing one the the many pass to split all these functions. This is not I/O and as you probably have already seen, I did not put in I/O. Also patch 19 takes care of the function pointers in BlockDriver, not this (but you discovered it already). Apologies. Emanuele Hanna + int (*bdrv_probe_geometry)(BlockDriverState *bs, HDGeometry *geo);
Re: [PATCH v4 06/25] include/block/block_int: split header into I/O and global state API
On 25.10.21 12:17, Emanuele Giuseppe Esposito wrote: Similarly to the previous patch, split block_int.h in block_int-io.h and block_int-global-state.h block_int-common.h contains the structures shared between the two headers, and the functions that can't be categorized as I/O or global state. Assertions are added in the next patch. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Stefan Hajnoczi --- blockdev.c |5 + include/block/block_int-common.h | 1164 +++ include/block/block_int-global-state.h | 319 + include/block/block_int-io.h | 163 +++ include/block/block_int.h | 1478 +--- 5 files changed, 1654 insertions(+), 1475 deletions(-) create mode 100644 include/block/block_int-common.h create mode 100644 include/block/block_int-global-state.h create mode 100644 include/block/block_int-io.h [...] diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h new file mode 100644 index 00..79a3d801d2 --- /dev/null +++ b/include/block/block_int-common.h [...] +struct BlockDriver { [...] +/** + * Try to get @bs's logical and physical block size. + * On success, store them in @bsz and return zero. + * On failure, return negative errno. + */ +/* I/O API, even though if it's a filter jumps on parent */ I don’t understand this... +int (*bdrv_probe_blocksizes)(BlockDriverState *bs, BlockSizes *bsz); +/** + * Try to get @bs's geometry (cyls, heads, sectors) + * On success, store them in @geo and return 0. + * On failure return -errno. + * Only drivers that want to override guest geometry implement this + * callback; see hd_geometry_guess(). + */ +/* I/O API, even though if it's a filter jumps on parent */ ...or this comment. bdrv_probe_blocksizes() and bdrv_probe_geometry() are in block-global-state.h, so why are these methods part of the I/O API? (And I’m afraid I can’t parse “even though if it’s a filter jumps on parent”.) Hanna +int (*bdrv_probe_geometry)(BlockDriverState *bs, HDGeometry *geo);
[PATCH v4 06/25] include/block/block_int: split header into I/O and global state API
Similarly to the previous patch, split block_int.h in block_int-io.h and block_int-global-state.h block_int-common.h contains the structures shared between the two headers, and the functions that can't be categorized as I/O or global state. Assertions are added in the next patch. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Stefan Hajnoczi --- blockdev.c |5 + include/block/block_int-common.h | 1164 +++ include/block/block_int-global-state.h | 319 + include/block/block_int-io.h | 163 +++ include/block/block_int.h | 1478 +--- 5 files changed, 1654 insertions(+), 1475 deletions(-) create mode 100644 include/block/block_int-common.h create mode 100644 include/block/block_int-global-state.h create mode 100644 include/block/block_int-io.h diff --git a/blockdev.c b/blockdev.c index ae322ed10e..ddba382abd 100644 --- a/blockdev.c +++ b/blockdev.c @@ -63,6 +63,7 @@ #include "qemu/main-loop.h" #include "qemu/throttle-options.h" +/* Protected by BQL lock */ QTAILQ_HEAD(, BlockDriverState) monitor_bdrv_states = QTAILQ_HEAD_INITIALIZER(monitor_bdrv_states); @@ -1207,6 +1208,8 @@ typedef struct BlkActionState BlkActionState; * * Only prepare() may fail. In a single transaction, only one of commit() or * abort() will be called. clean() will always be called if it is present. + * + * Always run under BQL. */ typedef struct BlkActionOps { size_t instance_size; @@ -2316,6 +2319,8 @@ static TransactionProperties *get_transaction_properties( /* * 'Atomic' group operations. The operations are performed as a set, and if * any fail then we roll back all operations in the group. + * + * Always run under BQL. */ void qmp_transaction(TransactionActionList *dev_list, bool has_props, diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h new file mode 100644 index 00..79a3d801d2 --- /dev/null +++ b/include/block/block_int-common.h @@ -0,0 +1,1164 @@ +/* + * QEMU System Emulator block driver + * + * Copyright (c) 2003 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef BLOCK_INT_COMMON_H +#define BLOCK_INT_COMMON_H + +#include "block/accounting.h" +#include "block/block.h" +#include "block/aio-wait.h" +#include "qemu/queue.h" +#include "qemu/coroutine.h" +#include "qemu/stats64.h" +#include "qemu/timer.h" +#include "qemu/hbitmap.h" +#include "block/snapshot.h" +#include "qemu/throttle.h" +#include "qemu/rcu.h" + +#define BLOCK_FLAG_LAZY_REFCOUNTS 8 + +#define BLOCK_OPT_SIZE "size" +#define BLOCK_OPT_ENCRYPT "encryption" +#define BLOCK_OPT_ENCRYPT_FORMAT"encrypt.format" +#define BLOCK_OPT_COMPAT6 "compat6" +#define BLOCK_OPT_HWVERSION "hwversion" +#define BLOCK_OPT_BACKING_FILE "backing_file" +#define BLOCK_OPT_BACKING_FMT "backing_fmt" +#define BLOCK_OPT_CLUSTER_SIZE "cluster_size" +#define BLOCK_OPT_TABLE_SIZE"table_size" +#define BLOCK_OPT_PREALLOC "preallocation" +#define BLOCK_OPT_SUBFMT"subformat" +#define BLOCK_OPT_COMPAT_LEVEL "compat" +#define BLOCK_OPT_LAZY_REFCOUNTS"lazy_refcounts" +#define BLOCK_OPT_ADAPTER_TYPE "adapter_type" +#define BLOCK_OPT_REDUNDANCY"redundancy" +#define BLOCK_OPT_NOCOW "nocow" +#define BLOCK_OPT_EXTENT_SIZE_HINT "extent_size_hint" +#define BLOCK_OPT_OBJECT_SIZE "object_size" +#define BLOCK_OPT_REFCOUNT_BITS "refcount_bits" +#define BLOCK_OPT_DATA_FILE "data_file" +#define BLOCK_OPT_DATA_FILE_RAW "data_file_raw" +#define BLOCK_OPT_COMPRESSION_TYPE "compression_type" +#define BLOCK_OPT_EXTL2 "extended_l2" + +#define BLOCK_PROBE_BUF_SIZE512 + +enum BdrvTrackedRequestType { +BDRV_TRACKED_READ, +BDRV_TRACKED_WRITE, +BDRV_TRACKED_DISCARD, +