From: Yan, Zheng Date: Thu, 26 Nov 2015 14:58:42 +0000 (+0800) Subject: Workunits : fs/misc/: check if cache is used in direct IO X-Git-Tag: v10.0.3~48^2~1^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F6463%2Fhead;p=ceph.git Workunits : fs/misc/: check if cache is used in direct IO Signed-off-by: Yan, Zheng --- diff --git a/qa/workunits/fs/misc/direct_io.py b/qa/workunits/fs/misc/direct_io.py new file mode 100755 index 000000000000..48be584ef71e --- /dev/null +++ b/qa/workunits/fs/misc/direct_io.py @@ -0,0 +1,47 @@ +#!/usr/bin/python + +import os +import mmap +import subprocess +import json + +def get_data_pool(): + cmd = ['ceph', 'fs', 'ls', '--format=json-pretty'] + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) + out = proc.communicate()[0] + return json.loads(out)[0]['data_pools'][0] + +def main(): + fd = os.open("testfile", os.O_RDWR | os.O_CREAT | os.O_TRUNC | os.O_DIRECT, 0644) + + ino = os.fstat(fd).st_ino + obj_name = "{ino:x}.00000000".format(ino=ino) + pool_name = get_data_pool() + + buf = mmap.mmap(-1, 1); + buf.write('1'); + os.write(fd, buf); + + proc = subprocess.Popen(['rados', '-p', pool_name, 'get', obj_name, 'tmpfile']) + proc.wait(); + + with open('tmpfile', 'r') as tmpf: + out = tmpf.read() + if out != '1': + raise RuntimeError("data were not written to object store directly") + + with open('tmpfile', 'w') as tmpf: + tmpf.write('2') + + proc = subprocess.Popen(['rados', '-p', pool_name, 'put', obj_name, 'tmpfile']) + proc.wait(); + + os.lseek(fd, 0, os.SEEK_SET) + out = os.read(fd, 1); + if out != '2': + raise RuntimeError("data were not directly read from object store") + + os.close(fd); + print 'ok' + +main()