Skip to contentSkip to conversation

Export mqueues to procfs

RFC PATCH In review Florian Bezdeka 3 participants 13 messages Aug 18, 2021

lore
Share & tools
lore
#0 lore raw

cover Export mqueues to procfs

Hi,

this is another try to make registered mqueues visible. This time by exporting them to the procfs, namely to /proc/xenomai/registry/mqueue/<name>

Let me know what you think...

I had to rework the existing export machinery a bit to get rid of the so called "root" directory which is normally created. See patch descriptions for details.

Best regards,
Florian

Florian Bezdeka (4):
cobalt/registry: Make the root directory for proc exports optional cobalt/registry: Share xnregistry_vfreg_ops with other compile units cobalt/registry: Initialize refcnt of exported virtual proc files cobalt/mqueue: Export created mqueues to procfs

 include/cobalt/kernel/registry.h |  2 ++
 kernel/cobalt/posix/mqueue.c     | 35 +++++++++++++++++++++++++++++++-
 kernel/cobalt/registry.c         | 13 ++++++------
 3 files changed, 43 insertions(+), 7 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

RFC PATCH 1/4 cobalt/registry: Make the root directory for proc exports optional

Previously the root directory was mandatory, which means that exports to the proc file system were forced to be located in /proc/xenomai/registry/<root-dir>/<class>/<file>.

The <root-dir> virtual directory is now optional. If not supplied the root node of <class> is set to registry_vfroot, which represents /proc/xenomai/registry.

---
 kernel/cobalt/registry.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
kernel/cobalt/registry.c +6 -6
index fa1de66c3..5cbebdc5b 100644
@@ -242,8 +242,8 @@ static void proc_callback(struct work_struct *work)
 		pnode = object->pnode;
 		type = pnode->dirname;
 		dir = &pnode->vdir;
-		rdir = &pnode->root->vdir;
-		rname = pnode->root->dirname;
+		rdir = pnode->root ? &pnode->root->vdir : &registry_vfroot;
+		rname = pnode->root ? pnode->root->dirname : NULL;
 
 		if (object->vfilp != XNOBJECT_EXPORT_SCHEDULED)
 			goto unexport;
