/** * virConnectListAllNWFilters: * @conn: Pointer to the hypervisor connection. * @filters: Pointer to a variable to store the array containing the network * filter objects or NULL if the list is not required (just returns * number of network filters). * @flags: extra flags; not used yet, so callers should always pass 0 * * Collect the list of network filters, and allocate an array to store those * objects. * * Returns the number of network filters found or -1 and sets @filters to NULL * in case of error. On success, the array stored into @filters is guaranteed to * have an extra allocated element set to NULL but not included in the return count, * to make iteration easier. The caller is responsible for calling * virNWFilterFree() on each array element, then calling free() on @filters. */ int virConnectListAllNWFilters(virConnectPtr conn, virNWFilterPtr **filters, unsigned int flags) { VIR_DEBUG("conn=%p, filters=%p, flags=0x%x", conn, filters, flags); virResetLastError(); if (filters) *filters = NULL; virCheckConnectReturn(conn, -1); if (conn->nwfilterDriver && conn->nwfilterDriver->connectListAllNWFilters) { int ret; ret = conn->nwfilterDriver->connectListAllNWFilters(conn, filters, flags); if (ret < 0) goto error; return ret; } virReportUnsupportedError(); error: virDispatchError(conn); return -1; }
/** * virNetworkDefineXML: * @conn: pointer to the hypervisor connection * @xml: the XML description for the network, preferably in UTF-8 * * Define an inactive persistent virtual network or modify an existing * persistent one from the XML description. * * virNetworkFree should be used to free the resources after the * network object is no longer needed. * * Returns NULL in case of error, a pointer to the network otherwise */ virNetworkPtr virNetworkDefineXML(virConnectPtr conn, const char *xml) { VIR_DEBUG("conn=%p, xml=%s", conn, NULLSTR(xml)); virResetLastError(); virCheckConnectReturn(conn, NULL); virCheckReadOnlyGoto(conn->flags, error); virCheckNonNullArgGoto(xml, error); if (conn->networkDriver && conn->networkDriver->networkDefineXML) { virNetworkPtr ret; ret = conn->networkDriver->networkDefineXML(conn, xml); if (!ret) goto error; return ret; } virReportUnsupportedError(); error: virDispatchError(conn); return NULL; }
/** * virDomainQemuAttach: * @conn: pointer to a hypervisor connection * @pid_value: the UNIX process ID of the external QEMU process * @flags: optional flags, currently unused * * This API is QEMU specific, so it will only work with hypervisor * connections to the QEMU driver. * * This API will attach to an externally launched QEMU process * identified by @pid. There are several requirements to successfully * attach to an external QEMU process: * * - It must have been started with a monitor socket using the UNIX * domain socket protocol. * - No device hotplug/unplug, or other configuration changes can * have been made via the monitor since it started. * - The '-name' and '-uuid' arguments should have been set (not * mandatory, but strongly recommended) * * To date, the only platforms we know of where pid_t is larger than * unsigned int (64-bit Windows) also lack UNIX sockets, so the choice * of @pid_value as an unsigned int should not present any difficulties. * * If successful, then the guest will appear in the list of running * domains for this connection, and other APIs should operate * normally (provided the above requirements were honored). * * Returns a new domain object on success, NULL otherwise */ virDomainPtr virDomainQemuAttach(virConnectPtr conn, unsigned int pid_value, unsigned int flags) { pid_t pid = pid_value; VIR_DEBUG("conn=%p, pid=%u, flags=%x", conn, pid_value, flags); virResetLastError(); virCheckConnectReturn(conn, NULL); virCheckPositiveArgGoto(pid_value, error); if (pid != pid_value) { virReportInvalidArg(pid_value, _("pid_value in %s is too large"), __FUNCTION__); goto error; } virCheckReadOnlyGoto(conn->flags, error); if (conn->driver->domainQemuAttach) { virDomainPtr ret; ret = conn->driver->domainQemuAttach(conn, pid_value, flags); if (!ret) goto error; return ret; } virReportUnsupportedError(); error: virDispatchError(conn); return NULL; }
/** * virNodeDeviceCreateXML: * @conn: pointer to the hypervisor connection * @xmlDesc: string containing an XML description of the device to be created * @flags: extra flags; not used yet, so callers should always pass 0 * * Create a new device on the VM host machine, for example, virtual * HBAs created using vport_create. * * virNodeDeviceFree should be used to free the resources after the * node device object is no longer needed. * * Returns a node device object if successful, NULL in case of failure */ virNodeDevicePtr virNodeDeviceCreateXML(virConnectPtr conn, const char *xmlDesc, unsigned int flags) { VIR_DEBUG("conn=%p, xmlDesc=%s, flags=%x", conn, xmlDesc, flags); virResetLastError(); virCheckConnectReturn(conn, NULL); virCheckReadOnlyGoto(conn->flags, error); virCheckNonNullArgGoto(xmlDesc, error); if (conn->nodeDeviceDriver && conn->nodeDeviceDriver->nodeDeviceCreateXML) { virNodeDevicePtr dev = conn->nodeDeviceDriver->nodeDeviceCreateXML(conn, xmlDesc, flags); if (dev == NULL) goto error; return dev; } virReportUnsupportedError(); error: virDispatchError(conn); return NULL; }
/** * virNodeDeviceLookupSCSIHostByWWN: * @conn: pointer to the hypervisor connection * @wwnn: WWNN of the SCSI Host. * @wwpn: WWPN of the SCSI Host. * @flags: extra flags; not used yet, so callers should always pass 0 * * Lookup SCSI Host which is capable with 'fc_host' by its WWNN and WWPN. * * virNodeDeviceFree should be used to free the resources after the * node device object is no longer needed. * * Returns a virNodeDevicePtr if found, NULL otherwise. */ virNodeDevicePtr virNodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, const char *wwnn, const char *wwpn, unsigned int flags) { VIR_DEBUG("conn=%p, wwnn=%p, wwpn=%p, flags=%x", conn, wwnn, wwpn, flags); virResetLastError(); virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(wwnn, error); virCheckNonNullArgGoto(wwpn, error); if (conn->nodeDeviceDriver && conn->nodeDeviceDriver->nodeDeviceLookupSCSIHostByWWN) { virNodeDevicePtr ret; ret = conn->nodeDeviceDriver->nodeDeviceLookupSCSIHostByWWN(conn, wwnn, wwpn, flags); if (!ret) goto error; return ret; } virReportUnsupportedError(); error: virDispatchError(conn); return NULL; }
/** * virNodeListDevices: * @conn: pointer to the hypervisor connection * @cap: capability name * @names: array to collect the list of node device names * @maxnames: size of @names * @flags: extra flags; not used yet, so callers should always pass 0 * * Collect the list of node devices, and store their names in @names * * For more control over the results, see virConnectListAllNodeDevices(). * * If the optional 'cap' argument is non-NULL, then the count * will be restricted to devices with the specified capability * * Returns the number of node devices found or -1 in case of error */ int virNodeListDevices(virConnectPtr conn, const char *cap, char **const names, int maxnames, unsigned int flags) { VIR_DEBUG("conn=%p, cap=%s, names=%p, maxnames=%d, flags=%x", conn, cap, names, maxnames, flags); virResetLastError(); virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(names, error); virCheckNonNegativeArgGoto(maxnames, error); if (conn->nodeDeviceDriver && conn->nodeDeviceDriver->nodeListDevices) { int ret; ret = conn->nodeDeviceDriver->nodeListDevices(conn, cap, names, maxnames, flags); if (ret < 0) goto error; return ret; } virReportUnsupportedError(); error: virDispatchError(conn); return -1; }
/** * virConnectListAllNetworks: * @conn: Pointer to the hypervisor connection. * @nets: Pointer to a variable to store the array containing the network * objects or NULL if the list is not required (just returns number * of networks). * @flags: bitwise-OR of virConnectListAllNetworksFlags. * * Collect the list of networks, and allocate an array to store those * objects. This API solves the race inherent between virConnectListNetworks * and virConnectListDefinedNetworks. * * Normally, all networks are returned; however, @flags can be used to * filter the results for a smaller list of targeted networks. The valid * flags are divided into groups, where each group contains bits that * describe mutually exclusive attributes of a network, and where all bits * within a group describe all possible networks. * * The first group of @flags is VIR_CONNECT_LIST_NETWORKS_ACTIVE (up) and * VIR_CONNECT_LIST_NETWORKS_INACTIVE (down) to filter the networks by state. * * The second group of @flags is VIR_CONNECT_LIST_NETWORKS_PERSISTENT (defined) * and VIR_CONNECT_LIST_NETWORKS_TRANSIENT (running but not defined), to filter * the networks by whether they have persistent config or not. * * The third group of @flags is VIR_CONNECT_LIST_NETWORKS_AUTOSTART * and VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART, to filter the networks by * whether they are marked as autostart or not. * * Returns the number of networks found or -1 and sets @nets to NULL in case * of error. On success, the array stored into @nets is guaranteed to have an * extra allocated element set to NULL but not included in the return count, * to make iteration easier. The caller is responsible for calling * virNetworkFree() on each array element, then calling free() on @nets. */ int virConnectListAllNetworks(virConnectPtr conn, virNetworkPtr **nets, unsigned int flags) { VIR_DEBUG("conn=%p, nets=%p, flags=0x%x", conn, nets, flags); virResetLastError(); if (nets) *nets = NULL; virCheckConnectReturn(conn, -1); if (conn->networkDriver && conn->networkDriver->connectListAllNetworks) { int ret; ret = conn->networkDriver->connectListAllNetworks(conn, nets, flags); if (ret < 0) goto error; return ret; } virReportUnsupportedError(); error: virDispatchError(conn); return -1; }
/** * virConnectListAllNodeDevices: * @conn: Pointer to the hypervisor connection. * @devices: Pointer to a variable to store the array containing the node * device objects or NULL if the list is not required (just returns * number of node devices). * @flags: bitwise-OR of virConnectListAllNodeDevices. * * Collect the list of node devices, and allocate an array to store those * objects. * * Normally, all node devices are returned; however, @flags can be used to * filter the results for a smaller list of targeted node devices. The valid * flags are divided into groups, where each group contains bits that * describe mutually exclusive attributes of a node device, and where all bits * within a group describe all possible node devices. * * Only one group of the @flags is provided to filter the node devices by * capability type, flags include: * VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM * VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV * VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV * VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_INTERFACE * VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET * VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_HOST * VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET * VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI * VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE * VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST * VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS * VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_GENERIC * * Returns the number of node devices found or -1 and sets @devices to NULL in * case of error. On success, the array stored into @devices is guaranteed to * have an extra allocated element set to NULL but not included in the return * count, to make iteration easier. The caller is responsible for calling * virNodeDeviceFree() on each array element, then calling free() on * @devices. */ int virConnectListAllNodeDevices(virConnectPtr conn, virNodeDevicePtr **devices, unsigned int flags) { VIR_DEBUG("conn=%p, devices=%p, flags=%x", conn, devices, flags); virResetLastError(); if (devices) *devices = NULL; virCheckConnectReturn(conn, -1); if (conn->nodeDeviceDriver && conn->nodeDeviceDriver->connectListAllNodeDevices) { int ret; ret = conn->nodeDeviceDriver->connectListAllNodeDevices(conn, devices, flags); if (ret < 0) goto error; return ret; } virReportUnsupportedError(); error: virDispatchError(conn); return -1; }
/** * virConnectListDefinedNetworks: * @conn: pointer to the hypervisor connection * @names: pointer to an array to store the names * @maxnames: size of the array * * list the inactive networks, stores the pointers to the names in @names * * For more control over the results, see virConnectListAllNetworks(). * * Returns the number of names provided in the array or -1 in case of error. * Note that this command is inherently racy; a network can be defined between * a call to virConnectNumOfDefinedNetworks() and this call; you are only * guaranteed that all currently defined networks were listed if the return * is less than @maxnames. The client must call free() on each returned name. */ int virConnectListDefinedNetworks(virConnectPtr conn, char **const names, int maxnames) { VIR_DEBUG("conn=%p, names=%p, maxnames=%d", conn, names, maxnames); virResetLastError(); virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(names, error); virCheckNonNegativeArgGoto(maxnames, error); if (conn->networkDriver && conn->networkDriver->connectListDefinedNetworks) { int ret; ret = conn->networkDriver->connectListDefinedNetworks(conn, names, maxnames); if (ret < 0) goto error; return ret; } virReportUnsupportedError(); error: virDispatchError(conn); return -1; }
/** * virNWFilterBindingCreateXML: * @conn: pointer to the hypervisor connection * @xml: an XML description of the binding * @flags: currently unused, pass 0 * * Define a new network filter, based on an XML description * similar to the one returned by virNWFilterGetXMLDesc(). This * API may be used to associate a filter with a currently running * guest that does not have a filter defined for a specific network * port. Since the bindings are generally automatically managed by * the hypervisor, using this command to define a filter for a network * port and then starting the guest afterwards may prevent the guest * from starting if it attempts to use the network port and finds a * filter already defined. * * virNWFilterFree should be used to free the resources after the * binding object is no longer needed. * * Returns a new binding object or NULL in case of failure */ virNWFilterBindingPtr virNWFilterBindingCreateXML(virConnectPtr conn, const char *xml, unsigned int flags) { VIR_DEBUG("conn=%p, xml=%s", conn, NULLSTR(xml)); virResetLastError(); virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(xml, error); virCheckReadOnlyGoto(conn->flags, error); if (conn->nwfilterDriver && conn->nwfilterDriver->nwfilterBindingCreateXML) { virNWFilterBindingPtr ret; ret = conn->nwfilterDriver->nwfilterBindingCreateXML(conn, xml, flags); if (!ret) goto error; return ret; } virReportUnsupportedError(); error: virDispatchError(conn); return NULL; }
/** * virConnectNetworkEventDeregisterAny: * @conn: pointer to the connection * @callbackID: the callback identifier * * Removes an event callback. The callbackID parameter should be the * value obtained from a previous virConnectNetworkEventRegisterAny() method. * * Returns 0 on success, -1 on failure */ int virConnectNetworkEventDeregisterAny(virConnectPtr conn, int callbackID) { VIR_DEBUG("conn=%p, callbackID=%d", conn, callbackID); virResetLastError(); virCheckConnectReturn(conn, -1); virCheckNonNegativeArgGoto(callbackID, error); if (conn->networkDriver && conn->networkDriver->connectNetworkEventDeregisterAny) { int ret; ret = conn->networkDriver->connectNetworkEventDeregisterAny(conn, callbackID); if (ret < 0) goto error; return ret; } virReportUnsupportedError(); error: virDispatchError(conn); return -1; }
/** * virConnectNetworkEventRegisterAny: * @conn: pointer to the connection * @net: pointer to the network * @eventID: the event type to receive * @cb: callback to the function handling network events * @opaque: opaque data to pass on to the callback * @freecb: optional function to deallocate opaque when not used anymore * * Adds a callback to receive notifications of arbitrary network events * occurring on a network. This function requires that an event loop * has been previously registered with virEventRegisterImpl() or * virEventRegisterDefaultImpl(). * * If @net is NULL, then events will be monitored for any network. If @net * is non-NULL, then only the specific network will be monitored. * * Most types of event have a callback providing a custom set of parameters * for the event. When registering an event, it is thus necessary to use * the VIR_NETWORK_EVENT_CALLBACK() macro to cast the supplied function pointer * to match the signature of this method. * * The virNetworkPtr object handle passed into the callback upon delivery * of an event is only valid for the duration of execution of the callback. * If the callback wishes to keep the network object after the callback * returns, it shall take a reference to it, by calling virNetworkRef(). * The reference can be released once the object is no longer required * by calling virNetworkFree(). * * The return value from this method is a positive integer identifier * for the callback. To unregister a callback, this callback ID should * be passed to the virConnectNetworkEventDeregisterAny() method. * * Returns a callback identifier on success, -1 on failure. */ int virConnectNetworkEventRegisterAny(virConnectPtr conn, virNetworkPtr net, int eventID, virConnectNetworkEventGenericCallback cb, void *opaque, virFreeCallback freecb) { VIR_DEBUG("conn=%p, eventID=%d, cb=%p, opaque=%p, freecb=%p", conn, eventID, cb, opaque, freecb); virResetLastError(); virCheckConnectReturn(conn, -1); if (net) { virCheckNetworkGoto(net, error); if (net->conn != conn) { virReportInvalidArg(net, _("network '%s' in %s must match connection"), net->name, __FUNCTION__); goto error; } } virCheckNonNullArgGoto(cb, error); virCheckNonNegativeArgGoto(eventID, error); if (eventID >= VIR_NETWORK_EVENT_ID_LAST) { virReportInvalidArg(eventID, _("eventID in %s must be less than %d"), __FUNCTION__, VIR_NETWORK_EVENT_ID_LAST); goto error; } if (conn->networkDriver && conn->networkDriver->connectNetworkEventRegisterAny) { int ret; ret = conn->networkDriver->connectNetworkEventRegisterAny(conn, net, eventID, cb, opaque, freecb); if (ret < 0) goto error; return ret; } virReportUnsupportedError(); error: virDispatchError(conn); return -1; }
/** * virNodeNumOfDevices: * @conn: pointer to the hypervisor connection * @cap: capability name * @flags: extra flags; not used yet, so callers should always pass 0 * * Provides the number of node devices. * * If the optional 'cap' argument is non-NULL, then the count * will be restricted to devices with the specified capability * * Returns the number of node devices or -1 in case of error */ int virNodeNumOfDevices(virConnectPtr conn, const char *cap, unsigned int flags) { VIR_DEBUG("conn=%p, cap=%s, flags=%x", conn, NULLSTR(cap), flags); virResetLastError(); virCheckConnectReturn(conn, -1); if (conn->nodeDeviceDriver && conn->nodeDeviceDriver->nodeNumOfDevices) { int ret; ret = conn->nodeDeviceDriver->nodeNumOfDevices(conn, cap, flags); if (ret < 0) goto error; return ret; } virReportUnsupportedError(); error: virDispatchError(conn); return -1; }
/** * virConnectNumOfDefinedNetworks: * @conn: pointer to the hypervisor connection * * Provides the number of inactive networks. * * Returns the number of networks found or -1 in case of error */ int virConnectNumOfDefinedNetworks(virConnectPtr conn) { VIR_DEBUG("conn=%p", conn); virResetLastError(); virCheckConnectReturn(conn, -1); if (conn->networkDriver && conn->networkDriver->connectNumOfDefinedNetworks) { int ret; ret = conn->networkDriver->connectNumOfDefinedNetworks(conn); if (ret < 0) goto error; return ret; } virReportUnsupportedError(); error: virDispatchError(conn); return -1; }
/** * virNWFilterBindingLookupByPortDev: * @conn: pointer to the hypervisor connection * @portdev: name for the network port device * * Try to lookup a network filter binding on the given hypervisor based * on network port device name. * * virNWFilterBindingFree should be used to free the resources after the * binding object is no longer needed. * * Returns a new binding object or NULL in case of failure. If the * network filter cannot be found, then VIR_ERR_NO_NWFILTER_BINDING * error is raised. */ virNWFilterBindingPtr virNWFilterBindingLookupByPortDev(virConnectPtr conn, const char *portdev) { VIR_DEBUG("conn=%p, name=%s", conn, NULLSTR(portdev)); virResetLastError(); virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(portdev, error); if (conn->nwfilterDriver && conn->nwfilterDriver->nwfilterBindingLookupByPortDev) { virNWFilterBindingPtr ret; ret = conn->nwfilterDriver->nwfilterBindingLookupByPortDev(conn, portdev); if (!ret) goto error; return ret; } virReportUnsupportedError(); error: virDispatchError(conn); return NULL; }
/** * virNodeDeviceLookupByName: * @conn: pointer to the hypervisor connection * @name: unique device name * * Lookup a node device by its name. * * virNodeDeviceFree should be used to free the resources after the * node device object is no longer needed. * * Returns a virNodeDevicePtr if found, NULL otherwise. */ virNodeDevicePtr virNodeDeviceLookupByName(virConnectPtr conn, const char *name) { VIR_DEBUG("conn=%p, name=%p", conn, name); virResetLastError(); virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(name, error); if (conn->nodeDeviceDriver && conn->nodeDeviceDriver->nodeDeviceLookupByName) { virNodeDevicePtr ret; ret = conn->nodeDeviceDriver->nodeDeviceLookupByName(conn, name); if (!ret) goto error; return ret; } virReportUnsupportedError(); error: virDispatchError(conn); return NULL; }
/** * virNetworkLookupByUUIDString: * @conn: pointer to the hypervisor connection * @uuidstr: the string UUID for the network * * Try to lookup a network on the given hypervisor based on its UUID. * * Returns a new network object or NULL in case of failure. If the * network cannot be found, then VIR_ERR_NO_NETWORK error is raised. */ virNetworkPtr virNetworkLookupByUUIDString(virConnectPtr conn, const char *uuidstr) { unsigned char uuid[VIR_UUID_BUFLEN]; VIR_DEBUG("conn=%p, uuidstr=%s", conn, NULLSTR(uuidstr)); virResetLastError(); virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(uuidstr, error); if (virUUIDParse(uuidstr, uuid) < 0) { virReportInvalidArg(uuidstr, _("uuidstr in %s must be a valid UUID"), __FUNCTION__); goto error; } return virNetworkLookupByUUID(conn, &uuid[0]); error: virDispatchError(conn); return NULL; }
/** * virNetworkLookupByUUID: * @conn: pointer to the hypervisor connection * @uuid: the raw UUID for the network * * Try to lookup a network on the given hypervisor based on its UUID. * * virNetworkFree should be used to free the resources after the * network object is no longer needed. * * Returns a new network object or NULL in case of failure. If the * network cannot be found, then VIR_ERR_NO_NETWORK error is raised. */ virNetworkPtr virNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { VIR_UUID_DEBUG(conn, uuid); virResetLastError(); virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(uuid, error); if (conn->networkDriver && conn->networkDriver->networkLookupByUUID) { virNetworkPtr ret; ret = conn->networkDriver->networkLookupByUUID(conn, uuid); if (!ret) goto error; return ret; } virReportUnsupportedError(); error: virDispatchError(conn); return NULL; }