Print this page
4374 dn_free_ranges should use range_tree_t
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Max Grossman <max.grossman@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com
Reviewed by: Garrett D'Amore <garrett@damore.org>
Reviewed by: Dan McDonald <danmcd@omniti.com>
Approved by: Dan McDonald <danmcd@omniti.com>


   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2013 by Delphix. All rights reserved.
  24  */
  25 
  26 /*
  27  * This file contains the top half of the zfs directory structure
  28  * implementation. The bottom half is in zap_leaf.c.
  29  *
  30  * The zdir is an extendable hash data structure. There is a table of
  31  * pointers to buckets (zap_t->zd_data->zd_leafs). The buckets are
  32  * each a constant size and hold a variable number of directory entries.
  33  * The buckets (aka "leaf nodes") are implemented in zap_leaf.c.
  34  *
  35  * The pointer table holds a power of 2 number of pointers.
  36  * (1<<zap_t->zd_data->zd_phys->zd_prefix_len).  The bucket pointed to
  37  * by the pointer at index i in the table holds entries whose hash value
  38  * has a zd_prefix_len - bit prefix
  39  */
  40 
  41 #include <sys/spa.h>
  42 #include <sys/dmu.h>
  43 #include <sys/zfs_context.h>


  67                 /* it's a ptrtbl block */
  68                 byteswap_uint64_array(vbuf, size);
  69         }
  70 }
  71 
  72 void
  73 fzap_upgrade(zap_t *zap, dmu_tx_t *tx, zap_flags_t flags)
  74 {
  75         dmu_buf_t *db;
  76         zap_leaf_t *l;
  77         int i;
  78         zap_phys_t *zp;
  79 
  80         ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
  81         zap->zap_ismicro = FALSE;
  82 
  83         (void) dmu_buf_update_user(zap->zap_dbuf, zap, zap,
  84             &zap->zap_f.zap_phys, zap_evict);
  85 
  86         mutex_init(&zap->zap_f.zap_num_entries_mtx, 0, 0, 0);
  87         zap->zap_f.zap_block_shift = highbit(zap->zap_dbuf->db_size) - 1;
  88 
  89         zp = zap->zap_f.zap_phys;
  90         /*
  91          * explicitly zero it since it might be coming from an
  92          * initialized microzap
  93          */
  94         bzero(zap->zap_dbuf->db_data, zap->zap_dbuf->db_size);
  95         zp->zap_block_type = ZBT_HEADER;
  96         zp->zap_magic = ZAP_MAGIC;
  97 
  98         zp->zap_ptrtbl.zt_shift = ZAP_EMBEDDED_PTRTBL_SHIFT(zap);
  99 
 100         zp->zap_freeblk = 2;         /* block 1 will be the first leaf */
 101         zp->zap_num_leafs = 1;
 102         zp->zap_num_entries = 0;
 103         zp->zap_salt = zap->zap_salt;
 104         zp->zap_normflags = zap->zap_normflags;
 105         zp->zap_flags = flags;
 106 
 107         /* block 1 will be the first leaf */


 441 static void
 442 zap_leaf_pageout(dmu_buf_t *db, void *vl)
 443 {
 444         zap_leaf_t *l = vl;
 445 
 446         rw_destroy(&l->l_rwlock);
 447         kmem_free(l, sizeof (zap_leaf_t));
 448 }
 449 
 450 static zap_leaf_t *
 451 zap_open_leaf(uint64_t blkid, dmu_buf_t *db)
 452 {
 453         zap_leaf_t *l, *winner;
 454 
 455         ASSERT(blkid != 0);
 456 
 457         l = kmem_alloc(sizeof (zap_leaf_t), KM_SLEEP);
 458         rw_init(&l->l_rwlock, 0, 0, 0);
 459         rw_enter(&l->l_rwlock, RW_WRITER);
 460         l->l_blkid = blkid;
 461         l->l_bs = highbit(db->db_size)-1;
 462         l->l_dbuf = db;
 463         l->l_phys = NULL;
 464 
 465         winner = dmu_buf_set_user(db, l, &l->l_phys, zap_leaf_pageout);
 466 
 467         rw_exit(&l->l_rwlock);
 468         if (winner != NULL) {
 469                 /* someone else set it first */
 470                 zap_leaf_pageout(NULL, l);
 471                 l = winner;
 472         }
 473 
 474         /*
 475          * lhr_pad was previously used for the next leaf in the leaf
 476          * chain.  There should be no chained leafs (as we have removed
 477          * support for them).
 478          */
 479         ASSERT0(l->l_phys->l_hdr.lh_pad1);
 480 
 481         /*




   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
  24  */
  25 
  26 /*
  27  * This file contains the top half of the zfs directory structure
  28  * implementation. The bottom half is in zap_leaf.c.
  29  *
  30  * The zdir is an extendable hash data structure. There is a table of
  31  * pointers to buckets (zap_t->zd_data->zd_leafs). The buckets are
  32  * each a constant size and hold a variable number of directory entries.
  33  * The buckets (aka "leaf nodes") are implemented in zap_leaf.c.
  34  *
  35  * The pointer table holds a power of 2 number of pointers.
  36  * (1<<zap_t->zd_data->zd_phys->zd_prefix_len).  The bucket pointed to
  37  * by the pointer at index i in the table holds entries whose hash value
  38  * has a zd_prefix_len - bit prefix
  39  */
  40 
  41 #include <sys/spa.h>
  42 #include <sys/dmu.h>
  43 #include <sys/zfs_context.h>


  67                 /* it's a ptrtbl block */
  68                 byteswap_uint64_array(vbuf, size);
  69         }
  70 }
  71 
  72 void
  73 fzap_upgrade(zap_t *zap, dmu_tx_t *tx, zap_flags_t flags)
  74 {
  75         dmu_buf_t *db;
  76         zap_leaf_t *l;
  77         int i;
  78         zap_phys_t *zp;
  79 
  80         ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
  81         zap->zap_ismicro = FALSE;
  82 
  83         (void) dmu_buf_update_user(zap->zap_dbuf, zap, zap,
  84             &zap->zap_f.zap_phys, zap_evict);
  85 
  86         mutex_init(&zap->zap_f.zap_num_entries_mtx, 0, 0, 0);
  87         zap->zap_f.zap_block_shift = highbit64(zap->zap_dbuf->db_size) - 1;
  88 
  89         zp = zap->zap_f.zap_phys;
  90         /*
  91          * explicitly zero it since it might be coming from an
  92          * initialized microzap
  93          */
  94         bzero(zap->zap_dbuf->db_data, zap->zap_dbuf->db_size);
  95         zp->zap_block_type = ZBT_HEADER;
  96         zp->zap_magic = ZAP_MAGIC;
  97 
  98         zp->zap_ptrtbl.zt_shift = ZAP_EMBEDDED_PTRTBL_SHIFT(zap);
  99 
 100         zp->zap_freeblk = 2;         /* block 1 will be the first leaf */
 101         zp->zap_num_leafs = 1;
 102         zp->zap_num_entries = 0;
 103         zp->zap_salt = zap->zap_salt;
 104         zp->zap_normflags = zap->zap_normflags;
 105         zp->zap_flags = flags;
 106 
 107         /* block 1 will be the first leaf */


 441 static void
 442 zap_leaf_pageout(dmu_buf_t *db, void *vl)
 443 {
 444         zap_leaf_t *l = vl;
 445 
 446         rw_destroy(&l->l_rwlock);
 447         kmem_free(l, sizeof (zap_leaf_t));
 448 }
 449 
 450 static zap_leaf_t *
 451 zap_open_leaf(uint64_t blkid, dmu_buf_t *db)
 452 {
 453         zap_leaf_t *l, *winner;
 454 
 455         ASSERT(blkid != 0);
 456 
 457         l = kmem_alloc(sizeof (zap_leaf_t), KM_SLEEP);
 458         rw_init(&l->l_rwlock, 0, 0, 0);
 459         rw_enter(&l->l_rwlock, RW_WRITER);
 460         l->l_blkid = blkid;
 461         l->l_bs = highbit64(db->db_size) - 1;
 462         l->l_dbuf = db;
 463         l->l_phys = NULL;
 464 
 465         winner = dmu_buf_set_user(db, l, &l->l_phys, zap_leaf_pageout);
 466 
 467         rw_exit(&l->l_rwlock);
 468         if (winner != NULL) {
 469                 /* someone else set it first */
 470                 zap_leaf_pageout(NULL, l);
 471                 l = winner;
 472         }
 473 
 474         /*
 475          * lhr_pad was previously used for the next leaf in the leaf
 476          * chain.  There should be no chained leafs (as we have removed
 477          * support for them).
 478          */
 479         ASSERT0(l->l_phys->l_hdr.lh_pad1);
 480 
 481         /*