@@ -254,7 +254,7 @@ static void proc_callback(struct work_struct *work)
 		xnlock_put_irqrestore(&nklock, s);
 
 		if (pnode->entries++ == 0) {
-			if (pnode->root->entries++ == 0) {
+			if (pnode->root && pnode->root->entries++ == 0) {
 				/* Create the root directory on the fly. */
 				ret = xnvfile_init_dir(rname, rdir, &registry_vfroot);
 				if (ret) {
@@ -268,7 +268,7 @@ static void proc_callback(struct work_struct *work)
 			/* Create the class directory on the fly. */
 			ret = xnvfile_init_dir(type, dir, rdir);
 			if (ret) {
-				if (pnode->root->entries == 1) {
+				if (pnode->root && pnode->root->entries == 1) {
 					pnode->root->entries = 0;
 					xnvfile_destroy_dir(rdir);
 				}
@@ -282,7 +282,7 @@ static void proc_callback(struct work_struct *work)
 		ret = pnode->ops->export(object, pnode);
 		if (ret && --pnode->entries == 0) {
 			xnvfile_destroy_dir(dir);
-			if (--pnode->root->entries == 0)
+			if (pnode->root && --pnode->root->entries == 0)
 				xnvfile_destroy_dir(rdir);
 			xnlock_get_irqsave(&nklock, s);
 			object->pnode = NULL;
@@ -315,7 +315,7 @@ static void proc_callback(struct work_struct *work)
 
 		if (--pnode->entries == 0) {
 			xnvfile_destroy_dir(dir);
-			if (--pnode->root->entries == 0)
+			if (pnode->root && --pnode->root->entries == 0)
 				xnvfile_destroy_dir(rdir);
 		}
 
Signature · 1 line
2.30.2
#2 lore raw

Re: [RFC PATCH 1/4] cobalt/registry: Make the root directory for proc exports optional

Quoted 7 lines · Florian Bezdeka via Xenomai

Previously the root directory was mandatory, which means that exports to the proc file system were forced to be located in /proc/xenomai/registry/<root-dir>/<class>/<file>.

The <root-dir> virtual directory is now optional. If not supplied the root node of <class> is set to registry_vfroot, which represents /proc/xenomai/registry.

This is not needed. You may want to try something along these lines (excerpt from the Xenomai 2 implementation the registry originates from, with a few adaptations for readability, ksrc/skins/native/queue.c):

static DEFINE_XNPTREE(__queue_ptree, "native");

static struct xnpnode_snapshot __q_pnode = {
	.node = {
		.dirname = "queues",
		.root = &__queue_ptree,
		.ops = &xnregistry_vfsnap_ops,
	},
	.vfile = {
		.privsz = sizeof(struct vfile_priv),
		.datasz = sizeof(struct vfile_data),
		.ops = &vfile_ops,
	},
};

...

xnregistry_enter(q->name, q, &q->handle, &__q_pnode.node);

With this, you would get the /proc/xenomai/registry/queues root directory for queues created automatically, the way the registry wants it to be done.

Signature · 1 line
Philippe.
#3 lore raw

Re: [RFC PATCH 1/4] cobalt/registry: Make the root directory for proc exports optional

Quoted 29 lines · Philippe Gerum
Quoted 7 lines · Florian Bezdeka via Xenomai

Previously the root directory was mandatory, which means that exports to the proc file system were forced to be located in /proc/xenomai/registry/<root-dir>/<class>/<file>.

The <root-dir> virtual directory is now optional. If not supplied the root node of <class> is set to registry_vfroot, which represents /proc/xenomai/registry.

This is not needed. You may want to try something along these lines (excerpt from the Xenomai 2 implementation the registry originates from, with a few adaptations for readability, ksrc/skins/native/queue.c):

static DEFINE_XNPTREE(__queue_ptree, "native");

static struct xnpnode_snapshot __q_pnode = {
	.node = {
		.dirname = "queues",
		.root = &__queue_ptree,
		.ops = &xnregistry_vfsnap_ops,
	},
	.vfile = {
		.privsz = sizeof(struct vfile_priv),
		.datasz = sizeof(struct vfile_data),
		.ops = &vfile_ops,
	},
};
Quoted 8 lines

...

xnregistry_enter(q->name, q, &q->handle, &__q_pnode.node);

With this, you would get the /proc/xenomai/registry/queues root directory for queues created automatically, the way the registry wants it to be done.

I tried exactly that, but ended up all queues to be visible in /proc/xenomai/registry/native/queues/<name> which was not what I wanted to achieve.

But if you tell me that there must be an additional subdirectory, I'm fine with it...

Florian

#4 lore raw

Re: [RFC PATCH 1/4] cobalt/registry: Make the root directory for proc exports optional

Quoted 39 lines · Florian
Quoted 29 lines · Philippe Gerum
Quoted 7 lines · Florian Bezdeka via Xenomai

Previously the root directory was mandatory, which means that exports to the proc file system were forced to be located in /proc/xenomai/registry/<root-dir>/<class>/<file>.

The <root-dir> virtual directory is now optional. If not supplied the root node of <class> is set to registry_vfroot, which represents /proc/xenomai/registry.

This is not needed. You may want to try something along these lines (excerpt from the Xenomai 2 implementation the registry originates from, with a few adaptations for readability, ksrc/skins/native/queue.c):

static DEFINE_XNPTREE(__queue_ptree, "native");

static struct xnpnode_snapshot __q_pnode = {
	.node = {
		.dirname = "queues",
		.root = &__queue_ptree,
		.ops = &xnregistry_vfsnap_ops,
	},
	.vfile = {
		.privsz = sizeof(struct vfile_priv),
		.datasz = sizeof(struct vfile_data),
		.ops = &vfile_ops,
	},
};
Quoted 8 lines

...

xnregistry_enter(q->name, q, &q->handle, &__q_pnode.node);

With this, you would get the /proc/xenomai/registry/queues root directory for queues created automatically, the way the registry wants it to be done.

Quoted 7 lines

I tried exactly that, but ended up all queues to be visible in /proc/xenomai/registry/native/queues/<name> which was not what I wanted to achieve.

But if you tell me that there must be an additional subdirectory, I'm fine with it...

DEFINE_XNPTREE(rtipc_ptree, "rtipc") already exists in the hierarchy, with protocols attached underneath. The current registry still exhibits some Xenomai 2 legacy, which would have one root per interface (native, posix, vxworks etc.)

So, you could either graft your mqueue hierarchy directly under the registry root the way your patch does, or reshuffle the whole thing a bit in order to account for a new set of object families, like POSIX (incl. mqueues), rtdm and other namespaces for some drivers if you plan to export more objects in the future.

The point being that POSIX and RTDM for instance both implement semaphores and threads. So either living with /proc/registry/posix_sema4 _and_ /proc/registry/rtdm_sema4 is ok with you, otherwise you may go for keeping toplevel categories so as to have /proc/registry/posix/sema4 and /proc/registry/rtdm/sema4.

Signature · 1 line
Philippe.
#5 lore raw

Re: [RFC PATCH 1/4] cobalt/registry: Make the root directory for proc exports optional

Quoted 60 lines · Philippe Gerum
Quoted 39 lines · Florian
Quoted 29 lines · Philippe Gerum
Quoted 7 lines · Florian Bezdeka via Xenomai

Previously the root directory was mandatory, which means that exports to the proc file system were forced to be located in /proc/xenomai/registry/<root-dir>/<class>/<file>.

The <root-dir> virtual directory is now optional. If not supplied the root node of <class> is set to registry_vfroot, which represents /proc/xenomai/registry.

This is not needed. You may want to try something along these lines (excerpt from the Xenomai 2 implementation the registry originates from, with a few adaptations for readability, ksrc/skins/native/queue.c):

static DEFINE_XNPTREE(__queue_ptree, "native");

static struct xnpnode_snapshot __q_pnode = {
	.node = {
		.dirname = "queues",
		.root = &__queue_ptree,
		.ops = &xnregistry_vfsnap_ops,
	},
	.vfile = {
		.privsz = sizeof(struct vfile_priv),
		.datasz = sizeof(struct vfile_data),
		.ops = &vfile_ops,
	},
};
Quoted 8 lines

...

xnregistry_enter(q->name, q, &q->handle, &__q_pnode.node);

With this, you would get the /proc/xenomai/registry/queues root directory for queues created automatically, the way the registry wants it to be done.

Quoted 7 lines

I tried exactly that, but ended up all queues to be visible in /proc/xenomai/registry/native/queues/<name> which was not what I wanted to achieve.

But if you tell me that there must be an additional subdirectory, I'm fine with it...

DEFINE_XNPTREE(rtipc_ptree, "rtipc") already exists in the hierarchy, with protocols attached underneath. The current registry still exhibits some Xenomai 2 legacy, which would have one root per interface (native, posix, vxworks etc.)

So, you could either graft your mqueue hierarchy directly under the registry root the way your patch does, or reshuffle the whole thing a bit in order to account for a new set of object families, like POSIX (incl. mqueues), rtdm and other namespaces for some drivers if you plan to export more objects in the future.

Quoted 6 lines

The point being that POSIX and RTDM for instance both implement semaphores and threads. So either living with /proc/registry/posix_sema4 _and_ /proc/registry/rtdm_sema4 is ok with you, otherwise you may go for keeping toplevel categories so as to have /proc/registry/posix/sema4 and /proc/registry/rtdm/sema4.

Thanks a lot for the explanation. I wasn't aware that rtdm is providing it's own semaphores. That's no problem for the mqueues in patch 4, but as we still would need something similar for semaphores we would have some kind of collision.

So there is one single question open for me: What is the correct name for the "root" directory in this case. "posix"?

I will resend a v2 which should consist of less patches. At least patch 1 (the one we are discussing here) should vanish.

Thanks!

Florian

#6 lore raw

Re: [RFC PATCH 1/4] cobalt/registry: Make the root directory for proc exports optional

Quoted 68 lines · Florian (T RDA IOT SES-DE)
Quoted 60 lines · Philippe Gerum
Quoted 39 lines · Florian
Quoted 29 lines · Philippe Gerum
Quoted 7 lines · Florian Bezdeka via Xenomai

Previously the root directory was mandatory, which means that exports to the proc file system were forced to be located in /proc/xenomai/registry/<root-dir>/<class>/<file>.

The <root-dir> virtual directory is now optional. If not supplied the root node of <class> is set to registry_vfroot, which represents /proc/xenomai/registry.

This is not needed. You may want to try something along these lines (excerpt from the Xenomai 2 implementation the registry originates from, with a few adaptations for readability, ksrc/skins/native/queue.c):

static DEFINE_XNPTREE(__queue_ptree, "native");

static struct xnpnode_snapshot __q_pnode = {
.node = {
.dirname = "queues",
.root = &__queue_ptree,
.ops = &xnregistry_vfsnap_ops,
},
.vfile = {
.privsz = sizeof(struct vfile_priv),
.datasz = sizeof(struct vfile_data),
.ops = &vfile_ops,
},
};

Quoted 8 lines

...

xnregistry_enter(q->name, q, &q->handle, &__q_pnode.node);

With this, you would get the /proc/xenomai/registry/queues root directory for queues created automatically, the way the registry wants it to be done.

Quoted 7 lines

I tried exactly that, but ended up all queues to be visible in /proc/xenomai/registry/native/queues/<name> which was not what I wanted to achieve.

But if you tell me that there must be an additional subdirectory, I'm fine with it...

DEFINE_XNPTREE(rtipc_ptree, "rtipc") already exists in the hierarchy, with protocols attached underneath. The current registry still exhibits some Xenomai 2 legacy, which would have one root per interface (native, posix, vxworks etc.)

So, you could either graft your mqueue hierarchy directly under the registry root the way your patch does, or reshuffle the whole thing a bit in order to account for a new set of object families, like POSIX (incl. mqueues), rtdm and other namespaces for some drivers if you plan to export more objects in the future.

Quoted 6 lines

The point being that POSIX and RTDM for instance both implement semaphores and threads. So either living with /proc/registry/posix_sema4 _and_ /proc/registry/rtdm_sema4 is ok with you, otherwise you may go for keeping toplevel categories so as to have /proc/registry/posix/sema4 and /proc/registry/rtdm/sema4.

Quoted 4 lines

Thanks a lot for the explanation. I wasn't aware that rtdm is providing it's own semaphores. That's no problem for the mqueues in patch 4, but as we still would need something similar for semaphores we would have some kind of collision.

RTDM does have semaphores but those are not registered, specifically not by any name.

Jan

Quoted 11 lines

So there is one single question open for me: What is the correct name for the "root" directory in this case. "posix"?

I will resend a v2 which should consist of less patches. At least patch 1 (the one we are discussing here) should vanish.

Thanks!

Florian

Signature · 2 lines
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
#7 lore raw

Re: [RFC PATCH 1/4] cobalt/registry: Make the root directory for proc exports optional

Quoted 69 lines · Jan Kiszka
Quoted 68 lines · Florian (T RDA IOT SES-DE)
Quoted 66 lines · Philippe Gerum
Quoted 39 lines · Florian
Quoted 29 lines · Philippe Gerum
Quoted 7 lines · Florian Bezdeka via Xenomai

Previously the root directory was mandatory, which means that exports to the proc file system were forced to be located in /proc/xenomai/registry/<root-dir>/<class>/<file>.

The <root-dir> virtual directory is now optional. If not supplied the root node of <class> is set to registry_vfroot, which represents /proc/xenomai/registry.

This is not needed. You may want to try something along these lines (excerpt from the Xenomai 2 implementation the registry originates from, with a few adaptations for readability, ksrc/skins/native/queue.c):

static DEFINE_XNPTREE(__queue_ptree, "native");

static struct xnpnode_snapshot __q_pnode = {
.node = {
.dirname = "queues",
.root = &__queue_ptree,
.ops = &xnregistry_vfsnap_ops,
},
.vfile = {
.privsz = sizeof(struct vfile_priv),
.datasz = sizeof(struct vfile_data),
.ops = &vfile_ops,
},
};

Quoted 8 lines

...

xnregistry_enter(q->name, q, &q->handle, &__q_pnode.node);

With this, you would get the /proc/xenomai/registry/queues root directory for queues created automatically, the way the registry wants it to be done.

Quoted 7 lines

I tried exactly that, but ended up all queues to be visible in /proc/xenomai/registry/native/queues/<name> which was not what I wanted to achieve.

But if you tell me that there must be an additional subdirectory, I'm fine with it...

DEFINE_XNPTREE(rtipc_ptree, "rtipc") already exists in the hierarchy, with protocols attached underneath. The current registry still exhibits some Xenomai 2 legacy, which would have one root per interface (native, posix, vxworks etc.)

So, you could either graft your mqueue hierarchy directly under the registry root the way your patch does, or reshuffle the whole thing a bit in order to account for a new set of object families, like POSIX (incl. mqueues), rtdm and other namespaces for some drivers if you plan to export more objects in the future.

The point being that POSIX and RTDM for instance both implement semaphores and threads. So either living with /proc/registry/posix_sema4 _and_ /proc/registry/rtdm_sema4 is ok with you, otherwise you may go for keeping toplevel categories so as to have /proc/registry/posix/sema4 and /proc/registry/rtdm/sema4.

Quoted 7 lines
Quoted 4 lines

Thanks a lot for the explanation. I wasn't aware that rtdm is providing it's own semaphores. That's no problem for the mqueues in patch 4, but as we still would need something similar for semaphores we would have some kind of collision.

RTDM does have semaphores but those are not registered, specifically not by any name.

Exporting them and other resources might further help debugging as well. Adding a new interface for the user to provide a name should not be an issue if such export is deemed useful eventually.

Signature · 1 line
Philippe.
#8 lore raw

RFC PATCH 2/4 cobalt/registry: Share xnregistry_vfreg_ops with other compile units

In reply to Florian Bezdeka

Allows re-using xnregistry_vfreg_ops. All other file options were already available.

---
 include/cobalt/kernel/registry.h | 2 ++
 1 file changed, 2 insertions(+)
include/cobalt/kernel/registry.h +2 -0
index 624db5a78..a459da503 100644
@@ -195,6 +195,8 @@ extern struct xnpnode_ops xnregistry_vfsnap_ops;
 
 extern struct xnpnode_ops xnregistry_vlink_ops;
 
+extern struct xnpnode_ops xnregistry_vfreg_ops;
+
 /** @} */
 
 #endif /* !_COBALT_KERNEL_REGISTRY_H */
Signature · 1 line
2.30.2
#9 lore raw

RFC PATCH 3/4 cobalt/registry: Initialize refcnt of exported virtual proc files

In reply to Florian Bezdeka

The refcnt field was never initialized and triggered a BUG() in vfile_regular_release (vfile.c) when closing / releasing such a virtual file.

---
 kernel/cobalt/registry.c | 1 +
 1 file changed, 1 insertion(+)
kernel/cobalt/registry.c +1 -0
index 5cbebdc5b..476254e65 100644
@@ -403,6 +403,7 @@ static int registry_export_vfreg(struct xnobject *object,
 	object->vfile_u.vfreg.privsz = p->vfile.privsz;
 	object->vfile_u.vfreg.ops = p->vfile.ops;
 	object->vfile_u.vfreg.entry.lockops = p->vfile.lockops;
+	object->vfile_u.vfreg.entry.refcnt = 0;
 
 	ret = xnvfile_init_regular(object->key, &object->vfile_u.vfreg,
 				   &pnode->vdir);
Signature · 1 line
2.30.2
#10 lore raw

RFC PATCH 4/4 cobalt/mqueue: Export created mqueues to procfs

In reply to Florian Bezdeka

Exporting created mqueues to /proc/xenomai/registry/mqueue helps to identify resource leaks by making mqueues visible. The content of all created virtual files is empty. Removal of such files is not possible and reports "operation not supported".

---
 kernel/cobalt/posix/mqueue.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
kernel/cobalt/posix/mqueue.c +34 -1
index ebe7cf7b0..59d176491 100644
@@ -87,6 +87,38 @@ static struct mq_attr default_attr = {
 
 static LIST_HEAD(cobalt_mqq);
 
+#ifdef CONFIG_XENO_OPT_VFILE
+
+static int mq_vfile_show(struct xnvfile_regular_iterator *it, void *data)
+{
+	return 0;
+}
+
+static struct xnvfile_regular_ops mq_vfile_ops = {
+	.show = mq_vfile_show,
+};
+
+static struct xnpnode_regular __mq_pnode = {
+	.node = {
+		.dirname = "mqueue",
+		.root = NULL,
+		.ops = &xnregistry_vfreg_ops,
+	},
+	.vfile = {
+		.ops = &mq_vfile_ops,
+	},
+};
+
+#else /* !CONFIG_XENO_OPT_VFILE */
+
+static struct xnpnode_link __iddp_pnode = {
+	.node = {
+		.dirname = "mqueue",
+	},
+};
+
+#endif /* !CONFIG_XENO_OPT_VFILE */
+
 static inline struct cobalt_msg *mq_msg_alloc(struct cobalt_mq *mq)
 {
 	if (list_empty(&mq->avail))
@@ -352,7 +384,8 @@ static int mq_open(int uqd, const char *name, int oflags,
 		}
 
 		xnlock_get_irqsave(&nklock, s);
-		err = xnregistry_enter(mq->name, mq, &mq->handle, NULL);
+		err = xnregistry_enter(mq->name, mq, &mq->handle,
+				       &__mq_pnode.node);
 		if (err < 0)
 			--mq->refs;
 		else
Signature · 1 line
2.30.2
#11 lore raw
In reply to Florian Bezdeka
Quoted 21 lines · Florian Bezdeka

Hi,

this is another try to make registered mqueues visible. This time by exporting them to the procfs, namely to /proc/xenomai/registry/mqueue/<name>

Let me know what you think...

I had to rework the existing export machinery a bit to get rid of the so called "root" directory which is normally created. See patch descriptions for details.

Best regards,
Florian

Florian Bezdeka (4):
cobalt/registry: Make the root directory for proc exports optional cobalt/registry: Share xnregistry_vfreg_ops with other compile units cobalt/registry: Initialize refcnt of exported virtual proc files cobalt/mqueue: Export created mqueues to procfs

Quoted 5 lines
 include/cobalt/kernel/registry.h |  2 ++
 kernel/cobalt/posix/mqueue.c     | 35 +++++++++++++++++++++++++++++++-
 kernel/cobalt/registry.c         | 13 ++++++------
 3 files changed, 43 insertions(+), 7 deletions(-)

Will have a look.

We likely then also want the same for pshared semaphores, right? Anything else that could get a name (which may collide or become orphaned)?

Jan

Signature · 2 lines
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
#12 lore raw
Quoted 28 lines · Jan Kiszka
Quoted 21 lines · Florian Bezdeka

Hi,

this is another try to make registered mqueues visible. This time by exporting them to the procfs, namely to /proc/xenomai/registry/mqueue/<name>

Let me know what you think...

I had to rework the existing export machinery a bit to get rid of the so called "root" directory which is normally created. See patch descriptions for details.

Best regards,
Florian

Florian Bezdeka (4):
cobalt/registry: Make the root directory for proc exports optional cobalt/registry: Share xnregistry_vfreg_ops with other compile units cobalt/registry: Initialize refcnt of exported virtual proc files cobalt/mqueue: Export created mqueues to procfs

Quoted 5 lines
 include/cobalt/kernel/registry.h |  2 ++
 kernel/cobalt/posix/mqueue.c     | 35 +++++++++++++++++++++++++++++++-
 kernel/cobalt/registry.c         | 13 ++++++------
 3 files changed, 43 insertions(+), 7 deletions(-)
Quoted 4 lines

Will have a look.

We likely then also want the same for pshared semaphores, right? Anything else that could get a name (which may collide or become orphaned)?

Yes, to be complete we should do the same for shared semaphores.

The previously submitted "dump patch" handled all registered types (mqueue, semaphore, ...) the same way. But there was no type information available. The registry holds the keys only.

Quoted 3 lines

Jan