Skip to contentSkip to conversation

Don't generate netlink .rst files inside $(srctree)

PATCH Superseded Mauro Carvalho Chehab 4 participants 15 messages Jun 10, 2025 – Jun 12, 2025

Subsystems (6)

v1 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

cover Don't generate netlink .rst files inside $(srctree)

As discussed at:
https://lore.kernel.org/all/[email protected]/

changeset f061c9f7d058 ("Documentation: Document each netlink family") added a logic which generates *.rst files inside $(srctree). This is bad when O=<BUILDDIR> is used.

A recent change renamed the yaml files used by Netlink, revealing a bad side effect: as "make cleandocs" don't clean the produced files, symbols appear duplicated for people that don't build the kernel from scratch.

There are some possible solutions for that. The simplest one, which is what this series address, places the build files inside Documentation/output. The changes to do that are simple enough, but has one drawback, as it requires a (simple) template file for every netlink family file from netlink/specs. The template is simple enough:

.. kernel-include:: $BUILDDIR/networking/netlink_spec/<family>.rst

Part of the issue is that sphinx-build only produces html files for sources inside the source tree (Documentation/). Well, such requirement is already fulfilled, as we do have one *.yaml file per family inside Documentation/netlink, but those aren't currently processed by Sphinx, as Documentation/conf.py currently has only:

	source_suffix = ['.rst']

To address that, a long term solution is to add '.yaml' to source_suffix and add an extension at Documentation/sphinx that parses *.yaml files. Something similar to:

https://github.com/Jakski/sphinxcontrib-autoyaml

This could internally call ynl_gen_rst.py, but some care is needed, as the yaml extension is also used by devicetree.

Mauro Carvalho Chehab (4):
tools: ynl_gen_rst.py: create a top-level reference
docs: netlink: netlink-raw.rst: use :ref: instead of :doc:
docs: netlink: don't ignore generated rst files
docs: netlink: store generated .rst files at Documentation/output

 Documentation/Makefile                        |  8 +++----
 .../networking/netlink_spec/.gitignore        |  1 -
 .../networking/netlink_spec/conntrack.rst     |  3 +++
 .../networking/netlink_spec/devlink.rst       |  3 +++
 .../networking/netlink_spec/dpll.rst          |  3 +++
 .../networking/netlink_spec/ethtool.rst       |  3 +++
 Documentation/networking/netlink_spec/fou.rst |  3 +++
 .../networking/netlink_spec/handshake.rst     |  3 +++
 .../networking/netlink_spec/index.rst         |  6 +++++
 .../networking/netlink_spec/lockd.rst         |  3 +++
 .../networking/netlink_spec/mptcp_pm.rst      |  3 +++
 .../networking/netlink_spec/net_shaper.rst    |  3 +++
 .../networking/netlink_spec/netdev.rst        |  3 +++
 .../networking/netlink_spec/nfsd.rst          |  3 +++
 .../networking/netlink_spec/nftables.rst      |  3 +++
 .../networking/netlink_spec/nl80211.rst       |  3 +++
 .../networking/netlink_spec/nlctrl.rst        |  3 +++
 .../networking/netlink_spec/ovpn.rst          |  3 +++
 .../networking/netlink_spec/ovs_datapath.rst  |  3 +++
 .../networking/netlink_spec/ovs_flow.rst      |  3 +++
 .../networking/netlink_spec/ovs_vport.rst     |  3 +++
 .../networking/netlink_spec/readme.txt        |  4 ----
 .../networking/netlink_spec/rt-addr.rst       |  3 +++
 .../networking/netlink_spec/rt-link.rst       |  3 +++
 .../networking/netlink_spec/rt-neigh.rst      |  3 +++
 .../networking/netlink_spec/rt-route.rst      |  3 +++
 .../networking/netlink_spec/rt-rule.rst       |  3 +++
 Documentation/networking/netlink_spec/tc.rst  |  3 +++
 .../networking/netlink_spec/tcp_metrics.rst   |  3 +++
 .../networking/netlink_spec/team.rst          |  3 +++
 .../userspace-api/netlink/netlink-raw.rst     |  6 ++---
 tools/net/ynl/pyynl/ynl_gen_rst.py            | 24 ++++++++++++-------
 32 files changed, 107 insertions(+), 20 deletions(-)
 delete mode 100644 Documentation/networking/netlink_spec/.gitignore
 create mode 100644 Documentation/networking/netlink_spec/conntrack.rst
 create mode 100644 Documentation/networking/netlink_spec/devlink.rst
 create mode 100644 Documentation/networking/netlink_spec/dpll.rst
 create mode 100644 Documentation/networking/netlink_spec/ethtool.rst
 create mode 100644 Documentation/networking/netlink_spec/fou.rst
 create mode 100644 Documentation/networking/netlink_spec/handshake.rst
 create mode 100644 Documentation/networking/netlink_spec/index.rst
 create mode 100644 Documentation/networking/netlink_spec/lockd.rst
 create mode 100644 Documentation/networking/netlink_spec/mptcp_pm.rst
 create mode 100644 Documentation/networking/netlink_spec/net_shaper.rst
 create mode 100644 Documentation/networking/netlink_spec/netdev.rst
 create mode 100644 Documentation/networking/netlink_spec/nfsd.rst
 create mode 100644 Documentation/networking/netlink_spec/nftables.rst
 create mode 100644 Documentation/networking/netlink_spec/nl80211.rst
 create mode 100644 Documentation/networking/netlink_spec/nlctrl.rst
 create mode 100644 Documentation/networking/netlink_spec/ovpn.rst
 create mode 100644 Documentation/networking/netlink_spec/ovs_datapath.rst
 create mode 100644 Documentation/networking/netlink_spec/ovs_flow.rst
 create mode 100644 Documentation/networking/netlink_spec/ovs_vport.rst
 delete mode 100644 Documentation/networking/netlink_spec/readme.txt
 create mode 100644 Documentation/networking/netlink_spec/rt-addr.rst
 create mode 100644 Documentation/networking/netlink_spec/rt-link.rst
 create mode 100644 Documentation/networking/netlink_spec/rt-neigh.rst
 create mode 100644 Documentation/networking/netlink_spec/rt-route.rst
 create mode 100644 Documentation/networking/netlink_spec/rt-rule.rst
 create mode 100644 Documentation/networking/netlink_spec/tc.rst
 create mode 100644 Documentation/networking/netlink_spec/tcp_metrics.rst
 create mode 100644 Documentation/networking/netlink_spec/team.rst
Signature · 1 line
2.49.0
#1 lore raw

PATCH 1/4 tools: ynl_gen_rst.py: create a top-level reference

Currently, rt documents are referred with:

Documentation/userspace-api/netlink/netlink-raw.rst: :doc:rt-link<../../networking/netlink_spec/rt-link> Documentation/userspace-api/netlink/netlink-raw.rst: :doc:tc<../../networking/netlink_spec/tc> Documentation/userspace-api/netlink/netlink-raw.rst: :doc:tc<../../networking/netlink_spec/tc>

that's hard to maintain, and may break if we change the way rst files are generated from yaml. Better to use instead a reference for the netlink family.

So, add a netlink-<foo> reference to all generated docs.

---
 tools/net/ynl/pyynl/ynl_gen_rst.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/net/ynl/pyynl/ynl_gen_rst.py +3 -2
index 0cb6348e28d3..7bfb8ceeeefc 100755
@@ -314,10 +314,11 @@ def parse_yaml(obj: Dict[str, Any]) -> str:
 
     # Main header
 
-    lines.append(rst_header())
-
     family = obj['name']
 
+    lines.append(rst_header())
+    lines.append(rst_label("netlink-" + family))
+
     title = f"Family ``{family}`` netlink specification"
     lines.append(rst_title(title))
     lines.append(rst_paragraph(".. contents:: :depth: 3\n"))
Signature · 1 line
2.49.0
#2 lore raw

PATCH 2/4 docs: netlink: netlink-raw.rst: use :ref: instead of :doc:

In reply to Mauro Carvalho Chehab

Having :doc: references with relative paths doesn't always work, as it may have troubles when O= is used. So, replace them by Sphinx cross-reference tag that are now created by ynl_gen_rst.py.

---
 Documentation/userspace-api/netlink/netlink-raw.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Documentation/userspace-api/netlink/netlink-raw.rst +3 -3
index 31fc91020eb3..aae296c170c5 100644
@@ -62,8 +62,8 @@ Sub-messages
 ------------
 
 Several raw netlink families such as
-:doc:`rt-link<../../networking/netlink_spec/rt-link>` and
-:doc:`tc<../../networking/netlink_spec/tc>` use attribute nesting as an
+:ref:`rt-link<netlink-rt-link>` and
+:ref:`tc<netlink-tc>` use attribute nesting as an
 abstraction to carry module specific information.
 
 Conceptually it looks as follows::
