eio: use new Eina_File infra to detect IO error during mmap copy.
SVN revision: 66800
This commit is contained in:
parent
edbee63134
commit
f185e2d950
|
@ -245,6 +245,22 @@ _eio_file_direct_notify(void *data, Ecore_Thread *thread __UNUSED__, void *msg_d
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_XATTR
|
#ifdef HAVE_XATTR
|
||||||
|
static void
|
||||||
|
_eio_file_copy_xattr(Ecore_Thread *thread __UNUSED__,
|
||||||
|
Eio_File_Progress *op __UNUSED__,
|
||||||
|
Eina_File *f, int out)
|
||||||
|
{
|
||||||
|
Eina_Iterator *it;
|
||||||
|
Eina_Xattr *attr;
|
||||||
|
|
||||||
|
it = eina_file_xattr_value_get(f);
|
||||||
|
EINA_ITERATOR_FOREACH(it, attr)
|
||||||
|
{
|
||||||
|
fsetxattr(out, attr->name, attr->value, attr->length, 0);
|
||||||
|
}
|
||||||
|
eina_iterator_free(it);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_eio_file_copy_xattr(Ecore_Thread *thread __UNUSED__,
|
_eio_file_copy_xattr(Ecore_Thread *thread __UNUSED__,
|
||||||
Eio_File_Progress *op __UNUSED__,
|
Eio_File_Progress *op __UNUSED__,
|
||||||
|
@ -298,7 +314,7 @@ _eio_file_write(int fd, void *mem, ssize_t length)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
_eio_file_copy_mmap(Ecore_Thread *thread, Eio_File_Progress *op, int in, int out, long long size)
|
_eio_file_copy_mmap(Ecore_Thread *thread, Eio_File_Progress *op, Eina_File *f, int out, long long size)
|
||||||
{
|
{
|
||||||
char *m = MAP_FAILED;
|
char *m = MAP_FAILED;
|
||||||
long long i;
|
long long i;
|
||||||
|
@ -309,12 +325,11 @@ _eio_file_copy_mmap(Ecore_Thread *thread, Eio_File_Progress *op, int in, int out
|
||||||
int k;
|
int k;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
m = mmap(NULL, EIO_PACKET_SIZE * EIO_PACKET_COUNT, PROT_READ, MAP_FILE | MAP_HUGETLB | MAP_SHARED, in, i);
|
m = eina_file_map_new(f, EINA_FILE_SEQUENTIAL,
|
||||||
if (m == MAP_FAILED)
|
i, EIO_PACKET_SIZE * EIO_PACKET_COUNT);
|
||||||
|
if (!m)
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
|
||||||
madvise(m, EIO_PACKET_SIZE * EIO_PACKET_COUNT, MADV_SEQUENTIAL);
|
|
||||||
|
|
||||||
c = size - i;
|
c = size - i;
|
||||||
if (c - EIO_PACKET_SIZE * EIO_PACKET_COUNT > 0)
|
if (c - EIO_PACKET_SIZE * EIO_PACKET_COUNT > 0)
|
||||||
c = EIO_PACKET_SIZE * EIO_PACKET_COUNT;
|
c = EIO_PACKET_SIZE * EIO_PACKET_COUNT;
|
||||||
|
@ -332,10 +347,13 @@ _eio_file_copy_mmap(Ecore_Thread *thread, Eio_File_Progress *op, int in, int out
|
||||||
if (!_eio_file_write(out, m + k, c - k))
|
if (!_eio_file_write(out, m + k, c - k))
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
|
||||||
|
if (eina_file_map_faulted(f, m))
|
||||||
|
goto on_error;
|
||||||
|
|
||||||
eio_progress_send(thread, op, i + c, size);
|
eio_progress_send(thread, op, i + c, size);
|
||||||
|
|
||||||
munmap(m, EIO_PACKET_SIZE * EIO_PACKET_COUNT);
|
eina_file_map_free(f, m);
|
||||||
m = MAP_FAILED;
|
m = NULL;
|
||||||
|
|
||||||
if (ecore_thread_check(thread))
|
if (ecore_thread_check(thread))
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
@ -344,7 +362,7 @@ _eio_file_copy_mmap(Ecore_Thread *thread, Eio_File_Progress *op, int in, int out
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
|
|
||||||
on_error:
|
on_error:
|
||||||
if (m != MAP_FAILED) munmap(m, EIO_PACKET_SIZE * EIO_PACKET_COUNT);
|
if (m != NULL) eina_file_map_free(f, m);
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -580,11 +598,15 @@ eio_progress_cb(Eio_Progress *progress, Eio_File_Progress *op)
|
||||||
Eina_Bool
|
Eina_Bool
|
||||||
eio_file_copy_do(Ecore_Thread *thread, Eio_File_Progress *copy)
|
eio_file_copy_do(Ecore_Thread *thread, Eio_File_Progress *copy)
|
||||||
{
|
{
|
||||||
|
Eina_File *f;
|
||||||
|
#ifdef EFL_HAVE_SPLICE
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
int result = -1;
|
|
||||||
int in = -1;
|
int in = -1;
|
||||||
|
#endif
|
||||||
|
int result = -1;
|
||||||
int out = -1;
|
int out = -1;
|
||||||
|
|
||||||
|
#ifdef EFL_HAVE_SPLICE
|
||||||
in = open(copy->source, O_RDONLY);
|
in = open(copy->source, O_RDONLY);
|
||||||
if (in < 0)
|
if (in < 0)
|
||||||
{
|
{
|
||||||
|
@ -598,6 +620,7 @@ eio_file_copy_do(Ecore_Thread *thread, Eio_File_Progress *copy)
|
||||||
*/
|
*/
|
||||||
if (fstat(in, &buf) < 0)
|
if (fstat(in, &buf) < 0)
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* open write */
|
/* open write */
|
||||||
out = open(copy->dest, O_WRONLY | O_CREAT | O_TRUNC, buf.st_mode);
|
out = open(copy->dest, O_WRONLY | O_CREAT | O_TRUNC, buf.st_mode);
|
||||||
|
@ -612,8 +635,29 @@ eio_file_copy_do(Ecore_Thread *thread, Eio_File_Progress *copy)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* classic copy method using mmap and write */
|
/* classic copy method using mmap and write */
|
||||||
if (result == -1 && !_eio_file_copy_mmap(thread, copy, in, out, buf.st_size))
|
if (result == -1)
|
||||||
goto on_error;
|
{
|
||||||
|
f = eina_file_open(copy->source, 0);
|
||||||
|
if (!f) goto on_error;
|
||||||
|
|
||||||
|
if (!_eio_file_copy_mmap(thread, copy, f, out, buf.st_size))
|
||||||
|
{
|
||||||
|
eina_file_close(f);
|
||||||
|
goto on_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_XATTR
|
||||||
|
_eio_file_copy_eina_xattr(thread, copy, f, out);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
eina_file_close(f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#ifdef HAVE_XATTR
|
||||||
|
_eio_file_copy_xattr(thread, copy, in, out);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* change access right to match source */
|
/* change access right to match source */
|
||||||
#ifdef HAVE_CHMOD
|
#ifdef HAVE_CHMOD
|
||||||
|
@ -624,12 +668,10 @@ eio_file_copy_do(Ecore_Thread *thread, Eio_File_Progress *copy)
|
||||||
goto on_error;
|
goto on_error;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_XATTR
|
|
||||||
_eio_file_copy_xattr(thread, copy, in, out);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
close(out);
|
close(out);
|
||||||
|
#ifdef EFL_HAVE_SPLICE
|
||||||
close(in);
|
close(in);
|
||||||
|
#endif
|
||||||
|
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue