mirror of
https://github.com/containers/fuse-overlayfs.git
synced 2025-09-19 04:05:23 -04:00
Merge pull request #60 from giuseppe/use-reflinks
main: copyup uses reflinks if possible
This commit is contained in:
commit
eb066fba6d
56
main.c
56
main.c
@ -36,6 +36,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
#ifdef HAVE_ERROR_H
|
#ifdef HAVE_ERROR_H
|
||||||
# include <error.h>
|
# include <error.h>
|
||||||
@ -118,6 +119,10 @@ open_by_handle_at (int mount_fd, struct file_handle *handle, int flags)
|
|||||||
#define PRIVILEGED_OPAQUE_XATTR "trusted.overlay.opaque"
|
#define PRIVILEGED_OPAQUE_XATTR "trusted.overlay.opaque"
|
||||||
#define PRIVILEGED_ORIGIN_XATTR "trusted.overlay.origin"
|
#define PRIVILEGED_ORIGIN_XATTR "trusted.overlay.origin"
|
||||||
|
|
||||||
|
#if !defined FICLONE && defined __linux__
|
||||||
|
# define FICLONE _IOW (0x94, 9, int)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define NODE_TO_INODE(x) ((fuse_ino_t) x)
|
#define NODE_TO_INODE(x) ((fuse_ino_t) x)
|
||||||
|
|
||||||
#if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 6) && !defined __cplusplus
|
#if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 6) && !defined __cplusplus
|
||||||
@ -1954,6 +1959,8 @@ copyup (struct ovl_data *lo, struct ovl_node *node)
|
|||||||
cleanup_free char *buf = NULL;
|
cleanup_free char *buf = NULL;
|
||||||
struct timespec times[2];
|
struct timespec times[2];
|
||||||
char wd_tmp_file_name[32];
|
char wd_tmp_file_name[32];
|
||||||
|
static bool support_reflinks = true;
|
||||||
|
bool data_copied = false;
|
||||||
|
|
||||||
sprintf (wd_tmp_file_name, "%lu", get_next_wd_counter ());
|
sprintf (wd_tmp_file_name, "%lu", get_next_wd_counter ());
|
||||||
|
|
||||||
@ -2019,27 +2026,42 @@ copyup (struct ovl_data *lo, struct ovl_node *node)
|
|||||||
buf = malloc (buf_size);
|
buf = malloc (buf_size);
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
goto exit;
|
goto exit;
|
||||||
for (;;)
|
|
||||||
|
if (support_reflinks)
|
||||||
{
|
{
|
||||||
int written;
|
if (ioctl (dfd, FICLONE, sfd) >= 0)
|
||||||
int nread;
|
data_copied = true;
|
||||||
|
else if (errno == ENOTSUP || errno == EINVAL)
|
||||||
|
{
|
||||||
|
/* Fallback to data copy and don't attempt again FICLONE. */
|
||||||
|
support_reflinks = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nread = TEMP_FAILURE_RETRY (read (sfd, buf, buf_size));
|
if (! data_copied)
|
||||||
if (nread < 0)
|
{
|
||||||
goto exit;
|
for (;;)
|
||||||
|
{
|
||||||
|
int written;
|
||||||
|
int nread;
|
||||||
|
|
||||||
if (nread == 0)
|
nread = TEMP_FAILURE_RETRY (read (sfd, buf, buf_size));
|
||||||
break;
|
if (nread < 0)
|
||||||
|
goto exit;
|
||||||
|
|
||||||
written = 0;
|
if (nread == 0)
|
||||||
{
|
break;
|
||||||
ret = TEMP_FAILURE_RETRY (write (dfd, buf + written, nread));
|
|
||||||
if (ret < 0)
|
written = 0;
|
||||||
goto exit;
|
{
|
||||||
written += ret;
|
ret = TEMP_FAILURE_RETRY (write (dfd, buf + written, nread));
|
||||||
nread -= ret;
|
if (ret < 0)
|
||||||
}
|
goto exit;
|
||||||
while (nread);
|
written += ret;
|
||||||
|
nread -= ret;
|
||||||
|
}
|
||||||
|
while (nread);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
times[0] = st.st_atim;
|
times[0] = st.st_atim;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user