Skip to content
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions include/sys/dmu_send.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ typedef struct dmu_recv_cookie {
boolean_t drc_force;
boolean_t drc_resumable;
boolean_t drc_raw;
boolean_t drc_clone;
struct avl_tree *drc_guid_to_ds_map;
zio_cksum_t drc_cksum;
uint64_t drc_newsnapobj;
Expand Down
71 changes: 70 additions & 1 deletion module/zfs/dmu_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,22 @@ static int
dump_freeobjects(dmu_sendarg_t *dsp, uint64_t firstobj, uint64_t numobjs)
{
struct drr_freeobjects *drrfo = &(dsp->dsa_drr->drr_u.drr_freeobjects);
uint64_t maxobj = DNODES_PER_BLOCK *
(DMU_META_DNODE(dsp->dsa_os)->dn_maxblkid + 1);

/*
* ZoL < 0.7 does not handle large FREEOBJECTS records correctly,
* leading to zfs recv never completing. to avoid this issue, don't
* send FREEOBJECTS records for object IDs which cannot exist on the
* receiving side.
*/
if (maxobj > 0) {
if (maxobj < firstobj)
return (0);

if (maxobj < firstobj + numobjs)
numobjs = maxobj - firstobj;
}

/*
* If there is a pending op, but it's not PENDING_FREEOBJECTS,
Expand Down Expand Up @@ -2072,6 +2088,7 @@ dmu_recv_begin(char *tofs, char *tosnap, dmu_replay_record_t *drr_begin,
drc->drc_force = force;
drc->drc_resumable = resumable;
drc->drc_cred = CRED();
drc->drc_clone = (origin != NULL);

if (drc->drc_drrb->drr_magic == BSWAP_64(DMU_BACKUP_MAGIC)) {
drc->drc_byteswap = B_TRUE;
Expand Down Expand Up @@ -2133,7 +2150,9 @@ struct receive_writer_arg {
avl_tree_t *guid_to_ds_map;
boolean_t resumable;
boolean_t raw;
uint64_t last_object, last_offset;
uint64_t last_object;
uint64_t last_offset;
uint64_t max_object; /* highest object ID referenced in stream */
uint64_t bytes_read; /* bytes read when current record created */
};

Expand Down Expand Up @@ -2435,6 +2454,9 @@ receive_object(struct receive_writer_arg *rwa, struct drr_object *drro,
return (SET_ERROR(EINVAL));
object = err == 0 ? drro->drr_object : DMU_NEW_OBJECT;

if (drro->drr_object > rwa->max_object)
rwa->max_object = drro->drr_object;

/*
* If we are losing blkptrs or changing the block size this must
* be a new file instance. We must clear out the previous file
Expand Down Expand Up @@ -2571,6 +2593,9 @@ receive_freeobjects(struct receive_writer_arg *rwa,
err = dmu_free_long_object(rwa->os, obj);
if (err != 0)
return (err);

if (obj > rwa->max_object)
rwa->max_object = obj;
}
if (next_err != ESRCH)
return (next_err);
Expand Down Expand Up @@ -2601,6 +2626,9 @@ receive_write(struct receive_writer_arg *rwa, struct drr_write *drrw,
rwa->last_object = drrw->drr_object;
rwa->last_offset = drrw->drr_offset;

if (rwa->last_object > rwa->max_object)
rwa->max_object = rwa->last_object;

if (dmu_object_info(rwa->os, drrw->drr_object, NULL) != 0)
return (SET_ERROR(EINVAL));

Expand Down Expand Up @@ -2682,6 +2710,9 @@ receive_write_byref(struct receive_writer_arg *rwa,
ref_os = rwa->os;
}

if (drrwbr->drr_object > rwa->max_object)
rwa->max_object = drrwbr->drr_object;

if (rwa->raw)
flags |= DMU_READ_NO_DECRYPT;

Expand Down Expand Up @@ -2735,6 +2766,9 @@ receive_write_embedded(struct receive_writer_arg *rwa,
if (drrwe->drr_compression >= ZIO_COMPRESS_FUNCTIONS)
return (SET_ERROR(EINVAL));

if (drrwe->drr_object > rwa->max_object)
rwa->max_object = drrwe->drr_object;

tx = dmu_tx_create(rwa->os);

dmu_tx_hold_write(tx, drrwe->drr_object,
Expand Down Expand Up @@ -2778,6 +2812,9 @@ receive_spill(struct receive_writer_arg *rwa, struct drr_spill *drrs,
if (dmu_object_info(rwa->os, drrs->drr_object, NULL) != 0)
return (SET_ERROR(EINVAL));

if (drrs->drr_object > rwa->max_object)
rwa->max_object = drrs->drr_object;

VERIFY0(dmu_bonus_hold(rwa->os, drrs->drr_object, FTAG, &db));
if ((err = dmu_spill_hold_by_bonus(db, FTAG, &db_spill)) != 0) {
dmu_buf_rele(db, FTAG);
Expand Down Expand Up @@ -2824,6 +2861,9 @@ receive_free(struct receive_writer_arg *rwa, struct drr_free *drrf)
if (dmu_object_info(rwa->os, drrf->drr_object, NULL) != 0)
return (SET_ERROR(EINVAL));

if (drrf->drr_object > rwa->max_object)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't actually need these, since we only consider this value when doing a receive of a full send as a clone, and in that case you have to get an object record before you get any other kind of record for that object. Doesn't hurt to have them, though, and to have it be accurate in all cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any other kind of record except FREEOBJECT ;) I originally attempted to just re-use last_object, but that obviously did not work out.

I did not feel comfortable enough with my level of understanding of the code to play guessing games (regarding which patterns are possible and which aren't), so I went the "better safe than sorry" route :)

rwa->max_object = drrf->drr_object;

err = dmu_free_long_range(rwa->os, drrf->drr_object,
drrf->drr_offset, drrf->drr_length);

Expand Down Expand Up @@ -2866,6 +2906,9 @@ receive_object_range(struct receive_writer_arg *rwa,
!rwa->raw)
return (SET_ERROR(EINVAL));

if (drror->drr_firstobj > rwa->max_object)
rwa->max_object = drror->drr_firstobj;

offset = drror->drr_firstobj * sizeof (dnode_phys_t);
mdn = DMU_META_DNODE(rwa->os);

Expand Down Expand Up @@ -3704,6 +3747,32 @@ dmu_recv_stream(dmu_recv_cookie_t *drc, vnode_t *vp, offset_t *voffp,
}
mutex_exit(&rwa->mutex);

/*
* If we are receiving a full stream as a clone, all object IDs which
* are greater than the maximum ID referenced in the stream are
* by definition unused and must be freed.
*/
if (drc->drc_clone && drc->drc_drrb->drr_fromguid == 0) {
uint64_t obj = rwa->max_object + 1;
int free_err = 0;
int next_err = 0;

while (next_err == 0) {
free_err = dmu_free_long_object(rwa->os, obj);
if (free_err != 0 && free_err != ENOENT)
break;

next_err = dmu_object_next(rwa->os, &obj, FALSE, 0);
}

if (err == 0) {
if (free_err != 0 && free_err != ENOENT)
err = free_err;
else if (next_err != ESRCH)
err = next_err;
}
}

cv_destroy(&rwa->cv);
mutex_destroy(&rwa->mutex);
bqueue_destroy(&rwa->q);
Expand Down