* [PATCH] gpio: create empty /sys/class/gpio with SYSFS disabled
@ 2024-10-14 12:10 Bartosz Golaszewski
2024-10-14 14:50 ` Bartosz Golaszewski
0 siblings, 1 reply; 3+ messages in thread
From: Bartosz Golaszewski @ 2024-10-14 12:10 UTC (permalink / raw)
To: Linus Walleij, Kent Gibson; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
User-space may want to use some kind of a compatibility layer for the
deprecated GPIO sysfs ABI. This would typically involve mounting
a fuse-based filesystem using the GPIO character device to emulate the
sysfs behavior and layout.
With GPIO_SYSFS disabled, the /sys/class/gpio directory doesn't exist
and user-space cannot create it. In order to facilitate moving away from
the sysfs, add a new Kconfig option that indicates to GPIOLIB that is
should create an empty directory where the GPIO class interface would
exist and enable it by default.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
As I've mentioned under a different patch, I'm working on a user-space
compatibility layer for the sysfs GPIO interface. FUSE allows us to
emulate almost all its functionalities using libgpiod except for
mounting it under /sys/class/gpio if GPIO_SYSFS is disabled. User-space
cannot create directories in sysfs so if we want to allow users to mount
the FUSE emulator under the old location, we need to create an empty
/sys/class/gpio directory from the kernel and this is what is patch is
for.
drivers/gpio/Kconfig | 18 ++++++++++++++++++
drivers/gpio/gpiolib.c | 12 ++++++++++++
2 files changed, 30 insertions(+)
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index bfa6b5a2c537..f2e7163cb46c 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -69,6 +69,24 @@ config GPIO_SYSFS
use the character device /dev/gpiochipN with the appropriate
ioctl() operations instead.
+config GPIO_SYSFS_CLASS_DIR_STUB
+ bool "Create empty /sys/class/gpio directory" if EXPERT
+ depends on !GPIO_SYSFS
+ default y
+ help
+ Say Y here to create an empty /sys/class/gpio directory.
+
+ User-space may want to use some kind of a compatibility layer for the
+ deprecated GPIO sysfs ABI. This would typically involve mounting
+ a fuse-based filesystem using the GPIO character device to emulate
+ the sysfs behavior and layout.
+
+ This option makes GPIOLIB create an empty directory at /sys/class/gpio
+ where user-space can mount the sysfs replacement and avoid having to
+ change existing programs to adjust to different filesystem paths.
+
+ If unsure, say Y.
+
config GPIO_CDEV
bool
prompt "Character device (/dev/gpiochipN) support" if EXPERT
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 97346b746ef5..31efb580beb8 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -4873,6 +4873,12 @@ static struct device_driver gpio_stub_drv = {
.probe = gpio_stub_drv_probe,
};
+#if IS_ENABLED(CONFIG_GPIO_SYSFS_CLASS_DIR_STUB)
+static const struct class gpio_class_stub = {
+ .name = "gpio",
+};
+#endif /* CONFIG_GPIO_SYSFS_CLASS_DIR_STUB */
+
static int __init gpiolib_dev_init(void)
{
int ret;
@@ -4899,6 +4905,12 @@ static int __init gpiolib_dev_init(void)
return ret;
}
+#if IS_ENABLED(CONFIG_GPIO_SYSFS_CLASS_DIR_STUB)
+ ret = class_register(&gpio_class_stub);
+ if (ret)
+ pr_err("gpiolib: failed to create the empty gpio class directory\n");
+#endif /* CONFIG_GPIO_SYSFS_CLASS_DIR_STUB */
+
gpiolib_initialized = true;
gpiochip_setup_devs();
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] gpio: create empty /sys/class/gpio with SYSFS disabled
2024-10-14 12:10 [PATCH] gpio: create empty /sys/class/gpio with SYSFS disabled Bartosz Golaszewski
@ 2024-10-14 14:50 ` Bartosz Golaszewski
2024-10-15 2:20 ` Kent Gibson
0 siblings, 1 reply; 3+ messages in thread
From: Bartosz Golaszewski @ 2024-10-14 14:50 UTC (permalink / raw)
To: Linus Walleij, Kent Gibson; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
On Mon, Oct 14, 2024 at 2:10 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> User-space may want to use some kind of a compatibility layer for the
> deprecated GPIO sysfs ABI. This would typically involve mounting
> a fuse-based filesystem using the GPIO character device to emulate the
> sysfs behavior and layout.
>
> With GPIO_SYSFS disabled, the /sys/class/gpio directory doesn't exist
> and user-space cannot create it. In order to facilitate moving away from
> the sysfs, add a new Kconfig option that indicates to GPIOLIB that is
> should create an empty directory where the GPIO class interface would
> exist and enable it by default.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---
> As I've mentioned under a different patch, I'm working on a user-space
> compatibility layer for the sysfs GPIO interface. FUSE allows us to
> emulate almost all its functionalities using libgpiod except for
> mounting it under /sys/class/gpio if GPIO_SYSFS is disabled. User-space
> cannot create directories in sysfs so if we want to allow users to mount
> the FUSE emulator under the old location, we need to create an empty
> /sys/class/gpio directory from the kernel and this is what is patch is
> for.
>
> drivers/gpio/Kconfig | 18 ++++++++++++++++++
> drivers/gpio/gpiolib.c | 12 ++++++++++++
> 2 files changed, 30 insertions(+)
>
> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> index bfa6b5a2c537..f2e7163cb46c 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -69,6 +69,24 @@ config GPIO_SYSFS
> use the character device /dev/gpiochipN with the appropriate
> ioctl() operations instead.
>
> +config GPIO_SYSFS_CLASS_DIR_STUB
> + bool "Create empty /sys/class/gpio directory" if EXPERT
> + depends on !GPIO_SYSFS
> + default y
> + help
> + Say Y here to create an empty /sys/class/gpio directory.
> +
> + User-space may want to use some kind of a compatibility layer for the
> + deprecated GPIO sysfs ABI. This would typically involve mounting
> + a fuse-based filesystem using the GPIO character device to emulate
> + the sysfs behavior and layout.
> +
> + This option makes GPIOLIB create an empty directory at /sys/class/gpio
> + where user-space can mount the sysfs replacement and avoid having to
> + change existing programs to adjust to different filesystem paths.
> +
> + If unsure, say Y.
> +
> config GPIO_CDEV
> bool
> prompt "Character device (/dev/gpiochipN) support" if EXPERT
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 97346b746ef5..31efb580beb8 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -4873,6 +4873,12 @@ static struct device_driver gpio_stub_drv = {
> .probe = gpio_stub_drv_probe,
> };
>
> +#if IS_ENABLED(CONFIG_GPIO_SYSFS_CLASS_DIR_STUB)
> +static const struct class gpio_class_stub = {
> + .name = "gpio",
> +};
> +#endif /* CONFIG_GPIO_SYSFS_CLASS_DIR_STUB */
> +
> static int __init gpiolib_dev_init(void)
> {
> int ret;
> @@ -4899,6 +4905,12 @@ static int __init gpiolib_dev_init(void)
> return ret;
> }
>
> +#if IS_ENABLED(CONFIG_GPIO_SYSFS_CLASS_DIR_STUB)
> + ret = class_register(&gpio_class_stub);
Gah I forgot to unregister the class. Also now that I think about it
we should maybe expose the class kobject in the kobject.h header and
use sysfs_create_mount_point() like what we do for debugfs, configfs
and other mountpoints at /sys/kernel?
In any case: please let me know what you think about this change in general.
Bart
> + if (ret)
> + pr_err("gpiolib: failed to create the empty gpio class directory\n");
> +#endif /* CONFIG_GPIO_SYSFS_CLASS_DIR_STUB */
> +
> gpiolib_initialized = true;
> gpiochip_setup_devs();
>
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gpio: create empty /sys/class/gpio with SYSFS disabled
2024-10-14 14:50 ` Bartosz Golaszewski
@ 2024-10-15 2:20 ` Kent Gibson
0 siblings, 0 replies; 3+ messages in thread
From: Kent Gibson @ 2024-10-15 2:20 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linus Walleij, linux-gpio, linux-kernel, Bartosz Golaszewski
On Mon, Oct 14, 2024 at 04:50:09PM +0200, Bartosz Golaszewski wrote:
> On Mon, Oct 14, 2024 at 2:10 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> >
> > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> >
>
> In any case: please let me know what you think about this change in general.
>
I've got no strong opinions either way.
Cheers,
Kent.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-15 2:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-14 12:10 [PATCH] gpio: create empty /sys/class/gpio with SYSFS disabled Bartosz Golaszewski
2024-10-14 14:50 ` Bartosz Golaszewski
2024-10-15 2:20 ` Kent Gibson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).