Give the fcore ptr a type

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