@@ -162,7 +162,7 @@ then this is an error.
 Nested struct definitions
 -------------------------
 
-Many raw netlink families such as :doc:`tc<../../networking/netlink_spec/tc>`
+Many raw netlink families such as :ref:`tc<netlink-tc>`
 make use of nested struct definitions. The ``netlink-raw`` schema makes it
 possible to embed a struct within a struct definition using the ``struct``
 property. For example, the following struct definition embeds the
Signature · 1 line
2.49.0
#3 lore raw

PATCH 3/4 docs: netlink: don't ignore generated rst files

In reply to Mauro Carvalho Chehab

Currently, the build system generates ReST files inside the source directory. This is not a good idea, specially when we have renames, as make clean won't get rid of them.

As the first step to address the issue, stop ignoring those files. This way, we can see exactly what has been produced at build time inside $(srctree):

Documentation/networking/netlink_spec/conntrack.rst Documentation/networking/netlink_spec/devlink.rst Documentation/networking/netlink_spec/dpll.rst Documentation/networking/netlink_spec/ethtool.rst Documentation/networking/netlink_spec/fou.rst Documentation/networking/netlink_spec/handshake.rst Documentation/networking/netlink_spec/index.rst Documentation/networking/netlink_spec/lockd.rst Documentation/networking/netlink_spec/mptcp_pm.rst Documentation/networking/netlink_spec/net_shaper.rst Documentation/networking/netlink_spec/netdev.rst Documentation/networking/netlink_spec/nfsd.rst Documentation/networking/netlink_spec/nftables.rst Documentation/networking/netlink_spec/nl80211.rst Documentation/networking/netlink_spec/nlctrl.rst Documentation/networking/netlink_spec/ovs_datapath.rst Documentation/networking/netlink_spec/ovs_flow.rst Documentation/networking/netlink_spec/ovs_vport.rst Documentation/networking/netlink_spec/rt_addr.rst Documentation/networking/netlink_spec/rt_link.rst Documentation/networking/netlink_spec/rt_neigh.rst Documentation/networking/netlink_spec/rt_route.rst Documentation/networking/netlink_spec/rt_rule.rst Documentation/networking/netlink_spec/tc.rst Documentation/networking/netlink_spec/tcp_metrics.rst Documentation/networking/netlink_spec/team.rst

---
 Documentation/networking/netlink_spec/.gitignore | 1 -
 1 file changed, 1 deletion(-)
 delete mode 100644 Documentation/networking/netlink_spec/.gitignore
Documentation/networking/netlink_spec/.gitignore deleted +0 -1
deleted file mode 100644
index 30d85567b592..000000000000
@@ -1 +0,0 @@
-*.rst
Signature · 1 line
2.49.0
maintainer
#4 lore raw

Re: [PATCH 3/4] docs: netlink: don't ignore generated rst files

Quoted 3 lines · Mauro Carvalho Chehab

Currently, the build system generates ReST files inside the source directory. This is not a good idea, specially when we have renames, as make clean won't get rid of them.

You're right that it's not a great idea, but it's the least bad option with sphinx because it only supports 1 source dir. It doesn't have the concept of a generated-sources dir and the alternative is to pollute the output dir. See e.g. https://docs.kernel.org/media.h.rst

Quoted 44 lines

As the first step to address the issue, stop ignoring those files. This way, we can see exactly what has been produced at build time inside $(srctree):

Documentation/networking/netlink_spec/conntrack.rst Documentation/networking/netlink_spec/devlink.rst Documentation/networking/netlink_spec/dpll.rst Documentation/networking/netlink_spec/ethtool.rst Documentation/networking/netlink_spec/fou.rst Documentation/networking/netlink_spec/handshake.rst Documentation/networking/netlink_spec/index.rst Documentation/networking/netlink_spec/lockd.rst Documentation/networking/netlink_spec/mptcp_pm.rst Documentation/networking/netlink_spec/net_shaper.rst Documentation/networking/netlink_spec/netdev.rst Documentation/networking/netlink_spec/nfsd.rst Documentation/networking/netlink_spec/nftables.rst Documentation/networking/netlink_spec/nl80211.rst Documentation/networking/netlink_spec/nlctrl.rst Documentation/networking/netlink_spec/ovs_datapath.rst Documentation/networking/netlink_spec/ovs_flow.rst Documentation/networking/netlink_spec/ovs_vport.rst Documentation/networking/netlink_spec/rt_addr.rst Documentation/networking/netlink_spec/rt_link.rst Documentation/networking/netlink_spec/rt_neigh.rst Documentation/networking/netlink_spec/rt_route.rst Documentation/networking/netlink_spec/rt_rule.rst Documentation/networking/netlink_spec/tc.rst Documentation/networking/netlink_spec/tcp_metrics.rst Documentation/networking/netlink_spec/team.rst

---
 Documentation/networking/netlink_spec/.gitignore | 1 -
 1 file changed, 1 deletion(-)
 delete mode 100644 Documentation/networking/netlink_spec/.gitignore
Documentation/networking/netlink_spec/.gitignore deleted +0 -1
deleted file mode 100644
index 30d85567b592..000000000000
@@ -1 +0,0 @@
-*.rst
#5 lore raw

PATCH 4/4 docs: netlink: store generated .rst files at Documentation/output

In reply to Mauro Carvalho Chehab

It is not a good practice to store build-generated files inside $(srctree), as one may be using O=<BUILDDIR> and even have the Kernel on a read-only directory.

Change the YAML generation for netlink files to be inside the documentation output directory.

This solution is not perfect, though, as sphinx-build only produces html files only for files inside the source tree. As it is desired to have one netlink file per family, it means that one template file is required for every file inside Documentation/netlink/specs. Such template files are simple enough. All they need is:

# Template for Documentation/netlink/specs/<foo>.yaml .. kernel-include:: $BUILDDIR/networking/netlink_spec/<foo>.rst

A better long term solution is to have an extension at Documentation/sphinx that parses *.yaml files for netlink files, which could internally be calling ynl_gen_rst.py. Yet, some care needs to be taken, as yaml extensions are also used inside device tree.

---
 Documentation/Makefile                        |  8 ++++----
 .../networking/netlink_spec/conntrack.rst     |  3 +++
 .../networking/netlink_spec/devlink.rst       |  3 +++
 .../networking/netlink_spec/dpll.rst          |  3 +++
 .../networking/netlink_spec/ethtool.rst       |  3 +++
 Documentation/networking/netlink_spec/fou.rst |  3 +++
 .../networking/netlink_spec/handshake.rst     |  3 +++
 .../networking/netlink_spec/index.rst         |  6 ++++++
 .../networking/netlink_spec/lockd.rst         |  3 +++
 .../networking/netlink_spec/mptcp_pm.rst      |  3 +++
 .../networking/netlink_spec/net_shaper.rst    |  3 +++
 .../networking/netlink_spec/netdev.rst        |  3 +++
 .../networking/netlink_spec/nfsd.rst          |  3 +++
 .../networking/netlink_spec/nftables.rst      |  3 +++
 .../networking/netlink_spec/nl80211.rst       |  3 +++
 .../networking/netlink_spec/nlctrl.rst        |  3 +++
 .../networking/netlink_spec/ovpn.rst          |  3 +++
 .../networking/netlink_spec/ovs_datapath.rst  |  3 +++
 .../networking/netlink_spec/ovs_flow.rst      |  3 +++
 .../networking/netlink_spec/ovs_vport.rst     |  3 +++
 .../networking/netlink_spec/readme.txt        |  4 ----
 .../networking/netlink_spec/rt-addr.rst       |  3 +++
 .../networking/netlink_spec/rt-link.rst       |  3 +++
 .../networking/netlink_spec/rt-neigh.rst      |  3 +++
 .../networking/netlink_spec/rt-route.rst      |  3 +++
 .../networking/netlink_spec/rt-rule.rst       |  3 +++
 Documentation/networking/netlink_spec/tc.rst  |  3 +++
 .../networking/netlink_spec/tcp_metrics.rst   |  3 +++
 .../networking/netlink_spec/team.rst          |  3 +++
 tools/net/ynl/pyynl/ynl_gen_rst.py            | 19 +++++++++++++------
 30 files changed, 101 insertions(+), 14 deletions(-)
 create mode 100644 Documentation/networking/netlink_spec/conntrack.rst
 create mode 100644 Documentation/networking/netlink_spec/devlink.rst
 create mode 100644 Documentation/networking/netlink_spec/dpll.rst
 create mode 100644 Documentation/networking/netlink_spec/ethtool.rst
 create mode 100644 Documentation/networking/netlink_spec/fou.rst
 create mode 100644 Documentation/networking/netlink_spec/handshake.rst
 create mode 100644 Documentation/networking/netlink_spec/index.rst
 create mode 100644 Documentation/networking/netlink_spec/lockd.rst
 create mode 100644 Documentation/networking/netlink_spec/mptcp_pm.rst
 create mode 100644 Documentation/networking/netlink_spec/net_shaper.rst
 create mode 100644 Documentation/networking/netlink_spec/netdev.rst
 create mode 100644 Documentation/networking/netlink_spec/nfsd.rst
 create mode 100644 Documentation/networking/netlink_spec/nftables.rst
 create mode 100644 Documentation/networking/netlink_spec/nl80211.rst
 create mode 100644 Documentation/networking/netlink_spec/nlctrl.rst
 create mode 100644 Documentation/networking/netlink_spec/ovpn.rst
 create mode 100644 Documentation/networking/netlink_spec/ovs_datapath.rst
 create mode 100644 Documentation/networking/netlink_spec/ovs_flow.rst
 create mode 100644 Documentation/networking/netlink_spec/ovs_vport.rst
 delete mode 100644 Documentation/networking/netlink_spec/readme.txt
 create mode 100644 Documentation/networking/netlink_spec/rt-addr.rst
 create mode 100644 Documentation/networking/netlink_spec/rt-link.rst
 create mode 100644 Documentation/networking/netlink_spec/rt-neigh.rst
 create mode 100644 Documentation/networking/netlink_spec/rt-route.rst
 create mode 100644 Documentation/networking/netlink_spec/rt-rule.rst
 create mode 100644 Documentation/networking/netlink_spec/tc.rst
 create mode 100644 Documentation/networking/netlink_spec/tcp_metrics.rst
 create mode 100644 Documentation/networking/netlink_spec/team.rst
