~ubuntu-branches/ubuntu/quantal/zfs-fuse/quantal

« back to all changes in this revision

Viewing changes to src/lib/libzpool/spa_misc.c

  • Committer: Bazaar Package Importer
  • Author(s): Mike Hommey, Mike Hommey, Seth Heeren
  • Date: 2010-06-30 18:03:52 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100630180352-d3jq25ytbcl23q3y
Tags: 0.6.9-1
* New upstream release.

[ Mike Hommey ]
* debian/control:
  - Build depend on libssl-dev and libattr1-dev, now required to build.
  - Build depend on docbook-xml to avoid xsltproc I/O error loading
    docbook DTD.
  - Add suggestions for a NFS server and kpartx.
* debian/man/*, debian/copyright, debian/rules: Remove manual pages, they
  are now shipped upstream.
* debian/copyright: Change download link.
* src/SConstruct:
  - Add an optim option to the build system.
  - Add support for DESTDIR.
  - Force debug=1 to mean optim, no strip, no debug.
  - Use -ffunction-sections, -fdata-sections, and --gc-sections flags to
    reduce the binary sizes.
* src/lib/libumem/SConscript: Cleanup src/lib/libumem when cleaning up
  build directory.
* src/cmd/*/SConscript: Don't link zfs, zpool and zdb against libssl.
* src/lib/libumem/SConscript: Only build static libumem.
* src/lib/libumem/sol_compat.h:
  - Add atomic cas support for sparc.
  - Use atomic functions from libsolcompat in libumem on unsupported
    platforms.
* debian/rules:
  - Set optimization level in build system according to DEB_BUILD_OPTIONS.
  - Build with debug=1 to have unstripped binaries ; dh_strip will do the
    right thing.
  - Don't depend on the local location of the docbook XSLT stylesheets.
    Use the catalogged url in place of the full path.
  - Don't clean src/.sconsign.dblite and src/path.pyc.
  - Set all destination directories when installing with scons.
  - Install bash completion and zfsrc files.
  - Don't use scons cache when building.
* debian/prerm: Remove /var/lib/zfs/zpool.cache in prerm.
* debian/dirs: Create /etc/bash_completion.d.
* debian/watch: Fix watch file.
* debian/rules, debian/control, debian/compat: Switch to dh.
* debian/README.Debian: Update README.Debian.
* debian/zfs-fuse.man.xml: Update zfs-fuse manual page.
* debian/zfs-fuse.init: Start sharing datasets marked as such at daemon
  startup.
* debian/rules, debian/control: Use config.guess and config.sub from
  autotools-dev.

[ Seth Heeren ]
* debian/zfs-fuse.man.xml:
  Added notes on the precedence, zfsrc, commandline, initscript vs.
  /etc/default/zfs-fuse on some systems.
* debian/zfs-fuse.init, debian/zfs-fuse.default: Deprecating DAEMON_OPTS.
* debian/zfs-fuse.init:
  - Removing import -a -f.
  - Removing the now unnecessary 'sleep 2'.
  - Extended shutdown wait to allow for zfs-fuse daemon's own shutdown
    timeouts.
  - Re-ordered dubious PATH setting.
* debian/zfs-fuse.init: Move existing zpool.cache to new location if
  possible.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 * CDDL HEADER END
20
20
 */
21
21
/*
22
 
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 
22
 * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23
23
 * Use is subject to license terms.
24
24
 */
25
25
 
43
43
#include <sys/dsl_prop.h>
44
44
#include <sys/fs/zfs.h>
45
45
#include <sys/metaslab_impl.h>
46
 
#include <sys/sunddi.h>
47
46
#include <sys/arc.h>
 
47
#include <sys/ddt.h>
48
48
#include "zfs_prop.h"
49
49
 
