[Ocfs2-test-devel] [PATCH 2/2] Ocfs2-test: Let multi-inline-tests accept different device name.

Tristan Ye tristan.ye at oracle.com
Mon Oct 12 19:11:37 PDT 2009


As we know, a same volume may be treated by different device name among nodes who share
the disk. and our former multi-inline-tests will definitely fail due to this reason.

To solve this issue, we try to pass UUID of a volume to mpi binary, and the binary
convert the UUID to a device name on its own, which will be later called by ocfs2_open() in
our testing binary.

Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
---
 programs/inline-data/inline-data-utils.c |   22 ++++++++++++++++-
 programs/inline-data/multi-inline-data.c |   21 ++++++++++-----
 programs/inline-data/multi-inline-dirs.c |   39 ++++++++++++++++++++++++-----
 programs/inline-data/multi-inline-run.sh |   23 ++++++++++-------
 4 files changed, 80 insertions(+), 25 deletions(-)

diff --git a/programs/inline-data/inline-data-utils.c b/programs/inline-data/inline-data-utils.c
index 415ad2d..bd65585 100644
--- a/programs/inline-data/inline-data-utils.c
+++ b/programs/inline-data/inline-data-utils.c
@@ -62,7 +62,6 @@ extern char mount_point[OCFS2_MAX_FILENAME_LEN];
 extern char work_place[OCFS2_MAX_FILENAME_LEN];
 extern char file_name[OCFS2_MAX_FILENAME_LEN];
 
-
 unsigned long get_rand(unsigned long min, unsigned long max)
 {
 	if (min == 0 && max == 0)
@@ -324,6 +323,27 @@ int verify_pattern_mmap(int fd, unsigned int size)
 	return 0;
 }
 
