[libvirt PATCH 00/16] Add support for persistent mediated devices

Jonathon Jongsma posted 16 patches 3 years, 9 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20200716222146.1241-1-jjongsma@redhat.com
There is a newer version of this series
examples/c/misc/event-test.c                  |   4 +
include/libvirt/libvirt-nodedev.h             |  19 +-
src/conf/node_device_conf.h                   |   9 +
src/conf/virnodedeviceobj.c                   |  24 +
src/conf/virnodedeviceobj.h                   |   7 +
src/driver-nodedev.h                          |  14 +
src/libvirt-nodedev.c                         | 115 ++++
src/libvirt_private.syms                      |   2 +
src/libvirt_public.syms                       |   6 +
src/node_device/node_device_driver.c          | 522 +++++++++++++++++-
src/node_device/node_device_driver.h          |  38 ++
src/node_device/node_device_udev.c            | 275 ++++++++-
src/remote/remote_driver.c                    |   3 +
src/remote/remote_protocol.x                  |  40 +-
src/remote_protocol-structs                   |  16 +
src/rpc/gendispatch.pl                        |   1 +
...19_36ea_4111_8f0a_8c9a70e21366-define.argv |   1 +
...19_36ea_4111_8f0a_8c9a70e21366-define.json |   1 +
...39_495e_4243_ad9f_beb3f14c23d9-define.argv |   1 +
...39_495e_4243_ad9f_beb3f14c23d9-define.json |   1 +
...16_1ca8_49ac_b176_871d16c13076-define.argv |   1 +
...16_1ca8_49ac_b176_871d16c13076-define.json |   1 +
tests/nodedevmdevctldata/mdevctl-create.argv  |   1 +
.../mdevctl-list-defined.argv                 |   1 +
.../mdevctl-list-multiple-parents.json        |  59 ++
.../mdevctl-list-multiple-parents.out.xml     |  39 ++
.../mdevctl-list-multiple.json                |  59 ++
.../mdevctl-list-multiple.out.xml             |  39 ++
.../mdevctl-list-single-noattr.json           |  11 +
.../mdevctl-list-single-noattr.out.xml        |   8 +
.../mdevctl-list-single.json                  |  31 ++
.../mdevctl-list-single.out.xml               |  14 +
.../nodedevmdevctldata/mdevctl-undefine.argv  |   1 +
tests/nodedevmdevctltest.c                    | 226 +++++++-
tools/virsh-nodedev.c                         | 281 ++++++++--
35 files changed, 1783 insertions(+), 88 deletions(-)
create mode 100644 tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-define.argv
create mode 100644 tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-define.json
create mode 100644 tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-define.argv
create mode 100644 tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-define.json
create mode 100644 tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-define.argv
create mode 100644 tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-define.json
create mode 100644 tests/nodedevmdevctldata/mdevctl-create.argv
create mode 100644 tests/nodedevmdevctldata/mdevctl-list-defined.argv
create mode 100644 tests/nodedevmdevctldata/mdevctl-list-multiple-parents.json
create mode 100644 tests/nodedevmdevctldata/mdevctl-list-multiple-parents.out.xml
create mode 100644 tests/nodedevmdevctldata/mdevctl-list-multiple.json
create mode 100644 tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml
create mode 100644 tests/nodedevmdevctldata/mdevctl-list-single-noattr.json
create mode 100644 tests/nodedevmdevctldata/mdevctl-list-single-noattr.out.xml
create mode 100644 tests/nodedevmdevctldata/mdevctl-list-single.json
create mode 100644 tests/nodedevmdevctldata/mdevctl-list-single.out.xml
create mode 100644 tests/nodedevmdevctldata/mdevctl-undefine.argv
[libvirt PATCH 00/16] Add support for persistent mediated devices
Posted by Jonathon Jongsma 3 years, 9 months ago
This patch series follows the previously-merged series which added support for
transient mediated devices. This series expands mdev support to include
persistent device definitions. Again, it relies on mdevctl as the backend.

It follows the common libvirt pattern of APIs by adding the following new APIs
for node devices:
    - virNodeDeviceDefineXML() - defines a persistent device
    - virNodeDeviceUndefine() - undefines a persistent device
    - virNodeDeviceCreate() - starts a previously-defined device

