Print this page
4574 get_clones_stat does not call zap_count in non-debug kernel
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Marcel Telka <marcel@telka.sk>
Approved by:


   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 (c) 2012, Joyent, Inc. All rights reserved.

  25  */
  26 
  27 #include <sys/dmu_objset.h>
  28 #include <sys/dsl_dataset.h>
  29 #include <sys/dsl_dir.h>
  30 #include <sys/dsl_prop.h>
  31 #include <sys/dsl_synctask.h>
  32 #include <sys/dmu_traverse.h>
  33 #include <sys/dmu_impl.h>
  34 #include <sys/dmu_tx.h>
  35 #include <sys/arc.h>
  36 #include <sys/zio.h>
  37 #include <sys/zap.h>
  38 #include <sys/zfeature.h>
  39 #include <sys/unique.h>
  40 #include <sys/zfs_context.h>
  41 #include <sys/zfs_ioctl.h>
  42 #include <sys/spa.h>
  43 #include <sys/zfs_znode.h>
  44 #include <sys/zfs_onexit.h>


1347 }
1348 
1349 static void
1350 get_clones_stat(dsl_dataset_t *ds, nvlist_t *nv)
1351 {
1352         uint64_t count = 0;
1353         objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset;
1354         zap_cursor_t zc;
1355         zap_attribute_t za;
1356         nvlist_t *propval = fnvlist_alloc();
1357         nvlist_t *val = fnvlist_alloc();
1358 
1359         ASSERT(dsl_pool_config_held(ds->ds_dir->dd_pool));
1360 
1361         /*
1362          * There may be missing entries in ds_next_clones_obj
1363          * due to a bug in a previous version of the code.
1364          * Only trust it if it has the right number of entries.
1365          */
1366         if (ds->ds_phys->ds_next_clones_obj != 0) {
1367                 ASSERT0(zap_count(mos, ds->ds_phys->ds_next_clones_obj,
1368                     &count));
1369         }
1370         if (count != ds->ds_phys->ds_num_children - 1)
1371                 goto fail;
1372         for (zap_cursor_init(&zc, mos, ds->ds_phys->ds_next_clones_obj);
1373             zap_cursor_retrieve(&zc, &za) == 0;
1374             zap_cursor_advance(&zc)) {
1375                 dsl_dataset_t *clone;
1376                 char buf[ZFS_MAXNAMELEN];
1377                 VERIFY0(dsl_dataset_hold_obj(ds->ds_dir->dd_pool,
1378                     za.za_first_integer, FTAG, &clone));
1379                 dsl_dir_name(clone->ds_dir, buf);
1380                 fnvlist_add_boolean(val, buf);
1381                 dsl_dataset_rele(clone, FTAG);
1382         }
1383         zap_cursor_fini(&zc);
1384         fnvlist_add_nvlist(propval, ZPROP_VALUE, val);
1385         fnvlist_add_nvlist(nv, zfs_prop_to_name(ZFS_PROP_CLONES), propval);
1386 fail:
1387         nvlist_free(val);




   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 (c) 2012, Joyent, Inc. All rights reserved.
  25  * Copyright (c) 2014 RackTop Systems.
  26  */
  27 
  28 #include <sys/dmu_objset.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/dmu_traverse.h>
  34 #include <sys/dmu_impl.h>
  35 #include <sys/dmu_tx.h>
  36 #include <sys/arc.h>
  37 #include <sys/zio.h>
  38 #include <sys/zap.h>
  39 #include <sys/zfeature.h>
  40 #include <sys/unique.h>
  41 #include <sys/zfs_context.h>
  42 #include <sys/zfs_ioctl.h>
  43 #include <sys/spa.h>
  44 #include <sys/zfs_znode.h>
  45 #include <sys/zfs_onexit.h>


1348 }
1349 
1350 static void
1351 get_clones_stat(dsl_dataset_t *ds, nvlist_t *nv)
1352 {
1353         uint64_t count = 0;
1354         objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset;
1355         zap_cursor_t zc;
1356         zap_attribute_t za;
1357         nvlist_t *propval = fnvlist_alloc();
1358         nvlist_t *val = fnvlist_alloc();
1359 
1360         ASSERT(dsl_pool_config_held(ds->ds_dir->dd_pool));
1361 
1362         /*
1363          * There may be missing entries in ds_next_clones_obj
1364          * due to a bug in a previous version of the code.
1365          * Only trust it if it has the right number of entries.
1366          */
1367         if (ds->ds_phys->ds_next_clones_obj != 0) {
1368                 VERIFY0(zap_count(mos, ds->ds_phys->ds_next_clones_obj,
1369                     &count));
1370         }
1371         if (count != ds->ds_phys->ds_num_children - 1)
1372                 goto fail;
1373         for (zap_cursor_init(&zc, mos, ds->ds_phys->ds_next_clones_obj);
1374             zap_cursor_retrieve(&zc, &za) == 0;
1375             zap_cursor_advance(&zc)) {
1376                 dsl_dataset_t *clone;
1377                 char buf[ZFS_MAXNAMELEN];
1378                 VERIFY0(dsl_dataset_hold_obj(ds->ds_dir->dd_pool,
1379                     za.za_first_integer, FTAG, &clone));
1380                 dsl_dir_name(clone->ds_dir, buf);
1381                 fnvlist_add_boolean(val, buf);
1382                 dsl_dataset_rele(clone, FTAG);
1383         }
1384         zap_cursor_fini(&zc);
1385         fnvlist_add_nvlist(propval, ZPROP_VALUE, val);
1386         fnvlist_add_nvlist(nv, zfs_prop_to_name(ZFS_PROP_CLONES), propval);
1387 fail:
1388         nvlist_free(val);