vmm: use modern list-model interface

Issue #4317
This commit is contained in:
Norman Feske 2023-10-26 17:39:46 +02:00 committed by Christian Helmuth
parent 672b03f553
commit 50d0a1b8f9
2 changed files with 45 additions and 48 deletions

View File

@ -61,6 +61,25 @@ void Vmm::Config::update(Xml_node node)
_cpu_count = 1;
}
Virtio_device_update_policy policy(*this);
_model.update_from_xml(policy, node);
update_list_model_from_xml(_model, node,
/* create */
[&] (Xml_node const &node) -> Virtio_device &
{
Config::Name name = node.attribute_value("name", Config::Name());
Virtio_device::Type t = Virtio_device::type_from_xml(node);
if (t == Virtio_device::INVALID || !name.valid()) {
error("Invalid type or missing name in Virtio device node");
throw Invalid_configuration();
}
return *new (_heap) Virtio_device(name, t, *this);
},
/* destroy */
[&] (Virtio_device &dev) { destroy(_heap, &dev); },
/* update */
[&] (Virtio_device &, Xml_node const &) { }
);
}

View File

@ -62,6 +62,30 @@ class Vmm::Config
void * const mmio_start;
size_t const mmio_size;
unsigned const irq;
static Type type_from_xml(Xml_node const &node)
{
Config::Name const type = node.attribute_value("type", Config::Name());
if (type == "console") return CONSOLE;
if (type == "net") return NET;
if (type == "block") return BLOCK;
if (type == "gpu") return GPU;
if (type == "input") return INPUT;
return INVALID;
}
bool matches(Xml_node const &node) const
{
return (name == node.attribute_value("name", Config::Name()))
&& (type == type_from_xml(node));
}
static bool type_matches(Xml_node const &node)
{
return node.has_type("virtio_device");
}
};
private:
@ -94,52 +118,6 @@ class Vmm::Config
List_model<Virtio_device> _model {};
struct Virtio_device_update_policy
: List_model<Config::Virtio_device>::Update_policy
{
Config & config;
Virtio_device_update_policy(Config & config)
: config(config) {}
static Virtio_device::Type type(Xml_node node)
{
Virtio_device::Type t = Virtio_device::INVALID;
Config::Name type = node.attribute_value("type", Config::Name());
if (type == "console") t = Virtio_device::CONSOLE;
if (type == "net") t = Virtio_device::NET;
if (type == "block") t = Virtio_device::BLOCK;
if (type == "gpu") t = Virtio_device::GPU;
if (type == "input") t = Virtio_device::INPUT;
return t;
}
void destroy_element(Element & dev) { destroy(config._heap, &dev); }
Element & create_element(Genode::Xml_node node)
{
Config::Name name = node.attribute_value("name", Config::Name());
Virtio_device::Type t = type(node);
if (t == Virtio_device::INVALID || !name.valid()) {
error("Invalid type or missing name in Virtio device node");
throw Invalid_configuration();
}
return *(new (config._heap) Element(name, t, config));
}
void update_element(Element &, Genode::Xml_node) {}
static bool element_matches_xml_node(Element const & dev, Xml_node node)
{
Config::Name name = node.attribute_value("name", Config::Name());
Virtio_device::Type t = type(node);
return name == dev.name && t == dev.type;
}
static bool node_is_element(Xml_node node) {
return node.has_type("virtio_device"); }
};
public:
Config(Heap & heap) : _heap(heap) {