#!/usr/bin/python # # Script to stress test flock on an ocfs2 filesystem # The script will print a '.' whenever it tries to get an exclusive lock # # Brad Plant # bplant@iinet.net.au # 3rd July 2009 # import sys import os import fcntl import random import time if len(sys.argv) != 3: print "Takes 2 args, the number of processes to create and the number of iterations per process" sys.exit() if sys.argv[1] <= 0: print "You must specify at least 1 process to create" sys.exit() x = int(sys.argv[1]) while x > 0: x -= 1 pid = os.fork() if pid == 0: i = int(sys.argv[2]) while i > 0: i -= 1 f = open("flock.test", "r") fcntl.flock(f.fileno(), fcntl.LOCK_SH) f.readlines() fcntl.flock(f.fileno(), fcntl.LOCK_UN) f.close() if random.randint(1, 1000) == 1: sys.stdout.write(".") f = open("flock.test", "a+") fcntl.flock(f.fileno(), fcntl.LOCK_EX) os.ftruncate(f.fileno(), 0) f.write(str(time.time())) fcntl.flock(f.fileno(), fcntl.LOCK_UN) f.close() sys.exit()