2 * Copyright (c) 2011 Christos Zoulas
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * File: am-utils/amd/ops_lustre.c
37 #endif /* HAVE_CONFIG_H */
42 /* forward declarations */
43 static char *lustre_match(am_opts *fo);
44 static int lustre_mount(am_node *am, mntfs *mf);
45 static int lustre_umount(am_node *am, mntfs *mf);
57 amfs_error_lookup_child,
58 amfs_error_mount_child,
60 0, /* lustre_readlink */
61 0, /* lustre_mounted */
62 0, /* lustre_umounted */
63 amfs_generic_find_srvr,
64 0, /* lustre_get_wchan */
65 FS_MKMNT | FS_UBACKGROUND | FS_AMQINFO, /* nfs_fs_flags */
67 AUTOFS_LUSTRE_FS_FLAGS,
68 #endif /* HAVE_FS_AUTOFS */
73 * Lustre needs remote filesystem and host.
76 lustre_match(am_opts *fo)
80 char *rhost, *ptr, *remhost;
83 if (fo->opt_fs && !fo->opt_rfs)
84 fo->opt_rfs = fo->opt_fs;
86 plog(XLOG_USER, "lustre: no remote filesystem specified");
90 plog(XLOG_USER, "lustre: no remote host specified");
95 * Determine magic cookie to put in mtab
97 rhost = xstrdup(fo->opt_rhost);
99 for (ptr = strtok(rhost, ":"); ptr; ptr = strtok(NULL, ":")) {
100 char *at = strchr(ptr, '@');
102 plog(XLOG_USER, "lustre: missing protocol in host `%s'", ptr);
108 * Convert symbolic addresses to numbers that the kernel likes
110 if (inet_aton(ptr, &addr) == 0) {
112 if ((hp = gethostbyname(ptr)) == NULL) {
113 plog(XLOG_USER, "lustre: unknown host `%s'", ptr);
117 if (hp->h_length != sizeof(addr.s_addr)) {
118 plog(XLOG_USER, "lustre: bad address length %zu != %d for %s",
119 sizeof(addr), hp->h_length, ptr);
123 memcpy(&addr.s_addr, hp->h_addr, sizeof(addr));
129 remhost = strvcat(cp, ":", inet_ntoa(addr), at, NULL);
131 remhost = strvcat(inet_ntoa(addr), at, NULL);
134 if (remhost == NULL) {
135 plog(XLOG_USER, "lustre: empty host");
141 XFREE(fo->opt_rhost);
142 fo->opt_rhost = remhost;
144 l = strlen(fo->opt_rhost) + strlen(fo->opt_rfs) + 2;
146 xsnprintf(xmtab, l, "%s:%s", fo->opt_rhost, fo->opt_rfs);
147 dlog("lustre: mounting remote server \"%s\", remote fs \"%s\" on \"%s\"",
148 fo->opt_rhost, fo->opt_rfs, fo->opt_fs);
155 lustre_mount(am_node *am, mntfs *mf)
159 int on_autofs = mf->mf_flags & MFF_ON_AUTOFS;
162 * Figure out the name of the file system type.
164 MTYPE_TYPE type = MOUNT_TYPE_LUSTRE;
167 * Fill in the mount structure
169 memset(&mnt, 0, sizeof(mnt));
170 mnt.mnt_dir = mf->mf_mount;
171 mnt.mnt_fsname = mf->mf_info;
172 mnt.mnt_type = MNTTAB_TYPE_LUSTRE;
173 mnt.mnt_opts = mf->mf_mopts;
175 genflags = compute_mount_flags(&mnt);
176 #ifdef HAVE_FS_AUTOFS
178 genflags |= autofs_compute_mount_flags(&mnt);
179 #endif /* HAVE_FS_AUTOFS */
182 * Call generic mount routine
184 error = mount_fs(&mnt, genflags, NULL, 0, type, 0,
185 NULL, mnttab_file_name, on_autofs);
188 plog(XLOG_ERROR, "mount_lustre: %m");
197 lustre_umount(am_node *am, mntfs *mf)
199 int unmount_flags = (mf->mf_flags & MFF_ON_AUTOFS) ? AMU_UMOUNT_AUTOFS : 0;
201 return UMOUNT_FS(mf->mf_mount, mnttab_file_name, unmount_flags);