Give the fcore ptr a type

parent d2bec9e9
...@@ -162,6 +162,7 @@ tus_file_final_concat(struct VPFX(tus_server) *srv, ...@@ -162,6 +162,7 @@ tus_file_final_concat(struct VPFX(tus_server) *srv,
pdisk = part->disk; pdisk = part->disk;
AN(pdisk); AN(pdisk);
if (part->ptr != NULL) { if (part->ptr != NULL) {
assert(TFCP_READABLE(part->ptr_type));
length += pdisk->upload_length; length += pdisk->upload_length;
continue; continue;
} }
...@@ -175,6 +176,7 @@ tus_file_final_concat(struct VPFX(tus_server) *srv, ...@@ -175,6 +176,7 @@ tus_file_final_concat(struct VPFX(tus_server) *srv,
AZ(pthread_mutex_unlock(&part->mtx)); AZ(pthread_mutex_unlock(&part->mtx));
if (part->ptr == NULL) if (part->ptr == NULL)
goto err; goto err;
assert(TFCP_READABLE(part->ptr_type));
length += pdisk->upload_length; length += pdisk->upload_length;
} }
...@@ -218,10 +220,12 @@ tus_file_final_birth(struct tus_file_core **fcorep, ...@@ -218,10 +220,12 @@ tus_file_final_birth(struct tus_file_core **fcorep,
fdisk = fcore->disk; fdisk = fcore->disk;
CHECK_OBJ_NOTNULL(fdisk, VMOD_TUS_FILE_DISK_MAGIC); CHECK_OBJ_NOTNULL(fdisk, VMOD_TUS_FILE_DISK_MAGIC);
assert(fcore->ptr_type == TFCP_INVALID);
AZ(fcore->ptr); AZ(fcore->ptr);
AZ(fcore->len); AZ(fcore->len);
fcore->ptr = embryo->concat; fcore->ptr = embryo->concat;
fcore->len = embryo->concat_l; fcore->len = embryo->concat_l;
fcore->ptr_type = TFCP_CONCAT;
fdisk->upload_length = fdisk->upload_offset = embryo->upload_length; fdisk->upload_length = fdisk->upload_offset = embryo->upload_length;
vsb = embryo->spec_vsb; vsb = embryo->spec_vsb;
...@@ -262,8 +266,10 @@ tus_file_final_fini(struct tus_file_core *fcore) ...@@ -262,8 +266,10 @@ tus_file_final_fini(struct tus_file_core *fcore)
if (fcore->ptr == NULL) if (fcore->ptr == NULL)
return; return;
assert(fcore->ptr_type == TFCP_CONCAT);
CAST_OBJ_NOTNULL(concat, fcore->ptr, TUS_CONCAT_MAGIC); CAST_OBJ_NOTNULL(concat, fcore->ptr, TUS_CONCAT_MAGIC);
fcore->ptr = NULL; fcore->ptr = NULL;
fcore->ptr_type == TFCP_INVALID;
assert (fcore->len >= sizeof *concat); assert (fcore->len >= sizeof *concat);
fcore->len = 0; fcore->len = 0;
...@@ -294,6 +300,7 @@ tus_concat_hash(VRT_CTX, const struct VPFX(tus_server) *srv, ...@@ -294,6 +300,7 @@ tus_concat_hash(VRT_CTX, const struct VPFX(tus_server) *srv,
part = concat->cores[i]; part = concat->cores[i];
if (part->len == 0) if (part->len == 0)
continue; continue;
assert(TFCP_READABLE(part->ptr_type));
AN(part->ptr); AN(part->ptr);
tus_chksum_update(ctx, c, part->ptr, part->len); tus_chksum_update(ctx, c, part->ptr, part->len);
} }
...@@ -315,6 +322,7 @@ tus_file_final_urls(VRT_CTX, const struct tus_file_core *fcore, const char *pfx) ...@@ -315,6 +322,7 @@ tus_file_final_urls(VRT_CTX, const struct tus_file_core *fcore, const char *pfx)
WS_VSB_new(vsb, ctx->ws); WS_VSB_new(vsb, ctx->ws);
VSB_cat(vsb, "final;"); VSB_cat(vsb, "final;");
assert(fcore->ptr_type == TFCP_CONCAT);
CAST_OBJ_NOTNULL(concat, fcore->ptr, TUS_CONCAT_MAGIC); CAST_OBJ_NOTNULL(concat, fcore->ptr, TUS_CONCAT_MAGIC);
for (i = 0; i < concat->n; i++) { for (i = 0; i < concat->n; i++) {
part = concat->cores[i]; part = concat->cores[i];
...@@ -420,12 +428,14 @@ tus_file_mmap(struct tus_file_core *fcore) ...@@ -420,12 +428,14 @@ tus_file_mmap(struct tus_file_core *fcore)
CHECK_TUS_FILE_DISK(fdisk); CHECK_TUS_FILE_DISK(fdisk);
assert(fdisk->upload_length == fdisk->upload_offset); assert(fdisk->upload_length == fdisk->upload_offset);
assert(fcore->ptr_type == TFCP_INVALID);
AZ(fcore->ptr); AZ(fcore->ptr);
AZ(fcore->len); AZ(fcore->len);
fcore->ptr = mmap(NULL, fdisk->upload_length, PROT_READ, fcore->ptr = mmap(NULL, fdisk->upload_length, PROT_READ,
MAP_SHARED | MAP_NORESERVE, fcore->fd, header_size); MAP_SHARED | MAP_NORESERVE, fcore->fd, header_size);
AN(fcore->ptr); AN(fcore->ptr);
fcore->ptr_type = TFCP_MMAP_RO;
tus_file_close(fcore); tus_file_close(fcore);
fcore->len = fdisk->upload_length; fcore->len = fdisk->upload_length;
} }
...@@ -467,6 +477,7 @@ tus_file_fini(struct tus_file_core *fcore) ...@@ -467,6 +477,7 @@ tus_file_fini(struct tus_file_core *fcore)
if (fdisk->type == TUS_FINAL) { if (fdisk->type == TUS_FINAL) {
tus_file_final_fini(fcore); tus_file_final_fini(fcore);
} else if (fcore->ptr != NULL) { } else if (fcore->ptr != NULL) {
fcore->ptr_type = TFCP_INVALID;
(void) munmap(fcore->ptr, fcore->len); (void) munmap(fcore->ptr, fcore->len);
fcore->ptr = NULL; fcore->ptr = NULL;
fcore->len = 0; fcore->len = 0;
......
...@@ -65,6 +65,16 @@ struct tus_file_disk { ...@@ -65,6 +65,16 @@ struct tus_file_disk {
enum tus_f_type type; enum tus_f_type type;
}; };
/* what ptr points to */
enum tus_file_core_ptr {
TFCP_INVALID = 0,
TFCP_CONCAT,
#define TFCP_READABLE(tfcp) ((tfcp) >= TFCP_ZERO)
TFCP_ZERO,
TFCP_MMAP_RO,
TFCP_MMAP_RW
};
struct tus_file_core { struct tus_file_core {
unsigned magic; unsigned magic;
#define VMOD_TUS_FILE_CORE_MAGIC 0x105f11e0 #define VMOD_TUS_FILE_CORE_MAGIC 0x105f11e0
...@@ -95,6 +105,7 @@ struct tus_file_core { ...@@ -95,6 +105,7 @@ struct tus_file_core {
*/ */
int ref; int ref;
enum tus_file_core_ptr ptr_type;
/* final mmap or concats list */ /* final mmap or concats list */
void *ptr; void *ptr;
size_t len; size_t len;
......
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