50
50
/*
186
186
 *
187
187
 * SCL_VDEV
188
188
 *      Held as reader to prevent changes to the vdev tree during trivial
189
 
 *      inquiries such as bp_get_dasize().  SCL_VDEV is distinct from the
 
189
 *      inquiries such as bp_get_dsize().  SCL_VDEV is distinct from the
190
190
 *      other locks, and lower than all of them, to ensure that it's safe
191
191
 *      to acquire regardless of caller context.
192
192
 *
314
314
void
315
315
spa_config_enter(spa_t *spa, int locks, void *tag, krw_t rw)
316
316
{
 
317
        int wlocks_held = 0;
 
318
 
317
319
        for (int i = 0; i < SCL_LOCKS; i++) {
318
320
                spa_config_lock_t *scl = &spa->spa_config_lock[i];
 
321
                if (scl->scl_writer == curthread)
 
322
                        wlocks_held |= (1 << i);
319
323
                if (!(locks & (1 << i)))
320
324
                        continue;
321
325
                mutex_enter(&scl->scl_lock);
335
339
                (void) refcount_add(&scl->scl_count, tag);
336
340
                mutex_exit(&scl->scl_lock);
337
341
        }
 
342
        ASSERT(wlocks_held <= locks);
338
343
}
339
344
 
340
345
void
419
424
 * exist by calling spa_lookup() first.
420
425
 */
421
426
spa_t *
422
 
spa_add(const char *name, const char *altroot)
 
427
spa_add(const char *name, nvlist_t *config, const char *altroot)
423
428
{
424
429
        spa_t *spa;
425
430
        spa_config_dirent_t *dp;
432
437
        mutex_init(&spa->spa_scrub_lock, NULL, MUTEX_DEFAULT, NULL);
433
438
        mutex_init(&spa->spa_errlog_lock, NULL, MUTEX_DEFAULT, NULL);
434
439
        mutex_init(&spa->spa_errlist_lock, NULL, MUTEX_DEFAULT, NULL);
435
 
        mutex_init(&spa->spa_sync_bplist.bpl_lock, NULL, MUTEX_DEFAULT, NULL);
436
440
        mutex_init(&spa->spa_history_lock, NULL, MUTEX_DEFAULT, NULL);
437
441
        mutex_init(&spa->spa_props_lock, NULL, MUTEX_DEFAULT, NULL);
 
442
        mutex_init(&spa->spa_suspend_lock, NULL, MUTEX_DEFAULT, NULL);
 
443
        mutex_init(&spa->spa_vdev_top_lock, NULL, MUTEX_DEFAULT, NULL);
438
444
 
439
445
        cv_init(&spa->spa_async_cv, NULL, CV_DEFAULT, NULL);
440
446
        cv_init(&spa->spa_scrub_io_cv, NULL, CV_DEFAULT, NULL);
441
447
        cv_init(&spa->spa_suspend_cv, NULL, CV_DEFAULT, NULL);
442
448
 
 
449
        for (int t = 0; t < TXG_SIZE; t++)
 
450
                bplist_init(&spa->spa_free_bplist[t]);
 
451
        bplist_init(&spa->spa_deferred_bplist);
 
452
 
443
453
        (void) strlcpy(spa->spa_name, name, sizeof (spa->spa_name));
444
454
        spa->spa_state = POOL_STATE_UNINITIALIZED;
445
455
        spa->spa_freeze_txg = UINT64_MAX;
446
456
        spa->spa_final_txg = UINT64_MAX;
 
457
        spa->spa_load_max_txg = UINT64_MAX;
447
458
 
448
459
        refcount_create(&spa->spa_refcount);
449
460
        spa_config_lock_init(spa);
450
461
 
451
462
        avl_add(&spa_namespace_avl, spa);
452
463
 
453
 
        mutex_init(&spa->spa_suspend_lock, NULL, MUTEX_DEFAULT, NULL);
454
 
 
455
464
        /*
456
465
         * Set the alternate root, if there is one.
457
466
         */
467
476
            offsetof(spa_config_dirent_t, scd_link));
468
477
 
469
478
        dp = kmem_zalloc(sizeof (spa_config_dirent_t), KM_SLEEP);
470
 
        dp->scd_path = spa_strdup(spa_config_path);
 
479
        dp->scd_path = altroot ? NULL : spa_strdup(spa_config_path);
471
480
        list_insert_head(&spa->spa_config_list, dp);
472
481
 
 
482
        if (config != NULL)
 
483
                VERIFY(nvlist_dup(config, &spa->spa_config, 0) == 0);
 
484
 
473
485
        return (spa);
474
486
}
475
487
 
