Print this page
4185 New hash algorithm support


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2012 by Delphix. All rights reserved.
  24  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.

  25  */
  26 
  27 #ifndef _SYS_SPA_H
  28 #define _SYS_SPA_H
  29 
  30 #include <sys/avl.h>
  31 #include <sys/zfs_context.h>
  32 #include <sys/nvpair.h>
  33 #include <sys/sysmacros.h>
  34 #include <sys/types.h>
  35 #include <sys/fs/zfs.h>
  36 
  37 #ifdef  __cplusplus
  38 extern "C" {
  39 #endif
  40 
  41 /*
  42  * Forward references that lots of things need.
  43  */
  44 typedef struct spa spa_t;
  45 typedef struct vdev vdev_t;
  46 typedef struct metaslab metaslab_t;
  47 typedef struct metaslab_group metaslab_group_t;
  48 typedef struct metaslab_class metaslab_class_t;
  49 typedef struct zio zio_t;
  50 typedef struct zilog zilog_t;
  51 typedef struct spa_aux_vdev spa_aux_vdev_t;
  52 typedef struct ddt ddt_t;
  53 typedef struct ddt_entry ddt_entry_t;
  54 struct dsl_pool;
  55 struct dsl_dataset;

  56 
  57 /*
  58  * General-purpose 32-bit and 64-bit bitfield encodings.
  59  */
  60 #define BF32_DECODE(x, low, len)        P2PHASE((x) >> (low), 1U << (len))
  61 #define BF64_DECODE(x, low, len)        P2PHASE((x) >> (low), 1ULL << (len))
  62 #define BF32_ENCODE(x, low, len)        (P2PHASE((x), 1U << (len)) << (low))
  63 #define BF64_ENCODE(x, low, len)        (P2PHASE((x), 1ULL << (len)) << (low))
  64 
  65 #define BF32_GET(x, low, len)           BF32_DECODE(x, low, len)
  66 #define BF64_GET(x, low, len)           BF64_DECODE(x, low, len)
  67 
  68 #define BF32_SET(x, low, len, val)      \
  69         ((x) ^= BF32_ENCODE((x >> low) ^ (val), low, len))
  70 #define BF64_SET(x, low, len, val)      \
  71         ((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len))
  72 
  73 #define BF32_GET_SB(x, low, len, shift, bias)   \
  74         ((BF32_GET(x, low, len) + (bias)) << (shift))
  75 #define BF64_GET_SB(x, low, len, shift, bias)   \


 107 #define SPA_LSIZEBITS           16      /* LSIZE up to 32M (2^16 * 512) */
 108 #define SPA_PSIZEBITS           16      /* PSIZE up to 32M (2^16 * 512) */
 109 #define SPA_ASIZEBITS           24      /* ASIZE up to 64 times larger  */
 110 
 111 /*
 112  * All SPA data is represented by 128-bit data virtual addresses (DVAs).
 113  * The members of the dva_t should be considered opaque outside the SPA.
 114  */
 115 typedef struct dva {
 116         uint64_t        dva_word[2];
 117 } dva_t;
 118 
 119 /*
 120  * Each block has a 256-bit checksum -- strong enough for cryptographic hashes.
 121  */
 122 typedef struct zio_cksum {
 123         uint64_t        zc_word[4];
 124 } zio_cksum_t;
 125 
 126 /*








 127  * Each block is described by its DVAs, time of birth, checksum, etc.
 128  * The word-by-word, bit-by-bit layout of the blkptr is as follows:
 129  *
 130  *      64      56      48      40      32      24      16      8       0
 131  *      +-------+-------+-------+-------+-------+-------+-------+-------+
 132  * 0    |               vdev1           | GRID  |         ASIZE         |
 133  *      +-------+-------+-------+-------+-------+-------+-------+-------+
 134  * 1    |G|                      offset1                                |
 135  *      +-------+-------+-------+-------+-------+-------+-------+-------+
 136  * 2    |               vdev2           | GRID  |         ASIZE         |
 137  *      +-------+-------+-------+-------+-------+-------+-------+-------+
 138  * 3    |G|                      offset2                                |
 139  *      +-------+-------+-------+-------+-------+-------+-------+-------+
 140  * 4    |               vdev3           | GRID  |         ASIZE         |
 141  *      +-------+-------+-------+-------+-------+-------+-------+-------+
 142  * 5    |G|                      offset3                                |
 143  *      +-------+-------+-------+-------+-------+-------+-------+-------+
 144  * 6    |BDX|lvl| type  | cksum | comp  |     PSIZE     |     LSIZE     |
 145  *      +-------+-------+-------+-------+-------+-------+-------+-------+
 146  * 7    |                       padding                                 |


 606 extern boolean_t spa_guid_exists(uint64_t pool_guid, uint64_t device_guid);
 607 extern char *spa_strdup(const char *);
 608 extern void spa_strfree(char *);
 609 extern uint64_t spa_get_random(uint64_t range);
 610 extern uint64_t spa_generate_guid(spa_t *spa);
 611 extern void sprintf_blkptr(char *buf, const blkptr_t *bp);
 612 extern void spa_freeze(spa_t *spa);
 613 extern int spa_change_guid(spa_t *spa);
 614 extern void spa_upgrade(spa_t *spa, uint64_t version);
 615 extern void spa_evict_all(void);
 616 extern vdev_t *spa_lookup_by_guid(spa_t *spa, uint64_t guid,
 617     boolean_t l2cache);
 618 extern boolean_t spa_has_spare(spa_t *, uint64_t guid);
 619 extern uint64_t dva_get_dsize_sync(spa_t *spa, const dva_t *dva);
 620 extern uint64_t bp_get_dsize_sync(spa_t *spa, const blkptr_t *bp);
 621 extern uint64_t bp_get_dsize(spa_t *spa, const blkptr_t *bp);
 622 extern boolean_t spa_has_slogs(spa_t *spa);
 623 extern boolean_t spa_is_root(spa_t *spa);
 624 extern boolean_t spa_writeable(spa_t *spa);
 625 



 626 extern int spa_mode(spa_t *spa);
 627 extern uint64_t strtonum(const char *str, char **nptr);
 628 
 629 extern char *spa_his_ievent_table[];
 630 
 631 extern void spa_history_create_obj(spa_t *spa, dmu_tx_t *tx);
 632 extern int spa_history_get(spa_t *spa, uint64_t *offset, uint64_t *len_read,
 633     char *his_buf);
 634 extern int spa_history_log(spa_t *spa, const char *his_buf);
 635 extern int spa_history_log_nvl(spa_t *spa, nvlist_t *nvl);
 636 extern void spa_history_log_version(spa_t *spa, const char *operation);
 637 extern void spa_history_log_internal(spa_t *spa, const char *operation,
 638     dmu_tx_t *tx, const char *fmt, ...);
 639 extern void spa_history_log_internal_ds(struct dsl_dataset *ds, const char *op,
 640     dmu_tx_t *tx, const char *fmt, ...);
 641 extern void spa_history_log_internal_dd(dsl_dir_t *dd, const char *operation,
 642     dmu_tx_t *tx, const char *fmt, ...);
 643 
 644 /* error handling */
 645 struct zbookmark;




   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2012 by Delphix. All rights reserved.
  24  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  25  * Copyright 2013 Saso Kiselkov. All rights reserved.
  26  */
  27 
  28 #ifndef _SYS_SPA_H
  29 #define _SYS_SPA_H
  30 
  31 #include <sys/avl.h>
  32 #include <sys/zfs_context.h>
  33 #include <sys/nvpair.h>
  34 #include <sys/sysmacros.h>
  35 #include <sys/types.h>
  36 #include <sys/fs/zfs.h>
  37 
  38 #ifdef  __cplusplus
  39 extern "C" {
  40 #endif
  41 
  42 /*
  43  * Forward references that lots of things need.
  44  */
  45 typedef struct spa spa_t;
  46 typedef struct vdev vdev_t;
  47 typedef struct metaslab metaslab_t;
  48 typedef struct metaslab_group metaslab_group_t;
  49 typedef struct metaslab_class metaslab_class_t;
  50 typedef struct zio zio_t;
  51 typedef struct zilog zilog_t;
  52 typedef struct spa_aux_vdev spa_aux_vdev_t;
  53 typedef struct ddt ddt_t;
  54 typedef struct ddt_entry ddt_entry_t;
  55 struct dsl_pool;
  56 struct dsl_dataset;
  57 struct zfeature_info;
  58 
  59 /*
  60  * General-purpose 32-bit and 64-bit bitfield encodings.
  61  */
  62 #define BF32_DECODE(x, low, len)        P2PHASE((x) >> (low), 1U << (len))
  63 #define BF64_DECODE(x, low, len)        P2PHASE((x) >> (low), 1ULL << (len))
  64 #define BF32_ENCODE(x, low, len)        (P2PHASE((x), 1U << (len)) << (low))
  65 #define BF64_ENCODE(x, low, len)        (P2PHASE((x), 1ULL << (len)) << (low))
  66 
  67 #define BF32_GET(x, low, len)           BF32_DECODE(x, low, len)
  68 #define BF64_GET(x, low, len)           BF64_DECODE(x, low, len)
  69 
  70 #define BF32_SET(x, low, len, val)      \
  71         ((x) ^= BF32_ENCODE((x >> low) ^ (val), low, len))
  72 #define BF64_SET(x, low, len, val)      \
  73         ((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len))
  74 
  75 #define BF32_GET_SB(x, low, len, shift, bias)   \
  76         ((BF32_GET(x, low, len) + (bias)) << (shift))
  77 #define BF64_GET_SB(x, low, len, shift, bias)   \


 109 #define SPA_LSIZEBITS           16      /* LSIZE up to 32M (2^16 * 512) */
 110 #define SPA_PSIZEBITS           16      /* PSIZE up to 32M (2^16 * 512) */
 111 #define SPA_ASIZEBITS           24      /* ASIZE up to 64 times larger  */
 112 
 113 /*
 114  * All SPA data is represented by 128-bit data virtual addresses (DVAs).
 115  * The members of the dva_t should be considered opaque outside the SPA.
 116  */
 117 typedef struct dva {
 118         uint64_t        dva_word[2];
 119 } dva_t;
 120 
 121 /*
 122  * Each block has a 256-bit checksum -- strong enough for cryptographic hashes.
 123  */
 124 typedef struct zio_cksum {
 125         uint64_t        zc_word[4];
 126 } zio_cksum_t;
 127 
 128 /*
 129  * Some checksums/hashes need a 256-bit initialization salt. This salt is kept
 130  * secret and is suitable for use in MAC algorithms as the key.
 131  */
 132 typedef struct zio_cksum_salt {
 133         uint8_t         zcs_bytes[32];
 134 } zio_cksum_salt_t;
 135 
 136 /*
 137  * Each block is described by its DVAs, time of birth, checksum, etc.
 138  * The word-by-word, bit-by-bit layout of the blkptr is as follows:
 139  *
 140  *      64      56      48      40      32      24      16      8       0
 141  *      +-------+-------+-------+-------+-------+-------+-------+-------+
 142  * 0    |               vdev1           | GRID  |         ASIZE         |
 143  *      +-------+-------+-------+-------+-------+-------+-------+-------+
 144  * 1    |G|                      offset1                                |
 145  *      +-------+-------+-------+-------+-------+-------+-------+-------+
 146  * 2    |               vdev2           | GRID  |         ASIZE         |
 147  *      +-------+-------+-------+-------+-------+-------+-------+-------+
 148  * 3    |G|                      offset2                                |
 149  *      +-------+-------+-------+-------+-------+-------+-------+-------+
 150  * 4    |               vdev3           | GRID  |         ASIZE         |
 151  *      +-------+-------+-------+-------+-------+-------+-------+-------+
 152  * 5    |G|                      offset3                                |
 153  *      +-------+-------+-------+-------+-------+-------+-------+-------+
 154  * 6    |BDX|lvl| type  | cksum | comp  |     PSIZE     |     LSIZE     |
 155  *      +-------+-------+-------+-------+-------+-------+-------+-------+
 156  * 7    |                       padding                                 |


 616 extern boolean_t spa_guid_exists(uint64_t pool_guid, uint64_t device_guid);
 617 extern char *spa_strdup(const char *);
 618 extern void spa_strfree(char *);
 619 extern uint64_t spa_get_random(uint64_t range);
 620 extern uint64_t spa_generate_guid(spa_t *spa);
 621 extern void sprintf_blkptr(char *buf, const blkptr_t *bp);
 622 extern void spa_freeze(spa_t *spa);
 623 extern int spa_change_guid(spa_t *spa);
 624 extern void spa_upgrade(spa_t *spa, uint64_t version);
 625 extern void spa_evict_all(void);
 626 extern vdev_t *spa_lookup_by_guid(spa_t *spa, uint64_t guid,
 627     boolean_t l2cache);
 628 extern boolean_t spa_has_spare(spa_t *, uint64_t guid);
 629 extern uint64_t dva_get_dsize_sync(spa_t *spa, const dva_t *dva);
 630 extern uint64_t bp_get_dsize_sync(spa_t *spa, const blkptr_t *bp);
 631 extern uint64_t bp_get_dsize(spa_t *spa, const blkptr_t *bp);
 632 extern boolean_t spa_has_slogs(spa_t *spa);
 633 extern boolean_t spa_is_root(spa_t *spa);
 634 extern boolean_t spa_writeable(spa_t *spa);
 635 
 636 /* Salted checksum handling */
 637 extern int spa_activate_salted_cksum(spa_t *spa, struct zfeature_info *feature);
 638 
 639 extern int spa_mode(spa_t *spa);
 640 extern uint64_t strtonum(const char *str, char **nptr);
 641 
 642 extern char *spa_his_ievent_table[];
 643 
 644 extern void spa_history_create_obj(spa_t *spa, dmu_tx_t *tx);
 645 extern int spa_history_get(spa_t *spa, uint64_t *offset, uint64_t *len_read,
 646     char *his_buf);
 647 extern int spa_history_log(spa_t *spa, const char *his_buf);
 648 extern int spa_history_log_nvl(spa_t *spa, nvlist_t *nvl);
 649 extern void spa_history_log_version(spa_t *spa, const char *operation);
 650 extern void spa_history_log_internal(spa_t *spa, const char *operation,
 651     dmu_tx_t *tx, const char *fmt, ...);
 652 extern void spa_history_log_internal_ds(struct dsl_dataset *ds, const char *op,
 653     dmu_tx_t *tx, const char *fmt, ...);
 654 extern void spa_history_log_internal_dd(dsl_dir_t *dd, const char *operation,
 655     dmu_tx_t *tx, const char *fmt, ...);
 656 
 657 /* error handling */
 658 struct zbookmark;