mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2025-04-06 17:49:11 +03:00
Remove code duplication
Remove code duplication by moving code responsible for partial block zeroing to a separate function: dnode_partial_zero(). Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Ryan Moeller <ryan@ixsystems.com> Signed-off-by: Pawel Jakub Dawidek <pawel@dawidek.net> Closes #12627
This commit is contained in:
parent
fd778e44c8
commit
a95c82bed8
@ -2037,10 +2037,40 @@ dnode_set_dirtyctx(dnode_t *dn, dmu_tx_t *tx, void *tag)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
dnode_partial_zero(dnode_t *dn, uint64_t off, uint64_t blkoff, uint64_t len,
|
||||||
|
dmu_tx_t *tx)
|
||||||
|
{
|
||||||
|
dmu_buf_impl_t *db;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
rw_enter(&dn->dn_struct_rwlock, RW_READER);
|
||||||
|
res = dbuf_hold_impl(dn, 0, dbuf_whichblock(dn, 0, off), TRUE, FALSE,
|
||||||
|
FTAG, &db);
|
||||||
|
rw_exit(&dn->dn_struct_rwlock);
|
||||||
|
if (res == 0) {
|
||||||
|
db_lock_type_t dblt;
|
||||||
|
boolean_t dirty;
|
||||||
|
|
||||||
|
dblt = dmu_buf_lock_parent(db, RW_READER, FTAG);
|
||||||
|
/* don't dirty if not on disk and not dirty */
|
||||||
|
dirty = !list_is_empty(&db->db_dirty_records) ||
|
||||||
|
(db->db_blkptr && !BP_IS_HOLE(db->db_blkptr));
|
||||||
|
dmu_buf_unlock_parent(db, dblt, FTAG);
|
||||||
|
if (dirty) {
|
||||||
|
caddr_t data;
|
||||||
|
|
||||||
|
dmu_buf_will_dirty(&db->db, tx);
|
||||||
|
data = db->db.db_data;
|
||||||
|
bzero(data + blkoff, len);
|
||||||
|
}
|
||||||
|
dbuf_rele(db, FTAG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dnode_free_range(dnode_t *dn, uint64_t off, uint64_t len, dmu_tx_t *tx)
|
dnode_free_range(dnode_t *dn, uint64_t off, uint64_t len, dmu_tx_t *tx)
|
||||||
{
|
{
|
||||||
dmu_buf_impl_t *db;
|
|
||||||
uint64_t blkoff, blkid, nblks;
|
uint64_t blkoff, blkid, nblks;
|
||||||
int blksz, blkshift, head, tail;
|
int blksz, blkshift, head, tail;
|
||||||
int trunc = FALSE;
|
int trunc = FALSE;
|
||||||
@ -2089,31 +2119,10 @@ dnode_free_range(dnode_t *dn, uint64_t off, uint64_t len, dmu_tx_t *tx)
|
|||||||
}
|
}
|
||||||
/* zero out any partial block data at the start of the range */
|
/* zero out any partial block data at the start of the range */
|
||||||
if (head) {
|
if (head) {
|
||||||
int res;
|
|
||||||
ASSERT3U(blkoff + head, ==, blksz);
|
ASSERT3U(blkoff + head, ==, blksz);
|
||||||
if (len < head)
|
if (len < head)
|
||||||
head = len;
|
head = len;
|
||||||
rw_enter(&dn->dn_struct_rwlock, RW_READER);
|
dnode_partial_zero(dn, off, blkoff, head, tx);
|
||||||
res = dbuf_hold_impl(dn, 0, dbuf_whichblock(dn, 0, off),
|
|
||||||
TRUE, FALSE, FTAG, &db);
|
|
||||||
rw_exit(&dn->dn_struct_rwlock);
|
|
||||||
if (res == 0) {
|
|
||||||
caddr_t data;
|
|
||||||
boolean_t dirty;
|
|
||||||
|
|
||||||
db_lock_type_t dblt = dmu_buf_lock_parent(db, RW_READER,
|
|
||||||
FTAG);
|
|
||||||
/* don't dirty if it isn't on disk and isn't dirty */
|
|
||||||
dirty = !list_is_empty(&db->db_dirty_records) ||
|
|
||||||
(db->db_blkptr && !BP_IS_HOLE(db->db_blkptr));
|
|
||||||
dmu_buf_unlock_parent(db, dblt, FTAG);
|
|
||||||
if (dirty) {
|
|
||||||
dmu_buf_will_dirty(&db->db, tx);
|
|
||||||
data = db->db.db_data;
|
|
||||||
bzero(data + blkoff, head);
|
|
||||||
}
|
|
||||||
dbuf_rele(db, FTAG);
|
|
||||||
}
|
|
||||||
off += head;
|
off += head;
|
||||||
len -= head;
|
len -= head;
|
||||||
}
|
}
|
||||||
@ -2135,27 +2144,9 @@ dnode_free_range(dnode_t *dn, uint64_t off, uint64_t len, dmu_tx_t *tx)
|
|||||||
ASSERT0(P2PHASE(off, blksz));
|
ASSERT0(P2PHASE(off, blksz));
|
||||||
/* zero out any partial block data at the end of the range */
|
/* zero out any partial block data at the end of the range */
|
||||||
if (tail) {
|
if (tail) {
|
||||||
int res;
|
|
||||||
if (len < tail)
|
if (len < tail)
|
||||||
tail = len;
|
tail = len;
|
||||||
rw_enter(&dn->dn_struct_rwlock, RW_READER);
|
dnode_partial_zero(dn, off + len, 0, tail, tx);
|
||||||
res = dbuf_hold_impl(dn, 0, dbuf_whichblock(dn, 0, off+len),
|
|
||||||
TRUE, FALSE, FTAG, &db);
|
|
||||||
rw_exit(&dn->dn_struct_rwlock);
|
|
||||||
if (res == 0) {
|
|
||||||
boolean_t dirty;
|
|
||||||
/* don't dirty if not on disk and not dirty */
|
|
||||||
db_lock_type_t type = dmu_buf_lock_parent(db, RW_READER,
|
|
||||||
FTAG);
|
|
||||||
dirty = !list_is_empty(&db->db_dirty_records) ||
|
|
||||||
(db->db_blkptr && !BP_IS_HOLE(db->db_blkptr));
|
|
||||||
dmu_buf_unlock_parent(db, type, FTAG);
|
|
||||||
if (dirty) {
|
|
||||||
dmu_buf_will_dirty(&db->db, tx);
|
|
||||||
bzero(db->db.db_data, tail);
|
|
||||||
}
|
|
||||||
dbuf_rele(db, FTAG);
|
|
||||||
}
|
|
||||||
len -= tail;
|
len -= tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user