486
498
        ASSERT(MUTEX_HELD(&spa_namespace_lock));
487
499
        ASSERT(spa->spa_state == POOL_STATE_UNINITIALIZED);
488
500
 
 
501
        nvlist_free(spa->spa_config_splitting);
 
502
 
489
503
        avl_remove(&spa_namespace_avl, spa);
490
504
        cv_broadcast(&spa_namespace_cv);
491
505
 
509
523
 
510
524
        spa_config_lock_destroy(spa);
511
525
 
 
526
        for (int t = 0; t < TXG_SIZE; t++)
 
527
                bplist_fini(&spa->spa_free_bplist[t]);
 
528
        bplist_fini(&spa->spa_deferred_bplist);
 
529
 
512
530
        cv_destroy(&spa->spa_async_cv);
513
531
        cv_destroy(&spa->spa_scrub_io_cv);
514
532
        cv_destroy(&spa->spa_suspend_cv);
517
535
        mutex_destroy(&spa->spa_scrub_lock);
518
536
        mutex_destroy(&spa->spa_errlog_lock);
519
537
        mutex_destroy(&spa->spa_errlist_lock);
520
 
        mutex_destroy(&spa->spa_sync_bplist.bpl_lock);
521
538
        mutex_destroy(&spa->spa_history_lock);
522
539
        mutex_destroy(&spa->spa_props_lock);
523
540
        mutex_destroy(&spa->spa_suspend_lock);
 
541
        mutex_destroy(&spa->spa_vdev_top_lock);
524
542
 
525
543
        kmem_free(spa, sizeof (spa_t));
526
544
}
814
832
        mutex_exit(&spa_l2cache_lock);
815
833
}
816
834
 
817
 
void
818
 
spa_l2cache_space_update(vdev_t *vd, int64_t space, int64_t alloc)
819
 
{
820
 
        vdev_space_update(vd, space, alloc, B_FALSE);
821
 
}
822
 
 
823
835
/*
824
836
 * ==========================================================================
825
837
 * SPA vdev locking
834
846
uint64_t
835
847
spa_vdev_enter(spa_t *spa)
836
848
{
 
849
        mutex_enter(&spa->spa_vdev_top_lock);
837
850
        mutex_enter(&spa_namespace_lock);
 
851
        return (spa_vdev_config_enter(spa));
 
852
}
 
853
 
 
854
/*
 
855
 * Internal implementation for spa_vdev_enter().  Used when a vdev
 
856
 * operation requires multiple syncs (i.e. removing a device) while
 
857
 * keeping the spa_namespace_lock held.
 
858
 */
 
859
uint64_t
 
860
spa_vdev_config_enter(spa_t *spa)
 
861
{
 
862
        ASSERT(MUTEX_HELD(&spa_namespace_lock));
838
863
 
839
864
        spa_config_enter(spa, SCL_ALL, spa, RW_WRITER);
840
865
 
842
867
}
843
868
 
844
869
/*
845
 
 * Unlock the spa_t after adding or removing a vdev.  Besides undoing the
846
 
 * locking of spa_vdev_enter(), we also want make sure the transactions have
847
 
 * synced to disk, and then update the global configuration cache with the new
848
 
 * information.
 
870
 * Used in combination with spa_vdev_config_enter() to allow the syncing
 
871
 * of multiple transactions without releasing the spa_namespace_lock.
849
872
 */
850
 
int
851
 
spa_vdev_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error)
 
873
void
 
