[systemd-commits] 2 commits - fixme src/readahead-collect.c src/readahead-common.c src/readahead-common.h src/readahead-replay.c

Lennart Poettering lennart at kemper.freedesktop.org
Tue Sep 28 12:49:32 PDT 2010


 fixme                   |   34 ++++++++++++++++------------
 src/readahead-collect.c |   58 ++++++++++++++++++++++++++++++------------------
 src/readahead-common.c  |   30 ++++++++++++++++++++++++
 src/readahead-common.h  |   10 ++++++++
 src/readahead-replay.c  |    8 ++++++
 5 files changed, 105 insertions(+), 35 deletions(-)

New commits:
commit 59fee421a08818a4c975d811f78a9a7082cc5ecd
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Sep 28 21:49:26 2010 +0200

    sort fixme for v11 todo list

diff --git a/fixme b/fixme
index 557d9c0..1782a04 100644
--- a/fixme
+++ b/fixme
@@ -1,9 +1,4 @@
-* do not throw error when .service file is linked to /dev/null
-
-* oneshot services which do not remain: 'exited' instead of 'dead'?
-  it should be visible in 'systemctl' that they have been run
-
-* dot output for --test showing the 'initial transaction'
+v11:
 
 * have a simple syslog bridge providing /dev/log and forward messages
   to /dev/kmsg. at the moment the real syslog can be started, the bridge
@@ -12,6 +7,25 @@
   support in the kernel ringbuffer, without any syslog service or disk
   access
 
+* emergency.service should start default.target after C-d. synchronize from fedora's initscripts package
+
+* tmpwatch: lower ioprio
+
+* drop empty assignments for parse_env_file
+
+* stability promise must say that #ifdef TARGET_XXX style distro compatibility will go away one day
+
+* enable tmpfiles by default
+
+later:
+
+* do not throw error when .service file is linked to /dev/null
+
+* oneshot services which do not remain: 'exited' instead of 'dead'?
+  it should be visible in 'systemctl' that they have been run
+
+* dot output for --test showing the 'initial transaction'
+
 * calendar time support in timer, iCalendar semantics for the timer stuff (RFC2445)
 
 * implicitly import "defaults" settings file into all types
@@ -73,8 +87,6 @@
 
 * passphrase agent https://bugs.freedesktop.org/show_bug.cgi?id=30038
 
-* emergency.service should start default.target after C-d.
-
 * support dbus introspection in mid-level object paths, i.e. in /org/freedesktop/systemd/units/.
 
 * systemctl auto-pager a la git
@@ -91,14 +103,8 @@
 
 * properly handle multiple inotify events per read() in path.c and util.c
 
-* tmpwatch: lower ioprio
-
 * readahead: btrfs/LVM SSD detection
 
-* stability promise must say that #ifdef TARGET_XXX style distro compatibility will go away one day
-
-* drop empty assignments for parse_env_file
-
 * document locale.conf, vconsole.conf and possibly the tempfiles.d and modules-load.d mechanism.
 
 External:
commit d9c7a87b35289e9a5ba94c097e861640d1357e6d
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Sep 28 21:46:14 2010 +0200

    readahead: ignore replay events when collecting

diff --git a/src/readahead-collect.c b/src/readahead-collect.c
index 0838dd3..5c09f7a 100644
--- a/src/readahead-collect.c
+++ b/src/readahead-collect.c
@@ -64,6 +64,8 @@ static unsigned arg_files_max = 16*1024;
 static off_t arg_file_size_max = READAHEAD_FILE_SIZE_MAX;
 static usec_t arg_timeout = 2*USEC_PER_MINUTE;
 
+static ReadaheadShared *shared = NULL;
+
 /* Avoid collisions with the NULL pointer */
 #define SECTOR_TO_PTR(s) ULONG_TO_PTR((s)+1)
 #define PTR_TO_SECTOR(p) (PTR_TO_ULONG(p)-1)
