Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-tus
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-tus
Commits
0bc8866b
Unverified
Commit
0bc8866b
authored
May 20, 2022
by
Nils Goroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Early mmap for basic multipart support
parent
f59c6eb0
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
632 additions
and
8 deletions
+632
-8
Makefile.am
src/Makefile.am
+1
-0
tus_file.c
src/tus_file.c
+91
-8
tus_server.h
src/tus_server.h
+1
-0
tus_servers.c
src/tus_servers.c
+8
-0
multipart.vtc
src/vtc/multipart.vtc
+531
-0
No files found.
src/Makefile.am
View file @
0bc8866b
...
@@ -14,6 +14,7 @@ vmod_get_h_LDADD = -ldl
...
@@ -14,6 +14,7 @@ vmod_get_h_LDADD = -ldl
TESTS
=
\
TESTS
=
\
vtc/plain.vtc
\
vtc/plain.vtc
\
vtc/plain_cors.vtc
\
vtc/plain_cors.vtc
\
vtc/multipart.vtc
\
vtc/name_hash.vtc
\
vtc/name_hash.vtc
\
vtc/expires.vtc
\
vtc/expires.vtc
\
vtc/done.vtc
\
vtc/done.vtc
\
...
...
src/tus_file.c
View file @
0bc8866b
...
@@ -1097,11 +1097,19 @@ struct tus_suck_fd {
...
@@ -1097,11 +1097,19 @@ struct tus_suck_fd {
struct
tus_suck_common
sc
;
struct
tus_suck_common
sc
;
};
};
struct
tus_suck_mmap
{
unsigned
magic
;
#define TUS_SUCK_MMAP_MAGIC 0x11ffbafa
void
*
ptr
;
struct
tus_suck_common
sc
;
};
typedef
int
suck_truncate_f
(
void
*
,
off_t
);
typedef
int
suck_truncate_f
(
void
*
,
off_t
);
struct
tus_suck
{
struct
tus_suck
{
union
{
union
{
struct
tus_suck_fd
sfd
;
struct
tus_suck_fd
sfd
;
struct
tus_suck_mmap
sm
;
}
priv
;
}
priv
;
objiterate_f
*
func
;
objiterate_f
*
func
;
suck_truncate_f
*
trunc
;
suck_truncate_f
*
trunc
;
...
@@ -1158,7 +1166,7 @@ tus_suck_fd_truncate_f(void *priv, off_t length)
...
@@ -1158,7 +1166,7 @@ tus_suck_fd_truncate_f(void *priv, off_t length)
CAST_OBJ_NOTNULL
(
sfd
,
priv
,
TUS_SUCK_FD_MAGIC
);
CAST_OBJ_NOTNULL
(
sfd
,
priv
,
TUS_SUCK_FD_MAGIC
);
return
(
ftruncate
(
sfd
->
fd
,
length
));
return
(
ftruncate
(
sfd
->
fd
,
header_size
+
length
));
}
}
static
inline
struct
tus_suck_common
*
static
inline
struct
tus_suck_common
*
...
@@ -1179,6 +1187,73 @@ tus_suck_fd_init(struct tus_suck *suck, struct tus_file_core *fcore)
...
@@ -1179,6 +1187,73 @@ tus_suck_fd_init(struct tus_suck *suck, struct tus_file_core *fcore)
* suck to mmapped
* suck to mmapped
*/
*/
static
int
v_matchproto_
(
objiterate_f
)
tus_suck_mmap_f
(
void
*
priv
,
unsigned
flush
,
const
void
*
ptr
,
ssize_t
len
)
{
struct
tus_suck_mmap
*
sm
;
struct
tus_suck_common
*
sc
;
void
*
wptr
;
CAST_OBJ_NOTNULL
(
sm
,
priv
,
TUS_SUCK_MMAP_MAGIC
);
sc
=
&
sm
->
sc
;
(
void
)
flush
;
if
(
len
==
0
)
return
(
0
);
assert
(
len
>
0
);
if
(
*
sc
->
upload_offset
+
len
>
sc
->
max
)
{
errno
=
EFBIG
;
return
(
-
1
);
}
wptr
=
(
char
*
)
sm
->
ptr
+
*
sc
->
upload_offset
;
memcpy
(
wptr
,
ptr
,
len
);
/* XXX write ordering with fdisk flush ?
*
* maybe we can just truncate all trailing NULs
* when reading?
*/
return
(
tus_suck_finish
(
sc
,
len
,
ptr
,
len
));
}
static
int
tus_suck_mmap_truncate_f
(
void
*
priv
,
off_t
length
)
{
struct
tus_suck_mmap
*
sm
;
struct
tus_suck_common
*
sc
;
void
*
wptr
;
CAST_OBJ_NOTNULL
(
sm
,
priv
,
TUS_SUCK_MMAP_MAGIC
);
sc
=
&
sm
->
sc
;
assert
(
length
<=
sc
->
max
);
if
(
length
>=
*
sc
->
upload_offset
)
return
(
0
);
wptr
=
(
char
*
)
sm
->
ptr
+
length
;
memset
(
wptr
,
0
,
*
sc
->
upload_offset
-
length
);
}
static
inline
struct
tus_suck_common
*
tus_suck_mmap_init
(
struct
tus_suck
*
suck
,
struct
tus_file_core
*
fcore
)
{
struct
tus_suck_mmap
*
sm
=
&
suck
->
priv
.
sm
;
tus_file_mmap
(
fcore
);
sm
->
magic
=
TUS_SUCK_MMAP_MAGIC
;
sm
->
ptr
=
fcore
->
ptr
;
AN
(
sm
->
ptr
);
suck
->
func
=
tus_suck_mmap_f
;
suck
->
trunc
=
tus_suck_mmap_truncate_f
;
return
(
&
sm
->
sc
);
}
/* ------------------------------------------------------------
/* ------------------------------------------------------------
* top level sucking
* top level sucking
*/
*/
...
@@ -1192,9 +1267,17 @@ tus_suck_trunc(struct tus_suck *suck, off_t length)
...
@@ -1192,9 +1267,17 @@ tus_suck_trunc(struct tus_suck *suck, off_t length)
}
}
static
inline
struct
tus_suck_common
*
static
inline
struct
tus_suck_common
*
tus_suck_init
(
struct
tus_suck
*
suck
,
struct
tus_file_core
*
fcore
)
tus_suck_init
(
struct
tus_suck
*
suck
,
struct
tus_file_core
*
fcore
,
struct
tus_file_disk
*
fdisk
)
{
{
return
(
tus_suck_fd_init
(
suck
,
fcore
));
VCL_BYTES
bm
;
bm
=
tus_server_multipart
(
fcore
->
server
);
if
(
bm
>
0
&&
fdisk
->
upload_offset
>=
bm
)
return
(
tus_suck_mmap_init
(
suck
,
fcore
));
else
return
(
tus_suck_fd_init
(
suck
,
fcore
));
}
}
unsigned
unsigned
...
@@ -1215,10 +1298,10 @@ tus_body_to_file(VRT_CTX, struct tus_file_core *fcore)
...
@@ -1215,10 +1298,10 @@ tus_body_to_file(VRT_CTX, struct tus_file_core *fcore)
memset
(
&
suck
,
0
,
sizeof
suck
);
memset
(
&
suck
,
0
,
sizeof
suck
);
sc
=
tus_suck_init
(
&
suck
,
fcore
);
sc
=
tus_suck_init
(
&
suck
,
fcore
,
fdisk
);
AN
(
sc
);
AN
(
sc
);
offset_saved
=
f
core
->
disk
->
upload_offset
;
offset_saved
=
fdisk
->
upload_offset
;
sc
->
ctx
=
ctx
;
sc
->
ctx
=
ctx
;
sc
->
max
=
tus_server_max
(
fcore
->
server
);
sc
->
max
=
tus_server_max
(
fcore
->
server
);
...
@@ -1238,8 +1321,8 @@ tus_body_to_file(VRT_CTX, struct tus_file_core *fcore)
...
@@ -1238,8 +1321,8 @@ tus_body_to_file(VRT_CTX, struct tus_file_core *fcore)
suck
.
func
,
&
suck
.
priv
);
suck
.
func
,
&
suck
.
priv
);
if
(
written
<
0
&&
errno
==
EFBIG
)
{
if
(
written
<
0
&&
errno
==
EFBIG
)
{
tus_suck_trunc
(
&
suck
,
sc
->
max
);
fdisk
->
upload_offset
=
fdisk
->
upload_length
=
sc
->
max
;
fdisk
->
upload_offset
=
fdisk
->
upload_length
=
sc
->
max
;
tus_suck_trunc
(
&
suck
,
header_size
+
sc
->
max
);
return
(
413
);
return
(
413
);
}
}
...
@@ -1253,8 +1336,8 @@ tus_body_to_file(VRT_CTX, struct tus_file_core *fcore)
...
@@ -1253,8 +1336,8 @@ tus_body_to_file(VRT_CTX, struct tus_file_core *fcore)
if
(
tus_chksum_equal
(
ctx
,
sc
->
chksum
))
if
(
tus_chksum_equal
(
ctx
,
sc
->
chksum
))
return
(
204
);
return
(
204
);
tus_suck_trunc
(
&
suck
,
offset_saved
);
fcore
->
disk
->
upload_offset
=
offset_saved
;
fcore
->
disk
->
upload_offset
=
offset_saved
;
tus_suck_trunc
(
&
suck
,
header_size
+
offset_saved
);
return
(
460
);
return
(
460
);
}
}
...
...
src/tus_server.h
View file @
0bc8866b
...
@@ -44,6 +44,7 @@ VCL_DURATION tus_server_expires(const struct VPFX(tus_server) *);
...
@@ -44,6 +44,7 @@ VCL_DURATION tus_server_expires(const struct VPFX(tus_server) *);
void
tus_server_lock
(
struct
VPFX
(
tus_server
)
*
);
void
tus_server_lock
(
struct
VPFX
(
tus_server
)
*
);
void
tus_server_unlock
(
struct
VPFX
(
tus_server
)
*
);
void
tus_server_unlock
(
struct
VPFX
(
tus_server
)
*
);
VCL_BYTES
tus_server_max
(
const
struct
VPFX
(
tus_server
)
*
s
);
VCL_BYTES
tus_server_max
(
const
struct
VPFX
(
tus_server
)
*
s
);
VCL_BYTES
tus_server_multipart
(
const
struct
VPFX
(
tus_server
)
*
s
);
struct
vmod_blobdigest_digest
*
tus_server_digest
(
struct
vmod_blobdigest_digest
*
tus_server_digest
(
const
struct
VPFX
(
tus_server
)
*
s
);
const
struct
VPFX
(
tus_server
)
*
s
);
struct
tus_exp
*
tus_server_exp
(
const
struct
VPFX
(
tus_server
)
*
);
struct
tus_exp
*
tus_server_exp
(
const
struct
VPFX
(
tus_server
)
*
);
src/tus_servers.c
View file @
0bc8866b
...
@@ -103,6 +103,14 @@ tus_server_max(const struct VPFX(tus_server) *s)
...
@@ -103,6 +103,14 @@ tus_server_max(const struct VPFX(tus_server) *s)
return
(
s
->
max
);
return
(
s
->
max
);
}
}
VCL_BYTES
tus_server_multipart
(
const
struct
VPFX
(
tus_server
)
*
s
)
{
CHECK_OBJ_NOTNULL
(
s
,
VMOD_TUS_SERVER_MAGIC
);
return
(
s
->
multipart
);
}
struct
vmod_blobdigest_digest
*
struct
vmod_blobdigest_digest
*
tus_server_digest
(
const
struct
VPFX
(
tus_server
)
*
s
)
tus_server_digest
(
const
struct
VPFX
(
tus_server
)
*
s
)
{
{
...
...
src/vtc/multipart.vtc
0 → 100644
View file @
0bc8866b
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment