| 5779 | } |
| 5780 | |
| 5781 | int |
| 5782 | metaslab_alloc(spa_t *spa, metaslab_class_t *mc, uint64_t psize, blkptr_t *bp, |
| 5783 | int ndvas, uint64_t txg, blkptr_t *hintbp, int flags, |
| 5784 | zio_alloc_list_t *zal, zio_t *zio, int allocator) |
| 5785 | { |
| 5786 | dva_t *dva = bp->blk_dva; |
| 5787 | dva_t *hintdva = (hintbp != NULL) ? hintbp->blk_dva : NULL; |
| 5788 | int error = 0; |
| 5789 | |
| 5790 | ASSERT(bp->blk_birth == 0); |
| 5791 | ASSERT(BP_PHYSICAL_BIRTH(bp) == 0); |
| 5792 | |
| 5793 | spa_config_enter(spa, SCL_ALLOC, FTAG, RW_READER); |
| 5794 | |
| 5795 | if (mc->mc_allocator[allocator].mca_rotor == NULL) { |
| 5796 | /* no vdevs in this class */ |
| 5797 | spa_config_exit(spa, SCL_ALLOC, FTAG); |
| 5798 | return (SET_ERROR(ENOSPC)); |
| 5799 | } |
| 5800 | |
| 5801 | ASSERT(ndvas > 0 && ndvas <= spa_max_replication(spa)); |
| 5802 | ASSERT(BP_GET_NDVAS(bp) == 0); |
| 5803 | ASSERT(hintbp == NULL || ndvas <= BP_GET_NDVAS(hintbp)); |
| 5804 | ASSERT3P(zal, !=, NULL); |
| 5805 | |
| 5806 | for (int d = 0; d < ndvas; d++) { |
| 5807 | error = metaslab_alloc_dva(spa, mc, psize, dva, d, hintdva, |
| 5808 | txg, flags, zal, allocator); |
| 5809 | if (error != 0) { |
| 5810 | for (d--; d >= 0; d--) { |
| 5811 | metaslab_unalloc_dva(spa, &dva[d], txg); |
| 5812 | metaslab_group_alloc_decrement(spa, |
| 5813 | DVA_GET_VDEV(&dva[d]), zio, flags, |
| 5814 | allocator, B_FALSE); |
| 5815 | bzero(&dva[d], sizeof (dva_t)); |
| 5816 | } |
| 5817 | spa_config_exit(spa, SCL_ALLOC, FTAG); |
| 5818 | return (error); |
| 5819 | } else { |
| 5820 | /* |
| 5821 | * Update the metaslab group's queue depth |
| 5822 | * based on the newly allocated dva. |
| 5823 | */ |
| 5824 | metaslab_group_alloc_increment(spa, |
| 5825 | DVA_GET_VDEV(&dva[d]), zio, flags, allocator); |
| 5826 | } |
| 5827 | } |
| 5828 | ASSERT(error == 0); |
| 5829 | ASSERT(BP_GET_NDVAS(bp) == ndvas); |
| 5830 | |
| 5831 | spa_config_exit(spa, SCL_ALLOC, FTAG); |
| 5832 | |
| 5833 | BP_SET_BIRTH(bp, txg, 0); |
| 5834 | |
| 5835 | return (0); |
| 5836 | } |
| 5837 | |
| 5838 | void |
no test coverage detected