Jan Kara
2009-Jul-28 10:18 UTC
[Ocfs2-devel] [PATCH 9-10/10] Quota support for disabling sparse feature
Hi, I'm sending a patch for proper quota support when disabling sparse feature. The second patch fixes a minor problem in tunefs.ocfs2 when disabling the sparse feature. In a few days I plan to resend the whole "quota support" series with all the changes people request included... Honza
Jan Kara
2009-Jul-28 10:18 UTC
[Ocfs2-devel] [PATCH 09/10] Implement quota support for disabling SPARSE feature
When filling holes after disabling SPARSE feature, we have to properly update quota information. Signed-off-by: Jan Kara <jack at suse.cz> --- tunefs.ocfs2/feature_sparse_files.c | 68 ++++++++++++++++++++++++++++++++-- 1 files changed, 64 insertions(+), 4 deletions(-) diff --git a/tunefs.ocfs2/feature_sparse_files.c b/tunefs.ocfs2/feature_sparse_files.c index 044523f..65db46b 100644 --- a/tunefs.ocfs2/feature_sparse_files.c +++ b/tunefs.ocfs2/feature_sparse_files.c @@ -53,6 +53,7 @@ struct sparse_file { uint32_t holes_num; uint32_t hole_clusters; int truncate; + uint32_t old_clusters; }; struct fill_hole_context { @@ -295,6 +296,7 @@ static errcode_t hole_iterate(ocfs2_filesys *fs, struct ocfs2_dinode *di, file->blkno = di->i_blkno; INIT_LIST_HEAD(&file->holes); + file->old_clusters = di->i_clusters; ret = find_holes_in_file(fs, di, file); if (ret) goto bail; @@ -439,6 +441,8 @@ static errcode_t fill_sparse_files(ocfs2_filesys *fs, struct list_head *pos; struct sparse_file *file; struct tools_progress *prog; + struct ocfs2_super_block *super = OCFS2_RAW_SB(fs->fs_super); + int has_usrquota, has_grpquota; prog = tools_progress_start("Filling holes", "filling", ctxt->holecount); @@ -447,6 +451,27 @@ static errcode_t fill_sparse_files(ocfs2_filesys *fs, goto out; } + has_usrquota = OCFS2_HAS_RO_COMPAT_FEATURE(super, + OCFS2_FEATURE_RO_COMPAT_USRQUOTA); + has_grpquota = OCFS2_HAS_RO_COMPAT_FEATURE(super, + OCFS2_FEATURE_RO_COMPAT_GRPQUOTA); + if (has_usrquota) { + ret = ocfs2_init_fs_quota_info(fs, USRQUOTA); + if (ret) + goto out; + ret = ocfs2_read_global_quota_info(fs, USRQUOTA); + if (ret) + goto out; + } + if (has_grpquota) { + ret = ocfs2_init_fs_quota_info(fs, GRPQUOTA); + if (ret) + goto out; + ret = ocfs2_read_global_quota_info(fs, GRPQUOTA); + if (ret) + goto out; + } + ret = ocfs2_malloc_block(fs->fs_io, &buf); if (ret) goto out; @@ -458,16 +483,51 @@ static errcode_t fill_sparse_files(ocfs2_filesys *fs, if (ret) break; - if (!file->truncate) + if (!file->truncate && !has_usrquota && !has_grpquota) continue; ret = ocfs2_read_inode(fs, file->blkno, buf); if (ret) break; di = (struct ocfs2_dinode *)buf; - ret = truncate_to_i_size(fs, di, NULL); - if (ret) - break; + if (file->truncate) { + ret = truncate_to_i_size(fs, di, NULL); + if (ret) + break; + } + if (di->i_clusters != file->old_clusters) { + long long change; + ocfs2_cached_dquot *udquot, *gdquot; + + if (di->i_clusters > file->old_clusters) { + change = ocfs2_clusters_to_bytes(fs, + di->i_clusters - file->old_clusters); + } else { + change = -ocfs2_clusters_to_bytes(fs, + file->old_clusters - di->i_clusters); + } + + if (has_usrquota) { + ret = ocfs2_read_dquot(fs, USRQUOTA, di->i_uid, + &udquot); + if (ret) + break; + udquot->d_ddquot.dqb_curspace += change; + ret = ocfs2_write_dquot(fs, USRQUOTA, udquot); + if (ret) + break; + } + if (has_grpquota) { + ret = ocfs2_read_dquot(fs, GRPQUOTA, di->i_gid, + &gdquot); + if (ret) + break; + gdquot->d_ddquot.dqb_curspace += change; + ret = ocfs2_write_dquot(fs, GRPQUOTA, gdquot); + if (ret) + break; + } + } } ocfs2_free(&buf); -- 1.6.0.2
Jan Kara
2009-Jul-28 10:18 UTC
[Ocfs2-devel] [PATCH 10/10] Fix tunefs space check when disabling SPARSE feature
Tunefs missed addition of number clusters needed to fill holes when disabling SPARSE feature and hence the check whether there's enough space in the filesystem didn't work. Signed-off-by: Jan Kara <jack at suse.cz> --- tunefs.ocfs2/feature_sparse_files.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/tunefs.ocfs2/feature_sparse_files.c b/tunefs.ocfs2/feature_sparse_files.c index 65db46b..e5b3dab 100644 --- a/tunefs.ocfs2/feature_sparse_files.c +++ b/tunefs.ocfs2/feature_sparse_files.c @@ -321,6 +321,7 @@ static errcode_t hole_iterate(ocfs2_filesys *fs, struct ocfs2_dinode *di, list_add_tail(&file->list, &ctxt->files); ctxt->holecount += file->holes_num; + ctxt->more_clusters += file->hole_clusters; tools_progress_step(ctxt->prog, 1); -- 1.6.0.2