[Reproducible-commits] [disorderfs] 02/02: Add options --shuffle-dirents, --reverse-dirents, and --pad-blocks

Andrew Ayer agwa at andrewayer.name
Sat Aug 29 09:06:35 UTC 2015


This is an automated email from the git hooks/post-receive script.

agwa-guest pushed a commit to branch master
in repository disorderfs.

commit 30a4376fcc161ad1ebc023ba0ecc5d66e8d71a2d
Author: Andrew Ayer <agwa at andrewayer.name>
Date:   Sat Aug 29 10:59:59 2015 +0200

    Add options --shuffle-dirents, --reverse-dirents, and --pad-blocks
    
    The defaults are:
    
    --shuffle-dirents=no (previously yes)
    --reverse-dirents=yes (previously no)
    --pad-blocks=1 (previously 0)
    
    We now reverse dirents instead of shuffling by default because:
     1. Normal filesystems don't return directory entries in a different order
        every time you read a directory, and we want disorderfs to act as
        normally as possible to avoid causing spurious build failures.
     2. There's a chance that shuffling returns the same order. (Especially
        problematic with small directories.)
---
 disorderfs.1.txt | 12 ++++++++++++
 disorderfs.cpp   | 36 +++++++++++++++++++++++-------------
 2 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/disorderfs.1.txt b/disorderfs.1.txt
index 8252fdb..b9e124b 100644
--- a/disorderfs.1.txt
+++ b/disorderfs.1.txt
@@ -30,6 +30,18 @@ See fusermount(1), mount.fuse(8), and mount(8) for a full list of options.
 
 Options specific to *disorderfs*:
 
+*--shuffle-dirents=yes|no*::
+  Whether or not to randomly shuffle directory entries (default: no).
+  The directory entries are shuffled every time the directory is read,
+  so repeated reads of the same directory will probably return different
+  results.
+
+*--reverse-dirents=yes|no*::
+  Whether or not to return directory entries in reverse order (default: yes).
+
+*--pad-blocks='N'*::
+  Add 'N' to the st_blocks field in struct stat(2) (default: 1).
+
 *--help*, *-h*::
   Display help.
 
diff --git a/disorderfs.cpp b/disorderfs.cpp
index 070795b..c0cf06b 100644
--- a/disorderfs.cpp
+++ b/disorderfs.cpp
@@ -35,16 +35,19 @@
 #include <algorithm>
 #include <attr/xattr.h>
 #include <sys/types.h>
+#include <stddef.h>
 
 #define DISORDERFS_VERSION "0.2.0"
 
 namespace {
 	std::vector<std::string>	bare_arguments;
 	std::string			root;
-	// TODO: cmdline opts for these:
-	bool				shuffle_dirents{true};
-	bool				reverse_dirents{false};
-	bool				randomize_block_count{false};
+	struct Disorderfs_config {
+		bool			shuffle_dirents{false};
+		bool			reverse_dirents{true};
+		unsigned int		pad_blocks{1};
+	};
+	Disorderfs_config		config;
 
 	int wrap (int retval) { return retval == -1 ? -errno : 0; }
 	using Dirents = std::vector<std::string>;
@@ -54,7 +57,13 @@ namespace {
 		KEY_HELP,
 		KEY_VERSION
 	};
+#define DISORDERFS_OPT(t, p, v) { t, offsetof(Disorderfs_config, p), v }
 	const struct fuse_opt disorderfs_fuse_opts[] = {
+		DISORDERFS_OPT("--shuffle-dirents=no", shuffle_dirents, false),
+		DISORDERFS_OPT("--shuffle-dirents=yes", shuffle_dirents, true),
+		DISORDERFS_OPT("--reverse-dirents=no", reverse_dirents, false),
+		DISORDERFS_OPT("--reverse-dirents=yes", reverse_dirents, true),
+		DISORDERFS_OPT("--pad-blocks=%i", pad_blocks, 0),
 		FUSE_OPT_KEY("-h", KEY_HELP),
 		FUSE_OPT_KEY("--help", KEY_HELP),
 		FUSE_OPT_KEY("-V", KEY_VERSION),
@@ -73,6 +82,11 @@ namespace {
 			std::clog << "    -h, --help             display help" << std::endl;
 			std::clog << "    -V, --version          display version info" << std::endl;
 			std::clog << std::endl;
+			std::clog << "disorderfs options:" << std::endl;
+			std::clog << "    --shuffle-dirents=yes|no  randomly shuffle dirents? (default: no)" << std::endl;
+			std::clog << "    --reverse-dirents=yes|no  reverse dirent order? (default: yes)" << std::endl;
+			std::clog << "    --pad-blocks=N         add N to st_blocks (default: 1)" << std::endl;
+			std::clog << std::endl;
 			fuse_opt_add_arg(outargs, "-ho");
 			fuse_main(outargs->argc, outargs->argv, &disorderfs_fuse_operations, NULL);
 			std::exit(0);
@@ -99,9 +113,7 @@ int	main (int argc, char** argv)
 		if (lstat((root + path).c_str(), st) == -1) {
 			return -errno;
 		}
-		if (randomize_block_count) {
-			// TODO: also randomize blocks st->st_blocks = 129381;
-		}
+		st->st_blocks += config.pad_blocks;
 		return 0;
 	};
 	disorderfs_fuse_operations.readlink = [] (const char* path, char* buf, size_t sz) -> int {
@@ -198,7 +210,7 @@ int	main (int argc, char** argv)
 		while ((res = readdir_r(d, &dirent_storage, &dirent_p)) == 0 && dirent_p) {
 			dirents->emplace_back(dirent_p->d_name);
 		}
-		if (reverse_dirents) {
+		if (config.reverse_dirents) {
 			std::reverse(dirents->begin(), dirents->end());
 		}
 		closedir(d);
@@ -211,7 +223,7 @@ int	main (int argc, char** argv)
 	};
 	disorderfs_fuse_operations.readdir = [] (const char* path, void* buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info* info) {
 		Dirents&		dirents = *reinterpret_cast<Dirents*>(info->fh);
-		if (shuffle_dirents) {
+		if (config.shuffle_dirents) {
 			std::random_device	rd;
 			std::mt19937		g(rd());
 			std::shuffle(dirents.begin(), dirents.end(), g);
@@ -251,9 +263,7 @@ int	main (int argc, char** argv)
 		if (fstat(info->fh, st) == -1) {
 			return -errno;
 		}
-		if (randomize_block_count) {
-			// TODO: also randomize blocks st->st_blocks = 129381;
-		}
+		st->st_blocks += config.pad_blocks;
 		return 0;
 	};
 	/* TODO: locking
@@ -291,7 +301,7 @@ int	main (int argc, char** argv)
 	 * Parse command line options
 	 */
 	struct fuse_args	fargs = FUSE_ARGS_INIT(argc, argv);
-	fuse_opt_parse(&fargs, nullptr, disorderfs_fuse_opts, fuse_opt_proc);
+	fuse_opt_parse(&fargs, &config, disorderfs_fuse_opts, fuse_opt_proc);
 
 	if (bare_arguments.size() != 2) {
 		std::clog << "disorderfs: error: wrong number of arguments" << std::endl;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/disorderfs.git



More information about the Reproducible-commits mailing list