ddt: split internal DDT API into separate header

Just to make it easier to know which bits to pay attention to.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Sponsored-by: Klara, Inc.
Sponsored-by: iXsystems, Inc.
Closes #15887
This commit is contained in:
Rob Norris 2023-06-30 13:35:18 +10:00 committed by Brian Behlendorf
parent 909006049f
commit 8e414fcdf4
7 changed files with 99 additions and 53 deletions

View File

@ -74,6 +74,7 @@
#include <sys/arc.h> #include <sys/arc.h>
#include <sys/arc_impl.h> #include <sys/arc_impl.h>
#include <sys/ddt.h> #include <sys/ddt.h>
#include <sys/ddt_impl.h>
#include <sys/zfeature.h> #include <sys/zfeature.h>
#include <sys/abd.h> #include <sys/abd.h>
#include <sys/blkptr.h> #include <sys/blkptr.h>

View File

@ -37,6 +37,7 @@ COMMON_H = \
sys/dataset_kstats.h \ sys/dataset_kstats.h \
sys/dbuf.h \ sys/dbuf.h \
sys/ddt.h \ sys/ddt.h \
sys/ddt_impl.h \
sys/dmu.h \ sys/dmu.h \
sys/dmu_impl.h \ sys/dmu_impl.h \
sys/dmu_objset.h \ sys/dmu_objset.h \

View File

@ -152,57 +152,16 @@ typedef struct ddt_bookmark {
uint64_t ddb_cursor; uint64_t ddb_cursor;
} ddt_bookmark_t; } ddt_bookmark_t;
/*
* Ops vector to access a specific DDT object type.
*/
typedef struct ddt_ops {
char ddt_op_name[32];
int (*ddt_op_create)(objset_t *os, uint64_t *object, dmu_tx_t *tx,
boolean_t prehash);
int (*ddt_op_destroy)(objset_t *os, uint64_t object, dmu_tx_t *tx);
int (*ddt_op_lookup)(objset_t *os, uint64_t object, ddt_entry_t *dde);
void (*ddt_op_prefetch)(objset_t *os, uint64_t object,
ddt_entry_t *dde);
int (*ddt_op_update)(objset_t *os, uint64_t object, ddt_entry_t *dde,
dmu_tx_t *tx);
int (*ddt_op_remove)(objset_t *os, uint64_t object, ddt_entry_t *dde,
dmu_tx_t *tx);
int (*ddt_op_walk)(objset_t *os, uint64_t object, ddt_entry_t *dde,
uint64_t *walk);
int (*ddt_op_count)(objset_t *os, uint64_t object, uint64_t *count);
} ddt_ops_t;
#define DDT_NAMELEN 107
extern void ddt_object_name(ddt_t *ddt, enum ddt_type type,
enum ddt_class clazz, char *name);
extern int ddt_object_walk(ddt_t *ddt, enum ddt_type type,
enum ddt_class clazz, uint64_t *walk, ddt_entry_t *dde);
extern int ddt_object_count(ddt_t *ddt, enum ddt_type type,
enum ddt_class clazz, uint64_t *count);
extern int ddt_object_info(ddt_t *ddt, enum ddt_type type,
enum ddt_class clazz, dmu_object_info_t *);
extern boolean_t ddt_object_exists(ddt_t *ddt, enum ddt_type type,
enum ddt_class clazz);
extern void ddt_bp_fill(const ddt_phys_t *ddp, blkptr_t *bp, extern void ddt_bp_fill(const ddt_phys_t *ddp, blkptr_t *bp,
uint64_t txg); uint64_t txg);
extern void ddt_bp_create(enum zio_checksum checksum, const ddt_key_t *ddk, extern void ddt_bp_create(enum zio_checksum checksum, const ddt_key_t *ddk,
const ddt_phys_t *ddp, blkptr_t *bp); const ddt_phys_t *ddp, blkptr_t *bp);
extern void ddt_key_fill(ddt_key_t *ddk, const blkptr_t *bp);
extern void ddt_phys_fill(ddt_phys_t *ddp, const blkptr_t *bp); extern void ddt_phys_fill(ddt_phys_t *ddp, const blkptr_t *bp);
extern void ddt_phys_clear(ddt_phys_t *ddp); extern void ddt_phys_clear(ddt_phys_t *ddp);
extern void ddt_phys_addref(ddt_phys_t *ddp); extern void ddt_phys_addref(ddt_phys_t *ddp);
extern void ddt_phys_decref(ddt_phys_t *ddp); extern void ddt_phys_decref(ddt_phys_t *ddp);
extern void ddt_phys_free(ddt_t *ddt, ddt_key_t *ddk, ddt_phys_t *ddp,
uint64_t txg);
extern ddt_phys_t *ddt_phys_select(const ddt_entry_t *dde, const blkptr_t *bp); extern ddt_phys_t *ddt_phys_select(const ddt_entry_t *dde, const blkptr_t *bp);
extern uint64_t ddt_phys_total_refcnt(const ddt_entry_t *dde);
extern void ddt_stat_update(ddt_t *ddt, ddt_entry_t *dde, uint64_t neg);
extern void ddt_stat_add(ddt_stat_t *dst, const ddt_stat_t *src, uint64_t neg);
extern void ddt_histogram_add(ddt_histogram_t *dst, const ddt_histogram_t *src); extern void ddt_histogram_add(ddt_histogram_t *dst, const ddt_histogram_t *src);
extern void ddt_histogram_stat(ddt_stat_t *dds, const ddt_histogram_t *ddh); extern void ddt_histogram_stat(ddt_stat_t *dds, const ddt_histogram_t *ddh);
@ -236,13 +195,9 @@ extern int ddt_load(spa_t *spa);
extern void ddt_unload(spa_t *spa); extern void ddt_unload(spa_t *spa);
extern void ddt_sync(spa_t *spa, uint64_t txg); extern void ddt_sync(spa_t *spa, uint64_t txg);
extern int ddt_walk(spa_t *spa, ddt_bookmark_t *ddb, ddt_entry_t *dde); extern int ddt_walk(spa_t *spa, ddt_bookmark_t *ddb, ddt_entry_t *dde);
extern int ddt_object_update(ddt_t *ddt, enum ddt_type type,
enum ddt_class clazz, ddt_entry_t *dde, dmu_tx_t *tx);
extern boolean_t ddt_addref(spa_t *spa, const blkptr_t *bp); extern boolean_t ddt_addref(spa_t *spa, const blkptr_t *bp);
extern const ddt_ops_t ddt_zap_ops;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

