Commit Graph

893 Commits

Author SHA1 Message Date
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
John Spencer
bd4e7340bc testsuite: fix usage of reserved names
stdout and stderr are names reserved for the implementation
and musl uses them rightfully as macro - and the expansion
causes (of course) unexpected results.

rename the struct members stdout to out and stderr
to err, to be 1) compliant 2) cause compilation to
succeed.

fixes build with musl libc.
2013-08-29 01:22:20 -03:00
Lucas De Marchi
18811d22e9 kmod 15 2013-08-22 10:44:08 -03:00
Lucas De Marchi
493dc650d6 libkmod: Fix getting param with no value from kcmdline 2013-08-13 22:04:46 -03:00
Lucas De Marchi
ea225b982c testsuite: Add test for parameter with no value in kcmdline
Currently we fail to add the module option if the parameter doesn't have
a value.
2013-08-13 22:03:26 -03:00
Jan Engelhardt
c1170883b4 depmod: add missing "else" clause
It occurred to an openSUSE user that our mkinitrd would throw a
warning when used with kmod:

libkmod: conf_files_list: unsupported file mode /dev/null: 0x21b6

Grepping for the error message revealed that there might be a missing
"else" keyword here, since it is unusual to put an "if" directly after
closing brace.
2013-08-09 12:01:10 -03:00
Lucas De Marchi
48a4096441 shell-completion: Make options accept '=' as last char 2013-08-02 12:07:39 -03:00
Lucas De Marchi
80cf2c8f05 build: Install bash completion data 2013-07-30 14:45:21 -03:00
Lucas De Marchi
ec6d026f26 shell-completion: Add kmod static-nodes 2013-07-30 14:45:21 -03:00
Lucas De Marchi
ac6573aab4 shell-completion: Add initial completion for kmod
Based on journalctl and udevadm from systemd and adapted to kmod needs.
2013-07-30 14:45:18 -03:00
Lucas De Marchi
b3e19ce92e NEWS: Add entries 2013-07-17 02:31:50 -03:00
Lucas De Marchi
cd923111c6 README: Move items from TODO
Put the differences between kmod and module-init-tools in the README
file so it's more visible.
2013-07-17 02:31:27 -03:00
Tom Gundersen
232bf4d863 static-nodes: create parent directories of output file
Allows us to drop call to "mkdir -p" from the systemd service file.
2013-07-15 12:46:12 -03:00
Lucas De Marchi
fa6fc9f0b8 util: Add mkdir_parents()
Like mkdir_p, but discards the leaf, creating the parent directories.
2013-07-15 12:45:35 -03:00
Lucas De Marchi
c493b93750 util: Add len arg to mkdir_p() 2013-07-15 12:44:33 -03:00
Tom Gundersen
ae17710117 static-nodes: don't fail if modules.devname not found
In containers/VM's/initrd one might not have installed any modules and
accompanying modules.devname Don't fail if this is the case, just warn.

When used in systemd this means we don't get a failing unit on booting
containers.
2013-07-15 12:44:33 -03:00