772 mutex_exit(&zvol_state_lock); |
772 mutex_exit(&zvol_state_lock); |
773 |
773 |
774 return (0); |
774 return (0); |
775 } |
775 } |
776 |
776 |
777 static int |
|
778 zvol_truncate(zvol_state_t *zv, uint64_t offset, uint64_t size) |
|
779 { |
|
780 dmu_tx_t *tx; |
|
781 int error; |
|
782 |
|
783 tx = dmu_tx_create(zv->zv_objset); |
|
784 dmu_tx_hold_free(tx, ZVOL_OBJ, offset, size); |
|
785 error = dmu_tx_assign(tx, TXG_WAIT); |
|
786 if (error) { |
|
787 dmu_tx_abort(tx); |
|
788 return (error); |
|
789 } |
|
790 error = dmu_free_range(zv->zv_objset, ZVOL_OBJ, offset, size, tx); |
|
791 dmu_tx_commit(tx); |
|
792 return (0); |
|
793 } |
|
794 |
|
795 int |
777 int |
796 zvol_prealloc(zvol_state_t *zv) |
778 zvol_prealloc(zvol_state_t *zv) |
797 { |
779 { |
798 objset_t *os = zv->zv_objset; |
780 objset_t *os = zv->zv_objset; |
799 dmu_tx_t *tx; |
781 dmu_tx_t *tx; |
821 dmu_tx_hold_write(tx, ZVOL_OBJ, off, bytes); |
803 dmu_tx_hold_write(tx, ZVOL_OBJ, off, bytes); |
822 error = dmu_tx_assign(tx, TXG_WAIT); |
804 error = dmu_tx_assign(tx, TXG_WAIT); |
823 if (error) { |
805 if (error) { |
824 dmu_tx_abort(tx); |
806 dmu_tx_abort(tx); |
825 kmem_free(data, SPA_MAXBLOCKSIZE); |
807 kmem_free(data, SPA_MAXBLOCKSIZE); |
826 (void) zvol_truncate(zv, 0, off); |
808 (void) dmu_free_long_range(os, ZVOL_OBJ, 0, off); |
827 return (error); |
809 return (error); |
828 } |
810 } |
829 dmu_write(os, ZVOL_OBJ, off, bytes, data, tx); |
811 dmu_write(os, ZVOL_OBJ, off, bytes, data, tx); |
830 dmu_tx_commit(tx); |
812 dmu_tx_commit(tx); |
831 off += bytes; |
813 off += bytes; |
845 |
827 |
846 ASSERT(MUTEX_HELD(&zvol_state_lock)); |
828 ASSERT(MUTEX_HELD(&zvol_state_lock)); |
847 |
829 |
848 tx = dmu_tx_create(zv->zv_objset); |
830 tx = dmu_tx_create(zv->zv_objset); |
849 dmu_tx_hold_zap(tx, ZVOL_ZAP_OBJ, TRUE, NULL); |
831 dmu_tx_hold_zap(tx, ZVOL_ZAP_OBJ, TRUE, NULL); |
850 dmu_tx_hold_free(tx, ZVOL_OBJ, volsize, DMU_OBJECT_END); |
|
851 error = dmu_tx_assign(tx, TXG_WAIT); |
832 error = dmu_tx_assign(tx, TXG_WAIT); |
852 if (error) { |
833 if (error) { |
853 dmu_tx_abort(tx); |
834 dmu_tx_abort(tx); |
854 return (error); |
835 return (error); |
855 } |
836 } |
857 error = zap_update(zv->zv_objset, ZVOL_ZAP_OBJ, "size", 8, 1, |
838 error = zap_update(zv->zv_objset, ZVOL_ZAP_OBJ, "size", 8, 1, |
858 &volsize, tx); |
839 &volsize, tx); |
859 dmu_tx_commit(tx); |
840 dmu_tx_commit(tx); |
860 |
841 |
861 if (error == 0) |
842 if (error == 0) |
862 error = zvol_truncate(zv, volsize, DMU_OBJECT_END); |
843 error = dmu_free_long_range(zv->zv_objset, |
|
844 ZVOL_OBJ, volsize, DMU_OBJECT_END); |
863 |
845 |
864 if (error == 0) { |
846 if (error == 0) { |
865 zv->zv_volsize = volsize; |
847 zv->zv_volsize = volsize; |
866 zvol_size_changed(zv, maj); |
848 zvol_size_changed(zv, maj); |
867 } |
849 } |
1649 uint64_t checksum, compress, refresrv; |
1631 uint64_t checksum, compress, refresrv; |
1650 |
1632 |
1651 ASSERT(MUTEX_HELD(&zvol_state_lock)); |
1633 ASSERT(MUTEX_HELD(&zvol_state_lock)); |
1652 |
1634 |
1653 tx = dmu_tx_create(os); |
1635 tx = dmu_tx_create(os); |
1654 dmu_tx_hold_free(tx, ZVOL_OBJ, 0, DMU_OBJECT_END); |
|
1655 dmu_tx_hold_zap(tx, ZVOL_ZAP_OBJ, TRUE, NULL); |
1636 dmu_tx_hold_zap(tx, ZVOL_ZAP_OBJ, TRUE, NULL); |
1656 error = dmu_tx_assign(tx, TXG_WAIT); |
1637 error = dmu_tx_assign(tx, TXG_WAIT); |
1657 if (error) { |
1638 if (error) { |
1658 dmu_tx_abort(tx); |
1639 dmu_tx_abort(tx); |
1659 return (error); |
1640 return (error); |
1811 (void) zap_lookup(zv->zv_objset, ZVOL_ZAP_OBJ, |
1793 (void) zap_lookup(zv->zv_objset, ZVOL_ZAP_OBJ, |
1812 zfs_prop_to_name(ZFS_PROP_REFRESERVATION), 8, 1, &refresrv); |
1794 zfs_prop_to_name(ZFS_PROP_REFRESERVATION), 8, 1, &refresrv); |
1813 |
1795 |
1814 (void) zap_remove(os, ZVOL_ZAP_OBJ, ZVOL_DUMPSIZE, tx); |
1796 (void) zap_remove(os, ZVOL_ZAP_OBJ, ZVOL_DUMPSIZE, tx); |
1815 zvol_free_extents(zv); |
1797 zvol_free_extents(zv); |
1816 (void) zvol_truncate(zv, 0, DMU_OBJECT_END); |
1798 (void) dmu_free_long_range(os, ZVOL_OBJ, 0, DMU_OBJECT_END); |
1817 zv->zv_flags &= ~ZVOL_DUMPIFIED; |
1799 zv->zv_flags &= ~ZVOL_DUMPIFIED; |
1818 dmu_tx_commit(tx); |
1800 dmu_tx_commit(tx); |
1819 |
1801 |
1820 VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0); |
1802 VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0); |
1821 (void) nvlist_add_uint64(nv, |
1803 (void) nvlist_add_uint64(nv, |