mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-25 03:37:45 +03:00
OpenZFS 8063 - verify that we do not attempt to access inactive txg
Authored by: Matthew Ahrens <mahrens@delphix.com> Reviewed by: Serapheim Dimitropoulos <serapheim@delphix.com> Reviewed by: Pavel Zakharov <pavel.zakharov@delphix.com> Approved by: Robert Mustacchi <rm@joyent.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Ported-by: George Melikov <mail@gmelikov.ru> A standard practice in ZFS is to keep track of "per-txg" state. Any of the 3 active TXG's (open, quiescing, syncing) can have different values for this state. We should assert that we do not attempt to modify other (inactive) TXG's. Porting Notes: - ASSERTV added to txg_sync_waiting() for unused variable. OpenZFS-issue: https://www.illumos.org/issues/8063 OpenZFS-commit: https://github.com/openzfs/openzfs/commit/01acb46 Closes #6109
This commit is contained in:
committed by
Brian Behlendorf
parent
335b251ac1
commit
4747a7d3d4
+27
-2
@@ -21,7 +21,7 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* Portions Copyright 2011 Martin Matuska
|
||||
* Copyright (c) 2012, 2014 by Delphix. All rights reserved.
|
||||
* Copyright (c) 2012, 2017 by Delphix. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <sys/zfs_context.h>
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <sys/dmu_tx.h>
|
||||
#include <sys/dsl_pool.h>
|
||||
#include <sys/dsl_scan.h>
|
||||
#include <sys/zil.h>
|
||||
#include <sys/callb.h>
|
||||
#include <sys/trace_txg.h>
|
||||
|
||||
@@ -722,17 +723,33 @@ txg_sync_waiting(dsl_pool_t *dp)
|
||||
tx->tx_quiesced_txg != 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify that this txg is active (open, quiescing, syncing). Non-active
|
||||
* txg's should not be manipulated.
|
||||
*/
|
||||
void
|
||||
txg_verify(spa_t *spa, uint64_t txg)
|
||||
{
|
||||
ASSERTV(dsl_pool_t *dp = spa_get_dsl(spa));
|
||||
if (txg <= TXG_INITIAL || txg == ZILTEST_TXG)
|
||||
return;
|
||||
ASSERT3U(txg, <=, dp->dp_tx.tx_open_txg);
|
||||
ASSERT3U(txg, >=, dp->dp_tx.tx_synced_txg);
|
||||
ASSERT3U(txg, >=, dp->dp_tx.tx_open_txg - TXG_CONCURRENT_STATES);
|
||||
}
|
||||
|
||||
/*
|
||||
* Per-txg object lists.
|
||||
*/
|
||||
void
|
||||
txg_list_create(txg_list_t *tl, size_t offset)
|
||||
txg_list_create(txg_list_t *tl, spa_t *spa, size_t offset)
|
||||
{
|
||||
int t;
|
||||
|
||||
mutex_init(&tl->tl_lock, NULL, MUTEX_DEFAULT, NULL);
|
||||
|
||||
tl->tl_offset = offset;
|
||||
tl->tl_spa = spa;
|
||||
|
||||
for (t = 0; t < TXG_SIZE; t++)
|
||||
tl->tl_head[t] = NULL;
|
||||
@@ -752,6 +769,7 @@ txg_list_destroy(txg_list_t *tl)
|
||||
boolean_t
|
||||
txg_list_empty(txg_list_t *tl, uint64_t txg)
|
||||
{
|
||||
txg_verify(tl->tl_spa, txg);
|
||||
return (tl->tl_head[txg & TXG_MASK] == NULL);
|
||||
}
|
||||
|
||||
@@ -786,6 +804,7 @@ txg_list_add(txg_list_t *tl, void *p, uint64_t txg)
|
||||
txg_node_t *tn = (txg_node_t *)((char *)p + tl->tl_offset);
|
||||
boolean_t add;
|
||||
|
||||
txg_verify(tl->tl_spa, txg);
|
||||
mutex_enter(&tl->tl_lock);
|
||||
add = (tn->tn_member[t] == 0);
|
||||
if (add) {
|
||||
@@ -810,6 +829,7 @@ txg_list_add_tail(txg_list_t *tl, void *p, uint64_t txg)
|
||||
txg_node_t *tn = (txg_node_t *)((char *)p + tl->tl_offset);
|
||||
boolean_t add;
|
||||
|
||||
txg_verify(tl->tl_spa, txg);
|
||||
mutex_enter(&tl->tl_lock);
|
||||
add = (tn->tn_member[t] == 0);
|
||||
if (add) {
|
||||
@@ -837,6 +857,7 @@ txg_list_remove(txg_list_t *tl, uint64_t txg)
|
||||
txg_node_t *tn;
|
||||
void *p = NULL;
|
||||
|
||||
txg_verify(tl->tl_spa, txg);
|
||||
mutex_enter(&tl->tl_lock);
|
||||
if ((tn = tl->tl_head[t]) != NULL) {
|
||||
p = (char *)tn - tl->tl_offset;
|
||||
@@ -858,6 +879,7 @@ txg_list_remove_this(txg_list_t *tl, void *p, uint64_t txg)
|
||||
int t = txg & TXG_MASK;
|
||||
txg_node_t *tn, **tp;
|
||||
|
||||
txg_verify(tl->tl_spa, txg);
|
||||
mutex_enter(&tl->tl_lock);
|
||||
|
||||
for (tp = &tl->tl_head[t]; (tn = *tp) != NULL; tp = &tn->tn_next[t]) {
|
||||
@@ -881,6 +903,7 @@ txg_list_member(txg_list_t *tl, void *p, uint64_t txg)
|
||||
int t = txg & TXG_MASK;
|
||||
txg_node_t *tn = (txg_node_t *)((char *)p + tl->tl_offset);
|
||||
|
||||
txg_verify(tl->tl_spa, txg);
|
||||
return (tn->tn_member[t] != 0);
|
||||
}
|
||||
|
||||
@@ -893,6 +916,7 @@ txg_list_head(txg_list_t *tl, uint64_t txg)
|
||||
int t = txg & TXG_MASK;
|
||||
txg_node_t *tn = tl->tl_head[t];
|
||||
|
||||
txg_verify(tl->tl_spa, txg);
|
||||
return (tn == NULL ? NULL : (char *)tn - tl->tl_offset);
|
||||
}
|
||||
|
||||
@@ -902,6 +926,7 @@ txg_list_next(txg_list_t *tl, void *p, uint64_t txg)
|
||||
int t = txg & TXG_MASK;
|
||||
txg_node_t *tn = (txg_node_t *)((char *)p + tl->tl_offset);
|
||||
|
||||
txg_verify(tl->tl_spa, txg);
|
||||
tn = tn->tn_next[t];
|
||||
|
||||
return (tn == NULL ? NULL : (char *)tn - tl->tl_offset);
|
||||
|
||||
Reference in New Issue
Block a user