From nobody Mon Feb 9 09:29:48 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1628778212; cv=none; d=zohomail.com; s=zohoarc; b=kxJVbau+7z393oht22MBC8IPFwrvTxa4apRe3XR6UTSec/VjbNXXMbYxrsdzzo5sH8Csy4Afa2+a8jAAQ6gOXnfQR7obkWM492AR6aX0qyon3o29nQVLIyCLZbq4ni6HMSvGcNKHY3vW8zAaQhBR9OoiqpY4zhOAQsWYMF/dAlY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628778212; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=mRu1nhbLdCG3tjQcY0lNShHW8lgPAtPkcfN4T//o5X4=; b=mMoC9/QClDJ/toib6K/G7NPEZUYQgtgIr7p4G9cN7B5wavsoLUQp6dqbhHSZQ+GDLxnT4e1SJzREOsgDk6UjhqomBwLZQLOHuK9AWHztDiYXaZAi1ZCREUEmtXeG6Z4gj5cYM07V0RzPtLAa5G3zInillt8uaOnI0/uBq5AlDtg= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1628778212191998.0888557060902; Thu, 12 Aug 2021 07:23:32 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.166478.303876 (Exim 4.92) (envelope-from ) id 1mEBc5-0006F4-Ef; Thu, 12 Aug 2021 14:23:17 +0000 Received: by outflank-mailman (output) from mailman id 166478.303876; Thu, 12 Aug 2021 14:23:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mEBc5-0006EQ-9g; Thu, 12 Aug 2021 14:23:17 +0000 Received: by outflank-mailman (input) for mailman id 166478; Thu, 12 Aug 2021 14:23:16 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mEBc3-0002Q2-Vu for xen-devel@lists.xenproject.org; Thu, 12 Aug 2021 14:23:16 +0000 Received: from mail-lf1-x135.google.com (unknown [2a00:1450:4864:20::135]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 8c57d227-a9ca-4282-96d4-222312233d86; Thu, 12 Aug 2021 14:22:43 +0000 (UTC) Received: by mail-lf1-x135.google.com with SMTP id z20so13830899lfd.2 for ; Thu, 12 Aug 2021 07:22:42 -0700 (PDT) Received: from localhost.localdomain (host-176-36-213-80.b024.la.net.ua. [176.36.213.80]) by smtp.gmail.com with ESMTPSA id s16sm329678ljj.48.2021.08.12.07.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Aug 2021 07:22:40 -0700 (PDT) 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" X-Inumbo-ID: 8c57d227-a9ca-4282-96d4-222312233d86 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mRu1nhbLdCG3tjQcY0lNShHW8lgPAtPkcfN4T//o5X4=; b=TsmtWtJS9CZTcjwYV8nlT64CwRYGtU17kWngeHIA6EfJAvRvqjyWr2IVNiXsoAQ7+Y ucooQelHRR3+fkHW2uBzPe7yAVyJ7saiqYttALbKFdARwjs32v17kZ9iUycLN71+IPWf V2fzgKaQUUfL8fPAN4WihEUHFxZjXfyWX+2AJsrnANjC47vo8QUvnNESvCYxu+/IUtah JWCWlEHca2MsB3LayUHVY6rNHfi5kD9gvx3ehxrbP2gZksVruQEghkVPIzq3CALgT3Kl Tzq6UqiGCKkOvkDfh+1waTPQJnt9OjB4KOz32VxAQmcAfBNgTWdkrVDAOEmu7VEhxzvm u16w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mRu1nhbLdCG3tjQcY0lNShHW8lgPAtPkcfN4T//o5X4=; b=bott3QLs4vuI5EGwIvFcfIRruscfbKm62eL1qUK+W6t9yi3+XzGFsgTLFFQOSAsF7+ 9FPzTN56sqqfcIsFvBgoj8GSJg+lWIF+jQd5y33vO2VN0Irl6ie+ODHEW7+uMDPuq+zP QHBBwDasux2xJpUlIQfub7KbkzlsdTAjR1/ppFOZgcrVK3wMjg4naeQwlpw5hJJscsoa h6Zvie4r2Lb8LRRfZSB8ATIslMoTZr+A7o2vC8GMWDhnHVeK6n3hhOXyyTgaZ1z3LKsh kZfujjTygzgTpHLSQkQpnPFXJC/pDCXgQgbOy5UtS/y5XEb2UBkP3uL6CRLRvcvVfZId FZHg== X-Gm-Message-State: AOAM532dB1Lm2fofi51sAqgQ5Mcjt5lsirWWK8+0/tZz5DkjyqMdcRk3 G0PdMRomXCvPccfRY6UYo28PKWCjtvKm+w== X-Google-Smtp-Source: ABdhPJyKYLsBa6gX9NJCphm/jfMzDBnLENzVcaDQ0n1Va8qU3IYb0qb5sxZmkrYIh+wdOfIwCJ1JuA== X-Received: by 2002:a05:6512:3884:: with SMTP id n4mr2763937lft.313.1628778160317; Thu, 12 Aug 2021 07:22:40 -0700 (PDT) From: Anastasiia Lukianenko To: xen-devel@lists.xenproject.org Cc: oleksandr_tyshchenko@epam.com, artem_mygaiev@epam.com, rahul.singh@arm.com, bertrand.marquis@arm.com, oleksandr_andrushchenko@epam.com, roger.pau@citrix.com, julien@xen.org, sstabellini@kernel.org, andr2000@gmail.com, vicooodin@gmail.com, Anastasiia Lukianenko Subject: [PATCH 7/9] tools/libs/light: Make Libxl PCI get values from xl pcid instead of libxl side Date: Thu, 12 Aug 2021 17:22:28 +0300 Message-Id: <20210812142230.19353-8-vicooodin@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210812142230.19353-1-vicooodin@gmail.com> References: <20210812142230.19353-1-vicooodin@gmail.com> X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1628778212597100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Anastasiia Lukianenko pci_multifunction_check needs to use "ls" and "lstat" commands to get information from sysfs. Add "is_exists" command processing to xl pcid daemon to make possible pci_multifunction_check read directories and check lstat by using xl pcid. Signed-off-by: Anastasiia Lukianenko --- tools/include/pcid.h | 1 + tools/libs/light/libxl_pci.c | 47 ++++++++++++++++++----------------- tools/libs/light/libxl_pcid.c | 47 +++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 23 deletions(-) diff --git a/tools/include/pcid.h b/tools/include/pcid.h index f39011ecb8..5c8efbb435 100644 --- a/tools/include/pcid.h +++ b/tools/include/pcid.h @@ -33,6 +33,7 @@ =20 #define PCID_CMD_WRITE "write" #define PCID_CMD_READ_HEX "read_hex" +#define PCID_CMD_EXISTS "exists" #define PCID_CMD_PCI_PATH "pci_path" #define PCID_CMD_PCI_INFO "pci_info" =20 diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index d5ddca4964..ab6709890e 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -1091,45 +1091,46 @@ int libxl_device_pci_assignable_remove(libxl_ctx *c= tx, libxl_device_pci *pci, */ static int pci_multifunction_check(libxl__gc *gc, libxl_device_pci *pci, u= nsigned int *func_mask) { - struct dirent *de; - DIR *dir; - *func_mask =3D 0; + struct vchan_info *vchan; + libxl__json_object *result =3D NULL, *args =3D NULL; + const libxl__json_object *lstat_obj, *dir; + const char *dir_name; + int i; =20 - dir =3D opendir(SYSFS_PCI_DEV); - if ( NULL =3D=3D dir ) { - LOGE(ERROR, "Couldn't open %s", SYSFS_PCI_DEV); + vchan =3D pci_prepare_vchan(gc); + if (!vchan) return -1; - } =20 - while( (de =3D readdir(dir)) ) { + libxl__vchan_param_add_string(gc, &args, PCID_CMD_DIR_ID, PCID_PCI_DEV= ); + result =3D vchan_send_command(gc, vchan, PCID_CMD_LIST, args); + if (!result) + return -1; + + for (i =3D 0; (dir =3D libxl__json_array_get(result, i)); i++) { + dir_name =3D libxl__json_object_get_string(dir); unsigned dom, bus, dev, func; - struct stat st; char *path; =20 - if ( sscanf(de->d_name, PCI_BDF, &dom, &bus, &dev, &func) !=3D 4 ) + if (sscanf(dir_name, PCI_BDF, &dom, &bus, &dev, &func) !=3D 4) continue; - if ( pci->domain !=3D dom ) + if (pci->domain !=3D dom) continue; - if ( pci->bus !=3D bus ) + if (pci->bus !=3D bus) continue; - if ( pci->dev !=3D dev ) + if (pci->dev !=3D dev) continue; =20 - path =3D GCSPRINTF("%s/" PCI_BDF, SYSFS_PCIBACK_DRIVER, dom, bus, = dev, func); - if ( lstat(path, &st) ) { - if ( errno =3D=3D ENOENT ) - LOG(ERROR, PCI_BDF " is not assigned to pciback driver", - dom, bus, dev, func); - else - LOGE(ERROR, "Couldn't lstat %s", path); - closedir(dir); + path =3D GCSPRINTF("/" PCI_BDF, dom, bus, dev, func); + libxl__vchan_param_add_string(gc, &args, PCID_CMD_DIR_ID, PCID_PCI= BACK_DRIVER); + libxl__vchan_param_add_string(gc, &args, PCID_CMD_PCI_INFO, path); + lstat_obj =3D vchan_send_command(gc, vchan, PCID_CMD_EXISTS, args); + if (!lstat_obj) return -1; - } + (*func_mask) |=3D (1 << func); } =20 - closedir(dir); return 0; } =20 diff --git a/tools/libs/light/libxl_pcid.c b/tools/libs/light/libxl_pcid.c index 0f736c68af..28d773f48d 100644 --- a/tools/libs/light/libxl_pcid.c +++ b/tools/libs/light/libxl_pcid.c @@ -34,6 +34,10 @@ #include #include =20 +#include +#include +#include + #define DOM0_ID 0 =20 static struct libxl__json_object *process_ls_cmd(libxl__gc *gc, @@ -202,6 +206,47 @@ out: return result; } =20 +static libxl__json_object *process_exists_cmd(libxl__gc *gc, + const struct libxl__json_obj= ect *resp) +{ + libxl__json_object *result =3D NULL; + const struct libxl__json_object *args, *pci_path, *pci_info; + char *full_path; + struct stat st; + + args =3D libxl__json_map_get(PCID_MSG_FIELD_ARGS, resp, JSON_MAP); + if (!args) + goto out; + pci_path =3D libxl__json_map_get(PCID_CMD_DIR_ID, args, JSON_ANY); + if (!pci_path) + goto out; + pci_info =3D libxl__json_map_get(PCID_CMD_PCI_INFO, args, JSON_ANY); + if (!pci_info) + goto out; + if (strcmp(pci_path->u.string, PCID_PCIBACK_DRIVER) =3D=3D 0) + full_path =3D libxl__sprintf(gc, SYSFS_PCIBACK_DRIVER"%s", pci_inf= o->u.string); + else + full_path =3D pci_info->u.string; + + if (lstat(full_path, &st)) { + if (errno =3D=3D ENOENT) + LOGE(ERROR, "%s is not assigned to pciback driver", full_path); + else + LOGE(ERROR, "Couldn't lstat %s", full_path); + goto out; + } + + result =3D libxl__json_object_alloc(gc, JSON_STRING); + if (!result) { + LOGE(ERROR, "Memory allocation failed\n"); + goto out; + } + result->u.string =3D pci_path->u.string; + +out: + return result; +} + static int pcid_handle_message(libxl__gc *gc, const libxl__json_object *re= quest, libxl__json_object **result) { @@ -221,6 +266,8 @@ static int pcid_handle_message(libxl__gc *gc, const lib= xl__json_object *request, *result =3D process_write_cmd(gc, request); else if (strcmp(command_name, PCID_CMD_READ_HEX) =3D=3D 0) *result =3D process_read_hex_cmd(gc, request); + else if (strcmp(command_name, PCID_CMD_EXISTS) =3D=3D 0) + *result =3D process_exists_cmd(gc, request); else return ERROR_NOTFOUND; =20 --=20 2.17.1