[systemd-devel] [PATCH] readahead: add option to create pack in directory other than root

alison_chaiken at mentor.com alison_chaiken at mentor.com
Tue Jul 8 04:05:57 PDT 2014


From: Alison Chaiken <alison_chaiken at mentor.com>

Add support for creating a readahead pack in a runtime-specified
directory.  Users may want the feature if they their rootfs is
read-only at boot or if they maintain more than one pack file.  The
new pack-file location is specified by a --pack-location command-line
switch.  Default behavior is retained if the switch is absent.

Signed-off-by: Alison Chaiken <alison_chaiken at mentor.com>
---
 man/systemd-readahead-replay.service.xml | 10 +++++++++-
 src/readahead/readahead-collect.c        | 16 ++++++++++++++--
 src/readahead/readahead-common.h         |  1 +
 src/readahead/readahead-replay.c         |  6 +++++-
 src/readahead/readahead.c                | 18 +++++++++++++++---
 5 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/man/systemd-readahead-replay.service.xml b/man/systemd-readahead-replay.service.xml
index 669fe78..a8b9a03 100644
--- a/man/systemd-readahead-replay.service.xml
+++ b/man/systemd-readahead-replay.service.xml
@@ -84,7 +84,7 @@
                 to end data collection. On this signal, this service
                 will then sort the collected disk accesses and store
                 information about them in
-                <filename>/.readahead</filename>.</para>
+                <filename>/.readahead</filename> by default.</para>
 
                 <para>Normally, both
                 <filename>systemd-readahead-collect.service</filename>
@@ -144,6 +144,14 @@
                                 command.</para></listitem>
                         </varlistentry>
 
+                        <varlistentry>
+                                <term><option>--pack-location=</option></term>
+                                <listitem><para>Directory where .readahead
+                                will be created, different from the root
+                                whose accesses are the basis of pack
+                                formation.</para></listitem>
+                        </varlistentry>
+
                         <xi:include href="standard-options.xml" xpointer="help" />
                         <xi:include href="standard-options.xml" xpointer="version" />
                 </variablelist>
diff --git a/src/readahead/readahead-collect.c b/src/readahead/readahead-collect.c
index c1afd0d..f63c078 100644
--- a/src/readahead/readahead-collect.c
+++ b/src/readahead/readahead-collect.c
@@ -253,7 +253,13 @@ static int collect(const char *root) {
 
         assert(root);
 
-        if (asprintf(&pack_fn, "%s/.readahead", root) < 0) {
+        if (strlen(arg_pack_loc)) {
+                if (asprintf(&pack_fn, "%s/.readahead", arg_pack_loc) < 0) {
+                        r = log_oom();
+                        goto finish;
+                }
+        }
+        else if (asprintf(&pack_fn, "%s/.readahead", root) < 0) {
                 r = log_oom();
                 goto finish;
         }
@@ -507,7 +513,13 @@ done:
         on_btrfs = statfs(root, &sfs) >= 0 && F_TYPE_EQUAL(sfs.f_type, BTRFS_SUPER_MAGIC);
         log_debug("On btrfs: %s", yes_no(on_btrfs));
 
-        if (asprintf(&pack_fn_new, "%s/.readahead.new", root) < 0) {
+        if (strlen(arg_pack_loc)) {
+                if (asprintf(&pack_fn_new, "%s/.readahead.new", arg_pack_loc) < 0) {
+                        r = log_oom();
+                        goto finish;
+                }
+        }
+        else if (asprintf(&pack_fn_new, "%s/.readahead.new", root) < 0) {
                 r = log_oom();
                 goto finish;
         }
diff --git a/src/readahead/readahead-common.h b/src/readahead/readahead-common.h
index b34f3aa..d26ad30 100644
--- a/src/readahead/readahead-common.h
+++ b/src/readahead/readahead-common.h
@@ -34,6 +34,7 @@
 extern unsigned arg_files_max;
 extern off_t arg_file_size_max;
 extern usec_t arg_timeout;
+extern char arg_pack_loc[LINE_MAX];
 
 int file_verify(int fd, const char *fn, off_t file_size_max, struct stat *st);
 
diff --git a/src/readahead/readahead-replay.c b/src/readahead/readahead-replay.c
index f46dc3b..852747d 100644
--- a/src/readahead/readahead-replay.c
+++ b/src/readahead/readahead-replay.c
@@ -136,7 +136,11 @@ static int replay(const char *root) {
 
         block_bump_request_nr(root);
 
-        if (asprintf(&pack_fn, "%s/.readahead", root) < 0)
+        if (strlen(arg_pack_loc)) {
+                if (asprintf(&pack_fn, "%s/.readahead", arg_pack_loc) < 0)
+                        return log_oom();
+        }
+        else if (asprintf(&pack_fn, "%s/.readahead", root) < 0) {
                 return log_oom();
 
         pack = fopen(pack_fn, "re");
diff --git a/src/readahead/readahead.c b/src/readahead/readahead.c
index 73cf538..3c45982 100644
--- a/src/readahead/readahead.c
+++ b/src/readahead/readahead.c
@@ -35,6 +35,7 @@
 unsigned arg_files_max = 16*1024;
 off_t arg_file_size_max = READAHEAD_FILE_SIZE_MAX;
 usec_t arg_timeout = 2*USEC_PER_MINUTE;
+char arg_pack_loc[LINE_MAX];
 
 static int help(void) {
 
@@ -44,14 +45,16 @@ static int help(void) {
                "     --version              Show package version\n"
                "     --files-max=INT        Maximum number of files to read ahead\n"
                "     --file-size-max=BYTES  Maximum size of files to read ahead\n"
-               "     --timeout=USEC         Maximum time to spend collecting data\n\n\n",
+               "     --timeout=USEC         Maximum time to spend collecting data\n"
+               "     --pack-location=DIR    Directory in which to create the pack-file\n\n\n",
                program_invocation_short_name);
 
         printf("%s [OPTIONS...] replay [DIRECTORY]\n\n"
                "Replay collected read-ahead data on early boot.\n\n"
                "  -h --help                 Show this help\n"
                "     --version              Show package version\n"
-               "     --file-size-max=BYTES  Maximum size of files to read ahead\n\n\n",
+               "     --file-size-max=BYTES  Maximum size of files to read ahead\n"
+               "     --pack-location=DIR    Directory from which to read the pack-file\n\n\n",
                program_invocation_short_name);
 
         printf("%s [OPTIONS...] analyze [PACK FILE]\n\n"
@@ -69,7 +72,8 @@ static int parse_argv(int argc, char *argv[]) {
                 ARG_VERSION = 0x100,
                 ARG_FILES_MAX,
                 ARG_FILE_SIZE_MAX,
-                ARG_TIMEOUT
+                ARG_TIMEOUT,
+                ARG_PACK_LOC
         };
 
         static const struct option options[] = {
@@ -125,6 +129,14 @@ static int parse_argv(int argc, char *argv[]) {
 
                         break;
 
+                case ARG_PACK_LOC:
+                        if (sscanf(optarg, "%s", arg_pack_loc) != 1) {
+                                log_error("Failed to parse pack location %s.", optarg);
+                                return -EINVAL;
+                        }
+
+                        break;
+
                 case '?':
                         return -EINVAL;
 
-- 
1.9.1



More information about the systemd-devel mailing list