All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: npiggin@suse.de
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-fsdevel@vger.kernel.org, Christoph Hellwig <hch@lst.de>
Subject: [PATCH 14/n] sysv: new truncate sequence
Date: Tue, 22 Sep 2009 16:55:32 -0400	[thread overview]
Message-ID: <20090922205532.GC12224@infradead.org> (raw)
In-Reply-To: <20090820163504.131529718@suse.de>

Signed-off-by: Christoph Hellwig <hch@lst.de>

Index: vfs-2.6.git/fs/sysv/file.c
===================================================================
--- vfs-2.6.git.orig/fs/sysv/file.c	2009-09-22 15:23:55.049764156 -0300
+++ vfs-2.6.git/fs/sysv/file.c	2009-09-22 15:35:52.993764871 -0300
@@ -31,6 +31,7 @@ const struct file_operations sysv_file_o
 };
 
 const struct inode_operations sysv_file_inode_operations = {
-	.truncate	= sysv_truncate,
+	.truncate_kludge_to_be_killed = 1,
+	.setattr	= sysv_setattr,
 	.getattr	= sysv_getattr,
 };
Index: vfs-2.6.git/fs/sysv/inode.c
===================================================================
--- vfs-2.6.git.orig/fs/sysv/inode.c	2009-09-22 15:23:55.077764435 -0300
+++ vfs-2.6.git/fs/sysv/inode.c	2009-09-22 15:31:45.210264810 -0300
@@ -305,7 +305,8 @@ static void sysv_delete_inode(struct ino
 {
 	truncate_inode_pages(&inode->i_data, 0);
 	inode->i_size = 0;
-	sysv_truncate(inode);
+	if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode))
+		sysv_truncate_blocks(inode, 0);
 	sysv_free_inode(inode);
 }
 
Index: vfs-2.6.git/fs/sysv/itree.c
===================================================================
--- vfs-2.6.git.orig/fs/sysv/itree.c	2009-09-22 15:23:55.121765981 -0300
+++ vfs-2.6.git/fs/sysv/itree.c	2009-09-22 15:39:17.898295684 -0300
@@ -360,7 +360,7 @@ static void free_branches(struct inode *
 		free_data(inode, p, q);
 }
 
-void sysv_truncate (struct inode * inode)
+void sysv_truncate_blocks(struct inode *inode, loff_t offset)
 {
 	sysv_zone_t *i_data = SYSV_I(inode)->i_data;
 	int offsets[DEPTH];
@@ -371,15 +371,8 @@ void sysv_truncate (struct inode * inode
 	long iblock;
 	unsigned blocksize;
 
-	if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
-	    S_ISLNK(inode->i_mode)))
-		return;
-
 	blocksize = inode->i_sb->s_blocksize;
-	iblock = (inode->i_size + blocksize-1)
-					>> inode->i_sb->s_blocksize_bits;
-
-	block_truncate_page(inode->i_mapping, inode->i_size, get_block);
+	iblock = (offset + blocksize - 1) >> inode->i_sb->s_blocksize_bits;
 
 	n = block_to_path(inode, iblock, offsets);
 	if (n == 0)
@@ -449,6 +442,47 @@ int sysv_getattr(struct vfsmount *mnt, s
 	return 0;
 }
 
+static int sysv_setsize(struct inode *inode, loff_t newsize)
+{
+	loff_t oldsize;
+	int error;
+
+	error = inode_newsize_ok(inode, newsize);
+	if (error)
+		return error;
+
+	oldsize = inode->i_size;
+	i_size_write(inode, newsize);
+	truncate_pagecache(inode, oldsize, newsize);
+
+	error = block_truncate_page(inode->i_mapping, newsize, get_block);
+	if (error)
+		return error;
+
+	sysv_truncate_blocks(inode, newsize);
+	return 0;
+}
+
+int sysv_setattr(struct dentry *dentry, struct iattr *iattr)
+{
+	struct inode *inode = dentry->d_inode;
+	int error;
+
+	error = inode_change_ok(inode, iattr);
+	if (error)
+		return error;
+
+	if (iattr->ia_valid & ATTR_SIZE) {
+		error = sysv_setsize(inode, iattr->ia_size);
+		if (error)
+			return error;
+	}
+
+	generic_setattr(inode, iattr);
+	mark_inode_dirty(inode);
+	return 0;
+}
+
 static int sysv_writepage(struct page *page, struct writeback_control *wbc)
 {
 	return block_write_full_page(page,get_block,wbc);
@@ -471,8 +505,33 @@ static int sysv_write_begin(struct file 
 			loff_t pos, unsigned len, unsigned flags,
 			struct page **pagep, void **fsdata)
 {
+	int ret;
+
 	*pagep = NULL;
-	return __sysv_write_begin(file, mapping, pos, len, flags, pagep, fsdata);
+	ret = __sysv_write_begin(file, mapping, pos, len, flags, pagep, fsdata);
+	if (ret < 0) {
+		struct inode *inode = mapping->host;
+		loff_t isize = inode->i_size;
+		if (pos + len > isize)
+			sysv_truncate_blocks(inode, isize);
+	}
+	return ret;
+}
+
+static int sysv_write_end(struct file *file, struct address_space *mapping,
+		loff_t pos, unsigned len, unsigned copied,
+		struct page *page, void *fsdata)
+{
+	int ret;
+
+	ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata);
+	if (ret < len) {
+		struct inode *inode = mapping->host;
+		loff_t isize = inode->i_size;
+		if (pos + len > isize)
+			sysv_truncate_blocks(inode, isize);
+	}
+	return ret;
 }
 
 static sector_t sysv_bmap(struct address_space *mapping, sector_t block)
