Print this page
4185 New hash algorithm support

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/zfs/spa_misc.c
          +++ new/usr/src/uts/common/fs/zfs/spa_misc.c
↓ open down ↓ 14 lines elided ↑ open up ↑
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  23   23   * Copyright (c) 2013 by Delphix. All rights reserved.
  24   24   * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
       25 + * Copyright 2013 Saso Kiselkov. All rights reserved.
  25   26   */
  26   27  
  27   28  #include <sys/zfs_context.h>
  28   29  #include <sys/spa_impl.h>
  29   30  #include <sys/spa_boot.h>
  30   31  #include <sys/zio.h>
  31   32  #include <sys/zio_checksum.h>
  32   33  #include <sys/zio_compress.h>
  33   34  #include <sys/dmu.h>
  34   35  #include <sys/dmu_tx.h>
↓ open down ↓ 7 lines elided ↑ open up ↑
  42   43  #include <sys/unique.h>
  43   44  #include <sys/dsl_pool.h>
  44   45  #include <sys/dsl_dir.h>
  45   46  #include <sys/dsl_prop.h>
  46   47  #include <sys/dsl_scan.h>
  47   48  #include <sys/fs/zfs.h>
  48   49  #include <sys/metaslab_impl.h>
  49   50  #include <sys/arc.h>
  50   51  #include <sys/ddt.h>
  51   52  #include "zfs_prop.h"
  52      -#include "zfeature_common.h"
       53 +#include <sys/zfeature.h>
  53   54  
  54   55  /*
  55   56   * SPA locking
  56   57   *
  57   58   * There are four basic locks for managing spa_t structures:
  58   59   *
  59   60   * spa_namespace_lock (global mutex)
  60   61   *
  61   62   *      This lock must be acquired to do any of the following:
  62   63   *
↓ open down ↓ 425 lines elided ↑ open up ↑
 488  489          ASSERT(MUTEX_HELD(&spa_namespace_lock));
 489  490  
 490  491          spa = kmem_zalloc(sizeof (spa_t), KM_SLEEP);
 491  492  
 492  493          mutex_init(&spa->spa_async_lock, NULL, MUTEX_DEFAULT, NULL);
 493  494          mutex_init(&spa->spa_errlist_lock, NULL, MUTEX_DEFAULT, NULL);
 494  495          mutex_init(&spa->spa_errlog_lock, NULL, MUTEX_DEFAULT, NULL);
 495  496          mutex_init(&spa->spa_history_lock, NULL, MUTEX_DEFAULT, NULL);
 496  497          mutex_init(&spa->spa_proc_lock, NULL, MUTEX_DEFAULT, NULL);
 497  498          mutex_init(&spa->spa_props_lock, NULL, MUTEX_DEFAULT, NULL);
      499 +        mutex_init(&spa->spa_cksum_tmpls_lock, NULL, MUTEX_DEFAULT, NULL);
 498  500          mutex_init(&spa->spa_scrub_lock, NULL, MUTEX_DEFAULT, NULL);
 499  501          mutex_init(&spa->spa_suspend_lock, NULL, MUTEX_DEFAULT, NULL);
 500  502          mutex_init(&spa->spa_vdev_top_lock, NULL, MUTEX_DEFAULT, NULL);
 501  503          mutex_init(&spa->spa_iokstat_lock, NULL, MUTEX_DEFAULT, NULL);
 502  504  
 503  505          cv_init(&spa->spa_async_cv, NULL, CV_DEFAULT, NULL);
 504  506          cv_init(&spa->spa_proc_cv, NULL, CV_DEFAULT, NULL);
 505  507          cv_init(&spa->spa_scrub_io_cv, NULL, CV_DEFAULT, NULL);
 506  508          cv_init(&spa->spa_suspend_cv, NULL, CV_DEFAULT, NULL);
 507  509  
↓ open down ↓ 126 lines elided ↑ open up ↑
 634  636          refcount_destroy(&spa->spa_refcount);
 635  637  
 636  638          spa_config_lock_destroy(spa);
 637  639  
 638  640          kstat_delete(spa->spa_iokstat);
 639  641          spa->spa_iokstat = NULL;
 640  642  
 641  643          for (int t = 0; t < TXG_SIZE; t++)
 642  644                  bplist_destroy(&spa->spa_free_bplist[t]);
 643  645  
      646 +        zio_checksum_templates_free(spa);
      647 +
 644  648          cv_destroy(&spa->spa_async_cv);
 645  649          cv_destroy(&spa->spa_proc_cv);
 646  650          cv_destroy(&spa->spa_scrub_io_cv);
 647  651          cv_destroy(&spa->spa_suspend_cv);
 648  652  
 649  653          mutex_destroy(&spa->spa_async_lock);
 650  654          mutex_destroy(&spa->spa_errlist_lock);
 651  655          mutex_destroy(&spa->spa_errlog_lock);
 652  656          mutex_destroy(&spa->spa_history_lock);
 653  657          mutex_destroy(&spa->spa_proc_lock);
 654  658          mutex_destroy(&spa->spa_props_lock);
      659 +        mutex_destroy(&spa->spa_cksum_tmpls_lock);
 655  660          mutex_destroy(&spa->spa_scrub_lock);
 656  661          mutex_destroy(&spa->spa_suspend_lock);
 657  662          mutex_destroy(&spa->spa_vdev_top_lock);
 658  663          mutex_destroy(&spa->spa_iokstat_lock);
 659  664  
 660  665          kmem_free(spa, sizeof (spa_t));
 661  666  }
 662  667  
 663  668  /*
 664  669   * Given a pool, return the next pool in the namespace, or NULL if there is
↓ open down ↓ 1110 lines elided ↑ open up ↑
1775 1780  {
1776 1781          return (spa->spa_is_root);
1777 1782  }
1778 1783  
1779 1784  boolean_t
1780 1785  spa_writeable(spa_t *spa)
1781 1786  {
1782 1787          return (!!(spa->spa_mode & FWRITE));
1783 1788  }
1784 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 +
1785 1847  int
1786 1848  spa_mode(spa_t *spa)
1787 1849  {
1788 1850          return (spa->spa_mode);
1789 1851  }
1790 1852  
1791 1853  uint64_t
1792 1854  spa_bootfs(spa_t *spa)
1793 1855  {
1794 1856          return (spa->spa_bootfs);
↓ open down ↓ 67 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX