fsck.f2fs: add an option to preserve quota limits
authorJaegeuk Kim <jaegeuk@kernel.org>
Wed, 8 Nov 2017 19:20:47 +0000 (11:20 -0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Sun, 12 Nov 2017 02:01:07 +0000 (18:01 -0800)
If it detects quota file errors, we can see insane quota limits. In order
to recover that, this patch adds an option to reset them as zeros.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/fsck.c
fsck/main.c
fsck/mkquota.c
fsck/quotaio.h
include/f2fs_fs.h
lib/libf2fs.c

index 4250e66..ef46e33 100644 (file)
@@ -1653,7 +1653,8 @@ int fsck_chk_quota_files(struct f2fs_sb_info *sbi)
 
                DBG(1, "Checking Quota file ([%3d] ino [0x%x])\n", qtype, ino);
                needs_writeout = 0;
-               ret = quota_compare_and_update(sbi, qtype, &needs_writeout);
+               ret = quota_compare_and_update(sbi, qtype, &needs_writeout,
+                                               c.preserve_limits);
                if (ret == 0 && needs_writeout == 0) {
                        DBG(1, "OK\n");
                        continue;
index 2d24e5b..b62fc29 100644 (file)
@@ -32,6 +32,7 @@ void fsck_usage()
        MSG(0, "  -f check/fix entire partition\n");
        MSG(0, "  -p preen mode [default:0 the same as -a [0|1]]\n");
        MSG(0, "  -t show directory tree\n");
+       MSG(0, "  -q preserve quota limits\n");
        MSG(0, "  --dry-run do not really fix corruptions\n");
        exit(1);
 }
@@ -119,7 +120,7 @@ void f2fs_parse_options(int argc, char *argv[])
        }
 
        if (!strcmp("fsck.f2fs", prog)) {
-               const char *option_string = ":ad:fp:t";
+               const char *option_string = ":ad:fp:q:t";
                int opt = 0;
                struct option long_opt[] = {
                        {"dry-run", no_argument, 0, 1},
@@ -176,11 +177,14 @@ void f2fs_parse_options(int argc, char *argv[])
                                c.fix_on = 1;
                                MSG(0, "Info: Force to fix corruption\n");
                                break;
+                       case 'q':
+                               c.preserve_limits = atoi(optarg);
+                               MSG(0, "Info: Preserve quota limits = %d\n",
+                                       c.preserve_limits);
+                               break;
                        case 't':
                                c.show_dentry = 1;
                                break;
-
-
                        case ':':
                                if (optopt == 'p') {
                                        MSG(0, "Info: Use default preen mode\n");
index aadfae7..b54be08 100644 (file)
@@ -355,7 +355,8 @@ static int scan_dquots_callback(struct dquot *dquot, void *cb_data)
  * set to 1 if the supplied and on-disk quota usage values are not identical.
  */
 errcode_t quota_compare_and_update(struct f2fs_sb_info *sbi,
-               enum quota_type qtype, int *usage_inconsistent)
+               enum quota_type qtype, int *usage_inconsistent,
+               int preserve_limits)
 {
        struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
        quota_ctx_t qctx = fsck->qctx;
@@ -376,7 +377,7 @@ errcode_t quota_compare_and_update(struct f2fs_sb_info *sbi,
        }
 
        scan_data.quota_dict = qctx->quota_dict[qtype];
-       scan_data.update_limits = 1;
+       scan_data.update_limits = preserve_limits;
        scan_data.update_usage = 0;
        scan_data.usage_is_inconsistent = 0;
        err = qh.qh_ops->scan_dquots(&qh, scan_dquots_callback, &scan_data);
index e796eb1..8087309 100644 (file)
@@ -216,7 +216,8 @@ void quota_add_inode_usage(quota_ctx_t qctx, f2fs_ino_t ino,
                struct f2fs_inode* inode);
 void quota_release_context(quota_ctx_t *qctx);
 errcode_t quota_compare_and_update(struct f2fs_sb_info *sbi,
-               enum quota_type qtype, int *usage_inconsistent);
+               enum quota_type qtype, int *usage_inconsistent,
+               int preserve_limits);
 
 static inline errcode_t quota_get_mem(unsigned long size, void *ptr)
 {
index ecffeaa..8d67a76 100644 (file)
@@ -315,6 +315,7 @@ struct f2fs_configuration {
        int auto_fix;
        int preen_mode;
        int ro;
+       int preserve_limits;            /* preserve quota limits */
        __le32 feature;                 /* defined features */
 
        /* defragmentation parameters */
index 259bd17..aea22d8 100644 (file)
@@ -577,6 +577,11 @@ void f2fs_init_configuration(void)
        c.zoned_mode = 0;
        c.zoned_model = 0;
        c.zone_blocks = 0;
+#ifdef WITH_ANDROID
+       c.preserve_limits = 0;
+#else
+       c.preserve_limits = 1;
+#endif
 
        for (i = 0; i < MAX_DEVICES; i++) {
                memset(&c.devices[i], 0, sizeof(struct device_info));