+int uuid2dev(const char *uuid, char *dev)
+{
+	FILE *df;
+	char cmd[300];
+
+	snprintf(cmd, 300, "blkid |grep %s|cut -d':' -f1", uuid);
+
+	df = popen(cmd, "r");
+
+	if (df == NULL) {
+		fprintf(stderr, "popen failed to get dev name.\n");
+		return -1;
+	}
+
+	fscanf(df, "%s\n", dev);
+
+	pclose(df);
+
+	return 0;
+}
+
 int open_ocfs2_volume(char *device_name)
 {
 	int open_flags = OCFS2_FLAG_HEARTBEAT_DEV_OK | OCFS2_FLAG_RO;
diff --git a/programs/inline-data/multi-inline-data.c b/programs/inline-data/multi-inline-data.c
index 7a6b929..2529780 100755
--- a/programs/inline-data/multi-inline-data.c
+++ b/programs/inline-data/multi-inline-data.c
@@ -70,6 +70,7 @@
 
 static char *prog;
 static char device[100];
+static char uuid[100];
 
 ocfs2_filesys *fs;
 struct ocfs2_super_block *ocfs2_sb;
@@ -113,6 +114,7 @@ extern int verify_pattern(int size, char *buf);
 extern int __verify_pattern_fd(int fd, unsigned int size, int direct_read);
 extern int verify_pattern_fd(int fd, unsigned int size);
 extern int verify_pattern_mmap(int fd, unsigned int size);
+extern int uuid2dev(const char *uuid, char *dev);
 extern int open_ocfs2_volume(char *device_name);
 extern int is_file_inlined(char *dirent_name, unsigned long *i_size,
 			   unsigned int *id_count);
@@ -120,11 +122,11 @@ extern int is_file_inlined(char *dirent_name, unsigned long *i_size,
 static void usage(void)
 {
 	printf("Usage: multi-inline-data [-i <iteration>] "
-	       "<-d <device>> <mount_point>\n"
+	       "<-u <uuid>> <mount_point>\n"
 	       "Run a series of tests intended to verify I/O to and from\n"
 	       "files/dirs with inline data.\n\n"
 	       "iteration specify the running times.\n"
-	       "device and mount_point are mandatory.\n");
+	       "uuid and mount_point are mandatory.\n");
 
 	MPI_Finalize();
 
@@ -156,7 +158,7 @@ static int parse_opts(int argc, char **argv)
 {
 	int c;
 	while (1) {
-		c = getopt(argc, argv, "D:d:I:i:");
+		c = getopt(argc, argv, "U:u:I:i:");
 		if (c == -1)
 			break;
 		switch (c) {
@@ -164,16 +166,16 @@ static int parse_opts(int argc, char **argv)
 		case 'I':
 			iteration = atol(optarg);
 			break;
-		case 'd':
-		case 'D':
-			strcpy(device, optarg);
+		case 'u':
+		case 'U':
+			strcpy(uuid, optarg);
 			break;
 		default:
 			break;
 		}
 	}
 
-	if (strcmp(device, "") == 0)
+	if (strcmp(uuid, "") == 0)
 		return EINVAL;
 
 	if (argc - optind != 1)
@@ -183,6 +185,11 @@ static int parse_opts(int argc, char **argv)
 	if (mount_point[strlen(mount_point) - 1] == '/')
 		 mount_point[strlen(mount_point) - 1] = '\0';
 
+	memset(device, 0, 100);
+
+	if (uuid2dev(uuid, device))
+		abort_printf("Failed to get device name from uuid!\n");
+
 	return 0;
 
 }
diff --git a/programs/inline-data/multi-inline-dirs.c b/programs/inline-data/multi-inline-dirs.c
index e3be06b..1001e06 100644
--- a/programs/inline-data/multi-inline-dirs.c
+++ b/programs/inline-data/multi-inline-dirs.c
@@ -71,6 +71,7 @@ struct my_dirent {
 
 static char *prog;
 static char device[100];
+static char uuid[100];
 
 static ocfs2_filesys *fs;
 static struct ocfs2_super_block *ocfs2_sb;
@@ -128,13 +129,13 @@ static inline char rand_char(void)
 static void usage(void)
 {
 	printf("Usage: multi-inline-dirs [-i <iteration>] [-s operated_entries] "
-	       "<-d <device>> <mount_point>\n"
+	       "<-u <uuid>> <mount_point>\n"
 	       "Run a series of tests intended to verify I/O to and from\n"
 	       "dirs with inline data.\n\n"
 	       "iteration specify the running times.\n"
 	       "operated_dir_entries specify the entires number to be "
 	       "operated,such as random create/unlink/rename.\n"
-	       "device and mount_point are mandatory.\n");
+	       "uuid and mount_point are mandatory.\n");
 
 	MPI_Finalize();
 	exit(1);
@@ -165,7 +166,7 @@ static int parse_opts(int argc, char **argv)
 {
 	int c;
 	while (1) {
-		c = getopt(argc, argv, "D:d:I:i:S:s:");
+		c = getopt(argc, argv, "U:u:I:i:S:s:");
 		if (c == -1)
 			break;
 		switch (c) {
@@ -173,9 +174,9 @@ static int parse_opts(int argc, char **argv)
 		case 'I':
 			iteration = atol(optarg);
 			break;
-		case 'd':
-		case 'D':
-			strcpy(device, optarg);
+		case 'u':
+		case 'U':
+			strcpy(uuid, optarg);
 			break;
 		case 's':
 		case 'S':
@@ -185,7 +186,7 @@ static int parse_opts(int argc, char **argv)
 		}
 	}
 
-	if (strcmp(device, "") == 0)
+	if (strcmp(uuid, "") == 0)
 		return EINVAL;
 
 	if (argc - optind != 1)
@@ -1123,6 +1124,25 @@ static void run_large_dir_tests(void)
 		abort_printf("MPI_Barrier failed: %d\n", ret);
 }
 
+static int uuid2dev(const char *uuid, char *dev)
+{
+	FILE *df;
+	char cmd[300];
+
+	snprintf(cmd, 300, "blkid |grep %s|cut -d':' -f1", uuid);
+
+	df = popen(cmd, "r");
+	if (df == NULL) {
+		fprintf(stderr, "popen failed to get dev name.\n");
+		return -1;
+	}
+
+	fscanf(df, "%s\n", dev);
+
+	pclose(df);
+	return 0;
+}
+
 static int open_ocfs2_volume(char *device_name)
 {
 	int open_flags = OCFS2_FLAG_HEARTBEAT_DEV_OK | OCFS2_FLAG_RO;
@@ -1243,6 +1263,11 @@ static void setup(int argc, char *argv[])
 	if (parse_opts(argc, argv))
 		usage();
 
+	memset(device, 0, 100);
+
+	if (uuid2dev(uuid, device))
+		abort_printf("Failed to get device name from uuid!\n");
+
 	ret = open_ocfs2_volume(device);
 	if (ret < 0)
 		abort_printf("open ocfs2 volume failed!\n");
diff --git a/programs/inline-data/multi-inline-run.sh b/programs/inline-data/multi-inline-run.sh
index acf5aca..9faa6ac 100755
--- a/programs/inline-data/multi-inline-run.sh
+++ b/programs/inline-data/multi-inline-run.sh
@@ -50,6 +50,7 @@ DIRS_LOG_FILE=
 RUN_LOG_FILE=
 MOUNT_POINT=
 OCFS2_DEVICE=
+OCFS2_UUID=
 
 BLOCKSIZE=
 CLUSTERSIZE=
@@ -200,6 +201,8 @@ f_setup()
 	if [ -z "$MPI_HOSTS" ];then
 		f_usage
 	fi
+
+	OCFS2_UUID=`blkid |grep ${OCFS2_DEVICE}|cut -d' ' -f3|cut -d'"' -f2`
 }
 
 f_do_mkfs_and_mount()
@@ -240,9 +243,9 @@ f_run_data_test()
         echo -ne "Functionality Test For Regular File Among Nodes:">> ${DATA_LOG_FILE}
         echo >>${DATA_LOG_FILE}
         echo "==========================================================">>${DATA_LOG_FILE}
-	echo -e "Testing Binary:\t\t${INLINE_DATA_BIN} -i 1 -d ${OCFS2_DEVICE} ${MOUNT_POINT}">>${DATA_LOG_FILE}
+	echo -e "Testing Binary:\t\t${INLINE_DATA_BIN} -i 1 -u ${OCFS2_UUID} ${MOUNT_POINT}">>${DATA_LOG_FILE}
 
-	${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} -mca btl tcp,self -np ${MPI_RANKS} --host ${MPI_HOSTS} ${INLINE_DATA_BIN} -i 1 -d ${OCFS2_DEVICE} ${MOUNT_POINT}>>${DATA_LOG_FILE} 2>&1
+	${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} -mca btl tcp,self -np ${MPI_RANKS} --host ${MPI_HOSTS} ${INLINE_DATA_BIN} -i 1 -u ${OCFS2_UUID} ${MOUNT_POINT}>>${DATA_LOG_FILE} 2>&1
 	RET=$?
 	echo_status ${RET} |tee -a ${RUN_LOG_FILE}
 	exit_or_not ${RET}
@@ -254,9 +257,9 @@ f_run_data_test()
         echo -ne "Stress Test For Regular File Among Nodes:">> ${DATA_LOG_FILE}             
         echo >>${DATA_LOG_FILE}
         echo "==========================================================">>${DATA_LOG_FILE}
-	echo -e "Testing Binary:\t\t${INLINE_DATA_BIN} -i 200 -d ${OCFS2_DEVICE} ${MOUNT_POINT}">>${DATA_LOG_FILE}
+	echo -e "Testing Binary:\t\t${INLINE_DATA_BIN} -i 200 -u ${OCFS2_UUID} ${MOUNT_POINT}">>${DATA_LOG_FILE}
 
-        ${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} -mca btl tcp,self -np ${MPI_RANKS} --host ${MPI_HOSTS} ${INLINE_DATA_BIN} -i 200 -d ${OCFS2_DEVICE} ${MOUNT_POINT}>>${DATA_LOG_FILE} 2>&1
+        ${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} -mca btl tcp,self -np ${MPI_RANKS} --host ${MPI_HOSTS} ${INLINE_DATA_BIN} -i 200 -u ${OCFS2_UUID} ${MOUNT_POINT}>>${DATA_LOG_FILE} 2>&1
 	RET=$?
         echo_status ${RET} |tee -a ${RUN_LOG_FILE}
         exit_or_not ${RET}
@@ -271,9 +274,9 @@ f_run_dirs_test()
         echo -ne "Functionality Test For Directory Among Nodes:">> ${DIRS_LOG_FILE}
         echo >>${DIRS_LOG_FILE}
         echo "==========================================================">>${DIRS_LOG_FILE}
-	echo -e "Testing Binary:\t\t${INLINE_DIRS_BIN} -i 1 -s 20 -d ${OCFS2_DEVICE} ${MOUNT_POINT}">>${DIRS_LOG_FILE}
+	echo -e "Testing Binary:\t\t${INLINE_DIRS_BIN} -i 1 -s 20 -u ${OCFS2_UUID} ${MOUNT_POINT}">>${DIRS_LOG_FILE}
 
-	${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} -mca btl tcp,self -np ${MPI_RANKS} --host ${MPI_HOSTS}  ${INLINE_DIRS_BIN} -i 1 -s 20 -d ${OCFS2_DEVICE} ${MOUNT_POINT}>>${DIRS_LOG_FILE} 2>&1
+	${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} -mca btl tcp,self -np ${MPI_RANKS} --host ${MPI_HOSTS}  ${INLINE_DIRS_BIN} -i 1 -s 20 -u ${OCFS2_UUID} ${MOUNT_POINT}>>${DIRS_LOG_FILE} 2>&1
 	RET=$?
         echo_status ${RET} |tee -a ${RUN_LOG_FILE}
         exit_or_not ${RET}
@@ -285,9 +288,9 @@ f_run_dirs_test()
         echo -ne "Stress Test I Test For Directory Among Nodes:">> ${DIRS_LOG_FILE}
         echo >>${DIRS_LOG_FILE}
         echo "==========================================================">>${DIRS_LOG_FILE}
-	echo -e "Testing Binary:\t\t${INLINE_DIRS_BIN} -i 1 -s 100 -d ${OCFS2_DEVICE} ${MOUNT_POINT}">>${DIRS_LOG_FILE}
+	echo -e "Testing Binary:\t\t${INLINE_DIRS_BIN} -i 1 -s 100 -u ${OCFS2_UUID} ${MOUNT_POINT}">>${DIRS_LOG_FILE}
 
-        ${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} -mca btl tcp,self -np ${MPI_RANKS} --host ${MPI_HOSTS}  ${INLINE_DIRS_BIN} -i 1 -s 100 -d ${OCFS2_DEVICE} ${MOUNT_POINT}>>${DIRS_LOG_FILE} 2>&1
+        ${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} -mca btl tcp,self -np ${MPI_RANKS} --host ${MPI_HOSTS}  ${INLINE_DIRS_BIN} -i 1 -s 100 -u ${OCFS2_UUID} ${MOUNT_POINT}>>${DIRS_LOG_FILE} 2>&1
 	RET=$?
         echo_status ${RET} |tee -a ${RUN_LOG_FILE}
         exit_or_not ${RET}
@@ -299,9 +302,9 @@ f_run_dirs_test()
         echo -ne "Stress Test II Test For Directory Among Nodes:">> ${DIRS_LOG_FILE}
         echo >>${DIRS_LOG_FILE}
         echo "==========================================================">>${DIRS_LOG_FILE}
-	echo -e "Testing Binary:\t\t${INLINE_DIRS_BIN} -i 5 -s 20 -d ${OCFS2_DEVICE} ${MOUNT_POINT}">>${DIRS_LOG_FILE}
+	echo -e "Testing Binary:\t\t${INLINE_DIRS_BIN} -i 5 -s 20 -u ${OCFS2_UUID} ${MOUNT_POINT}">>${DIRS_LOG_FILE}
 
-        ${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} -mca btl tcp,self -np ${MPI_RANKS} --host ${MPI_HOSTS}  ${INLINE_DIRS_BIN} -i 5 -s 20 -d ${OCFS2_DEVICE} ${MOUNT_POINT}>>${DIRS_LOG_FILE} 2>&1
+        ${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} -mca btl tcp,self -np ${MPI_RANKS} --host ${MPI_HOSTS}  ${INLINE_DIRS_BIN} -i 5 -s 20 -u ${OCFS2_UUID} ${MOUNT_POINT}>>${DIRS_LOG_FILE} 2>&1
 	RET=$?
         echo_status ${RET} |tee -a ${RUN_LOG_FILE}
         exit_or_not ${RET}
-- 
1.5.5




More information about the Ocfs2-test-devel mailing list