]) # LB_LIBCFS_DIR
#
+# LB_LIBMOUNT
+#
+# Check whether build with libmount for mount.lustre.
+# libmount is part of the util-linux since v2.18.
+# We need it to manipulate utab file.
+#
+AC_DEFUN([LB_LIBMOUNT], [
+AC_MSG_CHECKING([whether build with libmount])
+AC_CHECK_HEADER([libmount/libmount.h], [
+ AC_CHECK_LIB([mount], [mnt_update_set_fs], [
+ LDLIBMOUNT="-lmount"
+ AC_SUBST(LDLIBMOUNT)
+ AC_DEFINE(HAVE_LIBMOUNT, 1, [build with libmount])
+ AC_MSG_RESULT(yes)
+ ],[AC_MSG_RESULT(no)])
+], [AC_MSG_RESULT(no)])
+]) # LB_LIBMOUNT
+
+#
# LB_PATH_SNMP
#
# check for in-tree snmp support
LIBCFS_CONFIG_CDEBUG
LC_QUOTA
+LB_LIBMOUNT
LB_PATH_SNMP
LB_PATH_LUSTREIOKIT
mount_lustre_SOURCES = mount_lustre.c mount_utils.c mount_utils.h
mount_lustre_CPPFLAGS := ${MNTMODCFLAGS}
mount_lustre_LDFLAGS := ${MNTMODLDFLAGS}
-mount_lustre_LDADD := $(LIBPTLCTL) $(SELINUX)
+mount_lustre_LDADD := $(LIBPTLCTL) $(SELINUX) $(LDLIBMOUNT)
mount_lustre_DEPENDENCIES := $(LIBPTLCTL)
mkfs_lustre_SOURCES = mkfs_lustre.c mount_utils.c mount_utils.h
mkfs_lustre_CPPFLAGS := -UTUNEFS ${MNTMODCFLAGS}
mkfs_lustre_LDFLAGS := ${MNTMODLDFLAGS}
-mkfs_lustre_LDADD := $(LIBPTLCTL)
+mkfs_lustre_LDADD := $(LIBPTLCTL) $(LDLIBMOUNT)
mkfs_lustre_DEPENDENCIES := $(LIBPTLCTL)
tunefs_lustre_SOURCES = mkfs_lustre.c mount_utils.c mount_utils.h
#endif
#endif
+#ifdef HAVE_LIBMOUNT
+# define WITH_LIBMOUNT "(libmount)"
+#else
+# define WITH_LIBMOUNT ""
+#endif
+
#define MAXOPT 4096
#define MAX_RETRIES 99
break;
case 'V':
++version;
- fprintf(stdout, "%s %s\n", progname,
- LUSTRE_VERSION_STRING);
+ fprintf(stdout, "%s %s %s\n", progname,
+ LUSTRE_VERSION_STRING, WITH_LIBMOUNT);
return 0;
default:
fprintf(stderr, "%s: unknown option '%c'\n",
rc = WEXITSTATUS(ret);
}
- } else if (!mop.mo_nomtab) {
- rc = update_mtab_entry(mop.mo_usource, mop.mo_target, "lustre",
- mop.mo_orig_options, 0,0,0);
+ } else {
+ /* Deal with utab just for client. Note that we ignore
+ * the return value here since it is not worth to fail
+ * mount by prevent some rare cases */
+ if (strstr(mop.mo_usource, ":/") != NULL)
+ update_utab_entry(&mop);
+ if (!mop.mo_nomtab) {
+ rc = update_mtab_entry(mop.mo_usource, mop.mo_target,
+ "lustre", mop.mo_orig_options,
+ 0, 0, 0);
+ }
}
free(options);
return 1;
}
+#ifdef HAVE_LIBMOUNT
+
+# include <libmount/libmount.h>
+
+/*
+ * The libmount is part of util-linux since 2.18.
+ * We use it to update utab to avoid umount would
+ * blocked in some rare case.
+ */
+int update_utab_entry(struct mount_opts *mop)
+{
+ struct libmnt_fs *fs = mnt_new_fs();
+ struct libmnt_update *upd;
+ int rc;
+
+ mnt_fs_set_source(fs, mop->mo_source);
+ mnt_fs_set_target(fs, mop->mo_target);
+ mnt_fs_set_fstype(fs, "lustre");
+ mnt_fs_set_attributes(fs, "lustre");
+
+ upd = mnt_new_update();
+ if (!upd)
+ return -ENOMEM;
+
+ rc = mnt_update_set_fs(upd, mop->mo_nomtab ? MS_REMOUNT : 0, NULL, fs);
+ if (rc == 1) /* update is unnecessary */
+ rc = 0;
+ if (rc) {
+ fprintf(stderr,
+ "error: failed to save utab entry: rc = %d\n", rc);
+ } else {
+ rc = mnt_update_table(upd, NULL);
+ }
+
+ mnt_free_update(upd);
+ mnt_free_fs(fs);
+
+ return rc;
+}
+#else
+int update_utab_entry(struct mount_opts *mop)
+{
+ return 0;
+}
+#endif /* HAVE_LIBMOUNT */
+
int update_mtab_entry(char *spec, char *mtpt, char *type, char *opts,
int flags, int freq, int pass)
{
int check_mtab_entry(char *spec1, char *spec2, char *mntpt, char *type);
int update_mtab_entry(char *spec, char *mtpt, char *type, char *opts,
int flags, int freq, int pass);
+int update_utab_entry(struct mount_opts *mop);
int check_mountfsoptions(char *mountopts, char *wanted_mountopts);
void trim_mountfsoptions(char *s);
__u64 get_device_size(char* device);