86
include/sys/ddt_impl.h Normal file
View File

@ -0,0 +1,86 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016 by Delphix. All rights reserved.
* Copyright (c) 2023, Klara Inc.
*/
#ifndef _SYS_DDT_IMPL_H
#define _SYS_DDT_IMPL_H
#include <sys/ddt.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Ops vector to access a specific DDT object type.
*/
typedef struct ddt_ops {
char ddt_op_name[32];
int (*ddt_op_create)(objset_t *os, uint64_t *object, dmu_tx_t *tx,
boolean_t prehash);
int (*ddt_op_destroy)(objset_t *os, uint64_t object, dmu_tx_t *tx);
int (*ddt_op_lookup)(objset_t *os, uint64_t object, ddt_entry_t *dde);
void (*ddt_op_prefetch)(objset_t *os, uint64_t object,
ddt_entry_t *dde);
int (*ddt_op_update)(objset_t *os, uint64_t object, ddt_entry_t *dde,
dmu_tx_t *tx);
int (*ddt_op_remove)(objset_t *os, uint64_t object, ddt_entry_t *dde,
dmu_tx_t *tx);
int (*ddt_op_walk)(objset_t *os, uint64_t object, ddt_entry_t *dde,
uint64_t *walk);
int (*ddt_op_count)(objset_t *os, uint64_t object, uint64_t *count);
} ddt_ops_t;
extern const ddt_ops_t ddt_zap_ops;
extern void ddt_stat_update(ddt_t *ddt, ddt_entry_t *dde, uint64_t neg);
/*
* These are only exposed so that zdb can access them. Try not to use them
* outside of the DDT implementation proper, and if you do, consider moving
* them up.
*/
#define DDT_NAMELEN 107
extern uint64_t ddt_phys_total_refcnt(const ddt_entry_t *dde);
extern void ddt_key_fill(ddt_key_t *ddk, const blkptr_t *bp);
extern void ddt_stat_add(ddt_stat_t *dst, const ddt_stat_t *src, uint64_t neg);
extern void ddt_object_name(ddt_t *ddt, enum ddt_type type,
enum ddt_class clazz, char *name);
extern int ddt_object_walk(ddt_t *ddt, enum ddt_type type,
enum ddt_class clazz, uint64_t *walk, ddt_entry_t *dde);
extern int ddt_object_count(ddt_t *ddt, enum ddt_type type,
enum ddt_class clazz, uint64_t *count);
extern int ddt_object_info(ddt_t *ddt, enum ddt_type type,
enum ddt_class clazz, dmu_object_info_t *);
#ifdef __cplusplus
}
#endif
#endif /* _SYS_DDT_H */