It also adds virsh commands mapping to these new APIs: nodedev-define,
nodedev-undefine, and nodedev-start.

The method of staying up-to-date with devices defined by mdevctl is currently a
little bit crude due to the fact that mdevctl does not emit any events when new
devices are added or removed. As a workaround, we create a file monitor for the
mdevctl config directory and re-query mdevctl when we detect changes within
that directory. In the future, mdevctl may introduce a more elegant solution.

Jonathon Jongsma (16):
  tests: remove extra trailing semicolon
  nodedev: introduce concept of 'active' node devices
  nodedev: Add ability to filter by active state
  virsh: Add --active, --inactive, --all to nodedev-list
  nodedev: add ability to list and parse defined mdevs
  nodedev: add STOPPED/STARTED lifecycle events
  nodedev: add mdevctl devices to node device list
  nodedev: handle mdevs that disappear from mdevctl
  nodedev: add an mdevctl thread
  api: add virNodeDeviceDefineXML()
  virsh: add nodedev-define command
  api: add virNodeDeviceUndefine()
  virsh: Factor out function to find node device
  virsh: add nodedev-undefine command
  api: add virNodeDeviceCreate()
  virsh: add "nodedev-start" command

 examples/c/misc/event-test.c                  |   4 +
 include/libvirt/libvirt-nodedev.h             |  19 +-
 src/conf/node_device_conf.h                   |   9 +
 src/conf/virnodedeviceobj.c                   |  24 +
 src/conf/virnodedeviceobj.h                   |   7 +
 src/driver-nodedev.h                          |  14 +
 src/libvirt-nodedev.c                         | 115 ++++
 src/libvirt_private.syms                      |   2 +
 src/libvirt_public.syms                       |   6 +
 src/node_device/node_device_driver.c          | 522 +++++++++++++++++-
 src/node_device/node_device_driver.h          |  38 ++
 src/node_device/node_device_udev.c            | 275 ++++++++-
 src/remote/remote_driver.c                    |   3 +
 src/remote/remote_protocol.x                  |  40 +-
 src/remote_protocol-structs                   |  16 +
 src/rpc/gendispatch.pl                        |   1 +
 ...19_36ea_4111_8f0a_8c9a70e21366-define.argv |   1 +
 ...19_36ea_4111_8f0a_8c9a70e21366-define.json |   1 +
 ...39_495e_4243_ad9f_beb3f14c23d9-define.argv |   1 +
 ...39_495e_4243_ad9f_beb3f14c23d9-define.json |   1 +
 ...16_1ca8_49ac_b176_871d16c13076-define.argv |   1 +
 ...16_1ca8_49ac_b176_871d16c13076-define.json |   1 +
 tests/nodedevmdevctldata/mdevctl-create.argv  |   1 +
 .../mdevctl-list-defined.argv                 |   1 +
 .../mdevctl-list-multiple-parents.json        |  59 ++
 .../mdevctl-list-multiple-parents.out.xml     |  39 ++
 .../mdevctl-list-multiple.json                |  59 ++
 .../mdevctl-list-multiple.out.xml             |  39 ++
 .../mdevctl-list-single-noattr.json           |  11 +
 .../mdevctl-list-single-noattr.out.xml        |   8 +
 .../mdevctl-list-single.json                  |  31 ++
 .../mdevctl-list-single.out.xml               |  14 +
 .../nodedevmdevctldata/mdevctl-undefine.argv  |   1 +
 tests/nodedevmdevctltest.c                    | 226 +++++++-
 tools/virsh-nodedev.c                         | 281 ++++++++--
 35 files changed, 1783 insertions(+), 88 deletions(-)
 create mode 100644 tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-define.argv
 create mode 100644 tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-define.json
 create mode 100644 tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-define.argv
 create mode 100644 tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-define.json
 create mode 100644 tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-define.argv
 create mode 100644 tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-define.json
 create mode 100644 tests/nodedevmdevctldata/mdevctl-create.argv
 create mode 100644 tests/nodedevmdevctldata/mdevctl-list-defined.argv
 create mode 100644 tests/nodedevmdevctldata/mdevctl-list-multiple-parents.json
 create mode 100644 tests/nodedevmdevctldata/mdevctl-list-multiple-parents.out.xml
 create mode 100644 tests/nodedevmdevctldata/mdevctl-list-multiple.json
 create mode 100644 tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml
 create mode 100644 tests/nodedevmdevctldata/mdevctl-list-single-noattr.json
 create mode 100644 tests/nodedevmdevctldata/mdevctl-list-single-noattr.out.xml
 create mode 100644 tests/nodedevmdevctldata/mdevctl-list-single.json
 create mode 100644 tests/nodedevmdevctldata/mdevctl-list-single.out.xml
 create mode 100644 tests/nodedevmdevctldata/mdevctl-undefine.argv

