vhost-user.rst: Fix vring address description
[qemu/ar7.git] / block / block-ram-registrar.c
blob25dbafa789c217328952bc7080959878554d58a7
1 /*
2 * BlockBackend RAM Registrar
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
7 #include "qemu/osdep.h"
8 #include "sysemu/block-backend.h"
9 #include "sysemu/block-ram-registrar.h"
10 #include "qapi/error.h"
12 static void ram_block_added(RAMBlockNotifier *n, void *host, size_t size,
13 size_t max_size)
15 BlockRAMRegistrar *r = container_of(n, BlockRAMRegistrar, notifier);
16 Error *err = NULL;
18 if (!r->ok) {
19 return; /* don't try again if we've already failed */
22 if (!blk_register_buf(r->blk, host, max_size, &err)) {
23 error_report_err(err);
24 ram_block_notifier_remove(&r->notifier);
25 r->ok = false;
29 static void ram_block_removed(RAMBlockNotifier *n, void *host, size_t size,
30 size_t max_size)
32 BlockRAMRegistrar *r = container_of(n, BlockRAMRegistrar, notifier);
33 blk_unregister_buf(r->blk, host, max_size);
36 void blk_ram_registrar_init(BlockRAMRegistrar *r, BlockBackend *blk)
38 r->blk = blk;
39 r->notifier = (RAMBlockNotifier){
40 .ram_block_added = ram_block_added,
41 .ram_block_removed = ram_block_removed,
44 * .ram_block_resized() is not necessary because we use the max_size
45 * value that does not change across resize.
48 r->ok = true;
50 ram_block_notifier_add(&r->notifier);
53 void blk_ram_registrar_destroy(BlockRAMRegistrar *r)
55 if (r->ok) {
56 ram_block_notifier_remove(&r->notifier);