readahead-fedora (2:1.5.6-1) unsorted_custom_lists.patch

Summary

 scripts/readahead.cron    |   13 ++++++++++++-
 src/readahead-collector.c |   30 ++++++++++++++++++++----------
 src/readahead.c           |   15 +++++++++++----
 3 files changed, 43 insertions(+), 15 deletions(-)

    
download this patch

Patch contents

Index: readahead/src/readahead-collector.c
===================================================================
--- readahead.orig/src/readahead-collector.c
+++ readahead/src/readahead-collector.c
@@ -37,6 +37,7 @@
 #include <sys/param.h>
 #include <limits.h>
 #include <syslog.h>
+#include <search.h>
 
 
 /*
@@ -961,13 +962,9 @@ blocks_dump_as_lists(RacStatus *rac, con
 
 	if (nfiles) {
 		int e = sep ? : nfiles;
-		debug("sorting early list (%d/%d items)", e, nfiles);
-		qsort(all, e, sizeof(char *), pathcmp);
 		list_write(rac, all, e, filename_tpl, "early");
 	}
 	if (sep) {
-		debug("sorting later list (%d/%d items)", nfiles-sep, nfiles);
-		qsort(all + sep, nfiles - sep, sizeof(char *), pathcmp);
 		list_write(rac, all + sep, nfiles - sep, filename_tpl, "later");
 	}
 
@@ -981,7 +978,7 @@ list_write(RacStatus *rac, char **list,
 	int i;
 	FILE *out;
 	char filename[ PATH_MAX ];
-	char *last = NULL;
+	ENTRY e, *re;
 
 	snprintf(filename, sizeof(filename), filetpl, fileext);
 	if (!(out = fopen(filename, "w")))
@@ -989,13 +986,26 @@ list_write(RacStatus *rac, char **list,
 
 	debug("writing list to %s", filename);
 
+	hcreate(size);
+
 	for (i = 0; i < size; i++) {
-		if (last && strcmp(last, list[i]) == 0)
-			/* remove duplicates  */
-			continue;
-		fprintf(out, "%s\n", list[i]);
-		last = list[i];
+		e.key = list[i];
+		e.data = (void *) 1;
+		re = hsearch(e, ENTER);
+		if (re == NULL) {
+		    // error
+		    hdestroy();
+		    fclose(out);
+		    return -1;
+		}
+		// if data is 1 it is a new entry
+		// if it is 0, it is an old entry, and as such we skip it
+		if ((int)re->data) {
+			fprintf(out, "%s\n", list[i]);
+			re->data = (void *)0;
+		}
 	}
+	hdestroy();
 
 	fclose(out);
 	return 0;
Index: readahead/src/readahead.c
===================================================================
--- readahead.orig/src/readahead.c
+++ readahead/src/readahead.c
@@ -62,6 +62,7 @@ static long int maxsize;
 #define MODE_FULL	1
 #define MODE_SORT	2
 #define MODE_FAST	3
+#define MODE_BUILD	4
 
 struct device {
 	dev_t		st_dev;
@@ -416,7 +417,8 @@ static void
 usage(int excode)
 {
 	fprintf(stdout, _("\n%s [options] <file> [...]\n\n"), progname);
-	fputs(_("  -s | --sort            sort list of files only\n"
+	fputs(_("  -b | --build            build optimised list of files only\n"
+	      "  -s | --sort            sort list of files only (implies -b)\n"
 	      "  -o | --output <file>   output sorted list of files\n"
 	      "  -d | --dont-sort       call readahead(2) for already sorted list\n"
 	      "  -h | --help            this help\n"
@@ -436,6 +438,7 @@ main(int argc, char **argv)
 	char *p, *output = NULL;
 	struct option opts[] =
 	{
+		{ "build",	0, 0, 'b' },
 		{ "sort",	0, 0, 's' },
 		{ "dont-sort",  0, 0, 'd' },
 		{ "help",       0, 0, 'h' },
@@ -459,7 +462,7 @@ main(int argc, char **argv)
 	if ((p = strrchr(argv[0], '/')))
 		progname = p+1;
 
-	while((i = getopt_long(argc, argv, "dho:stvm:", opts, NULL)) != -1) {
+	while((i = getopt_long(argc, argv, "dho:bstvm:", opts, NULL)) != -1) {
 		switch(i) {
 		case 'd':
 			mode = MODE_FAST;
@@ -469,6 +472,9 @@ main(int argc, char **argv)
 			break;
 		case 'h':
 			usage(EXIT_SUCCESS);
+		case 'b':
+			mode = (mode != MODE_SORT)? MODE_BUILD : mode;
+			break;
 		case 's':
 			mode = MODE_SORT;
 			break;
@@ -497,7 +503,8 @@ main(int argc, char **argv)
 	if (verbose) {
 		fprintf(stderr, _("Mode: %s\n"),
 				mode == MODE_FULL ? "full" :
-				mode == MODE_FAST ? "fast" : "sort" );
+				mode == MODE_FAST ? "fast" :
+				mode == MODE_BUILD ? "build" : "build sorted" );
 		if (output)
 			fprintf(stderr, _("Output: %s\n"), output);
 		for (i = 0; i < argc; i++)
@@ -527,7 +534,7 @@ main(int argc, char **argv)
 	if (mode == MODE_FULL || mode == MODE_FAST)
 		list_do_readahead(files, nfiles);
 
-	else if (mode == MODE_SORT)
+	else if (mode == MODE_SORT || mode == MODE_BUILD)
 		res = list_write(files, nfiles, output);
 
 	list_destroy(files, nfiles);
Index: readahead/scripts/readahead.cron
===================================================================
--- readahead.orig/scripts/readahead.cron
+++ readahead/scripts/readahead.cron
@@ -41,13 +41,24 @@ done
 
 if $MERGE_LISTS; then
     tmpf="$(mktemp)"
+
+    extra_opts=--sort
+
+    major=$(stat -c '%D' . | cut -b1)
+    if [ -f "/sys/dev/block/${major}:0/queue/rotational" ]; then
+	rotational="$(cat "/sys/dev/block/${major}:0/queue/rotational")"
+	if [ "$rotational" = "0" ]; then
+	    extra_opts=--build
+	fi
+    fi
+
     for LTYPE in $TYPES; do
 	f="$READAHEAD_BASE/$LTYPE.sorted"
 	[ -f "$f" ] || continue
 	cut -d\  -f2- "$f" >> "$tmpf"
     done
     if [ -s "$tmpf" ]; then
-	$READAHEAD_CMD --sort --output="$READAHEAD_BASE/early.sorted" "$tmpf" >/dev/null 2>&1
+	$READAHEAD_CMD $extra_opts --output="$READAHEAD_BASE/early.sorted" "$tmpf" >/dev/null 2>&1
 	: > "$READAHEAD_BASE/later.sorted"
     fi
     rm -f "$tmpf"