make fdatasync() explicit

parent bcbf8d56
......@@ -949,11 +949,9 @@ tus_body_to_file(VRT_CTX, struct tus_file_core *fcore)
if (written < 0 && errno == EFBIG) {
fdisk->upload_offset = fdisk->upload_length = suck.max;
AZ(ftruncate(fcore->fd, header_size + suck.max));
AZ(fdatasync(fcore->fd));
return (413);
}
AZ(fdatasync(fcore->fd));
if (suck.chksum == NULL) {
if (written >= 0)
return (204);
......@@ -966,7 +964,6 @@ tus_body_to_file(VRT_CTX, struct tus_file_core *fcore)
fcore->disk->upload_offset = offset_saved;
AZ(ftruncate(fcore->fd, header_size + offset_saved));
AZ(fdatasync(fcore->fd));
return (460);
}
......@@ -998,8 +995,20 @@ tus_file_done(struct tus_file_core *fcore, struct tus_file_disk *fdisk, const ch
fd = tus_file_open(fcore);
if (fd >= 0) {
AZ(ftruncate(fd, header_size));
AZ(fdatasync(fd));
tus_file_close(fcore);
}
return (1);
}
void
tus_file_sync(struct tus_file_core *fcore)
{
if (fcore == NULL)
return;
CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC);
if (fcore->fd < 0)
return;
AZ(fdatasync(fcore->fd));
}
......@@ -175,3 +175,4 @@ void
tus_file_final_abort(struct concat_embryo *embryo);
VCL_BOOL
tus_file_done(struct tus_file_core *, struct tus_file_disk *, const char *);
void tus_file_sync(struct tus_file_core *);
......@@ -532,3 +532,18 @@ tus_server_metadata(VRT_CTX, struct VPFX(tus_server) *tussrv,
return (b);
}
VCL_VOID
tus_server_sync(VRT_CTX, struct VPFX(tus_server) *tussrv)
{
struct tus_response *r;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(tussrv, VMOD_TUS_SERVER_MAGIC);
r = tus_task_use(ctx, tussrv);
if (r == NULL)
return;
tus_file_sync(r->fcore);
}
......@@ -216,5 +216,19 @@ Extract *key* from metadata and return the corresponding value decoded.
Only available if vmod_blob is available (see `Hashes` _) and on the
client side after `xserver.recv()`_ was called from ``vcl_recv {}``.
$Method VOID .sync()
For lowest latencies, vmod_tus stores data in files opened without any
additional options affecting caching such that the operating system is
free to write data delayed. This could, in turn, lead to upload data
and/or state to be lost or reverted to an earlier state when the
system crashes.
When the `xserver.sync()`_ method is called, an `fdatasync(2)` call is
issued on the file backing the current upload, such that its current
state is flushed to stable storage (given that the underlying file
does provide stable storage).
SEE ALSO
========vcl\(7),varnishd\(1)
......@@ -73,6 +73,7 @@ varnish v1 -vcl+backend {
if (resp.status == 4200) {
call meta;
tmp.synth();
tmp.sync();
return (deliver);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment