Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TXG timestamp database #16853

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8367,6 +8367,8 @@ zpool_do_reopen(int argc, char **argv)
typedef struct scrub_cbdata {
int cb_type;
pool_scrub_cmd_t cb_scrub_cmd;
time_t cb_date_start;
time_t cb_date_end;
} scrub_cbdata_t;

static boolean_t
Expand Down Expand Up @@ -8410,7 +8412,8 @@ scrub_callback(zpool_handle_t *zhp, void *data)
return (1);
}

err = zpool_scan(zhp, cb->cb_type, cb->cb_scrub_cmd);
err = zpool_scan(zhp, cb->cb_type, cb->cb_scrub_cmd, cb->cb_date_start,
cb->cb_date_end);

if (err == 0 && zpool_has_checkpoint(zhp) &&
cb->cb_type == POOL_SCAN_SCRUB) {
Expand All @@ -8429,10 +8432,32 @@ wait_callback(zpool_handle_t *zhp, void *data)
return (zpool_wait(zhp, *act));
}

static time_t
date_string_to_sec(const char *timestr)
{
int ret;
struct tm tm = {0};

ret = sscanf(timestr, "%4d-%2d-%2d %2d:%2d", &tm.tm_year, &tm.tm_mon,
&tm.tm_mday, &tm.tm_hour, &tm.tm_min);
if (ret < 3) {
fprintf(stderr, gettext("Failed to parse the date.\n"));
usage(B_FALSE);
}

// Adjust struct
tm.tm_year -= 1900;
tm.tm_mon -= 1;

return (timegm(&tm));
Comment on lines +8441 to +8452
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if strptime() or something else specialized would be better.

}

