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

« back to all changes in this revision

Viewing changes to src/lib/libzpool/spa_config.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:
20
20
 */
21
21
 
22
22
/*
23
 
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 
23
 * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24
24
 * Use is subject to license terms.
25
25
 */
26
26
 
75
75
        void *buf = NULL;
76
76
        nvlist_t *nvlist, *child;
77
77
        nvpair_t *nvpair;
78
 
        spa_t *spa;
79
78
        char *pathname;
80
79
        struct _buf *file;
81
80
        uint64_t fsize;
119
118
        mutex_enter(&spa_namespace_lock);
120
119
        nvpair = NULL;
121
120
        while ((nvpair = nvlist_next_nvpair(nvlist, nvpair)) != NULL) {
122
 
 
123
121
                if (nvpair_type(nvpair) != DATA_TYPE_NVLIST)
124
122
                        continue;
125
123
 
127
125
 
128
126
                if (spa_lookup(nvpair_name(nvpair)) != NULL)
129
127
                        continue;
130
 
                spa = spa_add(nvpair_name(nvpair), NULL);
131
 
 
132
 
                /*
133
 
                 * We blindly duplicate the configuration here.  If it's
134
 
                 * invalid, we will catch it when the pool is first opened.
135
 
                 */
136
 
                VERIFY(nvlist_dup(child, &spa->spa_config, 0) == 0);
 
128
                (void) spa_add(nvpair_name(nvpair), child, NULL);
137
129
        }
138
130
        mutex_exit(&spa_namespace_lock);
139
131
 
209
201
 
210
202
        ASSERT(MUTEX_HELD(&spa_namespace_lock));
211
203
 
212
 
        if (rootdir == NULL)
 
204
        if (rootdir == NULL || !(spa_mode_global & FWRITE))
213
205
                return;
214
206
 
215
207
        /*
313
305
        mutex_exit(&spa->spa_props_lock);
314
306
}
315
307
 
 
308
/* Add discovered rewind info, if any to the provided nvlist */
 
309
void
 
310
spa_rewind_data_to_nvlist(spa_t *spa, nvlist_t *tonvl)
 
311
{
 
312
        int64_t loss = 0;
 
313
 
 
314
        if (tonvl == NULL || spa->spa_load_txg == 0)
 
315
                return;
 
316
 
 
317
        VERIFY(nvlist_add_uint64(tonvl, ZPOOL_CONFIG_LOAD_TIME,
 
318
            spa->spa_load_txg_ts) == 0);
 
319
        if (spa->spa_last_ubsync_txg)
 
320
                loss = spa->spa_last_ubsync_txg_ts - spa->spa_load_txg_ts;
 
321
        VERIFY(nvlist_add_int64(tonvl, ZPOOL_CONFIG_REWIND_TIME, loss) == 0);
 
322
        VERIFY(nvlist_add_uint64(tonvl, ZPOOL_CONFIG_LOAD_DATA_ERRORS,
 
323
            spa->spa_load_data_errors) == 0);
 
324
}
 
325
 
316
326
/*
317
327
 * Generate the pool's configuration based on the current in-core state.
318
328
 * We infer whether to generate a complete config or just one top-level config
325
335
        vdev_t *rvd = spa->spa_root_vdev;
326
336
        unsigned long hostid = 0;
327
337
        boolean_t locked = B_FALSE;
 
338
        uint64_t split_guid;
328
339
 
329
340
        if (vd == NULL) {
330
341
                vd = rvd;
378
389
                        VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_IS_LOG,
379
390
                            1ULL) == 0);
380
391
                vd = vd->vdev_top;              /* label contains top config */
 
392
        } else {
 
393
                /*
 
394
                 * Only add the (potentially large) split information
 
395
                 * in the mos config, and not in the vdev labels
 
396
                 */
 
397
                if (spa->spa_config_splitting != NULL)
 
398
                        VERIFY(nvlist_add_nvlist(config, ZPOOL_CONFIG_SPLIT,
 
399
                            spa->spa_config_splitting) == 0);
 
400
        }
 
401
 
 
402
        /*
 
403
         * Add the top-level config.  We even add this on pools which
 
404
         * don't support holes in the namespace as older pools will
 
405
         * just ignore it.
 
406
         */
 
407
        vdev_top_config_generate(spa, config);
 
408
 
 
409
        /*
 
410
         * If we're splitting, record the original pool's guid.
 
411
         */
 
412
        if (spa->spa_config_splitting != NULL &&
 
413
            nvlist_lookup_uint64(spa->spa_config_splitting,
 
414
            ZPOOL_CONFIG_SPLIT_GUID, &split_guid) == 0) {
 
415
                VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_SPLIT_GUID,
 
416
                    split_guid) == 0);
381
417
        }
382
418
 
383
419
        nvroot = vdev_config_generate(spa, vd, getstats, B_FALSE, B_FALSE);
384
420
        VERIFY(nvlist_add_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, nvroot) == 0);
385
421
        nvlist_free(nvroot);
386
422
 
 
423
        if (getstats && spa_load_state(spa) == SPA_LOAD_NONE) {
 
424
                ddt_histogram_t *ddh;
 
425
                ddt_stat_t *dds;
 
426
                ddt_object_t *ddo;
 
427
 
 
428
                ddh = kmem_zalloc(sizeof (ddt_histogram_t), KM_SLEEP);
 
429
                ddt_get_dedup_histogram(spa, ddh);
 
430
                VERIFY(nvlist_add_uint64_array(config,
 
431
                    ZPOOL_CONFIG_DDT_HISTOGRAM,
 
432
                    (uint64_t *)ddh, sizeof (*ddh) / sizeof (uint64_t)) == 0);
 
433
                kmem_free(ddh, sizeof (ddt_histogram_t));
 
434
 
 
435
                ddo = kmem_zalloc(sizeof (ddt_object_t), KM_SLEEP);
 
436
                ddt_get_dedup_object_stats(spa, ddo);
 
437
                VERIFY(nvlist_add_uint64_array(config,
 
438
                    ZPOOL_CONFIG_DDT_OBJ_STATS,
 
439
                    (uint64_t *)ddo, sizeof (*ddo) / sizeof (uint64_t)) == 0);
 
440
                kmem_free(ddo, sizeof (ddt_object_t));
 
441
 
 
442
                dds = kmem_zalloc(sizeof (ddt_stat_t), KM_SLEEP);
 
443
                ddt_get_dedup_stats(spa, dds);
 
444
                VERIFY(nvlist_add_uint64_array(config,
 
445
                    ZPOOL_CONFIG_DDT_STATS,
 
446
                    (uint64_t *)dds, sizeof (*dds) / sizeof (uint64_t)) == 0);
 
447
                kmem_free(dds, sizeof (ddt_stat_t));
 
448
        }
 
449
 
 
450
        spa_rewind_data_to_nvlist(spa, config);
 
451
 
387
452
        if (locked)
388
453
                spa_config_exit(spa, SCL_CONFIG | SCL_STATE, FTAG);
389
454
 
391
456
}
392
457
 
393
458
/*
394
 
 * For a pool that's not currently a booting rootpool, update all disk labels,
395
 
 * generate a fresh config based on the current in-core state, and sync the
396
 
 * global config cache.
397
 
 */
398
 
void
399
 
spa_config_update(spa_t *spa, int what)
400
 
{
401
 
        spa_config_update_common(spa, what, FALSE);
402
 
}
403
 
 
404
 
/*
405
459
 * Update all disk labels, generate a fresh config based on the current
406
460
 * in-core state, and sync the global config cache (do not sync the config
407
461
 * cache if this is a booting rootpool).
408
462
 */
409
463
void
410
 
spa_config_update_common(spa_t *spa, int what, boolean_t isroot)
 
464
spa_config_update(spa_t *spa, int what)
411
465
{
412
466
        vdev_t *rvd = spa->spa_root_vdev;
413
467
        uint64_t txg;
429
483
                 */
430
484
                for (c = 0; c < rvd->vdev_children; c++) {
431
485
                        vdev_t *tvd = rvd->vdev_child[c];
432
 
                        if (tvd->vdev_ms_array == 0) {
433
 
                                vdev_init(tvd, txg);
434
 
                                vdev_config_dirty(tvd);
435
 
                        }
 
486
                        if (tvd->vdev_ms_array == 0)
 
487
                                vdev_metaslab_set_size(tvd);
 
488
                        vdev_expand(tvd, txg);
436
489
                }
437
490
        }
438
491
        spa_config_exit(spa, SCL_ALL, FTAG);
445
498
        /*
446
499
         * Update the global config cache to reflect the new mosconfig.
447
500
         */
448
 
        if (!isroot)
 
501
        if (!spa->spa_is_root)
449
502
                spa_config_sync(spa, B_FALSE, what != SPA_CONFIG_UPDATE_POOL);
450
503
 
451
504
        if (what == SPA_CONFIG_UPDATE_POOL)
452
 
                spa_config_update_common(spa, SPA_CONFIG_UPDATE_VDEVS, isroot);
 
505
                spa_config_update(spa, SPA_CONFIG_UPDATE_VDEVS);
453
506
}