Quota fixes for 2.6.31-rc4
cover Quota fixes for 2.6.31-rc4
Hi,
I did some more in-depth testing of OCFS2 quota code, especially with ECC
feature enabled and spotted some problems. First four patches fix them. I need the fifth patch to be able to mount OCFS2 filesystem with 2.6.31-rc3. The sixth patch fixes a potential problem when quota syncing interval is updated while the cluster is running (which is not possible currently).
Joel, could you please merge those patches? Thanks.
Honza
PATCH 1/6 ocfs2: Make global quota files blocksize aligned
Change i_size of global quota files so that it always remains aligned to block size. This is mainly because the end of quota block may contain checksum (if checksumming is enabled) and it's a bit awkward for it to be "outside" of quota file (and it makes life harder for ocfs2-tools).
--- fs/ocfs2/quota_global.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
fs/ocfs2/quota_global.c +4 -2
@@ -211,14 +211,16 @@ ssize_t ocfs2_quota_write(struct super_block *sb, int type,mutex_lock_nested (&gqinode->i_mutex,I_MUTEX_QUOTA );if (gqinode->i_size < off + len) { +loff_t rounded_end =ALIGN (off + len, sb->s_blocksize); +down_write (&OCFS2_I (gqinode)->ip_alloc_sem); - err =ocfs2_extend_no_holes (gqinode, off + len, off); + err =ocfs2_extend_no_holes (gqinode, rounded_end, off);up_write (&OCFS2_I (gqinode)->ip_alloc_sem);if (err <0 ) goto out; err =ocfs2_simple_size_update (gqinode, oinfo->dqi_gqi_bh, - off + len); + rounded_end);if (err <0 ) goto out; new =1 ;
Signature · 1 line
1.6.0.2
PATCH 1/6 ocfs2: Make global quota files blocksize aligned
Quoted 15 lines · Jan Kara
Change
i_sizeof global quota files so that it always remains aligned to block size. This is mainly because the end of quota block may contain checksum (if checksumming is enabled) and it's a bit awkward for it to be "outside" of quota file (and it makes life harder for ocfs2-tools).Signed-off-by Jan Kara <[email protected]>--- fs/ocfs2/quota_global.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)fs/ocfs2/quota_global.c +0
-0
fs/ocfs2/quota_global.c ssize_t ocfs2_quota_write(struct super_block *sb, int type, · line 214
Quoted 4 lines
fs/ocfs2/quota_global.c +1
-0@@ -211,14 +211,16 @@ ssize_t ocfs2_quota_write(struct super_block *sb, int type,mutex_lock_nested (&gqinode->i_mutex,I_MUTEX_QUOTA );if (gqinode->i_size < off + len) { +loff_t rounded_end =ALIGN (off + len, sb->s_blocksize);
We have ocfs2_align_bytes_to_blocks() for this.
Joel
Signature · 10 lines
"Conservative, n. A statesman who is enamoured of existing evils, as distinguished from the Liberal, who wishes to replace them with others." - Ambrose Bierce, The Devil's Dictionary Joel Becker Principal Software Developer Oracle E-mail: joel.becker at oracle.com Phone: (650) 506-8127
PATCH 2/6 ocfs2: Mark buffer uptodate before calling ocfs2_journal_access_dq()
In reply to Jan KaraIn a code path extending local quota files we marked new header buffer uptodate only after calling ocfs2_journal_access_dq() which triggers a bug. Fix it and also call ocfs2 variant of the function marking buffer uptodate.
--- fs/ocfs2/quota_local.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
fs/ocfs2/quota_local.c +3 -1
@@ -20,6 +20,7 @@#include "sysfile.h" #include "dlmglue.h" #include "quota.h" +#include "uptodate.h" /* Number of local quota structures per block */ static inline unsigned int ol_quota_entries_per_block (struct super_block *sb)
@@ -979,6 +980,8 @@ static struct ocfs2_quota_chunk *ocfs2_local_quota_add_chunk(mlog_errno (status); goto out; } +ocfs2_set_new_buffer_uptodate (lqinode, bh); + dchunk = (struct ocfs2_local_disk_chunk *)bh->b_data; handle =ocfs2_start_trans (OCFS2_SB (sb),2 );
@@ -999,7 +1002,6 @@ static struct ocfs2_quota_chunk *ocfs2_local_quota_add_chunk(memset (dchunk->dqc_bitmap,0 , sb->s_blocksize -sizeof (struct ocfs2_local_disk_chunk ) -OCFS2_QBLK_RESERVED_SPACE ); -set_buffer_uptodate (bh);unlock_buffer (bh); status =ocfs2_journal_dirty (handle, bh);if (status <0 ) {
Signature · 1 line
1.6.0.2
PATCH 3/6 ocfs2: Initialize blocks allocated to local quota file
In reply to Jan KaraWhen we extend local quota file, we should initialize data in newly allocated block. Firstly because on recovery we could parse bogus data, secondly so that block checksums are properly computed.
--- fs/ocfs2/quota_local.c | 98 ++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 83 insertions(+), 15 deletions(-)
fs/ocfs2/quota_local.c +83 -15
@@ -941,7 +941,7 @@ static struct ocfs2_quota_chunk *ocfs2_local_quota_add_chunk(struct ocfs2_local_disk_chunk *dchunk;int status;handle_t *handle; -struct buffer_head *bh =NULL ; +struct buffer_head *bh =NULL , *dbh =NULL ;u64 p_blkno;/* We are protected by dqio_sem so no locking needed */
@@ -965,34 +965,32 @@ static struct ocfs2_quota_chunk *ocfs2_local_quota_add_chunk(mlog_errno (status); goto out; } + handle =ocfs2_start_trans (OCFS2_SB (sb),3 ); +if (IS_ERR (handle)) { + status =PTR_ERR (handle); +mlog_errno (status); + goto out; + } +/* Initialize chunk header */ down_read (&OCFS2_I (lqinode)->ip_alloc_sem); status =ocfs2_extent_map_get_blocks (lqinode, oinfo->dqi_blocks, &p_blkno,NULL ,NULL );up_read (&OCFS2_I (lqinode)->ip_alloc_sem);if (status <0 ) {mlog_errno (status); - goto out; + goto out_trans; } bh =sb_getblk (sb, p_blkno);if (!bh) { status = -ENOMEM ;mlog_errno (status); - goto out; + goto out_trans; } -ocfs2_set_new_buffer_uptodate (lqinode, bh); - dchunk = (struct ocfs2_local_disk_chunk *)bh->b_data; - - handle =ocfs2_start_trans (OCFS2_SB (sb),2 ); -if (IS_ERR (handle)) { - status =PTR_ERR (handle); -mlog_errno (status); - goto out; - } - +ocfs2_set_new_buffer_uptodate (lqinode, bh); status =ocfs2_journal_access_dq (handle, lqinode, bh, -OCFS2_JOURNAL_ACCESS_WRITE ); +OCFS2_JOURNAL_ACCESS_CREATE );if (status <0 ) {mlog_errno (status); goto out_trans;
@@ -1009,6 +1007,38 @@ static struct ocfs2_quota_chunk *ocfs2_local_quota_add_chunk( goto out_trans; } +/* Initialize new block with structures */ +down_read (&OCFS2_I (lqinode)->ip_alloc_sem); + status =ocfs2_extent_map_get_blocks (lqinode, oinfo->dqi_blocks +1 , + &p_blkno,NULL ,NULL ); +up_read (&OCFS2_I (lqinode)->ip_alloc_sem); +if (status <0 ) { +mlog_errno (status); + goto out_trans; + } + dbh =sb_getblk (sb, p_blkno); +if (!dbh) { + status = -ENOMEM ; +mlog_errno (status); + goto out_trans; + } +ocfs2_set_new_buffer_uptodate (lqinode, dbh); + status =ocfs2_journal_access_dq (handle, lqinode, dbh, +OCFS2_JOURNAL_ACCESS_CREATE ); +if (status <0 ) { +mlog_errno (status); + goto out_trans; + } +lock_buffer (dbh); +memset (dbh->b_data,0 , sb->s_blocksize -OCFS2_QBLK_RESERVED_SPACE ); +unlock_buffer (dbh); + status =ocfs2_journal_dirty (handle, dbh); +if (status <0 ) { +mlog_errno (status); + goto out_trans; + } + +/* Update local quotafile info */ oinfo->dqi_blocks +=2 ; oinfo->dqi_chunks++; status =ocfs2_local_write_info (sb, type);
@@ -1033,6 +1063,7 @@ out_trans:ocfs2_commit_trans (OCFS2_SB (sb), handle); out:brelse (bh); +brelse (dbh);kmem_cache_free (ocfs2_qf_chunk_cachep, chunk);return ERR_PTR (status); }
@@ -1050,6 +1081,8 @@ static struct ocfs2_quota_chunk *ocfs2_extend_local_quota_file(struct ocfs2_local_disk_chunk *dchunk;int epb =ol_quota_entries_per_block (sb);unsigned int chunk_blocks; +struct buffer_head *bh; +u64 p_blkno;int status;handle_t *handle;
@@ -1077,12 +1110,46 @@ static struct ocfs2_quota_chunk *ocfs2_extend_local_quota_file(mlog_errno (status); goto out; } - handle =ocfs2_start_trans (OCFS2_SB (sb),2 ); + +/* Get buffer from the just added block */ +down_read (&OCFS2_I (lqinode)->ip_alloc_sem); + status =ocfs2_extent_map_get_blocks (lqinode, oinfo->dqi_blocks, + &p_blkno,NULL ,NULL ); +up_read (&OCFS2_I (lqinode)->ip_alloc_sem); +if (status <0 ) { +mlog_errno (status); + goto out; + } + bh =sb_getblk (sb, p_blkno); +if (!bh) { + status = -ENOMEM ; +mlog_errno (status); + goto out; + } +ocfs2_set_new_buffer_uptodate (lqinode, bh); + + handle =ocfs2_start_trans (OCFS2_SB (sb),3 );if (IS_ERR (handle)) { status =PTR_ERR (handle);mlog_errno (status); goto out; } +/* Zero created block */ + status =ocfs2_journal_access_dq (handle, lqinode, bh, +OCFS2_JOURNAL_ACCESS_CREATE ); +if (status <0 ) { +mlog_errno (status); + goto out_trans; + } +lock_buffer (bh); +memset (bh->b_data,0 , sb->s_blocksize); +unlock_buffer (bh); + status =ocfs2_journal_dirty (handle, bh); +if (status <0 ) { +mlog_errno (status); + goto out_trans; + } +/* Update chunk header */ status =ocfs2_journal_access_dq (handle, lqinode, chunk->qc_headerbh,OCFS2_JOURNAL_ACCESS_WRITE );if (status <0 ) {
@@ -1099,6 +1166,7 @@ static struct ocfs2_quota_chunk *ocfs2_extend_local_quota_file(mlog_errno (status); goto out_trans; } +/* Update file header */ oinfo->dqi_blocks++; status =ocfs2_local_write_info (sb, type);if (status <0 ) {
Signature · 1 line
1.6.0.2
PATCH 3/6 ocfs2: Initialize blocks allocated to local quota file
fs/ocfs2/quota_local.c static struct ocfs2_quota_chunk *ocfs2_local_quota_add_chunk( · line 973
Quoted 6 lines · Jan Kara
fs/ocfs2/quota_local.c +6
-0+ handle =ocfs2_start_trans (OCFS2_SB (sb),3 ); +if (IS_ERR (handle)) { + status =PTR_ERR (handle); +mlog_errno (status); + goto out; + }
Can we define the quota credit counts in fs/ocfs2/journal.h like
all of our other transaction constants? I just realized how many raw numbers there are in the quota c files. Please define the _CREDITS values appropriately and put them in journal.h with descriptions. You can do this as a separate patch at the end of the series.
Joel
Signature · 9 lines
"I think it would be a good idea."
- Mahatma Ghandi, when asked what he thought of Western
civilization
Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127PATCH 3/6 ocfs2: Initialize blocks allocated to local quota file
Quoted 13 lines · Joel Becker
fs/ocfs2/quota_local.c static struct ocfs2_quota_chunk *ocfs2_local_quota_add_chunk( · line 973
Quoted 6 lines · Jan Kara
fs/ocfs2/quota_local.c +6
-0+ handle =ocfs2_start_trans (OCFS2_SB (sb),3 ); +if (IS_ERR (handle)) { + status =PTR_ERR (handle); +mlog_errno (status); + goto out; + }Can we define the quota credit counts in
fs/ocfs2/journal.hlike
all of our other transaction constants? I just realized how many raw numbers there are in the quota c files. Please define the_CREDITSvalues appropriately and put them injournal.hwith descriptions. You can do this as a separate patch at the end of the series.
OK, I'll clean up what I find :).
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH 4/6 ocfs2: Zero out padding of on disk dquot structure
In reply to Jan KaraPadding fields of on-disk dquot structure were not zeroed. Zero them so that it's easier to use them later.
--- fs/ocfs2/quota_global.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
fs/ocfs2/quota_global.c +1 -0
@@ -69,6 +69,7 @@ static void ocfs2_global_mem2diskdqb(void *dp, struct dquot *dquot) d->dqb_curspace =cpu_to_le64 (m->dqb_curspace); d->dqb_btime =cpu_to_le64 (m->dqb_btime); d->dqb_itime =cpu_to_le64 (m->dqb_itime); + d->dqb_pad1 = d->dqb_pad2 =0 ; }static int ocfs2_global_is_id (void *dp,struct dquot *dquot)
Signature · 1 line
1.6.0.2
PATCH 5/6 ocfs2: Fix initialization of blockcheck stats
In reply to Jan KaraWe just set blockcheck stats to zeros but we should also properly initialize the spinlock there.
--- fs/ocfs2/super.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
fs/ocfs2/super.c +1 -0
@@ -777,6 +777,7 @@ static int ocfs2_sb_probe(struct super_block *sb, } di = (struct ocfs2_dinode *) (*bh)->b_data;memset (stats,0 ,sizeof (struct ocfs2_blockcheck_stats )); +spin_lock_init (&stats->b_lock); status =ocfs2_verify_volume (di, *bh, blksize, stats);if (status >=0 ) goto bail;
Signature · 1 line
1.6.0.2
PATCH 6/6 ocfs2: Remove syncjiff field from quota info
In reply to Jan Karasyncjiff is just a converted value of syncms. Some places which are updating syncms forgot to update syncjiff as well. Since the conversion is just a simple division / multiplication and it does not happen frequently, just remove the syncjiff field to avoid forgotten conversions.
--- fs/ocfs2/aops.c | 4 +++- fs/ocfs2/quota.h | 1 - fs/ocfs2/quota_global.c | 5 ++--- 3 files changed, 5 insertions(+), 5 deletions(-)
fs/ocfs2/aops.c +3 -1
@@ -138,9 +138,11 @@ static int ocfs2_get_block(struct inode *inode, sector_t iblock,mlog_entry ("(0x%p, %llu, 0x%p, %d)\n" , inode, (unsigned long long )iblock, bh_result, create); -if (OCFS2_I (inode)->ip_flags &OCFS2_INODE_SYSTEM_FILE ) +if (OCFS2_I (inode)->ip_flags &OCFS2_INODE_SYSTEM_FILE ) {mlog (ML_NOTICE ,"get_block on system inode 0x%p (%lu)\n" , inode, inode->i_ino); +dump_stack (); + }if (S_ISLNK (inode->i_mode)) {/* this always does I/O for some reason. */
fs/ocfs2/quota.h +0 -1
@@ -50,7 +50,6 @@ struct ocfs2_mem_dqinfo {unsigned int dqi_chunks;/* Number of chunks in local quota file */ unsigned int dqi_blocks;/* Number of blocks allocated for local quota file */ unsigned int dqi_syncms;/* How often should we sync with other nodes */ -unsigned int dqi_syncjiff;/* Precomputed dqi_syncms in jiffies */ struct list_head dqi_chunk;/* List of chunks */ struct inode *dqi_gqinode;/* Global quota file inode */ struct ocfs2_lock_res dqi_gqlock;/* Lock protecting quota information structure */
fs/ocfs2/quota_global.c +2 -3
@@ -345,7 +345,6 @@ int ocfs2_global_read_info(struct super_block *sb, int type) info->dqi_bgrace =le32_to_cpu (dinfo.dqi_bgrace); info->dqi_igrace =le32_to_cpu (dinfo.dqi_igrace); oinfo->dqi_syncms =le32_to_cpu (dinfo.dqi_syncms); - oinfo->dqi_syncjiff =msecs_to_jiffies (oinfo->dqi_syncms); oinfo->dqi_gi.dqi_blocks =le32_to_cpu (dinfo.dqi_blocks); oinfo->dqi_gi.dqi_free_blk =le32_to_cpu (dinfo.dqi_free_blk); oinfo->dqi_gi.dqi_free_entry =le32_to_cpu (dinfo.dqi_free_entry);
@@ -355,7 +354,7 @@ int ocfs2_global_read_info(struct super_block *sb, int type) oinfo->dqi_gi.dqi_qtree_depth =qtree_depth (&oinfo->dqi_gi);INIT_DELAYED_WORK (&oinfo->dqi_sync_work, qsync_work_fn);queue_delayed_work (ocfs2_quota_wq, &oinfo->dqi_sync_work, - oinfo->dqi_syncjiff); +msecs_to_jiffies (oinfo->dqi_syncms)); out_err:mlog_exit (status);
@@ -610,7 +609,7 @@ static void qsync_work_fn(struct work_struct *work)dquot_scan_active (sb, ocfs2_sync_dquot_helper, oinfo->dqi_type);queue_delayed_work (ocfs2_quota_wq, &oinfo->dqi_sync_work, - oinfo->dqi_syncjiff); +msecs_to_jiffies (oinfo->dqi_syncms)); }/*
Signature · 1 line
1.6.0.2
PATCH 6/6 ocfs2: Remove syncjiff field from quota info
Quoted 18 lines · Jan Kara
syncjiff is just a converted value of syncms. Some places which are updating syncms forgot to update syncjiff as well. Since the conversion is just a simple division / multiplication and it does not happen frequently, just remove the syncjiff field to avoid forgotten conversions.
Signed-off-by Jan Kara <[email protected]>--- fs/ocfs2/aops.c | 4 +++- fs/ocfs2/quota.h | 1 - fs/ocfs2/quota_global.c | 5 ++--- 3 files changed, 5 insertions(+), 5 deletions(-)fs/ocfs2/aops.c +0
-0
fs/ocfs2/aops.c static int ocfs2_get_block(struct inode *inode, sector_t iblock, · line 145
Quoted 9 lines
fs/ocfs2/aops.c +3
-1@@ -138,9 +138,11 @@ static int ocfs2_get_block(struct inode *inode, sector_t iblock,mlog_entry ("(0x%p, %llu, 0x%p, %d)\n" , inode, (unsigned long long )iblock, bh_result, create); -if (OCFS2_I (inode)->ip_flags &OCFS2_INODE_SYSTEM_FILE ) +if (OCFS2_I (inode)->ip_flags &OCFS2_INODE_SYSTEM_FILE ) {mlog (ML_NOTICE ,"get_block on system inode 0x%p (%lu)\n" , inode, inode->i_ino); +dump_stack (); + }
What's this doing here?
Joel
Signature · 8 lines
"Win95 file and print sharing are for relatively friendly nets." - Paul Leach, Microsoft Joel Becker Principal Software Developer Oracle E-mail: joel.becker at oracle.com Phone: (650) 506-8127
PATCH 6/6 ocfs2: Remove syncjiff field from quota info
Quoted 22 lines · Joel Becker
Quoted 21 lines · Jan Kara
syncjiff is just a converted value of syncms. Some places which are updating syncms forgot to update syncjiff as well. Since the conversion is just a simple division / multiplication and it does not happen frequently, just remove the syncjiff field to avoid forgotten conversions.
Signed-off-by Jan Kara <[email protected]>--- fs/ocfs2/aops.c | 4 +++- fs/ocfs2/quota.h | 1 - fs/ocfs2/quota_global.c | 5 ++--- 3 files changed, 5 insertions(+), 5 deletions(-)fs/ocfs2/aops.c +0
-0@@ -138,9 +138,11 @@ static int ocfs2_get_block(struct inode *inode, sector_t iblock,mlog_entry ("(0x%p, %llu, 0x%p, %d)\n" , inode, (unsigned long long )iblock, bh_result, create);
Quoted 8 lines
fs/ocfs2/aops.c static int ocfs2_get_block(struct inode *inode, sector_t iblock, · line 145
Quoted 6 lines
fs/ocfs2/aops.c +3
-1-if (OCFS2_I (inode)->ip_flags &OCFS2_INODE_SYSTEM_FILE ) +if (OCFS2_I (inode)->ip_flags &OCFS2_INODE_SYSTEM_FILE ) {mlog (ML_NOTICE ,"get_block on system inode 0x%p (%lu)\n" , inode, inode->i_ino); +dump_stack (); + }What's this doing here?
Oops, that's a remainder of my debugging (I was at one point seeing this
message and it wasn't clear to me how we got there so I've added dump_stack() there and forgot about it). I'll remove it. Thanks for spotting this.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR