Whamcloud - gitweb
- new flag '--ssh <ssh_cmd>' for replay_single and recovery-small: still defaults...
authorccooper <ccooper>
Thu, 22 Apr 2004 22:41:04 +0000 (22:41 +0000)
committerccooper <ccooper>
Thu, 22 Apr 2004 22:41:04 +0000 (22:41 +0000)
- use safe_strncpy where applicable
- replace hard-coded string lengths with some defines

lustre/liblustre/tests/recovery_small.c
lustre/liblustre/tests/replay_single.c
lustre/liblustre/tests/sanity.c
lustre/liblustre/tests/test_common.c
lustre/liblustre/tests/test_common.h

index 5aed06c..baa4877 100644 (file)
@@ -39,6 +39,8 @@
 
 #include "test_common.h"
 
 
 #include "test_common.h"
 
+#define MAX_STRING_SIZE 2048
+
 static struct {
         const char   *name;
         unsigned long code;
 static struct {
         const char   *name;
         unsigned long code;
@@ -52,6 +54,7 @@ static struct {
 static int drop_index = 0;
 
 static char mds_server[1024] = {0, };
 static int drop_index = 0;
 
 static char mds_server[1024] = {0, };
+static char ssh_cmd[MAX_STRING_SIZE] = {0,};
 
 int do_stat(const char *name, struct stat *buf)
 {
 
 int do_stat(const char *name, struct stat *buf)
 {
@@ -121,14 +124,14 @@ void cleanup_dir(const char *path)
 
 #define FAIL()                                                             \
     do {                                                                   \
 
 #define FAIL()                                                             \
     do {                                                                   \
-        char cmd[1024];                                                    \
+        char cmd[MAX_STRING_SIZE];                                         \
         int rc;                                                            \
                                                                            \
         if (drop_arr[drop_index].name) {                                   \
             printf("server drops next %s\n", drop_arr[drop_index].name);   \
             sprintf(cmd,                                                   \
         int rc;                                                            \
                                                                            \
         if (drop_arr[drop_index].name) {                                   \
             printf("server drops next %s\n", drop_arr[drop_index].name);   \
             sprintf(cmd,                                                   \
-                    "ssh %s \"echo %lu > /proc/sys/lustre/fail_loc\"",     \
-                    mds_server, drop_arr[drop_index].code);                \
+                    "%s %s \"echo %lu > /proc/sys/lustre/fail_loc\"",      \
+                    ssh_cmd, mds_server, drop_arr[drop_index].code);       \
             if (system(cmd)) {                                             \
                 printf("error excuting remote command: %d\n", rc);         \
                 exit(rc);                                                  \
             if (system(cmd)) {                                             \
                 printf("error excuting remote command: %d\n", rc);         \
                 exit(rc);                                                  \
@@ -141,8 +144,8 @@ void cleanup_dir(const char *path)
         char cmd[1024];                                                    \
                                                                            \
         if (drop_arr[drop_index].name) {                                   \
         char cmd[1024];                                                    \
                                                                            \
         if (drop_arr[drop_index].name) {                                   \
-            sprintf(cmd, "ssh %s \"echo 0 > /proc/sys/lustre/fail_loc\"",  \
-                    mds_server);                                           \
+            sprintf(cmd, "%s %s \"echo 0 > /proc/sys/lustre/fail_loc\"",   \
+                    ssh_cmd, mds_server);                                  \
             system(cmd);                                                   \
         }                                                                  \
     } while (0)
             system(cmd);                                                   \
         }                                                                  \
     } while (0)
@@ -313,6 +316,7 @@ int main(int argc, char * argv[])
         static struct option long_opts[] = {
                 {"target", 1, 0, 0},
                 {"dumpfile", 1, 0, 0},
         static struct option long_opts[] = {
                 {"target", 1, 0, 0},
                 {"dumpfile", 1, 0, 0},
+                {"ssh", 1, 0, 0},
                 {0, 0, 0, 0}
         };
 
                 {0, 0, 0, 0}
         };
 
@@ -329,12 +333,14 @@ int main(int argc, char * argv[])
                                 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
                         } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
                                 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
                                 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
                         } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
                                 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
+                        } else if (!strcmp(long_opts[opt_index].name, "ssh")) {
+                                safe_strncpy(ssh_cmd, optarg, MAX_STRING_SIZE);
                         } else
                                 usage(argv[0]);
                         break;
                 }
                 case 's':
                         } else
                                 usage(argv[0]);
                         break;
                 }
                 case 's':
-                        strcpy(mds_server, optarg);
+                        safe_strncpy(mds_server, optarg, MAX_STRING_SIZE);
                         break;
                 default:
                         usage(argv[0]);
                         break;
                 default:
                         usage(argv[0]);
@@ -347,9 +353,14 @@ int main(int argc, char * argv[])
         if (strlen(mds_server) == 0)
                 usage(argv[0]);
 
         if (strlen(mds_server) == 0)
                 usage(argv[0]);
 
-        sprintf(cmd, "ssh %s cat /dev/null", mds_server);
+        /* default to using ssh */
+        if (!strlen(ssh_cmd)) {
+                safe_strncpy(ssh_cmd, "ssh", MAX_STRING_SIZE);
+        }
+
+        sprintf(cmd, "%s %s cat /dev/null", ssh_cmd, mds_server);
         if (system(cmd)) {
         if (system(cmd)) {
-                printf("can't access server node: %s\n", mds_server);
+                printf("Can't access server node: %s using method: %s\n", mds_server, ssh_cmd);
                 exit(-1);
         }
 
                 exit(-1);
         }
 
index 6645056..3394008 100644 (file)
 
 #include "test_common.h"
 
 
 #include "test_common.h"
 
+#define MAX_STRING_SIZE 2048
 
 
-
-static char mds_server[1024] = {0,};
-static char barrier_script[1024] = {0,};
-static char failover_script[1024] = {0,};
-static char barrier_cmd[1024] = {0,};
-static char failover_cmd[1024] = {0,};
+static char mds_server[MAX_STRING_SIZE] = {0,};
+static char barrier_script[MAX_STRING_SIZE] = {0,};
+static char failover_script[MAX_STRING_SIZE] = {0,};
+static char barrier_cmd[MAX_STRING_SIZE] = {0,};
+static char failover_cmd[MAX_STRING_SIZE] = {0,};
+static char ssh_cmd[MAX_STRING_SIZE] = {0,};
 
 static void replay_barrier()
 {
 
 static void replay_barrier()
 {
@@ -315,19 +316,19 @@ extern void __liblustre_cleanup_(void);
 void usage(const char *cmd)
 {
         printf("Usage: \t%s --target mdsnid:/mdsname/profile -s mds_hostname "
 void usage(const char *cmd)
 {
         printf("Usage: \t%s --target mdsnid:/mdsname/profile -s mds_hostname "
-                "-b \"barrier cmd\" -f \"failover cmd\"\n", cmd);
+                "-b \"barrier cmd\" -f \"failover cmd\" --ssh \"ssh_cmd\"\n", cmd);
         printf("       \t%s --dumpfile dumpfile -s mds_hostname -b \"barrier cmd\" "
         printf("       \t%s --dumpfile dumpfile -s mds_hostname -b \"barrier cmd\" "
-                "-f \"failover cmd\"\n", cmd);
+                "-f \"failover cmd\" --ssh \"ssh_cmd\"\n", cmd);
         exit(-1);
 }
 
 void test_ssh()
 {
         exit(-1);
 }
 
 void test_ssh()
 {
-        char cmd[1024];
+        char cmd[MAX_STRING_SIZE];
 
 
-        sprintf(cmd, "ssh %s cat /dev/null", mds_server);
+        sprintf(cmd, "%s %s cat /dev/null", ssh_cmd, mds_server);
         if (system(cmd)) {
         if (system(cmd)) {
-                printf("ssh can't access server node: %s\n", mds_server);
+                printf("Can't access server node: %s using method: %s\n", mds_server, ssh_cmd);
                 exit(-1);
         }
 }
                 exit(-1);
         }
 }
@@ -338,6 +339,7 @@ int main(int argc, char * const argv[])
         static struct option long_opts[] = {
                 {"target", 1, 0, 0},
                 {"dumpfile", 1, 0, 0},
         static struct option long_opts[] = {
                 {"target", 1, 0, 0},
                 {"dumpfile", 1, 0, 0},
+                {"ssh", 1, 0, 0},
                 {0, 0, 0, 0}
         };
 
                 {0, 0, 0, 0}
         };
 
@@ -354,18 +356,20 @@ int main(int argc, char * const argv[])
                                 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
                         } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
                                 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
                                 setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
                         } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
                                 setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
+                        } else if (!strcmp(long_opts[opt_index].name, "ssh")) {
+                                safe_strncpy(ssh_cmd, optarg, MAX_STRING_SIZE);
                         } else
                                 usage(argv[0]);
                         break;
                 }
                 case 's':
                         } else
                                 usage(argv[0]);
                         break;
                 }
                 case 's':
