Commit Graph

1008 Commits

Author SHA1 Message Date
Lucas De Marchi aa72284f83 build-sys: Remove bogus line causing warning
./configure: line 14316: xyes: command not found

We are not using have_manpages, so remove it.
2014-03-24 14:53:56 -03:00
Lucas De Marchi ad7f1757c0 Add test for depmod using search dirs with same prefix
Test depmod with search dirs "foo" and "foobar". Previously to 49b33c1
("depmod: do not allow partial matches with "search" directive") we were
failing this test due to matching the prefix without checking if
it's the full dir name.

We are adding 2 tests here in order to catch the case we only pass the
test due to processing the directories in a favourable order.
2014-03-19 09:22:20 -03:00
Anssi Hannula 49b33c1f21 depmod: do not allow partial matches with "search" directive
Currently e.g. "search foo foobar built-in" will cause unpredictable
results if baz.ko is in both foo/ and foobar/, since "foo" in search may
match both of those directories and the preferred module therefore
depends on processing order.

Fix the code to ensure that the match is performed on full pathname
components only.
2014-03-19 09:18:39 -03:00
Lucas De Marchi aa0abec721 Add test for simple search order in depmod 2014-03-19 08:52:33 -03:00
Anssi Hannula 27881f6fbc depmod: fix debug print parameter order 2014-03-19 07:04:24 -03:00
Lucas De Marchi fea655dcb3 libkmod-elf: Fix check by class in get_modversions()
Commit 51c409b ("Cache the offset of crc") unintentinally changed the
comparison "if (elf->class & KMOD_ELF_32)" to
"if (elf->class == KMOD_ELF_32)".

This has been reported by Serge Voilokov <serge0x76@gmail.com>:

	On Raspberry PI elf->class equals KMOD_ELF_32|KMOD_ELF_LSB so
	valid condition should be (elf->class & KMOD_ELF_32) instead of
	(elf->class == KMOD_ELF_32).

This fixes "modprobe --dump-modversions" failing on 32b systems.
2014-03-07 01:24:39 -03:00
Michal Marek 632fb7b463 testsuite: Fix uname() during glibc startup
In a specific configuration (chroot with the linux32 personality), the
modprobe_install_cmd_loop test failed, because the bash process handling
the install command segfaulted. The backtrace showed a uname() call
during libpthread initialization, at which point the environ pointer
hadn't been initialized yet:

	Program terminated with signal SIGSEGV, Segmentation fault.
	#0  0x080c1591 in getenv (name=<optimized out>,
	    name@entry=0xf775f850 "TESTSUITE_UNAME_R") at getenv.c:81
	81	      for (i = 0, len = strlen (name); environ[i]; i++)
	(gdb) bt
	#0  0x080c1591 in getenv (name=<optimized out>,
	    name@entry=0xf775f850 "TESTSUITE_UNAME_R") at getenv.c:81
	#1  0xf775f754 in uname (u=u@entry=0xff946350) at testsuite/uname.c:32
	#2  0xf74ffc6c in is_smp_system ()
	    at ../nptl/sysdeps/unix/sysv/linux/i386/smp.h:39
	#3  __pthread_initialize_minimal_internal () at nptl-init.c:460
	#4  0xf74fe32c in _init () at ../sysdeps/i386/crti.S:74
	#5  0x00000000 in ?? ()
	(gdb) p environ
	$1 = (char **) 0x0

I don't know why it only happend in the chroot, but glibc can call its
own functions and impose any restrictions before main() is started, so
we have to adapt.

Also, do not return error if there is an environment, but the
environment variable is not found. If uname() is called by kmod, then
the respective test will simply fail later. If it's something else
calling uname(), then we do not want to disturb the program.
2014-03-06 23:09:56 -03:00
Lucas De Marchi 3be5bf4646 man: use systemd as example instead of udev
Nowadays udev doesn't create nodes in /dev anymore. This role is rather
taken by systemd-tmpfiles on early boot so reference it generically as
systemd.
2014-03-06 02:47:05 -03:00
Lucas De Marchi eb18b26905 man: clarify the support to modules.dep file 2014-03-06 02:46:27 -03:00
Lucas De Marchi bccb4b2545 build-sys: Do not require xsltproc for installation of man pages
Same reason as found in this commit to systemd:

	commit 4ca39b280fce3c60d2fdecbd478fd9bf7f9d3e64
	Author: Mike Gilbert <floppym@gentoo.org>
	Date:   Sun Feb 23 11:21:13 2014 -0500

	    configure: Do not require xsltproc for installation of man pages

	    The release tarballs ship with pre-generated man pages, so we do not
	    need xsltproc for a typical end-user build.

	    Developers will probably have xsltproc anyway, but if not they will now
	    encounter a build-time failure instead of an error in configure.
