From nobody Tue Feb 10 05:46:46 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1609868827; cv=none; d=zohomail.com; s=zohoarc; b=lmLDxtABDgDug9QWYv5ntnv42kjWYLZVsDHhhco7k45VnZpav3+dVZq8hd0MSRRI39Qo4lilRUyuWe3NbXBSt4NVQooUV+HNSkGX+OZkag9auFO1Qaaf3mtHRaD0LHu+snOPYMbMKdKpRySteNZYhqUHeO6PmtCmIF3pBUE0YX4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609868827; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=mp9JJogkbVM9zNQc7dIMuCQa7vYObqg8Lb80h6tIDAc=; b=EO9wEZX2vWpyGQGa0IfNtc6gvbL8ACs4+Ia5FngC5T3QMoMR05QAuSkD+b67e4byhnizJRibqc3fazzOjOr3zgY/uJS2aE9MLf7TGEARzzuUaGBURn7eHMQwYLosAQ9vguLftqa2dKpAyVwFFyaKgi3x/SKpwN9/t1LV3a+eSUs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1609868827875995.7400962412734; Tue, 5 Jan 2021 09:47:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.62115.109816 (Exim 4.92) (envelope-from ) id 1kwqQ1-0005Wu-Ih; Tue, 05 Jan 2021 17:46:53 +0000 Received: by outflank-mailman (output) from mailman id 62115.109816; Tue, 05 Jan 2021 17:46:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwqQ1-0005WT-6T; Tue, 05 Jan 2021 17:46:53 +0000 Received: by outflank-mailman (input) for mailman id 62115; Tue, 05 Jan 2021 17:46:51 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwqPz-0005T6-Ro for xen-devel@lists.xenproject.org; Tue, 05 Jan 2021 17:46:51 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwqPz-0006Ih-7j; Tue, 05 Jan 2021 17:46:51 +0000 Received: from ec2-34-243-106-223.eu-west-1.compute.amazonaws.com ([34.243.106.223] helo=ip-10-0-70-185.eu-west-1.compute.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kwqPy-0008Uy-Vd; Tue, 05 Jan 2021 17:46:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=mp9JJogkbVM9zNQc7dIMuCQa7vYObqg8Lb80h6tIDAc=; b=34pAiUW+C7SGyVpGexlMOQrom G6dbYwXlOZ+3a4zr9P/ihHiC/uYZRqBRjBmgE0UMEX+a1K6oGHnrBb7eNTRG6B0yqgy5iKXkxrnEx SDpgYLpGewRafwjTvt+kQ/H3xURQWBtwRGg60QEpKeENX6/vzcrc9EktPaFbQ2RDfPADs=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v7 5/7] xl: support naming of assignable devices Date: Tue, 5 Jan 2021 17:46:40 +0000 Message-Id: <20210105174642.2754-6-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210105174642.2754-1-paul@xen.org> References: <20210105174642.2754-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant With this patch applied 'xl pci-assignable-add' will take an optional '--na= me' 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 Acked-by: Wei Liu --- Cc: Ian Jackson Cc: Wei Liu Cc: Anthony PERARD v7: - Heavily re-worked, bearing only some resemblance to similarly named v6 p= atch --- tools/xl/xl_cmdtable.c | 12 ++++--- tools/xl/xl_pci.c | 89 ++++++++++++++++++++++++++++++++++++----------= ---- 2 files changed, 73 insertions(+), 28 deletions(-) diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 30e17a2848..bd8af12ff3 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -105,21 +105,25 @@ struct cmd_spec cmd_table[] =3D { { "pci-assignable-add", &main_pciassignable_add, 0, 1, "Make a device assignable for pci-passthru", - "", + "[options] ", + "-n NAME, --name=3DNAME 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] ", + "[options] |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, diff --git a/tools/xl/xl_pci.c b/tools/xl/xl_pci.c index 9a66494bb5..b1c3ae2a72 100644 --- a/tools/xl/xl_pci.c +++ b/tools/xl/xl_pci.c @@ -151,7 +151,7 @@ int main_pciattach(int argc, char **argv) return EXIT_SUCCESS; } =20 -static void pciassignable_list(void) +static void pciassignable_list(bool show_names) { libxl_device_pci *pcis; int num, i; @@ -161,8 +161,12 @@ static void pciassignable_list(void) if ( pcis =3D=3D NULL ) return; for (i =3D 0; i < num; i++) { - printf("%04x:%02x:%02x.%01x\n", - pcis[i].domain, pcis[i].bus, pcis[i].dev, pcis[i].func); + libxl_device_pci *pci =3D &pcis[i]; + char *name =3D show_names ? pci->name : NULL; + + printf("%04x:%02x:%02x.%01x %s\n", + pci->domain, pci->bus, pci->dev, pci->func, + name ?: ""); } libxl_device_pci_assignable_list_free(pcis, num); } @@ -170,20 +174,27 @@ static void pciassignable_list(void) int main_pciassignable_list(int argc, char **argv) { int opt; - - SWITCH_FOREACH_OPT(opt, "", NULL, "pci-assignable-list", 0) { - /* No options */ + static struct option opts[] =3D { + {"show-names", 0, 0, 'n'}, + COMMON_LONG_OPTS + }; + bool show_names =3D false; + + SWITCH_FOREACH_OPT(opt, "n", opts, "pci-assignable-list", 0) { + case 'n': + show_names =3D true; + break; } =20 - pciassignable_list(); + pciassignable_list(show_names); return 0; } =20 -static int pciassignable_add(const char *bdf, int rebind) +static int pciassignable_add(const char *bdf, const char *name, int rebind) { libxl_device_pci pci; XLU_Config *config; - int r =3D 0; + int r; =20 libxl_device_pci_init(&pci); =20 @@ -195,8 +206,15 @@ static int pciassignable_add(const char *bdf, int rebi= nd) exit(2); } =20 - if (libxl_device_pci_assignable_add(ctx, &pci, rebind)) - r =3D 1; + if (name) { + pci.name =3D strdup(name); + if (!pci.name) { + fprintf(stderr, "pci-assignable-add: memory allocation failure= \n"); + exit(2); + } + } + + r =3D libxl_device_pci_assignable_add(ctx, &pci, rebind); =20 libxl_device_pci_dispose(&pci); xlu_cfg_destroy(config); @@ -208,38 +226,61 @@ int main_pciassignable_add(int argc, char **argv) { int opt; const char *bdf =3D NULL; - - SWITCH_FOREACH_OPT(opt, "", NULL, "pci-assignable-add", 1) { - /* No options */ + static struct option opts[] =3D { + {"name", 1, 0, 'n'}, + COMMON_LONG_OPTS + }; + const char *name =3D NULL; + + SWITCH_FOREACH_OPT(opt, "n:", opts, "pci-assignable-add", 1) { + case 'n': + name =3D optarg; + break; } =20 bdf =3D argv[optind]; =20 - if (pciassignable_add(bdf, 1)) + if (pciassignable_add(bdf, name, 1)) return EXIT_FAILURE; =20 return EXIT_SUCCESS; } =20 -static int pciassignable_remove(const char *bdf, int rebind) +static int pciassignable_remove(const char *ident, int rebind) { libxl_device_pci pci; XLU_Config *config; - int r =3D 0; + int r; =20 libxl_device_pci_init(&pci); =20 config =3D xlu_cfg_init(stderr, "command line"); if (!config) { perror("xlu_cfg_init"); exit(-1); } =20 - if (xlu_pci_parse_bdf(config, &pci, bdf)) { - fprintf(stderr, "pci-assignable-remove: malformed BDF \"%s\"\n", b= df); + /* Try remove-by-name first */ + pci.name =3D strdup(ident); + if (!pci.name) { + fprintf(stderr, "pci-assignable-add: memory allocation failure\n"); exit(2); } =20 - if (libxl_device_pci_assignable_remove(ctx, &pci, rebind)) - r =3D 1; + r =3D libxl_device_pci_assignable_remove(ctx, &pci, rebind); + if (!r || r !=3D ERROR_NOTFOUND) + goto out; + + /* If remove-by-name failed to find the device, try remove-by-BDF */ + free(pci.name); + pci.name =3D NULL; =20 + if (xlu_pci_parse_bdf(config, &pci, ident)) { + fprintf(stderr, + "pci-assignable-remove: malformed BDF '%s'\n", ident); + exit(2); + } + + r =3D libxl_device_pci_assignable_remove(ctx, &pci, rebind); + +out: libxl_device_pci_dispose(&pci); xlu_cfg_destroy(config); =20 @@ -249,7 +290,7 @@ static int pciassignable_remove(const char *bdf, int re= bind) int main_pciassignable_remove(int argc, char **argv) { int opt; - const char *bdf =3D NULL; + const char *ident =3D NULL; int rebind =3D 0; =20 SWITCH_FOREACH_OPT(opt, "r", NULL, "pci-assignable-remove", 1) { @@ -258,9 +299,9 @@ int main_pciassignable_remove(int argc, char **argv) break; } =20 - bdf =3D argv[optind]; + ident =3D argv[optind]; =20 - if (pciassignable_remove(bdf, rebind)) + if (pciassignable_remove(ident, rebind)) return EXIT_FAILURE; =20 return EXIT_SUCCESS; --=20 2.11.0