Commit 8287ca30 authored by Keir Fraser's avatar Keir Fraser

Port latest grub zfs boot code to pygrub

Signed-off-by: default avatarMark Johnson <mark.r.johnson@oracle.com>

Add -Werror to CFLAGS and fix numerous warnings/errors.
Signed-off-by: default avatarKeir Fraser <keir.fraser@citrix.com>
parent 58895a2e
include $(XEN_ROOT)/tools/Rules.mk
CFLAGS += -I$(XEN_ROOT)/tools/libfsimage/common/ -Werror
CFLAGS += -Wno-unknown-pragmas -I$(XEN_ROOT)/tools/libfsimage/common/
CFLAGS += -Werror -D_GNU_SOURCE
LDFLAGS += -L../common/
PIC_OBJS := $(patsubst %.c,%.opic,$(LIB_SRCS-y))
......
......@@ -78,6 +78,7 @@ unsigned long fsig_log2(unsigned long);
#define ERR_DEV_VALUES 1
#define ERR_WONT_FIT 1
#define ERR_READ 1
#define ERR_NEWER_VERSION 1
fsi_plugin_ops_t *fsig_init(fsi_plugin_t *, fsig_plugin_ops_t *);
......
......@@ -24,7 +24,8 @@
XEN_ROOT = ../../..
LIB_SRCS-y = fsys_zfs.c zfs_lzjb.c zfs_sha256.c zfs_fletcher.c
CFLAGS += -DFSYS_ZFS -DFSIMAGE -I$(XEN_ROOT)/tools/libfsimage/zfs
LIB_SRCS-y = zfs_lzjb.c zfs_sha256.c zfs_fletcher.c fsi_zfs.c fsys_zfs.c
FS = zfs
......
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _FILESYS_H
#define _FILESYS_H
#ifdef FSYS_ZFS
/* THIS FILE IS INTENTIONALLY BLANK */
#endif /* FSI_ZFS */
#endif /* !_FILESYS_H */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifdef FSYS_ZFS
#include <fsimage_grub.h>
#include <fsimage_priv.h>
#include <stdio.h>
#include <inttypes.h>
#include "mb_info.h"
#undef filemax
#undef filepos
#undef errnum
#define MAXNAMELEN 256
#define MAXPATHLEN 1024
/**** START FROM disk_io.c ****/
char current_rootpool[MAXNAMELEN];
char current_bootfs[MAXNAMELEN];
uint64_t current_bootfs_obj;
char current_bootpath[MAXPATHLEN];
char current_devid[MAXPATHLEN];
int is_zfs_mount;
unsigned long best_drive;
unsigned long best_part;
int find_best_root;
unsigned long part_length;
/**** END FROM disk_io.c ****/
uint64_t filemax;
uint64_t filepos;
struct multiboot_info mbi;
fsi_file_t *zfs_ffi;
int errnum;
char *bootstring = NULL;
extern int zfs_mount(void);
extern int zfs_open(char *filename);
extern int zfs_read(char *buf, int len);
#define ZFS_SCRATCH_SIZE 0x400000
#define FSI_MOS_SHIFT 10
#define FSI_MOS_MASK ((1 << FSI_MOS_SHIFT) - 1)
unsigned char fsi_mos_buf[ZFS_SCRATCH_SIZE + FSI_MOS_MASK + 1];
#define FSI_MOS_ALIGN(addr) (((uintptr_t)addr + FSI_MOS_MASK) & \
~FSI_MOS_MASK)
#define FSI_MOS(buf) ((FSI_MOS_ALIGN(buf) + \
ZFS_SCRATCH_SIZE - 0x100000) >> FSI_MOS_SHIFT)
static int
fsi_zfs_mount(fsi_file_t *ffi, const char *options)
{
zfs_ffi = ffi;
mbi.mem_upper = FSI_MOS(fsi_mos_buf);
/* If an boot filesystem is passed in, set it to current_bootfs */
if (options != NULL) {
if (strlen(options) < MAXNAMELEN) {
strcpy(current_bootfs, options);
}
}
return (zfs_mount());
}
static int
fsi_zfs_open(fsi_file_t *ffi, char *filename)
{
char *fsi_bootstring;
uint64_t *fmax;
uint64_t *fpos;
int rc;
zfs_ffi = ffi;
fmax = fsig_filemax(ffi);
fpos = fsig_filepos(ffi);
rc = zfs_open(filename);
if (rc != 1) {
return (rc);
}
*fmax = filemax;
*fpos = filepos;
if (bootstring == NULL) {
rc = asprintf(&bootstring,
"zfs-bootfs=%s/%"PRIu64",bootpath='%s'",
current_rootpool, current_bootfs_obj,
current_bootpath);
if (rc == -1) {
return (rc);
}
fsi_bootstring = fsi_bootstring_alloc(ffi->ff_fsi,
strlen(bootstring) + 1);
strcpy(fsi_bootstring, bootstring);
}
return (rc);
}
static int
fsi_zfs_read(fsi_file_t *ffi, char *buf, int len)
{
uint64_t *fpos;
int rc;
zfs_ffi = ffi;
fpos = fsig_filepos(ffi);
filepos = *fpos;
rc = zfs_read(buf, len);
*fpos = filepos;
return (rc);
}
fsi_plugin_ops_t *
fsi_init_plugin(int version, fsi_plugin_t *fp, const char **name)
{
static fsig_plugin_ops_t ops = {
FSIMAGE_PLUGIN_VERSION,
.fpo_mount = fsi_zfs_mount,
.fpo_dir = fsi_zfs_open,
.fpo_read = fsi_zfs_read,
};
*name = "zfs";
return (fsig_init(fp, &ops));
}
#endif /* FSYS_ZFS */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _FSI_ZFS_H
#define _FSI_ZFS_H
#ifdef FSYS_ZFS
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <fsimage_grub.h>
/*** START FROM shared.h ****/
#include "mb_info.h"
/* Boot signature related defines for the findroot command */
#define BOOTSIGN_DIR "/boot/grub/bootsign"
#define BOOTSIGN_BACKUP "/etc/bootsign"
/* Maybe redirect memory requests through grub_scratch_mem. */
#define RAW_ADDR(x) (x)
#define RAW_SEG(x) (x)
/* ZFS will use the top 4 Meg of physical memory (below 4Gig) for sratch */
#define ZFS_SCRATCH_SIZE 0x400000
#define MAXPATHLEN 1024
#define MAXNAMELEN 256
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAXUINT 0xFFFFFFFF
#undef NULL
#define NULL ((void *) 0)
#define grub_printf printf
#define grub_strcmp strcmp
#define grub_strncmp strncmp
#define grub_strstr strstr
#define grub_strlen strlen
#define grub_memmove memmove
extern char current_bootpath[MAXPATHLEN];
extern char current_rootpool[MAXNAMELEN];
extern char current_bootfs[MAXNAMELEN];
extern uint64_t current_bootfs_obj;
extern char current_devid[MAXPATHLEN];
extern int is_zfs_mount;
extern unsigned long best_drive;
extern unsigned long best_part;
extern int find_best_root;
extern unsigned long part_length;
#undef filemax
#undef filepos
extern uint64_t filemax;
extern uint64_t filepos;
extern struct multiboot_info mbi;
/*** END FROM shared.h ***/
#ifdef __linux__
typedef unsigned char uchar_t;
#endif
typedef struct fsi_file *fsi_file_handle_t;
extern fsi_file_handle_t zfs_ffi;
extern int fsig_devread(fsi_file_handle_t, unsigned int, unsigned int,
unsigned int, char *);
#undef devread
#define devread(a, b, c, d) fsig_devread(zfs_ffi, a, b, c, d)
#undef errnum
extern int errnum;
#endif /* FSI_ZFS */
#endif /* !_FSI_ZFS_H */
This diff is collapsed.
......@@ -17,64 +17,56 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _FSYS_ZFS_H
#define _FSYS_ZFS_H
#include <fsimage_grub.h>
#include <fsimage_priv.h>
#include "zfs-include/zfs.h"
#include "zfs-include/dmu.h"
#include "zfs-include/spa.h"
#include "zfs-include/zio.h"
#include "zfs-include/zio_checksum.h"
#include "zfs-include/vdev_impl.h"
#include "zfs-include/zap_impl.h"
#include "zfs-include/zap_leaf.h"
#include "zfs-include/uberblock_impl.h"
#include "zfs-include/dnode.h"
#include "zfs-include/dsl_dir.h"
#include "zfs-include/zfs_acl.h"
#include "zfs-include/zfs_znode.h"
#include "zfs-include/dsl_dataset.h"
#include "zfs-include/zil.h"
#include "zfs-include/dmu_objset.h"
#ifdef FSYS_ZFS
#ifndef FSIMAGE
typedef unsigned long long uint64_t;
typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
typedef unsigned char uchar_t;
#if defined(_LP64) || defined(_I32LPx)
typedef unsigned long size_t;
#else
typedef unsigned int size_t;
#endif
#else
#include "fsi_zfs.h"
#endif /* !FSIMAGE */
#include <zfs-include/zfs.h>
#include <zfs-include/dmu.h>
#include <zfs-include/spa.h>
#include <zfs-include/zio.h>
#include <zfs-include/zio_checksum.h>
#include <zfs-include/vdev_impl.h>
#include <zfs-include/zap_impl.h>
#include <zfs-include/zap_leaf.h>
#include <zfs-include/uberblock_impl.h>
#include <zfs-include/dnode.h>
#include <zfs-include/dsl_dir.h>
#include <zfs-include/zfs_acl.h>
#include <zfs-include/zfs_znode.h>
#include <zfs-include/dsl_dataset.h>
#include <zfs-include/zil.h>
#include <zfs-include/dmu_objset.h>
#include <zfs-include/sa_impl.h>
/*
* Global Memory addresses to store MOS and DNODE data
*/
#define MOS ((dnode_phys_t *)(((zfs_bootarea_t *) \
(ffi->ff_fsi->f_data))->zfs_data))
#define MOS ((dnode_phys_t *)\
(RAW_ADDR((mbi.mem_upper << 10) + 0x100000) - ZFS_SCRATCH_SIZE))
#define DNODE (MOS+1) /* move sizeof(dnode_phys_t) bytes */
#define ZFS_SCRATCH ((char *)(DNODE+1))
#define MAXNAMELEN 256
typedef struct zfs_bootarea {
char zfs_current_bootpath[MAXNAMELEN];
char zfs_current_rootpool[MAXNAMELEN];
char zfs_current_bootfs[MAXNAMELEN];
uint64_t zfs_current_bootfs_obj;
int zfs_open;
/* cache for a file block of the currently zfs_open()-ed file */
void *zfs_file_buf;
uint64_t zfs_file_start;
uint64_t zfs_file_end;
/* cache for a dnode block */
dnode_phys_t *zfs_dnode_buf;
dnode_phys_t *zfs_dnode_mdn;
uint64_t zfs_dnode_start;
uint64_t zfs_dnode_end;
char *zfs_stackbase;
char zfs_data[0x400000];
} zfs_bootarea_t;
/*
* Verify dnode type.
* Can only be used in functions returning non-0 for failure.
......@@ -108,9 +100,8 @@ typedef struct zfs_bootarea {
* can support large sector disks.
*/
#define UBERBLOCK_SIZE (1ULL << UBERBLOCK_SHIFT)
#undef offsetof
#define offsetof(t, m) (size_t)(&(((t *)0)->m))
#define VDEV_UBERBLOCK_SHIFT UBERBLOCK_SHIFT
#include <stddef.h>
#define VDEV_UBERBLOCK_OFFSET(n) \
offsetof(vdev_label_t, vl_uberblock[(n) << VDEV_UBERBLOCK_SHIFT])
......@@ -120,8 +111,8 @@ typedef struct uberblock uberblock_t;
typedef struct uberblock_phys {
uberblock_t ubp_uberblock;
char ubp_pad[UBERBLOCK_SIZE - sizeof (uberblock_t) -
sizeof (zio_block_tail_t)];
zio_block_tail_t ubp_zbt;
sizeof (zio_eck_t)];
zio_eck_t ubp_zec;
} uberblock_phys_t;
/*
......@@ -131,6 +122,15 @@ typedef struct uberblock_phys {
#define DVA_OFFSET_TO_PHYS_SECTOR(offset) \
((offset + VDEV_LABEL_START_SIZE) >> SPA_MINBLOCKSHIFT)
/*
* return x rounded down to an align boundary
* eg, P2ALIGN(1200, 1024) == 1024 (1*align)
* eg, P2ALIGN(1024, 1024) == 1024 (1*align)
* eg, P2ALIGN(0x1234, 0x100) == 0x1200 (0x12*align)
* eg, P2ALIGN(0x5600, 0x100) == 0x5600 (0x56*align)
*/
#define P2ALIGN(x, align) ((x) & -(align))
/*
* For nvlist manipulation. (from nvpair.h)
*/
......@@ -200,4 +200,6 @@ extern void fletcher_4_byteswap(const void *, uint64_t, zio_cksum_t *);
extern void zio_checksum_SHA256(const void *, uint64_t, zio_cksum_t *);
extern int lzjb_decompress(void *, void *, size_t, size_t);
#endif /* FSYS_ZFS */
#endif /* !_FSYS_ZFS_H */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _SHARED_H
#define _SHARED_H
#ifdef FSYS_ZFS
/* THIS FILE IS INTENTIONALLY BLANK */
#endif /* FSI_ZFS */
#endif /* !_SHARED_H */
......@@ -17,7 +17,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
......@@ -56,7 +56,7 @@ typedef enum dmu_object_type {
DMU_OT_DSL_DATASET, /* UINT64 */
/* zpl: */
DMU_OT_ZNODE, /* ZNODE */
DMU_OT_ACL, /* ACL */
DMU_OT_OLDACL, /* OLD ACL */
DMU_OT_PLAIN_FILE_CONTENTS, /* UINT8 */
DMU_OT_DIRECTORY_CONTENTS, /* ZAP */
DMU_OT_MASTER_NODE, /* ZAP */
......@@ -73,7 +73,22 @@ typedef enum dmu_object_type {
DMU_OT_SPA_HISTORY, /* UINT8 */
DMU_OT_SPA_HISTORY_OFFSETS, /* spa_his_phys_t */
DMU_OT_POOL_PROPS, /* ZAP */
DMU_OT_DSL_PERMS, /* ZAP */
DMU_OT_ACL, /* ACL */
DMU_OT_SYSACL, /* SYSACL */
DMU_OT_FUID, /* FUID table (Packed NVLIST UINT8) */
DMU_OT_FUID_SIZE, /* FUID table size UINT64 */
DMU_OT_NEXT_CLONES, /* ZAP */
DMU_OT_SCRUB_QUEUE, /* ZAP */
DMU_OT_USERGROUP_USED, /* ZAP */
DMU_OT_USERGROUP_QUOTA, /* ZAP */
DMU_OT_USERREFS, /* ZAP */
DMU_OT_DDT_ZAP, /* ZAP */
DMU_OT_DDT_STATS, /* ZAP */
DMU_OT_SA, /* System attr */
DMU_OT_SA_MASTER_NODE, /* ZAP */
DMU_OT_SA_ATTR_REGISTRATION, /* ZAP */
DMU_OT_SA_ATTR_LAYOUTS, /* ZAP */
DMU_OT_NUMTYPES
} dmu_object_type_t;
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
......@@ -47,6 +47,8 @@
#define DNODES_PER_BLOCK (1ULL << DNODES_PER_BLOCK_SHIFT)
#define DNODES_PER_LEVEL_SHIFT (DN_MAX_INDBLKSHIFT - SPA_BLKPTRSHIFT)
#define DNODE_FLAG_SPILL_BLKPTR (1<<2)
#define DN_BONUS(dnp) ((void*)((dnp)->dn_bonus + \
(((dnp)->dn_nblkptr - 1) * sizeof (blkptr_t))))
......@@ -70,7 +72,8 @@ typedef struct dnode_phys {
uint64_t dn_pad3[4];
blkptr_t dn_blkptr[1];
uint8_t dn_bonus[DN_MAX_BONUSLEN];
uint8_t dn_bonus[DN_MAX_BONUSLEN - sizeof (blkptr_t)];
blkptr_t dn_spill;
} dnode_phys_t;
#endif /* _SYS_DNODE_H */
......@@ -24,6 +24,8 @@
#ifndef _SYS_DSL_DATASET_H
#define _SYS_DSL_DATASET_H
#pragma ident "%Z%%M% %I% %E% SMI"
typedef struct dsl_dataset_phys {
uint64_t ds_dir_obj;
uint64_t ds_prev_snap_obj;
......
......@@ -24,6 +24,8 @@
#ifndef _SYS_DSL_DIR_H
#define _SYS_DSL_DIR_H
#pragma ident "%Z%%M% %I% %E% SMI"
typedef struct dsl_dir_phys {
uint64_t dd_creation_time; /* not actually used */
uint64_t dd_head_dataset_obj;
......
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _SYS_SA_IMPL_H
#define _SYS_SA_IMPL_H
typedef struct sa_hdr_phys {
uint32_t sa_magic;
uint16_t sa_layout_info;
uint16_t sa_lengths[1];
} sa_hdr_phys_t;
#define SA_HDR_SIZE(hdr) BF32_GET_SB(hdr->sa_layout_info, 10, 16, 3, 0)
#define SA_SIZE_OFFSET 0x8
#endif /* _SYS_SA_IMPL_H */
......@@ -17,7 +17,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
......@@ -62,6 +62,11 @@
#define SPA_BLOCKSIZES (SPA_MAXBLOCKSHIFT - SPA_MINBLOCKSHIFT + 1)
/*
* Size of block to hold the configuration data (a packed nvlist)
*/
#define SPA_CONFIG_BLOCKSIZE (1 << 14)
/*
* The DVA size encodings for LSIZE and PSIZE support blocks up to 32MB.
* The ASIZE encoding should be at least 64 times larger (6 more bits)
......@@ -106,15 +111,15 @@ typedef struct zio_cksum {
* +-------+-------+-------+-------+-------+-------+-------+-------+
* 5 |G| offset3 |
* +-------+-------+-------+-------+-------+-------+-------+-------+
* 6 |E| lvl | type | cksum | comp | PSIZE | LSIZE |
* 6 |BDX|lvl| type | cksum | comp | PSIZE | LSIZE |
* +-------+-------+-------+-------+-------+-------+-------+-------+
* 7 | padding |
* +-------+-------+-------+-------+-------+-------+-------+-------+
* 8 | padding |
* +-------+-------+-------+-------+-------+-------+-------+-------+
* 9 | padding |
* 9 | physical birth txg |
* +-------+-------+-------+-------+-------+-------+-------+-------+
* a | birth txg |
* a | logical birth txg |
* +-------+-------+-------+-------+-------+-------+-------+-------+
* b | fill count |
* +-------+-------+-------+-------+-------+-------+-------+-------+
......@@ -138,25 +143,29 @@ typedef struct zio_cksum {
* cksum checksum function
* comp compression function
* G gang block indicator
* E endianness
* type DMU object type
* B byteorder (endianness)
* D dedup
* X unused
* lvl level of indirection
* birth txg transaction group in which the block was born
* type DMU object type
* phys birth txg of block allocation; zero if same as logical birth txg
* log. birth transaction group in which the block was logically born
* fill count number of non-zero blocks under this bp
* checksum[4] 256-bit checksum of the data this bp describes
*/
typedef struct blkptr {
dva_t blk_dva[3]; /* 128-bit Data Virtual Address */
uint64_t blk_prop; /* size, compression, type, etc */
uint64_t blk_pad[3]; /* Extra space for the future */
uint64_t blk_birth; /* transaction group at birth */
uint64_t blk_fill; /* fill count */
zio_cksum_t blk_cksum; /* 256-bit checksum */
} blkptr_t;
#define SPA_BLKPTRSHIFT 7 /* blkptr_t is 128 bytes */
#define SPA_DVAS_PER_BP 3 /* Number of DVAs in a bp */
typedef struct blkptr {
dva_t blk_dva[SPA_DVAS_PER_BP]; /* Data Virtual Addresses */
uint64_t blk_prop; /* size, compression, type, etc */
uint64_t blk_pad[2]; /* Extra space for the future */
uint64_t blk_phys_birth; /* txg when block was allocated */
uint64_t blk_birth; /* transaction group at birth */
uint64_t blk_fill; /* fill count */
zio_cksum_t blk_cksum; /* 256-bit checksum */
} blkptr_t;
/*
* Macros to get and set fields in a bp or DVA.
*/
......@@ -180,8 +189,7 @@ typedef struct blkptr {
#define DVA_SET_GANG(dva, x) BF64_SET((dva)->dva_word[1], 63, 1, x)
#define BP_GET_LSIZE(bp) \
(BP_IS_HOLE(bp) ? 0 : \
BF64_GET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1))
BF64_GET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1)
#define BP_SET_LSIZE(bp, x) \
BF64_SET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1, x)
......@@ -190,20 +198,35 @@ typedef struct blkptr {
#define BP_SET_PSIZE(bp, x) \
BF64_SET_SB((bp)->blk_prop, 16, 16, SPA_MINBLOCKSHIFT, 1, x)
#define BP_GET_COMPRESS(bp) BF64_GET((bp)->blk_prop, 32, 8)
#define BP_SET_COMPRESS(bp, x) BF64_SET((bp)->blk_prop, 32, 8, x)
#define BP_GET_COMPRESS(bp) BF64_GET((bp)->blk_prop, 32, 8)
#define BP_SET_COMPRESS(bp, x) BF64_SET((bp)->blk_prop, 32, 8, x)
#define BP_GET_CHECKSUM(bp) BF64_GET((bp)->blk_prop, 40, 8)
#define BP_SET_CHECKSUM(bp, x) BF64_SET((bp)->blk_prop, 40, 8, x)
#define BP_GET_TYPE(bp) BF64_GET((bp)->blk_prop, 48, 8)
#define BP_SET_TYPE(bp, x) BF64_SET((bp)->blk_prop, 48, 8, x)
#define BP_GET_LEVEL(bp) BF64_GET((bp)->blk_prop, 56, 5)
#define BP_SET_LEVEL(bp, x) BF64_SET((bp)->blk_prop, 56, 5, x)
#define BP_GET_PROP_BIT_61(bp) BF64_GET((bp)->blk_prop, 61, 1)
#define BP_SET_PROP_BIT_61(bp, x) BF64_SET((bp)->blk_prop, 61, 1, x)
#define BP_GET_CHECKSUM(bp) BF64_GET((bp)->blk_prop, 40, 8)
#define BP_SET_CHECKSUM(bp, x) BF64_SET((bp)->blk_prop, 40, 8, x)
#define BP_GET_DEDUP(bp) BF64_GET((bp)->blk_prop, 62, 1)
#define BP_SET_DEDUP(bp, x) BF64_SET((bp)->blk_prop, 62, 1, x)
#define BP_GET_TYPE(bp) BF64_GET((bp)->blk_prop, 48, 8)