1
0
Fork 0

check for sync_file_range and patch

This commit is contained in:
Robert Schade 2017-11-26 00:01:17 +01:00
parent c182a19290
commit 565c61a0ad
7 changed files with 60 additions and 3 deletions

View file

@ -11,11 +11,14 @@ How to use:
- run "apt update; apt install git"
- run "git clone https://github.com/ravenschade/borgbackup_on_android.git"
- run "cd borgbackup_on_android; bash build.sh"
- (if virtualenv for python does not work properly you have to set selinux to permissive (do "/system/bin/setenforce 0" with root permissions))
- (if virtualenv for python does not work properly you have to set selinux to permissive (do "/system/bin/setenforce 0" with root permissions))
Known issues:
- borg starting at 1.1 requires the system call sync_file_range (see https://github.com/borgbackup/borg/pull/985 and https://github.com/borgbackup/borg/issues/1961). The linux subsystem in Windows 10 and some older Android versions (for example Lineage including 14.1) do not yet have this. Lineage 15.0 has this call and should work. I have added a test to the build script that checks if sync_file_range is available. If it is not, then I apply a patch (borg_sync_file_range.patch) that replaces this sync with convential file syncs.
Tested with:
- termux 0.56
- borg 1.1.3
- borg 1.0.12, 1.1.3
Tested and working so far is:
- creation of repositories

View file

@ -0,0 +1,16 @@
diff --git a/src/borg/platform/linux.pyx b/src/borg/platform/linux.pyx
index 25f71fa1..42ffa85f 100644
--- a/src/borg/platform/linux.pyx
+++ b/src/borg/platform/linux.pyx
@@ -225,8 +225,9 @@ def acl_set(path, item, numeric_owner=False):
cdef _sync_file_range(fd, offset, length, flags):
assert offset & PAGE_MASK == 0, "offset %d not page-aligned" % offset
assert length & PAGE_MASK == 0, "length %d not page-aligned" % length
- if sync_file_range(fd, offset, length, flags) != 0:
- raise OSError(errno.errno, os.strerror(errno.errno))
+ os.fdatasync(fd)
+ #if sync_file_range(fd, offset, length, flags) != 0:
+ # raise OSError(errno.errno, os.strerror(errno.errno))
safe_fadvise(fd, offset, length, 'DONTNEED')
cdef unsigned PAGE_MASK = sysconf(_SC_PAGESIZE) - 1

View file

@ -14,6 +14,16 @@ git checkout 1.1-maint
pip install -r requirements.d/development.txt
#find if sync_file_range is available
s=`bash ../sync_file_range_test/test.sh`
if [ "$s" = "1" ];
then
echo "patching borg to not use sync_file_range...."
git apply ../borg_sync_file_range.patch
else
echo "no need to patch borg"
fi
#download and build lz4
wget https://github.com/lz4/lz4/archive/v1.7.5.tar.gz -O lz4.tar.gz
tar -xf lz4.tar.gz

View file

@ -0,0 +1,6 @@
# setup.py - unnecessary if not redistributing the code, see below
from setuptools import setup
from Cython.Build import cythonize
setup(name = 'Hello world app',
ext_modules = cythonize("*.pyx"))

View file

@ -0,0 +1,6 @@
try:
import sync_file_range_test
except ImportError:
raise ImportError('sync_file_range not existent')
sync_file_range_test.sync_file_range_test(0)

View file

@ -0,0 +1,11 @@
cdef extern from "fcntl.h":
int sync_file_range(int fd, int offset, int nbytes, unsigned int flags)
def sync_file_range_test(int x):
print("sync_file_range exists\n")
if x==-1:
sync_file_range(1,1,1,1)

View file

@ -0,0 +1,5 @@
cd ../sync_file_range_test/
python setup.py build_ext --inplace > setup.log 2> setup.err
python sync_file_range_test.py > test.log 2> test.err
grep "sync_file_range not existent" test.err | tail -n 1 | wc -l