-                        strcpy(mds_server, optarg);
+                        safe_strncpy(mds_server, optarg, MAX_STRING_SIZE);
                         break;
                 case 'b':
                         break;
                 case 'b':
-                        strcpy(barrier_script, optarg);
+                        safe_strncpy(barrier_script, optarg, MAX_STRING_SIZE);
                         break;
                 case 'f':
                         break;
                 case 'f':
-                        strcpy(failover_script, optarg);
+                        safe_strncpy(failover_script, optarg, MAX_STRING_SIZE);
                         break;
                 default:
                         usage(argv[0]);
                         break;
                 default:
                         usage(argv[0]);
@@ -378,11 +382,18 @@ int main(int argc, char * const argv[])
             !strlen(failover_script))
                 usage(argv[0]);
 
             !strlen(failover_script))
                 usage(argv[0]);
 
+        /* default to using ssh */
+        if (!strlen(ssh_cmd)) {
+                safe_strncpy(ssh_cmd, "ssh", MAX_STRING_SIZE);
+        }
+
         test_ssh();
 
         /* prepare remote command */
         test_ssh();
 
         /* prepare remote command */
-        sprintf(barrier_cmd, "ssh %s \"%s\"", mds_server, barrier_script);
-        sprintf(failover_cmd, "ssh %s \"%s\"", mds_server, failover_script);
+        sprintf(barrier_cmd, "%s %s \"%s\"", 
+                ssh_cmd, mds_server, barrier_script);
+        sprintf(failover_cmd, "%s %s \"%s\"", 
+                ssh_cmd, mds_server, failover_script);
 
         setenv(ENV_LUSTRE_TIMEOUT, "10", 1);
 
 
         setenv(ENV_LUSTRE_TIMEOUT, "10", 1);
 
