Quota support for disabling sparse feature
PATCH 1/1 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
PATCH 9/10 Implement quota support for disabling SPARSE feature
When filling holes after disabling SPARSE feature, we have to properly update quota information.
--- tunefs.ocfs2/feature_sparse_files.c | 68 ++++++++++++++++++++++++++++++++-- 1 files changed, 64 insertions(+), 4 deletions(-)
tunefs.ocfs2/feature_sparse_files.c +64 -4
@@ -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);
Signature · 1 line
1.6.0.2
PATCH 9/10 Implement quota support for disabling SPARSE feature
Quoted 2 lines · Jan Kara
When filling holes after disabling SPARSE feature, we have to properly update quota information.
I read this as we adjust the quota but don't enforce it. That is, if filling a hole will make a user over quota, we allow that to happen. Right?
Joel
Signature · 11 lines
"You must remember this: A kiss is just a kiss, A sigh is just a sigh. The fundamental rules apply As time goes by." Joel Becker Principal Software Developer Oracle E-mail: joel.becker at oracle.com Phone: (650) 506-8127
PATCH 9/10 Implement quota support for disabling SPARSE feature
Quoted 7 lines · Joel Becker
Quoted 2 lines · Jan Kara
When filling holes after disabling SPARSE feature, we have to properly update quota information.
I read this as we adjust the quota but don't enforce it. That is, if filling a hole will make a user over quota, we allow that to happen. Right?
Yes, that's what I've decided makes the most sense. It's in the spirit
of "superuser ignores quota limits". Alternatively, we could issue a warning or even fail the conversion when some user would go over quota limit but I don't really see the use case.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH 9/10 Implement quota support for disabling SPARSE feature
Quoted 8 lines · Jan Kara
Quoted 3 lines · Joel Becker
I read this as we adjust the quota but don't enforce it. That is, if filling a hole will make a user over quota, we allow that to happen. Right?
Yes, that's what I've decided makes the most sense. It's in the spirit
of "superuser ignores quota limits". Alternatively, we could issue a warning or even fail the conversion when some user would go over quota limit but I don't really see the use case.
I agree, the superuser is asking for sparse to be removed, and
they have no quota. Upon remount, the regular user obviously can't create anything until they get below quota. So this is the right behavior.
Joel
Signature · 8 lines
"Sometimes one pays most for the things one gets for nothing."
- Albert Einstein
Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127PATCH 10/10 Fix tunefs space check when disabling SPARSE feature
In reply to Jan KaraTunefs 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.
--- tunefs.ocfs2/feature_sparse_files.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
tunefs.ocfs2/feature_sparse_files.c +1 -0
@@ -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 );
Signature · 1 line
1.6.0.2