Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
8643ead8
Commit
8643ead8
authored
Apr 30, 2024
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify VFIL_allocate() by using posix_fallocate(2) when insisting (=VSHM)
parent
2fb12478
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
30 deletions
+5
-30
vfil.c
lib/libvarnish/vfil.c
+5
-30
No files found.
lib/libvarnish/vfil.c
View file @
8643ead8
...
...
@@ -230,11 +230,6 @@ VFIL_allocate(int fd, uintmax_t size, int insist)
{
struct
stat
st
;
uintmax_t
fsspace
;
size_t
l
;
ssize_t
l2
,
l3
;
char
*
buf
;
ssize_t
bufsiz
;
int
retval
=
0
;
if
(
ftruncate
(
fd
,
size
))
return
(
-
1
);
...
...
@@ -248,6 +243,10 @@ VFIL_allocate(int fd, uintmax_t size, int insist)
errno
=
ENOSPC
;
return
(
-
1
);
}
if
(
insist
)
{
/* This falls back to writing zeros, as we want */
return
(
posix_fallocate
(
fd
,
0
,
size
)
?
-
1
:
0
);
}
#if defined(__linux__) && defined(HAVE_FALLOCATE)
{
/* fallocate will for some filesystems (e.g. xfs) not take
...
...
@@ -267,31 +266,7 @@ VFIL_allocate(int fd, uintmax_t size, int insist)
}
}
#endif
if
(
!
insist
)
return
(
0
);
/* Write size zero bytes to make sure the entire file is allocated
in the file system */
if
(
size
>
65536
)
bufsiz
=
64
*
1024
;
else
bufsiz
=
size
;
buf
=
calloc
(
1
,
bufsiz
);
AN
(
buf
);
assert
(
lseek
(
fd
,
0
,
SEEK_SET
)
==
0
);
for
(
l
=
0
;
l
<
size
;
l
+=
l2
)
{
l2
=
bufsiz
;
if
(
l
+
l2
>
size
)
l2
=
size
-
l
;
l3
=
write
(
fd
,
buf
,
l2
);
if
(
l3
!=
l2
)
{
retval
=
-
1
;
break
;
}
}
assert
(
lseek
(
fd
,
0
,
SEEK_SET
)
==
0
);
free
(
buf
);
return
(
retval
);
}
struct
vfil_dir
{
...
...
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