mirror of https://gitlab.com/libvirt/libvirt.git
Compare commits
5 Commits
72b49aa22d
...
14e412746d
Author | SHA1 | Date |
---|---|---|
aokblast | 14e412746d | |
Peter Krempa | df9ffb0256 | |
Peter Krempa | bc596f2751 | |
Michal Privoznik | e6a5592787 | |
aokblast | 45d2967af0 |
|
@ -604,6 +604,9 @@ struct _virDomain {
|
|||
unsigned char uuid[VIR_UUID_BUFLEN]; /* the domain unique identifier */
|
||||
};
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomain, virObjectUnref);
|
||||
|
||||
|
||||
/**
|
||||
* _virNetwork:
|
||||
*
|
||||
|
@ -647,6 +650,9 @@ struct _virInterface {
|
|||
char *mac; /* the interface MAC address */
|
||||
};
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virInterface, virObjectUnref);
|
||||
|
||||
|
||||
/**
|
||||
* _virStoragePool:
|
||||
*
|
||||
|
@ -706,6 +712,7 @@ struct _virNodeDevice {
|
|||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNodeDevice, virObjectUnref);
|
||||
|
||||
|
||||
/**
|
||||
* _virSecret:
|
||||
*
|
||||
|
@ -751,6 +758,8 @@ struct _virDomainCheckpoint {
|
|||
virDomainPtr domain;
|
||||
};
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainCheckpoint, virObjectUnref);
|
||||
|
||||
|
||||
/**
|
||||
* _virDomainSnapshot
|
||||
|
@ -763,6 +772,9 @@ struct _virDomainSnapshot {
|
|||
virDomainPtr domain;
|
||||
};
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainSnapshot, virObjectUnref);
|
||||
|
||||
|
||||
/**
|
||||
* _virNWFilter:
|
||||
*
|
||||
|
@ -775,6 +787,8 @@ struct _virNWFilter {
|
|||
unsigned char uuid[VIR_UUID_BUFLEN]; /* the network filter unique identifier */
|
||||
};
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNWFilter, virObjectUnref);
|
||||
|
||||
|
||||
/**
|
||||
* _virNWFilterBinding:
|
||||
|
@ -788,6 +802,8 @@ struct _virNWFilterBinding {
|
|||
char *filtername; /* the network filter name */
|
||||
};
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNWFilterBinding, virObjectUnref);
|
||||
|
||||
|
||||
/*
|
||||
* Helper APIs for allocating new object instances
|
||||
|
|
|
@ -137,55 +137,21 @@ udevGetDevices(struct udev *udev, virUdevStatus status)
|
|||
return enumerate;
|
||||
}
|
||||
|
||||
static int
|
||||
udevNumOfInterfacesByStatus(virConnectPtr conn, virUdevStatus status,
|
||||
virInterfaceObjListFilter filter)
|
||||
{
|
||||
struct udev *udev = udev_ref(driver->udev);
|
||||
struct udev_enumerate *enumerate = NULL;
|
||||
struct udev_list_entry *devices;
|
||||
struct udev_list_entry *dev_entry;
|
||||
int count = 0;
|
||||
|
||||
enumerate = udevGetDevices(udev, status);
|
||||
|
||||
if (!enumerate) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("failed to get number of %1$s interfaces on host"),
|
||||
virUdevStatusString(status));
|
||||
count = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Do the scan to load up the enumeration */
|
||||
udev_enumerate_scan_devices(enumerate);
|
||||
|
||||
/* Get a list we can walk */
|
||||
devices = udev_enumerate_get_list_entry(enumerate);
|
||||
|
||||
/* For each item so we can count */
|
||||
udev_list_entry_foreach(dev_entry, devices) {
|
||||
struct udev_device *dev;
|
||||
const char *path;
|
||||
g_autoptr(virInterfaceDef) def = NULL;
|
||||
|
||||
path = udev_list_entry_get_name(dev_entry);
|
||||
dev = udev_device_new_from_syspath(udev, path);
|
||||
|
||||
def = udevGetMinimalDefForDevice(dev);
|
||||
if (filter(conn, def))
|
||||
count++;
|
||||
udev_device_unref(dev);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if (enumerate)
|
||||
udev_enumerate_unref(enumerate);
|
||||
udev_unref(udev);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* udevListInterfacesByStatus:
|
||||
*
|
||||
* @conn: connection object
|
||||
* @names: optional pointer to array to be filled with interface names
|
||||
* @names_len: size of @names
|
||||
* @status: status of interfaces to be listed
|
||||
* @filter: ACL filter function
|
||||
*
|
||||
* Lists interfaces with status matching @status filling them into @names (if
|
||||
* non-NULL) and returns the number of such interfaces.
|
||||
*
|
||||
* In case of an error -1 is returned and no interfaces are filled into @names.
|
||||
*/
|
||||
static int
|
||||
udevListInterfacesByStatus(virConnectPtr conn,
|
||||
char **const names,
|
||||
|
@ -219,18 +185,27 @@ udevListInterfacesByStatus(virConnectPtr conn,
|
|||
udev_list_entry_foreach(dev_entry, devices) {
|
||||
struct udev_device *dev;
|
||||
const char *path;
|
||||
const char *name;
|
||||
g_autoptr(virInterfaceDef) def = NULL;
|
||||
|
||||
/* Ensure we won't exceed the size of our array */
|
||||
if (count >= names_len)
|
||||
if (names && count >= names_len)
|
||||
break;
|
||||
|
||||
path = udev_list_entry_get_name(dev_entry);
|
||||
dev = udev_device_new_from_syspath(udev, path);
|
||||
|
||||
if (!(name = udev_device_get_sysname(dev))) {
|
||||
/* Name can be NULL in case when the interface is being unbound
|
||||
* from the driver. The list API requires names to be present */
|
||||
VIR_DEBUG("Skipping interface '%s', name == NULL", path);
|
||||
continue;
|
||||
}
|
||||
|
||||
def = udevGetMinimalDefForDevice(dev);
|
||||
if (filter(conn, def)) {
|
||||
names[count] = g_strdup(udev_device_get_sysname(dev));
|
||||
if (names)
|
||||
names[count] = g_strdup(name);
|
||||
count++;
|
||||
}
|
||||
udev_device_unref(dev);
|
||||
|
@ -242,14 +217,15 @@ udevListInterfacesByStatus(virConnectPtr conn,
|
|||
return count;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
udevConnectNumOfInterfaces(virConnectPtr conn)
|
||||
{
|
||||
if (virConnectNumOfInterfacesEnsureACL(conn) < 0)
|
||||
return -1;
|
||||
|
||||
return udevNumOfInterfacesByStatus(conn, VIR_UDEV_IFACE_ACTIVE,
|
||||
virConnectNumOfInterfacesCheckACL);
|
||||
return udevListInterfacesByStatus(conn, NULL, 0, VIR_UDEV_IFACE_ACTIVE,
|
||||
virConnectNumOfInterfacesCheckACL);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -271,8 +247,8 @@ udevConnectNumOfDefinedInterfaces(virConnectPtr conn)
|
|||
if (virConnectNumOfDefinedInterfacesEnsureACL(conn) < 0)
|
||||
return -1;
|
||||
|
||||
return udevNumOfInterfacesByStatus(conn, VIR_UDEV_IFACE_INACTIVE,
|
||||
virConnectNumOfDefinedInterfacesCheckACL);
|
||||
return udevListInterfacesByStatus(conn, NULL, 0, VIR_UDEV_IFACE_INACTIVE,
|
||||
virConnectNumOfDefinedInterfacesCheckACL);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
@ -2104,7 +2104,7 @@ remoteDispatchConnectOpen(virNetServer *server G_GNUC_UNUSED,
|
|||
STREQ(type, "Xen") ||
|
||||
STREQ(type, "LXC") ||
|
||||
STREQ(type, "VBOX") ||
|
||||
STREQ(type, "bhyve") ||
|
||||
STREQ(type, "BHYVE") ||
|
||||
STREQ(type, "vz") ||
|
||||
STREQ(type, "Parallels") ||
|
||||
STREQ(type, "CH")) {
|
||||
|
|
Loading…
Reference in New Issue