]> granicus.if.org Git - zfs/blobdiff - include/sys/vdev_impl.h
Log Spacemap Project
[zfs] / include / sys / vdev_impl.h
index 6b27e75ae54d6e4b7ce0f646626f9cc1c28b3ecf..c179191e39db33e37d24ff9f9b1df76cbf8daa62 100644 (file)
  */
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
+ * Copyright (c) 2011, 2019 by Delphix. All rights reserved.
+ * Copyright (c) 2017, Intel Corporation.
  */
 
 #ifndef _SYS_VDEV_IMPL_H
 #define        _SYS_VDEV_IMPL_H
 
 #include <sys/avl.h>
+#include <sys/bpobj.h>
 #include <sys/dmu.h>
 #include <sys/metaslab.h>
 #include <sys/nvpair.h>
 #include <sys/vdev.h>
 #include <sys/dkio.h>
 #include <sys/uberblock_impl.h>
+#include <sys/vdev_indirect_mapping.h>
+#include <sys/vdev_indirect_births.h>
+#include <sys/vdev_removal.h>
+#include <sys/zfs_ratelimit.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -52,6 +58,11 @@ extern "C" {
 typedef struct vdev_queue vdev_queue_t;
 typedef struct vdev_cache vdev_cache_t;
 typedef struct vdev_cache_entry vdev_cache_entry_t;
