xl / libxl: named PCI pass-through devices
v7 cover xl / libxl: named PCI pass-through devices
From: Paul Durrant <[email protected]>
These are re-worked versions of the remaining patches from v6 of the series that were reverted by commit ac6a0af3870b "Revert patches that break libxl API".
Paul Durrant (7):
docs/man: modify xl(1) in preparation for naming of assignable devices
libxlu: introduce xlu_pci_parse_spec_string()
libxl: stop setting 'vdevfn' in pci_struct_fill()
libxl: add 'name' field to 'libxl_device_pci' in the IDL...
xl: support naming of assignable devices
docs/man: modify xl-pci-configuration(5) to add 'name' field to
PCI_SPEC_STRING
libxl / libxlu: support 'xl pci-attach/detach' by name
docs/man/xl-pci-configuration.5.pod | 25 ++- docs/man/xl.1.pod.in | 19 +- tools/include/libxl.h | 6 + tools/include/libxlutil.h | 8 +- tools/libs/light/libxl_pci.c | 133 ++++++++++++-- tools/libs/light/libxl_types.idl | 13 +- tools/libs/util/libxlu_pci.c | 353 +++++++++++++++++++----------------- tools/xl/xl_cmdtable.c | 16 +- tools/xl/xl_parse.c | 4 +- tools/xl/xl_pci.c | 120 ++++++++---- 10 files changed, 457 insertions(+), 240 deletions(-)
Signature · 1 line
2.11.0
PATCH v7 1/7 docs/man: modify xl(1) in preparation for naming of assignable devices
From: Paul Durrant <[email protected]>
A subsequent patch will introduce code to allow a name to be specified to 'xl pci-assignable-add' such that the assignable device may be referred to by than name in subsequent operations.
---
Cc: Ian Jackson <[email protected]>
--- docs/man/xl.1.pod.in | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
docs/man/xl.1.pod.in +12 -7
@@ -1595,19 +1595,23 @@ List virtual network interfaces for a domain. =over 4 -=item B<pci-assignable-list> +=item B<pci-assignable-list> [I<-n>] List all the B<BDF> of assignable PCI devices. See -L<xl-pci-configuration(5)> for more information. +L<xl-pci-configuration(5)> for more information. If the -n option is +specified then any name supplied when the device was made assignable +will also be displayed. These are devices in the system which are configured to be available for passthrough and are bound to a suitable PCI backend driver in domain 0 rather than a real driver. -=item B<pci-assignable-add> I<BDF> +=item B<pci-assignable-add> [I<-n NAME>] I<BDF> Make the device at B<BDF> assignable to guests. See -L<xl-pci-configuration(5)> for more information. +L<xl-pci-configuration(5)> for more information. If the -n option is +supplied then the assignable device entry will the named with the +given B<NAME>. This will bind the device to the pciback driver and assign it to the "quarantine domain". If it is already bound to a driver, it will
@@ -1622,10 +1626,11 @@ not to do this on a device critical to domain 0's operation, such as storage controllers, network interfaces, or GPUs that are currently being used. -=item B<pci-assignable-remove> [I<-r>] I<BDF> +=item B<pci-assignable-remove> [I<-r>] I<BDF>|I<NAME> -Make the device at B<BDF> not assignable to guests. See -L<xl-pci-configuration(5)> for more information. +Make a device non-assignable to guests. The device may be identified +either by its B<BDF> or the B<NAME> supplied when the device was made +assignable. See L<xl-pci-configuration(5)> for more information. This will at least unbind the device from pciback, and re-assign it from the "quarantine domain" back to domain 0. If the -r
Signature · 1 line
2.11.0
PATCH v7 2/7 libxlu: introduce xlu_pci_parse_spec_string()
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
This patch largely re-writes the code to parse a PCI_SPEC_STRING and enters it via the newly introduced function. The new parser also deals with 'bdf' and 'vslot' as non-positional paramaters, as per the documentation in xl-pci-configuration(5).
The existing xlu_pci_parse_bdf() function remains, but now strictly parses BDF values. Some existing callers of xlu_pci_parse_bdf() are modified to call xlu_pci_parse_spec_string() as per the documentation in xl(1).
NOTE: Usage text in xl_cmdtable.c and error messages are also modified
appropriately.
As a side-effect this patch also fixes a bug where using '*' to specify all functions would lead to an assertion failure at the end of xlu_pci_parse_bdf().
---
Cc: Ian Jackson <[email protected]>
Cc: Anthony PERARD <[email protected]>
v7:
- Minor modifications now that the 'libxl_pci_bdf' type no longer exists
- Modifications are largely mechanical so Wei's A-b is retained
--- tools/include/libxlutil.h | 8 +- tools/libs/util/libxlu_pci.c | 348 +++++++++++++++++++++++-------------------- tools/xl/xl_cmdtable.c | 4 +- tools/xl/xl_parse.c | 4 +- tools/xl/xl_pci.c | 33 ++-- 5 files changed, 213 insertions(+), 184 deletions(-)
tools/include/libxlutil.h +7 -1
@@ -109,9 +109,15 @@ int xlu_disk_parse(XLU_Config *cfg, int nspecs, const char *const *specs,*/ /* +* PCI BDF +*/ +int xlu_pci_parse_bdf (XLU_Config *cfg,libxl_device_pci *pci,const char *str); + +/* * PCI specification parsing */ -int xlu_pci_parse_bdf (XLU_Config *cfg,libxl_device_pci *pcidev,const char *str); +int xlu_pci_parse_spec_string (XLU_Config *cfg,libxl_device_pci *pci, +const char *str);/* * RDM parsing
tools/libs/util/libxlu_pci.c +186 -162
397 lines not on this page · raw message
tools/xl/xl_cmdtable.c +2 -2
@@ -90,12 +90,12 @@ struct cmd_spec cmd_table[] = { {"pci-attach" , &main_pciattach,0 ,1 ,"Insert a new pass-through pci device" , -"<Domain> <BDF> [Virtual Slot]" , +"<Domain> <PCI_SPEC_STRING>" , }, { "pci-detach", &main_pcidetach,0 ,1 ,"Remove a domain's pass-through pci device" , -"<Domain> <BDF>" , +"<Domain> <PCI_SPEC_STRING>" , }, { "pci-list", &main_pcilist, 0, 0,
tools/xl/xl_parse.c +2 -2
@@ -1487,10 +1487,10 @@ void parse_config_data(const char *config_source,* the global policy by default. */ pci->rdm_policy = b_info->u.hvm.rdm.policy; - e =xlu_pci_parse_bdf (config, pci, buf); + e =xlu_pci_parse_spec_string (config, pci, buf);if (e) {fprintf (stderr, -"unable to parse PCI BDF `%s' for passthrough\n" , +"unable to parse PCI_SPEC_STRING `%s' for passthrough\n" , buf);exit (-e); }
tools/xl/xl_pci.c +16 -17
@@ -54,7 +54,7 @@ int main_pcilist(int argc, char **argv)return 0 ; } -static int pcidetach (uint32_t domid,const char *bdf,int force) +static int pcidetach (uint32_t domid,const char *spec_string,int force) {libxl_device_pci pci;XLU_Config *config;
@@ -65,8 +65,9 @@ static int pcidetach(uint32_t domid, const char *bdf, int force) config =xlu_cfg_init (stderr,"command line" );if (!config) {perror ("xlu_cfg_inig" );exit (-1 ); } -if (xlu_pci_parse_bdf (config, &pci, bdf)) { -fprintf (stderr,"pci-detach: malformed BDF specification \"%s\"\n" , bdf); +if (xlu_pci_parse_spec_string (config, &pci, spec_string)) { +fprintf (stderr,"pci-detach: malformed PCI_SPEC_STRING \"%s\"\n" , + spec_string);exit (2 ); }if (force) {
@@ -88,7 +89,7 @@ int main_pcidetach(int argc, char **argv)uint32_t domid;int opt;int force =0 ; -const char *bdf =NULL ; +const char *spec_string =NULL ; SWITCH_FOREACH_OPT(opt, "f", NULL, "pci-detach", 2) {case 'f' :
@@ -97,15 +98,15 @@ int main_pcidetach(int argc, char **argv) } domid =find_domain (argv[optind]); - bdf = argv[optind +1 ]; + spec_string = argv[optind +1 ]; -if (pcidetach (domid, bdf, force)) +if (pcidetach (domid, spec_string, force))return EXIT_FAILURE ;return EXIT_SUCCESS ; } -static int pciattach (uint32_t domid,const char *bdf,const char *vs) +static int pciattach (uint32_t domid,const char *spec_string) {libxl_device_pci pci;XLU_Config *config;
@@ -116,8 +117,9 @@ static int pciattach(uint32_t domid, const char *bdf, const char *vs) config =xlu_cfg_init (stderr,"command line" );if (!config) {perror ("xlu_cfg_inig" );exit (-1 ); } -if (xlu_pci_parse_bdf (config, &pci, bdf)) { -fprintf (stderr,"pci-attach: malformed BDF specification \"%s\"\n" , bdf); +if (xlu_pci_parse_spec_string (config, &pci, spec_string)) { +fprintf (stderr,"pci-attach: malformed PCI_SPEC_STRING \"%s\"\n" , + spec_string);exit (2 ); }
@@ -134,19 +136,16 @@ int main_pciattach(int argc, char **argv) {uint32_t domid;int opt; -const char *bdf =NULL , *vs =NULL ; +const char *spec_string =NULL ; SWITCH_FOREACH_OPT(opt, "", NULL, "pci-attach", 2) {/* No options */ } domid =find_domain (argv[optind]); - bdf = argv[optind +1 ]; - -if (optind +1 < argc) - vs = argv[optind +2 ]; + spec_string = argv[optind +1 ]; -if (pciattach (domid, bdf, vs)) +if (pciattach (domid, spec_string))return EXIT_FAILURE ;return EXIT_SUCCESS ;
@@ -192,7 +191,7 @@ static int pciassignable_add(const char *bdf, int rebind)if (!config) {perror ("xlu_cfg_init" );exit (-1 ); }if (xlu_pci_parse_bdf (config, &pci, bdf)) { -fprintf (stderr,"pci-assignable-add: malformed BDF specification \"%s\"\n" , bdf); +fprintf (stderr,"pci-assignable-add: malformed BDF \"%s\"\n" , bdf);exit (2 ); }
@@ -234,7 +233,7 @@ static int pciassignable_remove(const char *bdf, int rebind)if (!config) {perror ("xlu_cfg_init" );exit (-1 ); }if (xlu_pci_parse_bdf (config, &pci, bdf)) { -fprintf (stderr,"pci-assignable-remove: malformed BDF specification \"%s\"\n" , bdf); +fprintf (stderr,"pci-assignable-remove: malformed BDF \"%s\"\n" , bdf);exit (2 ); }
Signature · 1 line
2.11.0
PATCH v7 3/7 libxl: stop setting 'vdevfn' in pci_struct_fill()
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
There are only two call-sites. One always sets it to 0 (which is unnecessary as the structure is already initialized to zero) and the other can simply set the 'vdevfn' field directly (after proper structure initialization), avoiding the need for a local variable.
A subsequent patch will also make use of pci_struct_fill() in a context where 'vdevfn' may already have been set.
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Anthony PERARD <[email protected]>
v7:
- New in v7
--- tools/libs/light/libxl_pci.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
tools/libs/light/libxl_pci.c +8 -7
@@ -39,13 +39,12 @@ static unsigned int pci_encode_bdf(libxl_device_pci *pci)static void pci_struct_fill (libxl_device_pci *pci,unsigned int domain,unsigned int bus,unsigned int dev, -unsigned int func,unsigned int vdevfn) +unsigned int func) { pci->domain = domain; pci->bus = bus; pci->dev = dev; pci->func = func; - pci->vdevfn = vdevfn; } static void libxl_create_pci_backend_device(libxl__gc *gc,
@@ -451,7 +450,7 @@ libxl_device_pci *libxl_device_pci_assignable_list(libxl_ctx *ctx, int *num) new = pcis + *num;libxl_device_pci_init (new); -pci_struct_fill (new, dom, bus, dev, func,0 ); +pci_struct_fill (new, dom, bus, dev, func);if (pci_info_xs_read (gc, new,"domid" ))/* already assigned */ continue ;
@@ -2288,17 +2287,19 @@ static int libxl__device_pci_from_xs_be(libxl__gc *gc, libxl_devid nr, void *data) { char *s; -unsigned int domain =0 , bus =0 , dev =0 , func =0 , vdevfn =0 ; +unsigned int domain =0 , bus =0 , dev =0 , func =0 ;libxl_device_pci *pci = data; +libxl_device_pci_init (pci); + s =libxl__xs_read (gc,XBT_NULL ,GCSPRINTF ("%s/dev-%d" , be_path, nr));sscanf (s,PCI_BDF , &domain, &bus, &dev, &func); +pci_struct_fill (pci, domain, bus, dev, func); + s =libxl__xs_read (gc,XBT_NULL ,GCSPRINTF ("%s/vdevfn-%d" , be_path, nr));if (s) - vdevfn =strtol (s, (char **)NULL ,16 ); - -pci_struct_fill (pci, domain, bus, dev, func, vdevfn); + pci->vdevfn =strtol (s, (char **)NULL ,16 ); s =libxl__xs_read (gc,XBT_NULL ,GCSPRINTF ("%s/opts-%d" , be_path, nr));if (s) {
Signature · 1 line
2.11.0
Re: [PATCH v7 3/7] libxl: stop setting 'vdevfn' in pci_struct_fill()
Quoted 11 lines · Paul Durrant
From: Paul Durrant <[email protected]>
There are only two call-sites. One always sets it to 0 (which is unnecessary as the structure is already initialized to zero) and the other can simply set the 'vdevfn' field directly (after proper structure initialization), avoiding the need for a local variable.
A subsequent patch will also make use of
pci_struct_fill()in a context where 'vdevfn' may already have been set.Signed-off-by Paul Durrant <[email protected]>
PATCH v7 4/7 libxl: add 'name' field to 'libxl_device_pci' in the IDL...
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
... and modify libxl_pci_bdf_assignable_add/remove/list() to make use of it.
libxl_pci_bdf_assignable_add() will store the name of the device in xenstore if the field is specified (i.e. non-NULL) and libxl_pci_bdf_assignable_remove() will remove devices specified only by name, looking up the BDF as necessary.
libxl_pci_bdf_assignable_list() will also populate the 'name' field if a name was stored by libxl_pci_bdf_assignable_add().
NOTE: This patch also fixes whitespace in the declaration of 'libxl_device_pci'
in the IDL.
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Anthony PERARD <[email protected]>
v7:
- New in v7
--- tools/include/libxl.h | 6 ++++ tools/libs/light/libxl_pci.c | 77 ++++++++++++++++++++++++++++++++++++++-- tools/libs/light/libxl_types.idl | 13 +++---- 3 files changed, 87 insertions(+), 9 deletions(-)
tools/include/libxl.h +6 -0
@@ -464,6 +464,12 @@#define LIBXL_HAVE_DEVICE_PCI_ASSIGNABLE_LIST_FREE 1/* +* LIBXL_HAVE_DEVICE_PCI_NAME indicates that the libxl_device_pci type +* has a name field. +*/ +#define LIBXL_HAVE_DEVICE_PCI_NAME 1 + +/* * libxl ABI compatibility * * The only guarantee which libxl makes regarding ABI compatibility
tools/libs/light/libxl_pci.c +74 -3
131 lines not on this page · raw message
tools/libs/light/libxl_types.idl +7 -6
@@ -771,17 +771,18 @@ libxl_device_nic = Struct("device_nic", [ ]) libxl_device_pci = Struct("device_pci", [ - ("func", uint8), - ("dev", uint8), - ("bus", uint8), - ("domain", integer), - ("vdevfn", uint32), + ("func", uint8), + ("dev", uint8), + ("bus", uint8), + ("domain", integer), + ("vdevfn", uint32), ("vfunc_mask", uint32), ("msitranslate", bool), ("power_mgmt", bool), ("permissive", bool), ("seize", bool), - ("rdm_policy", libxl_rdm_reserve_policy), + ("rdm_policy", libxl_rdm_reserve_policy), + ("name", string), ]) libxl_device_rdm = Struct("device_rdm", [
Signature · 1 line
2.11.0
Re: [PATCH v7 4/7] libxl: add 'name' field to 'libxl_device_pci' in the IDL...
Quoted 8 lines · Paul Durrant
From: Paul Durrant <[email protected]>
... and modify libxl_pci_bdf_assignable_add/remove/list() to make use of it.
libxl_pci_bdf_assignable_add()will store the name of the device in xenstore if the field is specified (i.e. non-NULL) andlibxl_pci_bdf_assignable_remove()will remove devices specified only by name, looking up the BDF as necessary.
Quoted 7 lines
libxl_pci_bdf_assignable_list()will also populate the 'name' field if a name was stored bylibxl_pci_bdf_assignable_add().NOTE: This patch also fixes whitespace in the declaration of '
libxl_device_pci'
in the IDL.Signed-off-by Paul Durrant <[email protected]>
PATCH v7 5/7 xl: support naming of assignable devices
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
With this patch applied 'xl pci-assignable-add' will take an optional '--name' parameter, 'xl pci-assignable-remove' can be passed either a BDF or a name and 'xl pci-assignable-list' will take a optional '--show-names' flag which determines whether names are displayed in its output.
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Anthony PERARD <[email protected]>
v7:
- Heavily re-worked, bearing only some resemblance to similarly named v6 patch
--- tools/xl/xl_cmdtable.c | 12 ++++--- tools/xl/xl_pci.c | 89 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 73 insertions(+), 28 deletions(-)
tools/xl/xl_cmdtable.c +8 -4
@@ -105,21 +105,25 @@ struct cmd_spec cmd_table[] = { {"pci-assignable-add" , &main_pciassignable_add,0 ,1 ,"Make a device assignable for pci-passthru" , -"<BDF>" , +"[options] <BDF>" , +"-n NAME, --name=NAME Name the assignable device.\n" "-h Print this help.\n" }, { "pci-assignable-remove", &main_pciassignable_remove,0 ,1 ,"Remove a device from being assignable" , -"[options] <BDF>" , +"[options] <BDF>|NAME" ,"-h Print this help.\n" "-r Attempt to re-assign the device to the\n" -" original driver" +" original driver." }, { "pci-assignable-list", &main_pciassignable_list,0 ,0 ,"List all the assignable pci devices" , -"" , +"[options]" , +"-h Print this help.\n" +"-n, --show-names Display assignable device names where\n" +" supplied.\n" }, { "pause", &main_pause, 0, 1,
tools/xl/xl_pci.c +65 -24
162 lines not on this page · raw message
Signature · 1 line
2.11.0
Re: [PATCH v7 5/7] xl: support naming of assignable devices
Quoted 8 lines · Paul Durrant
From: Paul Durrant <[email protected]>
With this patch applied 'xl pci-assignable-add' will take an optional '--name' parameter, 'xl pci-assignable-remove' can be passed either a BDF or a name and 'xl pci-assignable-list' will take a optional '--show-names' flag which determines whether names are displayed in its output.
Signed-off-by Paul Durrant <[email protected]>
PATCH v7 6/7 docs/man: modify xl-pci-configuration(5) to add 'name' field to PCI_SPEC_STRING
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
Since assignable devices can be named, a subsequent patch will support use of a PCI_SPEC_STRING containing a 'name' parameter instead of a 'bdf'. In this case the name will be used to look up the 'bdf' in the list of assignable (or assigned) devices.
---
Cc: Ian Jackson <[email protected]>
--- docs/man/xl-pci-configuration.5.pod | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
docs/man/xl-pci-configuration.5.pod +23 -2
@@ -51,7 +51,7 @@ is not specified, or if it is specified with an empty value (whether positionally or explicitly). B<NOTE>: In context of B<xl pci-detach> (see L<xl(1)>), parameters other than -B<bdf> will be ignored. +B<bdf> or B<name> will be ignored. =head1 Positional Parameters
@@ -70,7 +70,11 @@ B<*> to indicate all functions of a multi-function device. =item Default Value -None. This parameter is mandatory as it identifies the device. +None. This parameter is mandatory in its positional form. As a non-positional +parameter it is also mandatory unless a B<name> parameter is present, in +which case B<bdf> must not be present since the B<name> will be used to find +the B<bdf> in the list of assignable devices. See L<xl(1)> for more information +on naming assignable devices. =back
@@ -194,4 +198,21 @@ B<NOTE>: This overrides the global B<rdm> option. =back +=item B<name>=I<STRING> + +=over 4 + +=item Description + +This is the name given when the B<BDF> was made assignable. See L<xl(1)> for +more information on naming assignable devices. + +=item Default Value + +None. This parameter must not be present if a B<bdf> parameter is present. +If a B<bdf> parameter is not present then B<name> is mandatory as it is +required to look up the B<BDF> in the list of assignable devices. + +=back + =back
Signature · 1 line
2.11.0
PATCH v7 7/7 libxl / libxlu: support 'xl pci-attach/detach' by name
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
This patch modifies libxlu_pci_parse_spec_string() to parse the new 'name' parameter of PCI_SPEC_STRING detailed in the updated documention in xl-pci-configuration(5) and populate the 'name' field of 'libxl_device_pci'.
If the 'name' field is non-NULL then both libxl_device_pci_add() and libxl_device_pci_remove() will use it to look up the device BDF in the list of assignable devices.
---
Cc: Wei Liu <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Anthony PERARD <[email protected]>
v7:
- Re-worked (mainly because 'libxl_device_pci' already has a 'name' field)
- Dropped Wei's A-b because of the re-work
v6:
- Re-base
- Slight modification to the patch name
- Kept Wei's A-b since modifications are small
--- tools/libs/light/libxl_pci.c | 43 ++++++++++++++++++++++++++++++++++++++----- tools/libs/util/libxlu_pci.c | 7 ++++++- 2 files changed, 44 insertions(+), 6 deletions(-)
tools/libs/light/libxl_pci.c +38 -5
@@ -58,6 +58,8 @@ static void libxl_create_pci_backend_device(libxl__gc *gc,flexarray_append (back,GCSPRINTF (PCI_BDF , pci->domain, pci->bus, pci->dev, pci->func));if (pci->vdevfn)flexarray_append_pair (back,GCSPRINTF ("vdevfn-%d" , num),GCSPRINTF ("%x" , pci->vdevfn)); +if (pci->name) +flexarray_append_pair (back,GCSPRINTF ("name-%d" , num),GCSPRINTF ("%s" , pci->name));flexarray_append (back,GCSPRINTF ("opts-%d" , num)); flexarray_append(back, GCSPRINTF("msitranslate=%d,power_mgmt=%d,permissive=%d,rdm_policy=%s",
@@ -282,6 +284,7 @@ retry_transaction2:xs_rm (ctx->xsh, t,GCSPRINTF ("%s/vdev-%d" , be_path, i));xs_rm (ctx->xsh, t,GCSPRINTF ("%s/opts-%d" , be_path, i));xs_rm (ctx->xsh, t,GCSPRINTF ("%s/vdevfn-%d" , be_path, i)); +xs_rm (ctx->xsh, t,GCSPRINTF ("%s/name-%d" , be_path, i));libxl__xs_printf (gc, t, num_devs_path,"%d" , num -1 );for (j = i +1 ; j < num; j++) { tmppath =GCSPRINTF ("%s/state-%d" , be_path, j);
@@ -314,6 +317,12 @@ retry_transaction2:xs_write (ctx->xsh, t,GCSPRINTF ("%s/vdevfn-%d" , be_path, j -1 ), tmp,strlen (tmp));xs_rm (ctx->xsh, t, tmppath); } + tmppath =GCSPRINTF ("%s/name-%d" , be_path, j); + tmp =libxl__xs_read (gc, t, tmppath); +if (tmp) { +xs_write (ctx->xsh, t,GCSPRINTF ("%s/name-%d" , be_path, j -1 ), tmp,strlen (tmp)); +xs_rm (ctx->xsh, t, tmppath); + } }if (!xs_transaction_end (ctx->xsh, t,0 ))if (errno ==EAGAIN )
@@ -1589,6 +1598,12 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t domid,libxl_device_pci_copy (CTX , &pas->pci, pci); pci = &pas->pci; +/* If the device is named then we need to look up the BDF */ +if (pci->name) { + rc =name2bdf (gc, pci); +if (rc) goto out; + } + pas->starting = starting; pas->callback = device_pci_add_stubdom_done;
@@ -1739,11 +1754,19 @@ static void device_pci_add_done(libxl__egc *egc,libxl_device_pci *pci = &pas->pci;if (rc) { -LOGD (ERROR , domid, -"libxl__device_pci_add failed for " -"PCI device %x:%x:%x.%x (rc %d)" , - pci->domain, pci->bus, pci->dev, pci->func, - rc); +if (pci->name) { +LOGD (ERROR , domid, +"libxl__device_pci_add failed for " +"PCI device '%s' (rc %d)" , + pci->name, + rc); + }else { +LOGD (ERROR , domid, +"libxl__device_pci_add failed for " +"PCI device %x:%x:%x.%x (rc %d)" , + pci->domain, pci->bus, pci->dev, pci->func, + rc); + }pci_info_xs_remove (gc, pci,"domid" ); }libxl_device_pci_dispose (pci);
@@ -2250,6 +2273,12 @@ static void libxl__device_pci_remove_common(libxl__egc *egc,libxl_device_pci_copy (CTX , &prs->pci, pci); pci = &prs->pci; +/* If the device is named then we need to look up the BDF */ +if (pci->name) { + rc =name2bdf (gc, pci); +if (rc) goto out; + } + prs->force = force;libxl__xswait_init (&prs->xswait);libxl__ev_qmp_init (&prs->qmp);
@@ -2372,6 +2401,10 @@ static int libxl__device_pci_from_xs_be(libxl__gc *gc,if (s) pci->vdevfn =strtol (s, (char **)NULL ,16 ); + s =libxl__xs_read (gc,XBT_NULL ,GCSPRINTF ("%s/name-%d" , be_path, nr)); +if (s) + pci->name =strdup (s); + s =libxl__xs_read (gc,XBT_NULL ,GCSPRINTF ("%s/opts-%d" , be_path, nr));if (s) {char *saveptr;
tools/libs/util/libxlu_pci.c +6 -1
@@ -147,6 +147,7 @@ int xlu_pci_parse_spec_string(XLU_Config *cfg, libxl_device_pci *pci, {const char *ptr = str;bool bdf_present = false; +bool name_present = false;int ret;/* Attempt to parse 'bdf' as positional parameter */
@@ -189,6 +190,10 @@ int xlu_pci_parse_spec_string(XLU_Config *cfg, libxl_device_pci *pci, pci->power_mgmt =atoi (val); }else if (!strcmp (key,"rdm_policy" )) { ret =parse_rdm_policy (cfg, &pci->rdm_policy, val); + }else if (!strcmp (key,"name" )) { + name_present = true; + pci->name =strdup (val); +if (!pci->name) ret =ERROR_NOMEM ; }else {XLU__PCI_ERR (cfg,"Unknown PCI_SPEC_STRING option: %s" , key); ret =ERROR_INVAL ;
@@ -201,7 +206,7 @@ int xlu_pci_parse_spec_string(XLU_Config *cfg, libxl_device_pci *pci,return ret; } -if (!bdf_present) +if (!(bdf_present ^ name_present))return ERROR_INVAL ;return 0 ;
Signature · 1 line
2.11.0
Re: [PATCH v7 7/7] libxl / libxlu: support 'xl pci-attach/detach' by name
Quoted 11 lines · Paul Durrant
From: Paul Durrant <[email protected]>
This patch modifies
libxlu_pci_parse_spec_string()to parse the new 'name' parameter ofPCI_SPEC_STRINGdetailed in the updated documention in xl-pci-configuration(5) and populate the 'name' field of 'libxl_device_pci'.If the 'name' field is non-NULL then both
libxl_device_pci_add()andlibxl_device_pci_remove()will use it to look up the device BDF in the list of assignable devices.Signed-off-by Paul Durrant <[email protected]>
Hi, Wei!
Is this series good to go? Could you please tell if it breaks anything?
Thank you in advance,
Oleksandr
Quoted 28 lines · Paul Durrant
From: Paul Durrant <[email protected]>
These are re-worked versions of the remaining patches from v6 of the series that were reverted by commit
ac6a0af3870b"Revert patches that break libxl API".Paul Durrant (7):
docs/man: modify xl(1) in preparation for naming of assignable devices
libxlu: introducexlu_pci_parse_spec_string()
libxl: stop setting 'vdevfn' inpci_struct_fill()
libxl: add 'name' field to 'libxl_device_pci' in the IDL...
xl: support naming of assignable devices
docs/man: modify xl-pci-configuration(5) to add 'name' field to
PCI_SPEC_STRING
libxl / libxlu: support 'xl pci-attach/detach' by namedocs/man/xl-pci-configuration.5.pod | 25 ++- docs/man/xl.1.pod.in | 19 +- tools/include/libxl.h | 6 + tools/include/libxlutil.h | 8 +- tools/libs/light/libxl_pci.c | 133 ++++++++++++-- tools/libs/light/libxl_types.idl | 13 +- tools/libs/util/libxlu_pci.c | 353 +++++++++++++++++++----------------- tools/xl/xl_cmdtable.c | 16 +- tools/xl/xl_parse.c | 4 +- tools/xl/xl_pci.c | 120 ++++++++---- 10 files changed, 457 insertions(+), 240 deletions(-)