[systemd-devel] [PATCH] readahead: Add savedir option

Seunghun Pi sh.pi at samsung.com
Thu Feb 14 00:47:48 PST 2013


From: Byung-Soo Kim <bs1770.kim at samsung.com>

From: Byung-Soo Kim <bs1770.kim at samsung.com>

In case of root file system mounted in read-only mode,
the collected data cannot be stored.
Then add code to specify directory path of collected data as RW position.
With --savedir=PATH option, collected data can be stored in the path.

Signed-off-by: Byung-Soo Kim <bs1770.kim at samsung.com>
Signed-off-by: Seunghun Pi <sh.pi at samsung.com>
---
 src/readahead/readahead-collect.c |    7 +++++--
 src/readahead/readahead-common.h  |    1 +
 src/readahead/readahead-replay.c  |    5 ++++-
 src/readahead/readahead.c         |   11 ++++++++++-
 4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/readahead/readahead-collect.c b/src/readahead/readahead-collect.c
index 5d07f47..b8b3d6b 100644
--- a/src/readahead/readahead-collect.c
+++ b/src/readahead/readahead-collect.c
@@ -245,7 +245,10 @@ static int collect(const char *root) {
 
         assert(root);
 
-        if (asprintf(&pack_fn, "%s/.readahead", root) < 0) {
+        if (!arg_savedir)
+                arg_savedir = root;
+
+        if (asprintf(&pack_fn, "%s/.readahead", arg_savedir) < 0) {
                 r = log_oom();
                 goto finish;
         }
@@ -479,7 +482,7 @@ done:
         on_btrfs = statfs(root, &sfs) >= 0 && (long) sfs.f_type == (long) BTRFS_SUPER_MAGIC;
         log_debug("On btrfs: %s", yes_no(on_btrfs));
 
-        if (asprintf(&pack_fn_new, "%s/.readahead.new", root) < 0) {
+        if (asprintf(&pack_fn_new, "%s/.readahead.new", arg_savedir) < 0) {
                 r = log_oom();
                 goto finish;
         }
diff --git a/src/readahead/readahead-common.h b/src/readahead/readahead-common.h
index b34f3aa..5768b9a 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_savedir;
 
 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 cb04e5f..e934ba2 100644
--- a/src/readahead/readahead-replay.c
+++ b/src/readahead/readahead-replay.c
@@ -149,7 +149,10 @@ static int replay(const char *root) {
 
         block_bump_request_nr(root);
 
-        if (asprintf(&pack_fn, "%s/.readahead", root) < 0) {
+        if (!arg_savedir)
+                arg_savedir = root;
+
+        if (asprintf(&pack_fn, "%s/.readahead", arg_savedir) < 0) {
                 r = log_oom();
                 goto finish;
         }
diff --git a/src/readahead/readahead.c b/src/readahead/readahead.c
index abeecc7..377b69f 100644
--- a/src/readahead/readahead.c
+++ b/src/readahead/readahead.c
@@ -34,6 +34,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_savedir;
 
 static int help(void) {
 
@@ -43,12 +44,14 @@ static int help(void) {
                "     --max-files=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",
+               "     --savedir=PATH         Directory path to save collecting data\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"
                "     --file-size-max=BYTES  Maximum size of files to read ahead\n\n\n",
+               "     --savedir=PATH         Directory path to save collecting data\n\n\n",
                program_invocation_short_name);
 
         printf("%s [OPTIONS...] analyze [PACK FILE]\n\n"
@@ -64,7 +67,8 @@ static int parse_argv(int argc, char *argv[]) {
         enum {
                 ARG_FILES_MAX = 0x100,
                 ARG_FILE_SIZE_MAX,
-                ARG_TIMEOUT
+                ARG_TIMEOUT,
+                ARG_SAVEDIR,
         };
 
         static const struct option options[] = {
@@ -72,6 +76,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "files-max",     required_argument, NULL, ARG_FILES_MAX      },
                 { "file-size-max", required_argument, NULL, ARG_FILE_SIZE_MAX  },
                 { "timeout",       required_argument, NULL, ARG_TIMEOUT        },
+                { "savedir",       required_argument, NULL, ARG_SAVEDIR        },
                 { NULL,            0,                 NULL, 0                  }
         };
 
@@ -115,6 +120,10 @@ static int parse_argv(int argc, char *argv[]) {
 
                         break;
 
+                case ARG_SAVEDIR:
+                        arg_savedir = optarg;
+                        break;
+
                 case '?':
                         return -EINVAL;
 
-- 
1.7.5.4



More information about the systemd-devel mailing list