Whamcloud - gitweb
LU-4460 mount: fix lmd_parse() to handle comma-separated NIDs
[fs/lustre-release.git] / lustre / utils / mount_utils.c
index db3a0aa..31cec4a 100644 (file)
@@ -26,7 +26,7 @@
 /*
  * 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/
@@ -37,6 +37,7 @@
 #  include "config.h"
 #endif /* HAVE_CONFIG_H */
 
+#include "mount_utils.h"
 #include <stdio.h>
 #include <errno.h>
 #include <string.h>
@@ -45,7 +46,6 @@
 #include <lustre_ver.h>
 #include <sys/stat.h>
 #include <sys/utsname.h>
-#include "mount_utils.h"
 
 extern char *progname;
 extern int verbose;
@@ -339,7 +339,8 @@ int loop_setup(struct mkfs_opts *mop)
                                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,
@@ -355,11 +356,23 @@ int loop_setup(struct mkfs_opts *mop)
 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;
 }
 
@@ -367,7 +380,7 @@ int loop_format(struct mkfs_opts *mop)
 {
        int fd;
 
-       if (mop->mo_device_sz == 0) {
+       if (mop->mo_device_kb == 0) {
                fatal();
                fprintf(stderr, "loop device requires a --device-size= "
                        "param\n");
@@ -382,7 +395,7 @@ int loop_format(struct mkfs_opts *mop)
                return errno;
        }
 
-       if (ftruncate(fd, mop->mo_device_sz * 1024) != 0) {
+       if (ftruncate(fd, mop->mo_device_kb * 1024) != 0) {
                close(fd);
                fatal();
                fprintf(stderr, "%s: Unable to truncate backing store: %s\n",
@@ -592,6 +605,37 @@ int osd_label_lustre(struct mount_opts *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;
@@ -657,11 +701,23 @@ __u64 get_device_size(char* device)
        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);