Commit graph

38 commits

Author SHA1 Message Date
Michal Schmidt d5099efc47 hashmap: introduce hash_ops to make struct Hashmap smaller
It is redundant to store 'hash' and 'compare' function pointers in
struct Hashmap separately. The functions always comprise a pair.
Store a single pointer to struct hash_ops instead.

systemd keeps hundreds of hashmaps, so this saves a little bit of
memory.
2014-09-15 16:08:50 +02:00
Zbigniew Jędrzejewski-Szmek 73f860db98 Always prefer our headers to system headers
In practice this shouldn't make much difference, but
sometimes our headers might be newer, and we want to
test them.
2014-07-31 08:56:03 -04:00
Lennart Poettering 03e334a1c7 util: replace close_nointr_nofail() by a more useful safe_close()
safe_close() automatically becomes a NOP when a negative fd is passed,
and returns -1 unconditionally. This makes it easy to write lines like
this:

        fd = safe_close(fd);

Which will close an fd if it is open, and reset the fd variable
correctly.

By making use of this new scheme we can drop a > 200 lines of code that
was required to test for non-negative fds or to reset the closed fd
variable afterwards.
2014-03-18 19:31:34 +01:00
Lennart Poettering fb818b2ea1 util: use alloca0() intead of alloca() + memzero() 2014-01-31 17:48:36 +01:00
Greg KH 29804cc1e0 use memzero(foo, length); for all memset(foo, 0, length); calls
In trying to track down a stupid linker bug, I noticed a bunch of
memset() calls that should be using memzero() to make it more "obvious"
that the options are correct (i.e. 0 is not the length, but the data to
set).  So fix up all current calls to memset(foo, 0, length) to
memzero(foo, length).
2014-01-31 11:55:01 +01:00
Zbigniew Jędrzejewski-Szmek b47d419c25 Modernization
Fixes minor leak in error path in device.c.
2013-10-13 17:56:54 -04:00
Zbigniew Jędrzejewski-Szmek 7ff7394d9e Never call qsort on potentially NULL arrays
This extends 62678ded 'efi: never call qsort on potentially
NULL arrays' to all other places where qsort is used and it
is not obvious that the count is non-zero.
2013-10-13 17:56:54 -04:00
Zbigniew Jędrzejewski-Szmek c51cf05646 Rename F_TYPE_CMP() to F_TYPE_EQUAL() 2013-08-20 21:18:43 -04:00
Michael Marineau 4b357e1587 build-sys: Add configure check for linux/btrfs.h
btrfs.h was added to uapi in Linux 3.9. To fix building with older
header versions this adds a configure check for the header and re-adds
btrfs definitions to missing.h which was removed in bed2e820 along with
two other ioctls used by gpt-auto-generator.

[ Apparently, btrfs.h was only added recently:
  http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=55e301fd57a6239ec14b91a1cf2e70b3dd135194
  let's re-add it for now -- kay ]
2013-08-16 23:29:41 +02:00
Lennart Poettering bed2e820db missing: use btrfs.h instead of defining our own btrfs structures 2013-08-13 10:12:35 +02:00
Zbigniew Jędrzejewski-Szmek ef42202ac8 Add set_consume which always takes ownership
Freeing in error path is the common pattern with set_put().
2013-04-24 00:25:04 -04:00
Harald Hoyer bdd29249a8 Reintroduce f_type comparison macro
This reverts commit 4826f0b7b5.

Because statfs.t_type can be int on some architecures, we have to cast
the const magic to the type, otherwise the compiler warns about
signed/unsigned comparison, because the magic can be 32 bit unsigned.

statfs(2) man page is also wrong on some systems, because
f_type is not __SWORD_TYPE on some architecures.

The following program:

int main(int argc, char**argv)
{
        struct statfs s;
        statfs(argv[1], &s);

	printf("sizeof(f_type) = %d\n", sizeof(s.f_type));
	printf("sizeof(__SWORD_TYPE) = %d\n", sizeof(__SWORD_TYPE));
	printf("sizeof(long) = %d\n", sizeof(long));
	printf("sizeof(int) = %d\n", sizeof(int));
	if (sizeof(s.f_type) == sizeof(int)) {
		printf("f_type = 0x%x\n", s.f_type);
	} else {
                printf("f_type = 0x%lx\n", s.f_type);
	}
        return 0;
}

executed on s390x gives for a btrfs:

sizeof(f_type) = 4
sizeof(__SWORD_TYPE) = 8
sizeof(long) = 8
sizeof(int) = 4
f_type = 0x9123683e
2013-04-19 13:59:07 +02:00
Harald Hoyer 4826f0b7b5 Revert f_type fixups
This reverts commit a858b64ddd.
This reverts commit aea275c431.
This reverts commit fc6e6d245e.
This reverts commit c4073a27c5.
This reverts commit cddf148028.
This reverts commit 8c68a70170.

The constants are now casted to __SWORD_TYPE, which should resolve the
compiler warnings about signed vs unsigned.

After talking to Kay, we concluded:

This should be fixed in the kernel, not worked around in userspace tools.

Architectures cannot use int and expect magic constants lager than INT_MAX
to work correctly. The kernel header needs to be fixed.

Even coreutils cannot handle it:
  #define RAMFS_MAGIC  0x858458f6
  # stat -f -c%t /
  ffffffff858458f6

  #define BTRFS_SUPER_MAGIC 0x9123683E
  # stat -f -c%t /mnt
  ffffffff9123683e

Although I found the perfect working macro to fix the thing :)

        __extension__ ({                                                \
                        bool _ret = false;                              \
                        switch(f) { case c: _ret=true; };               \
                        ( _ret );                                       \
                })
2013-04-18 15:01:55 +02:00
Harald Hoyer aea275c431 rename CMP_F_TYPE to F_TYPE_CMP 2013-04-18 08:06:55 +02:00
Harald Hoyer fc6e6d245e Add ugly CMP_F_TYPE() macro
On some architectures (like s390x) the kernel has the type int for
f_type, but long in userspace.
Assigning the 32 bit magic constants from linux/magic.h to the 31 bit
signed f_type in the kernel, causes f_type to be negative for some
constants.
glibc extends the int to long for those architecures in 64 bit mode, so
the negative int becomes a negative long, which cannot be simply
compared to the original magic constant, because the compiler would
automatically cast the constant to long.
To workaround this issue, we also compare to the (int)MAGIC value in a
macro. Of course, we could do #ifdef with the architecure, but it has to
be maintained, and the magic constants are 32 bit anyway.

Someday, when the int is unsigned or long for all architectures, we can
remove this macro again. Until then, keep it as simple as it can be.
2013-04-18 07:34:25 +02:00
Harald Hoyer c4073a27c5 fixup for cddf148028
Instead of making a type up, just use __SWORD_TYPE, after reading
statfs(2).

Too bad, this does not fix s390x because __SWORD_TYPE is (long int) and
the kernel uses (int) to fill in the field!!!!!!
2013-04-17 19:00:50 +02:00
Harald Hoyer cddf148028 fixup 8c68a7017 and cast to (unsigned long) 2013-04-17 18:23:17 +02:00
Harald Hoyer 8c68a70170 fixed statfs.f_type signed vs unsigned comparisons
statfs.f_type is signed but the filesystem magics are unsigned.
Casting the magics to signed will not make the signed.

Problem seen on big-endian 64bit s390x with __fsword_t 8 bytes.

Casting statfs.f_type to unsigned on the other hand will get us what we
need.

https://bugzilla.redhat.com/show_bug.cgi?id=953217
2013-04-17 18:14:25 +02:00
Zbigniew Jędrzejewski-Szmek b92bea5d2a Use initalization instead of explicit zeroing
Before, we would initialize many fields twice: first
by filling the structure with zeros, and then a second
time with the real values. We can let the compiler do
the job for us, avoiding one copy.

A downside of this patch is that text gets slightly
bigger. This is because all zero() calls are effectively
inlined:

$ size build/.libs/systemd
         text    data     bss     dec     hex filename
before 897737  107300    2560 1007597   f5fed build/.libs/systemd
after  897873  107300    2560 1007733   f6075 build/.libs/systemd

… actually less than 1‰.

A few asserts that the parameter is not null had to be removed. I
don't think this changes much, because first, it is quite unlikely
for the assert to fail, and second, an immediate SEGV is almost as
good as an assert.
2013-04-05 19:50:57 -04:00
Zbigniew Jędrzejewski-Szmek 7989e1f2d7 Partially revert e62d8c3944
The ~80 chars per line part wasn't well received.
2013-03-31 19:50:30 -04:00
Zbigniew Jędrzejewski-Szmek e62d8c3944 Modernization
Use _cleanup_ and wrap lines to ~80 chars and such.
2013-03-31 14:36:12 -04:00
Auke Kok b0640287f7 readahead: cleanups
- check for OOM
- no need to use floats and round()
2013-03-26 11:35:27 -07:00
Auke Kok 94243ef299 readahead: chunk on spinning media
Readahead has all sorts of bad side effects depending on your
storage media. On rotating disks, it may be degrading startup
performance if enough requests are queued spanning linearly
over all blocks early at boot, and mount, blkid and friends
want to insert reads to the start of these block devices after.

The end result is that on spinning disks with ext3/4 that udev
and mounts take a very long time, and nothing really happens until
readahead is completely finished.

