Linux Container Development
 help / color / mirror / Atom feed
From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org
Cc: Containers
	<containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
Subject: [PATCH 05/11] Move event-notifications to libcrtest/common.c
Date: Fri, 29 Jan 2010 12:42:28 -0800	[thread overview]
Message-ID: <20100129204228.GD26721@us.ibm.com> (raw)
In-Reply-To: <20100129202842.GA25490-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>


From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Date: Tue, 26 Jan 2010 16:46:09 -0800
Subject: [PATCH 05/11] Move event-notifications to libcrtest/common.c

The event notification functions using eventfd can be used by other
fcntl tests (and possibly other tests). Move them out of filelock1.c
and into libcrtest/common.c

Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
 fileio/filelock1.c    |   53 -------------------------------------------
 libcrtest/common.c    |   60 +++++++++++++++++++++++++++++++++++++++++++++++++
 libcrtest/libcrtest.h |    7 +++++
 3 files changed, 67 insertions(+), 53 deletions(-)

diff --git a/fileio/filelock1.c b/fileio/filelock1.c
index 305cbeb..19f7e3b 100644
--- a/fileio/filelock1.c
+++ b/fileio/filelock1.c
@@ -9,8 +9,6 @@
 #define TEST_FILE	"data.d/data.filelock1"
 #define LOG_FILE	"logs.d/log.filelock1"
 
-typedef unsigned long long u64;
-
 extern FILE *logfp;
 int test_fd;
 int event_fd1;
@@ -31,57 +29,6 @@ int event_fd2;
  * 	held by the other process.
  */
 
-setup_notification()
-{
-	int efd;
-
-	efd = eventfd(0, 0);
-	if (efd < 0) {
-		fprintf(logfp, "ERROR: eventfd(): %s\n", strerror(errno));
-		do_exit(1);
-	}
-	return efd;
-}
-
-wait_for_events(int efd, u64 total)
-{
-	int n;
-	u64 events;
-	u64 count = (u64)0;
-
-	do {
-		fprintf(logfp, "%d: wait_for_events: fd %d, reading for %llu\n",
-				getpid(), efd, total);
-		fflush(logfp);
-
-		n = read(efd, &events, sizeof(events));
-		if (n != sizeof(events)) {
-			fprintf(logfp, "ERROR: read(event_fd) %s\n",
-						strerror(errno));
-			do_exit(1);
-		}
-		fprintf(logfp, "%d: wait_for_events: fd %d read %llu\n",
-				getpid(), efd, events);
-
-		count += events;
-	} while (count < total);
-}
-
-notify_one_event(int efd)
-{
-	int n;
-	u64 event = (u64)1;
-
-	fprintf(logfp, "%d: Notifying one event on fd %d\n", getpid(), efd);
-	fflush(logfp);
-
-	n = write(efd, &event, sizeof(event));
-	if (n != sizeof(event)) {
-		fprintf(logfp, "ERROR: write(event_fd) %s\n", strerror(errno));
-		do_exit(1);
-	}
-}
-
 struct test_arg {
 	int child_idx;
 	int type;
diff --git a/libcrtest/common.c b/libcrtest/common.c
index ca3d2d8..b29042a 100644
--- a/libcrtest/common.c
+++ b/libcrtest/common.c
@@ -335,3 +335,63 @@ int move_to_cgroup(char *subsys, char *grp, int pid)
 	fclose(fout);
 	return 1;
 }
+
+/*
+ * Set up an eventfd for communication between parent/child processes
+ */
+int setup_notification(void)
+{
+	int efd;
+
+	efd = eventfd(0, 0);
+	if (efd < 0) {
+		fprintf(logfp, "ERROR: eventfd(): %s\n", strerror(errno));
+		do_exit(1);
+	}
+	return efd;
+}
+
+/*
+ * Wait on eventfd @efd till the total number of events equals @total.
+ */
+void wait_for_events(int efd, u64 total)
+{
+	int n;
+	u64 events;
+	u64 count = (u64)0;
+
+	do {
+		fprintf(logfp, "%d: wait_for_events: fd %d, reading for %llu\n",
+				getpid(), efd, total);
+		fflush(logfp);
+
+		n = read(efd, &events, sizeof(events));
+		if (n != sizeof(events)) {
+			fprintf(logfp, "ERROR: read(event_fd) %s\n",
+						strerror(errno));
+			do_exit(1);
+		}
+		fprintf(logfp, "%d: wait_for_events: fd %d read %llu\n",
+				getpid(), efd, events);
+
+		count += events;
+	} while (count < total);
+}
+
+/*
+ * Notify one event on the eventfd @efd.
+ */
+void notify_one_event(int efd)
+{
+	int n;
+	u64 event = (u64)1;
+
+	fprintf(logfp, "%d: Notifying one event on fd %d\n", getpid(), efd);
+	fflush(logfp);
+
+	n = write(efd, &event, sizeof(event));
+	if (n != sizeof(event)) {
+		fprintf(logfp, "ERROR: write(event_fd) %s\n", strerror(errno));
+		do_exit(1);
+	}
+}
diff --git a/libcrtest/libcrtest.h b/libcrtest/libcrtest.h
index a42c178..9a0a13e 100644
--- a/libcrtest/libcrtest.h
+++ b/libcrtest/libcrtest.h
@@ -12,6 +12,10 @@ struct record {
 	char data[256];
 };
 
+#ifdef __i386__
+typedef unsigned long long u64;
+#endif
+
 extern void do_exit(int status);
 extern int test_done(void);
 extern int test_checkpoint_done();
@@ -23,4 +27,7 @@ extern char *freezer_mountpoint(void);
 /* right now, subsys must always be "freezer" */
 extern int move_to_cgroup(char *subsys, char *grp, int pid);
 
+extern void notify_one_event(int efd);
+extern void wait_for_events(int efd, u64 total);
+extern int setup_notification();
 #endif /* LIBCRTEST_H */
-- 
1.6.0.4

  parent reply	other threads:[~2010-01-29 20:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-29 20:28 [PATCH 01/11] runtests.sh: Make test bit more generic Sukadev Bhattiprolu
     [not found] ` <20100129202842.GA25490-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-01-29 20:37   ` [PATCH 02/11] Make runtests.sh a wrapper for fileio tests Sukadev Bhattiprolu
2010-01-29 20:38   ` [PATCH 03/11] Check for failure while waiting for checkpoint-ready Sukadev Bhattiprolu
2010-01-29 20:42   ` [PATCH 04/11] Rename run-filelock1 to run-fcntltests.sh Sukadev Bhattiprolu
2010-01-29 20:42   ` Sukadev Bhattiprolu [this message]
     [not found]     ` <20100129204228.GD26721-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-01-30  2:44       ` [PATCH 05/11] Move event-notifications to libcrtest/common.c Serge E. Hallyn
2010-01-29 20:42   ` [PATCH 06/11] filelease1: Test restore of file leases Sukadev Bhattiprolu
2010-01-29 20:43   ` [PATCH 07/11] fsetown1: Test async I/O notification after restart Sukadev Bhattiprolu
2010-01-29 20:43   ` [PATCH 08/11] filelock1: Extend for mandatory locks Sukadev Bhattiprolu
2010-01-29 20:43   ` [PATCH 09/11] pthread1: Don't close stderr() before opening log Sukadev Bhattiprolu
2010-01-29 20:44   ` [PATCH 10/11] filelock2: Test restart of process in F_GETLK Sukadev Bhattiprolu
2010-01-29 20:44   ` [PATCH 11/11] filelease2: Test C/R during lease-break-interval Sukadev Bhattiprolu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100129204228.GD26721@us.ibm.com \
    --to=sukadev-23vcf4htsmix0ybbhkvfkdbpr1lh4cv8@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox