shithub: gefs

Download patch

ref: 9bdccad213908337528dc897a4ca5d80d6ddf0e4
parent: 44784638d405ea51510523293ca77a256ac8ad9d
author: Ori Bernstein <ori@eigenstate.org>
date: Sun May 28 12:01:33 EDT 2023

freplay: add step command

--- a/test/freplay.c
+++ b/test/freplay.c
@@ -13,6 +13,7 @@
 vlong	membufsz;
 vlong	replaycount	= -1;
 int	logfd		= -1;
+int	replayfd	= -1;
 vlong	nwrites;
 
 void
@@ -87,8 +88,16 @@
 			r->ofcall.count = r->ifcall.count;
 			respond(r, nil);
 			exits(nil);
-		}
-		respond(r, "unknown ctl message");
+		}else if(strncmp(r->ifcall.data, "step", 4) == 0){
+			r->ofcall.count = r->ifcall.count;
+			if(replayfd == -1)
+				respond(r, "no active replay");
+			else if(!replay1(replayfd))
+				respond(r, "no replay left");
+			else
+				respond(r, nil);
+		}else
+			respond(r, "unknown ctl message");
 	}else
 		abort();
 }
@@ -107,7 +116,7 @@
 void
 main(int argc, char *argv[])
 {
-	int fd, replayfd;
+	int fd;
 	vlong n, off;
 	char *uid;
 	Dir *d;
@@ -146,7 +155,7 @@
 		sysfatal("failed to allocate buffer: %r");
 	memset(membuf, 0, d->length);
 	for(off = 0; off < d->length; off += n)
-		if((n = read(fd, membuf+off, 8192)) <= 0)
+		if((n = read(fd, membuf+off, d->length - off)) <= 0)
 			sysfatal("read %s: short read", argv[0]);
 	membufsz = d->length;
 	free(d);
@@ -157,7 +166,6 @@
 			if(replay1(replayfd) == 0)
 				break;
 		print("replayed %d ops\n", i);
-		close(replayfd);
 	}
 
 	if(logfile != nil){