874
spa_vdev_config_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error, char *tag)
852
875
{
 
876
        ASSERT(MUTEX_HELD(&spa_namespace_lock));
 
877
 
853
878
        int config_changed = B_FALSE;
854
879
 
855
880
        ASSERT(txg > spa_last_synced_txg(spa));
867
892
        if (error == 0 && !list_is_empty(&spa->spa_config_dirty_list)) {
868
893
                dsl_pool_scrub_restart(spa->spa_dsl_pool);
869
894
                config_changed = B_TRUE;
 
895
                spa->spa_config_generation++;
870
896
        }
871
897
 
 
898
        /*
 
899
         * Verify the metaslab classes.
 
900
         */
 
901
        ASSERT(metaslab_class_validate(spa_normal_class(spa)) == 0);
 
902
        ASSERT(metaslab_class_validate(spa_log_class(spa)) == 0);
 
903
 
872
904
        spa_config_exit(spa, SCL_ALL, spa);
873
905
 
874
906
        /*
 
907
         * Panic the system if the specified tag requires it.  This
 
908
         * is useful for ensuring that configurations are updated
 
909
         * transactionally.
 
910
         */
 
911
        if (zio_injection_enabled)
 
912
                zio_handle_panic_injection(spa, tag, 0);
 
913
 
 
914
        /*
875
915
         * Note: this txg_wait_synced() is important because it ensures
876
916
         * that there won't be more than one config change per txg.
877
917
         * This allows us to use the txg as the generation number.
891
931
         */
892
932
        if (config_changed)
893
933
                spa_config_sync(spa, B_FALSE, B_TRUE);
 
934
}
894
935
 
 
936
/*
 
937
 * Unlock the spa_t after adding or removing a vdev.  Besides undoing the
 
938
 * locking of spa_vdev_enter(), we also want make sure the transactions have
 
939
 * synced to disk, and then update the global configuration cache with the new
 
940
 * information.
 
941
 */
 
942
int
 
943
spa_vdev_exit(spa_t *spa, vdev_t *vd, uint64_t txg, int error)
 
944
{
 
945
        spa_vdev_config_exit(spa, vd, txg, error, FTAG);
895
946
        mutex_exit(&spa_namespace_lock);
 
947
        mutex_exit(&spa->spa_vdev_top_lock);
896
948
 
897
949
        return (error);
898
950
}
901
953
 * Lock the given spa_t for the purpose of changing vdev state.
902
954
 */
903
955
void
904
 
spa_vdev_state_enter(spa_t *spa)
 
956
spa_vdev_state_enter(spa_t *spa, int oplocks)
905
957
{
906
 
        spa_config_enter(spa, SCL_STATE_ALL, spa, RW_WRITER);
 
958
        int locks = SCL_STATE_ALL | oplocks;
 
959
 
 
960
        spa_config_enter(spa, locks, spa, RW_WRITER);
 
961
        spa->spa_vdev_locks = locks;
907
962
}
908
963
 
909
964
int
910
965
spa_vdev_state_exit(spa_t *spa, vdev_t *vd, int error)
911
966
{
912
 
        if (vd != NULL)
 
967
        boolean_t config_changed = B_FALSE;
 
968
 
 
969
        if (vd != NULL || error == 0)
 
970
                vdev_dtl_reassess(vd ? vd->vdev_top : spa->spa_root_vdev,
 
971
                    0, 0, B_FALSE);
 
972
 
 
973
        if (vd != NULL) {
913
974
                vdev_state_dirty(vd->vdev_top);
 
975
                config_changed = B_TRUE;
 
976
                spa->spa_config_generation++;
 
977
        }
914
978
 
915
 
        spa_config_exit(spa, SCL_STATE_ALL, spa);
 
979
        ASSERT3U(spa->spa_vdev_locks, >=, SCL_STATE_ALL);
 
980
        spa_config_exit(spa, spa->spa_vdev_locks, spa);
916
981
 
917
982
        /*
918
983
         * If anything changed, wait for it to sync.  This ensures that,
923
988
        if (vd != NULL)
924
989
                txg_wait_synced(spa->spa_dsl_pool, 0);
925
990
 
 
991
        /*
 
992
         * If the config changed, update the config cache.
 
993
         */
 
994
        if (config_changed) {
 
995
                mutex_enter(&spa_namespace_lock);
 
996
                spa_config_sync(spa, B_FALSE, B_TRUE);
 
997
                mutex_exit(&spa_namespace_lock);
 
998
        }
 
999
 
926
1000
        return (error);
927
1001
}
928
1002
 
1055
1129
        return (r % range);
1056
1130
}
1057
1131
 
 
1132
uint64_t
 
1133
spa_generate_guid(spa_t *spa)
 
