2 * BlockBackend RAM Registrar
4 * SPDX-License-Identifier: GPL-2.0-or-later
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
,
15 BlockRAMRegistrar
*r
= container_of(n
, BlockRAMRegistrar
, notifier
);
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
);
29 static void ram_block_removed(RAMBlockNotifier
*n
, void *host
, size_t 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
)
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.
50 ram_block_notifier_add(&r
->notifier
);
53 void blk_ram_registrar_destroy(BlockRAMRegistrar
*r
)
56 ram_block_notifier_remove(&r
->notifier
);