[PATCH 14/15] Add rename benchmark command to debugfs

Valerie Aurora val at versity.com
Wed Mar 12 07:33:53 PDT 2025


Add the "brename" command to debugfs to create a bunch of files and
rename them into their parent dir.

Signed-off-by: Valerie Aurora <val at versity.com>
---
 cli/debugfs.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/cli/debugfs.c b/cli/debugfs.c
index 9a61e80..07f6b5f 100644
--- a/cli/debugfs.c
+++ b/cli/debugfs.c
@@ -23,6 +23,7 @@
 #include "shared/mkfs.h"
 #include "shared/mount.h"
 #include "shared/nerr.h"
+#include "shared/parse.h"
 #include "shared/thread.h"
 
 #include "cli/cli.h"
@@ -37,6 +38,54 @@ struct debugfs_context {
 #define LINE_SIZE (PATH_MAX * 5)
 #define MAX_ARGC ((LINE_SIZE + 1) / 2)
 
+static void cmd_brename(struct debugfs_context *ctx, int argc, char **argv)
+{
+	struct ngnfs_dir_lookup_entry lent, sub_lent;
+	char filename[NGNFS_NAME_MAX];
+	char *subdir = "tmp";
+	char *dir;
+	u64 renames, i;
+	int ret;
+
+	if (argc != 3) {
+		printf("usage: %s <directory name> <number renames>\n", argv[0]);
+		return;
+	}
+
+	dir = argv[1];
+
+	ret = parse_ull(&renames, argv[2], 1, NGNFS_LINK_MAX - 1);
+	if (ret < 0) {
+		printf("number of renames must be between 1 and %d\n", NGNFS_LINK_MAX - 1);
+		return;
+	}
+
+	ret = ngnfs_dir_mkdir(ctx->nfi, &ctx->cwd_ig, 0755, dir, strlen(dir))			?:
+	      ngnfs_dir_lookup(ctx->nfi, &ctx->cwd_ig, dir, strlen(dir), &lent)			?:
+	      ngnfs_dir_mkdir(ctx->nfi, &lent.ig, 0755, subdir, strlen(subdir))			?:
+	      ngnfs_dir_lookup(ctx->nfi, &lent.ig, subdir, strlen(subdir), &sub_lent);
+
+	if (ret < 0) {
+		printf("error creating %s/%s/:"ENOF"\n", dir, subdir, ENOA(-ret));
+		return;
+	}
+
+	for (i = 0; i < renames; i++) {
+		snprintf(filename, sizeof(filename), "%llu", i);
+		ret = ngnfs_dir_create(ctx->nfi, &sub_lent.ig, 0644, filename, strlen(filename));
+		if (ret < 0) {
+			printf("create error: "ENOF"\n", ENOA(-ret));
+			return;
+		}
+		ret = ngnfs_dir_rename(ctx->nfi, &sub_lent.ig, filename, strlen(filename), &lent.ig,
+				       filename, strlen(filename));
+		if (ret < 0) {
+			printf("rename error: "ENOF"\n", ENOA(-ret));
+			return;
+		}
+	}
+}
+
 static void cmd_cd(struct debugfs_context *ctx, int argc, char **argv)
 {
 	struct ngnfs_dir_lookup_entry lent;
@@ -356,6 +405,7 @@ static struct command {
 	char *name;
 	void (*func)(struct debugfs_context *ctx, int argc, char **argv);
 } commands[] = {
+	{ "brename", cmd_brename, },
 	{ "cd", cmd_cd, },
 	{ "create", cmd_create, },
 	{ "lookup", cmd_lookup, },
-- 
2.48.1




More information about the ngnfs-devel mailing list