kpatch-build: find_parent_obj should search subdirs

The kpatch-build :: find_parent_obj() function's "deep find" may
failed to find objects if they are not located in current directory:

	ERROR: invalid ancestor xxx/xxx.o for xxx/xxx.o.

This is reproducable when building an out-of-tree module of the
following structure:

	wwheart@linux41:~/helloworld 0 > tree -a
	.
	├── buffer_overflow1.ko
	├── .buffer_overflow1.ko.cmd
	├── buffer_overflow1.mod.c
	├── buffer_overflow1.mod.o
	├── .buffer_overflow1.mod.o.cmd
	├── buffer_overflow1.o
	├── .buffer_overflow1.o.cmd
	├── hello.c
	├── hello.o
	├── .hello.o.cmd
	├── Makefile
	├── modules.order
	├── Module.symvers
	├── test.patch
	├── .tmp_versions
	│   └── buffer_overflow1.mod
	└── xxx
	    ├── xxx.c
	    ├── xxx.h
	    ├── xxx.o
	    └── .xxx.o.cmd

	wwheart@linux41:~/helloworld 0 > cat test.patch
	diff --git a/xxx/xxx.c b/xxx/xxx.c
	index aab3c67..d81ad00 100644
	--- a/xxx/xxx.c
	+++ b/xxx/xxx.c
	@@ -1,6 +1,7 @@
	#include <linux/kernel.h>
	void czf_test(void)
	{
	+       printk("livepatch test\n");
		printk("xxx\n");
	}

	wwheart@linux41:~/helloworld 0 > cat Makefile
	obj-m += buffer_overflow1.o
	buffer_overflow1-y += hello.o xxx/xxx.o

Modify the deep find to traverse sub-directories in order to search
the entire tree instead of only the current directory.

Fixes: 8c2792af6c ("kpatch-build: deep find performance improvement")

Signed-off-by: chenzefeng <chenzefeng2@huawei.com>
This commit is contained in:
chenzefeng 2019-05-05 15:42:08 +08:00
parent 9f1a0b85a8
commit eb4f5833e0

View File

@ -323,8 +323,8 @@ find_parent_obj() {
num="$(grep -l "$grepname" "$last_deep_find"/.*.cmd | grep -Fvc "$pdir/.${file}.cmd")"
fi
if [[ "$num" -eq 0 ]]; then
parent="$(find ./* -name ".*.cmd" -print0 | xargs -0 grep -l "$grepname" | grep -Fv "$pdir/.${file}.cmd" | cut -c3- | head -n1)"
num="$(find ./* -name ".*.cmd" -print0 | xargs -0 grep -l "$grepname" | grep -Fvc "$pdir/.${file}.cmd")"
parent="$(find . -name ".*.cmd" -print0 | xargs -0 grep -l "$grepname" | grep -Fv "$pdir/.${file}.cmd" | cut -c3- | head -n1)"
num="$(find . -name ".*.cmd" -print0 | xargs -0 grep -l "$grepname" | grep -Fvc "$pdir/.${file}.cmd")"
[[ "$num" -eq 1 ]] && last_deep_find="$(dirname "$parent")"
fi
else