@@ -379,36 +381,44 @@ static int collect(const char *root) {
                 }
 
                 for (m = &data.metadata; FAN_EVENT_OK(m, n); m = FAN_EVENT_NEXT(m, n)) {
+                        char fn[PATH_MAX];
+                        int k;
 
-                        if (m->pid != my_pid && m->fd >= 0) {
-                                char fn[PATH_MAX];
-                                int k;
+                        if (m->fd < 0)
+                                goto next_iteration;
 
-                                snprintf(fn, sizeof(fn), "/proc/self/fd/%i", m->fd);
-                                char_array_0(fn);
+                        if (m->pid == my_pid)
+                                goto next_iteration;
 
-                                if ((k = readlink_malloc(fn, &p)) >= 0) {
+                        __sync_synchronize();
+                        if (m->pid == shared->replay)
+                                goto next_iteration;
 
-                                        if (startswith(p, "/tmp") ||
-                                            hashmap_get(files, p))
-                                                /* Not interesting, or
-                                                 * already read */
-                                                free(p);
-                                        else {
-                                                unsigned long ul;
+                        snprintf(fn, sizeof(fn), "/proc/self/fd/%i", m->fd);
+                        char_array_0(fn);
+
+                        if ((k = readlink_malloc(fn, &p)) >= 0) {
 
-                                                ul = fd_first_block(m->fd);
+                                if (startswith(p, "/tmp") ||
+                                    hashmap_get(files, p))
+                                        /* Not interesting, or
+                                         * already read */
+                                        free(p);
+                                else {
+                                        unsigned long ul;
 
-                                                if ((k = hashmap_put(files, p, SECTOR_TO_PTR(ul))) < 0) {
-                                                        log_warning("set_put() failed: %s", strerror(-k));
-                                                        free(p);
-                                                }
+                                        ul = fd_first_block(m->fd);
+
+                                        if ((k = hashmap_put(files, p, SECTOR_TO_PTR(ul))) < 0) {
+                                                log_warning("set_put() failed: %s", strerror(-k));
+                                                free(p);
                                         }
+                                }
 
-                                } else
-                                        log_warning("readlink(%s) failed: %s", fn, strerror(-k));
-                        }
+                        } else
+                                log_warning("readlink(%s) failed: %s", fn, strerror(-k));
 
+                next_iteration:
                         if (m->fd)
                                 close_nointr_nofail(m->fd);
                 }
@@ -635,6 +645,12 @@ int main(int argc, char *argv[]) {
                 return 0;
         }
 
+        if (!(shared = shared_get()))
+                return 1;
+
+        shared->collect = getpid();
+        __sync_synchronize();
+
         if (collect(optind < argc ? argv[optind] : "/") < 0)
                 return 1;
 
diff --git a/src/readahead-common.c b/src/readahead-common.c
index a2f6f17..e01ae60 100644
--- a/src/readahead-common.c
+++ b/src/readahead-common.c
@@ -25,6 +25,9 @@
 #include <string.h>
 #include <sys/sysinfo.h>
 #include <sys/inotify.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <unistd.h>
 
 #include "log.h"
 #include "readahead-common.h"
@@ -137,3 +140,30 @@ int open_inotify(void) {
 
         return fd;
 }
+
+ReadaheadShared *shared_get(void) {
+        int fd;
+        ReadaheadShared *m = NULL;
+
+        if ((fd = open("/dev/.systemd/readahead/shared", O_CREAT|O_RDWR|O_CLOEXEC, 0644)) < 0) {
+                log_error("Failed to create shared memory segment: %m");
+                goto finish;
+        }
+
+        if (ftruncate(fd, sizeof(ReadaheadShared)) < 0) {
+                log_error("Failed to truncate shared memory segment: %m");
+                goto finish;
+        }
+
+        if ((m = mmap(NULL, sizeof(ReadaheadShared), PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) {
+                log_error("Failed to mmap shared memory segment: %m");
+                m = NULL;
+                goto finish;
+        }
+
+finish:
+        if (fd >= 0)
+                close_nointr_nofail(fd);
+
+        return m;
+}
diff --git a/src/readahead-common.h b/src/readahead-common.h
index 3f64f29..7add626 100644
--- a/src/readahead-common.h
+++ b/src/readahead-common.h
@@ -23,6 +23,9 @@
 ***/
 
 #include <sys/stat.h>
+#include <sys/types.h>
+
+#include "macro.h"
 
 #define READAHEAD_FILE_SIZE_MAX (128*1024*1024)
 
@@ -34,4 +37,11 @@ bool enough_ram(void);
 
 int open_inotify(void);
 
+typedef struct ReadaheadShared {
+        pid_t collect;
+        pid_t replay;
+} _packed_ ReadaheadShared;
+
+ReadaheadShared *shared_get(void);
+
 #endif
diff --git a/src/readahead-replay.c b/src/readahead-replay.c
index f0710e5..e22fc04 100644
--- a/src/readahead-replay.c
+++ b/src/readahead-replay.c
@@ -44,6 +44,8 @@
 
 static off_t arg_file_size_max = READAHEAD_FILE_SIZE_MAX;
 
+static ReadaheadShared *shared = NULL;
+
 static int unpack_file(FILE *pack) {
         char fn[PATH_MAX];
         int r = 0, fd = -1;
@@ -338,6 +340,12 @@ int main(int argc, char*argv[]) {
                 return 0;
         }
 
+        if (!(shared = shared_get()))
+                return 1;
+
+        shared->replay = getpid();
+        __sync_synchronize();
+
         if (replay(optind < argc ? argv[optind] : "/") < 0)
                 return 1;
 


More information about the systemd-commits mailing list