1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/utils/lshowmount.h
38 * Author: Herb Wartens <wartens2@llnl.gov>
39 * Author: Jim Garlick <garlick@llnl.gov>
54 #include <arpa/inet.h>
62 "/proc/fs/lustre/mgs", \
63 "/proc/fs/lustre/mdt", \
64 "/proc/fs/lustre/obdfilter", \
67 #define PROC_EXPORTS_TMPL "%s/%s/exports"
68 #define PROC_UUID_TMPL "%s/%s/uuid"
70 static void print_nids(NIDList nidlist, int lookup, int enumerate, int indent);
71 static int lshowmount(int lookup, int enumerate, int verbose);
72 static void read_exports(char *exports, NIDList nidlist);
76 #define OPTIONS "ehlv"
77 static struct option long_options[] = {
78 {"enumerate", no_argument, 0, 'e'},
79 {"help", no_argument, 0, 'h'},
80 {"lookup", no_argument, 0, 'l'},
81 {"verbose", no_argument, 0, 'v'},
85 static void usage(void)
87 fprintf(stderr, "usage: %s [-e] [-h] [-l] [-v]\n", prog);
91 int main(int argc, char **argv)
98 prog = basename(argv[0]);
100 while ((opt = getopt_long(argc, argv, OPTIONS, long_options, &optidx)) != -1) {
102 case 'e': /* --enumerate */
105 case 'l': /* --lookup */
108 case 'v': /* --verbose */
111 case 'h': /* --help */
117 if (lshowmount(lopt, eopt, vopt) == 0) {
118 fprintf(stderr, "%s: lustre server modules not loaded\n", prog);
124 static void print_nids(NIDList nidlist, int lookup, int enumerate, int indent)
126 char *s, *sep = "\n", *pfx = "";
129 nl_lookup_ip(nidlist);
132 if (nl_count(nidlist) > 0) {
138 s = nl_string(nidlist, sep);
140 s = nl_xstring(nidlist, sep);
141 printf("%s%s\n", pfx, s);
146 static int lshowmount(int lookup, int enumerate, int verbose)
148 char *dirs[] = PROC_DIRS;
149 char exp[PATH_MAX + 1];
150 NIDList nidlist = NULL;
157 nidlist = nl_create();
158 for (i = 0; dirs[i] != NULL; i++) {
159 if ((topdirp = opendir(dirs[i])) == NULL)
161 while ((dp = readdir(topdirp))) {
162 if (dp->d_type != DT_DIR)
164 if (!strcmp(dp->d_name, "."))
166 if (!strcmp(dp->d_name, ".."))
168 sprintf(exp, PROC_EXPORTS_TMPL, dirs[i], dp->d_name);
170 nidlist = nl_create();
171 read_exports(exp, nidlist);
172 printf("%s:\n", dp->d_name);
173 print_nids(nidlist, lookup, enumerate, 1);
176 read_exports(exp, nidlist);
182 print_nids(nidlist, lookup, enumerate, 0);
188 static int empty_proc_file(char *path)
194 if ((fd = open(path, O_RDONLY)) < 0 || read(fd, buf, sizeof(buf)) <= 0)
201 static void read_exports(char *exports, NIDList nidlist)
205 char path[PATH_MAX + 1];
207 if ((dirp = opendir(exports))) {
208 while ((dp = readdir(dirp))) {
209 if (dp->d_type != DT_DIR)
211 if (!strcmp(dp->d_name, "."))
213 if (!strcmp(dp->d_name, ".."))
215 if (strchr(dp->d_name, '@') == NULL)
217 sprintf(path, PROC_UUID_TMPL, exports, dp->d_name);
218 if (empty_proc_file(path))
221 nl_add(nidlist, dp->d_name);