-- 
2.21.3

Re: [libvirt PATCH 00/16] Add support for persistent mediated devices
Posted by Erik Skultety 3 years, 9 months ago
On Thu, Jul 16, 2020 at 05:21:30PM -0500, Jonathon Jongsma wrote:
> This patch series follows the previously-merged series which added support for
> transient mediated devices. This series expands mdev support to include
> persistent device definitions. Again, it relies on mdevctl as the backend.
>
> It follows the common libvirt pattern of APIs by adding the following new APIs
> for node devices:
>     - virNodeDeviceDefineXML() - defines a persistent device
>     - virNodeDeviceUndefine() - undefines a persistent device
>     - virNodeDeviceCreate() - starts a previously-defined device
>
> It also adds virsh commands mapping to these new APIs: nodedev-define,
> nodedev-undefine, and nodedev-start.
>
> The method of staying up-to-date with devices defined by mdevctl is currently a
> little bit crude due to the fact that mdevctl does not emit any events when new
> devices are added or removed. As a workaround, we create a file monitor for the
> mdevctl config directory and re-query mdevctl when we detect changes within
> that directory. In the future, mdevctl may introduce a more elegant solution.

In general, I don't think it is desirable for libvirt to monitor the
configuration directory for changes made outside of libvirt and expect libvirt
to keep up with the new configuration and still be able manage the device.
I'd say that we only manage devices that we created and have control over.
Everything else is outside libvirt's scope to handle (the same goes for
persistent device removals).
If a device cannot be created, because mdevctl already has a colliding device
that was created outside of libvirt, we should document that the user is
expected to remove the device configuration and re-create it with libvirt -
let's say mdevctl adds support for an alternative config dir, how does libvirt
know it should monitor that one instead /etc/mdev.d?

All summed up, until there's some event signalling in mdevctl, we should only
support devices we previously defined.

Regards,
Erik

Re: [libvirt PATCH 00/16] Add support for persistent mediated devices
Posted by Daniel P. Berrangé 3 years, 9 months ago
On Fri, Jul 17, 2020 at 10:08:59AM +0200, Erik Skultety wrote:
> On Thu, Jul 16, 2020 at 05:21:30PM -0500, Jonathon Jongsma wrote:
> > This patch series follows the previously-merged series which added support for
> > transient mediated devices. This series expands mdev support to include
> > persistent device definitions. Again, it relies on mdevctl as the backend.
> >
> > It follows the common libvirt pattern of APIs by adding the following new APIs
> > for node devices:
> >     - virNodeDeviceDefineXML() - defines a persistent device
> >     - virNodeDeviceUndefine() - undefines a persistent device
> >     - virNodeDeviceCreate() - starts a previously-defined device
> >
> > It also adds virsh commands mapping to these new APIs: nodedev-define,
> > nodedev-undefine, and nodedev-start.
> >
> > The method of staying up-to-date with devices defined by mdevctl is currently a
> > little bit crude due to the fact that mdevctl does not emit any events when new
> > devices are added or removed. As a workaround, we create a file monitor for the
> > mdevctl config directory and re-query mdevctl when we detect changes within
> > that directory. In the future, mdevctl may introduce a more elegant solution.
> 
> In general, I don't think it is desirable for libvirt to monitor the
> configuration directory for changes made outside of libvirt and expect libvirt
> to keep up with the new configuration and still be able manage the device.
> I'd say that we only manage devices that we created and have control over.
> Everything else is outside libvirt's scope to handle (the same goes for
> persistent device removals).
> If a device cannot be created, because mdevctl already has a colliding device
> that was created outside of libvirt, we should document that the user is
> expected to remove the device configuration and re-create it with libvirt -
> let's say mdevctl adds support for an alternative config dir, how does libvirt
> know it should monitor that one instead /etc/mdev.d?

