Print this page
3752 want more verifiable dbuf user eviction
Submitted by:   Justin Gibbs <justing@spectralogic.com>
Submitted by:   Will Andrews <willa@spectralogic.com>


  28 #define _SYS_DSL_DATASET_H
  29 
  30 #include <sys/dmu.h>
  31 #include <sys/spa.h>
  32 #include <sys/txg.h>
  33 #include <sys/zio.h>
  34 #include <sys/bplist.h>
  35 #include <sys/dsl_synctask.h>
  36 #include <sys/zfs_context.h>
  37 #include <sys/dsl_deadlist.h>
  38 #include <sys/refcount.h>
  39 
  40 #ifdef  __cplusplus
  41 extern "C" {
  42 #endif
  43 
  44 struct dsl_dataset;
  45 struct dsl_dir;
  46 struct dsl_pool;
  47 



  48 #define DS_FLAG_INCONSISTENT    (1ULL<<0)
  49 #define DS_IS_INCONSISTENT(ds)  \
  50         ((ds)->ds_phys->ds_flags & DS_FLAG_INCONSISTENT)
  51 /*
  52  * Note: nopromote can not yet be set, but we want support for it in this
  53  * on-disk version, so that we don't need to upgrade for it later.
  54  */
  55 #define DS_FLAG_NOPROMOTE       (1ULL<<1)
  56 
  57 /*
  58  * DS_FLAG_UNIQUE_ACCURATE is set if ds_unique_bytes has been correctly
  59  * calculated for head datasets (starting with SPA_VERSION_UNIQUE_ACCURATE,
  60  * refquota/refreservations).
  61  */
  62 #define DS_FLAG_UNIQUE_ACCURATE (1ULL<<2)
  63 
  64 /*
  65  * DS_FLAG_DEFER_DESTROY is set after 'zfs destroy -d' has been called
  66  * on a dataset. This allows the dataset to be destroyed using 'zfs release'.
  67  */


  94          */
  95         uint64_t ds_referenced_bytes;
  96         uint64_t ds_compressed_bytes;
  97         uint64_t ds_uncompressed_bytes;
  98         uint64_t ds_unique_bytes;       /* only relevant to snapshots */
  99         /*
 100          * The ds_fsid_guid is a 56-bit ID that can change to avoid
 101          * collisions.  The ds_guid is a 64-bit ID that will never
 102          * change, so there is a small probability that it will collide.
 103          */
 104         uint64_t ds_fsid_guid;
 105         uint64_t ds_guid;
 106         uint64_t ds_flags;              /* DS_FLAG_* */
 107         blkptr_t ds_bp;
 108         uint64_t ds_next_clones_obj;    /* DMU_OT_DSL_CLONES */
 109         uint64_t ds_props_obj;          /* DMU_OT_DSL_PROPS for snaps */
 110         uint64_t ds_userrefs_obj;       /* DMU_OT_USERREFS */
 111         uint64_t ds_pad[5]; /* pad out to 320 bytes for good measure */
 112 } dsl_dataset_phys_t;
 113 





 114 typedef struct dsl_dataset {


 115         /* Immutable: */
 116         struct dsl_dir *ds_dir;
 117         dsl_dataset_phys_t *ds_phys;
 118         dmu_buf_t *ds_dbuf;


 119         uint64_t ds_object;
 120         uint64_t ds_fsid_guid;
 121 
 122         /* only used in syncing context, only valid for non-snapshots: */
 123         struct dsl_dataset *ds_prev;
 124 
 125         /* has internal locking: */
 126         dsl_deadlist_t ds_deadlist;
 127         bplist_t ds_pending_deadlist;
 128 
 129         /* protected by lock on pool's dp_dirty_datasets list */
 130         txg_node_t ds_dirty_link;
 131         list_node_t ds_synced_link;
 132 
 133         /*
 134          * ds_phys->ds_<accounting> is also protected by ds_lock.
 135          * Protected by ds_lock:
 136          */
 137         kmutex_t ds_lock;
 138         objset_t *ds_objset;


 146          * dsl_pool_hold() for details.
 147          */
 148         refcount_t ds_longholds;
 149 
 150         /* no locking; only for making guesses */
 151         uint64_t ds_trysnap_txg;
 152 
 153         /* for objset_open() */
 154         kmutex_t ds_opening_lock;
 155 
 156         uint64_t ds_reserved;   /* cached refreservation */
 157         uint64_t ds_quota;      /* cached refquota */
 158 
 159         kmutex_t ds_sendstream_lock;
 160         list_t ds_sendstreams;
 161 
 162         /* Protected by ds_lock; keep at end of struct for better locality */
 163         char ds_snapname[MAXNAMELEN];
 164 } dsl_dataset_t;
 165 













 166 /*
 167  * The max length of a temporary tag prefix is the number of hex digits
 168  * required to express UINT64_MAX plus one for the hyphen.
 169  */
 170 #define MAX_TAG_PREFIX_LEN      17
 171 
 172 #define dsl_dataset_is_snapshot(ds) \
 173         ((ds)->ds_phys->ds_num_children != 0)
 174 
 175 #define DS_UNIQUE_IS_ACCURATE(ds)       \
 176         (((ds)->ds_phys->ds_flags & DS_FLAG_UNIQUE_ACCURATE) != 0)
 177 
 178 int dsl_dataset_hold(struct dsl_pool *dp, const char *name, void *tag,
 179     dsl_dataset_t **dsp);
 180 int dsl_dataset_hold_obj(struct dsl_pool *dp, uint64_t dsobj, void *tag,
 181     dsl_dataset_t **);
 182 void dsl_dataset_rele(dsl_dataset_t *ds, void *tag);
 183 int dsl_dataset_own(struct dsl_pool *dp, const char *name,
 184     void *tag, dsl_dataset_t **dsp);
 185 int dsl_dataset_own_obj(struct dsl_pool *dp, uint64_t dsobj,




  28 #define _SYS_DSL_DATASET_H
  29 
  30 #include <sys/dmu.h>
  31 #include <sys/spa.h>
  32 #include <sys/txg.h>
  33 #include <sys/zio.h>
  34 #include <sys/bplist.h>
  35 #include <sys/dsl_synctask.h>
  36 #include <sys/zfs_context.h>
  37 #include <sys/dsl_deadlist.h>
  38 #include <sys/refcount.h>
  39 
  40 #ifdef  __cplusplus
  41 extern "C" {
  42 #endif
  43 
  44 struct dsl_dataset;
  45 struct dsl_dir;
  46 struct dsl_pool;
  47 
  48 #define DS_HAS_PHYS(ds) \
  49         ((ds)->ds_dbuf != NULL && (ds)->ds_dbuf->db_data != NULL)
  50 
  51 #define DS_FLAG_INCONSISTENT    (1ULL<<0)
  52 #define DS_IS_INCONSISTENT(ds)  \
  53         ((ds)->ds_phys->ds_flags & DS_FLAG_INCONSISTENT)
  54 /*
  55  * Note: nopromote can not yet be set, but we want support for it in this
  56  * on-disk version, so that we don't need to upgrade for it later.
  57  */
  58 #define DS_FLAG_NOPROMOTE       (1ULL<<1)
  59 
  60 /*
  61  * DS_FLAG_UNIQUE_ACCURATE is set if ds_unique_bytes has been correctly
  62  * calculated for head datasets (starting with SPA_VERSION_UNIQUE_ACCURATE,
  63  * refquota/refreservations).
  64  */
  65 #define DS_FLAG_UNIQUE_ACCURATE (1ULL<<2)
  66 
  67 /*
  68  * DS_FLAG_DEFER_DESTROY is set after 'zfs destroy -d' has been called
  69  * on a dataset. This allows the dataset to be destroyed using 'zfs release'.
  70  */


  97          */
  98         uint64_t ds_referenced_bytes;
  99         uint64_t ds_compressed_bytes;
 100         uint64_t ds_uncompressed_bytes;
 101         uint64_t ds_unique_bytes;       /* only relevant to snapshots */
 102         /*
 103          * The ds_fsid_guid is a 56-bit ID that can change to avoid
 104          * collisions.  The ds_guid is a 64-bit ID that will never
 105          * change, so there is a small probability that it will collide.
 106          */
 107         uint64_t ds_fsid_guid;
 108         uint64_t ds_guid;
 109         uint64_t ds_flags;              /* DS_FLAG_* */
 110         blkptr_t ds_bp;
 111         uint64_t ds_next_clones_obj;    /* DMU_OT_DSL_CLONES */
 112         uint64_t ds_props_obj;          /* DMU_OT_DSL_PROPS for snaps */
 113         uint64_t ds_userrefs_obj;       /* DMU_OT_USERREFS */
 114         uint64_t ds_pad[5]; /* pad out to 320 bytes for good measure */
 115 } dsl_dataset_phys_t;
 116 
 117 typedef struct dsl_dataset_dbuf {
 118         uint8_t dsdb_pad[offsetof(dmu_buf_t, db_data)];
 119         dsl_dataset_phys_t *dsdb_data;
 120 } dsl_dataset_dbuf_t;
 121 
 122 typedef struct dsl_dataset {
 123         dmu_buf_user_t db_evict;
 124 
 125         /* Immutable: */
 126         struct dsl_dir *ds_dir;
 127         union {
 128                 dmu_buf_t *ds_dmu_db;
 129                 dsl_dataset_dbuf_t *ds_db;
 130         } ds_db_u;
 131         uint64_t ds_object;
 132         uint64_t ds_fsid_guid;
 133 
 134         /* only used in syncing context, only valid for non-snapshots: */
 135         struct dsl_dataset *ds_prev;
 136 
 137         /* has internal locking: */
 138         dsl_deadlist_t ds_deadlist;
 139         bplist_t ds_pending_deadlist;
 140 
 141         /* protected by lock on pool's dp_dirty_datasets list */
 142         txg_node_t ds_dirty_link;
 143         list_node_t ds_synced_link;
 144 
 145         /*
 146          * ds_phys->ds_<accounting> is also protected by ds_lock.
 147          * Protected by ds_lock:
 148          */
 149         kmutex_t ds_lock;
 150         objset_t *ds_objset;


 158          * dsl_pool_hold() for details.
 159          */
 160         refcount_t ds_longholds;
 161 
 162         /* no locking; only for making guesses */
 163         uint64_t ds_trysnap_txg;
 164 
 165         /* for objset_open() */
 166         kmutex_t ds_opening_lock;
 167 
 168         uint64_t ds_reserved;   /* cached refreservation */
 169         uint64_t ds_quota;      /* cached refquota */
 170 
 171         kmutex_t ds_sendstream_lock;
 172         list_t ds_sendstreams;
 173 
 174         /* Protected by ds_lock; keep at end of struct for better locality */
 175         char ds_snapname[MAXNAMELEN];
 176 } dsl_dataset_t;
 177 
 178 /* See sys/dmu.h:dmu_buf_user_t for why we have these. */
 179 #define ds_dbuf ds_db_u.ds_dmu_db
 180 #define ds_phys ds_db_u.ds_db->dsdb_data
 181 
 182 struct dsl_ds_destroyarg {
 183         dsl_dataset_t *ds;              /* ds to destroy */
 184         dsl_dataset_t *rm_origin;       /* also remove our origin? */
 185         boolean_t is_origin_rm;         /* set if removing origin snap */
 186         boolean_t defer;                /* destroy -d requested? */
 187         boolean_t releasing;            /* destroying due to release? */
 188         boolean_t need_prep;            /* do we need to retry due to EBUSY? */
 189 };
 190 
 191 /*
 192  * The max length of a temporary tag prefix is the number of hex digits
 193  * required to express UINT64_MAX plus one for the hyphen.
 194  */
 195 #define MAX_TAG_PREFIX_LEN      17
 196 
 197 #define dsl_dataset_is_snapshot(ds) \
 198         ((ds)->ds_phys->ds_num_children != 0)
 199 
 200 #define DS_UNIQUE_IS_ACCURATE(ds)       \
 201         (((ds)->ds_phys->ds_flags & DS_FLAG_UNIQUE_ACCURATE) != 0)
 202 
 203 int dsl_dataset_hold(struct dsl_pool *dp, const char *name, void *tag,
 204     dsl_dataset_t **dsp);
 205 int dsl_dataset_hold_obj(struct dsl_pool *dp, uint64_t dsobj, void *tag,
 206     dsl_dataset_t **);
 207 void dsl_dataset_rele(dsl_dataset_t *ds, void *tag);
 208 int dsl_dataset_own(struct dsl_pool *dp, const char *name,
 209     void *tag, dsl_dataset_t **dsp);
 210 int dsl_dataset_own_obj(struct dsl_pool *dp, uint64_t dsobj,