1134
{
 
1135
        uint64_t guid = spa_get_random(-1ULL);
 
1136
 
 
1137
        if (spa != NULL) {
 
1138
                while (guid == 0 || spa_guid_exists(spa_guid(spa), guid))
 
1139
                        guid = spa_get_random(-1ULL);
 
1140
        } else {
 
1141
                while (guid == 0 || spa_guid_exists(guid, 0))
 
1142
                        guid = spa_get_random(-1ULL);
 
1143
        }
 
1144
 
 
1145
        return (guid);
 
1146
}
 
1147
 
1058
1148
void
1059
 
sprintf_blkptr(char *buf, int len, const blkptr_t *bp)
 
1149
sprintf_blkptr(char *buf, const blkptr_t *bp)
1060
1150
{
1061
 
        int d;
1062
 
 
1063
 
        if (bp == NULL) {
1064
 
                (void) snprintf(buf, len, "<NULL>");
1065
 
                return;
1066
 
        }
1067
 
 
1068
 
        if (BP_IS_HOLE(bp)) {
1069
 
                (void) snprintf(buf, len, "<hole>");
1070
 
                return;
1071
 
        }
1072
 
 
1073
 
        (void) snprintf(buf, len, "[L%llu %s] %llxL/%llxP ",
1074
 
            (u_longlong_t)BP_GET_LEVEL(bp),
1075
 
            dmu_ot[BP_GET_TYPE(bp)].ot_name,
1076
 
            (u_longlong_t)BP_GET_LSIZE(bp),
1077
 
            (u_longlong_t)BP_GET_PSIZE(bp));
1078
 
 
1079
 
        for (d = 0; d < BP_GET_NDVAS(bp); d++) {
1080
 
                const dva_t *dva = &bp->blk_dva[d];
1081
 
                (void) snprintf(buf + strlen(buf), len - strlen(buf),
1082
 
                    "DVA[%d]=<%llu:%llx:%llx> ", d,
1083
 
                    (u_longlong_t)DVA_GET_VDEV(dva),
1084
 
                    (u_longlong_t)DVA_GET_OFFSET(dva),
1085
 
                    (u_longlong_t)DVA_GET_ASIZE(dva));
1086
 
        }
1087
 
 
1088
 
        (void) snprintf(buf + strlen(buf), len - strlen(buf),
1089
 
            "%s %s %s %s birth=%llu fill=%llu cksum=%llx:%llx:%llx:%llx",
1090
 
            zio_checksum_table[BP_GET_CHECKSUM(bp)].ci_name,
1091
 
            zio_compress_table[BP_GET_COMPRESS(bp)].ci_name,
1092
 
            BP_GET_BYTEORDER(bp) == 0 ? "BE" : "LE",
1093
 
            BP_IS_GANG(bp) ? "gang" : "contiguous",
1094
 
            (u_longlong_t)bp->blk_birth,
1095
 
            (u_longlong_t)bp->blk_fill,
1096
 
            (u_longlong_t)bp->blk_cksum.zc_word[0],
1097
 
            (u_longlong_t)bp->blk_cksum.zc_word[1],
1098
 
            (u_longlong_t)bp->blk_cksum.zc_word[2],
1099
 
            (u_longlong_t)bp->blk_cksum.zc_word[3]);
 
1151
        char *type = NULL;
 
1152
        char *checksum = NULL;
 
1153
        char *compress = NULL;
 
1154
 
 
1155
        if (bp != NULL) {
 
1156
                type = dmu_ot[BP_GET_TYPE(bp)].ot_name;
 
1157
                checksum = zio_checksum_table[BP_GET_CHECKSUM(bp)].ci_name;
 
1158
                compress = zio_compress_table[BP_GET_COMPRESS(bp)].ci_name;
 
1159
        }
 
1160
 
 
1161
        SPRINTF_BLKPTR(snprintf, ' ', buf, bp, type, checksum, compress);
1100
1162
}
1101
1163
 
1102
1164
void
1202
1264
        return (spa->spa_first_txg);
1203
1265
}
1204
1266
 
 
1267
uint64_t
 
1268
spa_syncing_txg(spa_t *spa)
 
1269
{
 
1270
        return (spa->spa_syncing_txg);
 
1271
}
 
1272
 
1205
1273
pool_state_t
1206
1274
spa_state(spa_t *spa)
1207
1275
{
1208
1276
        return (spa->spa_state);
1209
1277
}
1210
1278
 
 
1279
spa_load_state_t
 
