This source file includes following definitions.
- main
- main
- test
- get_mounts
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 
  19 
  20 
  21 
  22 
  23 
  24 
  25 
  26 
  27 
  28 
  29 #include "opal_config.h"
  30 
  31 #include <stdio.h>
  32 #include <string.h>
  33 #include <stdlib.h>
  34 #include <dirent.h>
  35 
  36 #include <sys/param.h>
  37 #ifdef HAVE_SYS_MOUNT_H
  38 #include <sys/mount.h>
  39 #endif
  40 #ifdef HAVE_SYS_STATFS_H
  41 #include <sys/statfs.h>
  42 #endif
  43 #ifdef HAVE_SYS_VFS_H
  44 #include <sys/vfs.h>
  45 #endif
  46 
  47 #include "support.h"
  48 #include "opal/util/path.h"
  49 #include "opal/util/output.h"
  50 #include "opal/util/printf.h"
  51 
  52 #define DEBUG
  53 
  54 
  55 
  56 
  57 
  58 
  59 
  60 
  61 
  62 
  63 
  64 
  65 
  66 
  67 #if !defined(__linux__)
  68 int main(int argc, char* argv[])
  69 {
  70     if (argc > 1) {
  71         int i;
  72 
  73         printf("Interactive opal_path_nfs() test:\n");
  74         for (i = 1; i < argc; i++) {
  75             printf ("Is dir[%d]:%s one of the detected network file systems? %s\n",
  76                     i, argv[i], opal_path_nfs (argv[i], NULL) ? "Yes": "No");
  77         }
  78 
  79         return 0;
  80     }
  81 
  82     printf("No filename was given; nothing to do\n");
  83     return 77;
  84 }
  85 
  86 #else 
  87 
  88 static void test(char* file, bool expect);
  89 static void get_mounts (int * num_dirs, char ** dirs[], bool ** nfs);
  90 
  91 
  92 int main(int argc, char* argv[])
  93 {
  94     int num_dirs;
  95     char ** dirs;
  96     bool * nfs;
  97 
  98     test_init("opal_path_nfs()");
  99 #ifdef DEBUG
 100     printf ("Test usage: ./opal_path_nfs [DIR]\n");
 101     printf ("On Linux interprets output from mount(8) to check for nfs and verify opal_path_nfs()\n");
 102     printf ("Additionally, you may specify multiple DIR on the cmd-line, of which you the output\n");
 103 #endif
 104 
 105     if (1 < argc) {
 106         int i;
 107         for (i = 1; i < argc; i++)
 108             printf ("Is dir[%d]:%s one of the detected network file systems? %s\n",
 109                     i, argv[i], opal_path_nfs (argv[i], NULL) ? "Yes": "No");
 110     }
 111 
 112     get_mounts (&num_dirs, &dirs, &nfs);
 113     while (num_dirs--) {
 114         test (dirs[num_dirs], nfs[num_dirs]);
 115     }
 116 
 117     
 118     return test_finalize();
 119 }
 120 
 121 
 122 void test(char* file, bool expect)
 123 {
 124 #ifdef DEBUG
 125     printf ("test(): file:%s bool:%d\n",
 126             file, expect);
 127 #endif
 128     if (expect == opal_path_nfs (file, NULL)) {
 129         test_success();
 130     } else {
 131         char * msg;
 132         opal_asprintf(&msg, "Mismatch: input \"%s\", expected:%d got:%d\n",
 133                  file, expect, !expect);
 134         test_failure(msg);
 135         free(msg);
 136     }
 137 }
 138 
 139 void get_mounts (int * num_dirs, char ** dirs[], bool * nfs[])
 140 {
 141 #define SIZE 1024
 142     char * cmd = "mount | cut -f3,5 -d' ' > opal_path_nfs.out";
 143     int rc;
 144     int i;
 145     FILE * file;
 146     char ** dirs_tmp;
 147     bool * nfs_tmp;
 148     char buffer[SIZE];
 149     struct statfs mystatfs;
 150 
 151     rc = system (cmd);
 152 
 153     if (-1 == rc) {
 154         *num_dirs = 0;
 155         **dirs = NULL;
 156         *nfs = NULL;
 157     }
 158 
 159     
 160 
 161 
 162 
 163 
 164 
 165     file = fopen("opal_path_nfs.out", "r");
 166     int count = 0;
 167     while (NULL != fgets (buffer, SIZE, file)) {
 168         ++count;
 169     }
 170     printf("Found %d mounts\n", count);
 171 
 172     
 173     ++count;
 174 
 175     dirs_tmp = (char**) calloc (count, sizeof(char*));
 176     nfs_tmp = (bool*) calloc (count, sizeof(bool));
 177 
 178     i = 0;
 179     rc = 4711;
 180     rewind(file);
 181     
 182     while (i < count && NULL != fgets (buffer, SIZE, file)) {
 183         int mount_known;
 184         char fs[MAXNAMLEN];
 185 
 186         if (!dirs_tmp[i]) {
 187             dirs_tmp[i] = malloc (MAXNAMLEN);
 188         }
 189 
 190         if (2 != (rc = sscanf (buffer, "%s %s\n", dirs_tmp[i], fs))) {
 191             goto out;
 192         }
 193 
 194         
 195 
 196 
 197 
 198 
 199         if (0 == strcasecmp (fs, "rpc_pipefs")) {
 200             continue;
 201         }
 202 
 203         
 204 
 205         if (0 == strncasecmp(fs, "fuse.", 5)) {
 206             continue;
 207         }
 208 
 209         
 210 
 211         if (0 == strcasecmp(fs, "none")) {
 212             continue;
 213         }
 214 
 215         
 216         if (statfs (dirs_tmp[i], &mystatfs)) {
 217             continue;
 218         }
 219 
 220         
 221 
 222 
 223 
 224         for (mount_known = 0; mount_known < i; mount_known++) {
 225             
 226             if (0 == strcasecmp (dirs_tmp[mount_known], dirs_tmp[i])) {
 227 #ifdef DEBUG
 228                 printf ("get_mounts: already know dir[%d]:%s\n",
 229                         mount_known, dirs_tmp[mount_known]);
 230 #endif
 231                 break;
 232             }
 233         }
 234 
 235         nfs_tmp[mount_known] = false;
 236         if (0 == strcasecmp (fs, "nfs") ||
 237             0 == strcasecmp (fs, "nfs4") ||
 238             0 == strcasecmp (fs, "lustre") ||
 239             0 == strcasecmp (fs, "panfs") ||
 240             0 == strcasecmp (fs, "gpfs"))
 241             nfs_tmp[mount_known] = true;
 242 #ifdef DEBUG
 243         printf ("get_mounts: dirs[%d]:%s fs:%s nfs:%s\n",
 244                 mount_known, dirs_tmp[mount_known],
 245                 fs, nfs_tmp[mount_known] ? "Yes" : "No");
 246 #endif
 247 
 248         if (mount_known >= i)
 249             i++;
 250 
 251     }
 252 out:
 253     *num_dirs = i;
 254     *dirs = dirs_tmp;
 255     *nfs = nfs_tmp;
 256 }
 257 
 258 #endif