Re: [RFC][PATCH] Implement SEEK_HOLE/SEEK_DATA

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Nov 28, 2007  15:02 -0500, Josef Bacik wrote:
> +static loff_t generic_seek_hole_data(struct file *file, loff_t offset,
> +				     int origin)
> +{
> +	loff_t retval = -ENXIO;
> +	struct inode *inode = file->f_mapping->host;
> +	sector_t block, found_block;
> +	sector_t last_block = (i_size_read(inode) - 1) >> inode->i_blkbits;
> +	int want = (origin == SEEK_HOLE) ? 0 : 1;
> +
> +	for (block = offset >> inode->i_blkbits; block <= last_block; block++) {
> +		found_block = bmap(inode, block);
> +
> +		if (!!found_block == want) {
> +			retval = block << inode->i_blkbits;
> +			break;
> +		}
> +	}

The problem with this is that it doesn't know anything about the filesystem,
and might spin for ages in a tight loop for a large sparse or dense file.

Almost any fs would have to implement ->seek_hole_data() for this to be
useful, at which point we might as well just report -EINVAL to the
application or glibc (since this needs to be handled anyways).

Also, what about network filesystems that don't support bmap?  They will
show up as entirely holes, since bmap() returns 0 if ->bmap is not
supported.  That could lead to serious data loss, if e.g. a filesystem
is being backed up with a SEEK_DATA-aware tool.

In light of this, it makes much more sense to only support this
functionality if the filesystem explicitly adds it, instead of pretending
that it works when there are sharp pointy things in the dark corners.

Cheers, Andreas
--
Andreas Dilger
Sr. Staff Engineer, Lustre Group
Sun Microsystems of Canada, Inc.

-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux