]> git.proxmox.com Git - mirror_zfs-debian.git/blobdiff - zfs/lib/libzpool/bplist.c
Rebase to OpenSolaris b103, in the process we are removing any code which did not...
[mirror_zfs-debian.git] / zfs / lib / libzpool / bplist.c
index 099d499c0d1a4d8710030a44ea7b46a7da8ec2e5..93b7741d77be22927045d2345d5b37693db55c32 100644 (file)
  * CDDL HEADER END
  */
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident  "@(#)bplist.c   1.5     07/10/29 SMI"
-
 #include <sys/bplist.h>
 #include <sys/zfs_context.h>
 
@@ -181,7 +179,7 @@ bplist_iterate(bplist_t *bpl, uint64_t *itorp, blkptr_t *bp)
 }
 
 int
-bplist_enqueue(bplist_t *bpl, blkptr_t *bp, dmu_tx_t *tx)
+bplist_enqueue(bplist_t *bpl, const blkptr_t *bp, dmu_tx_t *tx)
 {
        uint64_t blk, off;
        blkptr_t *bparray;
@@ -229,7 +227,7 @@ bplist_enqueue(bplist_t *bpl, blkptr_t *bp, dmu_tx_t *tx)
  * Deferred entry; will be written later by bplist_sync().
  */
 void
-bplist_enqueue_deferred(bplist_t *bpl, blkptr_t *bp)
+bplist_enqueue_deferred(bplist_t *bpl, const blkptr_t *bp)
 {
        bplist_q_t *bpq = kmem_alloc(sizeof (*bpq), KM_SLEEP);
 
@@ -311,3 +309,41 @@ bplist_space(bplist_t *bpl, uint64_t *usedp, uint64_t *compp, uint64_t *uncompp)
 
        return (err);
 }
+
+/*
+ * Return (in *dasizep) the amount of space on the deadlist which is:
+ * mintxg < blk_birth <= maxtxg
+ */
+int
+bplist_space_birthrange(bplist_t *bpl, uint64_t mintxg, uint64_t maxtxg,
+    uint64_t *dasizep)
+{
+       uint64_t size = 0;
+       uint64_t itor = 0;
+       blkptr_t bp;
+       int err;
+
+       /*
+        * As an optimization, if they want the whole txg range, just
+        * get bpl_bytes rather than iterating over the bps.
+        */
+       if (mintxg < TXG_INITIAL && maxtxg == UINT64_MAX) {
+               mutex_enter(&bpl->bpl_lock);
+               err = bplist_hold(bpl);
+               if (err == 0)
+                       *dasizep = bpl->bpl_phys->bpl_bytes;
+               mutex_exit(&bpl->bpl_lock);
+               return (err);
+       }
+
+       while ((err = bplist_iterate(bpl, &itor, &bp)) == 0) {
+               if (bp.blk_birth > mintxg && bp.blk_birth <= maxtxg) {
+                       size +=
+                           bp_get_dasize(dmu_objset_spa(bpl->bpl_mos), &bp);
+               }
+       }
+       if (err == ENOENT)
+               err = 0;
+       *dasizep = size;
+       return (err);
+}