FreeBSD ZFS
The Zettabyte File System
Functions | Variables

zio_checksum.c File Reference

Checksum vectors. More...

#include <sys/zfs_context.h>
#include <sys/spa.h>
#include <sys/zio.h>
#include <sys/zio_checksum.h>
#include <sys/zil.h>
#include <zfs_fletcher.h>
Include dependency graph for zio_checksum.c:

Go to the source code of this file.

Functions

static void zio_checksum_off (const void *buf, uint64_t size, zio_cksum_t *zcp)
enum zio_checksum zio_checksum_select (enum zio_checksum child, enum zio_checksum parent)
enum zio_checksum zio_checksum_dedup_select (spa_t *spa, enum zio_checksum child, enum zio_checksum parent)
static void zio_checksum_gang_verifier (zio_cksum_t *zcp, blkptr_t *bp)
 Set the external verifier for a gang block based on <vdev, offset, txg>, a tuple which is guaranteed to be unique for the life of the pool.
static void zio_checksum_label_verifier (zio_cksum_t *zcp, uint64_t offset)
 Set the external verifier for a label block based on its offset.
void zio_checksum_compute (zio_t *zio, enum zio_checksum checksum, void *data, uint64_t size)
 Generate the checksum.
int zio_checksum_error (zio_t *zio, zio_bad_cksum_t *info)

Variables

zio_checksum_info_t zio_checksum_table [ZIO_CHECKSUM_FUNCTIONS]

Detailed Description

Checksum vectors.

In the SPA, everything is checksummed. We support checksum vectors for three distinct reasons:

1. Different kinds of data need different levels of protection. For SPA metadata, we always want a very strong checksum. For user data, we let users make the trade-off between speed and checksum strength.

2. Cryptographic hash and MAC algorithms are an area of active research. It is likely that in future hash functions will be at least as strong as current best-of-breed, and may be substantially faster as well. We want the ability to take advantage of these new hashes as soon as they become available.

3. If someone develops hardware that can compute a strong hash quickly, we want the ability to take advantage of that hardware.

Of course, we don't want a checksum upgrade to invalidate existing data, so we store the checksum *function* in eight bits of the bp. This gives us room for up to 256 different checksum functions.

When writing a block, we always checksum it with the latest-and-greatest checksum function of the appropriate strength. When reading a block, we compare the expected checksum against the actual checksum, which we compute via the checksum function specified by BP_GET_CHECKSUM(bp).

Definition in file zio_checksum.c.


Function Documentation

void zio_checksum_compute ( zio_t zio,
enum zio_checksum  checksum,
void *  data,
uint64_t  size 
)

Generate the checksum.

Definition at line 152 of file zio_checksum.c.

enum zio_checksum zio_checksum_dedup_select ( spa_t spa,
enum zio_checksum  child,
enum zio_checksum  parent 
)

Definition at line 100 of file zio_checksum.c.

int zio_checksum_error ( zio_t zio,
zio_bad_cksum_t info 
)

Definition at line 190 of file zio_checksum.c.

static void zio_checksum_gang_verifier ( zio_cksum_t zcp,
blkptr_t bp 
) [static]

Set the external verifier for a gang block based on <vdev, offset, txg>, a tuple which is guaranteed to be unique for the life of the pool.

Definition at line 127 of file zio_checksum.c.

static void zio_checksum_label_verifier ( zio_cksum_t zcp,
uint64_t  offset 
) [static]

Set the external verifier for a label block based on its offset.

The vdev is implicit, and the txg is unknowable at pool open time -- hence the logic in vdev_uberblock_load() to find the most recent copy.

Definition at line 143 of file zio_checksum.c.

static void zio_checksum_off ( const void *  buf,
uint64_t  size,
zio_cksum_t zcp 
) [static]

Definition at line 65 of file zio_checksum.c.

enum zio_checksum zio_checksum_select ( enum zio_checksum  child,
enum zio_checksum  parent 
)

Definition at line 84 of file zio_checksum.c.


Variable Documentation

zio_checksum_info_t zio_checksum_table[ZIO_CHECKSUM_FUNCTIONS]
Initial value:
 {
        {{NULL,                 NULL},                  0, 0, 0, "inherit"},
        {{NULL,                 NULL},                  0, 0, 0, "on"},
        {{zio_checksum_off,     zio_checksum_off},      0, 0, 0, "off"},
        {{zio_checksum_SHA256,  zio_checksum_SHA256},   1, 1, 0, "label"},
        {{zio_checksum_SHA256,  zio_checksum_SHA256},   1, 1, 0, "gang_header"},
        {{fletcher_2_native,    fletcher_2_byteswap},   0, 1, 0, "zilog"},
        {{fletcher_2_native,    fletcher_2_byteswap},   0, 0, 0, "fletcher2"},
        {{fletcher_4_native,    fletcher_4_byteswap},   1, 0, 0, "fletcher4"},
        {{zio_checksum_SHA256,  zio_checksum_SHA256},   1, 0, 1, "sha256"},
        {{fletcher_4_native,    fletcher_4_byteswap},   0, 1, 0, "zilog2"},
}

Definition at line 70 of file zio_checksum.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines