Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c08d3b0e authored by npiggin@suse.de's avatar npiggin@suse.de Committed by al
Browse files

truncate: use new helpers



Update some fs code to make use of new helper functions introduced
in the previous patch. Should be no significant change in behaviour
(except CIFS now calls send_sig under i_lock, via inode_newsize_ok).

Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarMiklos Szeredi <miklos@szeredi.hu>
Cc: linux-nfs@vger.kernel.org
Cc: Trond.Myklebust@netapp.com
Cc: linux-cifs-client@lists.samba.org
Cc: sfrench@samba.org
Signed-off-by: default avatarNick Piggin <npiggin@suse.de>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 25d9e2d1
Loading
Loading
Loading
Loading
+2 −8
Original line number Original line Diff line number Diff line
@@ -2239,16 +2239,10 @@ int generic_cont_expand_simple(struct inode *inode, loff_t size)
	struct address_space *mapping = inode->i_mapping;
	struct address_space *mapping = inode->i_mapping;
	struct page *page;
	struct page *page;
	void *fsdata;
	void *fsdata;
	unsigned long limit;
	int err;
	int err;


	err = -EFBIG;
	err = inode_newsize_ok(inode, size);
        limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
	if (err)
	if (limit != RLIM_INFINITY && size > (loff_t)limit) {
		send_sig(SIGXFSZ, current, 0);
		goto out;
	}
	if (size > inode->i_sb->s_maxbytes)
		goto out;
		goto out;


	err = pagecache_write_begin(NULL, mapping, size, 0,
	err = pagecache_write_begin(NULL, mapping, size, 0,
+10 −43
Original line number Original line Diff line number Diff line
@@ -1557,57 +1557,24 @@ static int cifs_truncate_page(struct address_space *mapping, loff_t from)


static int cifs_vmtruncate(struct inode *inode, loff_t offset)
static int cifs_vmtruncate(struct inode *inode, loff_t offset)
{
{
	struct address_space *mapping = inode->i_mapping;
	loff_t oldsize;
	unsigned long limit;
	int err;


	spin_lock(&inode->i_lock);
	spin_lock(&inode->i_lock);
	if (inode->i_size < offset)
	err = inode_newsize_ok(inode, offset);
		goto do_expand;
	if (err) {
	/*
	 * truncation of in-use swapfiles is disallowed - it would cause
	 * subsequent swapout to scribble on the now-freed blocks.
	 */
	if (IS_SWAPFILE(inode)) {
		spin_unlock(&inode->i_lock);
		goto out_busy;
	}
	i_size_write(inode, offset);
	spin_unlock(&inode->i_lock);
	/*
	 * unmap_mapping_range is called twice, first simply for efficiency
	 * so that truncate_inode_pages does fewer single-page unmaps. However
	 * after this first call, and before truncate_inode_pages finishes,
	 * it is possible for private pages to be COWed, which remain after
	 * truncate_inode_pages finishes, hence the second unmap_mapping_range
	 * call must be made for correctness.
	 */
	unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
	truncate_inode_pages(mapping, offset);
	unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
	goto out_truncate;

do_expand:
	limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
	if (limit != RLIM_INFINITY && offset > limit) {
		spin_unlock(&inode->i_lock);
		spin_unlock(&inode->i_lock);
		goto out_sig;
		goto out;
	}
	if (offset > inode->i_sb->s_maxbytes) {
		spin_unlock(&inode->i_lock);
		goto out_big;
	}
	}

	oldsize = inode->i_size;
	i_size_write(inode, offset);
	i_size_write(inode, offset);
	spin_unlock(&inode->i_lock);
	spin_unlock(&inode->i_lock);
out_truncate:
	truncate_pagecache(inode, oldsize, offset);
	if (inode->i_op->truncate)
	if (inode->i_op->truncate)
		inode->i_op->truncate(inode);
		inode->i_op->truncate(inode);
	return 0;
out:
out_sig:
	return err;
	send_sig(SIGXFSZ, current, 0);
out_big:
	return -EFBIG;
out_busy:
	return -ETXTBSY;
}
}


static int
static int
+4 −10
Original line number Original line Diff line number Diff line
@@ -1276,14 +1276,9 @@ static int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
		return 0;
		return 0;


	if (attr->ia_valid & ATTR_SIZE) {
	if (attr->ia_valid & ATTR_SIZE) {
		unsigned long limit;
		err = inode_newsize_ok(inode, attr->ia_size);
		if (IS_SWAPFILE(inode))
		if (err)
			return -ETXTBSY;
			return err;
		limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
		if (limit != RLIM_INFINITY && attr->ia_size > (loff_t) limit) {
			send_sig(SIGXFSZ, current, 0);
			return -EFBIG;
		}
		is_truncate = true;
		is_truncate = true;
	}
	}


@@ -1350,8 +1345,7 @@ static int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
	 * FUSE_NOWRITE, otherwise fuse_launder_page() would deadlock.
	 * FUSE_NOWRITE, otherwise fuse_launder_page() would deadlock.
	 */
	 */
	if (S_ISREG(inode->i_mode) && oldsize != outarg.attr.size) {
	if (S_ISREG(inode->i_mode) && oldsize != outarg.attr.size) {
		if (outarg.attr.size < oldsize)
		truncate_pagecache(inode, oldsize, outarg.attr.size);
			fuse_truncate(inode->i_mapping, outarg.attr.size);
		invalidate_inode_pages2(inode->i_mapping);
		invalidate_inode_pages2(inode->i_mapping);
	}
	}


+0 −2
Original line number Original line Diff line number Diff line
@@ -606,8 +606,6 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
				   u64 attr_valid);
				   u64 attr_valid);


void fuse_truncate(struct address_space *mapping, loff_t offset);

/**
/**
 * Initialize the client device
 * Initialize the client device
 */
 */
+1 −10
Original line number Original line Diff line number Diff line
@@ -140,14 +140,6 @@ static int fuse_remount_fs(struct super_block *sb, int *flags, char *data)
	return 0;
	return 0;
}
}


void fuse_truncate(struct address_space *mapping, loff_t offset)
{
	/* See vmtruncate() */
	unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
	truncate_inode_pages(mapping, offset);
	unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
}

void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
				   u64 attr_valid)
				   u64 attr_valid)
{
{
@@ -205,8 +197,7 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
	spin_unlock(&fc->lock);
	spin_unlock(&fc->lock);


	if (S_ISREG(inode->i_mode) && oldsize != attr->size) {
	if (S_ISREG(inode->i_mode) && oldsize != attr->size) {
		if (attr->size < oldsize)
		truncate_pagecache(inode, oldsize, attr->size);
			fuse_truncate(inode->i_mapping, attr->size);
		invalidate_inode_pages2(inode->i_mapping);
		invalidate_inode_pages2(inode->i_mapping);
	}
	}
}
}
Loading