Whamcloud - gitweb
LU-1842 quota: tunefs.lustre --quota
authorNiu Yawei <niu@whamcloud.com>
Sat, 6 Oct 2012 09:31:30 +0000 (05:31 -0400)
committerOleg Drokin <green@whamcloud.com>
Sun, 7 Oct 2012 23:45:27 +0000 (19:45 -0400)
Add "--quota" for tunefs.lustre to convert old quota disk format
into new format.

Signed-off-by: Niu Yawei <niu@whamcloud.com>
Change-Id: Ie1951c9183b940c41956e863f76f5e357a1b2bd8
Reviewed-on: http://review.whamcloud.com/4205
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Johann Lombardi <johann.lombardi@intel.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/doc/tunefs.lustre.8
lustre/utils/mkfs_lustre.c
lustre/utils/mount_utils.c
lustre/utils/mount_utils.h
lustre/utils/mount_utils_ldiskfs.c

index 49458c6..a3a5cb5 100644 (file)
@@ -94,6 +94,10 @@ Correct order of operations is:
 * Mount MDT and OSTs
 .br
 * Mount clients
+.TP
+.BI \--quota
+Enable space accounting on old 2.x devices.
+
 .SH EXAMPLES
 .TP
 .B tunefs.lustre --erase-param --mgsnode=<new_nid> --writeconf /dev/sda
index d85ad5a..45ad45f 100644 (file)
@@ -166,6 +166,7 @@ void usage(FILE *out)
                "\t\t--erase-params: erase all old parameter settings\n"
                "\t\t--nomgs: turn off MGS service on this MDT\n"
                "\t\t--writeconf: erase all config logs for this fs.\n"
+               "\t\t--quota: enable space accounting on old 2.x device.\n"
 #endif
                "\t\t--comment=<user comment>: arbitrary string (%d bytes)\n"
                "\t\t--dryrun: report what we would do; don't write to disk\n"
@@ -314,6 +315,7 @@ int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
                 {"writeconf", 0, 0, 'w'},
                 {"upgrade_to_18", 0, 0, 'U'},
                 {"network", 1, 0, 't'},
+               {"quota", 0, 0, 'Q'},
                 {0, 0, 0, 0}
         };
         char *optstring = "b:c:C:d:ef:Ghi:k:L:m:MnNo:Op:Pqrs:t:Uu:vw";
@@ -521,6 +523,9 @@ int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
                 case 'U':
                         upgrade_to_18 = 1;
                         break;
+               case 'Q':
+                       mop->mo_flags |= MO_QUOTA;
+                       break;
                 default:
                         if (opt != '?') {
                                 fatal();
@@ -769,6 +774,13 @@ int main(int argc, char *const argv[])
                opts.mo_source = mop.mo_device;
                (void) osd_label_lustre(&opts);
        }
+
+       /* Enable quota accounting */
+       if (mop.mo_flags & MO_QUOTA) {
+               ret = osd_enable_quota(&mop);
+               goto out;
+       }
+
 #endif
 
         /* Write our config files */
index db3a0aa..565ed85 100644 (file)
@@ -592,6 +592,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;
index d7c965a..b583f5c 100644 (file)
@@ -52,6 +52,7 @@ extern int failover;
 #define MO_FORCEFORMAT         0x02
 #define MO_FAILOVER            0x04
 #define MO_DRYRUN              0x08
+#define MO_QUOTA               0x10
 
 #define MAX_LOOP_DEVICES       16
 #define INDEX_UNASSIGNED       0xFFFF
@@ -134,6 +135,7 @@ int osd_prepare_lustre(struct mkfs_opts *mop,
                       char *always_mountopts, int always_len);
 int osd_tune_lustre(char *dev, struct mount_opts *mop);
 int osd_label_lustre(struct mount_opts *mop);
+int osd_enable_quota(struct mkfs_opts *mop);
 int osd_init(void);
 void osd_fini(void);
 
@@ -146,6 +148,7 @@ int ldiskfs_prepare_lustre(struct mkfs_opts *mop,
                           char *always_mountopts, int always_len);
 int ldiskfs_tune_lustre(char *dev, struct mount_opts *mop);
 int ldiskfs_label_lustre(struct mount_opts *mop);
+int ldiskfs_enable_quota(struct mkfs_opts *mop);
 int ldiskfs_init(void);
 void ldiskfs_fini(void);
 
index fb96106..c7f551f 100644 (file)
@@ -1101,6 +1101,63 @@ out:
        return ret;
 }
 
+static int is_feature_enabled(const char *feature, const char *devpath)
+{
+       char cmd[PATH_MAX];
+       FILE *fp;
+       char enabled_features[4096] = "";
+
+       snprintf(cmd, sizeof(cmd), "%s -R features %s 2>&1",
+                DEBUGFS, devpath);
+
+       /* Using popen() instead of run_command() since debugfs does
+        * not return proper error code if command is not supported */
+       fp = popen(cmd, "r");
+       if (!fp) {
+               fprintf(stderr, "%s: %s\n", progname, strerror(errno));
+               return 0;
+       }
+
+       fread(enabled_features, 1, sizeof(enabled_features), fp);
+       fclose(fp);
+
+       if (strstr(enabled_features, feature))
+               return 1;
+       return 0;
+}
+
+/* Enable quota accounting */
+int ldiskfs_enable_quota(struct mkfs_opts *mop)
+{
+       char *dev;
+       char cmd[512];
+       int cmdsz = sizeof(cmd), ret;
+
+       if (is_e2fsprogs_feature_supp("-O quota") != 0) {
+               fprintf(stderr, "%s: \"-O quota\" is is not supported by "
+                       "current e2fsprogs\n", progname);
+               return EINVAL;
+       }
+
+       dev = mop->mo_device;
+       if (mop->mo_flags & MO_IS_LOOP)
+               dev = mop->mo_loopdev;
+
+       /* Quota feature is already enabled? */
+       if (is_feature_enabled("quota", dev)) {
+               vprint("Quota feature is already enabled.\n");
+               return 0;
+       }
+
+       /* Turn on quota feature by "tune2fs -O quota" */
+       snprintf(cmd, cmdsz, "%s -O quota %s", TUNE2FS, dev);
+       ret = run_command(cmd, cmdsz);
+       if (ret)
+               fprintf(stderr, "command:%s (%d)", cmd, ret);
+
+       return ret;
+}
+
 int ldiskfs_init(void)
 {
        /* Required because full path to DEBUGFS is not specified */