Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'tools-ynl-add-install-target'

Jan Stancek says:

====================
tools: ynl: add install target

This series adds an install target for ynl. The python code
is moved to a subdirectory, so it can be used as a package
with flat layout, as well as directly from the tree.

To try the install as a non-root user you can run:
$ mkdir /tmp/myroot
$ make DESTDIR=/tmp/myroot install

$ PATH="/tmp/myroot/usr/bin:$PATH" PYTHONPATH="$(ls -1d /tmp/myroot/usr/lib/python*/site-packages)" ynl --help

Proposed install layout is described in last patch.
====================

Link: https://patch.msgid.link/cover.1736343575.git.jstancek@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+113 -25
+1 -1
Documentation/Makefile
··· 104 104 YNL_INDEX:=$(srctree)/Documentation/networking/netlink_spec/index.rst 105 105 YNL_RST_DIR:=$(srctree)/Documentation/networking/netlink_spec 106 106 YNL_YAML_DIR:=$(srctree)/Documentation/netlink/specs 107 - YNL_TOOL:=$(srctree)/tools/net/ynl/ynl-gen-rst.py 107 + YNL_TOOL:=$(srctree)/tools/net/ynl/pyynl/ynl_gen_rst.py 108 108 109 109 YNL_RST_FILES_TMP := $(patsubst %.yaml,%.rst,$(wildcard $(YNL_YAML_DIR)/*.yaml)) 110 110 YNL_RST_FILES := $(patsubst $(YNL_YAML_DIR)%,$(YNL_RST_DIR)%, $(YNL_RST_FILES_TMP))
+2 -2
Documentation/networking/multi-pf-netdev.rst
··· 89 89 ============= 90 90 The relation between PF, irq, napi, and queue can be observed via netlink spec:: 91 91 92 - $ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml --dump queue-get --json='{"ifindex": 13}' 92 + $ ./tools/net/ynl/pyynl/cli.py --spec Documentation/netlink/specs/netdev.yaml --dump queue-get --json='{"ifindex": 13}' 93 93 [{'id': 0, 'ifindex': 13, 'napi-id': 539, 'type': 'rx'}, 94 94 {'id': 1, 'ifindex': 13, 'napi-id': 540, 'type': 'rx'}, 95 95 {'id': 2, 'ifindex': 13, 'napi-id': 541, 'type': 'rx'}, ··· 101 101 {'id': 3, 'ifindex': 13, 'napi-id': 542, 'type': 'tx'}, 102 102 {'id': 4, 'ifindex': 13, 'napi-id': 543, 'type': 'tx'}] 103 103 104 - $ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml --dump napi-get --json='{"ifindex": 13}' 104 + $ ./tools/net/ynl/pyynl/cli.py --spec Documentation/netlink/specs/netdev.yaml --dump napi-get --json='{"ifindex": 13}' 105 105 [{'id': 543, 'ifindex': 13, 'irq': 42}, 106 106 {'id': 542, 'ifindex': 13, 'irq': 41}, 107 107 {'id': 541, 'ifindex': 13, 'irq': 40},
+2 -2
Documentation/networking/napi.rst
··· 199 199 200 200 Per-NAPI configuration can be done programmatically in a user application 201 201 or by using a script included in the kernel source tree: 202 - ``tools/net/ynl/cli.py``. 202 + ``tools/net/ynl/pyynl/cli.py``. 203 203 204 204 For example, using the script: 205 205 206 206 .. code-block:: bash 207 207 208 - $ kernel-source/tools/net/ynl/cli.py \ 208 + $ kernel-source/tools/net/ynl/pyynl/cli.py \ 209 209 --spec Documentation/netlink/specs/netdev.yaml \ 210 210 --do napi-set \ 211 211 --json='{"id": 345,
+4 -4
Documentation/userspace-api/netlink/intro-specs.rst
··· 15 15 and can use a YAML specification to issue Netlink requests 16 16 to the kernel. Only Generic Netlink is supported. 17 17 18 - The tool is located at ``tools/net/ynl/cli.py``. It accepts 18 + The tool is located at ``tools/net/ynl/pyynl/cli.py``. It accepts 19 19 a handul of arguments, the most important ones are: 20 20 21 21 - ``--spec`` - point to the spec file ··· 27 27 28 28 Example use:: 29 29 30 - $ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/ethtool.yaml \ 30 + $ ./tools/net/ynl/pyynl/cli.py --spec Documentation/netlink/specs/ethtool.yaml \ 31 31 --do rings-get \ 32 32 --json '{"header":{"dev-index": 18}}' 33 33 {'header': {'dev-index': 18, 'dev-name': 'eni1np1'}, ··· 75 75 and run the regeneration tool. Grep the tree for ``YNL-GEN`` 76 76 to see other examples. 77 77 78 - The code generation itself is performed by ``tools/net/ynl/ynl-gen-c.py`` 78 + The code generation itself is performed by ``tools/net/ynl/pyynl/ynl_gen_c.py`` 79 79 but it takes a few arguments so calling it directly for each file 80 80 quickly becomes tedious. 81 81 ··· 84 84 85 85 ``tools/net/ynl/lib/`` contains an implementation of a C library 86 86 (based on libmnl) which integrates with code generated by 87 - ``tools/net/ynl/ynl-gen-c.py`` to create easy to use netlink wrappers. 87 + ``tools/net/ynl/pyynl/ynl_gen_c.py`` to create easy to use netlink wrappers. 88 88 89 89 YNL basics 90 90 ----------
+28 -1
tools/net/ynl/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 3 + include ../../scripts/Makefile.arch 4 + 5 + INSTALL ?= install 6 + prefix ?= /usr 7 + ifeq ($(LP64), 1) 8 + libdir_relative = lib64 9 + else 10 + libdir_relative = lib 11 + endif 12 + libdir ?= $(prefix)/$(libdir_relative) 13 + includedir ?= $(prefix)/include 14 + 3 15 SUBDIRS = lib generated samples 4 16 5 17 all: $(SUBDIRS) libynl.a ··· 33 21 fi \ 34 22 done 35 23 rm -f libynl.a 24 + rm -rf pyynl/__pycache__ 25 + rm -rf pyynl/lib/__pycache__ 26 + rm -rf pyynl.egg-info 27 + rm -rf build 36 28 37 - .PHONY: all clean distclean $(SUBDIRS) 29 + install: libynl.a lib/*.h 30 + @echo -e "\tINSTALL libynl.a" 31 + @$(INSTALL) -d $(DESTDIR)$(libdir) 32 + @$(INSTALL) -m 0644 libynl.a $(DESTDIR)$(libdir)/libynl.a 33 + @echo -e "\tINSTALL libynl headers" 34 + @$(INSTALL) -d $(DESTDIR)$(includedir)/ynl 35 + @$(INSTALL) -m 0644 lib/*.h $(DESTDIR)$(includedir)/ynl/ 36 + @echo -e "\tINSTALL pyynl" 37 + @pip install --prefix=$(DESTDIR)$(prefix) . 38 + @make -C generated install 39 + 40 + .PHONY: all clean distclean install $(SUBDIRS)
tools/net/ynl/cli.py tools/net/ynl/pyynl/cli.py
tools/net/ynl/ethtool.py tools/net/ynl/pyynl/ethtool.py
+1
tools/net/ynl/generated/.gitignore
··· 1 1 *-user.c 2 2 *-user.h 3 + *.rst
+43 -8
tools/net/ynl/generated/Makefile
··· 7 7 CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan 8 8 endif 9 9 10 + INSTALL ?= install 11 + prefix ?= /usr 12 + datarootdir ?= $(prefix)/share 13 + docdir ?= $(datarootdir)/doc 14 + includedir ?= $(prefix)/include 15 + 10 16 include ../Makefile.deps 11 17 12 18 YNL_GEN_ARG_ethtool:=--user-header linux/ethtool_netlink.h \ 13 19 --exclude-op stats-get 14 20 15 - TOOL:=../ynl-gen-c.py 21 + TOOL:=../pyynl/ynl_gen_c.py 22 + TOOL_RST:=../pyynl/ynl_gen_rst.py 16 23 24 + SPECS_DIR:=../../../../Documentation/netlink/specs 17 25 GENS_PATHS=$(shell grep -nrI --files-without-match \ 18 26 'protocol: netlink' \ 19 - ../../../../Documentation/netlink/specs/) 20 - GENS=$(patsubst ../../../../Documentation/netlink/specs/%.yaml,%,${GENS_PATHS}) 27 + $(SPECS_DIR)) 28 + GENS=$(patsubst $(SPECS_DIR)/%.yaml,%,${GENS_PATHS}) 21 29 SRCS=$(patsubst %,%-user.c,${GENS}) 22 30 HDRS=$(patsubst %,%-user.h,${GENS}) 23 31 OBJS=$(patsubst %,%-user.o,${GENS}) 24 32 25 - all: protos.a $(HDRS) $(SRCS) $(KHDRS) $(KSRCS) $(UAPI) 33 + SPECS_PATHS=$(wildcard $(SPECS_DIR)/*.yaml) 34 + SPECS=$(patsubst $(SPECS_DIR)/%.yaml,%,${SPECS_PATHS}) 35 + RSTS=$(patsubst %,%.rst,${SPECS}) 36 + 37 + all: protos.a $(HDRS) $(SRCS) $(KHDRS) $(KSRCS) $(UAPI) $(RSTS) 26 38 27 39 protos.a: $(OBJS) 28 40 @echo -e "\tAR $@" 29 41 @ar rcs $@ $(OBJS) 30 42 31 - %-user.h: ../../../../Documentation/netlink/specs/%.yaml $(TOOL) 43 + %-user.h: $(SPECS_DIR)/%.yaml $(TOOL) 32 44 @echo -e "\tGEN $@" 33 45 @$(TOOL) --mode user --header --spec $< -o $@ $(YNL_GEN_ARG_$*) 34 46 35 - %-user.c: ../../../../Documentation/netlink/specs/%.yaml $(TOOL) 47 + %-user.c: $(SPECS_DIR)/%.yaml $(TOOL) 36 48 @echo -e "\tGEN $@" 37 49 @$(TOOL) --mode user --source --spec $< -o $@ $(YNL_GEN_ARG_$*) 38 50 ··· 52 40 @echo -e "\tCC $@" 53 41 @$(COMPILE.c) $(CFLAGS_$*) -o $@ $< 54 42 43 + %.rst: $(SPECS_DIR)/%.yaml $(TOOL_RST) 44 + @echo -e "\tGEN_RST $@" 45 + @$(TOOL_RST) -o $@ -i $< 46 + 55 47 clean: 56 48 rm -f *.o 57 49 58 50 distclean: clean 59 - rm -f *.c *.h *.a 51 + rm -f *.c *.h *.a *.rst 60 52 61 53 regen: 62 54 @../ynl-regen.sh 63 55 64 - .PHONY: all clean distclean regen 56 + install-headers: $(HDRS) 57 + @echo -e "\tINSTALL generated headers" 58 + @$(INSTALL) -d $(DESTDIR)$(includedir)/ynl 59 + @$(INSTALL) -m 0644 *.h $(DESTDIR)$(includedir)/ynl/ 60 + 61 + install-rsts: $(RSTS) 62 + @echo -e "\tINSTALL generated docs" 63 + @$(INSTALL) -d $(DESTDIR)$(docdir)/ynl 64 + @$(INSTALL) -m 0644 $(RSTS) $(DESTDIR)$(docdir)/ynl/ 65 + 66 + install-specs: 67 + @echo -e "\tINSTALL specs" 68 + @$(INSTALL) -d $(DESTDIR)$(datarootdir)/ynl 69 + @$(INSTALL) -m 0644 ../../../../Documentation/netlink/*.yaml $(DESTDIR)$(datarootdir)/ynl/ 70 + @$(INSTALL) -d $(DESTDIR)$(datarootdir)/ynl/specs 71 + @$(INSTALL) -m 0644 $(SPECS_DIR)/*.yaml $(DESTDIR)$(datarootdir)/ynl/specs/ 72 + 73 + install: install-headers install-rsts install-specs 74 + 75 + .PHONY: all clean distclean regen install install-headers install-rsts install-specs 65 76 .DEFAULT_GOAL: all
-1
tools/net/ynl/lib/.gitignore
··· 1 - __pycache__/ 2 1 *.d
-1
tools/net/ynl/lib/Makefile
··· 19 19 20 20 clean: 21 21 rm -f *.o *.d *~ 22 - rm -rf __pycache__ 23 22 24 23 distclean: clean 25 24 rm -f *.a
tools/net/ynl/lib/__init__.py tools/net/ynl/pyynl/lib/__init__.py
tools/net/ynl/lib/nlspec.py tools/net/ynl/pyynl/lib/nlspec.py
tools/net/ynl/lib/ynl.py tools/net/ynl/pyynl/lib/ynl.py
+24
tools/net/ynl/pyproject.toml
··· 1 + [build-system] 2 + requires = ["setuptools>=61.0"] 3 + build-backend = "setuptools.build_meta" 4 + 5 + [project] 6 + name = "pyynl" 7 + authors = [ 8 + {name = "Donald Hunter", email = "donald.hunter@gmail.com"}, 9 + {name = "Jakub Kicinski", email = "kuba@kernel.org"}, 10 + ] 11 + description = "yaml netlink (ynl)" 12 + version = "0.0.1" 13 + requires-python = ">=3.9" 14 + dependencies = [ 15 + "pyyaml==6.*", 16 + "jsonschema==4.*" 17 + ] 18 + 19 + [tool.setuptools.packages.find] 20 + include = ["pyynl", "pyynl.lib"] 21 + 22 + [project.scripts] 23 + ynl = "pyynl.cli:main" 24 + ynl-ethtool = "pyynl.ethtool:main"
+2
tools/net/ynl/pyynl/.gitignore
··· 1 + __pycache__/ 2 + lib/__pycache__/
tools/net/ynl/pyynl/__init__.py
tools/net/ynl/ynl-gen-c.py tools/net/ynl/pyynl/ynl_gen_c.py
tools/net/ynl/ynl-gen-rst.py tools/net/ynl/pyynl/ynl_gen_rst.py
+1 -1
tools/net/ynl/ynl-regen.sh
··· 1 1 #!/bin/bash 2 2 # SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 3 3 4 - TOOL=$(dirname $(realpath $0))/ynl-gen-c.py 4 + TOOL=$(dirname $(realpath $0))/pyynl/ynl_gen_c.py 5 5 6 6 force= 7 7 search=
+2 -2
tools/testing/selftests/net/lib/py/ynl.py
··· 13 13 SPEC_PATH = KSFT_DIR / "net/lib/specs" 14 14 15 15 sys.path.append(tools_full_path.as_posix()) 16 - from net.lib.ynl.lib import YnlFamily, NlError 16 + from net.lib.ynl.pyynl.lib import YnlFamily, NlError 17 17 else: 18 18 # Running in tree 19 19 tools_full_path = KSRC / "tools" 20 20 SPEC_PATH = KSRC / "Documentation/netlink/specs" 21 21 22 22 sys.path.append(tools_full_path.as_posix()) 23 - from net.ynl.lib import YnlFamily, NlError 23 + from net.ynl.pyynl.lib import YnlFamily, NlError 24 24 except ModuleNotFoundError as e: 25 25 ksft_pr("Failed importing `ynl` library from kernel sources") 26 26 ksft_pr(str(e))
+2 -1
tools/testing/selftests/net/ynl.mk
··· 31 31 $(Q)cp $(top_srcdir)/tools/net/ynl/libynl.a $(OUTPUT)/libynl.a 32 32 33 33 EXTRA_CLEAN += \ 34 - $(top_srcdir)/tools/net/ynl/lib/__pycache__ \ 34 + $(top_srcdir)/tools/net/ynl/pyynl/__pycache__ \ 35 + $(top_srcdir)/tools/net/ynl/pyynl/lib/__pycache__ \ 35 36 $(top_srcdir)/tools/net/ynl/lib/*.[ado] \ 36 37 $(OUTPUT)/.libynl-*.sig \ 37 38 $(OUTPUT)/libynl.a