mirror of
https://github.com/containers/fuse-overlayfs.git
synced 2025-09-10 07:44:54 -04:00
Merge pull request #62 from giuseppe/use-sendfile-copyup
copyup: use sendfile(2) if available
This commit is contained in:
commit
9b6732407c
@ -12,7 +12,7 @@ AC_PROG_CC
|
|||||||
gl_EARLY
|
gl_EARLY
|
||||||
gl_INIT
|
gl_INIT
|
||||||
|
|
||||||
AC_CHECK_HEADERS([fcntl.h inttypes.h limits.h stddef.h stdint.h stdlib.h string.h unistd.h])
|
AC_CHECK_HEADERS([fcntl.h inttypes.h limits.h stddef.h stdint.h stdlib.h string.h unistd.h sys/sendfile.h])
|
||||||
|
|
||||||
AC_PROG_RANLIB
|
AC_PROG_RANLIB
|
||||||
|
|
||||||
|
68
main.c
68
main.c
@ -37,6 +37,9 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#ifdef HAVE_SYS_SENDFILE_H
|
||||||
|
# include <sys/sendfile.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_ERROR_H
|
#ifdef HAVE_ERROR_H
|
||||||
# include <error.h>
|
# include <error.h>
|
||||||
@ -1947,6 +1950,36 @@ create_node_directory (struct ovl_data *lo, struct ovl_node *src)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
copy_fd_to_fd (int sfd, int dfd, char *buf, size_t buf_size)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
int written;
|
||||||
|
int nread;
|
||||||
|
|
||||||
|
nread = TEMP_FAILURE_RETRY (read (sfd, buf, buf_size));
|
||||||
|
if (nread < 0)
|
||||||
|
return nread;
|
||||||
|
|
||||||
|
if (nread == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
written = 0;
|
||||||
|
{
|
||||||
|
ret = TEMP_FAILURE_RETRY (write (dfd, buf + written, nread));
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
written += ret;
|
||||||
|
nread -= ret;
|
||||||
|
}
|
||||||
|
while (nread);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
copyup (struct ovl_data *lo, struct ovl_node *node)
|
copyup (struct ovl_data *lo, struct ovl_node *node)
|
||||||
{
|
{
|
||||||
@ -2038,30 +2071,33 @@ copyup (struct ovl_data *lo, struct ovl_node *node)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_SYS_SENDFILE_H
|
||||||
if (! data_copied)
|
if (! data_copied)
|
||||||
{
|
{
|
||||||
for (;;)
|
off_t copied = 0;
|
||||||
|
|
||||||
|
while (copied < st.st_size)
|
||||||
{
|
{
|
||||||
int written;
|
off_t tocopy = st.st_size - copied;
|
||||||
int nread;
|
ssize_t n = sendfile (dfd, sfd, NULL, tocopy > SIZE_MAX ? SIZE_MAX : (size_t) tocopy);
|
||||||
|
if (n < 0)
|
||||||
nread = TEMP_FAILURE_RETRY (read (sfd, buf, buf_size));
|
|
||||||
if (nread < 0)
|
|
||||||
goto exit;
|
|
||||||
|
|
||||||
if (nread == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
written = 0;
|
|
||||||
{
|
{
|
||||||
ret = TEMP_FAILURE_RETRY (write (dfd, buf + written, nread));
|
/* On failure, fallback to the read/write loop. */
|
||||||
|
ret = copy_fd_to_fd (sfd, dfd, buf, buf_size);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto exit;
|
goto exit;
|
||||||
written += ret;
|
|
||||||
nread -= ret;
|
|
||||||
}
|
}
|
||||||
while (nread);
|
copied += n;
|
||||||
}
|
}
|
||||||
|
data_copied = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (! data_copied)
|
||||||
|
{
|
||||||
|
ret = copy_fd_to_fd (sfd, dfd, buf, buf_size);
|
||||||
|
if (ret < 0)
|
||||||
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
times[0] = st.st_atim;
|
times[0] = st.st_atim;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user