]> git.proxmox.com Git - ceph.git/blob - ceph/qa/workunits/fs/misc/direct_io.py
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / qa / workunits / fs / misc / direct_io.py
1 #!/usr/bin/python3
2
3 import mmap
4 import os
5 import subprocess
6
7 def main():
8 path = "testfile"
9 fd = os.open(path, os.O_RDWR | os.O_CREAT | os.O_TRUNC | os.O_DIRECT, 0o644)
10
11 ino = os.fstat(fd).st_ino
12 obj_name = "{ino:x}.00000000".format(ino=ino)
13 pool_name = os.getxattr(path, "ceph.file.layout.pool")
14
15 buf = mmap.mmap(-1, 1)
16 buf.write(b'1')
17 os.write(fd, buf)
18
19 proc = subprocess.Popen(['rados', '-p', pool_name, 'get', obj_name, 'tmpfile'])
20 proc.wait()
21
22 with open('tmpfile', 'rb') as tmpf:
23 out = tmpf.read(1)
24 if out != b'1':
25 raise RuntimeError("data were not written to object store directly")
26
27 with open('tmpfile', 'wb') as tmpf:
28 tmpf.write(b'2')
29
30 proc = subprocess.Popen(['rados', '-p', pool_name, 'put', obj_name, 'tmpfile'])
31 proc.wait()
32
33 os.lseek(fd, 0, os.SEEK_SET)
34 out = os.read(fd, 1)
35 if out != b'2':
36 raise RuntimeError("data were not directly read from object store")
37
38 os.close(fd)
39 print('ok')
40
41
42 main()