Linux-Modules Archive on lore.kernel.org
 help / Atom feed
* [PATCH 0/2] depmod: fix override lookup
@ 2017-12-07 19:16 Yauheni Kaliuta
  2017-12-07 19:16 ` [PATCH 1/2] testsuite: depmod: add override test Yauheni Kaliuta
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Yauheni Kaliuta @ 2017-12-07 19:16 UTC (permalink / raw)
  To: Lucas De Marchi; +Cc: linux-modules

Add override test.
Fix a relative path calculation mistake.


Yauheni Kaliuta (2):
  testsuite: depmod: add override test
  depmod: module_is_higher_priority: fix modname length calculation

 testsuite/populate-modules.sh                      |  2 ++
 .../etc/depmod.d/override.conf                     |  1 +
 .../search-order-override/etc/depmod.d/search.conf |  1 +
 .../lib/modules/4.4.4/correct-modules.dep          |  1 +
 testsuite/test-depmod.c                            | 26 ++++++++++++++++++++++
 tools/depmod.c                                     |  4 ++--
 6 files changed, 33 insertions(+), 2 deletions(-)
 create mode 100644 testsuite/rootfs-pristine/test-depmod/search-order-override/etc/depmod.d/override.conf
 create mode 100644 testsuite/rootfs-pristine/test-depmod/search-order-override/etc/depmod.d/search.conf
 create mode 100644 testsuite/rootfs-pristine/test-depmod/search-order-override/lib/modules/4.4.4/correct-modules.dep

-- 
2.15.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] testsuite: depmod: add override test
  2017-12-07 19:16 [PATCH 0/2] depmod: fix override lookup Yauheni Kaliuta
@ 2017-12-07 19:16 ` Yauheni Kaliuta
  2017-12-07 19:16 ` [PATCH 2/2] depmod: module_is_higher_priority: fix modname length calculation Yauheni Kaliuta
  2017-12-07 22:15 ` [PATCH 0/2] depmod: fix override lookup Lucas De Marchi
  2 siblings, 0 replies; 4+ messages in thread
From: Yauheni Kaliuta @ 2017-12-07 19:16 UTC (permalink / raw)
  To: Lucas De Marchi; +Cc: linux-modules

Simple test to check if depmod honors override keyword. Uses
mod-simple.ko for foo/ and override/ directories, search.conf to
search in foo and built-in and simple override configuration:

override mod-simple 4.4.4 override

The resulting modules.dep should point to the override directory.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
---
 testsuite/populate-modules.sh                      |  2 ++
 .../etc/depmod.d/override.conf                     |  1 +
 .../search-order-override/etc/depmod.d/search.conf |  1 +
 .../lib/modules/4.4.4/correct-modules.dep          |  1 +
 testsuite/test-depmod.c                            | 26 ++++++++++++++++++++++
 5 files changed, 31 insertions(+)
 create mode 100644 testsuite/rootfs-pristine/test-depmod/search-order-override/etc/depmod.d/override.conf
 create mode 100644 testsuite/rootfs-pristine/test-depmod/search-order-override/etc/depmod.d/search.conf
 create mode 100644 testsuite/rootfs-pristine/test-depmod/search-order-override/lib/modules/4.4.4/correct-modules.dep