/*
* zpool scrub [-e | -s | -p | -C] [-w] <pool> ...
*
* -e Only scrub blocks in the error log.
* -E End date of scrub.
* -S Start date of scrub.
* -s Stop. Stops any in-progress scrub.
* -p Pause. Pause in-progress scrub.
* -w Wait. Blocks until scrub has completed.
Expand All @@ -8448,21 +8473,28 @@ zpool_do_scrub(int argc, char **argv)

cb.cb_type = POOL_SCAN_SCRUB;
cb.cb_scrub_cmd = POOL_SCRUB_NORMAL;
cb.cb_date_start = cb.cb_date_end = 0;

boolean_t is_error_scrub = B_FALSE;
boolean_t is_pause = B_FALSE;
boolean_t is_stop = B_FALSE;
boolean_t is_txg_continue = B_FALSE;

/* check options */
while ((c = getopt(argc, argv, "spweC")) != -1) {
while ((c = getopt(argc, argv, "spweCE:S:")) != -1) {
switch (c) {
case 'e':
is_error_scrub = B_TRUE;
break;
case 'E':
cb.cb_date_end = date_string_to_sec(optarg);
break;
case 's':
is_stop = B_TRUE;
break;
case 'S':
cb.cb_date_start = date_string_to_sec(optarg);
break;
case 'p':
is_pause = B_TRUE;
break;
Expand Down Expand Up @@ -8510,6 +8542,13 @@ zpool_do_scrub(int argc, char **argv)
}
}

if ((cb.cb_date_start != 0 || cb.cb_date_end != 0) &&
cb.cb_scrub_cmd != POOL_SCRUB_NORMAL) {
(void) fprintf(stderr, gettext("invalid option combination: "
"start/end date is avlilable only with normal scrub\n"));
usage(B_FALSE);
}

if (wait && (cb.cb_type == POOL_SCAN_NONE ||
cb.cb_scrub_cmd == POOL_SCRUB_PAUSE)) {
(void) fprintf(stderr, gettext("invalid option combination: "
Expand Down
1 change: 1 addition & 0 deletions include/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ COMMON_H = \
cityhash.h \
zfeature_common.h \
zfs_comutil.h \
zfs_crrd.h \
zfs_deleg.h \
zfs_fletcher.h \
zfs_namecheck.h \
Expand Down
3 changes: 2 additions & 1 deletion include/libzfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ typedef struct trimflags {
/*
* Functions to manipulate pool and vdev state
*/
_LIBZFS_H int zpool_scan(zpool_handle_t *, pool_scan_func_t, pool_scrub_cmd_t);
_LIBZFS_H int zpool_scan(zpool_handle_t *, pool_scan_func_t, pool_scrub_cmd_t,
time_t, time_t);
_LIBZFS_H int zpool_initialize(zpool_handle_t *, pool_initialize_func_t,
nvlist_t *);
_LIBZFS_H int zpool_initialize_wait(zpool_handle_t *, pool_initialize_func_t,
Expand Down
3 changes: 3 additions & 0 deletions include/sys/dmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ typedef struct dmu_buf {
#define DMU_POOL_ZPOOL_CHECKPOINT "com.delphix:zpool_checkpoint"
#define DMU_POOL_LOG_SPACEMAP_ZAP "com.delphix:log_spacemap_zap"
#define DMU_POOL_DELETED_CLONES "com.delphix:deleted_clones"
#define DMU_POOL_TXG_LOG_TIME_MINUTES "com.klaraystems:txg_log_time:minutes"
#define DMU_POOL_TXG_LOG_TIME_DAYS "com.klaraystems:txg_log_time:days"
#define DMU_POOL_TXG_LOG_TIME_MONTHS "com.klaraystems:txg_log_time:months"

/*
* Allocate an object from this objset. The range of object numbers
Expand Down
8 changes: 8 additions & 0 deletions include/sys/spa_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
#include <sys/dsl_deadlist.h>
#include <zfeature_common.h>

#include "zfs_crrd.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -353,6 +355,12 @@ struct spa {
spa_checkpoint_info_t spa_checkpoint_info; /* checkpoint accounting */
zthr_t *spa_checkpoint_discard_zthr;

kmutex_t spa_txg_log_time_lock; /* for spa_txg_log_time */
dbrrd_t spa_txg_log_time;
uint64_t spa_last_noted_txg;
uint64_t spa_last_noted_txg_time;
uint64_t spa_last_flush_txg_time;

space_map_t *spa_syncing_log_sm; /* current log space map */
avl_tree_t spa_sm_logs_by_txg;
kmutex_t spa_flushed_ms_lock; /* for metaslabs_by_flushed */
Expand Down
1 change: 1 addition & 0 deletions include/zfeature_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ typedef enum spa_feature {
SPA_FEATURE_FAST_DEDUP,
SPA_FEATURE_LONGNAME,
SPA_FEATURE_LARGE_MICROZAP,
SPA_FEATURE_TXG_TIMELOG,
SPA_FEATURES
} spa_feature_t;

Expand Down
67 changes: 67 additions & 0 deletions include/zfs_crrd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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) 2024 Klara Inc.
*
* This software was developed by
* Fred Weigel <[email protected]>
* Mariusz Zaborski <[email protected]>
* under sponsorship from Wasabi Technology, Inc. and Klara Inc.
*/

#ifndef _CRRD_H_
#define _CRRD_H_

#define RRD_MAX_ENTRIES 256

typedef struct {
hrtime_t rrdd_time;
uint64_t rrdd_txg;
} rrd_data_t;

typedef struct {
int rrd_head; /* head (beginning) */
int rrd_tail; /* tail (end) */
size_t rrd_length;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why length is size_t, while head/tail are int. They all address the same array and limited by RRD_MAX_ENTRIES. Plus you are writing these data directly to pool, while int and size_t (and might be hrtime_t?) might have different sizes on different platforms.


rrd_data_t rrd_entries[RRD_MAX_ENTRIES];
} rrd_t;

typedef struct {
rrd_t dbr_minutes;
rrd_t dbr_days;
rrd_t dbr_months;
} dbrrd_t;

rrd_t *rrd_create(void);
size_t rrd_len(rrd_t *rrd);

const rrd_data_t *rrd_entry(rrd_t *r, size_t i);
const rrd_data_t *rrd_tail_entry(rrd_t *rrd);
uint64_t rrd_tail(rrd_t *rrd);
uint64_t rrd_get(rrd_t *rrd, size_t i);

void rrd_add(rrd_t *rrd, hrtime_t time, uint64_t txg);

void dbrrd_add(dbrrd_t *db, hrtime_t time, uint64_t txg);
uint64_t dbrrd_query(dbrrd_t *r, hrtime_t tv);

#endif
5 changes: 5 additions & 0 deletions lib/libnvpair/libnvpair.abi
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,7 @@
</data-member>
</class-decl>
<typedef-decl name='stack_t' type-id='380f9954' id='ac5e685f'/>
<typedef-decl name='unw_regnum_t' type-id='95e97e5e' id='c53620f0'/>
<class-decl name='unw_cursor' size-in-bits='8128' is-struct='yes' visibility='default' id='384a1f22'>
<data-member access='public' layout-offset-in-bits='0'>
<var-decl name='opaque' type-id='dc70ec0b' visibility='default'/>
Expand Down Expand Up @@ -2306,6 +2307,10 @@
<parameter type-id='b59d7dce'/>
<return type-id='79a0948f'/>
</function-decl>
<function-decl name='_Ux86_64_regname' visibility='default' binding='global' size-in-bits='64'>
<parameter type-id='c53620f0'/>
<return type-id='80f4b756'/>
</function-decl>
<function-decl name='_ULx86_64_init_local' visibility='default' binding='global' size-in-bits='64'>
<parameter type-id='3946e4d1'/>
<parameter type-id='2e408b96'/>
Expand Down
5 changes: 5 additions & 0 deletions lib/libuutil/libuutil.abi
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@
</data-member>
</class-decl>
<typedef-decl name='stack_t' type-id='380f9954' id='ac5e685f'/>
<typedef-decl name='unw_regnum_t' type-id='95e97e5e' id='c53620f0'/>
<class-decl name='unw_cursor' size-in-bits='8128' is-struct='yes' visibility='default' id='384a1f22'>
<data-member access='public' layout-offset-in-bits='0'>
<var-decl name='opaque' type-id='dc70ec0b' visibility='default'/>
Expand Down Expand Up @@ -763,6 +764,10 @@
<parameter type-id='b59d7dce'/>
<return type-id='79a0948f'/>
</function-decl>
<function-decl name='_Ux86_64_regname' visibility='default' binding='global' size-in-bits='64'>
<parameter type-id='c53620f0'/>
<return type-id='80f4b756'/>
</function-decl>
<function-decl name='_ULx86_64_init_local' visibility='default' binding='global' size-in-bits='64'>
<parameter type-id='3946e4d1'/>
<parameter type-id='2e408b96'/>
Expand Down
23 changes: 18 additions & 5 deletions lib/libzfs/libzfs.abi
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@
<elf-symbol name='fletcher_4_superscalar_ops' size='128' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='libzfs_config_ops' size='16' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='sa_protocol_names' size='16' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='spa_feature_table' size='2464' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='spa_feature_table' size='2520' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='zfeature_checks_disable' size='4' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='zfs_deleg_perm_tab' size='512' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='zfs_history_event_names' size='328' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
Expand Down Expand Up @@ -1170,6 +1170,7 @@
</data-member>
</class-decl>
<typedef-decl name='stack_t' type-id='380f9954' id='ac5e685f'/>
<typedef-decl name='unw_regnum_t' type-id='95e97e5e' id='c53620f0'/>
<class-decl name='unw_cursor' size-in-bits='8128' is-struct='yes' visibility='default' id='384a1f22'>
<data-member access='public' layout-offset-in-bits='0'>
<var-decl name='opaque' type-id='dc70ec0b' visibility='default'/>
Expand Down Expand Up @@ -1275,6 +1276,10 @@
<pointer-type-def type-id='1203d35c' size-in-bits='64' id='3946e4d1'/>
<pointer-type-def type-id='190d09ef' size-in-bits='64' id='3e0601f0'/>
<pointer-type-def type-id='73d941c6' size-in-bits='64' id='42f5faab'/>
<function-decl name='_Ux86_64_regname' visibility='default' binding='global' size-in-bits='64'>
<parameter type-id='c53620f0'/>
<return type-id='80f4b756'/>
</function-decl>
<function-decl name='_ULx86_64_init_local' visibility='default' binding='global' size-in-bits='64'>
<parameter type-id='3946e4d1'/>
<parameter type-id='2e408b96'/>
Expand Down Expand Up @@ -6197,7 +6202,8 @@
<enumerator name='SPA_FEATURE_FAST_DEDUP' value='41'/>
<enumerator name='SPA_FEATURE_LONGNAME' value='42'/>
<enumerator name='SPA_FEATURE_LARGE_MICROZAP' value='43'/>
<enumerator name='SPA_FEATURES' value='44'/>
<enumerator name='SPA_FEATURE_TXG_TIMELOG' value='44'/>
<enumerator name='SPA_FEATURES' value='45'/>
</enum-decl>
<typedef-decl name='spa_feature_t' type-id='33ecb627' id='d6618c78'/>
<qualified-type-def type-id='80f4b756' const='yes' id='b99c00c9'/>
Expand Down Expand Up @@ -6720,6 +6726,8 @@
<parameter type-id='4c81de99' name='zhp'/>
<parameter type-id='7313fbe2' name='func'/>
<parameter type-id='b51cf3c2' name='cmd'/>
<parameter type-id='c9d12d66' name='date_start'/>
<parameter type-id='c9d12d66' name='date_end'/>
<return type-id='95e97e5e'/>
</function-decl>
<function-decl name='zpool_find_vdev_by_physpath' mangled-name='zpool_find_vdev_by_physpath' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='zpool_find_vdev_by_physpath'>
Expand Down Expand Up @@ -8368,6 +8376,11 @@
<parameter type-id='95e97e5e'/>
<return type-id='48b5725f'/>
</function-decl>
<function-decl name='setpgid' visibility='default' binding='global' size-in-bits='64'>
<parameter type-id='3629bad8'/>
<parameter type-id='3629bad8'/>
<return type-id='95e97e5e'/>
</function-decl>
<function-decl name='fork' visibility='default' binding='global' size-in-bits='64'>
<return type-id='3629bad8'/>
</function-decl>
Expand Down Expand Up @@ -9376,8 +9389,8 @@
</function-decl>
</abi-instr>
<abi-instr address-size='64' path='module/zcommon/zfeature_common.c' language='LANG_C99'>
<array-type-def dimensions='1' type-id='83f29ca2' size-in-bits='19712' id='fd4573e5'>
<subrange length='44' type-id='7359adad' id='cf8ba455'/>
<array-type-def dimensions='1' type-id='83f29ca2' size-in-bits='20160' id='b948da70'>
<subrange length='45' type-id='7359adad' id='cb8ddca0'/>
</array-type-def>
<enum-decl name='zfeature_flags' id='6db816a4'>
<underlying-type type-id='9cac1fee'/>
Expand Down Expand Up @@ -9454,7 +9467,7 @@
<pointer-type-def type-id='611586a1' size-in-bits='64' id='2e243169'/>
<qualified-type-def type-id='eaa32e2f' const='yes' id='83be723c'/>
<pointer-type-def type-id='83be723c' size-in-bits='64' id='7acd98a2'/>
<var-decl name='spa_feature_table' type-id='fd4573e5' mangled-name='spa_feature_table' visibility='default' elf-symbol-id='spa_feature_table'/>
<var-decl name='spa_feature_table' type-id='b948da70' mangled-name='spa_feature_table' visibility='default' elf-symbol-id='spa_feature_table'/>
<var-decl name='zfeature_checks_disable' type-id='c19b74c3' mangled-name='zfeature_checks_disable' visibility='default' elf-symbol-id='zfeature_checks_disable'/>
<function-decl name='opendir' visibility='default' binding='global' size-in-bits='64'>
<parameter type-id='80f4b756'/>
Expand Down
5 changes: 4 additions & 1 deletion lib/libzfs/libzfs_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -2728,7 +2728,8 @@ zpool_trim(zpool_handle_t *zhp, pool_trim_func_t cmd_type, nvlist_t *vds,
* Scan the pool.
*/
int
zpool_scan(zpool_handle_t *zhp, pool_scan_func_t func, pool_scrub_cmd_t cmd)
zpool_scan(zpool_handle_t *zhp, pool_scan_func_t func, pool_scrub_cmd_t cmd,
time_t date_start, time_t date_end)
{
char errbuf[ERRBUFLEN];
int err;
Expand All @@ -2737,6 +2738,8 @@ zpool_scan(zpool_handle_t *zhp, pool_scan_func_t func, pool_scrub_cmd_t cmd)
nvlist_t *args = fnvlist_alloc();
fnvlist_add_uint64(args, "scan_type", (uint64_t)func);
fnvlist_add_uint64(args, "scan_command", (uint64_t)cmd);
fnvlist_add_uint64(args, "scan_date_start", (uint64_t)date_start);
fnvlist_add_uint64(args, "scan_date_end", (uint64_t)date_end);

err = lzc_scrub(ZFS_IOC_POOL_SCRUB, zhp->zpool_name, args, NULL);
fnvlist_free(args);
Expand Down
5 changes: 5 additions & 0 deletions lib/libzfs_core/libzfs_core.abi
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@
</data-member>
</class-decl>
<typedef-decl name='stack_t' type-id='380f9954' id='ac5e685f'/>
<typedef-decl name='unw_regnum_t' type-id='95e97e5e' id='c53620f0'/>
<class-decl name='unw_cursor' size-in-bits='8128' is-struct='yes' visibility='default' id='384a1f22'>
<data-member access='public' layout-offset-in-bits='0'>
<var-decl name='opaque' type-id='dc70ec0b' visibility='default'/>
Expand Down Expand Up @@ -762,6 +763,10 @@
<parameter type-id='b59d7dce'/>
<return type-id='79a0948f'/>
</function-decl>
<function-decl name='_Ux86_64_regname' visibility='default' binding='global' size-in-bits='64'>
<parameter type-id='c53620f0'/>
<return type-id='80f4b756'/>
</function-decl>
<function-decl name='_ULx86_64_init_local' visibility='default' binding='global' size-in-bits='64'>
<parameter type-id='3946e4d1'/>
<parameter type-id='2e408b96'/>
Expand Down
2 changes: 1 addition & 1 deletion lib/libzfsbootenv/libzfsbootenv.abi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<abi-corpus version='2.0' architecture='elf-amd-x86_64' soname='libzfsbootenv.so.1'>
<elf-needed>
<dependency name='libzfs.so.4'/>
<dependency name='libzfs.so.6'/>
<dependency name='libnvpair.so.3'/>
<dependency name='libc.so.6'/>
</elf-needed>
Expand Down
1 change: 1 addition & 0 deletions lib/libzpool/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ nodist_libzpool_la_SOURCES = \
module/zfs/zfeature.c \
module/zfs/zfs_byteswap.c \
module/zfs/zfs_chksum.c \
module/zfs/zfs_crrd.c \
module/zfs/zfs_fm.c \
module/zfs/zfs_fuid.c \
module/zfs/zfs_ratelimit.c \
Expand Down
Loading
Loading