source: grub-pc/trunk/fuentes/debian/patches/zfs-embedded-data.patch @ 22

Last change on this file since 22 was 22, checked in by mabarracus, 4 years ago

updated version and apply net.ifnames=0 into debian/rules

File size: 6.9 KB
  • grub-core/fs/zfs/zfs.c

    From e6e24a1e97e1f5d7b1b9d9b8d3132d9f3510b2f6 Mon Sep 17 00:00:00 2001
    From: Toomas Soome <tsoome@me.com>
    Date: Thu, 16 Apr 2015 08:23:22 +0300
    Subject: zfs: com.delphix:embedded_data feature support
    
    Origin: upstream, http://git.savannah.gnu.org/cgit/grub.git/commit/?id=4a7ea4003bd9f39e9bf2ebadbe4ab38f8874be66
    Last-Update: 2016-01-22
    
    Patch-Name: zfs-embedded-data.patch
    ---
     grub-core/fs/zfs/zfs.c | 84 +++++++++++++++++++++++++++++++++++++++++---------
     include/grub/zfs/spa.h | 27 +++++++++++++---
     2 files changed, 93 insertions(+), 18 deletions(-)
    
    diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c
    index b01c34f..a95e7e3 100644
    a b grub_crypto_cipher_handle_t (*grub_zfs_load_key) (const struct grub_zfs_key *key 
    282282static const char *spa_feature_names[] = {
    283283  "org.illumos:lz4_compress",
    284284  "com.delphix:hole_birth",
     285  "com.delphix:embedded_data",
    285286  NULL
    286287};
    287288
    zio_read_data (blkptr_t * bp, grub_zfs_endian_t endian, void *buf, 
    18001801}
    18011802
    18021803/*
     1804 * buf must be at least BPE_GET_PSIZE(bp) bytes long (which will never be
     1805 * more than BPE_PAYLOAD_SIZE bytes).
     1806 */
     1807static grub_err_t
     1808decode_embedded_bp_compressed(const blkptr_t *bp, void *buf)
     1809{
     1810  grub_size_t psize, i;
     1811  grub_uint8_t *buf8 = buf;
     1812  grub_uint64_t w = 0;
     1813  const grub_uint64_t *bp64 = (const grub_uint64_t *)bp;
     1814
     1815  psize = BPE_GET_PSIZE(bp);
     1816
     1817  /*
     1818   * Decode the words of the block pointer into the byte array.
     1819   * Low bits of first word are the first byte (little endian).
     1820   */
     1821  for (i = 0; i < psize; i++)
     1822    {
     1823      if (i % sizeof (w) == 0)
     1824       {
     1825         /* beginning of a word */
     1826         w = *bp64;
     1827         bp64++;
     1828         if (!BPE_IS_PAYLOADWORD(bp, bp64))
     1829         bp64++;
     1830       }
     1831      buf8[i] = BF64_GET(w, (i % sizeof (w)) * 8, 8);
     1832    }
     1833  return GRUB_ERR_NONE;
     1834}
     1835
     1836/*
    18031837 * Read in a block of data, verify its checksum, decompress if needed,
    18041838 * and put the uncompressed data in buf.
    18051839 */
    zio_read (blkptr_t *bp, grub_zfs_endian_t endian, void **buf, 
    18171851  *buf = NULL;
    18181852
    18191853  checksum = (grub_zfs_to_cpu64((bp)->blk_prop, endian) >> 40) & 0xff;
    1820   comp = (grub_zfs_to_cpu64((bp)->blk_prop, endian)>>32) & 0xff;
     1854  comp = (grub_zfs_to_cpu64((bp)->blk_prop, endian)>>32) & 0x7f;
    18211855  encrypted = ((grub_zfs_to_cpu64((bp)->blk_prop, endian) >> 60) & 3);
    1822   lsize = (BP_IS_HOLE(bp) ? 0 :
    1823            (((grub_zfs_to_cpu64 ((bp)->blk_prop, endian) & 0xffff) + 1)
    1824             << SPA_MINBLOCKSHIFT));
    1825   psize = get_psize (bp, endian);
     1856  if (BP_IS_EMBEDDED(bp))
     1857    {
     1858      if (BPE_GET_ETYPE(bp) != BP_EMBEDDED_TYPE_DATA)
     1859        return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
     1860                           "unsupported embedded BP (type=%u)\n",
     1861                           BPE_GET_ETYPE(bp));
     1862      lsize = BPE_GET_LSIZE(bp);
     1863      psize = BF64_GET_SB(grub_zfs_to_cpu64 ((bp)->blk_prop, endian), 25, 7, 0, 1);
     1864    }
     1865  else
     1866    {
     1867      lsize = (BP_IS_HOLE(bp) ? 0 :
     1868               (((grub_zfs_to_cpu64 ((bp)->blk_prop, endian) & 0xffff) + 1)
     1869                << SPA_MINBLOCKSHIFT));
     1870      psize = get_psize (bp, endian);
     1871    }
     1872  grub_dprintf("zfs", "zio_read: E %d: size %" PRIdGRUB_SSIZE "/%"
     1873               PRIdGRUB_SSIZE "\n", (int)BP_IS_EMBEDDED(bp), lsize, psize);
    18261874
    18271875  if (size)
    18281876    *size = lsize;
    zio_read (blkptr_t *bp, grub_zfs_endian_t endian, void **buf, 
    18461894    compbuf = *buf = grub_malloc (lsize);
    18471895
    18481896  grub_dprintf ("zfs", "endian = %d\n", endian);
    1849   err = zio_read_data (bp, endian, compbuf, data);
     1897  if (BP_IS_EMBEDDED(bp))
     1898    err = decode_embedded_bp_compressed(bp, compbuf);
     1899  else
     1900    {
     1901      err = zio_read_data (bp, endian, compbuf, data);
     1902      grub_memset (compbuf, 0, ALIGN_UP (psize, 16) - psize);
     1903    }
    18501904  if (err)
    18511905    {
    18521906      grub_free (compbuf);
    18531907      *buf = NULL;
    18541908      return err;
    18551909    }
    1856   grub_memset (compbuf, 0, ALIGN_UP (psize, 16) - psize);
    18571910
    1858   err = zio_checksum_verify (zc, checksum, endian,
    1859                              compbuf, psize);
    1860   if (err)
     1911  if (!BP_IS_EMBEDDED(bp))
    18611912    {
    1862       grub_dprintf ("zfs", "incorrect checksum\n");
    1863       grub_free (compbuf);
    1864       *buf = NULL;
    1865       return err;
     1913      err = zio_checksum_verify (zc, checksum, endian,
     1914                                 compbuf, psize);
     1915      if (err)
     1916        {
     1917          grub_dprintf ("zfs", "incorrect checksum\n");
     1918          grub_free (compbuf);
     1919          *buf = NULL;
     1920          return err;
     1921        }
    18661922    }
    18671923
    18681924  if (encrypted)
  • include/grub/zfs/spa.h

    diff --git a/include/grub/zfs/spa.h b/include/grub/zfs/spa.h
    index df43b6b..8dd1fa8 100644
    a b typedef struct zio_cksum { 
    126126 *      +-------+-------+-------+-------+-------+-------+-------+-------+
    127127 * 5    |G|                      offset3                                |
    128128 *      +-------+-------+-------+-------+-------+-------+-------+-------+
    129  * 6    |BDX|lvl| type  | cksum | comp  |     PSIZE     |     LSIZE     |
     129 * 6    |BDX|lvl| type  | cksum |E| comp|     PSIZE     |     LSIZE     |
    130130 *      +-------+-------+-------+-------+-------+-------+-------+-------+
    131131 * 7    |                       padding                                 |
    132132 *      +-------+-------+-------+-------+-------+-------+-------+-------+
    typedef struct zio_cksum { 
    160160 * G            gang block indicator
    161161 * B            byteorder (endianness)
    162162 * D            dedup
    163  * X            unused
     163 * X            encryption
     164 * E            blkptr_t contains embedded data
    164165 * lvl          level of indirection
    165166 * type         DMU object type
    166167 * phys birth   txg of block allocation; zero if same as logical birth txg
    typedef struct blkptr { 
    203204#define BP_SET_LSIZE(bp, x)     \
    204205        BF64_SET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1, x)
    205206
    206 #define BP_GET_COMPRESS(bp)             BF64_GET((bp)->blk_prop, 32, 8)
    207 #define BP_SET_COMPRESS(bp, x)          BF64_SET((bp)->blk_prop, 32, 8, x)
     207#define BP_GET_COMPRESS(bp)             BF64_GET((bp)->blk_prop, 32, 7)
     208#define BP_SET_COMPRESS(bp, x)          BF64_SET((bp)->blk_prop, 32, 7, x)
    208209
    209210#define BP_GET_CHECKSUM(bp)             BF64_GET((bp)->blk_prop, 40, 8)
    210211#define BP_SET_CHECKSUM(bp, x)          BF64_SET((bp)->blk_prop, 40, 8, x)
    typedef struct blkptr { 
    215216#define BP_GET_LEVEL(bp)                BF64_GET((bp)->blk_prop, 56, 5)
    216217#define BP_SET_LEVEL(bp, x)             BF64_SET((bp)->blk_prop, 56, 5, x)
    217218
     219#define BP_IS_EMBEDDED(bp)              BF64_GET((bp)->blk_prop, 39, 1)
     220
    218221#define BP_GET_PROP_BIT_61(bp)          BF64_GET((bp)->blk_prop, 61, 1)
    219222#define BP_SET_PROP_BIT_61(bp, x)       BF64_SET((bp)->blk_prop, 61, 1, x)
    220223
    typedef struct blkptr { 
    277280        (zcp)->zc_word[3] = w3;                 \
    278281}
    279282
     283#define BPE_GET_ETYPE(bp)       BP_GET_CHECKSUM(bp)
     284#define BPE_GET_LSIZE(bp)       \
     285        BF64_GET_SB((bp)->blk_prop, 0, 25, 0, 1)
     286#define BPE_GET_PSIZE(bp)       \
     287        BF64_GET_SB((bp)->blk_prop, 25, 7, 0, 1)
     288
     289typedef enum bp_embedded_type {
     290  BP_EMBEDDED_TYPE_DATA,
     291  NUM_BP_EMBEDDED_TYPES
     292} bp_embedded_type_t;
     293
     294#define BPE_NUM_WORDS   14
     295#define BPE_PAYLOAD_SIZE        (BPE_NUM_WORDS * sizeof(grub_uint64_t))
     296#define BPE_IS_PAYLOADWORD(bp, wp)      \
     297        ((wp) != &(bp)->blk_prop && (wp) != &(bp)->blk_birth)
     298
    280299#define BP_IDENTITY(bp)         (&(bp)->blk_dva[0])
    281300#define BP_IS_GANG(bp)          DVA_GET_GANG(BP_IDENTITY(bp))
    282301#define DVA_IS_EMPTY(dva)       ((dva)->dva_word[0] == 0ULL && \
Note: See TracBrowser for help on using the repository browser.