2014-03-06 02:07:20 -03:00
Lucas De Marchi 06eb29e117 build-sys: add small redirecting Makefiles
These redirecting makefiles simplifies compiling from some editors and
when CWD is not the root of the source tree. This is similar to what was
introduced in systemd in 340d89e ("build-sys: add small redirecting
Makefiles to simplify compilation from within emacs")
2014-03-06 01:59:58 -03:00
Lucas De Marchi 49776627e6 testsuite: add test for '.' correctly parsed in param's value
In kcmdline it's possible to have a dot in the param's value. The
support for this was added in 66f3228 ("libkmod: Add support for '.' in
module parameter on kcmdline") and is needed to correctly support some
modules that depend on it.

This test was added in order to make sure the commit  aa87854
("libkmod-config: Only match dot before '=' in /proc/cmdline") didn't
break it. Although that commit  message says it's allowing to match a
dot before '=' it's actually enforcing the first part of the string to
be always in the format "<module-name>.param". Dots after '=' are still
correctly allowed.
2014-03-06 01:36:02 -03:00
Lucas De Marchi 4214902482 testsuite: add test to ignore unrelated strings in kcmdline
Strings unrelated to modules and modprobe should be ignored and not
appear in the output of "modprobe -c".

This adds a test for the fix provided in aa87854 ("libkmod-config: Only
match dot before '=' in /proc/cmdline").
2014-03-06 01:30:56 -03:00
Lucas De Marchi bad84a9e6e testsuite: give a more suitable description to test
We are not only checking if those options are correctly parsed from
kcmdline, but if in fact they are being passed to the final
(f)init_module call. This is why we use 'modprobe --show-depends'
instead of the simpler 'modprobe -c'.
2014-03-06 01:30:08 -03:00
Lucas De Marchi 55bcc4a5bd testsuite: add test for kcmdline params with no value
Use "modprobe -c" to dump the configuration. Since we configure our
rootfs to have only a /proc/cmdline file, this should dump the knowledge
we have from its parsed content.

Test if <module>.option, without any value is correctly parsed, as fixed
in commit 493dc65 ("libkmod: Fix getting param with no value from kcmdline")
2014-03-06 01:29:41 -03:00
Michal Marek aa878540e6 libkmod-config: Only match dot before '=' in /proc/cmdline
Otherwise, we also parse strings like

  BOOT_IMAGE=/boot/vmlinuz-3.12.12-57.g5f654cf-default

In practice, this is not a problem, because there is no module named
BOOT_IMAGE=/boot/vmlinuz-3. It just disturbs in modprobe -c output.
2014-03-05 12:30:52 -03:00
Michal Marek 519d27de5a libkmod-config,depmod: Accept special files as configuration files, too
If we can open it and read it, it's good enough for us. Otherwise, we
cannot use -C /dev/null to skip the system configuration for instance:

$ ./tools/modprobe -C /dev/null -c
libkmod: ERROR libkmod/libkmod-config.c:821 conf_files_list: unsupported
file mode /dev/null: 0x21b6
...
2014-03-05 12:27:24 -03:00
Michal Marek c2f4d85a9a libkmod-module: Simplify kmod_module_insert_module()
Store the file and elf pointer in the kmod_module structure and have it
freed together with the module.
2014-03-05 12:22:37 -03:00
Michal Marek be29c40e25 Add some tests for kernels without finit_module(2) 2014-03-05 12:22:37 -03:00
Michal Marek 063086e038 testsuite: Do not provide finit_module(2) on older kernels
If the test's uname -r is less that 3.8, return -ENOSYS from
finit_module(), so that the fallback is tested.
2014-03-05 12:22:37 -03:00
Michal Marek 2ce5de0ae6 testsuite: Add test for modprobe --force
There is no check if the correct flags are passed to finit_module, but
at least we cover the respective code path in kmod.
2014-03-05 12:22:37 -03:00
Michal Marek 88ac40840f testsuite: Check the list of loaded modules after a test
Add a ->modules_loaded member to struct test, which is a comma-separated
list of modules that should be present after the test finishes. Both
missing and excess modules cause an error.
2014-03-05 12:22:37 -03:00
Stephen Kitt a4bd1441e5 Remove "rmmod -w" documentation and getopt entry
This patch removes the cmdopts declaration and the documentation. They
were leftover from the -w removal.
2014-01-26 18:00:23 -02:00
Lukas Berk 3d51a2f6ef man: insmod documentation fix
Add comma between lsmod(8) and modinfo(8)

Signed-off-by: Lukas Berk <lberk@redhat.com>
2014-01-24 10:23:30 -02:00
Lucas De Marchi 366e2ed791 Remove duplicate includes
Found by
https://raw.github.com/karelzak/util-linux/master/tools/checkincludes.pl
2014-01-21 14:03:02 -02:00
Lucas De Marchi 2726da5768 man: Change my contact email address 2014-01-02 17:13:38 -02:00
Lucas De Marchi 36c4bb928a kmod 16 2013-12-22 19:45:19 -02:00
Lucas De Marchi d96ca9c429 Use C11's noreturn
Also define noreturn w/o <stdnoreturn.h> and move it to macro.h instead
of in the testsuite.

Based on similar commit on systemd by Shawn Landden
<shawn@churchofgit.com>.
2013-12-17 19:10:16 -02:00
Lucas De Marchi 9f02561d84 module: use _cleanup_free and remove useless call to free() 2013-11-18 11:56:57 -02:00
Lucas De Marchi d3c16c7946 file: use _cleanup_free_ 2013-11-18 11:43:10 -02:00
Lucas De Marchi cacbcc4215 array: avoid duplicate code to reallocate 2013-11-18 11:29:11 -02:00
Lucas De Marchi 9c306bad2e util: Be OOM-safe and use _cleanup_free_ 2013-11-18 11:01:16 -02:00
Lucas De Marchi 1dda626f6b testsuite: add basic test for getline_wrapped 2013-11-18 11:01:16 -02:00
Lucas De Marchi b93d800640 util: use _cleanup_free_ on path_make_absolute_cwd() 2013-11-18 05:22:33 -02:00
Lucas De Marchi 342e9cea26 config: Use _cleanup_free_ 2013-11-18 04:35:04 -02:00
Lucas De Marchi d7aa6e23fc util: Add cleanup attribute 2013-11-18 04:35:04 -02:00
Lucas De Marchi 807c601df2 testsuite: Move test-alias to test-util
Move file so we can use the same file to test other functions from
libkmod-util.c
2013-11-18 04:35:03 -02:00
Anders Olofsson f5cc26c77d build: Allow disabling maintainer mode
This allows make rules for generated build files (i.e.  configure,
Makefile.in, ... ) to be skipped.  This is useful when
the source is stored without timestamps (for example in CVS or GIT).

When the build rules trigger to regenerate the build files, it tries to
use the same autotools version (currently 1.14) as was originally used
for the release.  Since many of our build machines run Debian Squeeze,
they only have autotools 1.11 available and the build fails.

Currently, we have to work around this by touching all the generated
files before building to avoid triggering the make rule. With this
patch, we would be able to just run configure with
--disable-maintainer-mode instead.  The patch sets the default to enable
to not change the default behavior.
2013-11-10 23:41:32 -02:00
Lucas De Marchi b3e0a07566 build-sys: enable colored diagnostics if available 2013-10-26 02:54:21 -02:00
Saul Wold 518daf4fd1 Makefile.am: add mkdir testsuite
If we are note building in the existing source tree and have disabled
dependency-tracking then the testsuite directory is not created during
the configure phase and will not exist when the cp of ROOTFS_PRISTINE
occurs, thus causing an error and fail.
2013-10-10 11:23:44 -03:00
Saul Wold 16535abe3a Makefile.am: Add target to all cross-compilation of testsuite
The buildtest-TESTS target allows for cross-compilation of the testsuites
without the actual running of the tests that check normally does.
2013-10-10 01:17:09 -03:00
Lucas De Marchi 8f67ab5340 NEWS: add entries 2013-09-20 01:50:40 -05:00
Lucas De Marchi 017893f244 rmmod: remove --wait option
Let libkmod enforce KMOD_REMOVE_NOWAIT.
2013-09-20 01:42:04 -05:00
Lucas De Marchi 7ab8804448 libkmod: always pass O_NONBLOCK to kernel
Not passsing O_NONBLOCK to delete_module() is deprecated since kmod 11
and is being removed from the kernel. Force this flag in libkmod.
2013-09-20 01:37:24 -05:00
Lucas De Marchi 82fc7d986c libkmod-hash: always align n_buckets to power of 2
By aligning n_buckets to power of 2 we can turn the "bucket = hashval %
n_buckets" into a less expensive bucket = hashval & (n_buckets - 1).
This removes the DIV instruction as shown below.

Before:
	xor    %edx,%edx
	divl   0x8(%rbx)
	mov    %edx,%eax
	add    $0x1,%rax
	shl    $0x4,%rax
	add    %rbx,%rax

After:
	lea    -0x1(%rdi),%edx
	and    %edx,%eax
	add    $0x1,%rax
	shl    $0x4,%rax
	add    %rbx,%rax

With a microbenchmark, measuring the time to locate the bucket (i.e.
time_to_calculate_hashval + time_to_calculate_bucket_position) we have
the results below (time in clock cycles):

	keylen      before   after
	2-10          79.0    61.9 (-21.65%)
	11-17         81.0    64.4 (-20.48%)
	18-25         90.0    73.2 (-18.69%)
	26-32        104.7    87.0 (-16.82%)
	33-40        108.4    89.6 (-17.37%)
	41-48        111.2    91.9 (-17.38%)
	49-55        120.1   102.1 (-15.04%)
	56-63        134.4   115.7 (-13.91%)

As expected the gain is constant, regardless of the key length.
The time to clculate the hashval varies with the key length, which
explains the bigger gains for short keys.
2013-09-20 01:10:37 -05:00
Lucas De Marchi 3ba7f59e84 util: Add ALIGN_POWER2
Add static inline function to align a value to it's next power of 2.
This is commonly done by a SWAR like the one in:

http://aggregate.org/MAGIC/#Next Largest Power of 2

However a microbench shows that the implementation herer is a faster.
It doesn't really impact the possible user of this function, but it's
interesting nonetheless.

Using a x86_64 i7 Ivy Bridge it shows a ~4% advantage by using clz
instead instead of the OR and SHL chain. And this is by using a BSR
since Ivy Bridge doesn't have LZCNT. New Haswell processors have the
LZCNT instruction which can make this even better. ARM also has a CLZ
instruction so it should be better, too.

Code used to test:

	...
	v = val[i];
	t1 = get_cycles(0);
	a = ALIGN_POWER2(v);
	t1 = get_cycles(t1);

	t2 = get_cycles(0);
	v = nlpo2(v);
	t2 = get_cycles(t2);

	printf("%u\t%llu\t%llu\t%d\n", v, t1, t2, v == a);
	...

In which val is an array of 20 random unsigned int, nlop2 is the SWAR
implementation and get_cycles uses RDTSC to measure the performance.

Averages:
	ALIGN_POWER2: 	30 cycles
	nlop2:		31.4 cycles
2013-09-20 01:08:46 -05:00
Tom Gundersen 6506ddf5a3 depmod: warn on invalid devname specification
During the last merge window (3.12) a couple of modules gained devname
aliases, but without the necessary major and minor information. These were
then silently ignored when generating modules.devname.

Complain loudly to avoid such errors sneaking in undetected in the future:

    depmod: ERROR: Module 'zram' has devname (zram) but lacks major and minor information. Ignoring.
    depmod: ERROR: Module 'uhid' has devname (uhid) but lacks major and minor information. Ignoring.

Cc: Kay Sievers <kay@vrfy.org>
Cc: Lucas De Marchi <lucas.demarchi@profusion.mobi>
2013-09-10 00:49:41 -03:00
Lucas De Marchi 4c2dc16a2e build: remove check for typeof
It's used in so many places without checking, that's really pointless to
check for it in macro.h.

Also remove AC_C_TYPEOF from configure.ac since we don't use -ansi.
2013-09-06 11:31:35 -03:00
Thomas Petazzoni dc8ed09f8f Add configure check for _Static_assert()
Commit 8efede20ef ("Use _Static_assert") introduced the usage of
_Static_assert(). However, _Static_assert() is a fairly new thing,
since it was introduced only in gcc 4.6. In order to support older
compilers, this patch adds a configure.in test that checks whether
_Static_assert() is usable or not, and adjust the behavior of the
assert_cc() macro accordingly.
2013-09-06 11:06:19 -03:00
Lucas De Marchi 7e0385c47a Fix usage of readdir_r()
With readdir_r() we should be providing enough space to store the dir
name. This could be accomplished by define an union like systemd does:

	union dirent_storage {
		struct dirent de;
		uint8_t storage[offsetof(struct dirent, d_name) +
				((NAME_MAX + 1 + sizeof(long)) & ~(sizeof(long) - 1))];
	};

However in all places that we use readdir_r() we have no concerns about
reentrance nor we have problems with threads. Thus use the simpler
readdir() instead.

We also remove the error logging here (that could be added back by
checking errno), but it was not adding much value so it's gone.
2013-08-29 01:33:51 -03:00