Skip to content

Commit

Permalink
Clean up by-dnode code in dmu_tx.c
Browse files Browse the repository at this point in the history
openzfs@0eef1bd
introduced some changes which we slightly improved the style of when
porting to illumos.

There is also one minor error-handling fix, in zap_add() the "zap" may
become NULL in case of an error re-opening the ZAP.

Originally suggested at: openzfs/openzfs#276

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed by: Pavel Zakharov <pavel.zakharov@delphix.com>
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Closes openzfs#5805
  • Loading branch information
ahrens authored and behlendorf committed Feb 24, 2017
1 parent f7e7682 commit 66eead5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 36 deletions.
2 changes: 1 addition & 1 deletion include/sys/dmu_tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ extern dmu_tx_t *dmu_tx_create_assigned(struct dsl_pool *dp, uint64_t txg);
dmu_tx_t *dmu_tx_create_dd(dsl_dir_t *dd);
int dmu_tx_is_syncing(dmu_tx_t *tx);
int dmu_tx_private_ok(dmu_tx_t *tx);
void dmu_tx_add_new_object(dmu_tx_t *tx, objset_t *os, dnode_t *dn);
void dmu_tx_add_new_object(dmu_tx_t *tx, dnode_t *dn);
void dmu_tx_willuse_space(dmu_tx_t *tx, int64_t delta);
void dmu_tx_dirty_buf(dmu_tx_t *tx, struct dmu_buf_impl *db);
int dmu_tx_holds(dmu_tx_t *tx, uint64_t object);
Expand Down
4 changes: 2 additions & 2 deletions module/zfs/dmu_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ dmu_object_alloc_dnsize(objset_t *os, dmu_object_type_t ot, int blocksize,
dnode_allocate(dn, ot, blocksize, 0, bonustype, bonuslen, dn_slots, tx);
mutex_exit(&os->os_obj_lock);

dmu_tx_add_new_object(tx, os, dn);
dmu_tx_add_new_object(tx, dn);
dnode_rele(dn, FTAG);

return (object);
Expand Down Expand Up @@ -168,7 +168,7 @@ dmu_object_claim_dnsize(objset_t *os, uint64_t object, dmu_object_type_t ot,
return (err);

dnode_allocate(dn, ot, blocksize, 0, bonustype, bonuslen, dn_slots, tx);
dmu_tx_add_new_object(tx, os, dn);
dmu_tx_add_new_object(tx, dn);

dnode_rele(dn, FTAG);

Expand Down
58 changes: 26 additions & 32 deletions module/zfs/dmu_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ dmu_tx_hold_dnode_impl(dmu_tx_t *tx, dnode_t *dn, enum dmu_tx_hold_type type,
dmu_tx_hold_t *txh;

if (dn != NULL) {
refcount_add(&dn->dn_holds, tx);
(void) refcount_add(&dn->dn_holds, tx);
if (tx->tx_txg != 0) {
mutex_enter(&dn->dn_mtx);
/*
Expand Down Expand Up @@ -163,7 +163,7 @@ dmu_tx_hold_object_impl(dmu_tx_t *tx, objset_t *os, uint64_t object,

if (object != DMU_NEW_OBJECT) {
err = dnode_hold(os, object, FTAG, &dn);
if (err) {
if (err != 0) {
tx->tx_err = err;
return (NULL);
}
Expand All @@ -175,7 +175,7 @@ dmu_tx_hold_object_impl(dmu_tx_t *tx, objset_t *os, uint64_t object,
}

void
dmu_tx_add_new_object(dmu_tx_t *tx, objset_t *os, dnode_t *dn)
dmu_tx_add_new_object(dmu_tx_t *tx, dnode_t *dn)
{
/*
* If we're syncing, they can manipulate any object anyhow, and
Expand Down Expand Up @@ -462,34 +462,32 @@ dmu_tx_hold_write(dmu_tx_t *tx, uint64_t object, uint64_t off, int len)
{
dmu_tx_hold_t *txh;

ASSERT(tx->tx_txg == 0);
ASSERT(len <= DMU_MAX_ACCESS);
ASSERT0(tx->tx_txg);
ASSERT3U(len, <=, DMU_MAX_ACCESS);
ASSERT(len == 0 || UINT64_MAX - off >= len - 1);

txh = dmu_tx_hold_object_impl(tx, tx->tx_objset,
object, THT_WRITE, off, len);
if (txh == NULL)
return;

dmu_tx_count_write(txh, off, len);
dmu_tx_count_dnode(txh);
if (txh != NULL) {
dmu_tx_count_write(txh, off, len);
dmu_tx_count_dnode(txh);
}
}

void
dmu_tx_hold_write_by_dnode(dmu_tx_t *tx, dnode_t *dn, uint64_t off, int len)
{
dmu_tx_hold_t *txh;

ASSERT(tx->tx_txg == 0);
ASSERT(len <= DMU_MAX_ACCESS);
ASSERT0(tx->tx_txg);
ASSERT3U(len, <=, DMU_MAX_ACCESS);
ASSERT(len == 0 || UINT64_MAX - off >= len - 1);

txh = dmu_tx_hold_dnode_impl(tx, dn, THT_WRITE, off, len);
if (txh == NULL)
return;

dmu_tx_count_write(txh, off, len);
dmu_tx_count_dnode(txh);
if (txh != NULL) {
dmu_tx_count_write(txh, off, len);
dmu_tx_count_dnode(txh);
}
}

static void
Expand Down Expand Up @@ -792,9 +790,8 @@ dmu_tx_hold_free(dmu_tx_t *tx, uint64_t object, uint64_t off, uint64_t len)

txh = dmu_tx_hold_object_impl(tx, tx->tx_objset,
object, THT_FREE, off, len);
if (txh == NULL)
return;
(void) dmu_tx_hold_free_impl(txh, off, len);
if (txh != NULL)
(void) dmu_tx_hold_free_impl(txh, off, len);
}

void
Expand All @@ -803,9 +800,8 @@ dmu_tx_hold_free_by_dnode(dmu_tx_t *tx, dnode_t *dn, uint64_t off, uint64_t len)
dmu_tx_hold_t *txh;

txh = dmu_tx_hold_dnode_impl(tx, dn, THT_FREE, off, len);
if (txh == NULL)
return;
(void) dmu_tx_hold_free_impl(txh, off, len);
if (txh != NULL)
(void) dmu_tx_hold_free_impl(txh, off, len);
}

static void
Expand Down Expand Up @@ -916,27 +912,25 @@ dmu_tx_hold_zap(dmu_tx_t *tx, uint64_t object, int add, const char *name)
{
dmu_tx_hold_t *txh;

ASSERT(tx->tx_txg == 0);
ASSERT0(tx->tx_txg);

txh = dmu_tx_hold_object_impl(tx, tx->tx_objset,
object, THT_ZAP, add, (uintptr_t)name);
if (txh == NULL)
return;
dmu_tx_hold_zap_impl(txh, add, name);
if (txh != NULL)
dmu_tx_hold_zap_impl(txh, add, name);
}

void
dmu_tx_hold_zap_by_dnode(dmu_tx_t *tx, dnode_t *dn, int add, const char *name)
{
dmu_tx_hold_t *txh;

ASSERT(tx->tx_txg == 0);
ASSERT0(tx->tx_txg);
ASSERT(dn != NULL);

txh = dmu_tx_hold_dnode_impl(tx, dn, THT_ZAP, add, (uintptr_t)name);
if (txh == NULL)
return;
dmu_tx_hold_zap_impl(txh, add, name);
if (txh != NULL)
dmu_tx_hold_zap_impl(txh, add, name);
}

void
Expand All @@ -957,7 +951,7 @@ dmu_tx_hold_bonus_by_dnode(dmu_tx_t *tx, dnode_t *dn)
{
dmu_tx_hold_t *txh;

ASSERT(tx->tx_txg == 0);
ASSERT0(tx->tx_txg);

txh = dmu_tx_hold_dnode_impl(tx, dn, THT_BONUS, 0, 0);
if (txh)
Expand Down
3 changes: 2 additions & 1 deletion module/zfs/zap_micro.c
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,8 @@ zap_add_impl(zap_t *zap, const char *key,
}
ASSERT(zap == zn->zn_zap);
zap_name_free(zn);
zap_unlockdir(zap, tag);
if (zap != NULL) /* may be NULL if fzap_add() failed */
zap_unlockdir(zap, tag);
return (err);
}

Expand Down

0 comments on commit 66eead5

Please sign in to comment.