4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * lustre/utils/lshowmount.h
36 * Author: Herb Wartens <wartens2@llnl.gov>
37 * Author: Jim Garlick <garlick@llnl.gov>
52 #include <arpa/inet.h>
60 "/proc/fs/lustre/mgs", \
61 "/proc/fs/lustre/mdt", \
62 "/proc/fs/lustre/obdfilter", \
65 #define PROC_EXPORTS_TMPL "%s/%s/exports"
66 #define PROC_UUID_TMPL "%s/%s/uuid"
68 static void print_nids(NIDList nidlist, int lookup, int enumerate, int indent);
69 static int lshowmount(int lookup, int enumerate, int verbose);
70 static void read_exports(char *exports, NIDList nidlist);
74 #define OPTIONS "ehlv"
75 static struct option long_options[] = {
76 {"enumerate", no_argument, 0, 'e'},
77 {"help", no_argument, 0, 'h'},
78 {"lookup", no_argument, 0, 'l'},
79 {"verbose", no_argument, 0, 'v'},
83 static void usage(void)
85 fprintf(stderr, "usage: %s [-e] [-h] [-l] [-v]\n", prog);
89 int main(int argc, char **argv)
96 prog = basename(argv[0]);
98 while ((opt = getopt_long(argc, argv, OPTIONS, long_options, &optidx)) != -1) {
100 case 'e': /* --enumerate */
103 case 'l': /* --lookup */
106 case 'v': /* --verbose */
109 case 'h': /* --help */
115 if (lshowmount(lopt, eopt, vopt) == 0) {
116 fprintf(stderr, "%s: lustre server modules not loaded\n", prog);
122 static void print_nids(NIDList nidlist, int lookup, int enumerate, int indent)
124 char *s, *sep = "\n", *pfx = "";
127 nl_lookup_ip(nidlist);
130 if (nl_count(nidlist) > 0) {
136 s = nl_string(nidlist, sep);
138 s = nl_xstring(nidlist, sep);
139 printf("%s%s\n", pfx, s);
144 static int lshowmount(int lookup, int enumerate, int verbose)
146 char *dirs[] = PROC_DIRS;
147 char exp[PATH_MAX + 1];
148 NIDList nidlist = NULL;
155 nidlist = nl_create();
156 for (i = 0; dirs[i] != NULL; i++) {
157 if ((topdirp = opendir(dirs[i])) == NULL)
159 while ((dp = readdir(topdirp))) {
160 if (dp->d_type != DT_DIR)
162 if (!strcmp(dp->d_name, "."))
164 if (!strcmp(dp->d_name, ".."))
166 sprintf(exp, PROC_EXPORTS_TMPL, dirs[i], dp->d_name);
168 nidlist = nl_create();
169 read_exports(exp, nidlist);
170 printf("%s:\n", dp->d_name);
171 print_nids(nidlist, lookup, enumerate, 1);
174 read_exports(exp, nidlist);
180 print_nids(nidlist, lookup, enumerate, 0);
186 static int empty_proc_file(char *path)
192 if ((fd = open(path, O_RDONLY)) < 0 || read(fd, buf, sizeof(buf)) <= 0)
199 static void read_exports(char *exports, NIDList nidlist)
203 char path[PATH_MAX + 1];
205 if ((dirp = opendir(exports))) {
206 while ((dp = readdir(dirp))) {
207 if (dp->d_type != DT_DIR)
209 if (!strcmp(dp->d_name, "."))
211 if (!strcmp(dp->d_name, ".."))
213 if (strchr(dp->d_name, '@') == NULL)
215 sprintf(path, PROC_UUID_TMPL, exports, dp->d_name);
216 if (empty_proc_file(path))
219 nl_add(nidlist, dp->d_name);