Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Aravind Iddamsetty <aravind.iddamsetty@linux.intel.com>
To: Riana Tauro <riana.tauro@intel.com>, igt-dev@lists.freedesktop.org
Cc: anshuman.gupta@intel.com, lucas.demarchi@intel.com,
	rodrigo.vivi@intel.com, kamil.konieczny@linux.intel.com,
	louis.chauvet@bootlin.com,
	"José Expósito" <jose.exposito89@gmail.com>,
	"Jim Shargo" <jshargo@chromium.org>,
	"Marius Vlad" <marius.vlad@collabora.com>
Subject: Re: [PATCH i-g-t 2/5] lib/igt_configfs: Add helper to mount configfs
Date: Mon, 5 May 2025 11:05:03 +0530	[thread overview]
Message-ID: <b5836a88-e575-483f-ac4b-68a509b85820@linux.intel.com> (raw)
In-Reply-To: <20250422095602.55041-3-riana.tauro@intel.com>


On 22-04-2025 15:25, Riana Tauro wrote:
> From: José Expósito <jose.exposito89@gmail.com>
>
> Add a new helper function to mount and open configfs
>
> Co-developed-by: Jim Shargo <jshargo@chromium.org>
> Signed-off-by: Jim Shargo <jshargo@chromium.org>
> Co-developed-by: Marius Vlad <marius.vlad@collabora.com>
> Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
> Co-developed-by: Riana Tauro <riana.tauro@intel.com>
> Signed-off-by: Riana Tauro <riana.tauro@intel.com>
> Signed-off-by: José Expósito <jose.exposito89@gmail.com>
> ---
>  lib/igt.h          |  1 +
>  lib/igt_configfs.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++
>  lib/igt_configfs.h | 15 +++++++++
>  lib/meson.build    |  1 +
>  4 files changed, 99 insertions(+)
>  create mode 100644 lib/igt_configfs.c
>  create mode 100644 lib/igt_configfs.h
>
> diff --git a/lib/igt.h b/lib/igt.h
> index 58c39e098..173ca70bf 100644
> --- a/lib/igt.h
> +++ b/lib/igt.h
> @@ -27,6 +27,7 @@
>  #include "drmtest.h"
>  #include "i915_3d.h"
>  #include "igt_aux.h"
> +#include "igt_configfs.h"
>  #include "igt_core.h"
>  #include "igt_debugfs.h"
>  #include "igt_draw.h"
> diff --git a/lib/igt_configfs.c b/lib/igt_configfs.c
> new file mode 100644
> index 000000000..6b202b76f
> --- /dev/null
> +++ b/lib/igt_configfs.c
> @@ -0,0 +1,82 @@
> +// SPDX-License-Identifier: MIT
> +/*
> + * Copyright © 2023 Google LLC.
> + * Copyright © 2023 Collabora, Ltd.
> + * Copyright © 2024 Red Hat, Inc.
> + * Copyright © 2025 Intel Corporation
> + */
> +
> +#include <sys/mount.h>
> +#include <fcntl.h>
> +#include <limits.h>
> +
> +#include "igt_aux.h"
> +#include "igt_configfs.h"
> +
> +/**
> + * SECTION:igt_configfs
> + * @short_description: Support code for configfs features
> + * @title: configfs
> + * @include: igt_configfs.h
> + *
> + * This library provides helpers to access configfs features.
> + */
> +
> +/*
> + * General configfs helpers
> + */
> +
> +static const char *__igt_configfs_mount(void)
> +{
> +	if (igt_is_mountpoint("/sys/kernel/config"))
> +		return "/sys/kernel/config";
> +
> +	if (igt_is_mountpoint("/config"))
> +		return "/config";
> +
> +	if (mount("config", "/sys/kernel/config", "configfs", 0, 0))
> +		return NULL;
> +
> +	return "/sys/kernel/config";
> +}
> +
> +/**
> + * igt_configfs_mount:
> + *
> + * This attempts to locate where configfs is mounted on the filesystem,
> + * and if not found, will then try to mount configfs at /sys/kernel/config.
> + *
> + * Returns:
> + * The path to the configfs mount point (e.g. /sys/kernel/config)
> + */
> +const char *igt_configfs_mount(void)
> +{
> +	static const char *path;
> +
> +	if (!path)
> +		path = __igt_configfs_mount();
> +
> +	return path;
> +}
> +
> +/**
> + * igt_configfs_open: open configfs path
> + * @name: name of the configfs directory
> + *
> + * Opens the configfs directory corresponding to the name
> + *
> + * Returns:
> + * The directory fd, or -1 on failure.
> + */
> +int igt_configfs_open(const char *name)
> +{
> +	char path[PATH_MAX];
> +	const char *configfs_path;
> +
> +	configfs_path = igt_configfs_mount();
> +	igt_assert(configfs_path);
> +
> +	snprintf(path, sizeof(path), "%s/%s", configfs_path, name);
> +
> +	return open(path, O_RDONLY);

to be safe better to use O_DIRECTORY flag as well.

Reviewed-by: Aravind Iddamsetty <aravind.iddamsetty@linux.intel.com>

Thanks,
Aravind.
> +}
> diff --git a/lib/igt_configfs.h b/lib/igt_configfs.h
> new file mode 100644
> index 000000000..91f95659b
> --- /dev/null
> +++ b/lib/igt_configfs.h
> @@ -0,0 +1,15 @@
> +/* SPDX-License-Identifier: MIT */
> +/*
> + * Copyright © 2023 Google LLC.
> + * Copyright © 2023 Collabora, Ltd.
> + * Copyright © 2024 Red Hat, Inc.
> + * Copyright © 2025 Intel Corporation
> + */
> +
> +#ifndef __IGT_CONFIGFS_H__
> +#define __IGT_CONFIGFS_H__
> +
> +const char *igt_configfs_mount(void);
> +int igt_configfs_open(const char *name);
> +
> +#endif /* __IGT_CONFIGFS_H__ */
> diff --git a/lib/meson.build b/lib/meson.build
> index 8517cd540..59072d8ce 100644
> --- a/lib/meson.build
> +++ b/lib/meson.build
> @@ -18,6 +18,7 @@ lib_sources = [
>  	'i915/i915_crc.c',
>  	'igt_collection.c',
>  	'igt_color_encoding.c',
> +	'igt_configfs.c',
>  	'igt_facts.c',
>  	'igt_crc.c',
>  	'igt_debugfs.c',

  reply	other threads:[~2025-05-05  5:35 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-22  9:55 [PATCH i-g-t 0/5] Add test to validate survivability mode Riana Tauro
2025-04-22  9:55 ` [PATCH i-g-t 1/5] lib/igt_aux: Move is_mountpoint() to igt_aux Riana Tauro
2025-04-22  9:55 ` [PATCH i-g-t 2/5] lib/igt_configfs: Add helper to mount configfs Riana Tauro
2025-05-05  5:35   ` Aravind Iddamsetty [this message]
2025-05-07 11:05   ` José Expósito
2025-05-07 15:57   ` Kamil Konieczny
2025-04-22  9:55 ` [PATCH i-g-t 3/5] lib/igt_fs: Rename igt_io to igt_fs to add additional helpers Riana Tauro
2025-05-05  5:35   ` Aravind Iddamsetty
2025-05-07 11:08   ` José Expósito
2025-05-07 15:58   ` Kamil Konieczny
2025-04-22  9:56 ` [PATCH i-g-t 4/5] lib/igt_fs: Add helper functions to create and remove directories Riana Tauro
2025-05-05  5:35   ` Aravind Iddamsetty
2025-05-07 13:31   ` José Expósito
2025-05-07 15:48   ` Kamil Konieczny
2025-04-22  9:56 ` [PATCH i-g-t 5/5] tests/intel/xe_configfs: Add test to validate survivability mode Riana Tauro
2025-04-22 13:57   ` Lucas De Marchi
2025-04-22 19:29     ` Rodrigo Vivi
2025-04-24  4:17       ` Lucas De Marchi
2025-04-24  5:41         ` Riana Tauro
2025-05-12 10:54           ` Riana Tauro
2025-05-12 14:50             ` Lucas De Marchi
2025-04-24 13:00         ` Rodrigo Vivi
2025-05-05  7:08   ` Aravind Iddamsetty
2025-05-13  5:25     ` Riana Tauro
2025-04-22 19:51 ` ✓ i915.CI.BAT: success for Add test to validate survivability mode (rev2) Patchwork
2025-04-23  1:36 ` ✗ Xe.CI.Full: failure " Patchwork
2025-04-23  5:57 ` ✗ i915.CI.Full: " Patchwork
2025-04-23 21:59 ` ✓ Xe.CI.BAT: success " Patchwork
2025-04-24  9:51 ` ✗ Xe.CI.Full: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b5836a88-e575-483f-ac4b-68a509b85820@linux.intel.com \
    --to=aravind.iddamsetty@linux.intel.com \
    --cc=anshuman.gupta@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=jose.exposito89@gmail.com \
    --cc=jshargo@chromium.org \
    --cc=kamil.konieczny@linux.intel.com \
    --cc=louis.chauvet@bootlin.com \
    --cc=lucas.demarchi@intel.com \
    --cc=marius.vlad@collabora.com \
    --cc=riana.tauro@intel.com \
    --cc=rodrigo.vivi@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox