Skip to content

Fix partial uiomove size handling #5

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

Open
wants to merge 1 commit into
base: tmp
Choose a base branch
from
Open
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
33 changes: 20 additions & 13 deletions module/zfs/dmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1419,24 +1419,28 @@ dmu_read_uio_dnode(dnode_t *dn, zfs_uio_t *uio, uint64_t size)
if (err)
return (err);

for (i = 0; i < numbufs; i++) {
for (i = 0; i < numbufs && size > 0; ) {
uint64_t tocpy;
int64_t bufoff;
dmu_buf_t *db = dbp[i];

ASSERT(size > 0);

bufoff = zfs_uio_offset(uio) - db->db_offset;
tocpy = MIN(db->db_size - bufoff, size);

ASSERT(db->db_data != NULL);
err = zfs_uio_fault_move((char *)db->db_data + bufoff, tocpy,
UIO_READ, uio);

if (err)
uint64_t resid_before = uio->uio_resid;
err = zfs_uio_fault_move((char *)db->db_data + bufoff,
tocpy, UIO_READ, uio);
uint64_t moved = resid_before - uio->uio_resid;

size -= moved;

if (err || moved == 0)
break;

size -= tocpy;
if (bufoff + moved >= db->db_size)
i++;
}
dmu_buf_rele_array(dbp, numbufs, FTAG);

Expand Down Expand Up @@ -1536,13 +1540,11 @@ dmu_write_uio_dnode(dnode_t *dn, zfs_uio_t *uio, uint64_t size, dmu_tx_t *tx)
if (err)
return (err);

for (int i = 0; i < numbufs; i++) {
for (int i = 0; i < numbufs && write_size > 0; ) {
uint64_t tocpy;
int64_t bufoff;
dmu_buf_t *db = dbp[i];

ASSERT(write_size > 0);

offset_t off = zfs_uio_offset(uio);
bufoff = off - db->db_offset;
tocpy = MIN(db->db_size - bufoff, write_size);
Expand All @@ -1555,19 +1557,24 @@ dmu_write_uio_dnode(dnode_t *dn, zfs_uio_t *uio, uint64_t size, dmu_tx_t *tx)
dmu_buf_will_dirty(db, tx);

ASSERT(db->db_data != NULL);
uint64_t resid_before = uio->uio_resid;
err = zfs_uio_fault_move((char *)db->db_data + bufoff,
tocpy, UIO_WRITE, uio);
uint64_t moved = resid_before - uio->uio_resid;

if (tocpy == db->db_size && dmu_buf_fill_done(db, tx, err)) {
/* The fill was reverted. Undo any uio progress. */
zfs_uio_advance(uio, off - zfs_uio_offset(uio));
}

if (err)
if (err || moved == 0)
break;

write_size -= tocpy;
size -= tocpy;
write_size -= moved;
size -= moved;

if (bufoff + moved >= db->db_size)
i++;
}

IMPLY(err == 0, write_size == 0);
Expand Down
Loading