linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Dilger <adilger@sun.com>
To: Josef Bacik <jbacik@redhat.com>
Cc: linux-fsdevel@vger.kernel.org
Subject: Re: [RFC][PATCH] Implement SEEK_HOLE/SEEK_DATA
Date: Wed, 28 Nov 2007 16:49:17 -0700	[thread overview]
Message-ID: <20071128234917.GG4913@webber.adilger.int> (raw)
In-Reply-To: <20071128200206.GB3977@dhcp243-37.rdu.redhat.com>

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.


      parent reply	other threads:[~2007-11-28 23:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-28 20:02 [RFC][PATCH] Implement SEEK_HOLE/SEEK_DATA Josef Bacik
2007-11-28 21:56 ` Brad Boyer
2007-11-28 23:38   ` Josef Bacik
2007-11-28 22:56 ` Nicholas Miell
2007-11-28 23:33   ` Josef Bacik
2007-11-28 23:50     ` Nicholas Miell
2007-11-28 23:39   ` Andreas Dilger
2007-11-28 23:48     ` Jörn Engel
2007-11-29  0:06       ` Nicholas Miell
2007-11-29  3:07         ` Jörn Engel
2007-11-29  3:27       ` Andreas Dilger
2007-11-29  4:14         ` Jörn Engel
2007-11-28 23:49 ` Andreas Dilger [this message]

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=20071128234917.GG4913@webber.adilger.int \
    --to=adilger@sun.com \
    --cc=jbacik@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    /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 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).