static int send_image_block(struct ploop_copy_handle *h, __u64 size, __u64 pos, ssize_t *nread) { struct delta *idelta = &h->idelta; void *iobuf = get_free_iobuf(h); ploop_dbg(4, "READ size=%llu pos=%llu", size, pos); *nread = pread(idelta->fd, iobuf, size, pos); if (*nread == 0) return 0; if (*nread < 0) { ploop_err(errno, "Error from read"); return SYSEXIT_READ; } return send_async(h, iobuf, *nread, pos); }
int ploop_copy_stop(struct ploop_copy_handle *h, struct ploop_copy_stat *stat) { int ret; int iter; ploop_log(3, "pcopy last"); ret = freeze(h); if (ret) goto err; iter = 1; for (;;) { ret = ploop_copy_next_iteration(h, stat); if (ret) goto err; else if (stat->xferred == 0) break; if (iter++ > 2) { ploop_err(0, "Too many iterations on frozen FS, aborting"); return SYSEXIT_LOOP; } } if (!h->raw) { /* Must clear dirty flag on ploop1 image. */ struct ploop_pvd_header *vh = get_free_iobuf(h); if (PREAD(&h->idelta, vh, 4096, 0)) { ret = SYSEXIT_READ; goto err; } vh->m_DiskInUse = 0; ploop_dbg(3, "Update header"); ret = send_buf(h, vh, 4096, 0); if (ret) goto err; ret = send_optional_header(h); if (ret) goto err; } ploop_dbg(4, "IOCTL TRACK_STOP"); ret = ioctl(h->devfd, PLOOP_IOC_TRACK_STOP, 0); if (ret) goto err; h->tracker_on = 0; ploop_dbg(3, "SEND 0 0 (close)"); send_async(h, NULL, 0, 0); pthread_join(h->send_th, NULL); h->send_th = 0; ploop_dbg(3, "pcopy stop done"); err: ploop_copy_release(h); return ret; }