index 944ae9c..cb42afe 100644 (file)
@@ -105,6 +105,8 @@ void t4()
 #define PAGE_SIZE (4096)
 #define _npages (2048)
 
 #define PAGE_SIZE (4096)
 #define _npages (2048)
 
+#define MAX_PATH_LENGTH 4096
+
 static int _buffer[_npages][PAGE_SIZE/sizeof(int)];
 
 /* pos:   i/o start from
 static int _buffer[_npages][PAGE_SIZE/sizeof(int)];
 
 /* pos:   i/o start from
@@ -282,11 +284,11 @@ void t10()
 void t11()
 {
         char *base="/mnt/lustre";
 void t11()
 {
         char *base="/mnt/lustre";
-        char path[4096], path2[4096];
+        char path[MAX_PATH_LENGTH], path2[MAX_PATH_LENGTH];
         int i, j, level = 5, nreg = 5;
         ENTRY("deep tree");
 
         int i, j, level = 5, nreg = 5;
         ENTRY("deep tree");
 
-        strcpy(path, base);
+        safe_strncpy(path, base, MAX_PATH_LENGTH);
 
         for (i = 0; i < level; i++) {
                 for (j = 0; j < nreg; j++) {
 
         for (i = 0; i < level; i++) {
                 for (j = 0; j < nreg; j++) {
@@ -299,7 +301,7 @@ void t11()
         }
 
         for (i = level; i > 0; i--) {
         }
 
         for (i = level; i > 0; i--) {
-                strcpy(path, base);
+                safe_strncpy(path, base, MAX_PATH_LENGTH);
                 for (j = 1; j < i; j++)
                         strcat(path, "/dir");
                 
                 for (j = 1; j < i; j++)
                         strcat(path, "/dir");
                 
index a87f0fa..a216d07 100644 (file)
@@ -313,3 +313,16 @@ void t_ls(int fd, char *buf, int size)
                EXIT(-1);
        }
 }
                EXIT(-1);
        }
 }
+
+char *safe_strncpy(char *dst, char *src, int max_size)
+{
+       int src_size;
+       src_size=strlen(src);
+       if (src_size >= max_size) {
+        src_size=max_size-1;
+       }
+       memcpy(dst, src, src_size);
+       dst[src_size]=0;
+
+       return(dst);
+}
index c3687b9..73fe391 100644 (file)
@@ -30,4 +30,6 @@ void t_grep(const char *path, char *str);
 void t_grep_v(const char *path, char *str);
 void t_ls(int fd, char *buf, int size);
 
 void t_grep_v(const char *path, char *str);
 void t_ls(int fd, char *buf, int size);
 
+char *safe_strncpy(char *dst, char *src, int max_size);
+
 #endif
 #endif