@@ -485,6 +544,6 @@ const struct address_space_operations sy
 	.writepage = sysv_writepage,
 	.sync_page = block_sync_page,
 	.write_begin = sysv_write_begin,
-	.write_end = generic_write_end,
+	.write_end = sysv_write_end,
 	.bmap = sysv_bmap
 };
Index: vfs-2.6.git/fs/sysv/sysv.h
===================================================================
--- vfs-2.6.git.orig/fs/sysv/sysv.h	2009-09-22 15:23:55.097764604 -0300
+++ vfs-2.6.git/fs/sysv/sysv.h	2009-09-22 15:32:51.722266473 -0300
@@ -135,7 +135,7 @@ extern void sysv_free_block(struct super
 extern unsigned long sysv_count_free_blocks(struct super_block *);
 
 /* itree.c */
-extern void sysv_truncate(struct inode *);
+extern void sysv_truncate_blocks(struct inode *, loff_t);
 extern int __sysv_write_begin(struct file *file, struct address_space *mapping,
 			loff_t pos, unsigned len, unsigned flags,
 			struct page **pagep, void **fsdata);
@@ -146,6 +146,7 @@ extern int sysv_write_inode(struct inode
 extern int sysv_sync_inode(struct inode *);
 extern void sysv_set_inode(struct inode *, dev_t);
 extern int sysv_getattr(struct vfsmount *, struct dentry *, struct kstat *);
+extern int sysv_setattr(struct dentry *dentry, struct iattr *iattr);
 extern int sysv_init_icache(void);
 extern void sysv_destroy_icache(void);
 

  parent reply	other threads:[~2009-09-22 20:55 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-20 16:35 [patch 00/11] new truncate sequence npiggin
2009-08-20 16:35 ` [patch 01/11] fs: new truncate helpers npiggin
2009-08-26  7:38   ` Artem Bityutskiy
2009-09-07  7:33     ` Nick Piggin
2009-09-07  7:48       ` Artem Bityutskiy
2009-08-20 16:35 ` [patch 02/11] fs: use " npiggin
2009-08-20 16:35   ` npiggin-l3A5Bk7waGM
2009-08-20 16:35 ` [patch 03/11] fs: introduce new truncate sequence npiggin
2009-08-26  7:40   ` Artem Bityutskiy
2009-08-20 16:35 ` [patch 04/11] fs: convert simple fs to new truncate npiggin
2009-08-20 16:35 ` [patch 05/11] tmpfs: convert to use the new truncate convention npiggin
2009-08-20 16:35 ` [patch 06/11] ext2: " npiggin
2009-08-21 13:42   ` Jan Kara
2009-08-21 14:06     ` Jan Kara
2009-08-24  5:30       ` [patch] ext2: convert to use the new truncate convention fix Nick Piggin
2009-08-20 16:35 ` [patch 07/11] fat: convert to use the new truncate convention npiggin
2009-08-20 16:35 ` [patch 08/11] btrfs: " npiggin
2009-08-20 16:35   ` npiggin
2009-08-20 16:35 ` [patch 09/11] jfs: " npiggin
2009-08-20 16:35 ` [patch 10/11] udf: " npiggin
2009-08-21 14:22   ` Jan Kara
2009-08-24  5:33     ` Nick Piggin
2009-08-20 16:35 ` [patch 11/11] minix: " npiggin
2009-09-09  7:11 ` [patch 00/11] new truncate sequence Artem Bityutskiy
2009-09-22 15:04 ` Al Viro
2009-09-22 20:00   ` Christoph Hellwig
2009-09-22 21:51     ` Al Viro
2009-09-22 23:27       ` Al Viro
2009-09-22 23:58         ` Al Viro
2009-09-23  2:29           ` Al Viro
2009-09-27 19:50             ` Nick Piggin
2009-12-07 12:49             ` Nick Piggin
2009-12-07 22:46               ` Tyler Hicks
2009-09-22 20:53 ` [PATCH 12/n] kill spurious reference to vmtruncate Christoph Hellwig
2009-09-22 20:54 ` [PATCH 13/n] xfs: new truncate sequence Christoph Hellwig
2009-09-22 20:54   ` Christoph Hellwig
2009-09-22 20:55 ` Christoph Hellwig [this message]
2009-09-22 20:56 ` [PATCH 15/n] ntfs: " Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090922205532.GC12224@infradead.org \
    --to=hch@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=npiggin@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.