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>
41 update_mtab_entry(char *spec, char *node, char *type, char *opts,
42 int flags, int freq, int pass)
47 mnt.mnt_fsname = spec;
50 mnt.mnt_opts = opts ? opts : "";
52 mnt.mnt_passno = pass;
55 fp = setmntent(MOUNTED, "a+");
57 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
60 if ((addmntent (fp, &mnt)) == 1) {
61 fprintf(stderr, "addmntent: %s:",
70 init_options(struct lustre_mount_data *lmd)
72 memset(lmd, 0, sizeof(lmd));
73 lmd->lmd_server_nid = PTL_NID_ANY;
74 lmd->lmd_local_nid = PTL_NID_ANY;
75 lmd->lmd_port = 988; /* XXX define LUSTRE_DEFAULT_PORT */
76 lmd->lmd_nal = SOCKNAL;
81 print_options(struct lustre_mount_data *lmd)
83 printf("mds: %s\n", lmd->lmd_mds);
84 printf("profile: %s\n", lmd->lmd_profile);
85 printf("server_nid: "LPX64"\n", lmd->lmd_server_nid);
86 printf("local_nid: "LPX64"\n", lmd->lmd_local_nid);
87 printf("nal: %d\n", lmd->lmd_nal);
88 printf("server_ipaddr: 0x%x\n", lmd->lmd_server_ipaddr);
89 printf("port: %d\n", lmd->lmd_port);
95 parse_options(char * options, struct lustre_mount_data *lmd)
102 /* parsing ideas here taken from util-linux/mount/nfsmount.c */
103 for (opt = strtok(options, ","); opt; opt = strtok(NULL, ",")) {
104 if ((opteq = strchr(opt, '='))) {
105 val = atoi(opteq + 1);
107 if (!strcmp(opt, "nettype")) {
108 lmd->lmd_nal = ptl_name2nal(opteq+1);
109 } else if(!strcmp(opt, "local_nid")) {
110 if (ptl_parse_nid(&nid, opteq+1) != 0) {
111 fprintf (stderr, "mount: "
112 "can't parse NID %s\n",
116 lmd->lmd_local_nid = nid;
117 } else if(!strcmp(opt, "server_nid")) {
118 if (ptl_parse_nid(&nid, opteq+1) != 0) {
119 fprintf (stderr, "mount: "
120 "can't parse NID %s\n",
124 lmd->lmd_server_nid = nid;
125 } else if (!strcmp(opt, "port")) {
130 if (!strncmp(opt, "no", 2)) {
134 if (!strcmp(opt, "debug")) {
143 get_local_elan_id(char *fname, char *buf)
145 FILE *fp = fopen(fname, "r");
151 rc = fscanf(fp, "NodeId %255s", buf);
155 return (rc == 1) ? 0 : -1;
159 set_local(struct lustre_mount_data *lmd)
162 * XXX PtlGetId() will be safer if portals is loaded and
163 * initialised correctly at this time... */
168 if (lmd->lmd_local_nid != PTL_NID_ANY)
171 memset(buf, 0, sizeof(buf));
173 if (lmd->lmd_nal == SOCKNAL || lmd->lmd_nal == TCPNAL) {
174 rc = gethostname(buf, sizeof(buf) - 1);
176 fprintf (stderr, "mount: can't get local buf:"
180 } else if (lmd->lmd_nal == QSWNAL) {
182 char *pfiles[] = {"/proc/qsnet/elan3/device0/position",
183 "/proc/qsnet/elan4/device0/position",
186 char *pfiles[] = {"/proc/elan/device0/position",
192 rc = get_local_elan_id(pfiles[i], buf);
194 pfiles[++i] != NULL);
197 fprintf(stderr, "mount: can't read elan ID"
203 if (ptl_parse_nid (&nid, buf) != 0) {
204 fprintf (stderr, "mount: can't parse NID %s\n",
209 lmd->lmd_local_nid = nid;
214 set_peer(char *hostname, struct lustre_mount_data *lmd)
219 if (lmd->lmd_nal == SOCKNAL || lmd->lmd_nal == TCPNAL) {
220 if (lmd->lmd_server_nid == PTL_NID_ANY) {
221 if (ptl_parse_nid (&nid, hostname) != 0) {
222 fprintf (stderr, "mount: can't parse NID %s\n",
226 lmd->lmd_server_nid = nid;
229 if (ptl_parse_ipaddr(&lmd->lmd_server_ipaddr, hostname) != 0) {
230 fprintf (stderr, "mount: can't parse host %s\n",
234 } else if (lmd->lmd_nal == QSWNAL) {
236 rc = sscanf(hostname, "%*[^0-9]%63[0-9]", buf);
238 fprintf (stderr, "mount: can't get elan id from host %s\n",
242 if (ptl_parse_nid (&nid, buf) != 0) {
243 fprintf (stderr, "mount: can't parse NID %s\n",
247 lmd->lmd_server_nid = nid;
255 build_data(char *source, char *options, struct lustre_mount_data *lmd)
258 char *hostname = NULL;
260 char *profile = NULL;
264 if (strlen(source) > sizeof(target) + 1) {
265 fprintf(stderr, "mount: "
266 "exessively long host:/mds/profile argument\n");
269 strcpy(target, source);
270 if ((s = strchr(target, ':'))) {
277 if ((s = strchr(mds, '/'))) {
281 fprintf(stderr, "mount: "
282 "directory to mount not in "
283 "host:/mds/profile format\n");
287 fprintf(stderr, "mount: "
288 "directory to mount not in host:/mds/profile format\n");
292 printf("host: %s\nmds: %s\nprofile: %s\n", hostname, mds,
295 rc = parse_options(options, lmd);
303 rc = set_peer(hostname, lmd);
306 if (strlen(mds) > sizeof(lmd->lmd_mds) + 1) {
307 fprintf(stderr, "mount: mds name too long\n");
310 strcpy(lmd->lmd_mds, mds);
312 if (strlen(profile) > sizeof(lmd->lmd_profile) + 1) {
313 fprintf(stderr, "mount: profile name too long\n");
316 strcpy(lmd->lmd_profile, profile);
325 main(int argc, char * const argv[])
327 char * source = argv[1];
328 char * target = argv[2];
332 struct lustre_mount_data lmd;
336 while ((opt = getopt(argc, argv, "vno:")) != EOF) {
340 printf("verbose: %d\n", verbose);
344 printf("nomtab: %d\n", nomtab);
355 for (i = 0; i < argc; i++) {
356 printf("arg[%d] = %s\n", i, argv[i]);
360 rc = build_data(source, options, &lmd);
366 printf("mount: debug mode, not mounting\n");
370 rc = mount(source, target, "lustre", 0, (void *)&lmd);
374 update_mtab_entry(source, target, "lustre", options, 0, 0, 0);