Commit 14e00779 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe
Browse files

zloop: use vfs_truncate



While vfs_truncate does various extra checks that we don't really need,
it is always better to use a VFS helper rather than open coding the
logic.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDamien Le Moal <dlemoal@kernel.org>
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Link: https://patch.msgid.link/20260414081811.549755-3-hch@lst.de


Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 32be3c01
Loading
Loading
Loading
Loading
+2 −15
Original line number Diff line number Diff line
@@ -1363,20 +1363,6 @@ static int zloop_ctl_add(struct zloop_options *opts)
	return ret;
}

static void zloop_truncate(struct file *file, loff_t pos)
{
	struct mnt_idmap *idmap = file_mnt_idmap(file);
	struct dentry *dentry = file_dentry(file);
	struct iattr newattrs;

	newattrs.ia_size = pos;
	newattrs.ia_valid = ATTR_SIZE;

	inode_lock(dentry->d_inode);
	notify_change(idmap, dentry, &newattrs, NULL);
	inode_unlock(dentry->d_inode);
}

static void zloop_forget_cache(struct zloop_device *zlo)
{
	unsigned int i;
@@ -1411,7 +1397,8 @@ static void zloop_forget_cache(struct zloop_device *zlo)
		if (WARN_ON_ONCE(old_wp == ULLONG_MAX))
			continue;

		zloop_truncate(file, (old_wp - zone->start) << SECTOR_SHIFT);
		vfs_truncate(&file->f_path,
			(old_wp - zone->start) << SECTOR_SHIFT);
	}
}