diff --git a/testsuite/populate-modules.sh b/testsuite/populate-modules.sh
index 3ac92ee8030d..b77e71edf0a4 100755
--- a/testsuite/populate-modules.sh
+++ b/testsuite/populate-modules.sh
@@ -28,6 +28,8 @@ map=(
     ["test-depmod/search-order-external-last/lib/modules/4.4.4/foo/"]="mod-simple.ko"
     ["test-depmod/search-order-external-last/lib/modules/4.4.4/foobar/"]="mod-simple.ko"
     ["test-depmod/search-order-external-last/lib/modules/external/"]="mod-simple.ko"
+    ["test-depmod/search-order-override/lib/modules/4.4.4/foo/"]="mod-simple.ko"
+    ["test-depmod/search-order-override/lib/modules/4.4.4/override/"]="mod-simple.ko"
     ["test-dependencies/lib/modules/4.0.20-kmod/kernel/fs/foo/"]="mod-foo-b.ko"
     ["test-dependencies/lib/modules/4.0.20-kmod/kernel/"]="mod-foo-c.ko"
     ["test-dependencies/lib/modules/4.0.20-kmod/kernel/lib/"]="mod-foo-a.ko"
diff --git a/testsuite/rootfs-pristine/test-depmod/search-order-override/etc/depmod.d/override.conf b/testsuite/rootfs-pristine/test-depmod/search-order-override/etc/depmod.d/override.conf
new file mode 100644
index 000000000000..fadf8112c26a
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-depmod/search-order-override/etc/depmod.d/override.conf
@@ -0,0 +1 @@
+override mod-simple 4.4.4 override
diff --git a/testsuite/rootfs-pristine/test-depmod/search-order-override/etc/depmod.d/search.conf b/testsuite/rootfs-pristine/test-depmod/search-order-override/etc/depmod.d/search.conf
new file mode 100644
index 000000000000..289ddcdd4152
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-depmod/search-order-override/etc/depmod.d/search.conf
@@ -0,0 +1 @@
+search foo built-in
diff --git a/testsuite/rootfs-pristine/test-depmod/search-order-override/lib/modules/4.4.4/correct-modules.dep b/testsuite/rootfs-pristine/test-depmod/search-order-override/lib/modules/4.4.4/correct-modules.dep
new file mode 100644
index 000000000000..4c7ea8e08c8e
--- /dev/null
+++ b/testsuite/rootfs-pristine/test-depmod/search-order-override/lib/modules/4.4.4/correct-modules.dep
@@ -0,0 +1 @@
+override/mod-simple.ko:
diff --git a/testsuite/test-depmod.c b/testsuite/test-depmod.c
index e249c61515dc..47dafb4dd618 100644
--- a/testsuite/test-depmod.c
+++ b/testsuite/test-depmod.c
@@ -183,4 +183,30 @@ DEFINE_TEST(depmod_search_order_external_last,
 		},
 	});
 
+#define SEARCH_ORDER_OVERRIDE_ROOTFS TESTSUITE_ROOTFS "test-depmod/search-order-override"
+static noreturn int depmod_search_order_override(const struct test *t)
+{
+	const char *progname = ABS_TOP_BUILDDIR "/tools/depmod";
+	const char *const args[] = {
+		progname,
+		NULL,
+	};
+
+	test_spawn_prog(progname, args);
+	exit(EXIT_FAILURE);
+}
+DEFINE_TEST(depmod_search_order_override,
+	.description = "check if depmod honor override keyword",
+	.config = {
+		[TC_UNAME_R] = "4.4.4",
+		[TC_ROOTFS] = SEARCH_ORDER_OVERRIDE_ROOTFS,
+	},
+	.output = {
+		.files = (const struct keyval[]) {
+			{ SEARCH_ORDER_OVERRIDE_ROOTFS "/lib/modules/4.4.4/correct-modules.dep",
+			  SEARCH_ORDER_OVERRIDE_ROOTFS "/lib/modules/4.4.4/modules.dep" },
+			{ }
+		},
+	});
+
 TESTSUITE_MAIN();
