Print this page
*** NO COMMENTS ***


 270         BP_SET_TYPE(bp, DMU_OT_DEDUP);
 271         BP_SET_LEVEL(bp, 0);
 272         BP_SET_DEDUP(bp, 0);
 273         BP_SET_BYTEORDER(bp, ZFS_HOST_BYTEORDER);
 274 }
 275 
 276 void
 277 ddt_key_fill(ddt_key_t *ddk, const blkptr_t *bp)
 278 {
 279         ddk->ddk_cksum = bp->blk_cksum;
 280         ddk->ddk_prop = 0;
 281 
 282         DDK_SET_LSIZE(ddk, BP_GET_LSIZE(bp));
 283         DDK_SET_PSIZE(ddk, BP_GET_PSIZE(bp));
 284         DDK_SET_COMPRESS(ddk, BP_GET_COMPRESS(bp));
 285 }
 286 
 287 void
 288 ddt_phys_fill(ddt_phys_t *ddp, const blkptr_t *bp)
 289 {

 290         ASSERT(ddp->ddp_phys_birth == 0);
 291 
 292         for (int d = 0; d < SPA_DVAS_PER_BP; d++)
 293                 ddp->ddp_dva[d] = bp->blk_dva[d];
 294         ddp->ddp_phys_birth = BP_PHYSICAL_BIRTH(bp);
 295 }
 296 
 297 void
 298 ddt_phys_clear(ddt_phys_t *ddp)
 299 {


 300         bzero(ddp, sizeof (*ddp));

 301 }
 302 
 303 void
 304 ddt_phys_addref(ddt_phys_t *ddp)
 305 {


 306         ddp->ddp_refcnt++;

 307 }
 308 
 309 void
 310 ddt_phys_decref(ddt_phys_t *ddp)
 311 {


 312         ASSERT((int64_t)ddp->ddp_refcnt > 0);
 313         ddp->ddp_refcnt--;

 314 }
 315 
 316 void
 317 ddt_phys_free(ddt_t *ddt, ddt_key_t *ddk, ddt_phys_t *ddp, uint64_t txg)
 318 {
 319         blkptr_t blk;
 320 
 321         ddt_bp_create(ddt->ddt_checksum, ddk, ddp, &blk);
 322         ddt_phys_clear(ddp);
 323         zio_free(ddt->ddt_spa, txg, &blk);
 324 }
 325 
 326 ddt_phys_t *
 327 ddt_phys_select(const ddt_entry_t *dde, const blkptr_t *bp)
 328 {
 329         ddt_phys_t *ddp = (ddt_phys_t *)dde->dde_phys;
 330 
 331         for (int p = 0; p < DDT_PHYS_TYPES; p++, ddp++) {
 332                 if (DVA_EQUAL(BP_IDENTITY(bp), &ddp->ddp_dva[0]) &&
 333                     BP_PHYSICAL_BIRTH(bp) == ddp->ddp_phys_birth)
 334                         return (ddp);
 335         }







 336         return (NULL);
 337 }
 338 
 339 uint64_t
 340 ddt_phys_total_refcnt(const ddt_entry_t *dde)
 341 {
 342         uint64_t refcnt = 0;
 343 
 344         for (int p = DDT_PHYS_SINGLE; p <= DDT_PHYS_TRIPLE; p++)
 345                 refcnt += dde->dde_phys[p].ddp_refcnt;
 346 
 347         return (refcnt);
 348 }
 349 
 350 static void
 351 ddt_stat_generate(ddt_t *ddt, ddt_entry_t *dde, ddt_stat_t *dds)
 352 {
 353         spa_t *spa = ddt->ddt_spa;
 354         ddt_phys_t *ddp = dde->dde_phys;
 355         ddt_key_t *ddk = &dde->dde_key;




 270         BP_SET_TYPE(bp, DMU_OT_DEDUP);
 271         BP_SET_LEVEL(bp, 0);
 272         BP_SET_DEDUP(bp, 0);
 273         BP_SET_BYTEORDER(bp, ZFS_HOST_BYTEORDER);
 274 }
 275 
 276 void
 277 ddt_key_fill(ddt_key_t *ddk, const blkptr_t *bp)
 278 {
 279         ddk->ddk_cksum = bp->blk_cksum;
 280         ddk->ddk_prop = 0;
 281 
 282         DDK_SET_LSIZE(ddk, BP_GET_LSIZE(bp));
 283         DDK_SET_PSIZE(ddk, BP_GET_PSIZE(bp));
 284         DDK_SET_COMPRESS(ddk, BP_GET_COMPRESS(bp));
 285 }
 286 
 287 void
 288 ddt_phys_fill(ddt_phys_t *ddp, const blkptr_t *bp)
 289 {
 290         ASSERT(ddp != NULL);
 291         ASSERT(ddp->ddp_phys_birth == 0);
 292 
 293         for (int d = 0; d < SPA_DVAS_PER_BP; d++)
 294                 ddp->ddp_dva[d] = bp->blk_dva[d];
 295         ddp->ddp_phys_birth = BP_PHYSICAL_BIRTH(bp);
 296 }
 297 
 298 void
 299 ddt_phys_clear(ddt_phys_t *ddp)
 300 {
 301         ASSERT(ddp != NULL);
 302         if (ddp) {
 303                 bzero(ddp, sizeof (*ddp));
 304         }
 305 }
 306 
 307 void
 308 ddt_phys_addref(ddt_phys_t *ddp)
 309 {
 310         ASSERT(ddp != NULL);
 311         if (ddp) {
 312                 ddp->ddp_refcnt++;
 313         }
 314 }
 315 
 316 void
 317 ddt_phys_decref(ddt_phys_t *ddp)
 318 {
 319 //      ASSERT(ddp != NULL);
 320         if (ddp) {
 321                 ASSERT((int64_t)ddp->ddp_refcnt > 0);
 322                 ddp->ddp_refcnt--;
 323         }
 324 }
 325 
 326 void
 327 ddt_phys_free(ddt_t *ddt, ddt_key_t *ddk, ddt_phys_t *ddp, uint64_t txg)
 328 {
 329         blkptr_t blk;
 330 
 331         ddt_bp_create(ddt->ddt_checksum, ddk, ddp, &blk);
 332         ddt_phys_clear(ddp);
 333         zio_free(ddt->ddt_spa, txg, &blk);
 334 }
 335 
 336 ddt_phys_t *
 337 ddt_phys_select(const ddt_entry_t *dde, const blkptr_t *bp)
 338 {
 339         ddt_phys_t *ddp = (ddt_phys_t *)dde->dde_phys;
 340 
 341         for (int p = 0; p < DDT_PHYS_TYPES; p++, ddp++) {
 342                 if (DVA_EQUAL(BP_IDENTITY(bp), &ddp->ddp_dva[0]) &&
 343                     BP_PHYSICAL_BIRTH(bp) == ddp->ddp_phys_birth)
 344                         return (ddp);
 345         }
 346         (void) printf("ddt_phys_select() found nothing for "
 347             "DVA[BP]=<%llu:%llx:%llx> and phys_birth[BP]=%llu\n",
 348             (u_longlong_t)DVA_GET_VDEV(BP_IDENTITY(bp)),
 349             (u_longlong_t)DVA_GET_OFFSET(BP_IDENTITY(bp)),
 350             (u_longlong_t)DVA_GET_ASIZE(BP_IDENTITY(bp)),
 351             (u_longlong_t)BP_PHYSICAL_BIRTH(bp)
 352         );
 353         return (NULL);
 354 }
 355 
 356 uint64_t
 357 ddt_phys_total_refcnt(const ddt_entry_t *dde)
 358 {
 359         uint64_t refcnt = 0;
 360 
 361         for (int p = DDT_PHYS_SINGLE; p <= DDT_PHYS_TRIPLE; p++)
 362                 refcnt += dde->dde_phys[p].ddp_refcnt;
 363 
 364         return (refcnt);
 365 }
 366 
 367 static void
 368 ddt_stat_generate(ddt_t *ddt, ddt_entry_t *dde, ddt_stat_t *dds)
 369 {
 370         spa_t *spa = ddt->ddt_spa;
 371         ddt_phys_t *ddp = dde->dde_phys;
 372         ddt_key_t *ddk = &dde->dde_key;