+struct abd;
+
+extern int zfs_vdev_queue_depth_pct;
+extern int zfs_vdev_def_queue_depth;
+extern uint32_t zfs_vdev_async_write_max_active;
 
 /*
  * Virtual device operations
@@ -63,9 +74,21 @@ typedef uint64_t vdev_asize_func_t(vdev_t *vd, uint64_t psize);
 typedef void   vdev_io_start_func_t(zio_t *zio);
 typedef void   vdev_io_done_func_t(zio_t *zio);
 typedef void   vdev_state_change_func_t(vdev_t *vd, int, int);
+typedef boolean_t vdev_need_resilver_func_t(vdev_t *vd, uint64_t, size_t);
 typedef void   vdev_hold_func_t(vdev_t *vd);
 typedef void   vdev_rele_func_t(vdev_t *vd);
 
+typedef void   vdev_remap_cb_t(uint64_t inner_offset, vdev_t *vd,
+    uint64_t offset, uint64_t size, void *arg);
+typedef void   vdev_remap_func_t(vdev_t *vd, uint64_t offset, uint64_t size,
+    vdev_remap_cb_t callback, void *arg);
+/*
+ * Given a target vdev, translates the logical range "in" to the physical
+ * range "res"
+ */
+typedef void vdev_xlation_func_t(vdev_t *cvd, const range_seg_t *in,
+    range_seg_t *res);
+
 typedef const struct vdev_ops {
        vdev_open_func_t                *vdev_op_open;
        vdev_close_func_t               *vdev_op_close;
@@ -73,8 +96,15 @@ typedef const struct vdev_ops {
        vdev_io_start_func_t            *vdev_op_io_start;
        vdev_io_done_func_t             *vdev_op_io_done;
        vdev_state_change_func_t        *vdev_op_state_change;
+       vdev_need_resilver_func_t       *vdev_op_need_resilver;
        vdev_hold_func_t                *vdev_op_hold;
        vdev_rele_func_t                *vdev_op_rele;
+       vdev_remap_func_t               *vdev_op_remap;
+       /*
+        * For translating ranges from non-leaf vdevs (e.g. raidz) to leaves.
+        * Used when initializing vdevs. Isn't used by leaf ops.
+        */
+       vdev_xlation_func_t             *vdev_op_xlate;
        char                            vdev_op_type[16];
        boolean_t                       vdev_op_leaf;
 } vdev_ops_t;
@@ -83,7 +113,7 @@ typedef const struct vdev_ops {
  * Virtual device properties
  */
 struct vdev_cache_entry {
-       char            *ve_data;
+       struct abd      *ve_abd;
        uint64_t        ve_offset;
        clock_t         ve_lastused;
        avl_node_t      ve_offset_node;
@@ -115,6 +145,7 @@ struct vdev_queue {
        avl_tree_t      vq_active_tree;
        avl_tree_t      vq_read_offset_tree;
        avl_tree_t      vq_write_offset_tree;
+       avl_tree_t      vq_trim_offset_tree;
        uint64_t        vq_last_offset;
        hrtime_t        vq_io_complete_ts; /* time last i/o completed */
        hrtime_t        vq_io_delta_ts;
@@ -122,6 +153,53 @@ struct vdev_queue {
        kmutex_t        vq_lock;
 };
 
+typedef enum vdev_alloc_bias {
+       VDEV_BIAS_NONE,
+       VDEV_BIAS_LOG,          /* dedicated to ZIL data (SLOG) */
+       VDEV_BIAS_SPECIAL,      /* dedicated to ddt, metadata, and small blks */
+       VDEV_BIAS_DEDUP         /* dedicated to dedup metadata */
+} vdev_alloc_bias_t;
+
+
+/*
+ * On-disk indirect vdev state.
+ *
+ * An indirect vdev is described exclusively in the MOS config of a pool.
+ * The config for an indirect vdev includes several fields, which are
+ * accessed in memory by a vdev_indirect_config_t.
+ */
+typedef struct vdev_indirect_config {
+       /*
+        * Object (in MOS) which contains the indirect mapping. This object
+        * contains an array of vdev_indirect_mapping_entry_phys_t ordered by
+        * vimep_src. The bonus buffer for this object is a
+        * vdev_indirect_mapping_phys_t. This object is allocated when a vdev
+        * removal is initiated.
+        *
+        * Note that this object can be empty if none of the data on the vdev
+        * has been copied yet.
+        */
+       uint64_t        vic_mapping_object;
+
+       /*
+        * Object (in MOS) which contains the birth times for the mapping
+        * entries. This object contains an array of
+        * vdev_indirect_birth_entry_phys_t sorted by vibe_offset. The bonus
+        * buffer for this object is a vdev_indirect_birth_phys_t. This object
+        * is allocated when a vdev removal is initiated.
+        *
+        * Note that this object can be empty if none of the vdev has yet been
+        * copied.
+        */
+       uint64_t        vic_births_object;
+
+       /*
+        * This is the vdev ID which was removed previous to this vdev, or
+        * UINT64_MAX if there are no previously removed vdevs.
+        */
+       uint64_t        vic_prev_indirect_vdev;
+} vdev_indirect_config_t;
+
 /*
  * Virtual device descriptor
  */
@@ -149,8 +227,10 @@ struct vdev {
        vdev_t          **vdev_child;   /* array of children            */
        uint64_t        vdev_children;  /* number of children           */
        vdev_stat_t     vdev_stat;      /* virtual device statistics    */
+       vdev_stat_ex_t  vdev_stat_ex;   /* extended statistics          */
        boolean_t       vdev_expanding; /* expand the vdev?             */
        boolean_t       vdev_reopening; /* reopen in progress?          */
+       boolean_t       vdev_nonrot;    /* true if solid state          */
        int             vdev_open_error; /* error on last open          */
        kthread_t       *vdev_open_thread; /* thread opening children   */
        uint64_t        vdev_crtxg;     /* txg when top-level was added */
@@ -174,7 +254,97 @@ struct vdev {
        uint64_t        vdev_deflate_ratio; /* deflation ratio (x512)   */
        uint64_t        vdev_islog;     /* is an intent log device      */
        uint64_t        vdev_removing;  /* device is being removed?     */
-       boolean_t       vdev_ishole;    /* is a hole in the namespace   */
+       boolean_t       vdev_ishole;    /* is a hole in the namespace   */
+       uint64_t        vdev_top_zap;
+       vdev_alloc_bias_t vdev_alloc_bias; /* metaslab allocation bias  */
+
+       /* pool checkpoint related */
+       space_map_t     *vdev_checkpoint_sm;    /* contains reserved blocks */
+
+       /* Initialize related */
+       boolean_t       vdev_initialize_exit_wanted;
+       vdev_initializing_state_t       vdev_initialize_state;
+       list_node_t     vdev_initialize_node;
+       kthread_t       *vdev_initialize_thread;
+       /* Protects vdev_initialize_thread and vdev_initialize_state. */
+       kmutex_t        vdev_initialize_lock;
+       kcondvar_t      vdev_initialize_cv;
+       uint64_t        vdev_initialize_offset[TXG_SIZE];
+       uint64_t        vdev_initialize_last_offset;
+       range_tree_t    *vdev_initialize_tree;  /* valid while initializing */
+       uint64_t        vdev_initialize_bytes_est;
+       uint64_t        vdev_initialize_bytes_done;
+       time_t          vdev_initialize_action_time;    /* start and end time */
+
+       /* TRIM related */
+       boolean_t       vdev_trim_exit_wanted;
+       boolean_t       vdev_autotrim_exit_wanted;
+       vdev_trim_state_t       vdev_trim_state;
+       list_node_t     vdev_trim_node;
+       kmutex_t        vdev_autotrim_lock;
+       kcondvar_t      vdev_autotrim_cv;
+       kthread_t       *vdev_autotrim_thread;
+       /* Protects vdev_trim_thread and vdev_trim_state. */
+       kmutex_t        vdev_trim_lock;
+       kcondvar_t      vdev_trim_cv;
+       kthread_t       *vdev_trim_thread;
+       uint64_t        vdev_trim_offset[TXG_SIZE];
+       uint64_t        vdev_trim_last_offset;
+       uint64_t        vdev_trim_bytes_est;
+       uint64_t        vdev_trim_bytes_done;
+       uint64_t        vdev_trim_rate;         /* requested rate (bytes/sec) */
+       uint64_t        vdev_trim_partial;      /* requested partial TRIM */
+       uint64_t        vdev_trim_secure;       /* requested secure TRIM */
+       time_t          vdev_trim_action_time;  /* start and end time */
+
+       /* for limiting outstanding I/Os (initialize and TRIM) */
+       kmutex_t        vdev_initialize_io_lock;
+       kcondvar_t      vdev_initialize_io_cv;
+       uint64_t        vdev_initialize_inflight;
+       kmutex_t        vdev_trim_io_lock;
+       kcondvar_t      vdev_trim_io_cv;
+       uint64_t        vdev_trim_inflight[2];
+
+       /*
+        * Values stored in the config for an indirect or removing vdev.
+        */
+       vdev_indirect_config_t  vdev_indirect_config;
+
+       /*
+        * The vdev_indirect_rwlock protects the vdev_indirect_mapping
+        * pointer from changing on indirect vdevs (when it is condensed).
+        * Note that removing (not yet indirect) vdevs have different
+        * access patterns (the mapping is not accessed from open context,
+        * e.g. from zio_read) and locking strategy (e.g. svr_lock).
+        */
+       krwlock_t vdev_indirect_rwlock;
+       vdev_indirect_mapping_t *vdev_indirect_mapping;
+       vdev_indirect_births_t *vdev_indirect_births;
+
+       /*
+        * In memory data structures used to manage the obsolete sm, for
+        * indirect or removing vdevs.
+        *
+        * The vdev_obsolete_segments is the in-core record of the segments
+        * that are no longer referenced anywhere in the pool (due to
+        * being freed or remapped and not referenced by any snapshots).
+        * During a sync, segments are added to vdev_obsolete_segments
+        * via vdev_indirect_mark_obsolete(); at the end of each sync
+        * pass, this is appended to vdev_obsolete_sm via
+        * vdev_indirect_sync_obsolete().  The vdev_obsolete_lock
+        * protects against concurrent modifications of vdev_obsolete_segments
+        * from multiple zio threads.
+        */
+       kmutex_t        vdev_obsolete_lock;
+       range_tree_t    *vdev_obsolete_segments;
+       space_map_t     *vdev_obsolete_sm;
+
+       /*
+        * Protects the vdev_scan_io_queue field itself as well as the
+        * structure's contents (when present).
+        */
+       kmutex_t                        vdev_scan_io_queue_lock;
+       struct dsl_scan_io_queue        *vdev_scan_io_queue;
 
        /*
         * Leaf vdev state.
@@ -194,10 +364,13 @@ struct vdev {
        char            *vdev_path;     /* vdev path (if any)           */
        char            *vdev_devid;    /* vdev devid (if any)          */
        char            *vdev_physpath; /* vdev device path (if any)    */
+       char            *vdev_enc_sysfs_path;   /* enclosure sysfs path */
        char            *vdev_fru;      /* physical FRU location        */
        uint64_t        vdev_not_present; /* not present during import  */
        uint64_t        vdev_unspare;   /* unspare when resilvering done */
        boolean_t       vdev_nowritecache; /* true if flushwritecache failed */
+       boolean_t       vdev_has_trim;  /* TRIM is supported            */
+       boolean_t       vdev_has_securetrim; /* secure TRIM is supported */
        boolean_t       vdev_checkremove; /* temporary online test      */
        boolean_t       vdev_forcefault; /* force online fault          */
        boolean_t       vdev_splitting; /* split or repair in progress  */
@@ -208,11 +381,18 @@ struct vdev {
        boolean_t       vdev_cant_write; /* vdev is failing all writes  */
        boolean_t       vdev_isspare;   /* was a hot spare              */
        boolean_t       vdev_isl2cache; /* was a l2cache device         */
+       boolean_t       vdev_copy_uberblocks;  /* post expand copy uberblocks */
+       boolean_t       vdev_resilver_deferred;  /* resilver deferred */
        vdev_queue_t    vdev_queue;     /* I/O deadline schedule queue  */
        vdev_cache_t    vdev_cache;     /* physical block cache         */
        spa_aux_vdev_t  *vdev_aux;      /* for l2cache and spares vdevs */
        zio_t           *vdev_probe_zio; /* root of current probe       */
        vdev_aux_t      vdev_label_aux; /* on-disk aux state            */
+       uint64_t        vdev_leaf_zap;
+       hrtime_t        vdev_mmp_pending; /* 0 if write finished        */
+       uint64_t        vdev_mmp_kstat_id;      /* to find kstat entry */
+       uint64_t        vdev_expansion_time;    /* vdev's last expansion time */
+       list_node_t     vdev_leaf_node;         /* leaf vdev list */
 
        /*
         * For DTrace to work in userland (libzpool) context, these fields must
@@ -224,6 +404,13 @@ struct vdev {
        kmutex_t        vdev_dtl_lock;  /* vdev_dtl_{map,resilver}      */
        kmutex_t        vdev_stat_lock; /* vdev_stat                    */
        kmutex_t        vdev_probe_lock; /* protects vdev_probe_zio     */
+
+       /*
+        * We rate limit ZIO delay and ZIO checksum events, since they
+        * can flood ZED with tons of events when a drive is acting up.
+        */
+       zfs_ratelimit_t vdev_delay_rl;
+       zfs_ratelimit_t vdev_checksum_rl;
 };
 
 #define        VDEV_RAIDZ_MAXPARITY    3
@@ -234,6 +421,12 @@ struct vdev {
 #define        VDEV_PHYS_SIZE          (112 << 10)
 #define        VDEV_UBERBLOCK_RING     (128 << 10)
 
+/*
+ * MMP blocks occupy the last MMP_BLOCKS_PER_LABEL slots in the uberblock
+ * ring when MMP is enabled.
+ */
+#define        MMP_BLOCKS_PER_LABEL    1
+
 /* The largest uberblock we support is 8k. */
 #define        MAX_UBERBLOCK_SHIFT (13)
 #define        VDEV_UBERBLOCK_SHIFT(vd)        \
@@ -308,9 +501,8 @@ extern void vdev_remove_parent(vdev_t *cvd);
 /*
  * vdev sync load and sync
  */
-extern void vdev_load_log_state(vdev_t *nvd, vdev_t *ovd);
 extern boolean_t vdev_log_state_valid(vdev_t *vd);
-extern void vdev_load(vdev_t *vd);
+extern int vdev_load(vdev_t *vd);
 extern int vdev_dtl_load(vdev_t *vd);
 extern void vdev_sync(vdev_t *vd, uint64_t txg);
 extern void vdev_sync_done(vdev_t *vd, uint64_t txg);
@@ -329,10 +521,13 @@ extern vdev_ops_t vdev_file_ops;
 extern vdev_ops_t vdev_missing_ops;
 extern vdev_ops_t vdev_hole_ops;
 extern vdev_ops_t vdev_spare_ops;
+extern vdev_ops_t vdev_indirect_ops;
 
 /*
  * Common size functions
  */
+extern void vdev_default_xlate(vdev_t *vd, const range_seg_t *in,
+    range_seg_t *out);
 extern uint64_t vdev_default_asize(vdev_t *vd, uint64_t psize);
 extern uint64_t vdev_get_min_asize(vdev_t *vd);
 extern void vdev_set_min_asize(vdev_t *vd);
@@ -340,9 +535,24 @@ extern void vdev_set_min_asize(vdev_t *vd);
 /*
  * Global variables
  */
+extern int zfs_vdev_standard_sm_blksz;
 /* zdb uses this tunable, so it must be declared here to make lint happy. */
 extern int zfs_vdev_cache_size;
 
+/*
+ * Functions from vdev_indirect.c
+ */
+extern void vdev_indirect_sync_obsolete(vdev_t *vd, dmu_tx_t *tx);
+extern boolean_t vdev_indirect_should_condense(vdev_t *vd);
+extern void spa_condense_indirect_start_sync(vdev_t *vd, dmu_tx_t *tx);
+extern int vdev_obsolete_sm_object(vdev_t *vd, uint64_t *sm_obj);
+extern int vdev_obsolete_counts_are_precise(vdev_t *vd, boolean_t *are_precise);
+
+/*
+ * Other miscellaneous functions
+ */
+int vdev_checkpoint_sm_object(vdev_t *vd, uint64_t *sm_obj);
+
 #ifdef __cplusplus
 }
 #endif