diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2020-10-02 16:19:42 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2020-10-02 16:19:42 +0100 |
commit | 469e72ab7dbbd7ff4ee601e5ea7c29545d46593b (patch) | |
tree | 0f49f57d83db9ae500cd79f8eb0455355ace4fe4 /qemu-nbd.c | |
parent | dd8c1e808f1ca311e1f50bff218c3ee3198b1f02 (diff) | |
parent | c508c73dca636cc0fc7413d1e4a43fcfe4a5698c (diff) |
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging
Block layer patches:
- Add block export infrastructure
- iotests improvements
- Document the throttle block filter
- Misc code cleanups
# gpg: Signature made Fri 02 Oct 2020 15:36:53 BST
# gpg: using RSA key DC3DEB159A9AF95D3D7456FE7F09B272C88F2FD6
# gpg: issuer "kwolf@redhat.com"
# gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>" [full]
# Primary key fingerprint: DC3D EB15 9A9A F95D 3D74 56FE 7F09 B272 C88F 2FD6
* remotes/kevin/tags/for-upstream: (37 commits)
qcow2: Use L1E_SIZE in qcow2_write_l1_entry()
qemu-storage-daemon: Fix help line for --export
iotests: Test block-export-* QMP interface
iotests: Allow supported and unsupported formats at the same time
iotests: Introduce qemu_nbd_list_log()
iotests: Factor out qemu_tool_pipe_and_status()
nbd: Deprecate nbd-server-add/remove
nbd: Merge nbd_export_new() and nbd_export_create()
block/export: Move writable to BlockExportOptions
block/export: Add query-block-exports
block/export: Create BlockBackend in blk_exp_add()
block/export: Move blk to BlockExport
block/export: Add BLOCK_EXPORT_DELETED event
block/export: Add block-export-del
block/export: Move strong user reference to block_exports
block/export: Add 'id' option to block-export-add
block/export: Add blk_exp_close_all(_type)
block/export: Allocate BlockExport in blk_exp_add()
block/export: Add node-name to BlockExportOptions
block/export: Move AioContext from NBDExport to BlockExport
...
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'qemu-nbd.c')
-rw-r--r-- | qemu-nbd.c | 67 |
1 files changed, 37 insertions, 30 deletions
diff --git a/qemu-nbd.c b/qemu-nbd.c index e39d3b23c1..bacb69b089 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -65,12 +65,11 @@ #define MBR_SIZE 512 -static NBDExport *export; static int verbose; static char *srcpath; static SocketAddress *saddr; static int persistent = 0; -static enum { RUNNING, TERMINATE, TERMINATING, TERMINATED } state; +static enum { RUNNING, TERMINATE, TERMINATED } state; static int shared = 1; static int nb_fds; static QIONetListener *server; @@ -332,12 +331,6 @@ static int nbd_can_accept(void) return state == RUNNING && nb_fds < shared; } -static void nbd_export_closed(NBDExport *export) -{ - assert(state == TERMINATING); - state = TERMINATED; -} - static void nbd_update_server_watch(void); static void nbd_client_closed(NBDClient *client, bool negotiated) @@ -524,7 +517,6 @@ int main(int argc, char **argv) const char *port = NULL; char *sockpath = NULL; char *device = NULL; - int64_t fd_size; QemuOpts *sn_opts = NULL; const char *sn_id_or_name = NULL; const char *sopt = "hVb:o:p:rsnc:dvk:e:f:tl:x:T:D:B:L"; @@ -587,6 +579,7 @@ int main(int argc, char **argv) int old_stderr = -1; unsigned socket_activation; const char *pid_file_name = NULL; + BlockExportOptions *export_opts; #if HAVE_NBD_DEVICE /* The client thread uses SIGTERM to interrupt the server. A signal @@ -1037,6 +1030,17 @@ int main(int argc, char **argv) } bs = blk_bs(blk); + if (dev_offset) { + QDict *raw_opts = qdict_new(); + qdict_put_str(raw_opts, "driver", "raw"); + qdict_put_str(raw_opts, "file", bs->node_name); + qdict_put_int(raw_opts, "offset", dev_offset); + bs = bdrv_open(NULL, NULL, raw_opts, flags, &error_fatal); + blk_remove_bs(blk); + blk_insert_bs(blk, bs, &error_fatal); + bdrv_unref(bs); + } + blk_set_enable_write_cache(blk, !writethrough); if (sn_opts) { @@ -1054,24 +1058,29 @@ int main(int argc, char **argv) } bs->detect_zeroes = detect_zeroes; - fd_size = blk_getlength(blk); - if (fd_size < 0) { - error_report("Failed to determine the image length: %s", - strerror(-fd_size)); - exit(EXIT_FAILURE); - } - if (dev_offset >= fd_size) { - error_report("Offset (%" PRIu64 ") has to be smaller than the image " - "size (%" PRId64 ")", dev_offset, fd_size); - exit(EXIT_FAILURE); - } - fd_size -= dev_offset; - - export = nbd_export_new(bs, dev_offset, fd_size, export_name, - export_description, bitmap, readonly, shared > 1, - nbd_export_closed, writethrough, NULL, - &error_fatal); + nbd_server_is_qemu_nbd(true); + + export_opts = g_new(BlockExportOptions, 1); + *export_opts = (BlockExportOptions) { + .type = BLOCK_EXPORT_TYPE_NBD, + .id = g_strdup("qemu-nbd-export"), + .node_name = g_strdup(bdrv_get_node_name(bs)), + .has_writethrough = true, + .writethrough = writethrough, + .has_writable = true, + .writable = !readonly, + .u.nbd = { + .has_name = true, + .name = g_strdup(export_name), + .has_description = !!export_description, + .description = g_strdup(export_description), + .has_bitmap = !!bitmap, + .bitmap = g_strdup(bitmap), + }, + }; + blk_exp_add(export_opts, &error_fatal); + qapi_free_BlockExportOptions(export_opts); if (device) { #if HAVE_NBD_DEVICE @@ -1111,10 +1120,8 @@ int main(int argc, char **argv) do { main_loop_wait(false); if (state == TERMINATE) { - state = TERMINATING; - nbd_export_close(export); - nbd_export_put(export); - export = NULL; + blk_exp_close_all(); + state = TERMINATED; } } while (state != TERMINATED); |