#include "crc/sha256.h"
#include "crc/sha512.h"
#include "crc/sha1.h"
+#include "crc/xxhash.h"
static void populate_hdr(struct thread_data *td, struct io_u *io_u,
struct verify_header *hdr, unsigned int header_num,
case VERIFY_SHA512:
len = sizeof(struct vhdr_sha512);
break;
+ case VERIFY_XXHASH:
+ len = sizeof(struct vhdr_xxhash);
+ break;
case VERIFY_META:
len = sizeof(struct vhdr_meta);
break;
unsigned int crc_len;
};
+#define DUMP_BUF_SZ 255
+static int dump_buf_warned;
+
static void dump_buf(char *buf, unsigned int len, unsigned long long offset,
const char *type, struct fio_file *f)
{
- char *ptr, fname[256];
+ char *ptr, fname[DUMP_BUF_SZ];
+ size_t buf_left = DUMP_BUF_SZ;
int ret, fd;
ptr = strdup(f->file_name);
- strcpy(fname, basename(ptr));
- sprintf(fname + strlen(fname), ".%llu.%s", offset, type);
+ fname[DUMP_BUF_SZ - 1] = '\0';
+ strncpy(fname, basename(ptr), DUMP_BUF_SZ - 1);
+
+ buf_left -= strlen(fname);
+ if (buf_left <= 0) {
+ if (!dump_buf_warned) {
+ log_err("fio: verify failure dump buffer too small\n");
+ dump_buf_warned = 1;
+ }
+ free(ptr);
+ return;
+ }
+
+ snprintf(fname + strlen(fname), buf_left, ".%llu.%s", offset, type);
fd = open(fname, O_CREAT | O_TRUNC | O_WRONLY, 0644);
if (fd < 0) {
return ret;
}
+static int verify_io_u_xxhash(struct verify_header *hdr, struct vcont *vc)
+{
+ void *p = io_u_verify_off(hdr, vc);
+ struct vhdr_xxhash *vh = hdr_priv(hdr);
+ uint32_t hash;
+ void *state;
+
+ dprint(FD_VERIFY, "xxhash verify io_u %p, len %u\n", vc->io_u, hdr->len);
+
+ state = XXH32_init(1);
+ XXH32_update(state, p, hdr->len - hdr_size(hdr));
+ hash = XXH32_digest(state);
+
+ if (vh->hash == hash)
+ return 0;
+
+ vc->name = "xxhash";
+ vc->good_crc = &vh->hash;
+ vc->bad_crc = &hash;
+ vc->crc_len = sizeof(hash);
+ log_verify_failure(hdr, vc);
+ return EILSEQ;
+}
+
static int verify_io_u_sha512(struct verify_header *hdr, struct vcont *vc)
{
void *p = io_u_verify_off(hdr, vc);
case VERIFY_SHA512:
ret = verify_io_u_sha512(hdr, &vc);
break;
+ case VERIFY_XXHASH:
+ ret = verify_io_u_xxhash(hdr, &vc);
+ break;
case VERIFY_META:
ret = verify_io_u_meta(hdr, &vc);
break;
vh->offset = io_u->offset + header_num * td->o.verify_interval;
}
+static void fill_xxhash(struct verify_header *hdr, void *p, unsigned int len)
+{
+ struct vhdr_xxhash *vh = hdr_priv(hdr);
+ void *state;
+
+ state = XXH32_init(1);
+ XXH32_update(state, p, len);
+ vh->hash = XXH32_digest(state);
+}
+
static void fill_sha512(struct verify_header *hdr, void *p, unsigned int len)
{
struct vhdr_sha512 *vh = hdr_priv(hdr);
io_u, hdr->len);
fill_sha512(hdr, data, data_len);
break;
+ case VERIFY_XXHASH:
+ dprint(FD_VERIFY, "fill xxhash io_u %p, len %u\n",
+ io_u, hdr->len);
+ fill_xxhash(hdr, data, data_len);
+ break;
case VERIFY_META:
dprint(FD_VERIFY, "fill meta io_u %p, len %u\n",
io_u, hdr->len);