Print this page
2882 implement libzfs_core
2883 changing "canmount" property to "on" should not always remount dataset
2900 "zfs snapshot" should be able to create multiple, arbitrary snapshots at once
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Chris Siden <christopher.siden@delphix.com>
Reviewed by: Garrett D'Amore <garrett@damore.org>
Reviewed by: Bill Pijewski <wdp@joyent.com>
Reviewed by: Dan Kruchinin <dan.kruchinin@gmail.com>


   3  *
   4  * The contents of this file are subject to the terms of the
   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  */
  24 
  25 #include <sys/zfs_context.h>
  26 #include <sys/dmu.h>
  27 #include <sys/dmu_objset.h>
  28 #include <sys/dmu_tx.h>
  29 #include <sys/dsl_dataset.h>
  30 #include <sys/dsl_dir.h>
  31 #include <sys/dsl_prop.h>
  32 #include <sys/dsl_synctask.h>
  33 #include <sys/spa.h>
  34 #include <sys/zap.h>
  35 #include <sys/fs/zfs.h>
  36 
  37 #include "zfs_prop.h"
  38 
  39 #define ZPROP_INHERIT_SUFFIX "$inherit"
  40 #define ZPROP_RECVD_SUFFIX "$recvd"
  41 
  42 static int


 685                         mutex_exit(&ds->ds_dir->dd_lock);
 686                 } else {
 687                         dsl_prop_changed_notify(ds->ds_dir->dd_pool,
 688                             ds->ds_dir->dd_object, propname, intval, TRUE);
 689                 }
 690 
 691                 (void) snprintf(valbuf, sizeof (valbuf),
 692                     "%lld", (longlong_t)intval);
 693                 valstr = valbuf;
 694         } else {
 695                 if (source == ZPROP_SRC_LOCAL) {
 696                         valstr = (char *)psa->psa_value;
 697                 } else {
 698                         tbuf = kmem_alloc(ZAP_MAXVALUELEN, KM_SLEEP);
 699                         if (dsl_prop_get_ds(ds, propname, 1,
 700                             ZAP_MAXVALUELEN, tbuf, NULL) == 0)
 701                                 valstr = tbuf;
 702                 }
 703         }
 704 
 705         spa_history_log_internal((source == ZPROP_SRC_NONE ||
 706             source == ZPROP_SRC_INHERITED) ? LOG_DS_INHERIT :
 707             LOG_DS_PROPSET, ds->ds_dir->dd_pool->dp_spa, tx,
 708             "%s=%s dataset = %llu", propname,
 709             (valstr == NULL ? "" : valstr), ds->ds_object);
 710 
 711         if (tbuf != NULL)
 712                 kmem_free(tbuf, ZAP_MAXVALUELEN);
 713 }
 714 
 715 void
 716 dsl_props_set_sync(void *arg1, void *arg2, dmu_tx_t *tx)
 717 {
 718         dsl_dataset_t *ds = arg1;
 719         dsl_props_arg_t *pa = arg2;
 720         nvlist_t *props = pa->pa_props;
 721         dsl_prop_setarg_t psa;
 722         nvpair_t *elem = NULL;
 723 
 724         psa.psa_source = pa->pa_source;
 725 
 726         while ((elem = nvlist_next_nvpair(props, elem)) != NULL) {
 727                 nvpair_t *pair = elem;
 728 
 729                 psa.psa_name = nvpair_name(pair);


 738                         VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
 739                             &pair) == 0);
 740                 }
 741 
 742                 if (nvpair_type(pair) == DATA_TYPE_STRING) {
 743                         VERIFY(nvpair_value_string(pair,
 744                             (char **)&psa.psa_value) == 0);
 745                         psa.psa_intsz = 1;
 746                         psa.psa_numints = strlen(psa.psa_value) + 1;
 747                 } else {
 748                         uint64_t intval;
 749                         VERIFY(nvpair_value_uint64(pair, &intval) == 0);
 750                         psa.psa_intsz = sizeof (intval);
 751                         psa.psa_numints = 1;
 752                         psa.psa_value = &intval;
 753                 }
 754                 dsl_prop_set_sync(ds, &psa, tx);
 755         }
 756 }
 757 
 758 void
 759 dsl_dir_prop_set_uint64_sync(dsl_dir_t *dd, const char *name, uint64_t val,
 760     dmu_tx_t *tx)
 761 {
 762         objset_t *mos = dd->dd_pool->dp_meta_objset;
 763         uint64_t zapobj = dd->dd_phys->dd_props_zapobj;
 764 
 765         ASSERT(dmu_tx_is_syncing(tx));
 766 
 767         VERIFY(0 == zap_update(mos, zapobj, name, sizeof (val), 1, &val, tx));
 768 
 769         dsl_prop_changed_notify(dd->dd_pool, dd->dd_object, name, val, TRUE);
 770 
 771         spa_history_log_internal(LOG_DS_PROPSET, dd->dd_pool->dp_spa, tx,
 772             "%s=%llu dataset = %llu", name, (u_longlong_t)val,
 773             dd->dd_phys->dd_head_dataset_obj);
 774 }
 775 
 776 int
 777 dsl_prop_set(const char *dsname, const char *propname, zprop_source_t source,
 778     int intsz, int numints, const void *buf)
 779 {
 780         dsl_dataset_t *ds;
 781         uint64_t version;
 782         int err;
 783         dsl_prop_setarg_t psa;
 784 
 785         /*
 786          * We must do these checks before we get to the syncfunc, since
 787          * it can't fail.
 788          */
 789         if (strlen(propname) >= ZAP_MAXNAMELEN)
 790                 return (ENAMETOOLONG);
 791 
 792         err = dsl_dataset_hold(dsname, FTAG, &ds);
 793         if (err)
 794                 return (err);
 795 




   3  *
   4  * The contents of this file are subject to the terms of the
   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) 2012 by Delphix. All rights reserved.
  24  */
  25 
  26 #include <sys/zfs_context.h>
  27 #include <sys/dmu.h>
  28 #include <sys/dmu_objset.h>
  29 #include <sys/dmu_tx.h>
  30 #include <sys/dsl_dataset.h>
  31 #include <sys/dsl_dir.h>
  32 #include <sys/dsl_prop.h>
  33 #include <sys/dsl_synctask.h>
  34 #include <sys/spa.h>
  35 #include <sys/zap.h>
  36 #include <sys/fs/zfs.h>
  37 
  38 #include "zfs_prop.h"
  39 
  40 #define ZPROP_INHERIT_SUFFIX "$inherit"
  41 #define ZPROP_RECVD_SUFFIX "$recvd"
  42 
  43 static int


 686                         mutex_exit(&ds->ds_dir->dd_lock);
 687                 } else {
 688                         dsl_prop_changed_notify(ds->ds_dir->dd_pool,
 689                             ds->ds_dir->dd_object, propname, intval, TRUE);
 690                 }
 691 
 692                 (void) snprintf(valbuf, sizeof (valbuf),
 693                     "%lld", (longlong_t)intval);
 694                 valstr = valbuf;
 695         } else {
 696                 if (source == ZPROP_SRC_LOCAL) {
 697                         valstr = (char *)psa->psa_value;
 698                 } else {
 699                         tbuf = kmem_alloc(ZAP_MAXVALUELEN, KM_SLEEP);
 700                         if (dsl_prop_get_ds(ds, propname, 1,
 701                             ZAP_MAXVALUELEN, tbuf, NULL) == 0)
 702                                 valstr = tbuf;
 703                 }
 704         }
 705 
 706         spa_history_log_internal_ds(ds, (source == ZPROP_SRC_NONE ||
 707             source == ZPROP_SRC_INHERITED) ? "inherit" : "set", tx,
 708             "%s=%s", propname, (valstr == NULL ? "" : valstr));


 709 
 710         if (tbuf != NULL)
 711                 kmem_free(tbuf, ZAP_MAXVALUELEN);
 712 }
 713 
 714 void
 715 dsl_props_set_sync(void *arg1, void *arg2, dmu_tx_t *tx)
 716 {
 717         dsl_dataset_t *ds = arg1;
 718         dsl_props_arg_t *pa = arg2;
 719         nvlist_t *props = pa->pa_props;
 720         dsl_prop_setarg_t psa;
 721         nvpair_t *elem = NULL;
 722 
 723         psa.psa_source = pa->pa_source;
 724 
 725         while ((elem = nvlist_next_nvpair(props, elem)) != NULL) {
 726                 nvpair_t *pair = elem;
 727 
 728                 psa.psa_name = nvpair_name(pair);


 737                         VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
 738                             &pair) == 0);
 739                 }
 740 
 741                 if (nvpair_type(pair) == DATA_TYPE_STRING) {
 742                         VERIFY(nvpair_value_string(pair,
 743                             (char **)&psa.psa_value) == 0);
 744                         psa.psa_intsz = 1;
 745                         psa.psa_numints = strlen(psa.psa_value) + 1;
 746                 } else {
 747                         uint64_t intval;
 748                         VERIFY(nvpair_value_uint64(pair, &intval) == 0);
 749                         psa.psa_intsz = sizeof (intval);
 750                         psa.psa_numints = 1;
 751                         psa.psa_value = &intval;
 752                 }
 753                 dsl_prop_set_sync(ds, &psa, tx);
 754         }
 755 }
 756 


















 757 int
 758 dsl_prop_set(const char *dsname, const char *propname, zprop_source_t source,
 759     int intsz, int numints, const void *buf)
 760 {
 761         dsl_dataset_t *ds;
 762         uint64_t version;
 763         int err;
 764         dsl_prop_setarg_t psa;
 765 
 766         /*
 767          * We must do these checks before we get to the syncfunc, since
 768          * it can't fail.
 769          */
 770         if (strlen(propname) >= ZAP_MAXNAMELEN)
 771                 return (ENAMETOOLONG);
 772 
 773         err = dsl_dataset_hold(dsname, FTAG, &ds);
 774         if (err)
 775                 return (err);
 776