|
Packit Service |
ea0369 |
/*
|
|
Packit Service |
ea0369 |
* libvirt-gconfig-domain-hostdev.c: libvirt domain hostdev configuration
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Copyright (C) 2016 Red Hat, Inc.
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
ea0369 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
ea0369 |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
ea0369 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
ea0369 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
ea0369 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
ea0369 |
* Lesser General Public License for more details.
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
ea0369 |
* License along with this library. If not, see
|
|
Packit Service |
ea0369 |
* <http://www.gnu.org/licenses/>.
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Authors: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
|
|
Packit Service |
ea0369 |
* Christophe Fergeau <cfergeau@redhat.com>
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
#include <config.h>
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
#include "libvirt-gconfig/libvirt-gconfig.h"
|
|
Packit Service |
ea0369 |
#include "libvirt-gconfig/libvirt-gconfig-private.h"
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
#define GVIR_CONFIG_DOMAIN_HOSTDEV_GET_PRIVATE(obj) \
|
|
Packit Service |
ea0369 |
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV, GVirConfigDomainHostdevPrivate))
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
struct _GVirConfigDomainHostdevPrivate
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
gboolean unused;
|
|
Packit Service |
ea0369 |
};
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(GVirConfigDomainHostdev, gvir_config_domain_hostdev, GVIR_CONFIG_TYPE_DOMAIN_DEVICE);
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
static void gvir_config_domain_hostdev_class_init(GVirConfigDomainHostdevClass *klass G_GNUC_UNUSED)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
static void gvir_config_domain_hostdev_init(GVirConfigDomainHostdev *hostdev)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
hostdev->priv = GVIR_CONFIG_DOMAIN_HOSTDEV_GET_PRIVATE(hostdev);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
G_GNUC_INTERNAL GVirConfigDomainDevice *
|
|
Packit Service |
ea0369 |
gvir_config_domain_hostdev_new_from_tree(GVirConfigXmlDoc *doc,
|
|
Packit Service |
ea0369 |
xmlNodePtr tree)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
const char *type;
|
|
Packit Service |
ea0369 |
GType gtype;
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
type = gvir_config_xml_get_attribute_content(tree, "type");
|
|
Packit Service |
ea0369 |
if (type == NULL)
|
|
Packit Service |
ea0369 |
return NULL;
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
if (g_str_equal(type, "usb")) {
|
|
Packit Service |
ea0369 |
goto unimplemented;
|
|
Packit Service |
ea0369 |
} else if (g_str_equal(type, "pci")) {
|
|
Packit Service |
ea0369 |
gtype = GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI;
|
|
Packit Service |
ea0369 |
} else if (g_str_equal(type, "scsi")) {
|
|
Packit Service |
ea0369 |
goto unimplemented;
|
|
Packit Service |
ea0369 |
} else {
|
|
Packit Service |
ea0369 |
g_debug("Unknown domain hostdev node: %s", type);
|
|
Packit Service |
ea0369 |
return NULL;
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
return GVIR_CONFIG_DOMAIN_DEVICE(gvir_config_object_new_from_tree(gtype, doc, NULL, tree));
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
unimplemented:
|
|
Packit Service |
ea0369 |
g_debug("Parsing of '%s' domain hostdev nodes is unimplemented", type);
|
|
Packit Service |
ea0369 |
return NULL;
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
/**
|
|
Packit Service |
ea0369 |
* gvir_config_domain_hostdev_set_boot_order:
|
|
Packit Service |
ea0369 |
* @hostdev: the host device
|
|
Packit Service |
ea0369 |
* @order: the boot order
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* If a positive integer is passed as @order, @hostdev is marked bootable and
|
|
Packit Service |
ea0369 |
* boot order set to @order, otherwise @hostdev is marked to be unbootable.
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
void gvir_config_domain_hostdev_set_boot_order(GVirConfigDomainHostdev *hostdev,
|
|
Packit Service |
ea0369 |
gint order)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_HOSTDEV(hostdev));
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
if (order >= 0) {
|
|
Packit Service |
ea0369 |
char *order_str = g_strdup_printf("%u", order);
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
gvir_config_object_replace_child_with_attribute(GVIR_CONFIG_OBJECT(hostdev),
|
|
Packit Service |
ea0369 |
"boot",
|
|
Packit Service |
ea0369 |
"order",
|
|
Packit Service |
ea0369 |
order_str);
|
|
Packit Service |
ea0369 |
g_free(order_str);
|
|
Packit Service |
ea0369 |
} else {
|
|
Packit Service |
ea0369 |
gvir_config_object_delete_child(GVIR_CONFIG_OBJECT(hostdev),
|
|
Packit Service |
ea0369 |
"boot",
|
|
Packit Service |
ea0369 |
NULL);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
/**
|
|
Packit Service |
ea0369 |
* gvir_config_domain_hostdev_get_boot_order:
|
|
Packit Service |
ea0369 |
* @hostdev: the host device
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Returns: The boot order if @hostdev is bootable, otherwise a negative integer.
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
gint gvir_config_domain_hostdev_get_boot_order(GVirConfigDomainHostdev *hostdev)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
return gvir_config_object_get_attribute_uint64(GVIR_CONFIG_OBJECT(hostdev),
|
|
Packit Service |
ea0369 |
"boot", "order", -1);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
/**
|
|
Packit Service |
ea0369 |
* gvir_config_domain_hostdev_set_readonly:
|
|
Packit Service |
ea0369 |
* @hostdev: the host device
|
|
Packit Service |
ea0369 |
* @readonly: the new readonly status
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Set the readonly status of @hostdev to @readonly.
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
void gvir_config_domain_hostdev_set_readonly(GVirConfigDomainHostdev *hostdev,
|
|
Packit Service |
ea0369 |
gboolean readonly)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_HOSTDEV(hostdev));
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
if (readonly) {
|
|
Packit Service |
ea0369 |
GVirConfigObject *node;
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(hostdev),
|
|
Packit Service |
ea0369 |
"readonly");
|
|
Packit Service |
ea0369 |
g_object_unref(node);
|
|
Packit Service |
ea0369 |
} else {
|
|
Packit Service |
ea0369 |
gvir_config_object_delete_child(GVIR_CONFIG_OBJECT(hostdev),
|
|
Packit Service |
ea0369 |
"readonly", NULL);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
/**
|
|
Packit Service |
ea0369 |
* gvir_config_domain_hostdev_get_readonly:
|
|
Packit Service |
ea0369 |
* @hostdev: the host device
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Returns: %TRUE if @hostdev is readonly, %FALSE otherwise.
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
gboolean gvir_config_domain_hostdev_get_readonly(GVirConfigDomainHostdev *hostdev)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
return gvir_config_object_has_child(GVIR_CONFIG_OBJECT(hostdev),
|
|
Packit Service |
ea0369 |
"readonly");
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
/**
|
|
Packit Service |
ea0369 |
* gvir_config_domain_hostdev_set_shareable:
|
|
Packit Service |
ea0369 |
* @hostdev: the host device
|
|
Packit Service |
ea0369 |
* @shareable: the new shareable status
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Set whether or not @hostdev is shared between domains.
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
void gvir_config_domain_hostdev_set_shareable(GVirConfigDomainHostdev *hostdev,
|
|
Packit Service |
ea0369 |
gboolean shareable)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_HOSTDEV(hostdev));
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
if (shareable) {
|
|
Packit Service |
ea0369 |
GVirConfigObject *node;
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(hostdev),
|
|
Packit Service |
ea0369 |
"shareable");
|
|
Packit Service |
ea0369 |
g_object_unref(node);
|
|
Packit Service |
ea0369 |
} else {
|
|
Packit Service |
ea0369 |
gvir_config_object_delete_child(GVIR_CONFIG_OBJECT(hostdev),
|
|
Packit Service |
ea0369 |
"shareable", NULL);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
/**
|
|
Packit Service |
ea0369 |
* gvir_config_domain_hostdev_get_shareable:
|
|
Packit Service |
ea0369 |
* @hostdev: the host device
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Returns: %TRUE if @hostdev is shared between domains, %FALSE otherwise.
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
gboolean gvir_config_domain_hostdev_get_shareable(GVirConfigDomainHostdev *hostdev)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
return gvir_config_object_has_child(GVIR_CONFIG_OBJECT(hostdev),
|
|
Packit Service |
ea0369 |
"shareable");
|
|
Packit Service |
ea0369 |
}
|