This has the net effect that the CPU is almost entirely idle
for the entire period that readahead is working. We could have
finished starting up quite a lot of services in this time if
we were smarter at how we do readahead.

This patch sorts all requests into 2 second "chunks" and sub-sorts
each chunk by block. This adds a single cross-drive seek per "chunk"
but has the benefit that we will have a lot of the blocks we need
early on in the boot sequence loaded into memory faster.

For a comparison of how before/after bootcharts look (ext4 on a
mobile 5400rpm 250GB drive) please look at:

    http://foo-projects.org/~sofar/blocked-tests/

There are bootcharts in the "before" and "after" folders where you
should be able to see that many low-level services finish 5-7
seconds earlier with the patch applied (after).
2013-03-26 10:32:32 -07:00
Michal Schmidt c4b996bd87 readahead: fix fd validity check
https://bugzilla.redhat.com/show_bug.cgi?id=868603
2012-10-22 22:08:06 +02:00
Lennart Poettering a8348796c0 missing: define name_to_handle_at on our own if it is missing 2012-09-04 15:30:24 -07:00
Shawn Landden 0d0f0c50d3 log.h: new log_oom() -> int -ENOMEM, use it
also a number of minor fixups and bug fixes: spelling, oom errors
that didn't print errors, not properly forwarding error codes,
few more consistency issues, et cetera
2012-07-26 11:48:26 +02:00
Shawn Landden 669241a076 use "Out of memory." consistantly (or with "\n")
glibc/glib both use "out of memory" consistantly so maybe we should
consider that instead of this.

Eliminates one string out of a number of binaries. Also fixes extra newline
in udev/scsi_id
2012-07-25 11:23:57 +02:00
Lennart Poettering 87ce22cc0d readahead: merge three binaries into one
since the binaries share much of the same code and we better load only
one binary instead of two from disk at early boot let's merge the three
readahead binaries into one. This also allows us to drop a lot of
duplicated code.
2012-06-21 23:53:20 +02:00
Auke Kok cae544bcdb readahead: Add tool to analyze the contents of the pack file. v3.
This patch adds code to compile 'systemd-readahead-analyze' and install
it into $bindir.

Use this program to parse the contents of the readahead pack file, or
an arbitrary pack file and display which files are listed in it, and
how much of the files are requested to be readahead.

This code is not new - it's partially taken from sreadahead (formerly
maintained by Arjan van der Ven and me, and was originally written
by me), and adapted with the right bits to parse the systemd
readahead pack files, which are slightly different in format.

v2 adds a common READAHEAD_PACK_FILE_VERSION used in all the code
to provide a quick way to assure all these programs are always
synchronized. v3 fixes the integer math.
2012-06-05 22:45:37 +02:00
Lennart Poettering e905f48fdc readahead: avoid activating the journal by accident, log directly to kmsg 2012-05-23 03:50:53 +02:00
Lennart Poettering 189455ab08 readahead: store inode numbers in pack file
If the inode nr for each file is available in the pack file we can
easily detect replaced files (like they result from package upgrades)
which we can then skip to readahead.
2012-05-04 00:34:12 +02:00
Lennart Poettering 4019a16d5b units: use OOMScoreAdjust= in the unit files to set OOM score adjust 2012-05-04 00:15:21 +02:00
Lennart Poettering 6de338a2d9 readhead: temporarily lower the kernel's read_ahead_kb setting while collecting
While collecting readahead data we want to know exactly what userspace
accesses unblurred by the kernel's read_ahead_kb. Hence lower this
during collection, and raise it afterwards.

This is mostly based on ideas and code by Auke Kok.
2012-05-04 00:13:20 +02:00
Lennart Poettering 3b2d5b02ae readahead: rather than checking for virtualization in the C code, use ConditionVirtualization= in the unit 2012-04-24 13:14:40 +02:00
Lennart Poettering 5430f7f2bc relicense to LGPLv2.1 (with exceptions)
We finally got the OK from all contributors with non-trivial commits to
relicense systemd from GPL2+ to LGPL2.1+.

Some udev bits continue to be GPL2+ for now, but we are looking into
relicensing them too, to allow free copy/paste of all code within
systemd.

The bits that used to be MIT continue to be MIT.

The big benefit of the relicensing is that closed source code may now
link against libsystemd-login.so and friends.
2012-04-12 00:24:39 +02:00
Lennart Poettering 4cfa2c999d core: switch all log targets to go directly to the journal, instead via syslog 2012-01-12 05:09:06 +01:00
Lennart Poettering 81527be142 build-sys: move public header files into a dir of their own 2012-01-05 16:01:58 +01:00
Lennart Poettering e5e83e8362 build-sys: make readahead and vconsole optional 2011-12-31 19:45:41 +01:00
Renamed from src/readahead-collect.c (Browse further)