1280
spa_load_state(spa_t *spa)
 
1281
{
 
1282
        return (spa->spa_load_state);
 
1283
}
 
1284
 
1211
1285
uint64_t
1212
1286
spa_freeze_txg(spa_t *spa)
1213
1287
{
1214
1288
        return (spa->spa_freeze_txg);
1215
1289
}
1216
1290
 
1217
 
/*
1218
 
 * Return how much space is allocated in the pool (ie. sum of all asize)
1219
 
 */
1220
 
uint64_t
1221
 
spa_get_alloc(spa_t *spa)
1222
 
{
1223
 
        return (spa->spa_root_vdev->vdev_stat.vs_alloc);
1224
 
}
1225
 
 
1226
 
/*
1227
 
 * Return how much (raid-z inflated) space there is in the pool.
1228
 
 */
1229
 
uint64_t
1230
 
spa_get_space(spa_t *spa)
1231
 
{
1232
 
        return (spa->spa_root_vdev->vdev_stat.vs_space);
1233
 
}
1234
 
 
1235
 
/*
1236
 
 * Return the amount of raid-z-deflated space in the pool.
1237
 
 */
1238
 
uint64_t
1239
 
spa_get_dspace(spa_t *spa)
1240
 
{
1241
 
        if (spa->spa_deflate)
1242
 
                return (spa->spa_root_vdev->vdev_stat.vs_dspace);
1243
 
        else
1244
 
                return (spa->spa_root_vdev->vdev_stat.vs_space);
1245
 
}
1246
 
 
1247
1291
/* ARGSUSED */
1248
1292
uint64_t
1249
1293
spa_get_asize(spa_t *spa, uint64_t lsize)
1250
1294
{
1251
1295
        /*
1252
 
         * For now, the worst case is 512-byte RAID-Z blocks, in which
1253
 
         * case the space requirement is exactly 2x; so just assume that.
1254
 
         * Add to this the fact that we can have up to 3 DVAs per bp, and
1255
 
         * we have to multiply by a total of 6x.
 
1296
         * The worst case is single-sector max-parity RAID-Z blocks, in which
 
1297
         * case the space requirement is exactly (VDEV_RAIDZ_MAXPARITY + 1)
 
1298
         * times the size; so just assume that.  Add to this the fact that
 
1299
         * we can have up to 3 DVAs per bp, and one more factor of 2 because
 
1300
         * the block may be dittoed with up to 3 DVAs by ddt_sync().
1256
1301
         */
1257
 
        return (lsize * 6);
 
1302
        return (lsize * (VDEV_RAIDZ_MAXPARITY + 1) * SPA_DVAS_PER_BP * 2);
 
1303
}
 
1304
 
 
1305
uint64_t
 
1306
spa_get_dspace(spa_t *spa)
 
1307
{
 
1308
        return (spa->spa_dspace);
 
1309
}
 
1310
 
 
1311
void
 
1312
spa_update_dspace(spa_t *spa)
 
1313
{
 
1314
        spa->spa_dspace = metaslab_class_get_dspace(spa_normal_class(spa)) +
 
1315
            ddt_get_dedup_dspace(spa);
1258
1316
}
1259
1317
 
