[PATCH i-g-t] lib/igt_sriov_device: Adjust the igt_sriov_is_pf function

Adam Miszczak adam.miszczak at linux.intel.com
Wed Sep 4 09:25:07 UTC 2024


Hi Marcin,

On 09.05.2024 16:15, Marcin Bernatowicz wrote:
> A device is considered a PF if it supports the creation of one or more
> VFs. This capability is indicated by the presence of the sriov_totalvfs
> attribute in the device's sysfs entry, with a value greater than zero.
> The igt_sriov_is_pf function checks for this attribute and its value to
> confirm the device's PF status.
> This adjustment streamlines the process for tests that manipulate Virtual
> Functions (VFs) by consolidating prerequisite checks into a single
> `igt_require(igt_sriov_is_pf)`.
>
> Cc: Lukasz Laguna <lukasz.laguna at intel.com>
> Cc: Michal Wajdeczko <michal.wajdeczko at intel.com>
> Signed-off-by: Marcin Bernatowicz <marcin.bernatowicz at linux.intel.com>
> ---
>   lib/igt_sriov_device.c | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/lib/igt_sriov_device.c b/lib/igt_sriov_device.c
> index a0ef05d5c..8d59bfdca 100644
> --- a/lib/igt_sriov_device.c
> +++ b/lib/igt_sriov_device.c
> @@ -19,23 +19,25 @@
>    * igt_sriov_is_pf - Check if device is PF
>    * @device: device file descriptor
>    *
> - * Determine if device is PF by checking existence of sriov_totalvfs file.
> + * Determines if a device is a Physical Function (PF) by verifying
> + * the presence of the sriov_totalvfs attribute and ensuring its
> + * read value is greater than zero.
>    *
>    * Return:
>    * True if device is PF, false otherwise.
>    */
>   bool igt_sriov_is_pf(int device)
>   {
> +	uint32_t value = 0;
>   	int sysfs;
> -	bool ret;
>   
>   	sysfs = igt_sysfs_open(device);
>   	igt_assert_fd(sysfs);
>   
> -	ret = igt_sysfs_has_attr(sysfs, "device/sriov_totalvfs");
> +	__igt_sysfs_get_u32(sysfs, "device/sriov_totalvfs", &value);
>   	close(sysfs);
>   
> -	return ret;
> +	return value > 0;

LGTM,
Reviewed-by: Adam Miszczak <adam.miszczak at linux.intel.com>

>   }
>   
>   static bool __pf_attr_get_u32(int pf, const char *attr, uint32_t *value)


More information about the igt-dev mailing list