View File

@ -30,6 +30,7 @@
#include <sys/spa_impl.h> #include <sys/spa_impl.h>
#include <sys/zio.h> #include <sys/zio.h>
#include <sys/ddt.h> #include <sys/ddt.h>
#include <sys/ddt_impl.h>
#include <sys/zap.h> #include <sys/zap.h>
#include <sys/dmu_tx.h> #include <sys/dmu_tx.h>
#include <sys/arc.h> #include <sys/arc.h>
@ -171,6 +172,12 @@ ddt_object_sync(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
ddo->ddo_mspace = doi.doi_fill_count * doi.doi_data_block_size; ddo->ddo_mspace = doi.doi_fill_count * doi.doi_data_block_size;
} }
static boolean_t
ddt_object_exists(ddt_t *ddt, enum ddt_type type, enum ddt_class class)
{
return (!!ddt->ddt_object[type][class]);
}
static int static int
ddt_object_lookup(ddt_t *ddt, enum ddt_type type, enum ddt_class class, ddt_object_lookup(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
ddt_entry_t *dde) ddt_entry_t *dde)
@ -193,7 +200,7 @@ ddt_object_prefetch(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
ddt->ddt_object[type][class], dde); ddt->ddt_object[type][class], dde);
} }
int static int
ddt_object_update(ddt_t *ddt, enum ddt_type type, enum ddt_class class, ddt_object_update(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
ddt_entry_t *dde, dmu_tx_t *tx) ddt_entry_t *dde, dmu_tx_t *tx)
{ {
@ -244,12 +251,6 @@ ddt_object_info(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
doi)); doi));
} }
boolean_t
ddt_object_exists(ddt_t *ddt, enum ddt_type type, enum ddt_class class)
{
return (!!ddt->ddt_object[type][class]);
}
void void
ddt_object_name(ddt_t *ddt, enum ddt_type type, enum ddt_class class, ddt_object_name(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
char *name) char *name)
@ -341,7 +342,7 @@ ddt_phys_decref(ddt_phys_t *ddp)
} }
} }
void static void
ddt_phys_free(ddt_t *ddt, ddt_key_t *ddk, ddt_phys_t *ddp, uint64_t txg) ddt_phys_free(ddt_t *ddt, ddt_key_t *ddk, ddt_phys_t *ddp, uint64_t txg)
{ {
blkptr_t blk; blkptr_t blk;

View File

@ -30,6 +30,7 @@
#include <sys/spa.h> #include <sys/spa.h>
#include <sys/spa_impl.h> #include <sys/spa_impl.h>
#include <sys/ddt.h> #include <sys/ddt.h>
#include <sys/ddt_impl.h>
static void static void
ddt_stat_generate(ddt_t *ddt, ddt_entry_t *dde, ddt_stat_t *dds) ddt_stat_generate(ddt_t *ddt, ddt_entry_t *dde, ddt_stat_t *dds)

View File

@ -28,6 +28,7 @@
#include <sys/spa.h> #include <sys/spa.h>
#include <sys/zio.h> #include <sys/zio.h>
#include <sys/ddt.h> #include <sys/ddt.h>
#include <sys/ddt_impl.h>
#include <sys/zap.h> #include <sys/zap.h>
#include <sys/dmu_tx.h> #include <sys/dmu_tx.h>
#include <sys/zio_compress.h> #include <sys/zio_compress.h>