1260
1318
/*
1279
1337
        return (spa->spa_ubsync.ub_version);
1280
1338
}
1281
1339
 
 
1340
boolean_t
 
1341
spa_deflate(spa_t *spa)
 
1342
{
 
1343
        return (spa->spa_deflate);
 
1344
}
 
1345
 
 
1346
metaslab_class_t *
 
1347
spa_normal_class(spa_t *spa)
 
1348
{
 
1349
        return (spa->spa_normal_class);
 
1350
}
 
1351
 
 
1352
metaslab_class_t *
 
1353
spa_log_class(spa_t *spa)
 
1354
{
 
1355
        return (spa->spa_log_class);
 
1356
}
 
1357
 
1282
1358
int
1283
1359
spa_max_replication(spa_t *spa)
1284
1360
{
1293
1369
}
1294
1370
 
1295
1371
uint64_t
1296
 
bp_get_dasize(spa_t *spa, const blkptr_t *bp)
1297
 
{
1298
 
        int sz = 0, i;
1299
 
 
1300
 
        if (!spa->spa_deflate)
1301
 
                return (BP_GET_ASIZE(bp));
 
1372
dva_get_dsize_sync(spa_t *spa, const dva_t *dva)
 
1373
{
 
1374
        uint64_t asize = DVA_GET_ASIZE(dva);
 
1375
        uint64_t dsize = asize;
 
1376
 
 
1377
        ASSERT(spa_config_held(spa, SCL_ALL, RW_READER) != 0);
 
1378
 
 
1379
        if (asize != 0 && spa->spa_deflate) {
 
1380
                vdev_t *vd = vdev_lookup_top(spa, DVA_GET_VDEV(dva));
 
1381
                dsize = (asize >> SPA_MINBLOCKSHIFT) * vd->vdev_deflate_ratio;
 
1382
        }
 
1383
 
 
1384
        return (dsize);
 
1385
}
 
1386
 
 
1387
uint64_t
 
1388
bp_get_dsize_sync(spa_t *spa, const blkptr_t *bp)
 
1389
{
 
1390
        uint64_t dsize = 0;
 
1391
 
 
1392
        for (int d = 0; d < SPA_DVAS_PER_BP; d++)
 
1393
                dsize += dva_get_dsize_sync(spa, &bp->blk_dva[d]);
 
1394
 
 
1395
        return (dsize);
 
1396
}
 
1397
 
 
1398
uint64_t
 
1399
bp_get_dsize(spa_t *spa, const blkptr_t *bp)
 
1400
{
 
1401
        uint64_t dsize = 0;
1302
1402
 
1303
1403
        spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
1304
 
        for (i = 0; i < SPA_DVAS_PER_BP; i++) {
1305
 
                vdev_t *vd =
1306
 
                    vdev_lookup_top(spa, DVA_GET_VDEV(&bp->blk_dva[i]));
1307
 
                if (vd)
1308
 
                        sz += (DVA_GET_ASIZE(&bp->blk_dva[i]) >>
1309
 
                            SPA_MINBLOCKSHIFT) * vd->vdev_deflate_ratio;
1310
 
        }
 
1404
 
 
1405
        for (int d = 0; d < SPA_DVAS_PER_BP; d++)
 
1406
                dsize += dva_get_dsize_sync(spa, &bp->blk_dva[d]);
 
1407
 
1311
1408
        spa_config_exit(spa, SCL_VDEV, FTAG);
1312
 
        return (sz);
 
1409
 
 
1410
        return (dsize);
1313
1411
}
1314
1412
 
1315
1413
/*
1411
1509
        return (spa->spa_log_class->mc_rotor != NULL);
1412
1510
}
1413
1511
 
1414
 
/*
1415
 
 * Return whether this pool is the root pool.
1416
 
 */
 
1512
spa_log_state_t
 
1513
spa_get_log_state(spa_t *spa)
 
1514
{
 
1515
        return (spa->spa_log_state);
 
1516
}
 
1517
 
 
1518
void
 
1519
spa_set_log_state(spa_t *spa, spa_log_state_t state)
 
1520
{
 
1521
        spa->spa_log_state = state;
 
1522
}
 
1523
 
1417
1524
boolean_t
1418
1525
spa_is_root(spa_t *spa)
1419
1526
{
1431
1538
{
1432
1539
        return (spa->spa_mode);
1433
1540
}
 
1541
 
 
1542
uint64_t
 
1543
spa_bootfs(spa_t *spa)
 
1544
{
 
1545
        return (spa->spa_bootfs);
 
1546
}
 
1547
 
 
1548
uint64_t
 
1549
spa_delegation(spa_t *spa)
 
1550
{
 
1551
        return (spa->spa_delegation);
 
1552
}
 
1553
 
 
1554
objset_t *
 
1555
spa_meta_objset(spa_t *spa)
 
1556
{
 
1557
        return (spa->spa_meta_objset);
 
1558
}
 
1559
 
 
1560
enum zio_checksum
 
1561
spa_dedup_checksum(spa_t *spa)
 
1562
{
 
1563
        return (spa->spa_dedup_checksum);
 
1564
}