[Ocfs2-tools-devel] [PATCH 12/12] dx_dirs v7: quota to dx_leaf in ocfs2_dx_dir_buld()
Coly Li
coly.li at suse.de
Fri Jan 29 10:19:14 PST 2010
This patch add quota to dx_leaf, when build indexed trees for
directories.
Signed-off-by: Coly Li <coly.li at suse.de>
Cc: Mark Fasheh <mfasheh at suse.com>
---
libocfs2/dir_indexed.c | 41 +++++++++++++++++++++++++++++++++++++----
1 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/libocfs2/dir_indexed.c b/libocfs2/dir_indexed.c
index e7c106d..92580b5 100644
--- a/libocfs2/dir_indexed.c
+++ b/libocfs2/dir_indexed.c
@@ -1065,12 +1065,23 @@ out:
errcode_t ocfs2_dx_dir_build(ocfs2_filesys *fs,
uint64_t dir)
{
- errcode_t ret = 0;
+ errcode_t ret = 0, err;
uint64_t dr_blkno;
char *dx_buf = NULL, *di_buf = NULL;
struct ocfs2_dinode *di;
struct ocfs2_dx_root_block *dx_root;
struct dx_insert_ctxt ctxt;
+ ocfs2_quota_hash *usrhash = NULL, *grphash = NULL;
+ uint32_t uid, gid;
+ long long change;
+
+ ret = ocfs2_load_fs_quota_info(fs);
+ if (ret)
+ goto out;
+
+ ret = ocfs2_init_quota_change(fs, &usrhash, &grphash);
+ if (ret)
+ goto out;
ret = ocfs2_malloc_block(fs->fs_io, &di_buf);
if (ret)
@@ -1117,15 +1128,37 @@ errcode_t ocfs2_dx_dir_build(ocfs2_filesys *fs,
if (ret)
goto out;
- ocfs2_free(&dx_buf);
- ocfs2_free(&di_buf);
-
ctxt.dir_blkno = dir;
ctxt.dx_root_blkno = dr_blkno;
ctxt.fs = fs;
ret = ocfs2_dir_iterate(fs, dir, 0, NULL,
ocfs2_dx_dir_insert, &ctxt);
+
+ /* check quota for dx_leaf */
+ ret = ocfs2_read_dx_root(fs, dr_blkno, dx_buf);
+ if (ret)
+ goto out;
+ ret = ocfs2_read_inode(fs, dir, di_buf);
+ if (ret)
+ goto out;
+
+ change = ocfs2_clusters_to_bytes(fs,
+ dx_root->dr_clusters);
+ uid = di->i_uid;
+ gid = di->i_gid;
+
+ ret = ocfs2_apply_quota_change(fs, usrhash, grphash,
+ uid, gid, change, 0);
+ if (ret) {
+ /* exceed quota, truncate the indexed tree */
+ ret = ocfs2_dx_dir_truncate(fs, dir);
+ }
+
out:
+ err = ocfs2_finish_quota_change(fs, usrhash, grphash);
+ if (!ret)
+ ret = err;
+
if (di_buf)
ocfs2_free(&di_buf);
if (dx_buf)
--
Coly Li
SuSE Labs
More information about the Ocfs2-tools-devel
mailing list