Path: blob/main/sys/contrib/openzfs/tests/unit/mock_dmu.h
289174 views
// SPDX-License-Identifier: CDDL-1.01/*2* This file and its contents are supplied under the terms of the3* Common Development and Distribution License ("CDDL"), version 1.0.4* You may only use this file in accordance with the terms of version5* 1.0 of the CDDL.6*7* A full copy of the text of the CDDL should have accompanied this8* source. A copy of the CDDL is also available via the Internet at9* http://www.illumos.org/license/CDDL.10*/1112/*13* Copyright (c) 2026, TrueNAS.14*/1516#ifndef _MOCK_DMU_H17#define _MOCK_DMU_H1819/*20* In-memory mock of the core DMU types for unit testing.21*22* Provides mock_dnode_t carrying a flat array of fixed-size blocks.23*/2425#include <sys/types.h>2627typedef struct mock_dnode mock_dnode_t;28typedef struct mock_dmu_tx mock_dmu_tx_t;2930/* Create a mock dnode with the given block size and object type. */31mock_dnode_t *mock_dnode_create(size_t blksize, dmu_object_type_t type);3233/* Free a mock dnode and all its blocks. */34void mock_dnode_destroy(mock_dnode_t *mdn);3536/* Returns the current number of blocks underlying this dnode. */37size_t mock_dnode_block_count(mock_dnode_t *mdn);3839/* Returns a pointer to the data under the given block id. */40const void *mock_dnode_block_data(mock_dnode_t *mdn, uint64_t blkid);4142/* Returns the current dnode ref (hold) count. */43uint64_t mock_dnode_refcount(mock_dnode_t *mdn);4445/* Create/destroy a mock transaction handle. */46mock_dmu_tx_t *mock_tx_create(void);47void mock_tx_destroy(mock_dmu_tx_t *tx);4849#endif /* _MOCK_DMU_H */505152