Print this page
4185 New hash algorithm support


   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  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.

  25  */
  26 
  27 #include <sys/zfs_context.h>
  28 #include <sys/spa_impl.h>
  29 #include <sys/spa_boot.h>
  30 #include <sys/zio.h>
  31 #include <sys/zio_checksum.h>
  32 #include <sys/zio_compress.h>
  33 #include <sys/dmu.h>
  34 #include <sys/dmu_tx.h>
  35 #include <sys/zap.h>
  36 #include <sys/zil.h>
  37 #include <sys/vdev_impl.h>
  38 #include <sys/metaslab.h>
  39 #include <sys/uberblock_impl.h>
  40 #include <sys/txg.h>
  41 #include <sys/avl.h>
  42 #include <sys/unique.h>
  43 #include <sys/dsl_pool.h>
  44 #include <sys/dsl_dir.h>
  45 #include <sys/dsl_prop.h>
  46 #include <sys/dsl_scan.h>
  47 #include <sys/fs/zfs.h>
  48 #include <sys/metaslab_impl.h>
  49 #include <sys/arc.h>
  50 #include <sys/ddt.h>
  51 #include "zfs_prop.h"
  52 #include "zfeature_common.h"
  53 
  54 /*
  55  * SPA locking
  56  *
  57  * There are four basic locks for managing spa_t structures:
  58  *
  59  * spa_namespace_lock (global mutex)
  60  *
  61  *      This lock must be acquired to do any of the following:
  62  *
  63  *              - Lookup a spa_t by name
  64  *              - Add or remove a spa_t from the namespace
  65  *              - Increase spa_refcount from non-zero
  66  *              - Check if spa_refcount is zero
  67  *              - Rename a spa_t
  68  *              - add/remove/attach/detach devices
  69  *              - Held for the duration of create/destroy/import/export
  70  *
  71  *      It does not need to handle recursion.  A create or destroy may
  72  *      reference objects (files or zvols) in other pools, but by


 478  * exist by calling spa_lookup() first.
 479  */
 480 spa_t *
 481 spa_add(const char *name, nvlist_t *config, const char *altroot)
 482 {
 483         spa_t *spa;
 484         spa_config_dirent_t *dp;
 485         cyc_handler_t hdlr;
 486         cyc_time_t when;
 487 
 488         ASSERT(MUTEX_HELD(&spa_namespace_lock));
 489 
 490         spa = kmem_zalloc(sizeof (spa_t), KM_SLEEP);
 491 
 492         mutex_init(&spa->spa_async_lock, NULL, MUTEX_DEFAULT, NULL);
 493         mutex_init(&spa->spa_errlist_lock, NULL, MUTEX_DEFAULT, NULL);
 494         mutex_init(&spa->spa_errlog_lock, NULL, MUTEX_DEFAULT, NULL);
 495         mutex_init(&spa->spa_history_lock, NULL, MUTEX_DEFAULT, NULL);
 496         mutex_init(&spa->spa_proc_lock, NULL, MUTEX_DEFAULT, NULL);
 497         mutex_init(&spa->spa_props_lock, NULL, MUTEX_DEFAULT, NULL);

 498         mutex_init(&spa->spa_scrub_lock, NULL, MUTEX_DEFAULT, NULL);
 499         mutex_init(&spa->spa_suspend_lock, NULL, MUTEX_DEFAULT, NULL);
 500         mutex_init(&spa->spa_vdev_top_lock, NULL, MUTEX_DEFAULT, NULL);
 501         mutex_init(&spa->spa_iokstat_lock, NULL, MUTEX_DEFAULT, NULL);
 502 
 503         cv_init(&spa->spa_async_cv, NULL, CV_DEFAULT, NULL);
 504         cv_init(&spa->spa_proc_cv, NULL, CV_DEFAULT, NULL);
 505         cv_init(&spa->spa_scrub_io_cv, NULL, CV_DEFAULT, NULL);
 506         cv_init(&spa->spa_suspend_cv, NULL, CV_DEFAULT, NULL);
 507 
 508         for (int t = 0; t < TXG_SIZE; t++)
 509                 bplist_create(&spa->spa_free_bplist[t]);
 510 
 511         (void) strlcpy(spa->spa_name, name, sizeof (spa->spa_name));
 512         spa->spa_state = POOL_STATE_UNINITIALIZED;
 513         spa->spa_freeze_txg = UINT64_MAX;
 514         spa->spa_final_txg = UINT64_MAX;
 515         spa->spa_load_max_txg = UINT64_MAX;
 516         spa->spa_proc = &p0;
 517         spa->spa_proc_state = SPA_PROC_NONE;


 624         nvlist_free(spa->spa_label_features);
 625         nvlist_free(spa->spa_load_info);
 626         spa_config_set(spa, NULL);
 627 
 628         mutex_enter(&cpu_lock);
 629         if (spa->spa_deadman_cycid != CYCLIC_NONE)
 630                 cyclic_remove(spa->spa_deadman_cycid);
 631         mutex_exit(&cpu_lock);
 632         spa->spa_deadman_cycid = CYCLIC_NONE;
 633 
 634         refcount_destroy(&spa->spa_refcount);
 635 
 636         spa_config_lock_destroy(spa);
 637 
 638         kstat_delete(spa->spa_iokstat);
 639         spa->spa_iokstat = NULL;
 640 
 641         for (int t = 0; t < TXG_SIZE; t++)
 642                 bplist_destroy(&spa->spa_free_bplist[t]);
 643 


 644         cv_destroy(&spa->spa_async_cv);
 645         cv_destroy(&spa->spa_proc_cv);
 646         cv_destroy(&spa->spa_scrub_io_cv);
 647         cv_destroy(&spa->spa_suspend_cv);
 648 
 649         mutex_destroy(&spa->spa_async_lock);
 650         mutex_destroy(&spa->spa_errlist_lock);
 651         mutex_destroy(&spa->spa_errlog_lock);
 652         mutex_destroy(&spa->spa_history_lock);
 653         mutex_destroy(&spa->spa_proc_lock);
 654         mutex_destroy(&spa->spa_props_lock);

 655         mutex_destroy(&spa->spa_scrub_lock);
 656         mutex_destroy(&spa->spa_suspend_lock);
 657         mutex_destroy(&spa->spa_vdev_top_lock);
 658         mutex_destroy(&spa->spa_iokstat_lock);
 659 
 660         kmem_free(spa, sizeof (spa_t));
 661 }
 662 
 663 /*
 664  * Given a pool, return the next pool in the namespace, or NULL if there is
 665  * none.  If 'prev' is NULL, return the first pool.
 666  */
 667 spa_t *
 668 spa_next(spa_t *prev)
 669 {
 670         ASSERT(MUTEX_HELD(&spa_namespace_lock));
 671 
 672         if (prev)
 673                 return (AVL_NEXT(&spa_namespace_avl, prev));
 674         else


1765 }
1766 
1767 void
1768 spa_set_log_state(spa_t *spa, spa_log_state_t state)
1769 {
1770         spa->spa_log_state = state;
1771 }
1772 
1773 boolean_t
1774 spa_is_root(spa_t *spa)
1775 {
1776         return (spa->spa_is_root);
1777 }
1778 
1779 boolean_t
1780 spa_writeable(spa_t *spa)
1781 {
1782         return (!!(spa->spa_mode & FWRITE));
1783 }
1784 

























































