Dmitry Monakhov <dmonakhov@xxxxxxxxxx> writes: > This patch solves write vs chown race condition. > > Signed-off-by: Dmitry Monakhov <dmonakhov@xxxxxxxxxx> > --- > fs/ext4/ext4.h | 6 +++++- > fs/ext4/inode.c | 13 ++++--------- > 2 files changed, 9 insertions(+), 10 deletions(-) Oops.. i've forgot to init EXT4_I(inode)->i_reserved_quota before usage. This is strange, but this wasn't triggered by my simple test :( Will send new version. > > diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h > index 26d3cf8..992cecd 100644 > --- a/fs/ext4/ext4.h > +++ b/fs/ext4/ext4.h > @@ -705,6 +705,10 @@ struct ext4_inode_info { > struct list_head i_aio_dio_complete_list; > /* current io_end structure for async DIO write*/ > ext4_io_end_t *cur_aio_dio; > +#ifdef CONFIG_QUOTA > + /* quota space reservation, managed internally by quota code */ > + qsize_t i_reserved_quota; > +#endif > }; > > /* > @@ -1427,7 +1431,7 @@ extern int ext4_chunk_trans_blocks(struct inode *, int nrblocks); > extern int ext4_block_truncate_page(handle_t *handle, > struct address_space *mapping, loff_t from); > extern int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf); > -extern qsize_t ext4_get_reserved_space(struct inode *inode); > +extern qsize_t* ext4_get_reserved_space(struct inode *inode); > extern int flush_aio_dio_completed_IO(struct inode *inode); > /* ioctl.c */ > extern long ext4_ioctl(struct file *, unsigned int, unsigned long); > diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c > index f693768..d833e5a 100644 > --- a/fs/ext4/inode.c > +++ b/fs/ext4/inode.c > @@ -1048,17 +1048,12 @@ out: > return err; > } > > -qsize_t ext4_get_reserved_space(struct inode *inode) > +#ifdef CONFIG_QUOTA > +qsize_t* ext4_get_reserved_space(struct inode *inode) > { > - unsigned long long total; > - > - spin_lock(&EXT4_I(inode)->i_block_reservation_lock); > - total = EXT4_I(inode)->i_reserved_data_blocks + > - EXT4_I(inode)->i_reserved_meta_blocks; > - spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); > - > - return (total << inode->i_blkbits); > + return &EXT4_I(inode)->i_reserved_quota; > } > +#endif > /* > * Calculate the number of metadata blocks need to reserve > * to allocate @blocks for non extent file based file -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html