summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile8
-rw-r--r--bcache-test.c56
-rw-r--r--make-bcache.c10
3 files changed, 48 insertions, 26 deletions
diff --git a/Makefile b/Makefile
index 8d8c0da..a47719d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,15 @@
+PREFIX=/usr/local
CFLAGS=-O2 -Wall -g
-all: make-bcache bcache-test
+all: make-bcache
clean:
rm -f make-bcache bcache-test *.o
+install: make-bcache
+ install -m0755 make-bcache ${PREFIX}/sbin/
+ install -m0755 bcache-test ${PREFIX}/sbin/
+
+
bcache-test: LDFLAGS += -lm -lssl -lcrypto
diff --git a/bcache-test.c b/bcache-test.c
index 2b183cf..93da058 100644
--- a/bcache-test.c
+++ b/bcache-test.c
@@ -28,6 +28,8 @@ static const unsigned char bcache_magic[] = {
unsigned char zero[4096];
+bool klog = false;
+
#define Pread(fd, buf, size, offset) do { \
int _read = 0, _r; \
while (_read < size) { \
@@ -97,9 +99,29 @@ struct pagestuff {
int writecount;
};
-void flushlog(int fd, char *logbuf)
+void flushlog(void)
{
- int w = 0, len = klogctl(4, logbuf, 1 << 21);
+ char logbuf[1 << 21];
+ int w = 0, len;
+ static int fd;
+
+ if (!klog)
+ return;
+
+ if (!fd) {
+ klogctl(8, 0, 6);
+
+ sprintf(logbuf, "log.%i", abs(random()) % 1000);
+ fd = open(logbuf, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+
+ if (fd == -1) {
+ perror("Error opening log file");
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ len = klogctl(4, logbuf, 1 << 21);
+
if (len == -1) {
perror("Error reading kernel log");
exit(EXIT_FAILURE);
@@ -127,20 +149,19 @@ void usage()
int main(int argc, char **argv)
{
- bool walk = false, randsize = false, verbose = false, csum = false, destructive = false, log = false;
- int fd1, fd2 = 0, logfd, direct = 0, nbytes = 4096, j, o;
+ bool walk = false, randsize = false, verbose = false, csum = false, destructive = false;
+ int fd1, fd2 = 0, direct = 0, nbytes = 4096, j, o;
unsigned long size, i, offset = 0, done = 0, unique = 0, benchmark = 0;
void *buf1 = NULL, *buf2 = NULL;
struct pagestuff *pages, *p;
unsigned char c[16];
- char logbuf[1 << 21];
time_t last_printed = 0;
extern char *optarg;
RC4_KEY writedata;
RC4_set_key(&writedata, 16, bcache_magic);
- while ((o = getopt(argc, argv, "dwvscwlb:")) != EOF)
+ while ((o = getopt(argc, argv, "dnwvscwlb:")) != EOF)
switch (o) {
case 'd':
direct = O_DIRECT;
@@ -161,7 +182,7 @@ int main(int argc, char **argv)
destructive = true;
break;
case 'l':
- log = true;
+ klog = true;
break;
case 'b':
benchmark = atol(optarg);
@@ -207,16 +228,6 @@ int main(int argc, char **argv)
}
//setvbuf(stdout, NULL, _IONBF, 0);
- if (log) {
- sprintf(logbuf, "log.%i", abs(random()) % 1000);
- logfd = open(logbuf, O_WRONLY|O_CREAT|O_TRUNC, 0644);
- if (logfd == -1) {
- perror("Error opening log file");
- exit(EXIT_FAILURE);
- }
- klogctl(8, 0, 6);
- }
-
for (i = 0; !benchmark || i < benchmark; i++) {
bool writing = destructive && (i & 1);
nbytes = randsize ? drand48() * 16 + 1 : 1;
@@ -227,8 +238,8 @@ int main(int argc, char **argv)
offset %= size;
offset <<= 12;
- if (log && !(i % 200))
- flushlog(logfd, logbuf);
+ if (!(i % 200))
+ flushlog();
if (!verbose) {
time_t now = time(NULL);
@@ -278,11 +289,12 @@ print: printf("Loop %6li offset %9li sectors %3i, %6lu mb done, %6lu mb unique
if (writing && !csum && !benchmark)
Pwrite(fd2, buf2, nbytes, offset);
}
+ printf("Loop %6li offset %9li sectors %3i, %6lu mb done, %6lu mb unique\n",
+ i, offset >> 9, nbytes >> 9, done >> 11, unique >> 11);
exit(EXIT_SUCCESS);
err:
perror("IO error");
- if (log)
- flushlog(logfd, logbuf);
+ flushlog();
exit(EXIT_FAILURE);
bad:
printf("Bad read! loop %li offset %li readcount %i writecount %i\n",
@@ -291,6 +303,6 @@ bad:
if (!memcmp(&p->oldcsum[0], c, 16))
printf("Matches previous csum\n");
- flushlog(logfd, logbuf);
+ flushlog();
exit(EXIT_FAILURE);
}
diff --git a/make-bcache.c b/make-bcache.c
index 2defbaf..04861f9 100644
--- a/make-bcache.c
+++ b/make-bcache.c
@@ -8,7 +8,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -75,19 +74,24 @@ long hatoi(const char *s)
return i;
}
+void usage()
+{
+ printf("");
+ exit(EXIT_FAILURE);
+}
+
int main(int argc, char **argv)
{
int64_t nblocks, bucketsize = 32, blocksize = 8;
int fd, i, c;
struct cache_sb sb;
- while ((c = getopt(argc, argv, "b:")) != -1) {
+ while ((c = getopt(argc, argv, "b:")) != -1)
switch (c) {
case 'b':
bucketsize = hatoi(optarg) / 512;
break;
}
- }
if (argc <= optind) {
printf("Please supply a device\n");