1785 int
1786 spa_mode(spa_t *spa)
1787 {
1788         return (spa->spa_mode);
1789 }
1790 
1791 uint64_t
1792 spa_bootfs(spa_t *spa)
1793 {
1794         return (spa->spa_bootfs);
1795 }
1796 
1797 uint64_t
1798 spa_delegation(spa_t *spa)
1799 {
1800         return (spa->spa_delegation);
1801 }
1802 
1803 objset_t *
1804 spa_meta_objset(spa_t *spa)




   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  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  25  * Copyright 2013 Saso Kiselkov. All rights reserved.
  26  */
  27 
  28 #include <sys/zfs_context.h>
  29 #include <sys/spa_impl.h>
  30 #include <sys/spa_boot.h>
  31 #include <sys/zio.h>
  32 #include <sys/zio_checksum.h>
  33 #include <sys/zio_compress.h>
  34 #include <sys/dmu.h>
  35 #include <sys/dmu_tx.h>
  36 #include <sys/zap.h>
  37 #include <sys/zil.h>
  38 #include <sys/vdev_impl.h>
  39 #include <sys/metaslab.h>
  40 #include <sys/uberblock_impl.h>
  41 #include <sys/txg.h>
  42 #include <sys/avl.h>
  43 #include <sys/unique.h>
  44 #include <sys/dsl_pool.h>
  45 #include <sys/dsl_dir.h>
  46 #include <sys/dsl_prop.h>
  47 #include <sys/dsl_scan.h>
  48 #include <sys/fs/zfs.h>
  49 #include <sys/metaslab_impl.h>
  50 #include <sys/arc.h>
  51 #include <sys/ddt.h>
  52 #include "zfs_prop.h"
  53 #include <sys/zfeature.h>
  54 
  55 /*
  56  * SPA locking
  57  *
  58  * There are four basic locks for managing spa_t structures:
  59  *
  60  * spa_namespace_lock (global mutex)
  61  *
  62  *      This lock must be acquired to do any of the following:
  63  *
  64  *              - Lookup a spa_t by name
  65  *              - Add or remove a spa_t from the namespace
  66  *              - Increase spa_refcount from non-zero
  67  *              - Check if spa_refcount is zero
  68  *              - Rename a spa_t
  69  *              - add/remove/attach/detach devices
  70  *              - Held for the duration of create/destroy/import/export
  71  *
  72  *      It does not need to handle recursion.  A create or destroy may
  73  *      reference objects (files or zvols) in other pools, but by


 479  * exist by calling spa_lookup() first.
 480  */
 481 spa_t *
 482 spa_add(const char *name, nvlist_t *config, const char *altroot)
 483 {
 484         spa_t *spa;
 485         spa_config_dirent_t *dp;
 486         cyc_handler_t hdlr;
 487         cyc_time_t when;
 488 
 489         ASSERT(MUTEX_HELD(&spa_namespace_lock));
 490 
 491         spa = kmem_zalloc(sizeof (spa_t), KM_SLEEP);
 492 
 493         mutex_init(&spa->spa_async_lock, NULL, MUTEX_DEFAULT, NULL);
 494         mutex_init(&spa->spa_errlist_lock, NULL, MUTEX_DEFAULT, NULL);
 495         mutex_init(&spa->spa_errlog_lock, NULL, MUTEX_DEFAULT, NULL);
 496         mutex_init(&spa->spa_history_lock, NULL, MUTEX_DEFAULT, NULL);
 497         mutex_init(&spa->spa_proc_lock, NULL, MUTEX_DEFAULT, NULL);
 498         mutex_init(&spa->spa_props_lock, NULL, MUTEX_DEFAULT, NULL);
 499         mutex_init(&spa->spa_cksum_tmpls_lock, NULL, MUTEX_DEFAULT, NULL);
 500         mutex_init(&spa->spa_scrub_lock, NULL, MUTEX_DEFAULT, NULL);
 501         mutex_init(&spa->spa_suspend_lock, NULL, MUTEX_DEFAULT, NULL);
 502         mutex_init(&spa->spa_vdev_top_lock, NULL, MUTEX_DEFAULT, NULL);
 503         mutex_init(&spa->spa_iokstat_lock, NULL, MUTEX_DEFAULT, NULL);
 504 
 505         cv_init(&spa->spa_async_cv, NULL, CV_DEFAULT, NULL);
 506         cv_init(&spa->spa_proc_cv, NULL, CV_DEFAULT, NULL);
 507         cv_init(&spa->spa_scrub_io_cv, NULL, CV_DEFAULT, NULL);
 508         cv_init(&spa->spa_suspend_cv, NULL, CV_DEFAULT, NULL);
 509 
 510         for (int t = 0; t < TXG_SIZE; t++)
 511                 bplist_create(&spa->spa_free_bplist[t]);
 512 
 513         (void) strlcpy(spa->spa_name, name, sizeof (spa->spa_name));
 514         spa->spa_state = POOL_STATE_UNINITIALIZED;
 515         spa->spa_freeze_txg = UINT64_MAX;
 516         spa->spa_final_txg = UINT64_MAX;
 517         spa->spa_load_max_txg = UINT64_MAX;
 518         spa->spa_proc = &p0;
 519         spa->spa_proc_state = SPA_PROC_NONE;


 626         nvlist_free(spa->spa_label_features);
 627         nvlist_free(spa->spa_load_info);
 628         spa_config_set(spa, NULL);
 629 
 630         mutex_enter(&cpu_lock);
 631         if (spa->spa_deadman_cycid != CYCLIC_NONE)
 632                 cyclic_remove(spa->spa_deadman_cycid);
 633         mutex_exit(&cpu_lock);
 634         spa->spa_deadman_cycid = CYCLIC_NONE;
 635 
 636         refcount_destroy(&spa->spa_refcount);
 637 
 638         spa_config_lock_destroy(spa);
 639 
 640         kstat_delete(spa->spa_iokstat);
 641         spa->spa_iokstat = NULL;
 642 
 643         for (int t = 0; t < TXG_SIZE; t++)
 644                 bplist_destroy(&spa->spa_free_bplist[t]);
 645 
 646         zio_checksum_templates_free(spa);
 647 
 648         cv_destroy(&spa->spa_async_cv);
 649         cv_destroy(&spa->spa_proc_cv);
 650         cv_destroy(&spa->spa_scrub_io_cv);
 651         cv_destroy(&spa->spa_suspend_cv);
 652 
 653         mutex_destroy(&spa->spa_async_lock);
 654         mutex_destroy(&spa->spa_errlist_lock);
 655         mutex_destroy(&spa->spa_errlog_lock);
 656         mutex_destroy(&spa->spa_history_lock);
 657         mutex_destroy(&spa->spa_proc_lock);
 658         mutex_destroy(&spa->spa_props_lock);
 659         mutex_destroy(&spa->spa_cksum_tmpls_lock);
 660         mutex_destroy(&spa->spa_scrub_lock);
 661         mutex_destroy(&spa->spa_suspend_lock);
 662         mutex_destroy(&spa->spa_vdev_top_lock);
 663         mutex_destroy(&spa->spa_iokstat_lock);
 664 
 665         kmem_free(spa, sizeof (spa_t));
 666 }
 667 
 668 /*
 669  * Given a pool, return the next pool in the namespace, or NULL if there is
 670  * none.  If 'prev' is NULL, return the first pool.
 671  */
 672 spa_t *
 673 spa_next(spa_t *prev)
 674 {
 675         ASSERT(MUTEX_HELD(&spa_namespace_lock));
 676 
 677         if (prev)
 678                 return (AVL_NEXT(&spa_namespace_avl, prev));
 679         else


1770 }
1771 
1772 void
1773 spa_set_log_state(spa_t *spa, spa_log_state_t state)
1774 {
1775         spa->spa_log_state = state;
1776 }
1777 
1778 boolean_t
1779 spa_is_root(spa_t *spa)
1780 {
1781         return (spa->spa_is_root);
1782 }
1783 
1784 boolean_t
1785 spa_writeable(spa_t *spa)
1786 {
1787         return (!!(spa->spa_mode & FWRITE));
1788 }
1789 
1790 static int
1791 activate_salted_cksum_check(zfeature_info_t *feature, dmu_tx_t *tx)
1792 {
1793         spa_t   *spa = dmu_tx_pool(tx)->dp_spa;
1794 
1795         if (!spa_feature_is_active(spa, feature))
1796                 return (0);
1797         else
1798                 return (SET_ERROR(EBUSY));
1799 }
1800 
1801 static void
1802 activate_salted_cksum_sync(zfeature_info_t *feature, dmu_tx_t *tx)
1803 {
1804         spa_t   *spa = dmu_tx_pool(tx)->dp_spa;
1805 
1806         spa_feature_incr(spa, feature, tx);
1807         /*
1808          * This is the first salted checksum that's been activated, so
1809          * create the persistent checksum salt object now.
1810          */
1811         if (spa->spa_cksum_salt_obj == 0) {
1812                 spa->spa_cksum_salt_obj = zap_create_link(spa->spa_meta_objset,
1813                     DMU_OTN_ZAP_METADATA, DMU_POOL_DIRECTORY_OBJECT,
1814                     DMU_POOL_CHECKSUM_SALT, tx);
1815                 VERIFY3U(zap_add(spa->spa_meta_objset,
1816                     spa->spa_cksum_salt_obj, DMU_POOL_CHECKSUM_SALT, 1,
1817                     sizeof (spa->spa_cksum_salt.zcs_bytes),
1818                     spa->spa_cksum_salt.zcs_bytes, tx), ==, 0);
1819         }
1820 }
1821 
1822 /*
1823  * Activates a feature associated with a salted checksum. You must call this
1824  * function instead of calling spa_feature_incr() directly, because we may
1825  * also need to sync the MOS object holding the checksum salt.
1826  * Arguments:
1827  *      spa     Pool on which to activate the salted checksum feature.
1828  *      feature Salted checksum algorithm feature to activate (see
1829  *              spa_feature_table).
1830  */
1831 int
1832 spa_activate_salted_cksum(spa_t *spa, struct zfeature_info *feature)
1833 {
1834         int err;
1835 
1836         /* EBUSY here indicates that the feature is already active */
1837         err = dsl_sync_task(spa_name(spa),
1838             (dsl_checkfunc_t *)activate_salted_cksum_check,
1839             (dsl_syncfunc_t *)activate_salted_cksum_sync, feature, 2);
1840 
1841         if (err != 0 && err != EBUSY)
1842                 return (err);
1843         else
1844                 return (0);
1845 }
1846 
1847 int
1848 spa_mode(spa_t *spa)
1849 {
1850         return (spa->spa_mode);
1851 }
1852 
1853 uint64_t
1854 spa_bootfs(spa_t *spa)
1855 {
1856         return (spa->spa_bootfs);
1857 }
1858 
1859 uint64_t
1860 spa_delegation(spa_t *spa)
1861 {
1862         return (spa->spa_delegation);
1863 }
1864 
1865 objset_t *
1866 spa_meta_objset(spa_t *spa)