Documentation/Makefile +4 -4
index d30d66ddf1ad..2383825dba49 100644
@@ -102,8 +102,8 @@ quiet_cmd_sphinx = SPHINX  $@ --> file://$(abspath $(BUILDDIR)/$3/$4)
 		cp $(if $(patsubst /%,,$(DOCS_CSS)),$(abspath $(srctree)/$(DOCS_CSS)),$(DOCS_CSS)) $(BUILDDIR)/$3/_static/; \
 	fi
 
-YNL_INDEX:=$(srctree)/Documentation/networking/netlink_spec/index.rst
-YNL_RST_DIR:=$(srctree)/Documentation/networking/netlink_spec
+YNL_INDEX:=$(BUILDDIR)/networking/netlink_spec/netlink_index.rst
+YNL_RST_DIR:=$(BUILDDIR)/networking/netlink_spec/
 YNL_YAML_DIR:=$(srctree)/Documentation/netlink/specs
 YNL_TOOL:=$(srctree)/tools/net/ynl/pyynl/ynl_gen_rst.py
 
@@ -111,12 +111,12 @@ YNL_RST_FILES_TMP := $(patsubst %.yaml,%.rst,$(wildcard $(YNL_YAML_DIR)/*.yaml))
 YNL_RST_FILES := $(patsubst $(YNL_YAML_DIR)%,$(YNL_RST_DIR)%, $(YNL_RST_FILES_TMP))
 
 $(YNL_INDEX): $(YNL_RST_FILES)
-	$(Q)$(YNL_TOOL) -o $@ -x
+	$(Q)$(YNL_TOOL) -o $@ -d $(YNL_YAML_DIR) -x
 
 $(YNL_RST_DIR)/%.rst: $(YNL_YAML_DIR)/%.yaml $(YNL_TOOL)
 	$(Q)$(YNL_TOOL) -i $< -o $@
 
-htmldocs texinfodocs latexdocs epubdocs xmldocs: $(YNL_INDEX)
+htmldocs texinfodocs latexdocs epubdocs xmldocs: $(YNL_INDEX) $(YNL_RST_FILES)
 
 htmldocs:
 	@$(srctree)/scripts/sphinx-pre-install --version-check
Documentation/networking/netlink_spec/conntrack.rst new file +3 -0
new file mode 100644
index 000000000000..6fc6af1e6de4
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/conntrack.rst
Documentation/networking/netlink_spec/devlink.rst new file +3 -0
new file mode 100644
index 000000000000..412295d396c1
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/devlink.rst
Documentation/networking/netlink_spec/dpll.rst new file +3 -0
new file mode 100644
index 000000000000..913e1d9ef744
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/dpll.rst
Documentation/networking/netlink_spec/ethtool.rst new file +3 -0
new file mode 100644
index 000000000000..42136a8572b9
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/ethtool.rst
Documentation/networking/netlink_spec/fou.rst new file +3 -0
new file mode 100644
index 000000000000..103528337d46
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/fou.rst
Documentation/networking/netlink_spec/handshake.rst new file +3 -0
new file mode 100644
index 000000000000..600abec80431
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/handshake.rst
Documentation/networking/netlink_spec/index.rst new file +6 -0
new file mode 100644
index 000000000000..8a07a77f2e8b
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+
+# Netlink documentation is populated during the build of the documentation
+# (htmldocs) by the tools/net/ynl/pyynl/ynl_gen_rst.py script.
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/netlink_index.rst
Documentation/networking/netlink_spec/lockd.rst new file +3 -0
new file mode 100644
index 000000000000..6374dc2a982c
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/lockd.rst
Documentation/networking/netlink_spec/mptcp_pm.rst new file +3 -0
new file mode 100644
index 000000000000..8923db35603e
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/mptcp_pm.rst
Documentation/networking/netlink_spec/net_shaper.rst new file +3 -0
new file mode 100644
index 000000000000..82d9300f1c0c
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/net_shaper.rst
Documentation/networking/netlink_spec/netdev.rst new file +3 -0
new file mode 100644
index 000000000000..c379a79c5f23
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/netdev.rst
Documentation/networking/netlink_spec/nfsd.rst new file +3 -0
new file mode 100644
index 000000000000..40716f4a3fa8
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/nfsd.rst
Documentation/networking/netlink_spec/nftables.rst new file +3 -0
new file mode 100644
index 000000000000..1dc6d7c5ca58
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/nftables.rst
Documentation/networking/netlink_spec/nl80211.rst new file +3 -0
new file mode 100644
index 000000000000..c056418f7068
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/nl80211.rst
Documentation/networking/netlink_spec/nlctrl.rst new file +3 -0
new file mode 100644
index 000000000000..7fe48f26718e
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/nlctrl.rst
Documentation/networking/netlink_spec/ovpn.rst new file +3 -0
new file mode 100644
index 000000000000..c146b803d742
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/ovpn.rst
Documentation/networking/netlink_spec/ovs_datapath.rst new file +3 -0
new file mode 100644
index 000000000000..0b1242f2cc9c
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/ovs_datapath.rst
Documentation/networking/netlink_spec/ovs_flow.rst new file +3 -0
new file mode 100644
index 000000000000..c1019ab06aff
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/ovs_flow.rst
Documentation/networking/netlink_spec/ovs_vport.rst new file +3 -0
new file mode 100644
index 000000000000..13eb53ff4c75
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/ovs_vport.rst
Documentation/networking/netlink_spec/readme.txt deleted +0 -4
deleted file mode 100644
index 030b44aca4e6..000000000000
@@ -1,4 +0,0 @@
-SPDX-License-Identifier: GPL-2.0
-
-This file is populated during the build of the documentation (htmldocs) by the
-tools/net/ynl/pyynl/ynl_gen_rst.py script.
Documentation/networking/netlink_spec/rt-addr.rst new file +3 -0
new file mode 100644
index 000000000000..2739e81b7a04
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/rt-addr.rst
Documentation/networking/netlink_spec/rt-link.rst new file +3 -0
new file mode 100644
index 000000000000..d4df7268d07c
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/rt-link.rst
Documentation/networking/netlink_spec/rt-neigh.rst new file +3 -0
new file mode 100644
index 000000000000..6c8b62d7b2ff
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/rt-neigh.rst
Documentation/networking/netlink_spec/rt-route.rst new file +3 -0
new file mode 100644
index 000000000000..a629d14bf405
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/rt-route.rst
Documentation/networking/netlink_spec/rt-rule.rst new file +3 -0
new file mode 100644
index 000000000000..e4a991b1bacd
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/rt-rule.rst
Documentation/networking/netlink_spec/tc.rst new file +3 -0
new file mode 100644
index 000000000000..1e78d3caeb5d
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/tc.rst
Documentation/networking/netlink_spec/tcp_metrics.rst new file +3 -0
new file mode 100644
index 000000000000..ea43bd6f6925
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/tcp_metrics.rst
Documentation/networking/netlink_spec/team.rst new file +3 -0
new file mode 100644
index 000000000000..45a3f4d3ed80
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/team.rst
tools/net/ynl/pyynl/ynl_gen_rst.py +13 -6
index 7bfb8ceeeefc..70417a9a8e96 100755
@@ -365,6 +365,7 @@ def parse_arguments() -> argparse.Namespace:
 
     parser.add_argument("-v", "--verbose", action="store_true")
     parser.add_argument("-o", "--output", help="Output file name")
+    parser.add_argument("-d", "--input_dir", help="YAML input directory")
 
     # Index and input are mutually exclusive
     group = parser.add_mutually_exclusive_group()
@@ -405,11 +406,14 @@ def write_to_rstfile(content: str, filename: str) -> None:
     """Write the generated content into an RST file"""
     logging.debug("Saving RST file to %s", filename)
 
+    dir = os.path.dirname(filename)
+    os.makedirs(dir, exist_ok=True)
+
     with open(filename, "w", encoding="utf-8") as rst_file:
         rst_file.write(content)
 
 
-def generate_main_index_rst(output: str) -> None:
+def generate_main_index_rst(output: str, index_dir: str, ) -> None:
     """Generate the `networking_spec/index` content and write to the file"""
     lines = []
 
@@ -418,12 +422,15 @@ def generate_main_index_rst(output: str) -> None:
     lines.append(rst_title("Netlink Family Specifications"))
     lines.append(rst_toctree(1))
 
-    index_dir = os.path.dirname(output)
-    logging.debug("Looking for .rst files in %s", index_dir)
+    index_fname = os.path.basename(output)
+    if not index_dir:
+        index_dir = os.path.dirname(output)
+
+    logging.debug("Looking for .yaml files in %s", index_dir)
     for filename in sorted(os.listdir(index_dir)):
-        if not filename.endswith(".rst") or filename == "index.rst":
+        if not filename.endswith(".yaml") or filename == index_fname:
             continue
-        lines.append(f"   {filename.replace('.rst', '')}\n")
+        lines.append(f"   {filename.replace('.yaml', '')}\n")
 
     logging.debug("Writing an index file at %s", output)
     write_to_rstfile("".join(lines), output)
@@ -447,7 +454,7 @@ def main() -> None:
 
     if args.index:
         # Generate the index RST file
-        generate_main_index_rst(args.output)
+        generate_main_index_rst(args.output, args.input_dir)
 
 
 if __name__ == "__main__":
Signature · 1 line
2.49.0
#6 lore raw

Re: [PATCH 4/4] docs: netlink: store generated .rst files at Documentation/output

Hello Mauro,

Quoted 5 lines · Mauro Carvalho Chehab

A better long term solution is to have an extension at Documentation/sphinx that parses *.yaml files for netlink files, which could internally be calling ynl_gen_rst.py. Yet, some care needs to be taken, as yaml extensions are also used inside device tree.

In fact, This is very similar to what I did initially in v1. And I was creating a sphinx extension to handle the generation, have a look here:

https://lore.kernel.org/all/[email protected]/

During the review, we agree to move out of the sphinx extension. the reasons are the stubs/templates that needs to be created and you are creating here.

So, if we decide to come back to sphinx extension, we can leverage that code from v1 ?!

tools/net/ynl/pyynl/ynl_gen_rst.py def write_to_rstfile(content: str, filename: str) -> None: · line 416

Quoted 2 lines
tools/net/ynl/pyynl/ynl_gen_rst.py +1 -1
-def generate_main_index_rst(output: str) -> None:
+def generate_main_index_rst(output: str, index_dir: str, ) -> None:

You probably don't need the last , before ).

Other than that, LGTM.

The question is, are we OK with the templates that need to be created for netlink specs?!

Thanks for looking at it,
--breno

#7 lore raw

Re: [PATCH 4/4] docs: netlink: store generated .rst files at Documentation/output

Hi Breno,

Em Tue, 10 Jun 2025 08:43:55 -0700
Breno Leitao <[email protected]> escreveu:

Quoted 9 lines

Hello Mauro,

Quoted 5 lines · Mauro Carvalho Chehab

A better long term solution is to have an extension at Documentation/sphinx that parses *.yaml files for netlink files, which could internally be calling ynl_gen_rst.py. Yet, some care needs to be taken, as yaml extensions are also used inside device tree.

Quoted 4 lines

In fact, This is very similar to what I did initially in v1. And I was creating a sphinx extension to handle the generation, have a look here:

https://lore.kernel.org/all/[email protected]/

Heh, I liked that ;-)

Still, I would try to make the template there just a single line, e.g. instead of:

	--- /dev/null
	+++ b/Documentation/networking/netlink_spec/devlink.rst
	@@ -0,0 +1,9 @@
	+.. SPDX-License-Identifier: GPL-2.0
	+
	+========================================
	+Family ``devlink`` netlink specification
	+========================================
	+
	+.. contents::
	+
	+.. netlink-spec:: devlink.yaml

I would just add:

.. netlink-spec:: devlink.yaml

-

With regards to the code itself, IMHO the best would be to place the yaml conversion code inside a python library (just like we did with scripts/lib/kdoc) and keep having a command line program to call it, as it is easier to test/debug parser issues via command line.

Quoted 6 lines

During the review, we agree to move out of the sphinx extension. the reasons are the stubs/templates that needs to be created and you are creating here.

So, if we decide to come back to sphinx extension, we can leverage that code from v1 ?!

For me, that's fine. Still, I wonder if are there a way to avoid creating a template for every yaml, while still using a Sphinx extension.

As there is an 1:1 mapping between .yaml files and output files, perhaps there's a way to teach Sphinx to do the right thing, creating one html per file. If so, ideally, the best would be to have an index.rst file similar to this:

	.. SPDX-License-Identifier: GPL-2.0

	======================
	Netlink Specifications
	======================

	.. netlink-specs:: netlink/specs

which would teach the Sphinx extension to look for *.yaml files inside Documentation/netlink/specs, parsing them, creating one html per file and create a TOC here. As there are some Sphinx extensions that handle non-ReST formats, maybe this or something similar to it could be possible.

Quoted 5 lines

tools/net/ynl/pyynl/ynl_gen_rst.py def write_to_rstfile(content: str, filename: str) -> None: · line 416

Quoted 3 lines
tools/net/ynl/pyynl/ynl_gen_rst.py +1 -1
-def generate_main_index_rst(output: str) -> None:
+def generate_main_index_rst(output: str, index_dir: str, ) -> None:  

You probably don't need the last , before ).

Sure.

Quoted 5 lines

Other than that, LGTM.

The question is, are we OK with the templates that need to be created for netlink specs?!

If there's no other way, one might have a tool for maintainers to use to update templates, but yeah, having one template per each yaml is not ideal. I think we need to investigate it better and seek for some alternatives to avoid it.

Thanks,
Mauro

maintainer
#8 lore raw

Re: [PATCH 4/4] docs: netlink: store generated .rst files at Documentation/output

Quoted 7 lines · On Tue, 10 Jun 2025 22:59:11 +0200 Mauro Carvalho Chehab wrote:
Quoted 2 lines

The question is, are we OK with the templates that need to be created for netlink specs?!

If there's no other way, one might have a tool for maintainers to use to update templates, but yeah, having one template per each yaml is not ideal. I think we need to investigate it better and seek for some alternatives to avoid it.

FWIW we have tools/net/ynl/ynl-regen.sh, it regenerates the C code we have committed in the tree (uAPI headers mostly).
We could add it there. Which is not to distract from your main point that not having the templates would be ideal.

#9 lore raw

Re: [PATCH 4/4] docs: netlink: store generated .rst files at Documentation/output

Em Tue, 10 Jun 2025 14:07:24 -0700
Jakub Kicinski <[email protected]> escreveu:

Quoted 9 lines · On Tue, 10 Jun 2025 22:59:11 +0200 Mauro Carvalho Chehab wrote:
Quoted 7 lines
Quoted 2 lines

The question is, are we OK with the templates that need to be created for netlink specs?!

If there's no other way, one might have a tool for maintainers to use to update templates, but yeah, having one template per each yaml is not ideal. I think we need to investigate it better and seek for some alternatives to avoid it.

Quoted 4 lines

FWIW we have tools/net/ynl/ynl-regen.sh, it regenerates the C code we have committed in the tree (uAPI headers mostly).
We could add it there. Which is not to distract from your main point that not having the templates would be ideal.

With the new Sphinx extension for netlink specs I posted:

	https://lore.kernel.org/linux-doc/[email protected]/T/#t
	https://lore.kernel.org/linux-doc/20250612142438.MED5SEN3C-3RDQI5I1ELC-u8QJEjH8W4vUQRBdyK1tI@z/T/#t

There's no need for a template for each file, although it does require updating Documentation/netlink/specs/index.rst. There are a couple of reasons:

1. on my tests, I got some errors auto-generating it while using:
make SPHINXDIRS="networking netlink" htmldocs

2. a dynamically-generated file will cause a extra warnings at the userspace files that contain the name of the netlink spec index.html. Basically, kernel build runs a script which validates that all files under Documentation/ actually exist

3. adding/renaming files typically require changing MAINTAINERS and/or Makefiles. Updating index.rst accordingly is already expected for documentation.

In any case, as I didn't drop the existing script, you could add a call inside tools/net/ynl/ynl-regen.sh to:

tools/net/ynl/pyynl/ynl_gen_rst.py -x -v -o Documentation/netlink/specs/index.rst

To ensure that nobody would forget updating it.

Regards,
Mauro

#10 lore raw

Re: [PATCH 4/4] docs: netlink: store generated .rst files at Documentation/output

In reply to Breno Leitao

Em Tue, 10 Jun 2025 08:43:55 -0700
Breno Leitao <[email protected]> escreveu:

Quoted 26 lines

Hello Mauro,

Quoted 5 lines · Mauro Carvalho Chehab

A better long term solution is to have an extension at Documentation/sphinx that parses *.yaml files for netlink files, which could internally be calling ynl_gen_rst.py. Yet, some care needs to be taken, as yaml extensions are also used inside device tree.

In fact, This is very similar to what I did initially in v1. And I was creating a sphinx extension to handle the generation, have a look here:

https://lore.kernel.org/all/[email protected]/

During the review, we agree to move out of the sphinx extension. the reasons are the stubs/templates that needs to be created and you are creating here.

So, if we decide to come back to sphinx extension, we can leverage that code from v1 ?!

Review

Quoted 2 lines
(quoted diff) +1 -1
-def generate_main_index_rst(output: str) -> None:
+def generate_main_index_rst(output: str, index_dir: str, ) -> None:  

You probably don't need the last , before ).

Quoted 7 lines

Other than that, LGTM.

The question is, are we OK with the templates that need to be created for netlink specs?!

Thanks for looking at it,
--breno

Hi Breno,

I did here a test creating a completely new repository using sphinx-quickstart, adding yaml to conf.py with:

	source_suffix = ['.rst', '.yaml']

There, I imported your v1 patch from:

	https://lore.kernel.org/all/[email protected]/

While your extension seems to require some work, as it has issues processing the current patch, it *is* creating one html file per each yaml, without needing any template. All it is needed there is to place an yaml file somewhere under source/ directory:

source/

├── conf.py
├── index.rst
├── specs
│   ├── conntrack.yaml
│   ├── devlink.yaml
│   ├── dpll.yaml
│   ├── ethtool.yaml
│   ├── fou.yaml
│   ├── handshake.yaml
│   ├── index.rst
│   ├── lockd.yaml
│   ├── mptcp_pm.yaml
│   ├── netdev.yaml
│   ├── net_shaper.yaml
│   ├── nfsd.yaml
│   ├── nftables.yaml
│   ├── nl80211.yaml
│   ├── nlctrl.yaml
│   ├── ovs_datapath.yaml
│   ├── ovs_flow.yaml
│   ├── ovs_vport.yaml
│   ├── rt_addr.yaml
│   ├── rt_link.yaml
│   ├── rt_neigh.yaml
│   ├── rt_route.yaml
│   ├── rt_rule.yaml
│   ├── tcp_metrics.yaml
│   ├── tc.yaml
│   └── team.yaml
├── _static
└── _templates

make html produces:

build/

├── doctrees
│   ├── environment.pickle
│   ├── index.doctree
│   └── specs
│       ├── conntrack.doctree
│       ├── devlink.doctree
│       ├── dpll.doctree
│       ├── ethtool.doctree
│       ├── fou.doctree
│       ├── handshake.doctree
│       ├── index.doctree
│       ├── lockd.doctree
│       ├── mptcp_pm.doctree
│       ├── netdev.doctree
│       ├── net_shaper.doctree
│       ├── nfsd.doctree
│       ├── nftables.doctree
│       ├── nl80211.doctree
│       ├── nlctrl.doctree
│       ├── ovs_datapath.doctree
│       ├── ovs_flow.doctree
│       ├── ovs_vport.doctree
│       ├── rt_addr.doctree
│       ├── rt_link.doctree
│       ├── rt_neigh.doctree
│       ├── rt_route.doctree
│       ├── rt_rule.doctree
│       ├── tc.doctree
│       ├── tcp_metrics.doctree
│       └── team.doctree
└── html
    ├── genindex.html
    ├── index.html
    ├── objects.inv
    ├── search.html
    ├── searchindex.js
    ├── _sources
    │   ├── index.rst.txt
    │   └── specs
    │       ├── conntrack.yaml.txt
    │       ├── devlink.yaml.txt
    │       ├── dpll.yaml.txt
    │       ├── ethtool.yaml.txt
    │       ├── fou.yaml.txt
    │       ├── handshake.yaml.txt
    │       ├── index.rst.txt
    │       ├── lockd.yaml.txt
    │       ├── mptcp_pm.yaml.txt
    │       ├── netdev.yaml.txt
    │       ├── net_shaper.yaml.txt
    │       ├── nfsd.yaml.txt
    │       ├── nftables.yaml.txt
    │       ├── nl80211.yaml.txt
    │       ├── nlctrl.yaml.txt
    │       ├── ovs_datapath.yaml.txt
    │       ├── ovs_flow.yaml.txt
    │       ├── ovs_vport.yaml.txt
    │       ├── rt_addr.yaml.txt
    │       ├── rt_link.yaml.txt
    │       ├── rt_neigh.yaml.txt
    │       ├── rt_route.yaml.txt
    │       ├── rt_rule.yaml.txt
    │       ├── tcp_metrics.yaml.txt
    │       ├── tc.yaml.txt
    │       └── team.yaml.txt
    ├── specs
    │   ├── conntrack.html
    │   ├── devlink.html
    │   ├── dpll.html
    │   ├── ethtool.html
    │   ├── fou.html
    │   ├── handshake.html
    │   ├── index.html
    │   ├── lockd.html
    │   ├── mptcp_pm.html
    │   ├── netdev.html
    │   ├── net_shaper.html
    │   ├── nfsd.html
    │   ├── nftables.html
    │   ├── nl80211.html
    │   ├── nlctrl.html
    │   ├── ovs_datapath.html
    │   ├── ovs_flow.html
    │   ├── ovs_vport.html
    │   ├── rt_addr.html
    │   ├── rt_link.html
    │   ├── rt_neigh.html
    │   ├── rt_route.html
    │   ├── rt_rule.html
    │   ├── tc.html
    │   ├── tcp_metrics.html
    │   └── team.html
    └── _static
        ├── alabaster.css
        ├── basic.css
        ├── custom.css
        ├── doctools.js
        ├── documentation_options.js
        ├── file.png
        ├── language_data.js
        ├── minus.png
        ├── plus.png
        ├── pygments.css
        ├── searchtools.js
        └── sphinx_highlight.js

There are several warnings at the build, but that's likely because you may need to do changes at the Sphinx extension to align with the current version of ynl_gen_rst.py.

Please notice that I found a bug on kerneldoc due to the way it was splitting lines. The correct way to do it is to use Sphinx statemachine, e.g.:

lines = statemachine.string2lines(out, self.tab_width,
convert_whitespace=True)
result = ViewList()

for line, lineoffset in enum(lines):
doc = str(env.srcdir) + "/" + env.docname + ":" + str(self.lineno) result.append(line, doc + ": " + filename, lineoffset)

Perhaps some of the errors/warnings there are due to that.

You will likely need to add an index.yaml file to Documentation/netlink (which could be empty), as Sphinx requires an 1:1 mapping between source and output files, but everything can be generated automatically.

The only extra logic you might need at the extension would be to ignore yaml files under doctree. Even this may not require code changes, as conf.py has "exclude_patterns" variable that could be used for such purpose.

The vast majority of the code outside the Kernel tree were automatically generated by sphinx-quickstart. All changes I did are under GPL v2.

Regards,
Mauro

---

commit e37c713f3c8236c3e28d392c835c2c94c24c88aa

Author: Mauro Carvalho Chehab <[email protected]>
Date:   Tue Jun 10 23:08:05 2025 +0200

Initial version of a test repository generated by sphinx-quickstart

The original script at extensions/netlink_spec.py was written by Breno Leitão, and comes from:

	https://lore.kernel.org/all/[email protected]/

The contents under source/specs came from linux-docs git tree.

Signed-off-by Mauro Carvalho Chehab <mchehab+huawei.com>
.gitignore new file +2 -0
new file mode 100644
index 000000000000..8025bc04008c
@@ -0,0 +1,2 @@
+__pycache__
+*~
Makefile new file +20 -0
new file mode 100644
index 000000000000..d0c3cbf1020d
@@ -0,0 +1,20 @@
+# Minimal makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line, and also
+# from the environment for the first two.
+SPHINXOPTS    ?=
+SPHINXBUILD   ?= sphinx-build
+SOURCEDIR     = source
+BUILDDIR      = build
+
+# Put it first so that "make" without argument is like "make help".
+help:
+	@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
+
+.PHONY: help Makefile
+
+# Catch-all target: route all unknown targets to Sphinx using the new
+# "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).
+%: Makefile
+	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
extensions/netlink_spec.py new file +283 -0

283 lines not on this page · raw message

source/conf.py new file +37 -0
new file mode 100644
index 000000000000..d68b56368335
@@ -0,0 +1,37 @@
+# Configuration file for the Sphinx documentation builder.
+#
+# For the full list of built-in configuration values, see the documentation:
+# https://www.sphinx-doc.org/en/master/usage/configuration.html
+
+# -- Project information -----------------------------------------------------
+# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
+
+import os
+import sys
+
+project = 'gen_html'
+copyright = '2025, Mauro Carvalho Chehab'
+author = 'Mauro Carvalho Chehab'
+
+# -- General configuration ---------------------------------------------------
+# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
+
+sys.path.insert(0, os.path.abspath("../extensions"))
+
+extensions = [
+#    "write_pages",
+    "netlink_spec",
+]
+
+templates_path = ['_templates']
+exclude_patterns = []
+
+
+# File extensions to process
+source_suffix = ['.rst', '.yaml']
+
+# -- Options for HTML output -------------------------------------------------
+# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
+
+html_theme = 'alabaster'
+html_static_path = ['_static']
source/index.rst new file +8 -0
new file mode 100644
index 000000000000..bbedcf38b48f
@@ -0,0 +1,8 @@
+Sphinx extension test
+=====================
+
+
+.. toctree::
+   :maxdepth: 2
+
+   specs/index
source/specs/conntrack.yaml new file +643 -0

643 lines not on this page · raw message

source/specs/devlink.yaml new file +2268 -0

2,005 lines not on this page · raw message

source/specs/dpll.yaml new file +623 -0

623 lines not on this page · raw message

source/specs/ethtool.yaml new file +2384 -0

2,384 lines not on this page · raw message

source/specs/fou.yaml new file +132 -0

132 lines not on this page · raw message

source/specs/handshake.yaml new file +128 -0

128 lines not on this page · raw message

source/specs/index.rst new file +32 -0
new file mode 100644
index 000000000000..f317340c97aa

Lines of this file are not shown. View the raw message.

source/specs/lockd.yaml new file +45 -0

45 lines not on this page · raw message

source/specs/mptcp_pm.yaml new file +394 -0

394 lines not on this page · raw message

source/specs/net_shaper.yaml new file +362 -0

362 lines not on this page · raw message

source/specs/netdev.yaml new file +756 -0

756 lines not on this page · raw message

source/specs/nfsd.yaml new file +224 -0

224 lines not on this page · raw message

source/specs/nftables.yaml new file +1526 -0

1,526 lines not on this page · raw message

source/specs/nl80211.yaml new file +2000 -0

2,000 lines not on this page · raw message

source/specs/nlctrl.yaml new file +208 -0

208 lines not on this page · raw message

source/specs/ovs_datapath.yaml new file +162 -0

162 lines not on this page · raw message

source/specs/ovs_flow.yaml new file +998 -0

998 lines not on this page · raw message

source/specs/ovs_vport.yaml new file +175 -0

175 lines not on this page · raw message

source/specs/rt_addr.yaml new file +204 -0

204 lines not on this page · raw message

source/specs/rt_link.yaml new file +2523 -0

2,523 lines not on this page · raw message

source/specs/rt_neigh.yaml new file +442 -0

442 lines not on this page · raw message

source/specs/rt_route.yaml new file +336 -0

336 lines not on this page · raw message

source/specs/rt_rule.yaml new file +269 -0

269 lines not on this page · raw message

source/specs/tc.yaml new file +4032 -0

4,032 lines not on this page · raw message

source/specs/tcp_metrics.yaml new file +169 -0

169 lines not on this page · raw message

source/specs/team.yaml new file +204 -0

204 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#11 lore raw

Re: [PATCH 4/4] docs: netlink: store generated .rst files at Documentation/output

Hello Mauro,

Quoted 44 lines · Mauro Carvalho Chehab

Em Tue, 10 Jun 2025 08:43:55 -0700
Breno Leitao <[email protected]> escreveu:

Quoted 26 lines

Hello Mauro,

Quoted 5 lines · Mauro Carvalho Chehab

A better long term solution is to have an extension at Documentation/sphinx that parses *.yaml files for netlink files, which could internally be calling ynl_gen_rst.py. Yet, some care needs to be taken, as yaml extensions are also used inside device tree.

In fact, This is very similar to what I did initially in v1. And I was creating a sphinx extension to handle the generation, have a look here:

https://lore.kernel.org/all/[email protected]/

During the review, we agree to move out of the sphinx extension. the reasons are the stubs/templates that needs to be created and you are creating here.

So, if we decide to come back to sphinx extension, we can leverage that code from v1 ?!

Review

Quoted 2 lines
(quoted diff) +1 -1
-def generate_main_index_rst(output: str) -> None:
+def generate_main_index_rst(output: str, index_dir: str, ) -> None:  

You probably don't need the last , before ).

Quoted 7 lines

Other than that, LGTM.

The question is, are we OK with the templates that need to be created for netlink specs?!

Thanks for looking at it,
--breno

Hi Breno,

I did here a test creating a completely new repository using sphinx-quickstart, adding yaml to conf.py with:

	source_suffix = ['.rst', '.yaml']
Quoted 7 lines

There, I imported your v1 patch from:

	https://lore.kernel.org/all/[email protected]/

While your extension seems to require some work, as it has issues processing the current patch, it *is* creating one html file per each yaml, without needing any template. All it is needed there is to place an yaml file somewhere under source/ directory:

Thanks for the tests. It appears that the sphinx extension can function without requiring stubs and templates, right?

Given you have your hands dirty with it, and probably more experience than I have with sphinx extensions, would you be willing to take ownership of this extension and submit it? I'd be more than happy to review it.

--breno

#12 lore raw

Re: [PATCH 4/4] docs: netlink: store generated .rst files at Documentation/output

Hi Breno,

Em Wed, 11 Jun 2025 08:55:13 -0700
Breno Leitao <[email protected]> escreveu:

Quoted 55 lines

Hello Mauro,

Quoted 44 lines · Mauro Carvalho Chehab

Em Tue, 10 Jun 2025 08:43:55 -0700
Breno Leitao <[email protected]> escreveu:

Quoted 26 lines

Hello Mauro,

Quoted 5 lines · Mauro Carvalho Chehab

A better long term solution is to have an extension at Documentation/sphinx that parses *.yaml files for netlink files, which could internally be calling ynl_gen_rst.py. Yet, some care needs to be taken, as yaml extensions are also used inside device tree.

In fact, This is very similar to what I did initially in v1. And I was creating a sphinx extension to handle the generation, have a look here:

https://lore.kernel.org/all/[email protected]/

During the review, we agree to move out of the sphinx extension. the reasons are the stubs/templates that needs to be created and you are creating here.

So, if we decide to come back to sphinx extension, we can leverage that code from v1 ?!

Review

Quoted 2 lines
(quoted diff) +1 -1
-def generate_main_index_rst(output: str) -> None:
+def generate_main_index_rst(output: str, index_dir: str, ) -> None:    

You probably don't need the last , before ).

Quoted 7 lines

Other than that, LGTM.

The question is, are we OK with the templates that need to be created for netlink specs?!

Thanks for looking at it,
--breno

Hi Breno,

I did here a test creating a completely new repository using sphinx-quickstart, adding yaml to conf.py with:

	source_suffix = ['.rst', '.yaml']
Quoted 7 lines

There, I imported your v1 patch from:

	https://lore.kernel.org/all/[email protected]/

While your extension seems to require some work, as it has issues processing the current patch, it *is* creating one html file per each yaml, without needing any template. All it is needed there is to place an yaml file somewhere under source/ directory:

Quoted 7 lines

Thanks for the tests. It appears that the sphinx extension can function without requiring stubs and templates, right?

Given you have your hands dirty with it, and probably more experience than I have with sphinx extensions, would you be willing to take ownership of this extension and submit it? I'd be more than happy to review it.

Sure. I wrote an extension that will do what it is expected. Yet, I opted to have a static index.rst file. I tried to do auto-generation, but, at least when using SPHINXDIRS, it didn't work.

I'm sending the patch series in a few.

Thanks,
Mauro

maintainer
#13 lore raw

Re: [PATCH 4/4] docs: netlink: store generated .rst files at Documentation/output

In reply to Mauro Carvalho Chehab
Quoted 7 lines · Mauro Carvalho Chehab

It is not a good practice to store build-generated files inside $(srctree), as one may be using O=<BUILDDIR> and even have the Kernel on a read-only directory.

Change the YAML generation for netlink files to be inside the documentation output directory.

Quoted 8 lines

This solution is not perfect, though, as sphinx-build only produces html files only for files inside the source tree. As it is desired to have one netlink file per family, it means that one template file is required for every file inside Documentation/netlink/specs. Such template files are simple enough. All they need is:

# Template for Documentation/netlink/specs/<foo>.yaml .. kernel-include:: $BUILDDIR/networking/netlink_spec/<foo>.rst

I am not a fan of this approach because it pollutes the Documentation/output dir with source files and the kernel-include directive is a bit of a hacky workaround.

Quoted 5 lines

A better long term solution is to have an extension at Documentation/sphinx that parses *.yaml files for netlink files, which could internally be calling ynl_gen_rst.py. Yet, some care needs to be taken, as yaml extensions are also used inside device tree.

The extension does seem like a better approach, but as mentioned by Jakub, we'd want to add stub creation to the YNL regen.

The only other approach I can think of to avoid generating files in the source tree or polluting the Documentation/output dir is to stage all of the Documentation/ tree into BUILDDIR before adding generated files there, then running:

sphinx-build BUILDDIR/Documentation BUILDDIR/Documentation/output

Quoted 405 lines
---
 Documentation/Makefile                        |  8 ++++----
 .../networking/netlink_spec/conntrack.rst     |  3 +++
 .../networking/netlink_spec/devlink.rst       |  3 +++
 .../networking/netlink_spec/dpll.rst          |  3 +++
 .../networking/netlink_spec/ethtool.rst       |  3 +++
 Documentation/networking/netlink_spec/fou.rst |  3 +++
 .../networking/netlink_spec/handshake.rst     |  3 +++
 .../networking/netlink_spec/index.rst         |  6 ++++++
 .../networking/netlink_spec/lockd.rst         |  3 +++
 .../networking/netlink_spec/mptcp_pm.rst      |  3 +++
 .../networking/netlink_spec/net_shaper.rst    |  3 +++
 .../networking/netlink_spec/netdev.rst        |  3 +++
 .../networking/netlink_spec/nfsd.rst          |  3 +++
 .../networking/netlink_spec/nftables.rst      |  3 +++
 .../networking/netlink_spec/nl80211.rst       |  3 +++
 .../networking/netlink_spec/nlctrl.rst        |  3 +++
 .../networking/netlink_spec/ovpn.rst          |  3 +++
 .../networking/netlink_spec/ovs_datapath.rst  |  3 +++
 .../networking/netlink_spec/ovs_flow.rst      |  3 +++
 .../networking/netlink_spec/ovs_vport.rst     |  3 +++
 .../networking/netlink_spec/readme.txt        |  4 ----
 .../networking/netlink_spec/rt-addr.rst       |  3 +++
 .../networking/netlink_spec/rt-link.rst       |  3 +++
 .../networking/netlink_spec/rt-neigh.rst      |  3 +++
 .../networking/netlink_spec/rt-route.rst      |  3 +++
 .../networking/netlink_spec/rt-rule.rst       |  3 +++
 Documentation/networking/netlink_spec/tc.rst  |  3 +++
 .../networking/netlink_spec/tcp_metrics.rst   |  3 +++
 .../networking/netlink_spec/team.rst          |  3 +++
 tools/net/ynl/pyynl/ynl_gen_rst.py            | 19 +++++++++++++------
 30 files changed, 101 insertions(+), 14 deletions(-)
 create mode 100644 Documentation/networking/netlink_spec/conntrack.rst
 create mode 100644 Documentation/networking/netlink_spec/devlink.rst
 create mode 100644 Documentation/networking/netlink_spec/dpll.rst
 create mode 100644 Documentation/networking/netlink_spec/ethtool.rst
 create mode 100644 Documentation/networking/netlink_spec/fou.rst
 create mode 100644 Documentation/networking/netlink_spec/handshake.rst
 create mode 100644 Documentation/networking/netlink_spec/index.rst
 create mode 100644 Documentation/networking/netlink_spec/lockd.rst
 create mode 100644 Documentation/networking/netlink_spec/mptcp_pm.rst
 create mode 100644 Documentation/networking/netlink_spec/net_shaper.rst
 create mode 100644 Documentation/networking/netlink_spec/netdev.rst
 create mode 100644 Documentation/networking/netlink_spec/nfsd.rst
 create mode 100644 Documentation/networking/netlink_spec/nftables.rst
 create mode 100644 Documentation/networking/netlink_spec/nl80211.rst
 create mode 100644 Documentation/networking/netlink_spec/nlctrl.rst
 create mode 100644 Documentation/networking/netlink_spec/ovpn.rst
 create mode 100644 Documentation/networking/netlink_spec/ovs_datapath.rst
 create mode 100644 Documentation/networking/netlink_spec/ovs_flow.rst
 create mode 100644 Documentation/networking/netlink_spec/ovs_vport.rst
 delete mode 100644 Documentation/networking/netlink_spec/readme.txt
 create mode 100644 Documentation/networking/netlink_spec/rt-addr.rst
 create mode 100644 Documentation/networking/netlink_spec/rt-link.rst
 create mode 100644 Documentation/networking/netlink_spec/rt-neigh.rst
 create mode 100644 Documentation/networking/netlink_spec/rt-route.rst
 create mode 100644 Documentation/networking/netlink_spec/rt-rule.rst
 create mode 100644 Documentation/networking/netlink_spec/tc.rst
 create mode 100644 Documentation/networking/netlink_spec/tcp_metrics.rst
 create mode 100644 Documentation/networking/netlink_spec/team.rst
Documentation/Makefile +4 -4
index d30d66ddf1ad..2383825dba49 100644
@@ -102,8 +102,8 @@ quiet_cmd_sphinx = SPHINX  $@ --> file://$(abspath $(BUILDDIR)/$3/$4)
 		cp $(if $(patsubst /%,,$(DOCS_CSS)),$(abspath $(srctree)/$(DOCS_CSS)),$(DOCS_CSS)) $(BUILDDIR)/$3/_static/; \
 	fi
 
-YNL_INDEX:=$(srctree)/Documentation/networking/netlink_spec/index.rst
-YNL_RST_DIR:=$(srctree)/Documentation/networking/netlink_spec
+YNL_INDEX:=$(BUILDDIR)/networking/netlink_spec/netlink_index.rst
+YNL_RST_DIR:=$(BUILDDIR)/networking/netlink_spec/
 YNL_YAML_DIR:=$(srctree)/Documentation/netlink/specs
 YNL_TOOL:=$(srctree)/tools/net/ynl/pyynl/ynl_gen_rst.py
 
@@ -111,12 +111,12 @@ YNL_RST_FILES_TMP := $(patsubst %.yaml,%.rst,$(wildcard $(YNL_YAML_DIR)/*.yaml))
 YNL_RST_FILES := $(patsubst $(YNL_YAML_DIR)%,$(YNL_RST_DIR)%, $(YNL_RST_FILES_TMP))
 
 $(YNL_INDEX): $(YNL_RST_FILES)
-	$(Q)$(YNL_TOOL) -o $@ -x
+	$(Q)$(YNL_TOOL) -o $@ -d $(YNL_YAML_DIR) -x
 
 $(YNL_RST_DIR)/%.rst: $(YNL_YAML_DIR)/%.yaml $(YNL_TOOL)
 	$(Q)$(YNL_TOOL) -i $< -o $@
 
-htmldocs texinfodocs latexdocs epubdocs xmldocs: $(YNL_INDEX)
+htmldocs texinfodocs latexdocs epubdocs xmldocs: $(YNL_INDEX) $(YNL_RST_FILES)
 
 htmldocs:
 	@$(srctree)/scripts/sphinx-pre-install --version-check
Documentation/networking/netlink_spec/conntrack.rst new file +3 -0
new file mode 100644
index 000000000000..6fc6af1e6de4
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/conntrack.rst
Documentation/networking/netlink_spec/devlink.rst new file +3 -0
new file mode 100644
index 000000000000..412295d396c1
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/devlink.rst
Documentation/networking/netlink_spec/dpll.rst new file +3 -0
new file mode 100644
index 000000000000..913e1d9ef744
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/dpll.rst
Documentation/networking/netlink_spec/ethtool.rst new file +3 -0
new file mode 100644
index 000000000000..42136a8572b9
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/ethtool.rst
Documentation/networking/netlink_spec/fou.rst new file +3 -0
new file mode 100644
index 000000000000..103528337d46
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/fou.rst
Documentation/networking/netlink_spec/handshake.rst new file +3 -0
new file mode 100644
index 000000000000..600abec80431
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/handshake.rst
Documentation/networking/netlink_spec/index.rst new file +6 -0
new file mode 100644
index 000000000000..8a07a77f2e8b
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+
+# Netlink documentation is populated during the build of the documentation
+# (htmldocs) by the tools/net/ynl/pyynl/ynl_gen_rst.py script.
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/netlink_index.rst
Documentation/networking/netlink_spec/lockd.rst new file +3 -0
new file mode 100644
index 000000000000..6374dc2a982c
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/lockd.rst
Documentation/networking/netlink_spec/mptcp_pm.rst new file +3 -0
new file mode 100644
index 000000000000..8923db35603e
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/mptcp_pm.rst
Documentation/networking/netlink_spec/net_shaper.rst new file +3 -0
new file mode 100644
index 000000000000..82d9300f1c0c
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/net_shaper.rst
Documentation/networking/netlink_spec/netdev.rst new file +3 -0
new file mode 100644
index 000000000000..c379a79c5f23
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/netdev.rst
Documentation/networking/netlink_spec/nfsd.rst new file +3 -0
new file mode 100644
index 000000000000..40716f4a3fa8
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/nfsd.rst
Documentation/networking/netlink_spec/nftables.rst new file +3 -0
new file mode 100644
index 000000000000..1dc6d7c5ca58
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/nftables.rst
Documentation/networking/netlink_spec/nl80211.rst new file +3 -0
new file mode 100644
index 000000000000..c056418f7068
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/nl80211.rst
Documentation/networking/netlink_spec/nlctrl.rst new file +3 -0
new file mode 100644
index 000000000000..7fe48f26718e
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/nlctrl.rst
Documentation/networking/netlink_spec/ovpn.rst new file +3 -0
new file mode 100644
index 000000000000..c146b803d742
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/ovpn.rst
Documentation/networking/netlink_spec/ovs_datapath.rst new file +3 -0
new file mode 100644
index 000000000000..0b1242f2cc9c
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/ovs_datapath.rst
Documentation/networking/netlink_spec/ovs_flow.rst new file +3 -0
new file mode 100644
index 000000000000..c1019ab06aff
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/ovs_flow.rst
Documentation/networking/netlink_spec/ovs_vport.rst new file +3 -0
new file mode 100644
index 000000000000..13eb53ff4c75
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/ovs_vport.rst
Documentation/networking/netlink_spec/readme.txt deleted +0 -4
deleted file mode 100644
index 030b44aca4e6..000000000000
@@ -1,4 +0,0 @@
-SPDX-License-Identifier: GPL-2.0
-
-This file is populated during the build of the documentation (htmldocs) by the
-tools/net/ynl/pyynl/ynl_gen_rst.py script.
Documentation/networking/netlink_spec/rt-addr.rst new file +3 -0
new file mode 100644
index 000000000000..2739e81b7a04
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/rt-addr.rst
Documentation/networking/netlink_spec/rt-link.rst new file +3 -0
new file mode 100644
index 000000000000..d4df7268d07c
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/rt-link.rst
Documentation/networking/netlink_spec/rt-neigh.rst new file +3 -0
new file mode 100644
index 000000000000..6c8b62d7b2ff
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/rt-neigh.rst
Documentation/networking/netlink_spec/rt-route.rst new file +3 -0
new file mode 100644
index 000000000000..a629d14bf405
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/rt-route.rst
Documentation/networking/netlink_spec/rt-rule.rst new file +3 -0
new file mode 100644
index 000000000000..e4a991b1bacd
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/rt-rule.rst
Documentation/networking/netlink_spec/tc.rst new file +3 -0
new file mode 100644
index 000000000000..1e78d3caeb5d
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/tc.rst
Documentation/networking/netlink_spec/tcp_metrics.rst new file +3 -0
new file mode 100644
index 000000000000..ea43bd6f6925
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/tcp_metrics.rst
Documentation/networking/netlink_spec/team.rst new file +3 -0
new file mode 100644
index 000000000000..45a3f4d3ed80
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+.. kernel-include:: $BUILDDIR/networking/netlink_spec/team.rst
tools/net/ynl/pyynl/ynl_gen_rst.py +13 -6
index 7bfb8ceeeefc..70417a9a8e96 100755
@@ -365,6 +365,7 @@ def parse_arguments() -> argparse.Namespace:
 
     parser.add_argument("-v", "--verbose", action="store_true")
     parser.add_argument("-o", "--output", help="Output file name")
+    parser.add_argument("-d", "--input_dir", help="YAML input directory")
 
     # Index and input are mutually exclusive
     group = parser.add_mutually_exclusive_group()
@@ -405,11 +406,14 @@ def write_to_rstfile(content: str, filename: str) -> None:
     """Write the generated content into an RST file"""
     logging.debug("Saving RST file to %s", filename)
 
+    dir = os.path.dirname(filename)
+    os.makedirs(dir, exist_ok=True)
+
     with open(filename, "w", encoding="utf-8") as rst_file:
         rst_file.write(content)
 
 
-def generate_main_index_rst(output: str) -> None:
+def generate_main_index_rst(output: str, index_dir: str, ) -> None:
     """Generate the `networking_spec/index` content and write to the file"""
     lines = []
 
@@ -418,12 +422,15 @@ def generate_main_index_rst(output: str) -> None:
     lines.append(rst_title("Netlink Family Specifications"))
     lines.append(rst_toctree(1))
 
-    index_dir = os.path.dirname(output)
-    logging.debug("Looking for .rst files in %s", index_dir)
+    index_fname = os.path.basename(output)
+    if not index_dir:
+        index_dir = os.path.dirname(output)
+
+    logging.debug("Looking for .yaml files in %s", index_dir)
     for filename in sorted(os.listdir(index_dir)):
-        if not filename.endswith(".rst") or filename == "index.rst":
+        if not filename.endswith(".yaml") or filename == index_fname:
             continue
-        lines.append(f"   {filename.replace('.rst', '')}\n")
+        lines.append(f"   {filename.replace('.yaml', '')}\n")
 
     logging.debug("Writing an index file at %s", output)
     write_to_rstfile("".join(lines), output)
@@ -447,7 +454,7 @@ def main() -> None:
 
     if args.index:
         # Generate the index RST file
-        generate_main_index_rst(args.output)
+        generate_main_index_rst(args.output, args.input_dir)
 
 
 if __name__ == "__main__":
#14 lore raw

Re: [PATCH 4/4] docs: netlink: store generated .rst files at Documentation/output

Em Wed, 11 Jun 2025 12:36:57 +0100
Donald Hunter <[email protected]> escreveu:

Quoted 31 lines
Quoted 7 lines · Mauro Carvalho Chehab

It is not a good practice to store build-generated files inside $(srctree), as one may be using O=<BUILDDIR> and even have the Kernel on a read-only directory.

Change the YAML generation for netlink files to be inside the documentation output directory.

Quoted 8 lines

This solution is not perfect, though, as sphinx-build only produces html files only for files inside the source tree. As it is desired to have one netlink file per family, it means that one template file is required for every file inside Documentation/netlink/specs. Such template files are simple enough. All they need is:

# Template for Documentation/netlink/specs/<foo>.yaml .. kernel-include:: $BUILDDIR/networking/netlink_spec/<foo>.rst

I am not a fan of this approach because it pollutes the Documentation/output dir with source files and the kernel-include directive is a bit of a hacky workaround.

Quoted 5 lines

A better long term solution is to have an extension at Documentation/sphinx that parses *.yaml files for netlink files, which could internally be calling ynl_gen_rst.py. Yet, some care needs to be taken, as yaml extensions are also used inside device tree.

The extension does seem like a better approach, but as mentioned by Jakub, we'd want to add stub creation to the YNL regen.

Quoted 6 lines

The only other approach I can think of to avoid generating files in the source tree or polluting the Documentation/output dir is to stage all of the Documentation/ tree into BUILDDIR before adding generated files there, then running:

sphinx-build BUILDDIR/Documentation BUILDDIR/Documentation/output

I did some tests here adding yaml to conf.py:

	-source_suffix = '.rst'
	+source_suffix = ['.rst', '.yaml']

Such change made the extension to automatically generate one file per each existing yaml without the need of adding any template. I tested on a brand new tree with just Sphinx + netlink files + Breno's original extension (untouched). Such empty tree was generated with sphinx-quickstart (sent a reply to Breno with a patch with all inside it).

When applying it to the Kernel, we can do this change at Documentation/conf.py, together with:

-exclude_patterns = ['output']
+exclude_patterns = ['output', 'devicetree/bindings/**.yaml']

(glob pattern not tested)

As we don't want DT yaml files to be processed as netlink families.

After such tests, it sounds to me that the Sphinx extension approach may work without requiring templates. Tested here with Sphinx 8.1.3.

Regards,
Mauro