21 #include <linux/time.h>
37 static int ext4_release_file(
struct inode *
inode,
struct file *filp)
39 if (ext4_test_inode_state(inode, EXT4_STATE_DA_ALLOC_CLOSE)) {
41 ext4_clear_inode_state(inode, EXT4_STATE_DA_ALLOC_CLOSE);
46 !
EXT4_I(inode)->i_reserved_data_blocks)
75 ext4_unaligned_aio(
struct inode *inode,
const struct iovec *iov,
76 unsigned long nr_segs, loff_t
pos)
80 size_t count = iov_length(iov, nr_segs);
81 loff_t final_size = pos +
count;
86 if ((pos & blockmask) || (final_size & blockmask))
94 unsigned long nr_segs, loff_t pos)
97 struct inode *inode = file->
f_mapping->host;
99 int unaligned_aio = 0;
102 size_t length = iov_length(iov, nr_segs);
105 !is_sync_kiocb(iocb))
106 unaligned_aio = ext4_unaligned_aio(inode, iov, nr_segs, pos);
110 static unsigned long unaligned_warn_time;
113 if (printk_timed_ratelimit(&unaligned_warn_time, 60*60*24*
HZ))
115 "Unaligned AIO/DIO on inode %ld by %s; "
116 "performance will be poor.",
130 if (ext4_should_dioread_nolock(inode) && !unaligned_aio &&
131 !file->
f_mapping->nrpages && pos + length <= i_size_read(inode)) {
136 map.m_lblk = pos >> blkbits;
162 if (err < 0 && ret > 0)
174 ext4_file_write(
struct kiocb *iocb,
const struct iovec *iov,
175 unsigned long nr_segs, loff_t pos)
177 struct inode *inode = iocb->
ki_filp->f_path.dentry->d_inode;
187 size_t length = iov_length(iov, nr_segs);
189 if ((pos > sbi->s_bitmap_maxbytes ||
190 (pos == sbi->s_bitmap_maxbytes && length > 0)))
193 if (pos + length > sbi->s_bitmap_maxbytes) {
195 sbi->s_bitmap_maxbytes - pos);
200 ret = ext4_file_dio_write(iocb, iov, nr_segs, pos);
207 static const struct vm_operations_struct ext4_file_vm_ops = {
213 static int ext4_file_mmap(
struct file *file,
struct vm_area_struct *vma)
217 if (!mapping->
a_ops->readpage)
220 vma->
vm_ops = &ext4_file_vm_ops;
224 static int ext4_file_open(
struct inode * inode,
struct file * filp)
233 if (
unlikely(!(sbi->s_mount_flags & EXT4_MF_MNTDIR_SAMPLED) &&
235 sbi->s_mount_flags |= EXT4_MF_MNTDIR_SAMPLED;
242 memset(buf, 0,
sizeof(buf));
252 return PTR_ERR(handle);
258 strlcpy(sbi->s_es->s_last_mounted, cp,
259 sizeof(sbi->s_es->s_last_mounted));
269 struct jbd2_inode *jinode = jbd2_alloc_inode(
GFP_KERNEL);
271 spin_lock(&inode->
i_lock);
274 spin_unlock(&inode->
i_lock);
281 spin_unlock(&inode->
i_lock);
283 jbd2_free_inode(jinode);
295 struct inode *inode = file->
f_mapping->host;
299 maxbytes =
EXT4_SB(inode->
i_sb)->s_bitmap_maxbytes;
301 maxbytes = inode->
i_sb->s_maxbytes;
304 maxbytes, i_size_read(inode));
312 .aio_write = ext4_file_write,
315 .compat_ioctl = ext4_compat_ioctl,
317 .mmap = ext4_file_mmap,
318 .open = ext4_file_open,
319 .release = ext4_release_file,
329 #ifdef CONFIG_EXT4_FS_XATTR