* [PATCH] ext4: Convert ext4 to new truncate calling convention
@ 2011-05-25 8:43 Jan Kara
2011-05-25 9:15 ` Jan Kara
2011-05-25 13:45 ` Ted Ts'o
0 siblings, 2 replies; 4+ messages in thread
From: Jan Kara @ 2011-05-25 8:43 UTC (permalink / raw)
To: linux-ext4; +Cc: Christoph Hellwig, Ted Tso, Jan Kara
Mostly trivial conversion. We fix a bug that IS_IMMUTABLE and IS_APPEND
files could not be truncated during failed writes as we change the code.
Signed-off-by: Jan Kara <jack@suse.cz>
---
fs/ext4/file.c | 1 -
fs/ext4/inode.c | 24 ++++++++++++++++++++----
2 files changed, 20 insertions(+), 5 deletions(-)
Ted, can you please merge this patch? Thanks.
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 7b80d54..2c09723 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -272,7 +272,6 @@ const struct file_operations ext4_file_operations = {
};
const struct inode_operations ext4_file_inode_operations = {
- .truncate = ext4_truncate,
.setattr = ext4_setattr,
.getattr = ext4_getattr,
#ifdef CONFIG_EXT4_FS_XATTR
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 4eca654..0aa52b4 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3513,7 +3513,7 @@ retry:
loff_t end = offset + iov_length(iov, nr_segs);
if (end > isize)
- vmtruncate(inode, isize);
+ ext4_truncate_failed_write(inode);
}
}
if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
@@ -4380,8 +4380,6 @@ static void ext4_free_branches(handle_t *handle, struct inode *inode,
int ext4_can_truncate(struct inode *inode)
{
- if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
- return 0;
if (S_ISREG(inode->i_mode))
return 1;
if (S_ISDIR(inode->i_mode))
@@ -5236,6 +5234,24 @@ int ext4_write_inode(struct inode *inode, struct writeback_control *wbc)
return err;
}
+static int ext4_setsize(struct inode *inode, loff_t newsize)
+{
+ loff_t oldsize;
+ int rc;
+
+ rc = inode_newsize_ok(inode, newsize);
+ if (rc)
+ return rc;
+ if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
+ return -EPERM;
+ oldsize = inode->i_size;
+ i_size_write(inode, newsize);
+ truncate_pagecache(inode, oldsize, newsize);
+ ext4_truncate(inode);
+
+ return 0;
+}
+
/*
* ext4_setattr()
*
@@ -5353,7 +5369,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
if ((attr->ia_valid & ATTR_SIZE) &&
attr->ia_size != i_size_read(inode))
- rc = vmtruncate(inode, attr->ia_size);
+ rc = ext4_setsize(inode, attr->ia_size);
if (!rc) {
setattr_copy(inode, attr);
--
1.7.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ext4: Convert ext4 to new truncate calling convention
2011-05-25 8:43 [PATCH] ext4: Convert ext4 to new truncate calling convention Jan Kara
@ 2011-05-25 9:15 ` Jan Kara
2011-05-25 13:45 ` Ted Ts'o
1 sibling, 0 replies; 4+ messages in thread
From: Jan Kara @ 2011-05-25 9:15 UTC (permalink / raw)
To: linux-ext4; +Cc: Christoph Hellwig, Ted Tso, Jan Kara
On Wed 25-05-11 10:43:08, Jan Kara wrote:
> Mostly trivial conversion. We fix a bug that IS_IMMUTABLE and IS_APPEND
> files could not be truncated during failed writes as we change the code.
>
> Signed-off-by: Jan Kara <jack@suse.cz>
I've just noticed that Ted has changed the code this week as well and
removed vmtruncate() from ->setattr(). So Ted, please ignore this patch and
I'll send you another patch based on current ext4 state in your tree.
Honza
> ---
> fs/ext4/file.c | 1 -
> fs/ext4/inode.c | 24 ++++++++++++++++++++----
> 2 files changed, 20 insertions(+), 5 deletions(-)
>
> Ted, can you please merge this patch? Thanks.
>
> diff --git a/fs/ext4/file.c b/fs/ext4/file.c
> index 7b80d54..2c09723 100644
> --- a/fs/ext4/file.c
> +++ b/fs/ext4/file.c
> @@ -272,7 +272,6 @@ const struct file_operations ext4_file_operations = {
> };
>
> const struct inode_operations ext4_file_inode_operations = {
> - .truncate = ext4_truncate,
> .setattr = ext4_setattr,
> .getattr = ext4_getattr,
> #ifdef CONFIG_EXT4_FS_XATTR
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 4eca654..0aa52b4 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -3513,7 +3513,7 @@ retry:
> loff_t end = offset + iov_length(iov, nr_segs);
>
> if (end > isize)
> - vmtruncate(inode, isize);
> + ext4_truncate_failed_write(inode);
> }
> }
> if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
> @@ -4380,8 +4380,6 @@ static void ext4_free_branches(handle_t *handle, struct inode *inode,
>
> int ext4_can_truncate(struct inode *inode)
> {
> - if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
> - return 0;
> if (S_ISREG(inode->i_mode))
> return 1;
> if (S_ISDIR(inode->i_mode))
> @@ -5236,6 +5234,24 @@ int ext4_write_inode(struct inode *inode, struct writeback_control *wbc)
> return err;
> }
>
> +static int ext4_setsize(struct inode *inode, loff_t newsize)
> +{
> + loff_t oldsize;
> + int rc;
> +
> + rc = inode_newsize_ok(inode, newsize);
> + if (rc)
> + return rc;
> + if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
> + return -EPERM;
> + oldsize = inode->i_size;
> + i_size_write(inode, newsize);
> + truncate_pagecache(inode, oldsize, newsize);
> + ext4_truncate(inode);
> +
> + return 0;
> +}
> +
> /*
> * ext4_setattr()
> *
> @@ -5353,7 +5369,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
>
> if ((attr->ia_valid & ATTR_SIZE) &&
> attr->ia_size != i_size_read(inode))
> - rc = vmtruncate(inode, attr->ia_size);
> + rc = ext4_setsize(inode, attr->ia_size);
>
> if (!rc) {
> setattr_copy(inode, attr);
> --
> 1.7.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ext4: Convert ext4 to new truncate calling convention
2011-05-25 8:43 [PATCH] ext4: Convert ext4 to new truncate calling convention Jan Kara
2011-05-25 9:15 ` Jan Kara
@ 2011-05-25 13:45 ` Ted Ts'o
2011-05-25 15:34 ` Jan Kara
1 sibling, 1 reply; 4+ messages in thread
From: Ted Ts'o @ 2011-05-25 13:45 UTC (permalink / raw)
To: Jan Kara; +Cc: linux-ext4, Christoph Hellwig
On Wed, May 25, 2011 at 10:43:08AM +0200, Jan Kara wrote:
> int ext4_can_truncate(struct inode *inode)
> {
> - if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
> - return 0;
I agree this change is correct, but I noticed that at the VFS level,
the ftruncate() path doesn't seem to check for IS_APPEND() and
IS_IMMUTABLE(). Am I missing something? Fixing that should be a
separate patch, of course, but it does seem to be a problem.
- Ted
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ext4: Convert ext4 to new truncate calling convention
2011-05-25 13:45 ` Ted Ts'o
@ 2011-05-25 15:34 ` Jan Kara
0 siblings, 0 replies; 4+ messages in thread
From: Jan Kara @ 2011-05-25 15:34 UTC (permalink / raw)
To: Ted Ts'o; +Cc: Jan Kara, linux-ext4, Christoph Hellwig
On Wed 25-05-11 09:45:36, Ted Tso wrote:
> On Wed, May 25, 2011 at 10:43:08AM +0200, Jan Kara wrote:
> > int ext4_can_truncate(struct inode *inode)
> > {
> > - if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
> > - return 0;
>
> I agree this change is correct, but I noticed that at the VFS level,
> the ftruncate() path doesn't seem to check for IS_APPEND() and
> IS_IMMUTABLE(). Am I missing something? Fixing that should be a
> separate patch, of course, but it does seem to be a problem.
It does check it - IMMUTABLE file cannot be open for writing so cannot
be ftruncated, APPEND file is checked in do_sys_ftruncate() AFAICS.
Honza
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-05-25 15:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-25 8:43 [PATCH] ext4: Convert ext4 to new truncate calling convention Jan Kara
2011-05-25 9:15 ` Jan Kara
2011-05-25 13:45 ` Ted Ts'o
2011-05-25 15:34 ` Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).