git: 0078d54c0985 - stable/13 - loader: Add a readtest command

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Thu, 13 Jan 2022 09:49:01 UTC
The branch stable/13 has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=0078d54c0985a41ef172022bb9880cf751982f8b

commit 0078d54c0985a41ef172022bb9880cf751982f8b
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2021-12-09 13:54:58 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-01-13 07:55:42 +0000

    loader: Add a readtest command
    
    readtest will simply load the file in memory, useful for timing
    loading on some filesystems.
    
    Reviewed by:    tsoome
    MFC after:      2 weeks
    Sponsored by:   Beckhoff Automation GmbH & Co. KG
    Differential Revision:  https://reviews.freebsd.org/D33411
    
    (cherry picked from commit 70661eaafa069062317ae2c6012cc2bc303da0cc)
---
 stand/common/commands.c | 31 +++++++++++++++++++++++++++++++
 stand/libsa/tftp.c      |  1 +
 2 files changed, 32 insertions(+)

diff --git a/stand/common/commands.c b/stand/common/commands.c
index 9f7252014d87..0d21ed44c681 100644
--- a/stand/common/commands.c
+++ b/stand/common/commands.c
@@ -545,3 +545,34 @@ command_lsdev(int argc, char *argv[])
 	pager_close();
 	return (CMD_OK);
 }
+
+static int
+command_readtest(int argc, char *argv[])
+{
+	int fd;
+	time_t start, end;
+	char buf[512];
+	ssize_t rv, count = 0;
+
+	if (argc != 2) {
+		snprintf(command_errbuf, sizeof(command_errbuf),
+		  "Usage: readtest <filename>");
+		return (CMD_ERROR);
+	}
+
+	start = getsecs();
+	if ((fd = open(argv[1], O_RDONLY)) < 0) {
+		snprintf(command_errbuf, sizeof(command_errbuf),
+		  "can't open '%s'", argv[1]);
+		return (CMD_ERROR);
+	}
+	while ((rv = read(fd, buf, sizeof(buf))) > 0)
+		count += rv;
+	end = getsecs();
+
+	printf("Received %zd bytes during %jd seconds\n", count, (intmax_t)end - start);
+	close(fd);
+	return (CMD_OK);
+}
+
+COMMAND_SET(readtest, "readtest", "Time a file read", command_readtest);
diff --git a/stand/libsa/tftp.c b/stand/libsa/tftp.c
index 6cfa670b6e22..37f8b64f99aa 100644
--- a/stand/libsa/tftp.c
+++ b/stand/libsa/tftp.c
@@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$");
 
 #include <string.h>
 
+#include <bootstrap.h>
 #include "stand.h"
 #include "net.h"
 #include "netif.h"