1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
5 * Author: Robert Read <rread@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Lustre; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include <sys/mount.h>
34 #include <portals/ptlctl.h>
39 static char *progname = NULL;
42 update_mtab_entry(char *spec, char *node, char *type, char *opts,
43 int flags, int freq, int pass)
48 mnt.mnt_fsname = spec;
51 mnt.mnt_opts = opts ? opts : "";
53 mnt.mnt_passno = pass;
56 fp = setmntent(MOUNTED, "a+");
58 fprintf(stderr, "%s: setmntent(%s): %s:",
59 progname, MOUNTED, strerror (errno));
61 if ((addmntent (fp, &mnt)) == 1) {
62 fprintf(stderr, "%s: addmntent: %s:",
63 progname, strerror (errno));
71 init_options(struct lustre_mount_data *lmd)
73 memset(lmd, 0, sizeof(*lmd));
74 lmd->lmd_magic = LMD_MAGIC;
75 lmd->lmd_server_nid = PTL_NID_ANY;
76 lmd->lmd_local_nid = PTL_NID_ANY;
77 lmd->lmd_port = 988; /* XXX define LUSTRE_DEFAULT_PORT */
78 lmd->lmd_nal = SOCKNAL;
83 print_options(struct lustre_mount_data *lmd)
85 printf("mds: %s\n", lmd->lmd_mds);
86 printf("profile: %s\n", lmd->lmd_profile);
87 printf("server_nid: "LPX64"\n", lmd->lmd_server_nid);
88 printf("local_nid: "LPX64"\n", lmd->lmd_local_nid);
89 printf("nal: %d\n", lmd->lmd_nal);
90 printf("server_ipaddr: 0x%x\n", lmd->lmd_server_ipaddr);
91 printf("port: %d\n", lmd->lmd_port);
97 parse_options(char * options, struct lustre_mount_data *lmd)
104 /* parsing ideas here taken from util-linux/mount/nfsmount.c */
105 for (opt = strtok(options, ","); opt; opt = strtok(NULL, ",")) {
106 if ((opteq = strchr(opt, '='))) {
107 val = atoi(opteq + 1);
109 if (!strcmp(opt, "nettype")) {
110 lmd->lmd_nal = ptl_name2nal(opteq+1);
111 } else if(!strcmp(opt, "local_nid")) {
112 if (ptl_parse_nid(&nid, opteq+1) != 0) {
113 fprintf (stderr, "%s: "
114 "can't parse NID %s\n",
119 lmd->lmd_local_nid = nid;
120 } else if(!strcmp(opt, "server_nid")) {
121 if (ptl_parse_nid(&nid, opteq+1) != 0) {
122 fprintf (stderr, "%s: "
123 "can't parse NID %s\n",
127 lmd->lmd_server_nid = nid;
128 } else if (!strcmp(opt, "port")) {
133 if (!strncmp(opt, "no", 2)) {
137 if (!strcmp(opt, "debug")) {
146 get_local_elan_id(char *fname, char *buf)
148 FILE *fp = fopen(fname, "r");
154 rc = fscanf(fp, "NodeId %255s", buf);
158 return (rc == 1) ? 0 : -1;
162 set_local(struct lustre_mount_data *lmd)
165 * XXX PtlGetId() will be safer if portals is loaded and
166 * initialised correctly at this time... */
171 if (lmd->lmd_local_nid != PTL_NID_ANY)
174 memset(buf, 0, sizeof(buf));
176 if (lmd->lmd_nal == SOCKNAL || lmd->lmd_nal == TCPNAL) {
177 rc = gethostname(buf, sizeof(buf) - 1);
179 fprintf (stderr, "%s: can't get local buf: %d\n",
183 } else if (lmd->lmd_nal == QSWNAL) {
184 char *pfiles[] = {"/proc/qsnet/elan3/device0/position",
185 "/proc/qsnet/elan4/device0/position",
186 "/proc/elan/device0/position",
191 rc = get_local_elan_id(pfiles[i], buf);
192 } while (rc != 0 && pfiles[++i] != NULL);
195 fprintf(stderr, "%s: can't read Elan ID from /proc\n",
202 if (ptl_parse_nid (&nid, buf) != 0) {
203 fprintf (stderr, "%s: can't parse NID %s\n", progname, buf);
207 lmd->lmd_local_nid = nid;
212 set_peer(char *hostname, struct lustre_mount_data *lmd)
217 if (lmd->lmd_nal == SOCKNAL || lmd->lmd_nal == TCPNAL) {
218 if (lmd->lmd_server_nid == PTL_NID_ANY) {
219 if (ptl_parse_nid (&nid, hostname) != 0) {
220 fprintf (stderr, "%s: can't parse NID %s\n",
224 lmd->lmd_server_nid = nid;
227 if (ptl_parse_ipaddr(&lmd->lmd_server_ipaddr, hostname) != 0) {
228 fprintf (stderr, "%s: can't parse host %s\n",
232 } else if (lmd->lmd_nal == QSWNAL) {
234 rc = sscanf(hostname, "%*[^0-9]%63[0-9]", buf);
236 fprintf (stderr, "%s: can't get elan id from host %s\n",
240 if (ptl_parse_nid (&nid, buf) != 0) {
241 fprintf (stderr, "%s: can't parse NID %s\n",
245 lmd->lmd_server_nid = nid;
253 build_data(char *source, char *options, struct lustre_mount_data *lmd)
256 char *hostname = NULL;
258 char *profile = NULL;
262 if (lmd_bad_magic(lmd))
265 if (strlen(source) > sizeof(target) + 1) {
266 fprintf(stderr, "%s: "
267 "exessively long host:/mds/profile argument\n",
271 strcpy(target, source);
272 if ((s = strchr(target, ':'))) {
279 if ((s = strchr(mds, '/'))) {
283 fprintf(stderr, "%s: "
284 "directory to mount not in "
285 "host:/mds/profile format\n",
290 fprintf(stderr, "%s: "
291 "directory to mount not in host:/mds/profile format\n",
296 printf("host: %s\nmds: %s\nprofile: %s\n", hostname, mds,
299 rc = parse_options(options, lmd);
307 rc = set_peer(hostname, lmd);
310 if (strlen(mds) > sizeof(lmd->lmd_mds) + 1) {
311 fprintf(stderr, "%s: mds name too long\n", progname);
314 strcpy(lmd->lmd_mds, mds);
316 if (strlen(profile) > sizeof(lmd->lmd_profile) + 1) {
317 fprintf(stderr, "%s: profile name too long\n", progname);
320 strcpy(lmd->lmd_profile, profile);
328 main(int argc, char * const argv[])
330 char * source = argv[1];
331 char * target = argv[2];
335 struct lustre_mount_data lmd;
339 progname = strrchr(argv[0], '/');
340 progname = progname ? progname + 1 : argv[0];
342 while ((opt = getopt(argc, argv, "vno:")) != EOF) {
346 printf("verbose: %d\n", verbose);
351 printf("nomtab: %d\n", nomtab);
366 "%s: too few arguments\n"
367 "Usage: %s <source> <target> [-v] [-n] [-o ...]\n",
373 for (i = 0; i < argc; i++) {
374 printf("arg[%d] = %s\n", i, argv[i]);
378 rc = build_data(source, options, &lmd);
384 printf("%s: debug mode, not mounting\n", progname);
388 rc = mount(source, target, "lustre", 0, (void *)&lmd);
393 fprintf(stderr, "Are the lustre modules loaded?\n"
394 "Check /etc/modules.conf and /proc/filesystems\n");
396 update_mtab_entry(source, target, "lustre", options, 0, 0, 0);