fsck.f2fs: add an option to preserve quota limits

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>
This commit is contained in:
Jaegeuk Kim 2017-11-08 11:20:47 -08:00
parent b62ca9ed3c
commit bbdbca4e22
6 changed files with 20 additions and 7 deletions

View 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;

View 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");

View 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);

View 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)
{

View 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 */

View 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));