Lines Matching refs:e
61 RawExport *raw_export_unref(RawExport *e) { in raw_export_unref() argument
62 if (!e) in raw_export_unref()
65 sd_event_source_unref(e->output_event_source); in raw_export_unref()
67 import_compress_free(&e->compress); in raw_export_unref()
69 sd_event_unref(e->event); in raw_export_unref()
71 safe_close(e->input_fd); in raw_export_unref()
73 free(e->buffer); in raw_export_unref()
74 free(e->path); in raw_export_unref()
75 return mfree(e); in raw_export_unref()
84 _cleanup_(raw_export_unrefp) RawExport *e = NULL; in raw_export_new()
89 e = new(RawExport, 1); in raw_export_new()
90 if (!e) in raw_export_new()
93 *e = (RawExport) { in raw_export_new()
103 e->event = sd_event_ref(event); in raw_export_new()
105 r = sd_event_default(&e->event); in raw_export_new()
110 *ret = TAKE_PTR(e); in raw_export_new()
115 static void raw_export_report_progress(RawExport *e) { in raw_export_report_progress() argument
117 assert(e); in raw_export_report_progress()
119 if (e->written_uncompressed >= (uint64_t) e->st.st_size) in raw_export_report_progress()
122 … percent = (unsigned) ((e->written_uncompressed * UINT64_C(100)) / (uint64_t) e->st.st_size); in raw_export_report_progress()
124 if (percent == e->last_percent) in raw_export_report_progress()
127 if (!ratelimit_below(&e->progress_ratelimit)) in raw_export_report_progress()
133 e->last_percent = percent; in raw_export_report_progress()
136 static int raw_export_process(RawExport *e) { in raw_export_process() argument
140 assert(e); in raw_export_process()
142 if (!e->tried_reflink && e->compress.type == IMPORT_COMPRESS_UNCOMPRESSED) { in raw_export_process()
148 r = btrfs_reflink(e->input_fd, e->output_fd); in raw_export_process()
154 e->tried_reflink = true; in raw_export_process()
157 if (!e->tried_sendfile && e->compress.type == IMPORT_COMPRESS_UNCOMPRESSED) { in raw_export_process()
159 l = sendfile(e->output_fd, e->input_fd, NULL, COPY_BUFFER_SIZE); in raw_export_process()
164 e->tried_sendfile = true; in raw_export_process()
169 e->written_uncompressed += l; in raw_export_process()
170 e->written_compressed += l; in raw_export_process()
172 raw_export_report_progress(e); in raw_export_process()
178 while (e->buffer_size <= 0) { in raw_export_process()
181 if (e->eof) { in raw_export_process()
186 l = read(e->input_fd, input, sizeof(input)); in raw_export_process()
193 e->eof = true; in raw_export_process()
194 … r = import_compress_finish(&e->compress, &e->buffer, &e->buffer_size, &e->buffer_allocated); in raw_export_process()
196 e->written_uncompressed += l; in raw_export_process()
197 … r = import_compress(&e->compress, input, l, &e->buffer, &e->buffer_size, &e->buffer_allocated); in raw_export_process()
205 l = write(e->output_fd, e->buffer, e->buffer_size); in raw_export_process()
214 assert((size_t) l <= e->buffer_size); in raw_export_process()
215 memmove(e->buffer, (uint8_t*) e->buffer + l, e->buffer_size - l); in raw_export_process()
216 e->buffer_size -= l; in raw_export_process()
217 e->written_compressed += l; in raw_export_process()
219 raw_export_report_progress(e); in raw_export_process()
225 (void) copy_times(e->input_fd, e->output_fd, COPY_CRTIME); in raw_export_process()
226 (void) copy_xattr(e->input_fd, e->output_fd, 0); in raw_export_process()
229 if (e->on_finished) in raw_export_process()
230 e->on_finished(e, r, e->userdata); in raw_export_process()
232 sd_event_exit(e->event, r); in raw_export_process()
276 int raw_export_start(RawExport *e, const char *path, int fd, ImportCompressType compress) { in raw_export_start() argument
280 assert(e); in raw_export_start()
286 if (e->output_fd >= 0) in raw_export_start()
293 r = free_and_strdup(&e->path, path); in raw_export_start()
301 if (fstat(sfd, &e->st) < 0) in raw_export_start()
303 r = stat_verify_regular(&e->st); in raw_export_start()
310 e->input_fd = TAKE_FD(tfd); in raw_export_start()
312 e->input_fd = TAKE_FD(sfd); in raw_export_start()
314 r = import_compress_init(&e->compress, compress); in raw_export_start()
318 … r = sd_event_add_io(e->event, &e->output_event_source, fd, EPOLLOUT, raw_export_on_output, e); in raw_export_start()
320 r = sd_event_add_defer(e->event, &e->output_event_source, raw_export_on_defer, e); in raw_export_start()
324 r = sd_event_source_set_enabled(e->output_event_source, SD_EVENT_ON); in raw_export_start()
329 e->output_fd = fd; in raw_export_start()