/*
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
- * Copyright (c) 2012 Whamcloud, Inc.
+ * Copyright (c) 2012, 2013, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
# include "config.h"
#endif /* HAVE_CONFIG_H */
+#include "mount_utils.h"
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <lustre_ver.h>
#include <sys/stat.h>
#include <sys/utsname.h>
-#include "mount_utils.h"
extern char *progname;
extern int verbose;
int add_param(char *buf, char *key, char *val)
{
- int end = sizeof(((struct lustre_disk_data *)0)->ldd_params);
- int start = strlen(buf);
- int keylen = 0;
+ char *sub_val = NULL;
+ int buflen = strlen(buf);
+ int end = sizeof(((struct lustre_disk_data *)0)->ldd_params);
+ int start = 0;
+ int keylen = 0;
- if (key)
+ if (key != NULL)
keylen = strlen(key);
- if (start + 1 + keylen + strlen(val) >= end) {
- fprintf(stderr, "%s: params are too long-\n%s %s%s\n",
- progname, buf, key ? key : "", val);
- return 1;
+
+ start = buflen;
+ while ((sub_val = strsep(&val, ",")) != NULL) {
+ if (*sub_val == 0)
+ continue;
+
+ if (start + 1 + keylen + strlen(sub_val) >= end) {
+ fprintf(stderr, "%s: params are too long-\n%s %s%s\n",
+ progname, buf, key != NULL ? key : "", sub_val);
+ buf[buflen] = '\0';
+ return 1;
+ }
+
+ sprintf(buf + start, " %s%s", key != NULL ? key : "", sub_val);
+ start = strlen(buf);
}
- sprintf(buf + start, " %s%s", key ? key : "", val);
return 0;
}
return 0;
}
+#define PROC_DIR "/proc/"
+static int mtab_is_proc(const char *mtab)
+{
+ char path[16];
+
+ if (readlink(mtab, path, sizeof(path)) < 0)
+ return 0;
+
+ if (strncmp(path, PROC_DIR, strlen(PROC_DIR)))
+ return 0;
+
+ return 1;
+}
+
int update_mtab_entry(char *spec, char *mtpt, char *type, char *opts,
int flags, int freq, int pass)
{
struct mntent mnt;
int rc = 0;
+ /* Don't update mtab if it is linked to any file in /proc direcotry.*/
+ if (mtab_is_proc(MOUNTED))
+ return 0;
+
mnt.mnt_fsname = spec;
mnt.mnt_dir = mtpt;
mnt.mnt_type = type;
continue;
if (ret) {
fprintf(stderr, "%s: error %d on losetup: %s\n",
- progname, ret, strerror(ret));
+ progname, ret,
+ ret >= 0 ? strerror(ret) : "");
return ret;
}
strscpy(mop->mo_loopdev, l_device,
int loop_cleanup(struct mkfs_opts *mop)
{
char cmd[150];
- int ret = 1;
+ int ret = 0;
+
if ((mop->mo_flags & MO_IS_LOOP) && *mop->mo_loopdev) {
+ int tries;
+
sprintf(cmd, "losetup -d %s", mop->mo_loopdev);
- ret = run_command(cmd, sizeof(cmd));
+ for (tries = 0; tries < 3; tries++) {
+ ret = run_command(cmd, sizeof(cmd));
+ if (ret == 0)
+ break;
+ sleep(1);
+ }
}
+
+ if (ret != 0)
+ fprintf(stderr, "cannot cleanup %s: rc = %d\n",
+ mop->mo_loopdev, ret);
return ret;
}
int ret;
switch (ldd->ldd_mount_type) {
+#ifdef HAVE_LDISKFS_OSD
case LDD_MT_LDISKFS:
case LDD_MT_LDISKFS2:
ret = ldiskfs_write_ldd(mop);
break;
+#endif /* HAVE_LDISKFS_OSD */
#ifdef HAVE_ZFS_OSD
case LDD_MT_ZFS:
ret = zfs_write_ldd(mop);
int ret;
switch (ldd->ldd_mount_type) {
+#ifdef HAVE_LDISKFS_OSD
case LDD_MT_LDISKFS:
case LDD_MT_LDISKFS2:
ret = ldiskfs_read_ldd(dev, ldd);
break;
+#endif /* HAVE_LDISKFS_OSD */
#ifdef HAVE_ZFS_OSD
case LDD_MT_ZFS:
ret = zfs_read_ldd(dev, ldd);
{
vprint("checking for existing Lustre data: ");
+#ifdef HAVE_LDISKFS_OSD
if (ldiskfs_is_lustre(dev, mount_type)) {
vprint("found\n");
return 1;
}
+#endif /* HAVE_LDISKFS_OSD */
#ifdef HAVE_ZFS_OSD
if (zfs_is_lustre(dev, mount_type)) {
vprint("found\n");
int ret;
switch (ldd->ldd_mount_type) {
+#ifdef HAVE_LDISKFS_OSD
case LDD_MT_LDISKFS:
case LDD_MT_LDISKFS2:
ret = ldiskfs_make_lustre(mop);
break;
+#endif /* HAVE_LDISKFS_OSD */
#ifdef HAVE_ZFS_OSD
case LDD_MT_ZFS:
ret = zfs_make_lustre(mop);
int ret;
switch (ldd->ldd_mount_type) {
+#ifdef HAVE_LDISKFS_OSD
case LDD_MT_LDISKFS:
case LDD_MT_LDISKFS2:
ret = ldiskfs_prepare_lustre(mop,
default_mountopts, default_len,
always_mountopts, always_len);
break;
+#endif /* HAVE_LDISKFS_OSD */
#ifdef HAVE_ZFS_OSD
case LDD_MT_ZFS:
ret = zfs_prepare_lustre(mop,
int ret;
switch (ldd->ldd_mount_type) {
+#ifdef HAVE_LDISKFS_OSD
case LDD_MT_LDISKFS:
case LDD_MT_LDISKFS2:
ret = ldiskfs_tune_lustre(dev, mop);
break;
+#endif /* HAVE_LDISKFS_OSD */
#ifdef HAVE_ZFS_OSD
case LDD_MT_ZFS:
ret = zfs_tune_lustre(dev, mop);
int ret;
switch (ldd->ldd_mount_type) {
+#ifdef HAVE_LDISKFS_OSD
case LDD_MT_LDISKFS:
case LDD_MT_LDISKFS2:
ret = ldiskfs_label_lustre(mop);
break;
+#endif /* HAVE_LDISKFS_OSD */
#ifdef HAVE_ZFS_OSD
case LDD_MT_ZFS:
ret = zfs_label_lustre(mop);
return ret;
}
+/* Enable quota accounting */
+int osd_enable_quota(struct mkfs_opts *mop)
+{
+ struct lustre_disk_data *ldd = &mop->mo_ldd;
+ int ret;
+
+ switch (ldd->ldd_mount_type) {
+#ifdef HAVE_LDISKFS_OSD
+ case LDD_MT_EXT3:
+ case LDD_MT_LDISKFS:
+ case LDD_MT_LDISKFS2:
+ ret = ldiskfs_enable_quota(mop);
+ break;
+#endif /* HAVE_LDISKFS_OSD */
+#ifdef HAVE_ZFS_OSD
+ case LDD_MT_ZFS:
+ fprintf(stderr, "this option is only valid for ldiskfs\n");
+ ret = EINVAL;
+ break;
+#endif /* HAVE_ZFS_OSD */
+ default:
+ fatal();
+ fprintf(stderr, "unknown fs type %d '%s'\n",
+ ldd->ldd_mount_type, MT_STR(ldd));
+ ret = EINVAL;
+ break;
+ }
+
+ return ret;
+}
+
int osd_init(void)
{
int ret = 0;
+#ifdef HAVE_LDISKFS_OSD
ret = ldiskfs_init();
if (ret)
return ret;
+#endif /* HAVE_LDISKFS_OSD */
#ifdef HAVE_ZFS_OSD
ret = zfs_init();
/* we want to be able to set up a ldiskfs-based filesystem w/o
void osd_fini(void)
{
+#ifdef HAVE_LDISKFS_OSD
ldiskfs_fini();
+#endif /* HAVE_LDISKFS_OSD */
#ifdef HAVE_ZFS_OSD
zfs_fini();
#endif /* HAVE_ZFS_OSD */
return size >> 10;
}
-int file_create(char *path, int size)
+int file_create(char *path, __u64 size)
{
+ __u64 size_max;
int ret;
int fd;
+ /*
+ * Since "size" is in KB, the file offset it represents could overflow
+ * off_t.
+ */
+ size_max = (off_t)1 << (_FILE_OFFSET_BITS - 1 - 10);
+ if (size >= size_max) {
+ fprintf(stderr, "%s: "LPU64" KB: Backing store size must be "
+ "smaller than "LPU64" KB\n", progname, size, size_max);
+ return EFBIG;
+ }
+
ret = access(path, F_OK);
if (ret == 0) {
ret = unlink(path);