Print this page
cstyle fixes
dsl_dataset_set_fsid_guid should use ZFS_SPACE_CHECK_RESERVED
dsl_dataset_set_fsid_guid _check and _sync func declared static,
removed from dsl_dataset.h
rewrite unique_valid
6333 ZFS should let the user specify or modify the fsid_guid of a dataset


  82         unique_t *un = kmem_alloc(sizeof (unique_t), KM_SLEEP);
  83 
  84         un->un_value = value;
  85 
  86         mutex_enter(&unique_mtx);
  87         while (un->un_value == 0 || un->un_value & ~UNIQUE_MASK ||
  88             avl_find(&unique_avl, un, &idx)) {
  89                 mutex_exit(&unique_mtx);
  90                 (void) random_get_pseudo_bytes((void*)&un->un_value,
  91                     sizeof (un->un_value));
  92                 un->un_value &= UNIQUE_MASK;
  93                 mutex_enter(&unique_mtx);
  94         }
  95 
  96         avl_insert(&unique_avl, un, idx);
  97         mutex_exit(&unique_mtx);
  98 
  99         return (un->un_value);
 100 }
 101 















 102 void
 103 unique_remove(uint64_t value)
 104 {
 105         unique_t un_tofind;
 106         unique_t *un;
 107 
 108         un_tofind.un_value = value;
 109         mutex_enter(&unique_mtx);
 110         un = avl_find(&unique_avl, &un_tofind, NULL);
 111         if (un != NULL) {
 112                 avl_remove(&unique_avl, un);
 113                 kmem_free(un, sizeof (unique_t));
 114         }
 115         mutex_exit(&unique_mtx);
 116 }


  82         unique_t *un = kmem_alloc(sizeof (unique_t), KM_SLEEP);
  83 
  84         un->un_value = value;
  85 
  86         mutex_enter(&unique_mtx);
  87         while (un->un_value == 0 || un->un_value & ~UNIQUE_MASK ||
  88             avl_find(&unique_avl, un, &idx)) {
  89                 mutex_exit(&unique_mtx);
  90                 (void) random_get_pseudo_bytes((void*)&un->un_value,
  91                     sizeof (un->un_value));
  92                 un->un_value &= UNIQUE_MASK;
  93                 mutex_enter(&unique_mtx);
  94         }
  95 
  96         avl_insert(&unique_avl, un, idx);
  97         mutex_exit(&unique_mtx);
  98 
  99         return (un->un_value);
 100 }
 101 
 102 boolean_t
 103 unique_valid(uint64_t value)
 104 {
 105         unique_t un_tofind;
 106 
 107         un_tofind.un_value = value;
 108 
 109         mutex_enter(&unique_mtx);
 110         boolean_t rv = ((value & ~UNIQUE_MASK) == 0 &&
 111             avl_find(&unique_avl, &un_tofind, NULL) == NULL);
 112         mutex_exit(&unique_mtx);
 113 
 114         return (rv);
 115 }
 116 
 117 void
 118 unique_remove(uint64_t value)
 119 {
 120         unique_t un_tofind;
 121         unique_t *un;
 122 
 123         un_tofind.un_value = value;
 124         mutex_enter(&unique_mtx);
 125         un = avl_find(&unique_avl, &un_tofind, NULL);
 126         if (un != NULL) {
 127                 avl_remove(&unique_avl, un);
 128                 kmem_free(un, sizeof (unique_t));
 129         }
 130         mutex_exit(&unique_mtx);
 131 }