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

« back to all changes in this revision

Viewing changes to src/lib/libzpool/bplist.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 2008 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
 
26
26
#include <sys/bplist.h>
27
27
#include <sys/zfs_context.h>
28
28
 
 
29
void
 
30
bplist_init(bplist_t *bpl)
 
31
{
 
32
        bzero(bpl, sizeof (*bpl));
 
33
        mutex_init(&bpl->bpl_lock, NULL, MUTEX_DEFAULT, NULL);
 
34
        mutex_init(&bpl->bpl_q_lock, NULL, MUTEX_DEFAULT, NULL);
 
35
        list_create(&bpl->bpl_queue, sizeof (bplist_q_t),
 
36
            offsetof(bplist_q_t, bpq_node));
 
37
}
 
38
 
 
39
void
 
40
bplist_fini(bplist_t *bpl)
 
41
{
 
42
        ASSERT(list_is_empty(&bpl->bpl_queue));
 
43
        list_destroy(&bpl->bpl_queue);
 
44
        mutex_destroy(&bpl->bpl_q_lock);
 
45
        mutex_destroy(&bpl->bpl_lock);
 
46
}
 
47
 
29
48
static int
30
49
bplist_hold(bplist_t *bpl)
31
50
{
73
92
        ASSERT(bpl->bpl_dbuf == NULL);
74
93
        ASSERT(bpl->bpl_phys == NULL);
75
94
        ASSERT(bpl->bpl_cached_dbuf == NULL);
76
 
        ASSERT(bpl->bpl_queue == NULL);
 
95
        ASSERT(list_is_empty(&bpl->bpl_queue));
77
96
        ASSERT(object != 0);
78
97
        ASSERT3U(doi.doi_type, ==, DMU_OT_BPLIST);
79
98
        ASSERT3U(doi.doi_bonus_type, ==, DMU_OT_BPLIST_HDR);
93
112
{
94
113
        mutex_enter(&bpl->bpl_lock);
95
114
 
96
 
        ASSERT(bpl->bpl_queue == NULL);
 
115
        ASSERT(list_is_empty(&bpl->bpl_queue));
97
116
 
98
117
        if (bpl->bpl_cached_dbuf) {
99
118
                dmu_buf_rele(bpl->bpl_cached_dbuf, bpl);
208
227
        bparray[off].blk_fill = 0;
209
228
 
210
229
        /* The bplist will compress better if we can leave off the checksum */
211
 
        bzero(&bparray[off].blk_cksum, sizeof (bparray[off].blk_cksum));
 
230
        if (!BP_GET_DEDUP(&bparray[off]))
 
231
                bzero(&bparray[off].blk_cksum, sizeof (bparray[off].blk_cksum));
212
232
 
213
233
        dmu_buf_will_dirty(bpl->bpl_dbuf, tx);
214
234
        bpl->bpl_phys->bpl_entries++;
215
235
        bpl->bpl_phys->bpl_bytes +=
216
 
            bp_get_dasize(dmu_objset_spa(bpl->bpl_mos), bp);
 
236
            bp_get_dsize_sync(dmu_objset_spa(bpl->bpl_mos), bp);
217
237
        if (bpl->bpl_havecomp) {
218
238
                bpl->bpl_phys->bpl_comp += BP_GET_PSIZE(bp);
219
239
                bpl->bpl_phys->bpl_uncomp += BP_GET_UCSIZE(bp);
223
243
        return (0);
224
244
}
225
245
 
 
246
void
 
247
bplist_enqueue_cb(void *bpl, const blkptr_t *bp, dmu_tx_t *tx)
 
248
{
 
249
        VERIFY(bplist_enqueue(bpl, bp, tx) == 0);
 
250
}
 
251
 
226
252
/*
227
 
 * Deferred entry; will be written later by bplist_sync().
 
253
 * Deferred entry; will be processed later by bplist_sync().
228
254
 */
229
255
void
230
256
bplist_enqueue_deferred(bplist_t *bpl, const blkptr_t *bp)
232
258
        bplist_q_t *bpq = kmem_alloc(sizeof (*bpq), KM_SLEEP);
233
259
 
234
260
        ASSERT(!BP_IS_HOLE(bp));
235
 
        mutex_enter(&bpl->bpl_lock);
 
261
        mutex_enter(&bpl->bpl_q_lock);
236
262
        bpq->bpq_blk = *bp;
237
 
        bpq->bpq_next = bpl->bpl_queue;
238
 
        bpl->bpl_queue = bpq;
239
 
        mutex_exit(&bpl->bpl_lock);
 
263
        list_insert_tail(&bpl->bpl_queue, bpq);
 
264
        mutex_exit(&bpl->bpl_q_lock);
240
265
}
241
266
 
242
267
void
243
 
bplist_sync(bplist_t *bpl, dmu_tx_t *tx)
 
268
bplist_sync(bplist_t *bpl, bplist_sync_cb_t *func, void *arg, dmu_tx_t *tx)
244
269
{
245
270
        bplist_q_t *bpq;
246
271
 
247
 
        mutex_enter(&bpl->bpl_lock);
248
 
        while ((bpq = bpl->bpl_queue) != NULL) {
249
 
                bpl->bpl_queue = bpq->bpq_next;
250
 
                mutex_exit(&bpl->bpl_lock);
251
 
                VERIFY(0 == bplist_enqueue(bpl, &bpq->bpq_blk, tx));
 
272
        mutex_enter(&bpl->bpl_q_lock);
 
273
        while (bpq = list_head(&bpl->bpl_queue)) {
 
274
                list_remove(&bpl->bpl_queue, bpq);
 
275
                mutex_exit(&bpl->bpl_q_lock);
 
276
                func(arg, &bpq->bpq_blk, tx);
252
277
                kmem_free(bpq, sizeof (*bpq));
253
 
                mutex_enter(&bpl->bpl_lock);
 
278
                mutex_enter(&bpl->bpl_q_lock);
254
279
        }
255
 
        mutex_exit(&bpl->bpl_lock);
 
280
        mutex_exit(&bpl->bpl_q_lock);
256
281
}
257
282
 
258
283
void
259
284
bplist_vacate(bplist_t *bpl, dmu_tx_t *tx)
260
285
{
261
286
        mutex_enter(&bpl->bpl_lock);
262
 
        ASSERT3P(bpl->bpl_queue, ==, NULL);
 
287
        ASSERT(list_is_empty(&bpl->bpl_queue));
263
288
        VERIFY(0 == bplist_hold(bpl));
264
289
        dmu_buf_will_dirty(bpl->bpl_dbuf, tx);
265
290
        VERIFY(0 == dmu_free_range(bpl->bpl_mos,
311
336
}
312
337
 
313
338
/*
314
 
 * Return (in *dasizep) the amount of space on the deadlist which is:
 
339
 * Return (in *dsizep) the amount of space on the deadlist which is:
315
340
 * mintxg < blk_birth <= maxtxg
316
341
 */
317
342
int
318
343
bplist_space_birthrange(bplist_t *bpl, uint64_t mintxg, uint64_t maxtxg,
319
 
    uint64_t *dasizep)
 
344
    uint64_t *dsizep)
320
345
{
321
346
        uint64_t size = 0;
322
347
        uint64_t itor = 0;
331
356
                mutex_enter(&bpl->bpl_lock);
332
357
                err = bplist_hold(bpl);
333
358
                if (err == 0)
334
 
                        *dasizep = bpl->bpl_phys->bpl_bytes;
 
359
                        *dsizep = bpl->bpl_phys->bpl_bytes;
335
360
                mutex_exit(&bpl->bpl_lock);
336
361
                return (err);
337
362
        }
338
363
 
339
364
        while ((err = bplist_iterate(bpl, &itor, &bp)) == 0) {
340
365
                if (bp.blk_birth > mintxg && bp.blk_birth <= maxtxg) {
341
 
                        size +=
342
 
                            bp_get_dasize(dmu_objset_spa(bpl->bpl_mos), &bp);
 
366
                        size += bp_get_dsize(dmu_objset_spa(bpl->bpl_mos), &bp);
343
367
                }
344
368
        }
345
369
        if (err == ENOENT)
346
370
                err = 0;
347
 
        *dasizep = size;
 
371
        *dsizep = size;
348
372
        return (err);
349
373
}