aboutsummaryrefslogtreecommitdiffstats
path: root/module/zfs
diff options
context:
space:
mode:
authorMatthew Ahrens <[email protected]>2017-02-24 13:34:26 -0800
committerBrian Behlendorf <[email protected]>2017-02-24 13:34:26 -0800
commit66eead53c9d2480f2a464ef170920953431ad200 (patch)
tree14f8e0ab26d9c89503e36d74a49a906a89e0a9bf /module/zfs
parentf7e76821c525a7764a01f4a0e16aa9e2b77e3170 (diff)
Clean up by-dnode code in dmu_tx.c
https://github.com/zfsonlinux/zfs/commit/0eef1bde31d67091d3deed23fe2394f5a8bf2276 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: https://github.com/openzfs/openzfs/pull/276 Reviewed-by: Brian Behlendorf <[email protected]> Reviewed by: Pavel Zakharov <[email protected]> Signed-off-by: Matthew Ahrens <[email protected]> Closes #5805
Diffstat (limited to 'module/zfs')
-rw-r--r--module/zfs/dmu_object.c4
-rw-r--r--module/zfs/dmu_tx.c58
-rw-r--r--module/zfs/zap_micro.c3
3 files changed, 30 insertions, 35 deletions
diff --git a/module/zfs/dmu_object.c b/module/zfs/dmu_object.c
index 3e3efe0c1..8ca699ebf 100644
--- a/module/zfs/dmu_object.c
+++ b/module/zfs/dmu_object.c
@@ -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);
@@ -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);
diff --git a/module/zfs/dmu_tx.c b/module/zfs/dmu_tx.c
index 7c1801be4..4d4c74f51 100644
--- a/module/zfs/dmu_tx.c
+++ b/module/zfs/dmu_tx.c
@@ -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);
/*
@@ -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);
}
@@ -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
@@ -462,17 +462,16 @@ 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
@@ -480,16 +479,15 @@ 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
@@ -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
@@ -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
@@ -916,13 +912,12 @@ 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
@@ -930,13 +925,12 @@ 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
@@ -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)
diff --git a/module/zfs/zap_micro.c b/module/zfs/zap_micro.c
index 0c8ee9d25..53f8d2313 100644
--- a/module/zfs/zap_micro.c
+++ b/module/zfs/zap_micro.c
@@ -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);
}