On daemon startup, libvirt is going to scan the directory and detect
everything in it regardless who/what created it. So that would mean
we need a restart to pick up externally made changes. This is already
true for config files libvirt owns of course in /etc/libvirt, but it
is not unreasonable to use file monitor to do live updates.

It is unlikely people will be using both libvirt and direct mdevctl
to create devices - they're likely to exclusively use one or the other.
IN particular there's likely already apps that exist and call mdevctl
directly to persist devices, and it is fairly desirable that libvirt
can see those I think, even if we think the apps should switch to using
these new libvirt aps.

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

Re: [libvirt PATCH 00/16] Add support for persistent mediated devices
Posted by Jonathon Jongsma 3 years, 9 months ago
On Fri, 2020-07-17 at 10:08 +0200, Erik Skultety wrote:
> On Thu, Jul 16, 2020 at 05:21:30PM -0500, Jonathon Jongsma wrote:
> > This patch series follows the previously-merged series which added
> > support for
> > transient mediated devices. This series expands mdev support to
> > include
> > persistent device definitions. Again, it relies on mdevctl as the
> > backend.
> > 
> > It follows the common libvirt pattern of APIs by adding the
> > following new APIs
> > for node devices:
> >     - virNodeDeviceDefineXML() - defines a persistent device
> >     - virNodeDeviceUndefine() - undefines a persistent device
> >     - virNodeDeviceCreate() - starts a previously-defined device
> > 
> > It also adds virsh commands mapping to these new APIs: nodedev-
> > define,
> > nodedev-undefine, and nodedev-start.
> > 
> > The method of staying up-to-date with devices defined by mdevctl is
> > currently a
> > little bit crude due to the fact that mdevctl does not emit any
> > events when new
> > devices are added or removed. As a workaround, we create a file
> > monitor for the
> > mdevctl config directory and re-query mdevctl when we detect
> > changes within
> > that directory. In the future, mdevctl may introduce a more elegant
> > solution.
> 
> In general, I don't think it is desirable for libvirt to monitor the
> configuration directory for changes made outside of libvirt and
> expect libvirt
> to keep up with the new configuration and still be able manage the
> device.
> I'd say that we only manage devices that we created and have control
> over.


I'm not sure that it's entirely accurate to say that we have "control
over" these devices. If we're using mdevctl as our configuration
backend (which I think is the right decision), then any device that is
defined in mdevctl can also be changed or removed by a user executing
mdevctl externally. I'm not sure there's really anything we can do to
prevent that unless we decide to abandon mdevctl as a backend.


> Everything else is outside libvirt's scope to handle (the same goes
> for
> persistent device removals).


If any externally-created mediated devices are active (not just
defined, but actually started) libvirt will already see them because
they will be visible via udev. So trying to limit the list of mdevs to
only those created by libvirt might quickly become a bit complicated, I
think.

(Note also that the previously-merged first patch series already allows
libvirt to e.g. stop devices that are started externally by mdevctl. If
we really wanted to maintain a strict separation between mdevs created
by libvirt and those created externally, it may require some more
substantial changes.)


> If a device cannot be created, because mdevctl already has a
> colliding device
> that was created outside of libvirt, we should document that the user
> is
> expected to remove the device configuration and re-create it with
> libvirt -
> let's say mdevctl adds support for an alternative config dir, how
> does libvirt
> know it should monitor that one instead /etc/mdev.d?


Yes, relying on external programs always comes with some risk of
changes. But I envision this as a stopgap measure until mdevctl
introduces a more elegant event notification feature. I think we can
get that feature implemented in mdevctl (and supported in libvirt)
before mdevctl changes its configuration directory location.


> All summed up, until there's some event signalling in mdevctl, we
> should only
> support devices we previously defined.

So this sounds like you would be ok with supporting externally-defined
devices if there was a more elegant solution to signalling? Earlier it
sounded like you objected to that as out-of-scope.

Another thing to note: the directory monitoring is not only for
monitoring new external changes. Currently the directory monitor also
serves as the mechanism by which we pick up new devices that libvirt
itself defines. If we decide to remove the directory monitoring, we'd
need a different approach for this. That would not be difficult of
course, but it's something to note.

Jonathon