diff --git a/module/zfs/dmu_send.c b/module/zfs/dmu_send.c index 940454977c69..e572d04e9224 100644 --- a/module/zfs/dmu_send.c +++ b/module/zfs/dmu_send.c @@ -1600,22 +1600,30 @@ restore_freeobjects(struct restorearg *ra, objset_t *os, struct drr_freeobjects *drrfo) { uint64_t obj; + int next_err = 0; if (drrfo->drr_firstobj + drrfo->drr_numobjs < drrfo->drr_firstobj) return (SET_ERROR(EINVAL)); - for (obj = drrfo->drr_firstobj; - obj < drrfo->drr_firstobj + drrfo->drr_numobjs; - (void) dmu_object_next(os, &obj, FALSE, 0)) { + for (obj = drrfo->drr_firstobj == 0 ? 1 : drrfo->drr_firstobj; + obj < drrfo->drr_firstobj + drrfo->drr_numobjs && next_err == 0; + next_err = dmu_object_next(os, &obj, FALSE, 0)) { int err; - if (dmu_object_info(os, obj, NULL) != 0) + err = dmu_object_info(os, obj, NULL); + if (err == ENOENT) { + obj++; continue; + } else if (err != 0) { + return (err); + } err = dmu_free_long_object(os, obj); if (err != 0) return (err); } + if (next_err != ESRCH) + return (next_err); return (0); }