Print this page
3909 Fix hang when sending dedup stream


1549 
1550                         fnvlist_free(sdd.snapholds);
1551                         sdd.snapholds = NULL;
1552                 }
1553 
1554                 sdd.dryrun = B_FALSE;
1555                 sdd.verbose = B_FALSE;
1556         }
1557 
1558         err = dump_filesystems(zhp, &sdd);
1559         fsavl_destroy(fsavl);
1560         nvlist_free(fss);
1561 
1562         /* Ensure no snaps found is treated as an error. */
1563         if (err == 0 && !sdd.seento)
1564                 err = ENOENT;
1565 
1566         if (tid != 0) {
1567                 if (err != 0)
1568                         (void) pthread_cancel(tid);
1569                 (void) pthread_join(tid, NULL);
1570                 (void) close(pipefd[0]);

1571         }
1572 
1573         if (sdd.cleanup_fd != -1) {
1574                 VERIFY(0 == close(sdd.cleanup_fd));
1575                 sdd.cleanup_fd = -1;
1576         }
1577 
1578         if (!flags->dryrun && (flags->replicate || flags->doall ||
1579             flags->props)) {
1580                 /*
1581                  * write final end record.  NB: want to do this even if
1582                  * there was some error, because it might not be totally
1583                  * failed.
1584                  */
1585                 dmu_replay_record_t drr = { 0 };
1586                 drr.drr_type = DRR_END;
1587                 if (write(outfd, &drr, sizeof (drr)) == -1) {
1588                         return (zfs_standard_error(zhp->zfs_hdl,
1589                             errno, errbuf));
1590                 }
1591         }
1592 
1593         return (err || sdd.err);
1594 
1595 stderr_out:
1596         err = zfs_standard_error(zhp->zfs_hdl, err, errbuf);
1597 err_out:
1598         fsavl_destroy(fsavl);
1599         nvlist_free(fss);
1600         fnvlist_free(sdd.snapholds);
1601 
1602         if (sdd.cleanup_fd != -1)
1603                 VERIFY(0 == close(sdd.cleanup_fd));
1604         if (tid != 0) {
1605                 (void) pthread_cancel(tid);
1606                 (void) pthread_join(tid, NULL);
1607                 (void) close(pipefd[0]);

1608         }
1609         return (err);
1610 }
1611 
1612 /*
1613  * Routines specific to "zfs recv"
1614  */
1615 
1616 static int
1617 recv_read(libzfs_handle_t *hdl, int fd, void *buf, int ilen,
1618     boolean_t byteswap, zio_cksum_t *zc)
1619 {
1620         char *cp = buf;
1621         int rv;
1622         int len = ilen;
1623 
1624         do {
1625                 rv = read(fd, cp, len);
1626                 cp += rv;
1627                 len -= rv;




1549 
1550                         fnvlist_free(sdd.snapholds);
1551                         sdd.snapholds = NULL;
1552                 }
1553 
1554                 sdd.dryrun = B_FALSE;
1555                 sdd.verbose = B_FALSE;
1556         }
1557 
1558         err = dump_filesystems(zhp, &sdd);
1559         fsavl_destroy(fsavl);
1560         nvlist_free(fss);
1561 
1562         /* Ensure no snaps found is treated as an error. */
1563         if (err == 0 && !sdd.seento)
1564                 err = ENOENT;
1565 
1566         if (tid != 0) {
1567                 if (err != 0)
1568                         (void) pthread_cancel(tid);

1569                 (void) close(pipefd[0]);
1570                 (void) pthread_join(tid, NULL);
1571         }
1572 
1573         if (sdd.cleanup_fd != -1) {
1574                 VERIFY(0 == close(sdd.cleanup_fd));
1575                 sdd.cleanup_fd = -1;
1576         }
1577 
1578         if (!flags->dryrun && (flags->replicate || flags->doall ||
1579             flags->props)) {
1580                 /*
1581                  * write final end record.  NB: want to do this even if
1582                  * there was some error, because it might not be totally
1583                  * failed.
1584                  */
1585                 dmu_replay_record_t drr = { 0 };
1586                 drr.drr_type = DRR_END;
1587                 if (write(outfd, &drr, sizeof (drr)) == -1) {
1588                         return (zfs_standard_error(zhp->zfs_hdl,
1589                             errno, errbuf));
1590                 }
1591         }
1592 
1593         return (err || sdd.err);
1594 
1595 stderr_out:
1596         err = zfs_standard_error(zhp->zfs_hdl, err, errbuf);
1597 err_out:
1598         fsavl_destroy(fsavl);
1599         nvlist_free(fss);
1600         fnvlist_free(sdd.snapholds);
1601 
1602         if (sdd.cleanup_fd != -1)
1603                 VERIFY(0 == close(sdd.cleanup_fd));
1604         if (tid != 0) {
1605                 (void) pthread_cancel(tid);

1606                 (void) close(pipefd[0]);
1607                 (void) pthread_join(tid, NULL);
1608         }
1609         return (err);
1610 }
1611 
1612 /*
1613  * Routines specific to "zfs recv"
1614  */
1615 
1616 static int
1617 recv_read(libzfs_handle_t *hdl, int fd, void *buf, int ilen,
1618     boolean_t byteswap, zio_cksum_t *zc)
1619 {
1620         char *cp = buf;
1621         int rv;
1622         int len = ilen;
1623 
1624         do {
1625                 rv = read(fd, cp, len);
1626                 cp += rv;
1627                 len -= rv;