* [Virtio-fs] [PATCH] virtiofs: Export filesystem tags through sysfs
@ 2023-10-05 20:30 Vivek Goyal
2023-10-09 9:53 ` Miklos Szeredi
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Vivek Goyal @ 2023-10-05 20:30 UTC (permalink / raw)
To: linux-fsdevel, virtio-fs; +Cc: vgoyal, miklos, stefanha, mzxreary, gmaglione
virtiofs filesystem is mounted using a "tag" which is exported by the
virtiofs device. virtiofs driver knows about all the available tags but
these are not exported to user space.
People have asked these tags to be exported to user space. Most recently
Lennart Poettering has asked for it as he wants to scan the tags and mount
virtiofs automatically in certain cases.
https://gitlab.com/virtio-fs/virtiofsd/-/issues/128
This patch exports tags through sysfs. One tag is associated with each
virtiofs device. A new "tag" file appears under virtiofs device dir.
Actual filesystem tag can be obtained by reading this "tag" file.
For example, if a virtiofs device exports tag "myfs", a new file "tag"
will show up here.
/sys/bus/virtio/devices/virtio<N>/tag
# cat /sys/bus/virtio/devices/virtio<N>/tag
myfs
Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
---
fs/fuse/virtio_fs.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
index 5f1be1da92ce..a5b11e18f331 100644
--- a/fs/fuse/virtio_fs.c
+++ b/fs/fuse/virtio_fs.c
@@ -107,6 +107,21 @@ static const struct fs_parameter_spec virtio_fs_parameters[] = {
{}
};
+/* Forward Declarations */
+static void virtio_fs_stop_all_queues(struct virtio_fs *fs);
+
+/* sysfs related */
+static ssize_t tag_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct virtio_device *vdev = container_of(dev, struct virtio_device,
+ dev);
+ struct virtio_fs *fs = vdev->priv;
+
+ return sysfs_emit(buf, "%s", fs->tag);
+}
+static DEVICE_ATTR_RO(tag);
+
static int virtio_fs_parse_param(struct fs_context *fsc,
struct fs_parameter *param)
{
@@ -265,6 +280,15 @@ static int virtio_fs_add_instance(struct virtio_fs *fs)
return 0;
}
+static void virtio_fs_remove_instance(struct virtio_fs *fs)
+{
+ mutex_lock(&virtio_fs_mutex);
+ list_del_init(&fs->list);
+ virtio_fs_stop_all_queues(fs);
+ virtio_fs_drain_all_queues_locked(fs);
+ mutex_unlock(&virtio_fs_mutex);
+}
+
/* Return the virtio_fs with a given tag, or NULL */
static struct virtio_fs *virtio_fs_find_instance(const char *tag)
{
@@ -891,8 +915,15 @@ static int virtio_fs_probe(struct virtio_device *vdev)
if (ret < 0)
goto out_vqs;
+ /* Export tag through sysfs */
+ ret = device_create_file(&vdev->dev, &dev_attr_tag);
+ if (ret < 0)
+ goto out_sysfs_attr;
+
return 0;
+out_sysfs_attr:
+ virtio_fs_remove_instance(fs);
out_vqs:
virtio_reset_device(vdev);
virtio_fs_cleanup_vqs(vdev);
@@ -922,6 +953,9 @@ static void virtio_fs_remove(struct virtio_device *vdev)
struct virtio_fs *fs = vdev->priv;
mutex_lock(&virtio_fs_mutex);
+ /* Remove tag attr from sysfs */
+ device_remove_file(&vdev->dev, &dev_attr_tag);
+
/* This device is going away. No one should get new reference */
list_del_init(&fs->list);
virtio_fs_stop_all_queues(fs);
--
2.41.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [Virtio-fs] [PATCH] virtiofs: Export filesystem tags through sysfs
2023-10-05 20:30 [Virtio-fs] [PATCH] virtiofs: Export filesystem tags through sysfs Vivek Goyal
@ 2023-10-09 9:53 ` Miklos Szeredi
2023-10-09 20:21 ` Vivek Goyal
2023-10-10 17:21 ` Stefan Hajnoczi
2023-10-21 16:10 ` Alyssa Ross
2 siblings, 1 reply; 7+ messages in thread
From: Miklos Szeredi @ 2023-10-09 9:53 UTC (permalink / raw)
To: Vivek Goyal; +Cc: linux-fsdevel, virtio-fs, stefanha, mzxreary, gmaglione
On Thu, 5 Oct 2023 at 22:30, Vivek Goyal <vgoyal@redhat.com> wrote:
>
> virtiofs filesystem is mounted using a "tag" which is exported by the
> virtiofs device. virtiofs driver knows about all the available tags but
> these are not exported to user space.
>
> People have asked these tags to be exported to user space. Most recently
> Lennart Poettering has asked for it as he wants to scan the tags and mount
> virtiofs automatically in certain cases.
>
> https://gitlab.com/virtio-fs/virtiofsd/-/issues/128
>
> This patch exports tags through sysfs. One tag is associated with each
> virtiofs device. A new "tag" file appears under virtiofs device dir.
> Actual filesystem tag can be obtained by reading this "tag" file.
>
> For example, if a virtiofs device exports tag "myfs", a new file "tag"
> will show up here.
>
> /sys/bus/virtio/devices/virtio<N>/tag
>
> # cat /sys/bus/virtio/devices/virtio<N>/tag
> myfs
>
> Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
Hi Vivek,
This needs something under Documentation/.
While the interface looks good to me, I think we need an ack on that
from the virtio maintainer.
Thanks,
Miklos
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Virtio-fs] [PATCH] virtiofs: Export filesystem tags through sysfs
2023-10-09 9:53 ` Miklos Szeredi
@ 2023-10-09 20:21 ` Vivek Goyal
0 siblings, 0 replies; 7+ messages in thread
From: Vivek Goyal @ 2023-10-09 20:21 UTC (permalink / raw)
To: Miklos Szeredi; +Cc: linux-fsdevel, virtio-fs, mzxreary, stefanha
On Mon, Oct 09, 2023 at 11:53:42AM +0200, Miklos Szeredi wrote:
> On Thu, 5 Oct 2023 at 22:30, Vivek Goyal <vgoyal@redhat.com> wrote:
> >
> > virtiofs filesystem is mounted using a "tag" which is exported by the
> > virtiofs device. virtiofs driver knows about all the available tags but
> > these are not exported to user space.
> >
> > People have asked these tags to be exported to user space. Most recently
> > Lennart Poettering has asked for it as he wants to scan the tags and mount
> > virtiofs automatically in certain cases.
> >
> > https://gitlab.com/virtio-fs/virtiofsd/-/issues/128
> >
> > This patch exports tags through sysfs. One tag is associated with each
> > virtiofs device. A new "tag" file appears under virtiofs device dir.
> > Actual filesystem tag can be obtained by reading this "tag" file.
> >
> > For example, if a virtiofs device exports tag "myfs", a new file "tag"
> > will show up here.
> >
> > /sys/bus/virtio/devices/virtio<N>/tag
> >
> > # cat /sys/bus/virtio/devices/virtio<N>/tag
> > myfs
> >
> > Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
>
> Hi Vivek,
>
> This needs something under Documentation/.
Hi Miklos,
Hmm.., I can easily update the virtiofs documentation.
Initially I was thinking to put something in Documentation/ABI/testing/
as well. But I don't see any virtio related. In fact can't find any
files related to "virtio" at all.
So I will just update the Documentation/filesystems/virtiofs.rst for now.
>
> While the interface looks good to me, I think we need an ack on that
> from the virtio maintainer.
I am assuming Stefan should be able to provide an ACK. But I will also
add Michael and Paolo in the V2 of the patch and hoping we should be
able to get atleast 1 ACK.
Thanks
Vivek
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Virtio-fs] [PATCH] virtiofs: Export filesystem tags through sysfs
2023-10-05 20:30 [Virtio-fs] [PATCH] virtiofs: Export filesystem tags through sysfs Vivek Goyal
2023-10-09 9:53 ` Miklos Szeredi
@ 2023-10-10 17:21 ` Stefan Hajnoczi
2023-10-11 18:08 ` German Maglione
2023-10-21 16:10 ` Alyssa Ross
2 siblings, 1 reply; 7+ messages in thread
From: Stefan Hajnoczi @ 2023-10-10 17:21 UTC (permalink / raw)
To: Vivek Goyal; +Cc: linux-fsdevel, virtio-fs, miklos, mzxreary, gmaglione
[-- Attachment #1: Type: text/plain, Size: 1376 bytes --]
On Thu, Oct 05, 2023 at 04:30:30PM -0400, Vivek Goyal wrote:
> virtiofs filesystem is mounted using a "tag" which is exported by the
> virtiofs device. virtiofs driver knows about all the available tags but
> these are not exported to user space.
>
> People have asked these tags to be exported to user space. Most recently
> Lennart Poettering has asked for it as he wants to scan the tags and mount
> virtiofs automatically in certain cases.
>
> https://gitlab.com/virtio-fs/virtiofsd/-/issues/128
>
> This patch exports tags through sysfs. One tag is associated with each
> virtiofs device. A new "tag" file appears under virtiofs device dir.
> Actual filesystem tag can be obtained by reading this "tag" file.
>
> For example, if a virtiofs device exports tag "myfs", a new file "tag"
> will show up here.
>
> /sys/bus/virtio/devices/virtio<N>/tag
>
> # cat /sys/bus/virtio/devices/virtio<N>/tag
> myfs
If you respin this series, please mention that the tag is available at
KOBJ_BIND time, but not KOBJ_ADD. Just a sentence or two is enough to
help someone trying to figure out how to use this new sysfs attr with
udev.
>
> Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
> ---
> fs/fuse/virtio_fs.c | 34 ++++++++++++++++++++++++++++++++++
> 1 file changed, 34 insertions(+)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Virtio-fs] [PATCH] virtiofs: Export filesystem tags through sysfs
2023-10-10 17:21 ` Stefan Hajnoczi
@ 2023-10-11 18:08 ` German Maglione
0 siblings, 0 replies; 7+ messages in thread
From: German Maglione @ 2023-10-11 18:08 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: Vivek Goyal, linux-fsdevel, virtio-fs, miklos, mzxreary
On Tue, Oct 10, 2023 at 8:38 PM Stefan Hajnoczi <stefanha@redhat.com> wrote:
>
> On Thu, Oct 05, 2023 at 04:30:30PM -0400, Vivek Goyal wrote:
> > virtiofs filesystem is mounted using a "tag" which is exported by the
> > virtiofs device. virtiofs driver knows about all the available tags but
> > these are not exported to user space.
> >
> > People have asked these tags to be exported to user space. Most recently
> > Lennart Poettering has asked for it as he wants to scan the tags and mount
> > virtiofs automatically in certain cases.
> >
> > https://gitlab.com/virtio-fs/virtiofsd/-/issues/128
> >
> > This patch exports tags through sysfs. One tag is associated with each
> > virtiofs device. A new "tag" file appears under virtiofs device dir.
> > Actual filesystem tag can be obtained by reading this "tag" file.
> >
> > For example, if a virtiofs device exports tag "myfs", a new file "tag"
> > will show up here.
> >
> > /sys/bus/virtio/devices/virtio<N>/tag
> >
> > # cat /sys/bus/virtio/devices/virtio<N>/tag
> > myfs
>
> If you respin this series, please mention that the tag is available at
> KOBJ_BIND time, but not KOBJ_ADD. Just a sentence or two is enough to
> help someone trying to figure out how to use this new sysfs attr with
> udev.
Maybe it's also worth mention, that the tag file is created after a successful
probe, so the tag should be a valid one: non-empty and unique
>
> >
> > Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
> > ---
> > fs/fuse/virtio_fs.c | 34 ++++++++++++++++++++++++++++++++++
> > 1 file changed, 34 insertions(+)
>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
--
German
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Virtio-fs] [PATCH] virtiofs: Export filesystem tags through sysfs
2023-10-05 20:30 [Virtio-fs] [PATCH] virtiofs: Export filesystem tags through sysfs Vivek Goyal
2023-10-09 9:53 ` Miklos Szeredi
2023-10-10 17:21 ` Stefan Hajnoczi
@ 2023-10-21 16:10 ` Alyssa Ross
[not found] ` <ZUv56DRM/aiBRspd@redhat.com>
2 siblings, 1 reply; 7+ messages in thread
From: Alyssa Ross @ 2023-10-21 16:10 UTC (permalink / raw)
To: Vivek Goyal
Cc: linux-fsdevel, virtio-fs, miklos, stefanha, mzxreary, gmaglione
[-- Attachment #1: Type: text/plain, Size: 2452 bytes --]
On Thu, Oct 05, 2023 at 04:30:30PM -0400, Vivek Goyal wrote:
> virtiofs filesystem is mounted using a "tag" which is exported by the
> virtiofs device. virtiofs driver knows about all the available tags but
> these are not exported to user space.
>
> People have asked these tags to be exported to user space. Most recently
> Lennart Poettering has asked for it as he wants to scan the tags and mount
> virtiofs automatically in certain cases.
>
> https://gitlab.com/virtio-fs/virtiofsd/-/issues/128
Hi, I was one of those people. :)
> This patch exports tags through sysfs. One tag is associated with each
> virtiofs device. A new "tag" file appears under virtiofs device dir.
> Actual filesystem tag can be obtained by reading this "tag" file.
>
> For example, if a virtiofs device exports tag "myfs", a new file "tag"
> will show up here.
>
> /sys/bus/virtio/devices/virtio<N>/tag
>
> # cat /sys/bus/virtio/devices/virtio<N>/tag
> myfs
>
> Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
Are you still thinking about exposing this in the uevent as well?
That would be much more convenient for me, because with this approach
by the time the "remove" uevent arrives, it's no longer possible to
check what tag was associated with the device — you have to store it
somewhere when the device appears, so you can look it up again when the
device is removed. (Not everybody uses udev.)
Regardless,
Tested-by: Alyssa Ross <hi@alyssa.is>
… and a review comment below.
> ---
> fs/fuse/virtio_fs.c | 34 ++++++++++++++++++++++++++++++++++
> 1 file changed, 34 insertions(+)
>
> diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
> index 5f1be1da92ce..a5b11e18f331 100644
> --- a/fs/fuse/virtio_fs.c
> +++ b/fs/fuse/virtio_fs.c
> @@ -107,6 +107,21 @@ static const struct fs_parameter_spec virtio_fs_parameters[] = {
> {}
> };
>
> +/* Forward Declarations */
> +static void virtio_fs_stop_all_queues(struct virtio_fs *fs);
> +
> +/* sysfs related */
> +static ssize_t tag_show(struct device *dev, struct device_attribute *attr,
> + char *buf)
> +{
> + struct virtio_device *vdev = container_of(dev, struct virtio_device,
> + dev);
> + struct virtio_fs *fs = vdev->priv;
> +
> + return sysfs_emit(buf, "%s", fs->tag);
All of the other files in the device directory end with trailing
newlines. Should this one be an exception?
> +}
> +static DEVICE_ATTR_RO(tag);
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-11-12 17:43 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-05 20:30 [Virtio-fs] [PATCH] virtiofs: Export filesystem tags through sysfs Vivek Goyal
2023-10-09 9:53 ` Miklos Szeredi
2023-10-09 20:21 ` Vivek Goyal
2023-10-10 17:21 ` Stefan Hajnoczi
2023-10-11 18:08 ` German Maglione
2023-10-21 16:10 ` Alyssa Ross
[not found] ` <ZUv56DRM/aiBRspd@redhat.com>
[not found] ` <87r0ky538y.fsf@alyssa.is>
2023-11-12 10:10 ` Stefan Hajnoczi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox