FreeBSD ZFS
The Zettabyte File System
|
00001 /* 00002 * CDDL HEADER START 00003 * 00004 * The contents of this file are subject to the terms of the 00005 * Common Development and Distribution License (the "License"). 00006 * You may not use this file except in compliance with the License. 00007 * 00008 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 00009 * or http://www.opensolaris.org/os/licensing. 00010 * See the License for the specific language governing permissions 00011 * and limitations under the License. 00012 * 00013 * When distributing Covered Code, include this CDDL HEADER in each 00014 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 00015 * If applicable, add the following below this CDDL HEADER, with the 00016 * fields enclosed by brackets "[]" replaced with your own identifying 00017 * information: Portions Copyright [yyyy] [name of copyright owner] 00018 * 00019 * CDDL HEADER END 00020 */ 00021 /* 00022 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 00023 */ 00024 00025 #include <sys/bplist.h> 00026 #include <sys/zfs_context.h> 00027 00028 00029 void 00030 bplist_create(bplist_t *bpl) 00031 { 00032 mutex_init(&bpl->bpl_lock, NULL, MUTEX_DEFAULT, NULL); 00033 list_create(&bpl->bpl_list, sizeof (bplist_entry_t), 00034 offsetof(bplist_entry_t, bpe_node)); 00035 } 00036 00037 void 00038 bplist_destroy(bplist_t *bpl) 00039 { 00040 list_destroy(&bpl->bpl_list); 00041 mutex_destroy(&bpl->bpl_lock); 00042 } 00043 00044 void 00045 bplist_append(bplist_t *bpl, const blkptr_t *bp) 00046 { 00047 bplist_entry_t *bpe = kmem_alloc(sizeof (*bpe), KM_SLEEP); 00048 00049 mutex_enter(&bpl->bpl_lock); 00050 bpe->bpe_blk = *bp; 00051 list_insert_tail(&bpl->bpl_list, bpe); 00052 mutex_exit(&bpl->bpl_lock); 00053 } 00054 00055 void 00056 bplist_iterate(bplist_t *bpl, bplist_itor_t *func, void *arg, dmu_tx_t *tx) 00057 { 00058 bplist_entry_t *bpe; 00059 00060 mutex_enter(&bpl->bpl_lock); 00061 while (bpe = list_head(&bpl->bpl_list)) { 00062 list_remove(&bpl->bpl_list, bpe); 00063 mutex_exit(&bpl->bpl_lock); 00064 func(arg, &bpe->bpe_blk, tx); 00065 kmem_free(bpe, sizeof (*bpe)); 00066 mutex_enter(&bpl->bpl_lock); 00067 } 00068 mutex_exit(&bpl->bpl_lock); 00069 }