Commit Graph

3004 Commits

Author SHA1 Message Date
Laine Stump
9c004d55d0 util: use new virNetDev*NetConfig() functions for hostdev setup/teardown
virHostdevNetConfigReplace() and virHostdevNetConfigRestore() are
modified to use the new virNetDev*NetConfig() functions.

Note that due to the VF's original MAC addresses being saved after it
has already been un-bound from the host net driver, the actual current
VF MAC address won't be saved (because it no longer exists) - only the
"admin MAC" will be saved. This reflects existing behavior that will
be fixed in an upcoming patch.
2017-03-27 10:19:12 -04:00
Laine Stump
b91a336384 util: use new virNetDev*NetConfig() functions for macvtap setup/teardown
This patch modifies the macvtap passthrough setup to use
virNetDevSaveNetConfig()+virNetDevSetConfig() instead of
virNetDevReplaceNetConfig() or virNetDevReplaceMacAddress(), and the
teardown to use virNetDevReadNetConfig()+virNetDevSetConfig() instead
of virNetDevRestoreNetConfig() or virNetDevRestoreMacAddress().

Since the older functions only saved/restored the admin MAC and vlan
tag (which is incorrect) and the new functions save/restore the VF's
own MAC address and vlan tag (correct), this actually fixes a bug
(which was introduced by commit cb3fe38c7, which was itself supposed
to be a fix for https://bugzilla.redhat.com/1113474 ).

The downside to this patch is that it causes an *apparent* regression
in that bug (because there will once again be an error reported if the
interface had previously been used for VFIO device assignment), but in
reality, the code hasn't been working for *any* case before this
current patch (at least not with any recent kernel). Anyway, that
"regression" will be fixed with an upcoming patch that fixes it the
*right* way.
2017-03-27 10:19:04 -04:00
Laine Stump
26694daf09 util: new functions virNetDev(Save|Read|Set)NetConfig()
These three functions are destined to replace
virNetDev(Replace|Restore)NetConfig() and
virNetDev(Replace|Restore)MacAddress(), which both do the save and set
together as a single step. We need to separate the save, read, and set
steps because there will be situations where we need to do something
else in between (in particular, we will need to rebind a VF's driver
after save but before set).

This patch creates the new functions, but doesn't call them - that
will come in a subsequent patch. Note that the new functions to
read/write the file that stores the original network config now uses
JSON rather than plaintext (it still recognizes the old format as well
though, so it won't get confused during an upgrade).
2017-03-27 10:18:58 -04:00
Erik Skultety
a4a39d90ab hostdev: Maintain a driver list of active mediated devices
Keep track of the assigned mediated devices the same way we do it for
the rest of hostdevs. Methods like 'Prepare', 'Update', and 'ReAttach'
are introduced by this patch.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2017-03-27 15:39:35 +02:00
Erik Skultety
e1ec4f88ff util: Introduce new module virmdev
Beside creation, disposal, getter, and setter methods the module exports
methods to work with lists of mediated devices.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2017-03-27 15:39:35 +02:00
Eric Blake
044198476a util: fix build on RHEL 6
We keep forgetting that older setups don't like 'index':

  CC     util/libvirt_util_la-virsysinfo.lo
cc1: warnings being treated as errors
util/virstoragefile.c: In function 'virStorageSourceFindByNodeName':
util/virstoragefile.c:3804: error: declaration of 'index' shadows a global declaration [-Wshadow]
/usr/include/string.h:489: error: shadowed declaration is here [-Wshadow]

Signed-off-by: Eric Blake <eblake@redhat.com>
2017-03-27 08:12:18 -05:00
Martin Kletzander
d2d1dec1f5 util: Fix naming in util/virnodesuspend
That file has only two exported files and each one of them has
different naming.  virNode is what all the other files use, so let's
use it.  It wasn't used before because the clash with public API
naming, so let's fix that by shortening the name (there is no other
private variant of it anyway).

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-03-27 13:13:29 +02:00
Martin Kletzander
bdcb199532 Move src/fdstream to src/util/virfdstream
There is no reason for it not to be in the utils, all global symbols
under that file already have prefix vir* and there is no reason for it
to be part of DRIVER_SOURCES because that is just a leftover from
older days (pre-driver modules era, I believe).

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-03-27 13:13:29 +02:00
Martin Kletzander
c67e04e25f util: Adapt virhostcpu to the new virsysfs
While on that, drop support for kernels from RHEL-5 era (missing
cpu/present file).  Also add some useful functions and export them.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-03-27 13:13:29 +02:00
Martin Kletzander
a7b902c082 util: Add virsysfs for handling sysfs files
By using this we are able to easily switch the sysfs path being
used (fake it).  This will not only help tests in the future but can
be also used from files where the code is duplicated currently.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-03-27 13:13:29 +02:00
Martin Kletzander
9fdd077de7 virfile: Add helpers for reading simple values
These helpers are doing just a read and covert the value, but they
properly size the read limit, handle additional whitespace characters,
and unify error reporting.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-03-27 13:13:29 +02:00
Martin Kletzander
eec3b255d2 Fix build with GCC's static analysis
STREQ_NULLABLE returns true if both parameters are NULL.  And that's
not what we want here.  We just want to skop comparing source nodes
that don't have that info set.  The function wouldn't make much sense
with nodeName == NULL, so we don't need to check that.  Moreover, the
function's declaration uses ATTRIBUDE_NONNULL for nodeName, which not
only means that function expects the parameter not to be NULL, but
actually tells the compiler that it can optimize out the NULL checks.
That way it could end up calling strcmp on NULL (either nodeformat or
nodebacking).  GCC figures this out if libvirt is compiled with
lv_cv_static_analysis=yes, unfortunately not everyone uses that.

Caused by cbc6d53513.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-03-27 13:12:23 +02:00
Peter Krempa
86e51d68f9 util: json: Make function to free JSON values in virHash universal
Move the helper that frees JSON entries put into hash tables into the
JSON module so that it does not have to be reimplemented.
2017-03-27 10:35:19 +02:00
Peter Krempa
cbc6d53513 util: storage: Add variables for node names into virStorageSource
'nodeformat' should be used for strings which describe the storage
format object, and 'nodebacking' for the actual storage object itself.
2017-03-27 09:29:57 +02:00
Peter Krempa
ad36f3853b util: storage: Split out useful bits of virStorageFileParseChainIndex
The function has very specific semantics. Split out the part that parses
the backing store specification string into a separate helper so that it
can be reused later while keeping the wrapper with existing semantics.

Note that virStorageFileParseChainIndex is pretty well covered by the
test suite.
2017-03-27 09:29:57 +02:00
Peter Krempa
91e7862c15 util: buffer: Add API to set indentation level to a given value
It will be useful to set indentation level to 0 after formatting a
nested structure rather than having to track the depth.
2017-03-27 09:29:57 +02:00
Roman Bogorodskiy
27a59a9230 virpci: fix build on non-Linux
virPCIGetDeviceAddressFromSysfsLink() should return
virPCIDeviceAddressPtr, so return NULL in the stub instead of "-1".
2017-03-25 20:48:24 +04:00
Roman Bogorodskiy
a7496ad29a util: fix build on non-Linux
Fix typo in virNetDevPFGetVF() stub:

  ATTRUBUTE_UNUSED -> ATTRIBUTE_UNUSED.

While here, use common indent style for arguments in
virNetDevGetVirtualFunctionIndex() stub.
2017-03-25 08:24:21 +04:00
Laine Stump
554253ad04 util: new function virNetDevPFGetVF()
Given an SRIOV PF netdev name (e.g. "enp2s0f0") and VF#, this new
function returns the netdev name of the referenced VF device
(e.g. "enp2s11f6"), or NULL if the device isn't bound to a net driver.
2017-03-24 00:39:31 -04:00
Laine Stump
f4ef3a71f8 util: new internal function to permit silent failure of virNetDevSetMAC()
We will want to allow silent failure of virNetDevSetMAC() in the case
that the SIOSIFHWADDR ioctl fails with errno == EADDRNOTAVAIL. (Yes,
that is very specific, but we really *do* want a logged failure in all
other circumstances, and don't want to duplicate code in the caller
for the other possibilities).

This patch renames the 3 different virNetDevSetMAC() functions to
virNetDevSetMACInternal(), adding a 3rd arg called "quiet" and making
them static (because this extra control will only be needed within
virnetdev.c). A new global virNetDevSetMAC() is defined that calls
whichever of the three *Internal() functions gets compiled with quiet
= false. Callers in virnetdev.c that want to notice a failure with
errno == EADDRNOTAVAIL and retry with a different strategy rather than
immediately failing, can call virNetDevSetMACInternal(..., true).
2017-03-24 00:39:08 -04:00
Laine Stump
251d179bf2 util: new function virPCIDeviceRebind()
This function unbinds a device from its driver, then immediately
rebinds it to its driver again. The code for this new function is just
the 2nd half of virPCIDeviceBindWithDriverOverride(), so that
function's 2nd half is replaced with a call to virPCIDeviceRebind().
2017-03-24 00:38:21 -04:00
Laine Stump
9a238c16b3 util: make virPCIGetDeviceAddressFromSysfsLink() public
This function will be useful in virnetdev.c, so promote it from static.
2017-03-24 00:37:36 -04:00
Laine Stump
d6ee56d723 util: change virPCIGetNetName() to not return error if device has no net name
...and cleanup the callers to report it when it *is* an error.

In many cases It's useful for virPCIGetNetName() to not log an error
and simply return a NULL pointer when the given device isn't bound to
a net driver (e.g. we're looking at a VF that is permanently bound to
vfio-pci). The existing code would silently return an error in this
case, which could eventually lead to the dreaded "An error occurred
but the cause is unknown" log message.

This patch changes virPCIGetNetName() to still return success if the
device simply isn't bound to a net driver, and adjusts all the callers
that require a non-null netname to check for that condition and log an
error when it happens.
2017-03-24 00:37:19 -04:00
Laine Stump
30b07a425d util: make virMacAddrParse more versatile
Previously the MAC address text was required to be terminated with a
NULL. After this, it can be terminated with a space or any control
character.
2017-03-24 00:37:01 -04:00
Laine Stump
606a013395 util: eliminate useless local variable
vf in virNetDevMacVLanDeleteWithVPortProfile() is initialized to -1
and never set. It's not set for a good reason - because it doesn't
make sense during macvtap device setup to refer to a VF device as
"PF:VF#". This patch replaces the two uses of "vf" with "-1", and
removes the local variable, so that it's more clear we are always
calling the utility functions with vf set to -1.
2017-03-24 00:36:43 -04:00
Laine Stump
19c5db749c util: use cleanup label consistently in virHostdevNetConfigReplace()
This will make an upcoming functional change more straightforward.
2017-03-24 00:36:22 -04:00
Laine Stump
0a583c26f7 util: remove unused args from virNetDevSetVfConfig()
This function is only called in two places, and the ifindex,
nltarget_kernel, and getPidFunc args are never used (and never will
be).

ifindex - we always know the name of the device, and never know the
ifindex - if we really did need the ifindex we would have to get it
from the name using virNetDevGetIndex(). In practice, we just send -1
to virNetDevSetVfConfig(), which doesn't bother to learn the real
ifindex (you only need a name *or* an ifindex for the netlink command
to succeed, not both).

nltarget_kernel - messages to set the config of an SRIOV VF will
always go to netlink in the kernel, not to another user process, so
this arg is always true (there are other uses of netlink messages
where the message might need to go to another user process, but never
in the case of RTM_SETLINK for SRIOV).

getPidFunc - this arg is only used if nltarget_kernel is false, and it
never is.

None of this has any functional effect, it just makes it easier to
follow what's happening when virNetDevSetVfConfig() is called.
2017-03-24 00:35:43 -04:00
Laine Stump
176229dd05 util: permit querying a VF MAC address or VLAN tag by itself
virNetDevParseVfConfig() assumed that both the MAC address and VLAN
tag pointers were valid, so even if you only wanted one or the other,
you would need a variable to hold the returned value for both. This
patch checks each for a NULL pointer before filling it in.
2017-03-24 00:34:08 -04:00
Roman Bogorodskiy
8095828480 util: fix build on non-Linux
Decorate unused arguments of the virNetDevGetMaster() stub
with ATTRIBUTE_UNUSED to fix build on systems where this
stub is used.
2017-03-23 07:45:29 +04:00
John Ferlan
73f5256b4c util: Remove NONNULL(1) for virNetDevMacVLanDeleteWithVPortProfile
Since the source code checks 'ifname' for NULL before using, the prototype
doesn't need the NONNULL
2017-03-22 13:50:00 -04:00
John Ferlan
5482db8176 util: Remove NONNULL's for virNetDevVPortProfile[Associate|Disassociate]
The source code will check for NULL arguments for 'macvtap_macaddr' and
'vmuuid', so no need for the NONNULL in the prototypes. Following the stack
for both arguments to virNetDevVPortProfileOpSetLink also shows called
functions would handle a NULL value.

Additionally, modified the prototype to use the same 'macvtap_macaddr'
name as the source code for consistency.
2017-03-22 13:50:00 -04:00
John Ferlan
fbd804ff3d util: Remove NONNULL(1) for virNetDevOpenvswitchGetVhostuserIfname
Since the code checks and handles a NULL 'path', no need for the NONNULL
2017-03-22 13:50:00 -04:00
John Ferlan
cb91d5cc58 util: Remove NONNULL(2) for virNetDevBandwidthPlug
Since the code checks and handles a NULL 'net_bandwidth' parameter,
so no need for NONNNULL.
2017-03-22 13:50:00 -04:00
John Ferlan
dc2d9431a0 util: Remove NONNULL(1,3,4) from virTypedParamsFilter
The API checks each parameter for NULL anyway and would error, so need
to add NONNULL on prototype.
2017-03-22 13:50:00 -04:00
John Ferlan
3ae0e7853e util: Remove NONNULL(1) for virNetDevOpenvswitchSetMigrateData
The code checks and handles a NULL 'migrate', so no need for NONNULL
2017-03-22 13:50:00 -04:00
John Ferlan
cd0ed1456d util: Remove NONNULL(1) for virHostdevReAttachDomainDevices
Since the function handles a NULL 'mgr' condition, no need for the NONNULL
2017-03-22 13:50:00 -04:00
John Ferlan
40f2a476d1 util: Remove NONNULL(1) for virHostdevPrepareDomainDevices
Since the code checks 'mgr == NULL' anyway, no need for the prototype
to have the NONNULL arg check.  Also add an error message to indicate what
the failure is so that there isn't a failed for some reason error.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-03-22 13:50:00 -04:00
John Ferlan
47dcce2f08 util: Remove NONNULL(2,3) for virHostdevReAttachSCSIVHostDevices
The comparison code used STREQ_NULLABLE anyway for both 'drv_name' and
'dom_name', so no need. Add a NULLSTR on the 'dom_name' too.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-03-22 13:50:00 -04:00
John Ferlan
ceaf327475 util: Remove NONNULL(2,3) for virHostdevReAttachUSBDevices
The comparison code used STREQ_NULLABLE anyway for both 'drv_name' and
'dom_name', so no need. Add a NULLSTR on the 'dom_name' too.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-03-22 13:49:59 -04:00
John Ferlan
17a448da1d util: Remove NONNULL(2,3) for virHostdevReAttachPCIDevices
The called function uses a STRNEQ_NULLABLE anyway for both 'drv_name' and
'dom_name', so no need.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-03-22 13:49:59 -04:00
John Ferlan
fecc6ed090 util: Remove NONNULL(1) for virBitmapParseUnlimited
The code checks and handles a NULL 'str', so just remove the NONNULL.

Update the error message to add the NULLSTR() around 'str' also.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-03-22 13:49:59 -04:00
John Ferlan
9f66e09bc5 util: Change return argument for virBitmapParseUnlimited
Rather than returning an int and a *bitmap pointer, just return and
check a NULL bitmap pointer
2017-03-22 13:49:59 -04:00
John Ferlan
91d28d993f util: Remove NONNULL(1) for virNetDevGetName
The 'ifindex' argument is not a pointer, so no need for NONNULL in prototype
2017-03-22 13:49:59 -04:00
Laine Stump
a454134951 util: new function virNetDevTapAttachBridge()
This patch splits out the part of virNetDevTapCreateInBridgePort()
that would need to be re-done if an existing tap device had to be
re-attached to a bridge, and puts it into a separate function. This
can be used both when an existing domain interface config is updated
to change its connection, and also to re-attach to the "same" bridge
when a network has been stopped and restarted. So far it is used for
nothing.
2017-03-22 12:16:51 -04:00
Laine Stump
e75f5bfbe8 util: new function virNetDevGetMaster()
This function provides the bridge/bond device that the given network
device is attached to. The return value is 0 or -1, and the master
device is a char** argument to the function - this is needed in order
to allow for a "success" return from a device that has no master.
2017-03-22 12:12:52 -04:00
Laine Stump
549fe5a882 util: allow retrieving ethtool features when unprivileged
The only reason that the ethtool features weren't being retrieved in
an unprivileged libvirtd was because they required ioctl(), and the
ioctl was using an AF_PACKET socket, which requires root. Now that we
are using AF_UNIX for ioctl(), this restriction can be removed.
2017-03-22 12:10:09 -04:00
Laine Stump
1c9a8746ef util: use AF_UNIX family (not AF_PACKET) for ioctl sockets
The exact family of the socket created for the fd used by ioctl(7)
doesn't matter, it just needs to be a socket and not a file. But for
some reason when macvtap support was added, it used
AF_PACKET/SOCK_DGRAM sockets for its ioctls; we later used the same
AF_PACKET/SOCK_DGRAM socket for new ioctls we added, and eventually
modified the other pre-existing ioctl sockets (for creating/deleting
bridges) to also use AF_PACKET/SOCK_DGRAM (that code originally used
AF_UNIX/SOCK_STREAM).

The problem with using AF_PACKET (intended for sending/receiving "raw"
packets, i.e. packets that can be some protocol other than TCP or UDP)
is that it requires root privileges. This meant that none of the
ioctls in virnetdev.c or virnetdevip.c would work when running
libvirtd unprivileged.

This packet solves that problem by changing the family to AF_UNIX when
creating the socket used for any ioctl().
2017-03-22 12:07:13 -04:00
Cédric Bosdonnat
00d28a78b5 network: check accept_ra before enabling ipv6 forwarding
When enabling IPv6 on all interfaces, we may get the host Router
Advertisement routes discarded. To avoid this, the user needs to set
accept_ra to 2 for the interfaces with such routes.

See https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt
on this topic.

To avoid user mistakenly losing routes on their hosts, check
accept_ra values before enabling IPv6 forwarding. If a RA route is
detected, but neither the corresponding device nor global accept_ra
is set to 2, the network will fail to start.
2017-03-22 09:01:33 +01:00
Cédric Bosdonnat
5dd607059d util: add virNetDevGetName() function
Add a function getting the name of a network interface out of its index.
2017-03-22 09:01:33 +01:00
Cédric Bosdonnat
754515b7db util: add virNetlinkDumpCommand()
virNetlinkCommand() processes only one response message, while some
netlink commands, like route dumping, need to process several.
Add virNetlinkDumpCommand() as a virNetlinkCommand() sister.
2017-03-22 09:01:32 +01:00