2014-12-05 23:11:32 +03:00
|
|
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
|
2010-02-11 02:18:29 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2015-06-24 06:59:57 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
2010-02-11 02:18:29 +03:00
|
|
|
* University of Stuttgart. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2015-06-24 06:59:57 +03:00
|
|
|
* Copyright (c) 2010 Oak Ridge National Laboratory.
|
2010-02-11 02:18:29 +03:00
|
|
|
* All rights reserved.
|
2014-01-10 04:13:10 +04:00
|
|
|
* Copyright (c) 2010-2014 Cisco Systems, Inc. All rights reserved.
|
2010-08-30 21:46:47 +04:00
|
|
|
* Copyright (c) 2010 IBM Corporation. All rights reserved.
|
2014-12-05 23:11:32 +03:00
|
|
|
* Copyright (c) 2014 Los Alamos National Security, LLC. All rights
|
|
|
|
* reserved.
|
2010-02-11 02:18:29 +03:00
|
|
|
* $COPYRIGHT$
|
2015-06-24 06:59:57 +03:00
|
|
|
*
|
2010-02-11 02:18:29 +03:00
|
|
|
* Additional copyrights may follow
|
2015-06-24 06:59:57 +03:00
|
|
|
*
|
2010-02-11 02:18:29 +03:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2010-07-28 18:20:58 +04:00
|
|
|
#include "opal_config.h"
|
2010-02-11 02:18:29 +03:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
|
2014-12-05 23:11:32 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
2014-12-06 08:54:41 +03:00
|
|
|
#ifdef HAVE_SYS_STATFS_H
|
|
|
|
#include <sys/statfs.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_VFS_H
|
|
|
|
#include <sys/vfs.h>
|
|
|
|
#endif
|
2014-12-05 23:11:32 +03:00
|
|
|
|
2010-02-11 02:18:29 +03:00
|
|
|
#include "support.h"
|
|
|
|
#include "opal/util/path.h"
|
|
|
|
#include "opal/util/output.h"
|
|
|
|
|
|
|
|
#define DEBUG
|
|
|
|
|
2014-01-10 04:13:10 +04:00
|
|
|
/*
|
|
|
|
* On Linux, if this test is run with no command line params, it will
|
|
|
|
* run "mount" and analyze the output. It will slurp up all mount
|
|
|
|
* points and figure out if they are network mounts or not. Then it
|
|
|
|
* will send each of the mount points through opal_path_nfs() and
|
|
|
|
* compare the answer it gets to the answer it slurped from the output
|
|
|
|
* of "mount".
|
|
|
|
*
|
|
|
|
* On all platforms, if you provide one or more command line options,
|
|
|
|
* each command line option is given to opal_path_nfs() and the result
|
|
|
|
* is sent to stdout.
|
|
|
|
*/
|
|
|
|
|
2010-07-23 17:15:24 +04:00
|
|
|
#if !defined(__linux__)
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2014-01-10 04:13:10 +04:00
|
|
|
if (argc > 1) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printf("Interactive opal_path_nfs() test:\n");
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
printf ("Is dir[%d]:%s one of the detected network file systems? %s\n",
|
|
|
|
i, argv[i], opal_path_nfs (argv[i]) ? "Yes": "No");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("No filename was given; nothing to do\n");
|
2010-07-23 17:15:24 +04:00
|
|
|
return 77;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* __linux__ */
|
|
|
|
|
2010-02-11 02:18:29 +03:00
|
|
|
static void test(char* file, bool expect);
|
|
|
|
static void get_mounts (int * num_dirs, char ** dirs[], bool ** nfs);
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
int num_dirs;
|
|
|
|
char ** dirs;
|
|
|
|
bool * nfs;
|
|
|
|
|
|
|
|
test_init("opal_path_nfs()");
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf ("Test usage: ./opal_path_nfs [DIR]\n");
|
|
|
|
printf ("On Linux interprets output from mount(8) to check for nfs and verify opal_path_nfs()\n");
|
|
|
|
printf ("Additionally, you may specify multiple DIR on the cmd-line, of which you the output\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (1 < argc) {
|
|
|
|
int i;
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
printf ("Is dir[%d]:%s one of the detected network file systems? %s\n",
|
|
|
|
i, argv[i], opal_path_nfs (argv[i]) ? "Yes": "No");
|
|
|
|
}
|
|
|
|
|
|
|
|
get_mounts (&num_dirs, &dirs, &nfs);
|
|
|
|
while (num_dirs--) {
|
|
|
|
test (dirs[num_dirs], nfs[num_dirs]);
|
|
|
|
}
|
2010-02-12 01:07:07 +03:00
|
|
|
|
2010-02-11 02:18:29 +03:00
|
|
|
/* All done */
|
|
|
|
return test_finalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void test(char* file, bool expect)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf ("test(): file:%s bool:%d\n",
|
|
|
|
file, expect);
|
2015-06-24 06:59:57 +03:00
|
|
|
#endif
|
2010-02-11 02:18:29 +03:00
|
|
|
if (expect == opal_path_nfs (file)) {
|
|
|
|
test_success();
|
2012-09-11 23:56:58 +04:00
|
|
|
} else {
|
2010-02-11 02:18:29 +03:00
|
|
|
char * msg;
|
|
|
|
asprintf(&msg, "Mismatch: input \"%s\", expected:%d got:%d\n",
|
|
|
|
file, expect, !expect);
|
|
|
|
test_failure(msg);
|
|
|
|
free(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void get_mounts (int * num_dirs, char ** dirs[], bool * nfs[])
|
|
|
|
{
|
|
|
|
#define MAX_DIR 256
|
|
|
|
#define SIZE 1024
|
|
|
|
char * cmd = "mount | cut -f3,5 -d' ' > opal_path_nfs.out";
|
|
|
|
int rc;
|
|
|
|
int i;
|
|
|
|
FILE * file;
|
|
|
|
char ** dirs_tmp;
|
|
|
|
bool * nfs_tmp;
|
|
|
|
char buffer[SIZE];
|
2014-12-06 08:50:40 +03:00
|
|
|
struct statfs mystatfs;
|
2010-02-11 02:18:29 +03:00
|
|
|
|
|
|
|
rc = system (cmd);
|
|
|
|
|
|
|
|
if (-1 == rc) {
|
|
|
|
*num_dirs = 0;
|
|
|
|
**dirs = NULL;
|
|
|
|
*nfs = NULL;
|
|
|
|
}
|
2014-12-05 23:11:32 +03:00
|
|
|
dirs_tmp = (char**) calloc (MAX_DIR, sizeof(char**));
|
2010-02-11 02:18:29 +03:00
|
|
|
nfs_tmp = (bool*) malloc (MAX_DIR * sizeof(bool));
|
|
|
|
|
|
|
|
file = fopen("opal_path_nfs.out", "r");
|
|
|
|
i = 0;
|
|
|
|
rc = 4711;
|
|
|
|
while (NULL != fgets (buffer, SIZE, file)) {
|
2010-02-18 21:05:55 +03:00
|
|
|
int mount_known;
|
2010-02-11 02:18:29 +03:00
|
|
|
char fs[MAXNAMLEN];
|
|
|
|
|
2014-12-05 23:11:32 +03:00
|
|
|
if (!dirs_tmp[i]) {
|
|
|
|
dirs_tmp[i] = malloc (MAXNAMLEN);
|
|
|
|
}
|
|
|
|
|
2010-02-11 02:18:29 +03:00
|
|
|
if (2 != (rc = sscanf (buffer, "%s %s\n", dirs_tmp[i], fs))) {
|
|
|
|
goto out;
|
|
|
|
}
|
2010-02-12 01:07:07 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* rpc_pipefs is a FS mounted on /var/lib/nfs/rpc_pipefs for NFS4
|
|
|
|
* Cannot distinguish it from NFS in opal_path_nfs, therefore just
|
|
|
|
* disregard it, as it is NOT an parallel filesystem...
|
|
|
|
*/
|
2012-09-12 18:38:37 +04:00
|
|
|
if (0 == strcasecmp (fs, "rpc_pipefs")) {
|
2010-02-12 01:07:07 +03:00
|
|
|
continue;
|
2012-09-12 18:38:37 +04:00
|
|
|
}
|
|
|
|
|
2014-07-08 17:30:49 +04:00
|
|
|
/* Per https://svn.open-mpi.org/trac/ompi/ticket/4767, Linux
|
|
|
|
lies about fuse filesystems. Skip them. */
|
|
|
|
if (0 == strncasecmp(fs, "fuse.", 5)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-09-12 18:38:37 +04:00
|
|
|
/* If we get an fs type of "none", skip it (e.g.,
|
|
|
|
http://www.open-mpi.org/community/lists/devel/2012/09/11493.php) */
|
|
|
|
if (0 == strcasecmp(fs, "none")) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-02-12 01:07:07 +03:00
|
|
|
|
2014-12-05 23:11:32 +03:00
|
|
|
/* If we can not stat the fs, skip it */
|
2014-12-06 08:50:40 +03:00
|
|
|
if (statfs (dirs_tmp[i], &mystatfs)) {
|
2014-12-05 23:11:32 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-02-18 21:05:55 +03:00
|
|
|
/*
|
|
|
|
* Later mounts override earlier mounts
|
|
|
|
* (e.g. nfs-mount of /, vs. initial rootfs-mount of /).
|
|
|
|
*/
|
|
|
|
for (mount_known = 0; mount_known < i; mount_known++) {
|
|
|
|
/* If we know this mount-point, then exit early */
|
|
|
|
if (0 == strcasecmp (dirs_tmp[mount_known], dirs_tmp[i])) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf ("get_mounts: already know dir[%d]:%s\n",
|
|
|
|
mount_known, dirs_tmp[mount_known]);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nfs_tmp[mount_known] = false;
|
2010-02-11 02:18:29 +03:00
|
|
|
if (0 == strcasecmp (fs, "nfs") ||
|
2012-02-16 07:00:07 +04:00
|
|
|
0 == strcasecmp (fs, "nfs4") ||
|
2010-02-11 02:18:29 +03:00
|
|
|
0 == strcasecmp (fs, "lustre") ||
|
2010-08-26 14:10:16 +04:00
|
|
|
0 == strcasecmp (fs, "panfs") ||
|
|
|
|
0 == strcasecmp (fs, "gpfs"))
|
2010-02-18 21:05:55 +03:00
|
|
|
nfs_tmp[mount_known] = true;
|
2010-02-11 02:18:29 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf ("get_mounts: dirs[%d]:%s fs:%s nfs:%s\n",
|
2010-02-18 21:05:55 +03:00
|
|
|
mount_known, dirs_tmp[mount_known],
|
|
|
|
fs, nfs_tmp[mount_known] ? "Yes" : "No");
|
2010-02-11 02:18:29 +03:00
|
|
|
#endif
|
2010-02-18 21:05:55 +03:00
|
|
|
|
|
|
|
if (mount_known >= i)
|
|
|
|
i++;
|
|
|
|
|
2010-02-11 02:18:29 +03:00
|
|
|
}
|
|
|
|
out:
|
|
|
|
*num_dirs = i;
|
|
|
|
*dirs = dirs_tmp;
|
|
|
|
*nfs = nfs_tmp;
|
|
|
|
}
|
|
|
|
|
2010-07-23 17:15:24 +04:00
|
|
|
#endif /* __linux__ */
|