ml->linkfile = ln;
ml->lockfile = lo;
- DBG(LOCKS, mnt_debug_h(ml, "alloc"));
+ DBG(LOCKS, mnt_debug_h(ml, "alloc: linkfile=%s, lockfile=%s", ln, lo));
return ml;
err:
free(lo);
int test_lock(struct mtest *ts, int argc, char *argv[])
{
- const char *datafile;
- int verbose = 0, loops, l;
+ time_t synctime = 0;
+ unsigned int usecs;
+ struct timeval tv;
+ const char *datafile = NULL;
+ int verbose = 0, loops = 0, l, idx = 1;
if (argc < 3)
- return -1;
-
- datafile = argv[1];
- loops = atoi(argv[2]);
+ return -EINVAL;
- if (argc == 5 && strcmp(argv[4], "--verbose") == 0)
+ if (strcmp(argv[idx], "--synctime") == 0) {
+ synctime = (time_t) atol(argv[idx + 1]);
+ idx += 2;
+ }
+ if (idx < argc && strcmp(argv[idx], "--verbose") == 0) {
verbose = 1;
+ idx++;
+ }
+
+ if (idx < argc)
+ datafile = argv[idx++];
+ if (idx < argc)
+ loops = atoi(argv[idx++]);
+
+ if (!datafile || !loops)
+ return -EINVAL;
+
+ fprintf(stderr, "%d: start: synctime=%u, verbose=%d, datafile=%s, loops=%d\n",
+ getpid(), (int) synctime, verbose, datafile, loops);
atexit(clean_lock);
sigaction (sig, &sa, (struct sigaction *) 0);
}
+ /* start the test in exactly defined time */
+ if (synctime) {
+ gettimeofday(&tv, NULL);
+ if (synctime && synctime - tv.tv_sec > 1) {
+ usecs = ((synctime - tv.tv_sec) * 1000000UL) -
+ (1000000UL - tv.tv_usec);
+ usleep(usecs);
+ }
+ }
+
for (l = 0; l < loops; l++) {
lock = mnt_new_lock(datafile, 0);
if (!lock)
mnt_unlock_file(lock);
mnt_free_lock(lock);
lock = NULL;
+
+ /* The mount command usually finish after mtab update. We
+ * simulate this via short sleep -- it's also enough to make
+ * concurrent processes happy.
+ */
+ if (synctime)
+ usleep(25000);
}
return 0;
int main(int argc, char *argv[])
{
struct mtest tss[] = {
- { "--lock", test_lock, " <datafile> <loops> [--verbose] increment number in datafile" },
+ { "--lock", test_lock, " [--synctime <time_t>] [--verbose] <datafile> <loops> "
+ "increment a number in datafile" },
{ NULL }
};
--- /dev/null
+#!/bin/bash
+
+# Copyright (C) 2010 Karel Zak <kzak@redhat.com>
+
+TS_TOPDIR="$(dirname $0)/../.."
+TS_DESC="lock"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+TESTPROG="$TS_HELPER_LIBMOUNT_LOCK"
+
+#
+# Be careful with number of processes. Don't forget that there is time limit
+# when the mount waits on the mtab lock. If you define too much processes some
+# of them will fail with timeout.
+#
+# Note: the original version (< 2.13) of util-linux is completely useless for
+# this test (maximum for this old version is NLOOPS=10 and NPROCESSES=5 (2-way
+# 2GHz machine)). It has terrible performance due a bad timeouts implemntation
+# in lock_mtab().
+#
+NLOOPS=1000
+NPROCESSES=50
+
+
+> $TS_OUTPUT.debug
+echo 0 > $TS_OUTPUT
+SYNCTIME=$(( $(date +%s) + 5 ))
+
+for id in $(seq 0 $(( $NPROCESSES - 1 ))); do
+ $TESTPROG --lock --synctime $SYNCTIME $TS_OUTPUT $NLOOPS >> $TS_OUTPUT.debug 2>&1 &
+done
+
+wait
+
+ts_finalize