-- 
2.15.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] depmod: module_is_higher_priority: fix modname length calculation
  2017-12-07 19:16 [PATCH 0/2] depmod: fix override lookup Yauheni Kaliuta
  2017-12-07 19:16 ` [PATCH 1/2] testsuite: depmod: add override test Yauheni Kaliuta
@ 2017-12-07 19:16 ` Yauheni Kaliuta
  2017-12-07 22:15 ` [PATCH 0/2] depmod: fix override lookup Lucas De Marchi
  2 siblings, 0 replies; 4+ messages in thread
From: Yauheni Kaliuta @ 2017-12-07 19:16 UTC (permalink / raw)
  To: Lucas De Marchi; +Cc: linux-modules

depmod_module_is_higher_priority checks module's path if it is under
module root directory and if so uses relative to the root path to
lookup the module in override and search lists.

Originally only relative path was used in the function, so the
variables with full path and and path length were changed:

       newpath += cfg->dirnamelen + 1;
       newlen -= cfg->dirnamelen + 1;
       oldpath += cfg->dirnamelen + 1;
       oldlen -= cfg->dirnamelen + 1;

Commit 7da6884e7357ac05772e90f6d7e63b1948103fc4 (depmod: implement
external directories support) changed the logic since it need the
full path to the module for comparations as well.

Unfortunately, it introduce a mistake in calculation of the relative
paths replacing '-=' with assignment to a new variable -- the
'cfg->dirnamelen + 1' value must be substracted all together. It
breaks, for example, overrides lookup.

Fix the calculation by putting braces around the value in the
subsctuction expression.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
---
 tools/depmod.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/depmod.c b/tools/depmod.c
index 7ff3e9ed191e..921dc5cc93eb 100644
--- a/tools/depmod.c
+++ b/tools/depmod.c
@@ -1118,11 +1118,11 @@ static int depmod_module_is_higher_priority(const struct depmod *depmod, const s
 
 	if (strncmp(newpath, cfg->dirname, cfg->dirnamelen) == 0) {
 		relnewpath = newpath + cfg->dirnamelen + 1;
-		relnewlen = newlen - cfg->dirnamelen + 1;
+		relnewlen = newlen - (cfg->dirnamelen + 1);
 	}
 	if (strncmp(oldpath, cfg->dirname, cfg->dirnamelen) == 0) {
 		reloldpath = oldpath + cfg->dirnamelen + 1;
-		reloldlen = oldlen - cfg->dirnamelen + 1;
+		reloldlen = oldlen - (cfg->dirnamelen + 1);
 	}
 
 	for (ov = cfg->overrides; ov != NULL; ov = ov->next) {
-- 
2.15.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] depmod: fix override lookup
  2017-12-07 19:16 [PATCH 0/2] depmod: fix override lookup Yauheni Kaliuta
  2017-12-07 19:16 ` [PATCH 1/2] testsuite: depmod: add override test Yauheni Kaliuta
  2017-12-07 19:16 ` [PATCH 2/2] depmod: module_is_higher_priority: fix modname length calculation Yauheni Kaliuta
@ 2017-12-07 22:15 ` Lucas De Marchi
  2 siblings, 0 replies; 4+ messages in thread
From: Lucas De Marchi @ 2017-12-07 22:15 UTC (permalink / raw)
  To: Yauheni Kaliuta; +Cc: linux-modules

On Thu, Dec 7, 2017 at 11:16 AM, Yauheni Kaliuta
<yauheni.kaliuta@redhat.com> wrote:
> Add override test.
> Fix a relative path calculation mistake.
>
>
> Yauheni Kaliuta (2):
>   testsuite: depmod: add override test
>   depmod: module_is_higher_priority: fix modname length calculation

both patches applied, thanks.

Lucas De Marchi

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-07 19:16 [PATCH 0/2] depmod: fix override lookup Yauheni Kaliuta
2017-12-07 19:16 ` [PATCH 1/2] testsuite: depmod: add override test Yauheni Kaliuta
2017-12-07 19:16 ` [PATCH 2/2] depmod: module_is_higher_priority: fix modname length calculation Yauheni Kaliuta
2017-12-07 22:15 ` [PATCH 0/2] depmod: fix override lookup Lucas De Marchi

Linux-Modules Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-modules/0 linux-modules/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-modules linux-modules/ https://lore.kernel.org/linux-modules \
		linux-modules@vger.kernel.org linux-modules@archiver.kernel.org
	public-inbox-index linux-modules


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-modules


AGPL code for this site: git clone https://public-inbox.org/ public-inbox