Skip to contentSkip to conversation

fs: add SEEK_HOLE and SEEK_DATA flags

PATCH In review Josef Bacik 11 participants 46 messages Jun 28, 2011 – Aug 31, 2011 1 message not in the archive

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 fs: add SEEK_HOLE and SEEK_DATA flags

This just gets us ready to support the SEEK_HOLE and SEEK_DATA flags. Turns out using fiemap in things like cp cause more problems than it solves, so lets try and give userspace an interface that doesn't suck. We need to match solaris here, and the definitions are

*o* If /whence/ is SEEK_HOLE, the offset of the start of the next hole greater than or equal to the supplied offset is returned. The definition of a hole is provided near the end of the DESCRIPTION.

*o* If /whence/ is SEEK_DATA, the file pointer is set to the start of the next non-hole file region greater than or equal to the supplied offset.

So in the generic case the entire file is data and there is a virtual hole at the end. That means we will just return i_size for SEEK_HOLE and will return the same offset for SEEK_DATA. This is how Solaris does it so we have to do it the same way.

Thanks,

---
 fs/read_write.c    |   44 +++++++++++++++++++++++++++++++++++++++++---
 include/linux/fs.h |    4 +++-
 2 files changed, 44 insertions(+), 4 deletions(-)
fs/read_write.c +41 -3
index 5520f8a..5907b49 100644
@@ -64,6 +64,23 @@ generic_file_llseek_unlocked(struct file *file, loff_t offset, int origin)
 			return file->f_pos;
 		offset += file->f_pos;
 		break;
+	case SEEK_DATA:
+		/*
+		 * In the generic case the entire file is data, so as long as
+		 * offset isn't at the end of the file then the offset is data.
+		 */
+		if (offset >= inode->i_size)
+			return -ENXIO;
+		break;
+	case SEEK_HOLE:
+		/*
+		 * There is a virtual hole at the end of the file, so as long as
+		 * offset isn't i_size or larger, return i_size.
+		 */
+		if (offset >= inode->i_size)
+			return -ENXIO;
+		offset = inode->i_size;
+		break;
 	}
 
 	if (offset < 0 && !unsigned_offsets(file))
@@ -128,12 +145,13 @@ EXPORT_SYMBOL(no_llseek);
 
 loff_t default_llseek(struct file *file, loff_t offset, int origin)
 {
+	struct inode *inode = file->f_path.dentry->d_inode;
 	loff_t retval;
 
-	mutex_lock(&file->f_dentry->d_inode->i_mutex);
+	mutex_lock(&inode->i_mutex);
 	switch (origin) {
 		case SEEK_END:
-			offset += i_size_read(file->f_path.dentry->d_inode);
+			offset += i_size_read(inode);
 			break;
 		case SEEK_CUR:
 			if (offset == 0) {
@@ -141,6 +159,26 @@ loff_t default_llseek(struct file *file, loff_t offset, int origin)
 				goto out;
 			}
 			offset += file->f_pos;
+			break;
+		case SEEK_DATA:
+			/*
+			 * In the generic case the entire file is data, so as
+			 * long as offset isn't at the end of the file then the
+			 * offset is data.
+			 */
+			if (offset >= inode->i_size)
+				return -ENXIO;
+			break;
+		case SEEK_HOLE:
+			/*
+			 * There is a virtual hole at the end of the file, so
+			 * as long as offset isn't i_size or larger, return
+			 * i_size.
+			 */
+			if (offset >= inode->i_size)
+				return -ENXIO;
+			offset = inode->i_size;
+			break;
 	}
 	retval = -EINVAL;
 	if (offset >= 0 || unsigned_offsets(file)) {
@@ -151,7 +189,7 @@ loff_t default_llseek(struct file *file, loff_t offset, int origin)
 		retval = offset;
 	}
 out:
-	mutex_unlock(&file->f_dentry->d_inode->i_mutex);
+	mutex_unlock(&inode->i_mutex);
 	return retval;
 }
 EXPORT_SYMBOL(default_llseek);
include/linux/fs.h +3 -1
index b5b9792..c9156f3 100644
@@ -32,7 +32,9 @@
 #define SEEK_SET	0	/* seek relative to beginning of file */
 #define SEEK_CUR	1	/* seek relative to current file position */
 #define SEEK_END	2	/* seek relative to end of file */
-#define SEEK_MAX	SEEK_END
+#define SEEK_DATA	3	/* seek to the next data */
+#define SEEK_HOLE	4	/* seek to the next hole */
+#define SEEK_MAX	SEEK_HOLE
 
 struct fstrim_range {
 	__u64 start;
Signature · 1 line
1.7.5.2
#1 lore raw

PATCH 2/4 Btrfs: implement our own ->llseek

In order to handle SEEK_HOLE/SEEK_DATA we need to implement our own llseek. Basically for the normal SEEK_*'s we will just defer to the generic helper, and for SEEK_HOLE/SEEK_DATA we will use our fiemap helper to figure out the nearest hole or data. Currently this helper doesn't check for delalloc bytes for prealloc space, so for now treat prealloc as data until that is fixed. Thanks,

---
 fs/btrfs/ctree.h |    3 +
 fs/btrfs/file.c  |  148 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 150 insertions(+), 1 deletions(-)
fs/btrfs/ctree.h +3 -0
index f30ac05..32be5e0 100644
@@ -2505,6 +2505,9 @@ int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
 int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
 			     struct list_head *list, int search_commit);
 /* inode.c */
+struct extent_map *btrfs_get_extent_fiemap(struct inode *inode, struct page *page,
+					   size_t pg_offset, u64 start, u64 len,
+					   int create);
 
 /* RHEL and EL kernels have a patch that renames PG_checked to FsMisc */
 #if defined(ClearPageFsMisc) && !defined(ClearPageChecked)
fs/btrfs/file.c +147 -1

155 lines not on this page · raw message

Signature · 1 line
1.7.5.2
#2 lore raw

PATCH 3/4 Ext4: handle SEEK_HOLE/SEEK_DATA generically

In reply to Josef Bacik

Since Ext4 has its own lseek we need to make sure it handles SEEK_HOLE/SEEK_DATA. For now just do the same thing that is done in the generic case, somebody else can come along and make it do fancy things later. Thanks,

---
 fs/ext4/file.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
fs/ext4/file.c +21 -0
index 2c09723..ce766f9 100644
@@ -236,6 +236,27 @@ loff_t ext4_llseek(struct file *file, loff_t offset, int origin)
 		}
 		offset += file->f_pos;
 		break;
+	case SEEK_DATA:
+		/*
+		 * In the generic case the entire file is data, so as long as
+		 * offset isn't at the end of the file then the offset is data.
+		 */
+		if (offset >= inode->i_size) {
+			mutex_unlock(&inode->i_mutex);
+			return -ENXIO;
+		}
+		break;
+	case SEEK_HOLE:
+		/*
+		 * There is a virtual hole at the end of the file, so as long as
+		 * offset isn't i_size or larger, return i_size.
+		 */
+		if (offset >= inode->i_size) {
+			mutex_unlock(&inode->i_mutex);
+			return -ENXIO;
+		}
+		offset = inode->i_size;
+		break;
 	}
 
 	if (offset < 0 || offset > maxbytes) {
Signature · 1 line
1.7.5.2
#3 lore raw

Re: [PATCH 3/4] Ext4: handle SEEK_HOLE/SEEK_DATA generically

Quoted 3 lines · Josef Bacik

Since Ext4 has its own lseek we need to make sure it handles SEEK_HOLE/SEEK_DATA. For now just do the same thing that is done in the generic case, somebody else can come along and make it do fancy things later. Thanks,

Josef,
are you planning to add an ext4-based version of this in the future? Another possibility is to have a generic SEEK_{DATA,HOLE} -> FIEMAP converter, since there are several filesystems that already support FIEMAP (ext3, ext4, etc).

Quoted 44 lines

---
fs/ext4/file.c | 21 +++++++++++++++++++++

1 files changed, 21 insertions(+), 0 deletions(-)
fs/ext4/file.c +21 -0
index 2c09723..ce766f9 100644
@@ -236,6 +236,27 @@ loff_t ext4_llseek(struct file *file, loff_t offset, int origin)
 		}
 		offset += file->f_pos;
 		break;
+	case SEEK_DATA:
+		/*
+		 * In the generic case the entire file is data, so as long as
+		 * offset isn't at the end of the file then the offset is data.
+		 */
+		if (offset >= inode->i_size) {
+			mutex_unlock(&inode->i_mutex);
+			return -ENXIO;
+		}
+		break;
+	case SEEK_HOLE:
+		/*
+		 * There is a virtual hole at the end of the file, so as long as
+		 * offset isn't i_size or larger, return i_size.
+		 */
+		if (offset >= inode->i_size) {
+			mutex_unlock(&inode->i_mutex);
+			return -ENXIO;
+		}
+		offset = inode->i_size;
+		break;
 	}
 
 	if (offset < 0 || offset > maxbytes) {
Signature · 6 lines
1.7.5.2

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

Cheers, Andreas

#4 lore raw

Re: [PATCH 3/4] Ext4: handle SEEK_HOLE/SEEK_DATA generically

Quoted 10 lines · Andreas Dilger
Quoted 3 lines · Josef Bacik

Since Ext4 has its own lseek we need to make sure it handles SEEK_HOLE/SEEK_DATA. For now just do the same thing that is done in the generic case, somebody else can come along and make it do fancy things later. Thanks,

Josef,
are you planning to add an ext4-based version of this in the future? Another possibility is to have a generic SEEK_{DATA,HOLE} -> FIEMAP converter, since there are several filesystems that already support FIEMAP (ext3, ext4, etc).

Probably not, I'm pretty tied up in Btrfs work. I had thought about doing a generic one that used fiemap but that's a lot of work and I'm lazy :). Plus everybody who does fiemap all have different answers on what is a hole. For example btrfs can safely say prealloc'ed space is a hole, but xfs can't (and I *think* ext4 can't either but I'm not sure).
So I figured just leaving it up to each individual fs'es instead of
hobbling together a generic fiemap->seek_hole/data translator was more prudent, especially since everybody will eventually want to do their own thing. Thanks,

Josef

#5 lore raw

PATCH 4/4 fs: handle SEEK_HOLE/SEEK_DATA properly in all fs's that define their own llseek

In reply to Josef Bacik

This converts everybody to handle SEEK_HOLE/SEEK_DATA properly. In some cases we just return -EINVAL, in others we do the normal generic thing, and in others we're simply making sure that the properly due-dilligence is done. For example in NFS/CIFS we need to make sure the file size is update properly for the SEEK_HOLE and SEEK_DATA case, but since it calls the generic llseek stuff itself that is all we have to do. Thanks,

---
 fs/block_dev.c   |   11 ++++++++---
 fs/ceph/dir.c    |    8 +++++++-
 fs/ceph/file.c   |   20 ++++++++++++++++++--
 fs/cifs/cifsfs.c |    7 +++++--
 fs/fuse/file.c   |   21 +++++++++++++++++++--
 fs/hpfs/dir.c    |    4 ++++
 fs/nfs/file.c    |    7 +++++--
 7 files changed, 66 insertions(+), 12 deletions(-)
fs/block_dev.c +8 -3
index 610e8e0..966617a 100644
@@ -355,20 +355,25 @@ static loff_t block_llseek(struct file *file, loff_t offset, int origin)
 	mutex_lock(&bd_inode->i_mutex);
 	size = i_size_read(bd_inode);
 
+	retval = -EINVAL;
 	switch (origin) {
-		case 2:
+		case SEEK_END:
 			offset += size;
 			break;
-		case 1:
+		case SEEK_CUR:
 			offset += file->f_pos;
+		case SEEK_SET:
+			break;
+		default:
+			goto out;
 	}
-	retval = -EINVAL;
 	if (offset >= 0 && offset <= size) {
 		if (offset != file->f_pos) {
 			file->f_pos = offset;
 		}
 		retval = offset;
 	}
+out:
 	mutex_unlock(&bd_inode->i_mutex);
 	return retval;
 }
fs/ceph/dir.c +7 -1
index ef8f08c..79cd77c 100644
@@ -446,14 +446,19 @@ static loff_t ceph_dir_llseek(struct file *file, loff_t offset, int origin)
 	loff_t retval;
 
 	mutex_lock(&inode->i_mutex);
+	retval = -EINVAL;
 	switch (origin) {
 	case SEEK_END:
 		offset += inode->i_size + 2;   /* FIXME */
 		break;
 	case SEEK_CUR:
 		offset += file->f_pos;
+	case SEEK_SET:
+		break;
+	default:
+		goto out;
 	}
-	retval = -EINVAL;
+
 	if (offset >= 0 && offset <= inode->i_sb->s_maxbytes) {
 		if (offset != file->f_pos) {
 			file->f_pos = offset;
@@ -477,6 +482,7 @@ static loff_t ceph_dir_llseek(struct file *file, loff_t offset, int origin)
 		if (offset > old_offset)
 			fi->dir_release_count--;
 	}
+out:
 	mutex_unlock(&inode->i_mutex);
 	return retval;
 }
fs/ceph/file.c +18 -2
index 9542f07..774feb1 100644
@@ -770,13 +770,16 @@ static loff_t ceph_llseek(struct file *file, loff_t offset, int origin)
 
 	mutex_lock(&inode->i_mutex);
 	__ceph_do_pending_vmtruncate(inode);
-	switch (origin) {
-	case SEEK_END:
+	if (origin != SEEK_CUR || origin != SEEK_SET) {
 		ret = ceph_do_getattr(inode, CEPH_STAT_CAP_SIZE);
 		if (ret < 0) {
 			offset = ret;
 			goto out;
 		}
+	}
+
+	switch (origin) {
+	case SEEK_END:
 		offset += inode->i_size;
 		break;
 	case SEEK_CUR:
@@ -792,6 +795,19 @@ static loff_t ceph_llseek(struct file *file, loff_t offset, int origin)
 		}
 		offset += file->f_pos;
 		break;
+	case SEEK_DATA:
+		if (offset >= inode->i_size) {
+			ret = -ENXIO;
+			goto out;
+		}
+		break;
+	case SEEK_HOLE:
+		if (offset >= inode->i_size) {
+			ret = -ENXIO;
+			goto out;
+		}
+		offset = inode->i_size;
+		break;
 	}
 
 	if (offset < 0 || offset > inode->i_sb->s_maxbytes) {
fs/cifs/cifsfs.c +5 -2
index 35f9154..5feb6bb 100644
@@ -746,8 +746,11 @@ static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
 
 static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
 {
-	/* origin == SEEK_END => we must revalidate the cached file length */
-	if (origin == SEEK_END) {
+	/*
+	 * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate
+	 * the cached file length
+	 */
+	if (origin != SEEK_SET || origin != SEEK_CUR) {
 		int rc;
 		struct inode *inode = file->f_path.dentry->d_inode;
 
fs/fuse/file.c +19 -2
index 82a6646..73b89df 100644
@@ -1600,15 +1600,32 @@ static loff_t fuse_file_llseek(struct file *file, loff_t offset, int origin)
 	struct inode *inode = file->f_path.dentry->d_inode;
 
 	mutex_lock(&inode->i_mutex);
-	switch (origin) {
-	case SEEK_END:
+	if (origin != SEEK_CUR || origin != SEEK_SET) {
 		retval = fuse_update_attributes(inode, NULL, file, NULL);
 		if (retval)
 			goto exit;
+	}
+
+	switch (origin) {
+	case SEEK_END:
 		offset += i_size_read(inode);
 		break;
 	case SEEK_CUR:
 		offset += file->f_pos;
+		break;
+	case SEEK_DATA:
+		if (offset >= i_size_read(inode)) {
+			retval = -ENXIO;
+			goto exit;
+		}
+		break;
+	case SEEK_HOLE:
+		if (offset >= i_size_read(inode)) {
+			retval = -ENXIO;
+			goto exit;
+		}
+		offset = i_size_read(inode);
+		break;
 	}
 	retval = -EINVAL;
 	if (offset >= 0 && offset <= inode->i_sb->s_maxbytes) {
fs/hpfs/dir.c +4 -0
index f46ae02..96a8ed9 100644
@@ -29,6 +29,10 @@ static loff_t hpfs_dir_lseek(struct file *filp, loff_t off, int whence)
 	struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
 	struct super_block *s = i->i_sb;
 
+	/* Somebody else will have to figure out what to do here */
+	if (whence == SEEK_DATA || whence == SEEK_HOLE)
+		return -EINVAL;
+
 	hpfs_lock(s);
 
 	/*printk("dir lseek\n");*/
fs/nfs/file.c +5 -2
index 2f093ed..2c1705b 100644
@@ -187,8 +187,11 @@ static loff_t nfs_file_llseek(struct file *filp, loff_t offset, int origin)
 			filp->f_path.dentry->d_name.name,
 			offset, origin);
 
-	/* origin == SEEK_END => we must revalidate the cached file length */
-	if (origin == SEEK_END) {
+	/*
+	 * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate
+	 * the cached file length
+	 */
+	if (origin != SEEK_SET || origin != SEEK_CUR) {
 		struct inode *inode = filp->f_mapping->host;
 
 		int retval = nfs_revalidate_file_size(inode, filp);
Signature · 1 line
1.7.5.2
#6 lore raw

PATCH 1/1 xfstests 255: add a seek_data/seek_hole tester

In reply to Josef Bacik

This is a test to make sure seek_data/seek_hole is acting like it does on Solaris. It will check to see if the fs supports finding a hole or not and will adjust as necessary.

---
 255               |   71 ++++++++
 255.out           |    2 +
 group             |    1 +
 src/Makefile      |    2 +-
 src/seek-tester.c |  475 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 550 insertions(+), 1 deletions(-)
 create mode 100755 255
 create mode 100644 255.out
 create mode 100644 src/seek-tester.c
255 new file +71 -0
new file mode 100755
index 0000000..4bb4d0b
@@ -0,0 +1,71 @@
+#! /bin/bash
+# FS QA Test No. 255
+#
+# Test SEEK_DATA and SEEK_HOLE
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2011 Red Hat.  All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+#-----------------------------------------------------------------------
+#
+# creator
[email protected]
+
+seq=`basename $0`
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1	# failure is the default!
+
+_cleanup()
+{
+    rm -f $tmp.*
+}
+
+trap "_cleanup ; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+
+testfile=$TEST_DIR/seek_test.$$
+logfile=$TEST_DIR/seek_test.$$.log
+
+[ -x $here/src/seek-tester ] || _notrun "seek-tester not built"
+
+_cleanup()
+{
+	rm -f $testfile
+	rm -f $logfile
+}
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+echo "Silence is golden"
+$here/src/seek-tester -q $testfile 2>&1 | tee -a $logfile
+
+if grep -q "SEEK_HOLE is not supported" $logfile; then
+	_notrun "SEEK_HOLE/SEEK_DATA not supported by this kernel"
+fi
+
+rm -f $logfile
+rm -f $testfile
+
+status=0 ; exit
255.out new file +2 -0
new file mode 100644
index 0000000..7eefb82
@@ -0,0 +1,2 @@
+QA output created by 255
+Silence is golden
group +1 -0
index 1f86075..c045e70 100644
@@ -368,3 +368,4 @@ deprecated
 252 auto quick prealloc
 253 auto quick
 254 auto quick
+255 auto quick
src/Makefile +1 -1
index 91088bf..ccdaeec 100644
@@ -17,7 +17,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
 	preallo_rw_pattern_writer ftrunc trunc fs_perms testx looptest \
 	locktest unwritten_mmap bulkstat_unlink_test t_stripealign \
 	bulkstat_unlink_test_modified t_dir_offset t_futimens t_immutable \
-	stale_handle pwrite_mmap_blocked fstrim
+	stale_handle pwrite_mmap_blocked fstrim seek-tester
 
 SUBDIRS =
 
src/seek-tester.c new file +475 -0

475 lines not on this page · raw message

Signature · 1 line
1.7.5.2
#7 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

Quoted 1 line · Josef Bacik

This is a test to make sure seek_data/seek_hole is acting like it doe=

s on

Quoted 1 line

Solaris. It will check to see if the fs supports finding a hole or n=

ot and will

Quoted 1 line

adjust as necessary.

So I just looked at this with an eye to validating an XFS implementation, and I came up with this list of stuff that the test does not cover that I'd need to test in some way:

- files with clean unwritten extents. Are they a hole or data? What's SEEK_DATA supposed to return on layout like hole-unwritten-data? i.e. needs to add fallocate to the picture...

- files with dirty unwritten extents (i.e. dirty in memory, not on disk). They are most definitely data, and most filesystems will need a separate lookup path to detect dirty unwritten ranges because the state is kept separately (page cache vs extent cache). Plenty of scope for filesystem specific bugs here so needs a roubust test.

- cold cache behaviour - all dirty data ranges the test creates are hot in cache and not even forced to disk, so it is not testing the no-page-cache-over-the-data-range case. i.e. it tests delalloc state tracking but not data-extent-already exists lookups during a seek.

- assumes that allocation size is the block size and that holes follows block size alignment. We already know that ext4 does not follow that rule when doing small sparse writes close together in a file, and XFS is also known to fill holes when doing sparse writes past EOF.

- only tests single block data extents =D1=95o doesn't cover corner cases like skipping over multiple fragmented data extents to the next hole.

Some more comments in line....

Quoted 7 lines
255 new file +7 -0
+_cleanup()
+{
+    rm -f $tmp.*
+}
+
+trap "_cleanup ; exit \$status" 0 1 2 3 15
+

255

Quoted 10 lines
255 new file +10 -0
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+
+testfile=3D$TEST_DIR/seek_test.$$
+logfile=3D$TEST_DIR/seek_test.$$.log

The log file is usually named $seq.full, and doesn't get placed in the filesystem being tested. It gets saved in the xfstests directory along side $seq.out.bad for analysis whenteh test fails...

255 line 62

Quoted 11 lines

+[ -x $here/src/seek-tester ] || _notrun "seek-tester not built"

255 new file +10 -0
+
+_cleanup()
+{
+	rm -f $testfile
+	rm -f $logfile
+}
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+echo "Silence is golden"
+$here/src/seek-tester -q $testfile 2>&1 | tee -a $logfile

Personally I'd prefer the test to be a bit noisy about what it is running, especially when there are so many subtests the single invocation is running. It makes no difference to the run time ofthe test, or the output when something fails, but it at least allows you to run the test manually and see what it is doing easily...

Quoted 22 lines
255 new file +9 -0
+
+if grep -q "SEEK_HOLE is not supported" $logfile; then
+	_notrun "SEEK_HOLE/SEEK_DATA not supported by this kernel"
+fi
+
+rm -f $logfile
+rm -f $testfile
+
+status=3D0 ; exit
255.out new file +2 -0
new file mode 100644
index 0000000..7eefb82
@@ -0,0 +1,2 @@
+QA output created by 255
+Silence is golden
group +0 -0
index 1f86075..c045e70 100644

group deprecated · line 371

Quoted 4 lines
group +1 -0
@@ -368,3 +368,4 @@ deprecated
 252 auto quick prealloc
 253 auto quick
 254 auto quick
+255 auto quick

I'd suggest that rw and prealloc (once unwritten extent testing is added) groups should also be defined for this test.

Otherwise, the test code looks ok if a bit over-engineered....

group

Quoted 13 lines
group +13 -0
+struct testrec {
+	int	test_num;
+	int	(*test_func)(int fd, int testnum);
+	char	*test_desc;
+};
+
+struct testrec seek_tests[] =3D {
+	{  1, test01, "Test basic support" },
+	{  2, test02, "Test an empty file" },
+	{  3, test03, "Test a full file" },
+	{  4, test04, "Test file hole at beg, data at end" },
+	{  5, test05, "Test file data at beg, hole at end" },
+	{  6, test06, "Test file hole data hole data" },

So, to take from the hole punch test matrix, it covers a bunch more file state transitions and cases that are just as relevant to SEEK_HOLE/SEEK_DATA. Those cases are:

#       1. into a hole
#       2. into allocated space
#       3. into unwritten space
#       4. hole -> data
#       5. hole -> unwritten
#       6. data -> hole
#       7. data -> unwritten
#       8. unwritten -> hole
#       9. unwritten -> data
#       10. hole -> data -> hole
#       11. data -> hole -> data
#       12. unwritten -> data -> unwritten
#       13. data -> unwritten -> data
#       14. data -> hole @ EOF
#       15. data -> hole @ 0
#       16. data -> cache cold ->hole
#       17. data -> hole in single block file

I thikn we also need to cover most of these same cases, right? And SEEK_HOLE/SEEK data also need to explicitly separate the unwritten tests into "clean unwritten" and "dirty unwritten" and cover the transitions between regions of those states as well, right?

Cheers,

Dave.

--=20
Dave Chinner
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

Quoted 14 lines · Dave Chinner
Quoted 3 lines · Josef Bacik

This is a test to make sure seek_data/seek_hole is acting like it does on Solaris. It will check to see if the fs supports finding a hole or not and will adjust as necessary.

So I just looked at this with an eye to validating an XFS implementation, and I came up with this list of stuff that the test does not cover that I'd need to test in some way:

- files with clean unwritten extents. Are they a hole or data? What's SEEK_DATA supposed to return on layout like hole-unwritten-data? i.e. needs to add fallocate to the picture...

Quoted 6 lines

- files with dirty unwritten extents (i.e. dirty in memory, not on disk). They are most definitely data, and most filesystems will need a separate lookup path to detect dirty unwritten ranges because the state is kept separately (page cache vs extent cache). Plenty of scope for filesystem specific bugs here so needs a roubust test.

The discussion leading up to the resurrection of SEEK_HOLE/SEEK_DATA was pretty much about that point. The conclusion based on the Sun documentation and common sense was that SEEK_DATA may only consider unwritten extents as hole if the filesystem has a way to distinguish plain unwritten extents and those that have been dirtied. Else it should be considered data.

Testing for making sure dirty preallocated areas aren't wrongly reported sounds relatively easy, the rest falls into implementation details, which imho is fine. Not reporting preallocated extents as holes just is a quality of implementation issue and not a bug.

#9 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

Quoted 3 lines · Christoph Hellwig
Quoted 2 lines · Dave Chinner
Quoted 1 line · Josef Bacik

This is a test to make sure seek_data/seek_hole is acting like it d=

oes on

Quoted 1 line
Quoted 1 line
Quoted 1 line

Solaris. It will check to see if the fs supports finding a hole or=

not and will

Quoted 17 lines
Quoted 11 lines
Quoted 1 line

adjust as necessary.

So I just looked at this with an eye to validating an XFS implementation, and I came up with this list of stuff that the test does not cover that I'd need to test in some way:

- files with clean unwritten extents. Are they a hole or data? What's SEEK_DATA supposed to return on layout like hole-unwritten-data? i.e. needs to add fallocate to the picture...

Quoted 6 lines

- files with dirty unwritten extents (i.e. dirty in memory, not on disk). They are most definitely data, and most filesystems will need a separate lookup path to detect dirty unwritten ranges because the state is kept separately (page cache vs extent cache). Plenty of scope for filesystem specific bugs here so needs a roubust test.

Quoted 12 lines

=20
The discussion leading up to the resurrection of SEEK_HOLE/SEEK_DATA was pretty much about that point. The conclusion based on the Sun documentation and common sense was that SEEK_DATA may only consider unwritten extents as hole if the filesystem has a way to distinguish plain unwritten extents and those that have been dirtied. Else it should be considered data.
=20
Testing for making sure dirty preallocated areas aren't wrongly reported sounds relatively easy, the rest falls into implementation details, which imho is fine. Not reporting preallocated extents as holes just is a quality of implementation issue and not a bug.

There is the argument, that if this interface can distinguish these dirty unwritten extents, then why can't the fiemap interface too? The advantage of the fiemap interface is that it can distinguish empty extents vs holes. Empty extents will become increasingly common I think, given the fragmentation and space guarantee benefits they give= =2E
It would be cool for cp for example to be able to efficiently copy empty extents from source to dest.

cheers,
P=E1draig.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

Quoted 2 lines · On 06/29/2011 03:42 AM, P=E1draig Brady wrote:

There is the argument, that if this interface can distinguish these dirty unwritten extents, then why can't the fiemap interface to=

o?

Quoted 3 lines

The advantage of the fiemap interface is that it can distinguish empty extents vs holes. Empty extents will become increasingly common I think, given the fragmentation and space guarantee benefits they gi=

ve.

Quoted 2 lines

It would be cool for cp for example to be able to efficiently copy empty extents from source to dest.

I'm not too sure about that. Atleast not enabled by default. Most users use cp to backup data. Not empty space. In this case, this empty extent may not even be de-dupable.

=46rankly I'd be happier of cp started to exploited fallocate() to crea= te larger
extents before copying data into them. Atleast for the large files. --
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel= " in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#11 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

Quoted 6 lines · Sunil Mushran

I'm not too sure about that. Atleast not enabled by default. Most users use cp to backup data. Not empty space. In this case, this empty extent may not even be de-dupable.

Frankly I'd be happier of cp started to exploited fallocate() to create larger extents before copying data into them. Atleast for the large files.

That's what delayed allocation is for.

#12 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

Quoted 8 lines · Christoph Hellwig
Quoted 6 lines · Sunil Mushran

I'm not too sure about that. Atleast not enabled by default. Most users use cp to backup data. Not empty space. In this case, this empty extent may not even be de-dupable.

Frankly I'd be happier of cp started to exploited fallocate() to create larger extents before copying data into them. Atleast for the large files.

That's what delayed allocation is for.

A feature fewer file systems support than fallocate(). ;)

#13 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

In reply to Sunil Mushran
Quoted 3 lines · Sunil Mushran
Quoted 2 lines · On 06/29/2011 03:42 AM, P=E1draig Brady wrote:

There is the argument, that if this interface can distinguish these dirty unwritten extents, then why can't the fiemap interface t=

oo?

Quoted 2 lines
Quoted 2 lines

The advantage of the fiemap interface is that it can distinguish empty extents vs holes. Empty extents will become increasingly commo=

n

Quoted 1 line
Quoted 1 line

I think, given the fragmentation and space guarantee benefits they g=

ive.

Quoted 4 lines
Quoted 2 lines

It would be cool for cp for example to be able to efficiently copy empty extents from source to dest.

=20
I'm not too sure about that. Atleast not enabled by default. Most use=

rs

Quoted 1 line

use cp to backup data. Not empty space. In this case, this empty exte=

nt

Quoted 1 line

may not even be de-dupable.

That's a fair point. On the other hand if
you wanted to start working with the backup copy,
you might want it allocated to avoid fragmentation and ENOSPC issues. What we were going with was empty -> hole with cp --sparse=3Dalways and empty -> empty otherwise. If empty and hole can not be distinguished though, then this process will be impacted.

Quoted 2 lines

=20
Frankly I'd be happier of cp started to exploited fallocate() to crea=

te

Quoted 2 lines

larger
extents before copying data into them. Atleast for the large files.

Yes we definitely will start doing that. That will help fragmentation and give early ENOSPC. We can't use fiemap for this at the moment (on XSF or ext4 (without a sync))
but the seek_data interface should allow us to do this to some extent (pardon the pun).

cheers,
P=E1draig.

#14 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

In reply to Pádraig Brady
Quoted 7 lines · P?draig Brady

There is the argument, that if this interface can distinguish these dirty unwritten extents, then why can't the fiemap interface too? The advantage of the fiemap interface is that it can distinguish empty extents vs holes. Empty extents will become increasingly common I think, given the fragmentation and space guarantee benefits they give. It would be cool for cp for example to be able to efficiently copy empty extents from source to dest.

That brings us back to square one. FIEMAP is supposed to tell you about the physical layout on disk. Unwritten extents physically always are there, but whether they might have to be copied depends entirely on in-core state. Finding that incore state in addition is not all that easy compared to simply walking the extents. People might decide it's worth for an interface like SEEK_HOLE specificly asking for that, but grafting it into FIEMAP through the backdoor is a horrible idea.

#15 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

In reply to Christoph Hellwig
Quoted 27 lines · Christoph Hellwig
Quoted 13 lines · Dave Chinner
Quoted 3 lines · Josef Bacik

This is a test to make sure seek_data/seek_hole is acting like it does on Solaris. It will check to see if the fs supports finding a hole or not and will adjust as necessary.

So I just looked at this with an eye to validating an XFS implementation, and I came up with this list of stuff that the test does not cover that I'd need to test in some way:

- files with clean unwritten extents. Are they a hole or data? What's SEEK_DATA supposed to return on layout like hole-unwritten-data? i.e. needs to add fallocate to the picture...

Quoted 6 lines

- files with dirty unwritten extents (i.e. dirty in memory, not on disk). They are most definitely data, and most filesystems will need a separate lookup path to detect dirty unwritten ranges because the state is kept separately (page cache vs extent cache). Plenty of scope for filesystem specific bugs here so needs a roubust test.

The discussion leading up to the resurrection of SEEK_HOLE/SEEK_DATA was pretty much about that point. The conclusion based on the Sun documentation and common sense was that SEEK_DATA may only consider unwritten extents as hole if the filesystem has a way to distinguish plain unwritten extents and those that have been dirtied. Else it should be considered data.

Quoted 4 lines

Testing for making sure dirty preallocated areas aren't wrongly reported sounds relatively easy, the rest falls into implementation details, which imho is fine. Not reporting preallocated extents as holes just is a quality of implementation issue and not a bug.

I agree. And if I might add my 2 cents that it would be much easier if we added another test that created files with all the worrisome boundary conditions and used SEEK_DATA/HOLE to copy the files and compared using md5sum. This would be far easier than one that expects a certain pos for each operation.

#16 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

Quoted 35 lines · Sunil Mushran
Quoted 29 lines · Christoph Hellwig
Quoted 15 lines · Dave Chinner
Quoted 5 lines · Josef Bacik

This is a test to make sure seek_data/seek_hole is acting like it does on
Solaris. It will check to see if the fs supports finding a hole or not and will
adjust as necessary.

So I just looked at this with an eye to validating an XFS implementation, and I came up with this list of stuff that the test does not cover that I'd need to test in some way:

- files with clean unwritten extents. Are they a hole or data? What's SEEK_DATA supposed to return on layout like hole-unwritten-data? i.e. needs to add fallocate to the picture...

Quoted 6 lines

- files with dirty unwritten extents (i.e. dirty in memory, not on disk). They are most definitely data, and most filesystems will need a separate lookup path to detect dirty unwritten ranges because the state is kept separately (page cache vs extent cache). Plenty of scope for filesystem specific bugs here so needs a roubust test.

The discussion leading up to the resurrection of SEEK_HOLE/SEEK_DATA was pretty much about that point. The conclusion based on the Sun documentation and common sense was that SEEK_DATA may only consider unwritten extents as hole if the filesystem has a way to distinguish plain unwritten extents and those that have been dirtied. Else it should be considered data.

Quoted 4 lines

Testing for making sure dirty preallocated areas aren't wrongly reported sounds relatively easy, the rest falls into implementation details, which imho is fine. Not reporting preallocated extents as holes just is a quality of implementation issue and not a bug.

Quoted 5 lines

I agree. And if I might add my 2 cents that it would be much easier if we added another test that created files with all the worrisome boundary conditions and used SEEK_DATA/HOLE to copy the files and compared using md5sum. This would be far easier than one that expects a certain pos for each operation.

That's a great point, I think I will rig something like that up. Thanks,

Josef

#17 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

In reply to Dave Chinner
Quoted 2 lines · Dave Chinner
Quoted 1 line · Josef Bacik

This is a test to make sure seek_data/seek_hole is acting like it do=

es on

Quoted 1 line
Quoted 1 line

Solaris. It will check to see if the fs supports finding a hole or =

not and will

Quoted 30 lines
Quoted 1 line

adjust as necessary.

So I just looked at this with an eye to validating an XFS implementation, and I came up with this list of stuff that the test does not cover that I'd need to test in some way:

- files with clean unwritten extents. Are they a hole or data? What's SEEK_DATA supposed to return on layout like hole-unwritten-data? i.e. needs to add fallocate to the picture...

- files with dirty unwritten extents (i.e. dirty in memory, not on disk). They are most definitely data, and most filesystems will need a separate lookup path to detect dirty unwritten ranges because the state is kept separately (page cache vs extent cache). Plenty of scope for filesystem specific bugs here so needs a roubust test.

- cold cache behaviour - all dirty data ranges the test creates are hot in cache and not even forced to disk, so it is not testing the no-page-cache-over-the-data-range case. i.e. it tests delalloc state tracking but not data-extent-already exists lookups during a seek.

- assumes that allocation size is the block size and that holes follows block size alignment. We already know that ext4 does not follow that rule when doing small sparse writes close together in a file, and XFS is also known to fill holes when doing sparse writes past EOF.

Quoted 4 lines

- only tests single block data extents =D1=95o doesn't cover corner cases like skipping over multiple fragmented data extents to the next hole.

Yeah I intentionally left out preallocated stuff because these are goin= g=20
to be implementation specific, so I was going to leave that for a later= =20
exercise when people actually start doing proper implementations.

Quoted 15 lines

Some more comments in line....

Quoted 13 lines
255 new file +13 -0
+_cleanup()
+{
+    rm -f $tmp.*
+}
+
+trap "_cleanup ; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+
+# real QA test starts here
+_supported_fs generic
Quoted 9 lines

255

Quoted 4 lines
255 new file +4 -0
+_supported_os Linux
+
+testfile=3D$TEST_DIR/seek_test.$$
+logfile=3D$TEST_DIR/seek_test.$$.log

The log file is usually named $seq.full, and doesn't get placed in the filesystem being tested. It gets saved in the xfstests directory along side $seq.out.bad for analysis whenteh test fails...

I only want it to see if SEEK_HOLE fails so I can say it didn't run. I= =20
followed the same example as the fiemap test that Eric wrote.

Quoted 9 lines
Quoted 9 lines

+[ -x $here/src/seek-tester ] || _notrun "seek-tester not built"

255 new file +8 -0
+
+_cleanup()
+{
+	rm -f $testfile
+	rm -f $logfile
+}
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
Quoted 9 lines
Quoted 2 lines

+echo "Silence is golden"
+$here/src/seek-tester -q $testfile 2>&1 | tee -a $logfile

Personally I'd prefer the test to be a bit noisy about what it is running, especially when there are so many subtests the single invocation is running. It makes no difference to the run time ofthe test, or the output when something fails, but it at least allows you to run the test manually and see what it is doing easily...

Right, the problem with this test is it will run differently depending=20 on the implementation. I agree, I really like the noisy output tests,=20 but unfortunately if I run this test on ext4 where it currently treats=20 the entire file as data, and then run it on btrfs where it is smarter=20 and actually recognizes holes, we end up with two different outputs tha= t=20
are both correct.

Quoted 68 lines
Quoted 22 lines
255 new file +9 -0
+
+if grep -q "SEEK_HOLE is not supported" $logfile; then
+	_notrun "SEEK_HOLE/SEEK_DATA not supported by this kernel"
+fi
+
+rm -f $logfile
+rm -f $testfile
+
+status=3D0 ; exit
255.out new file +2 -0
new file mode 100644
index 0000000..7eefb82
@@ -0,0 +1,2 @@
+QA output created by 255
+Silence is golden
group +0 -0
index 1f86075..c045e70 100644

group deprecated · line 371

Quoted 4 lines
group +1 -0
@@ -368,3 +368,4 @@ deprecated
  252 auto quick prealloc
  253 auto quick
  254 auto quick
+255 auto quick

I'd suggest that rw and prealloc (once unwritten extent testing is added) groups should also be defined for this test.

Otherwise, the test code looks ok if a bit over-engineered....

group

Quoted 13 lines
group +13 -0
+struct testrec {
+	int	test_num;
+	int	(*test_func)(int fd, int testnum);
+	char	*test_desc;
+};
+
+struct testrec seek_tests[] =3D {
+	{  1, test01, "Test basic support" },
+	{  2, test02, "Test an empty file" },
+	{  3, test03, "Test a full file" },
+	{  4, test04, "Test file hole at beg, data at end" },
+	{  5, test05, "Test file data at beg, hole at end" },
+	{  6, test06, "Test file hole data hole data" },

So, to take from the hole punch test matrix, it covers a bunch more file state transitions and cases that are just as relevant to SEEK_HOLE/SEEK_DATA. Those cases are:

#       1. into a hole
#       2. into allocated space
#       3. into unwritten space
#       4. hole ->  data
#       5. hole ->  unwritten
#       6. data ->  hole
#       7. data ->  unwritten
#       8. unwritten ->  hole
#       9. unwritten ->  data
#       10. hole ->  data ->  hole
#       11. data ->  hole ->  data
#       12. unwritten ->  data ->  unwritten
#       13. data ->  unwritten ->  data
#       14. data ->  hole @ EOF
#       15. data ->  hole @ 0
#       16. data ->  cache cold ->hole
#       17. data ->  hole in single block file
Quoted 5 lines

I thikn we also need to cover most of these same cases, right? And SEEK_HOLE/SEEK data also need to explicitly separate the unwritten tests into "clean unwritten" and "dirty unwritten" and cover the transitions between regions of those states as well, right?

Yeah you are right, but again doing preallocated stuff is tricky, but I= =20
can expand it now if that's what we want. Thanks,

Josef

#18 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

In reply to Josef Bacik
Quoted 3 lines · Josef Bacik

This is a test to make sure seek_data/seek_hole is acting like it does on Solaris. It will check to see if the fs supports finding a hole or not and will adjust as necessary.

Can you resend this with any updates that happened in the meantime?

Dave also still had some comments about semantics, so it might be worth to incorporate that as well.

#19 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

Quoted 9 lines · Christoph Hellwig
Quoted 3 lines · Josef Bacik

This is a test to make sure seek_data/seek_hole is acting like it does on Solaris. It will check to see if the fs supports finding a hole or not and will adjust as necessary.

Can you resend this with any updates that happened in the meantime?

Dave also still had some comments about semantics, so it might be worth to incorporate that as well.

The main questions I had when looking at this was how we should handle unwritten extents - the only answer I got was along the lines of "we'll deal with that once filesystems have implemented something". That's a bit of a chicken-and-egg situation, and doesn't help me decide what is the best thing to do. I don't want to have to re-implement this code when it's decided i did the wrong thing initially.

The most basic question I really want answered is this:

- is preallocated space a HOLE, or is it DATA?

Whatever the answer, I think it should be consistently presented by all filesystems that support preallocation, and it should be encoded into the generic SEEK_HOLE/SEEK_DATA tests....

Answering that question then helps answer the more complex questions I had, like:

- what does SEEK_DATA return when you have a file layout like "hole-prealloc-data"?

Answers to that sort of question need to be known so we can write corner-case tests to correctly verify the filesystem implementation.

I like to do better than present userspace with an interface that behaves vastly different depending on the underlying filesystem, but if the answer is "definition and implementation is entirely filesystem specific" then I'll just go make something up....

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#20 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

Quoted 10 lines · Dave Chinner
Quoted 8 lines · Christoph Hellwig
Quoted 2 lines · Josef Bacik

This is a test to make sure seek_data/seek_hole is acting like it does on
Solaris. It will check to see if the fs supports finding a hole or not and will adjust as necessary.

Can you resend this with any updates that happened in the meantime?

Dave also still had some comments about semantics, so it might be worth to incorporate that as well.

Quoted 7 lines

The main questions I had when looking at this was how we should handle unwritten extents - the only answer I got was along the lines of "we'll deal with that once filesystems have implemented something". That's a bit of a chicken-and-egg situation, and doesn't help me decide what is the best thing to do. I don't want to have to re-implement this code when it's decided i did the wrong thing initially.

Let's first clarify what you mean by an unwritten extent? Do you mean a preallocated extent that returns 0 when read, or do you mean a delayed allocation extent that was written by the application that is still in memory but not yet written to disk?

Unfortunately, ZFS has no concept of preallocated extents, so we can't look to it for precedent, but it definitely has delayed allocation. Possibly if UFS on Solaris has SEEK_HOLE and also preallocated extents (I have no idea) it could be tested?

Quoted 7 lines

The most basic question I really want answered is this:

- is preallocated space a HOLE, or is it DATA?

Whatever the answer, I think it should be consistently presented by all filesystems that support preallocation, and it should be encoded into the generic SEEK_HOLE/SEEK_DATA tests....

My thought would be that a preallocated extent is still a HOLE, because it doesn't contain data that an application actually cares about. On the other hand, a delalloc extent is DATA because it has something that an application cares about.

The original reason SEEK_HOLE/SEEK_DATA were brought up over FIEMAP was "cp" being able to consistently access delalloc data that was only in the page cache, so if we don't get that right it will have been a pointless exercise.

Quoted 5 lines

Answering that question then helps answer the more complex questions I had, like:

- what does SEEK_DATA return when you have a file layout like "hole-prealloc-data"?

I would think only the "data" part, since that is what the definition of "SEEK_DATA" is IMHO.

Quoted 18 lines

Answers to that sort of question need to be known so we can write corner-case tests to correctly verify the filesystem implementation.

I like to do better than present userspace with an interface that behaves vastly different depending on the underlying filesystem, but if the answer is "definition and implementation is entirely filesystem specific" then I'll just go make something up....

Cheers,

Dave.

Signature · 6 lines
Dave Chinner
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Cheers, Andreas

#21 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

Quoted 19 lines · Andreas Dilger
Quoted 10 lines · Dave Chinner
Quoted 8 lines · Christoph Hellwig
Quoted 2 lines · Josef Bacik

This is a test to make sure seek_data/seek_hole is acting like it does on
Solaris. It will check to see if the fs supports finding a hole or not and will adjust as necessary.

Can you resend this with any updates that happened in the meantime?

Dave also still had some comments about semantics, so it might be worth to incorporate that as well.

Quoted 7 lines

The main questions I had when looking at this was how we should handle unwritten extents - the only answer I got was along the lines of "we'll deal with that once filesystems have implemented something". That's a bit of a chicken-and-egg situation, and doesn't help me decide what is the best thing to do. I don't want to have to re-implement this code when it's decided i did the wrong thing initially.

Quoted 2 lines

Let's first clarify what you mean by an unwritten extent? Do you mean a preallocated extent that returns 0 when read,

Exactly that.

Quoted 3 lines

or do you mean a delayed
allocation extent that was written by the application that is still in memory but not yet written to disk?

That's not an unwritten extent - that's a delayed allocation extent ;)

Quoted 9 lines

Unfortunately, ZFS has no concept of preallocated extents, so we can't look to it for precedent, but it definitely has delayed allocation. Possibly if UFS on Solaris has SEEK_HOLE and also preallocated extents (I have no idea) it could be tested?

Quoted 4 lines

The most basic question I really want answered is this:

- is preallocated space a HOLE, or is it DATA?

Quoted 8 lines
Quoted 3 lines

Whatever the answer, I think it should be consistently presented by all filesystems that support preallocation, and it should be encoded into the generic SEEK_HOLE/SEEK_DATA tests....

My thought would be that a preallocated extent is still a HOLE, because it doesn't contain data that an application actually cares about. On the other hand, a delalloc extent is DATA because it has something that an application cares about.

OK, that's the way I'd expect to treat both preallocated and delalloc space.

Quoted 8 lines
Quoted 5 lines

Answering that question then helps answer the more complex questions I had, like:

- what does SEEK_DATA return when you have a file layout like "hole-prealloc-data"?

I would think only the "data" part, since that is what the definition of "SEEK_DATA" is IMHO.

Agreed, that's the way I'd interpret it, too. So perhaps we need to ensure that this interpretation is actually tested by this test?

How about some definitions to work by:

Data: a range of the file that contains valid data, regardless of whether it exists in memory or on disk. The valid data can be preceeded and/or followed by an arbitrary number of zero bytes dependent on the underlying implementation of hole detection.

Hole: a range of the file that contains no data or is made up entirely of NULL (zero) data. Holes include preallocated ranges of files that have not had actual data written to them.

Does that make sense? It has sufficient flexibility in it for the existing generic "non-implementation", allows for filesystems to define their own hole detection boundaries (e.g. filesystem block size), and effectively defines how preallocated ranges from fallocate() should be treated (i.e. as holes). If we can agree on those definitions, I think that we should document them in both the kernel and the man page that defines SEEK_HOLE/SEEK_DATA so everyone is on the same page...

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#22 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

2011/8/26 Dave Chinner <[email protected]>:

Quoted 5 lines · Andreas Dilger
Quoted 4 lines · Dave Chinner
Quoted 3 lines · Christoph Hellwig
Quoted 2 lines · Josef Bacik
Quoted 1 line

This is a test to make sure seek_data/seek_hole is acting like i=

t does on

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Solaris. =A0It will check to see if the fs supports finding a ho=

le or not and will adjust as necessary.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Can you resend this with any updates that happened in the meantim=

e?

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Dave also still had some comments about semantics, so it might be=

worth

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

to incorporate that as well.

The main questions I had when looking at this was how we should handle unwritten extents - the only answer I got was along the lin=

es

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

of "we'll deal with that once filesystems have implemented something". That's a bit of a chicken-and-egg situation, and doesn=

't

Quoted 1 line
Quoted 1 line
Quoted 1 line

help me decide what is the best thing to do. I don't want to have =

to

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

re-implement this code when it's decided i did the wrong thing initially.

Let's first clarify what you mean by an unwritten extent? =A0Do you =

mean a

Quoted 6 lines
Quoted 1 line

preallocated extent that returns 0 when read,

Exactly that.

Quoted 2 lines

or do you mean a delayed
allocation extent that was written by the application that is still =

in

Quoted 3 lines
Quoted 1 line

memory but not yet written to disk?

That's not an unwritten extent - that's a delayed allocation extent ;=

)

Quoted 2 lines
Quoted 2 lines

Unfortunately, ZFS has no concept of preallocated extents, so we can=

't

Quoted 2 lines
Quoted 2 lines

look to it for precedent, but it definitely has delayed allocation. Possibly if UFS on Solaris has SEEK_HOLE and also preallocated exten=

ts

Quoted 11 lines
Quoted 11 lines

(I have no idea) it could be tested?

Quoted 7 lines

The most basic question I really want answered is this:

=A0 =A0 - is preallocated space a HOLE, or is it DATA?

Whatever the answer, I think it should be consistently presented by all filesystems that support preallocation, and it should be encoded into the generic SEEK_HOLE/SEEK_DATA tests....

My thought would be that a preallocated extent is still a HOLE, beca=

use

Quoted 1 line
Quoted 1 line

it doesn't contain data that an application actually cares about. =A0=

On

Quoted 1 line
Quoted 1 line

the other hand, a delalloc extent is DATA because it has something t=

hat

Quoted 6 lines
Quoted 1 line

an application cares about.

OK, that's the way I'd expect to treat both preallocated and delalloc space.

Quoted 1 line
Quoted 1 line

Answering that question then helps answer the more complex questio=

ns

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

I had, like:

=A0 =A0 - what does SEEK_DATA return when you have a file layout =A0 =A0 =A0 like "hole-prealloc-data"?

I would think only the "data" part, since that is what the definitio=

n

Quoted 12 lines
Quoted 1 line

of "SEEK_DATA" is IMHO.

Agreed, that's the way I'd interpret it, too. So perhaps we need to ensure that this interpretation is actually tested by this test?

How about some definitions to work by:

Data: a range of the file that contains valid data, regardless of whether it exists in memory or on disk. The valid data can be preceeded and/or followed by an arbitrary number of zero bytes dependent on the underlying implementation of hole detection.

Quoted 5 lines

Hole: a range of the file that contains no data or is made up entirely of =A0NULL (zero) data. Holes include preallocated ranges of files that have not had actual data written to them.

Does that make sense? It has sufficient flexibility in it for the

No for me. A hole is made up of zero data? It's a strange definition for me. A hole is simply no data. With this definition a hole can be start from a block with data but partially filled, and fs should check instead of presence of a block, the data content. I don't like it very much. For the fallocate case, we need only a simple rule: no check is done beyond eof. At this point it's clear that we can check the file block allocation till i_size, don't care if there are other blocks allocated. I don't know if it's applicable even for unwritten extents case.

Marco

#23 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

Quoted 2 lines
Quoted 2 lines

Hole: a range of the file that contains no data or is made up entirely of =A0NULL (zero) data. Holes include preallocated ranges =

of

Quoted 4 lines
Quoted 1 line

files that have not had actual data written to them.

No for me. A hole is made up of zero data? It's a strange definition for me.

It's a very natural definition for me. It mirrors the behaviour of read() of sparse data inside i_size that file system authors already have to consider.

It's also a reminder for people that this interface is about avoiding reading zeros. Systems that track contents can do this for files that had tons of zeros written. The data is there but the app is specifically asking us to skip it by using SEEK_DATA.

- z
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#24 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

Il 26/08/2011 16:41, Zach Brown ha scritto:

Quoted 11 lines
Quoted 6 lines
Quoted 3 lines

Hole: a range of the file that contains no data or is made up entirely of NULL (zero) data. Holes include preallocated ranges of files that have not had actual data written to them.

No for me. A hole is made up of zero data? It's a strange definition for me.

It's a very natural definition for me. It mirrors the behaviour of read() of sparse data inside i_size that file system authors already have to consider.

Quoted 7 lines

It's also a reminder for people that this interface is about avoiding reading zeros. Systems that track contents can do this for files that had tons of zeros written. The data is there but the app is specifically asking us to skip it by using SEEK_DATA.

- z

I think we need to consider a hole and "data not present/not written yet" as two different cases even they are related. For example, if I do an fallocate without keep size option, then I do a read, I have the same behavior of sparse data inside i_size, but the blocks are allocated so no sparse data in this case. Simply there are no difference from app point of view.

Marco

#25 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

Il 27/08/2011 10:30, Marco Stornelli ha scritto:

Quoted 20 lines

Il 26/08/2011 16:41, Zach Brown ha scritto:

Quoted 11 lines
Quoted 6 lines
Quoted 3 lines

Hole: a range of the file that contains no data or is made up entirely of NULL (zero) data. Holes include preallocated ranges of files that have not had actual data written to them.

No for me. A hole is made up of zero data? It's a strange definition for me.

It's a very natural definition for me. It mirrors the behaviour of read() of sparse data inside i_size that file system authors already have to consider.

Quoted 7 lines

It's also a reminder for people that this interface is about avoiding reading zeros. Systems that track contents can do this for files that had tons of zeros written. The data is there but the app is specifically asking us to skip it by using SEEK_DATA.

- z

Quoted 8 lines

I think we need to consider a hole and "data not present/not written yet" as two different cases even they are related. For example, if I do an fallocate without keep size option, then I do a read, I have the same behavior of sparse data inside i_size, but the blocks are allocated so no sparse data in this case. Simply there are no difference from app point of view.

Marco

Please don't care about the last part, when reading in this case the app will have a return value different from zero obviously, I was under the effect of a beer :) However I'd add to the definition, that we consider holes only inside i_size, as Zack said. In this way, we haven't got any ambiguity for preallocated space beyond eof.

Marco

#26 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

In reply to Marco Stornelli
Quoted 17 lines · Marco Stornelli

Il 26/08/2011 16:41, Zach Brown ha scritto:

Quoted 16 lines
Quoted 6 lines
Quoted 3 lines

Hole: a range of the file that contains no data or is made up entirely of NULL (zero) data. Holes include preallocated ranges of files that have not had actual data written to them.

No for me. A hole is made up of zero data? It's a strange definition for me.

It's a very natural definition for me. It mirrors the behaviour of read() of sparse data inside i_size that file system authors already have to consider.

It's also a reminder for people that this interface is about avoiding reading zeros. Systems that track contents can do this for files that had tons of zeros written. The data is there but the app is specifically asking us to skip it by using SEEK_DATA.

Quoted 4 lines
Quoted 2 lines

- z

I think we need to consider a hole and "data not present/not written yet" as two different cases even they are related. For example, if I do an fallocate without keep size option, then I do a read, I have the same behavior of sparse data inside i_size, but the blocks are allocated so no sparse data in this case. Simply there are no difference from app point of view.

Exactly. That's why seek_hole should identify them alike, if possible. But that should not be a requirement because the sole aim here is to improve performance. Identifying a hole as data is not the end of the world. In some cases it may be more efficient. We just have to ensure that we don't identify data as a hole.

BTW, we still have the fiemap interface that allows users to identify unwritten extents, etc. Use that if you want that kind of detail.

#27 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

In reply to Dave Chinner
Quoted 14 lines · Dave Chinner

Agreed, that's the way I'd interpret it, too. So perhaps we need to ensure that this interpretation is actually tested by this test?

How about some definitions to work by:

Data: a range of the file that contains valid data, regardless of whether it exists in memory or on disk. The valid data can be preceeded and/or followed by an arbitrary number of zero bytes dependent on the underlying implementation of hole detection.

Hole: a range of the file that contains no data or is made up entirely of NULL (zero) data. Holes include preallocated ranges of files that have not had actual data written to them.

Quoted 8 lines

Does that make sense? It has sufficient flexibility in it for the existing generic "non-implementation", allows for filesystems to define their own hole detection boundaries (e.g. filesystem block size), and effectively defines how preallocated ranges from fallocate() should be treated (i.e. as holes). If we can agree on those definitions, I think that we should document them in both the kernel and the man page that defines SEEK_HOLE/SEEK_DATA so everyone is on the same page...

We should not tie in the definition to existing fs technologies. Instead we should let the fs weigh the cost of providing accurate information with the possible gain in performance.

Data:
A range in a file that could contain something other than nulls. If in doubt, it is data.

Hole:
A range in a file that only contains nulls.

#28 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

Quoted 24 lines · Sunil Mushran
Quoted 14 lines · Dave Chinner

Agreed, that's the way I'd interpret it, too. So perhaps we need to ensure that this interpretation is actually tested by this test?

How about some definitions to work by:

Data: a range of the file that contains valid data, regardless of whether it exists in memory or on disk. The valid data can be preceeded and/or followed by an arbitrary number of zero bytes dependent on the underlying implementation of hole detection.

Hole: a range of the file that contains no data or is made up entirely of NULL (zero) data. Holes include preallocated ranges of files that have not had actual data written to them.

Quoted 8 lines

Does that make sense? It has sufficient flexibility in it for the existing generic "non-implementation", allows for filesystems to define their own hole detection boundaries (e.g. filesystem block size), and effectively defines how preallocated ranges from fallocate() should be treated (i.e. as holes). If we can agree on those definitions, I think that we should document them in both the kernel and the man page that defines SEEK_HOLE/SEEK_DATA so everyone is on the same page...

Quoted 1 line

We should not tie in the definition to existing fs technologies.

Such as? If we don't use well known, well defined terminology, we end up with ambiguous, vague functionality and inconsistent implementations.

Quoted 10 lines

Instead
we should let the fs weigh the cost of providing accurate information with the possible gain in performance.

Data:
A range in a file that could contain something other than nulls. If in doubt, it is data.

Hole:
A range in a file that only contains nulls.

And that's -exactly- the ambiguous, vague definition that has raised all these questions in the first place. I was in doubt about whether unwritten extents can be considered a hole, and by your definition that means it should be data. But Andreas seems to be in no doubt it should be considered a hole.

Hence if I implement XFS support and Andreas implements ext4 support by your defintion, we end with vastly different behaviour even though the two filesystems use the same underlying technology for preallocated ranges. That's exactly the inconsistency in implementation that I'd like us to avoid.

IOWs, the definition needs to be clear enough to prevent these inconsistencies from occurring. Indeed, the phrase "preallocated ranges that have not had data written to them" is as independent of filesystem implementation or technologies as possible. However, because Linux supports preallocation (unlike our reference platform), and we encourage developers to use it where appropriate, it is best that we define how we expect such ranges to behave clearly. That makes life easier for everyone.

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#29 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

Quoted 54 lines · Dave Chinner
Quoted 24 lines · Sunil Mushran
Quoted 14 lines · Dave Chinner

Agreed, that's the way I'd interpret it, too. So perhaps we need to ensure that this interpretation is actually tested by this test?

How about some definitions to work by:

Data: a range of the file that contains valid data, regardless of whether it exists in memory or on disk. The valid data can be preceeded and/or followed by an arbitrary number of zero bytes dependent on the underlying implementation of hole detection.

Hole: a range of the file that contains no data or is made up entirely of NULL (zero) data. Holes include preallocated ranges of files that have not had actual data written to them.

Quoted 8 lines

Does that make sense? It has sufficient flexibility in it for the existing generic "non-implementation", allows for filesystems to define their own hole detection boundaries (e.g. filesystem block size), and effectively defines how preallocated ranges from fallocate() should be treated (i.e. as holes). If we can agree on those definitions, I think that we should document them in both the kernel and the man page that defines SEEK_HOLE/SEEK_DATA so everyone is on the same page...

Quoted 1 line

We should not tie in the definition to existing fs technologies.

Such as? If we don't use well known, well defined terminology, we end up with ambiguous, vague functionality and inconsistent implementations.

Quoted 10 lines

Instead
we should let the fs weigh the cost of providing accurate information with the possible gain in performance.

Data:
A range in a file that could contain something other than nulls. If in doubt, it is data.

Hole:
A range in a file that only contains nulls.

And that's -exactly- the ambiguous, vague definition that has raised all these questions in the first place. I was in doubt about whether unwritten extents can be considered a hole, and by your definition that means it should be data. But Andreas seems to be in no doubt it should be considered a hole.

Hence if I implement XFS support and Andreas implements ext4 support by your defintion, we end with vastly different behaviour even though the two filesystems use the same underlying technology for preallocated ranges. That's exactly the inconsistency in implementation that I'd like us to avoid.

Quoted 8 lines

IOWs, the definition needs to be clear enough to prevent these inconsistencies from occurring. Indeed, the phrase "preallocated ranges that have not had data written to them" is as independent of filesystem implementation or technologies as possible. However, because Linux supports preallocation (unlike our reference platform), and we encourage developers to use it where appropriate, it is best that we define how we expect such ranges to behave clearly. That makes life easier for everyone.

Since a sparse file has the holes filled by nulls by definition, it seems fairly clear that they chould count as holes. In fact, I would not be surprised to see some filesystem _only_ report the unwritten pieces of sparse files as holes (not any other ranges of nulls)

the question I have is how large does the range of nulls need to be before it's reported as a hole? disk sectors, filesystem blocks, other?

David Lang

#30 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

In reply to Dave Chinner
Quoted 5 lines · Dave Chinner

And that's -exactly- the ambiguous, vague definition that has raised all these questions in the first place. I was in doubt about whether unwritten extents can be considered a hole, and by your definition that means it should be data. But Andreas seems to be in no doubt it should be considered a hole.

Fair enough. Let me rephrase.

Data:
A range in a file when read could return something other than nulls.

Hole:
A range in a file when read only returns nulls.

Considering preallocated extents only return null, they should be considered holes.

#31 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

Quoted 6 lines · Sunil Mushran
Quoted 5 lines · Dave Chinner

And that's -exactly- the ambiguous, vague definition that has raised all these questions in the first place. I was in doubt about whether unwritten extents can be considered a hole, and by your definition that means it should be data. But Andreas seems to be in no doubt it should be considered a hole.

Quoted 11 lines

=20
Fair enough. Let me rephrase.
=20
Data:
A range in a file when read could return something other than nulls. =20
Hole:
A range in a file when read only returns nulls.
=20
Considering preallocated extents only return null, they should be considered holes.

I would concur with this.
Treating preallocated extents as holes will allow them to be processed quickly by cp etc.

What we lose is the ability to copy the allocation from src to dst. But that's less important in comparison, and could probably be done on a per file rather than per extent basis anyway.
Note preallocation would be good for disk layout and timely ENOSPC.

Note fiemap gives us greater control by distinguishing holes and empty extents, thus allowing us to both efficiently copy and maintain allocation. But that interface currently requires a sync of the file on some file systems, which we couldn't enable for performance reasons in cp.

cheers,
P=E1draig.

#32 lore raw

Re: [PATCH] xfstests 255: add a seek_data/seek_hole tester

In reply to Dave Chinner
Quoted 9 lines · Dave Chinner
Quoted 8 lines · Sunil Mushran

Instead
we should let the fs weigh the cost of providing accurate information with the possible gain in performance.

Data:
A range in a file that could contain something other than nulls. If in doubt, it is data.

Quoted 8 lines
Quoted 2 lines

Hole:
A range in a file that only contains nulls.

And that's -exactly- the ambiguous, vague definition that has raised all these questions in the first place. I was in doubt about whether unwritten extents can be considered a hole, and by your definition that means it should be data. But Andreas seems to be in no doubt it should be considered a hole.

That's fine, though. Different filesystems have different abilities
to recognize a data hole - FAT can't do it at all. Perhaps the
requirements would be better stated in reverse: If the filesystem knows that a read() will return nulls (for whatever reason based on it's internal knowledge), it can report a hole. If it can't guarantee
that, it's data. It's an absolute requirement that SEEK_DATA never
miss data. SEEK_HOLE working is a nicety that userspace would appreciate - remember that the consumer here is cp(1), using it to skip empty portions of files and create sparse destination files.

#33 lore raw
In reply to Josef Bacik

Sorry maybe I'm a bit late? :)

Il 28/06/2011 17:33, Josef Bacik ha scritto:

fs/read_write.c EXPORT_SYMBOL(no_llseek); · line 154

Quoted 12 lines
  loff_t default_llseek(struct file *file, loff_t offset, int origin)
  {
fs/read_write.c +3 -2
+	struct inode *inode = file->f_path.dentry->d_inode;
  	loff_t retval;
 
-	mutex_lock(&file->f_dentry->d_inode->i_mutex);
+	mutex_lock(&inode->i_mutex);
  	switch (origin) {
  		case SEEK_END:
-			offset += i_size_read(file->f_path.dentry->d_inode);
+			offset += i_size_read(inode);

Here we are under mutex, so I think we can use directly i_size without i_size_read.

Marco

#34 lore raw
In reply to Josef Bacik

Hi,

Il 28/06/2011 17:33, Josef Bacik ha scritto:

Quoted 5 lines

This just gets us ready to support the SEEK_HOLE and SEEK_DATA flags. Turns out using fiemap in things like cp cause more problems than it solves, so lets try and give userspace an interface that doesn't suck. We need to match solaris here, and the definitions are

Quoted 9 lines

*o* If /whence/ is SEEK_HOLE, the offset of the start of the next hole greater than or equal to the supplied offset is returned. The definition of a hole is provided near the end of the DESCRIPTION.

*o* If /whence/ is SEEK_DATA, the file pointer is set to the start of the next non-hole file region greater than or equal to the supplied offset.

I'm implementing the SEEK_DATA/SEEK_HOLE management for pramfs and I've got some doubts about the right behavior:

1) when we use SEEK_DATA/SEEK_HOLE, the offset used in lseek means always the offset from the start of the file, right?

2) in case of a file with hole at the beginning and data at the end, if I do lseek(fd, 0, SEEK_HOLE) I should receive the end of the file because the idea is to search the *next* hole and we have always a virtual hole at the end of the file, right?

3) about the last sentence of point 2), is it always true even if we have a case of block allocation beyond the end of file (fallocate with keep size option)?

Thanks.

Regards,

Marco

#35 lore raw

Il 20/08/2011 11:41, Marco Stornelli ha scritto:

Quoted 24 lines

Hi,

Il 28/06/2011 17:33, Josef Bacik ha scritto:

Quoted 8 lines

This just gets us ready to support the SEEK_HOLE and SEEK_DATA flags. Turns out
using fiemap in things like cp cause more problems than it solves, so lets try
and give userspace an interface that doesn't suck. We need to match solaris
here, and the definitions are

Quoted 9 lines

*o* If /whence/ is SEEK_HOLE, the offset of the start of the next hole greater than or equal to the supplied offset is returned. The definition of a hole is provided near the end of the DESCRIPTION.

*o* If /whence/ is SEEK_DATA, the file pointer is set to the start of the next non-hole file region greater than or equal to the supplied offset.

I'm implementing the SEEK_DATA/SEEK_HOLE management for pramfs and I've got some doubts about the right behavior:

Quoted 7 lines

1) when we use SEEK_DATA/SEEK_HOLE, the offset used in lseek means always the offset from the start of the file, right?

2) in case of a file with hole at the beginning and data at the end, if I do lseek(fd, 0, SEEK_HOLE) I should receive the end of the file because the idea is to search the *next* hole and we have always a virtual hole at the end of the file, right?

Just to be precise about this question: the alternative here, it's to return the same position because we are already in a hole.

Marco

#36 lore raw
Quoted 28 lines · Marco Stornelli

Il 20/08/2011 11:41, Marco Stornelli ha scritto:

Quoted 27 lines

Hi,

Il 28/06/2011 17:33, Josef Bacik ha scritto:

Quoted 8 lines

This just gets us ready to support the SEEK_HOLE and SEEK_DATA flags. Turns out
using fiemap in things like cp cause more problems than it solves, so lets try
and give userspace an interface that doesn't suck. We need to match solaris
here, and the definitions are

Quoted 9 lines

*o* If /whence/ is SEEK_HOLE, the offset of the start of the next hole greater than or equal to the supplied offset is returned. The definition of a hole is provided near the end of the DESCRIPTION.

*o* If /whence/ is SEEK_DATA, the file pointer is set to the start of the next non-hole file region greater than or equal to the supplied offset.

I'm implementing the SEEK_DATA/SEEK_HOLE management for pramfs and I've got some doubts about the right behavior:

1) when we use SEEK_DATA/SEEK_HOLE, the offset used in lseek means always the offset from the start of the file, right?

Quoted 6 lines
Quoted 4 lines

2) in case of a file with hole at the beginning and data at the end, if I do lseek(fd, 0, SEEK_HOLE) I should receive the end of the file because the idea is to search the *next* hole and we have always a virtual hole at the end of the file, right?

Just to be precise about this question: the alternative here, it's to return the same position because we are already in a hole.

Yes, the offset is from the start of the file.

And yes, same offset is ok. I think the word next should be dropped from the definition. It is misleading.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#37 lore raw

Il 20/08/2011 17:36, Sunil Mushran ha scritto:

Quoted 34 lines · Marco Stornelli
Quoted 33 lines

Il 20/08/2011 11:41, Marco Stornelli ha scritto:

Quoted 31 lines

Hi,

Il 28/06/2011 17:33, Josef Bacik ha scritto:

Quoted 8 lines

This just gets us ready to support the SEEK_HOLE and SEEK_DATA flags. Turns out
using fiemap in things like cp cause more problems than it solves, so lets try
and give userspace an interface that doesn't suck. We need to match solaris
here, and the definitions are

Quoted 9 lines

*o* If /whence/ is SEEK_HOLE, the offset of the start of the next hole greater than or equal to the supplied offset is returned. The definition of a hole is provided near the end of the DESCRIPTION.

*o* If /whence/ is SEEK_DATA, the file pointer is set to the start of the next non-hole file region greater than or equal to the supplied offset.

I'm implementing the SEEK_DATA/SEEK_HOLE management for pramfs and I've got some doubts about the right behavior:

1) when we use SEEK_DATA/SEEK_HOLE, the offset used in lseek means always the offset from the start of the file, right?

2) in case of a file with hole at the beginning and data at the end, if I do lseek(fd, 0, SEEK_HOLE) I should receive the end of the file because the idea is to search the *next* hole and we have always a virtual hole at the end of the file, right?

Quoted 8 lines
Quoted 2 lines

Just to be precise about this question: the alternative here, it's to return the same position because we are already in a hole.

Yes, the offset is from the start of the file.

And yes, same offset is ok. I think the word next should be dropped from the definition. It is misleading.

Thank. Yes the word "next" is not very clear. I re-read the proposal for the standard, actually it's seems to me that if we are in the last hole we should return the file size, if we are not in the last hole than it's ok the same offset - "....except that if offset falls beyond the last byte not within a hole, then the file
offset may be set to the file size instead".

Marco

#38 lore raw
Quoted 40 lines · Marco Stornelli

Il 20/08/2011 17:36, Sunil Mushran ha scritto:

Quoted 39 lines · Marco Stornelli
Quoted 28 lines

Il 20/08/2011 11:41, Marco Stornelli ha scritto:

Quoted 27 lines

Hi,

Il 28/06/2011 17:33, Josef Bacik ha scritto:

Quoted 8 lines

This just gets us ready to support the SEEK_HOLE and SEEK_DATA flags. Turns out
using fiemap in things like cp cause more problems than it solves, so lets try
and give userspace an interface that doesn't suck. We need to match solaris
here, and the definitions are

Quoted 9 lines

*o* If /whence/ is SEEK_HOLE, the offset of the start of the next hole greater than or equal to the supplied offset is returned. The definition of a hole is provided near the end of the DESCRIPTION.

*o* If /whence/ is SEEK_DATA, the file pointer is set to the start of the next non-hole file region greater than or equal to the supplied offset.

I'm implementing the SEEK_DATA/SEEK_HOLE management for pramfs and I've got some doubts about the right behavior:

1) when we use SEEK_DATA/SEEK_HOLE, the offset used in lseek means always the offset from the start of the file, right?

Quoted 7 lines
Quoted 4 lines

2) in case of a file with hole at the beginning and data at the end, if I do lseek(fd, 0, SEEK_HOLE) I should receive the end of the file because the idea is to search the *next* hole and we have always a virtual hole at the end of the file, right?

Just to be precise about this question: the alternative here, it's to return the same position because we are already in a hole.

Yes, the offset is from the start of the file.

Quoted 7 lines
Quoted 3 lines

And yes, same offset is ok. I think the word next should be dropped from the definition. It is misleading.

Thank. Yes the word "next" is not very clear. I re-read the proposal for the standard, actually it's seems to me that if we are in the last hole we should return the file size, if we are not in the last hole than it's ok the same offset - "....except that if offset falls beyond the last byte not within a hole, then the file
offset may be set to the file size instead".

Any proposal that differentiates between holes is wrong. It should not matter where the hole is.

Think of it from the usage-pov.

doff = 0;

while ((doff = lseek(SEEK_DATA, doff)) != -ENXIO) {
    hoff = lseek(SEEK_HOLE, doff);
    read_offset = doff;
    read_len = hoff -doff;
    process();
    doff = hoff;
}

The goal is to make this as efficient as follows. Treating the last hole differently adds more code for no benefit.

#39 lore raw

2011/8/22 Sunil Mushran <[email protected]>:

Quoted 6 lines · Marco Stornelli
Quoted 5 lines

Il 20/08/2011 17:36, Sunil Mushran ha scritto:

Quoted 3 lines · Marco Stornelli
Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Il 20/08/2011 11:41, Marco Stornelli ha scritto:

Quoted 6 lines

Hi,

Il 28/06/2011 17:33, Josef Bacik ha scritto:

Quoted 2 lines

This just gets us ready to support the SEEK_HOLE and SEEK_DATA f=

lags.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Turns out
using fiemap in things like cp cause more problems than it solve=

s, so

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

lets try
and give userspace an interface that doesn't suck. We need to ma=

tch

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

solaris
here, and the definitions are

*o* If /whence/ is SEEK_HOLE, the offset of the start of the next hole greater than or equal to the supplied offset is returned. The definition of a hole is provided near the end of the DESCRIPTION.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

*o* If /whence/ is SEEK_DATA, the file pointer is set to the start of the next non-hole file region greater than or equal to the supplied offset.

I'm implementing the SEEK_DATA/SEEK_HOLE management for pramfs an=

d I've

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

got some doubts about the right behavior:

1) when we use SEEK_DATA/SEEK_HOLE, the offset used in lseek mean=

s

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

always the offset from the start of the file, right?

2) in case of a file with hole at the beginning and data at the e=

nd, if

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

I do lseek(fd, 0, SEEK_HOLE) I should receive the end of the file because the idea is to search the *next* hole and we have always =

a

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

virtual hole at the end of the file, right?

Just to be precise about this question: the alternative here, it's=

to

Quoted 9 lines
Quoted 9 lines
Quoted 7 lines
Quoted 1 line

return the same position because we are already in a hole.

Yes, the offset is from the start of the file.

And yes, same offset is ok. I think the word next should be dropped from the definition. It is misleading.

Thank. Yes the word "next" is not very clear. I re-read the proposal=

for

Quoted 1 line
Quoted 1 line

the standard, actually it's seems to me that if we are in the last h=

ole we

Quoted 1 line
Quoted 1 line

should return the file size, if we are not in the last hole than it'=

s ok the

Quoted 2 lines
Quoted 2 lines

same offset - "....except that
if offset falls beyond the last byte not within a hole, then the fil=

e

Quoted 3 lines
Quoted 1 line

offset may be set to the file size instead".

Any proposal that differentiates between holes is wrong. It should no=

t

Quoted 13 lines

matter where the hole is.

Think of it from the usage-pov.

doff =3D 0;
while ((doff =3D lseek(SEEK_DATA, doff)) !=3D -ENXIO) { =A0 =A0hoff =3D lseek(SEEK_HOLE, doff);
=A0 =A0read_offset =3D doff;
=A0 =A0read_len =3D hoff -doff;
=A0 =A0process();
=A0 =A0doff =3D hoff;
}

Quoted 4 lines

The goal is to make this as efficient as follows. Treating the last hole differently adds more code for no benefit.

Mmmm.....It seems that Josef has to be clear in this point. However I looked for the seek hole test in xfs test suite, but I didn't find anything. Btrfs guys, how have you got tested the implementation? What do you think about this corner case? Al, what do you think about it?

Marco
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#40 lore raw
Quoted 22 lines · Marco Stornelli

2011/8/22 Sunil Mushran<[email protected]>:

Quoted 21 lines · Marco Stornelli
Quoted 6 lines

Thank. Yes the word "next" is not very clear. I re-read the proposal for the standard, actually it's seems to me that if we are in the last hole we should return the file size, if we are not in the last hole than it's ok the same offset - "....except that
if offset falls beyond the last byte not within a hole, then the file offset may be set to the file size instead".

Any proposal that differentiates between holes is wrong. It should not matter where the hole is.

Think of it from the usage-pov.

doff = 0;

while ((doff = lseek(SEEK_DATA, doff)) != -ENXIO) {
    hoff = lseek(SEEK_HOLE, doff);
    read_offset = doff;
    read_len = hoff -doff;
    process();
    doff = hoff;
}
Quoted 7 lines
Quoted 3 lines

The goal is to make this as efficient as follows. Treating the last hole differently adds more code for no benefit.

Mmmm.....It seems that Josef has to be clear in this point. However I looked for the seek hole test in xfs test suite, but I didn't find anything. Btrfs guys, how have you got tested the implementation? What do you think about this corner case? Al, what do you think about it?

The following test was used to test the early implementations.
http://oss.oracle.com/~smushran/seek_data/

#41 lore raw

Il 22/08/2011 17:57, Sunil Mushran ha scritto:

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines

Any proposal that differentiates between holes is wrong. It should not matter where the hole is.

Think of it from the usage-pov.

doff = 0;
while ((doff = lseek(SEEK_DATA, doff)) != -ENXIO) { hoff = lseek(SEEK_HOLE, doff);
read_offset = doff;
read_len = hoff -doff;
process();
doff = hoff;
}

The goal is to make this as efficient as follows. Treating the last hole differently adds more code for no benefit.

Quoted 9 lines
Quoted 4 lines

Mmmm.....It seems that Josef has to be clear in this point. However I looked for the seek hole test in xfs test suite, but I didn't find anything. Btrfs guys, how have you got tested the implementation? What do you think about this corner case? Al, what do you think about it?

The following test was used to test the early implementations.
http://oss.oracle.com/~smushran/seek_data/

Thank you very much!! I found another point. Your test fails with my implementation because here (http://www.austingroupbugs.net/view.php?id=415) says: "If whence is SEEK_DATA, the file offset shall be set to the smallest location of a byte not within a hole and not less than offset. It shall be an error if no such byte exists." So in this case I return ENXIO but the test expects another value. I have to say that there is a bit of confusion about the real behavior of this new feature :)

Marco

#42 lore raw
Quoted 8 lines · Marco Stornelli

Il 22/08/2011 17:57, Sunil Mushran ha scritto:

Quoted 4 lines

The following test was used to test the early implementations.
http://oss.oracle.com/~smushran/seek_data/

Thank you very much!! I found another point. Your test fails with my implementation because here (http://www.austingroupbugs.net/view.php?id=415) says: "If whence is SEEK_DATA, the file offset shall be set to the smallest location of a byte not within a hole and not less than offset. It shall be an error if no such byte exists." So in this case I return ENXIO but the test expects another value. I have to say that there is a bit of confusion about the real behavior of this new feature :)

That's test 5.10, 5.12, 5.14. And it expects -ENXIO.

Which test is failing for you?

#43 lore raw

Il 22/08/2011 23:22, Sunil Mushran ha scritto:

Quoted 17 lines · Marco Stornelli
Quoted 6 lines

Il 22/08/2011 17:57, Sunil Mushran ha scritto:

Quoted 4 lines

The following test was used to test the early implementations.
http://oss.oracle.com/~smushran/seek_data/

Quoted 9 lines

Thank you very much!! I found another point. Your test fails with my implementation because here
(http://www.austingroupbugs.net/view.php?id=415) says: "If whence is SEEK_DATA, the file offset shall be set to the smallest location of a byte not within a hole and not less than offset. It shall be an error if no such byte exists." So in this case I return ENXIO but the test expects another value. I have to say that there is a bit of confusion about the real behavior of this new feature :)

Quoted 4 lines

That's test 5.10, 5.12, 5.14. And it expects -ENXIO.

Which test is failing for you?

Sorry, I was reading the results in a wrong way.

Marco

#44 lore raw
In reply to Marco Stornelli
Quoted 28 lines · Marco Stornelli

Il 22/08/2011 17:57, Sunil Mushran ha scritto:

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines

Any proposal that differentiates between holes is wrong. It should not matter where the hole is.

Think of it from the usage-pov.

doff = 0;
while ((doff = lseek(SEEK_DATA, doff)) != -ENXIO) { hoff = lseek(SEEK_HOLE, doff);
read_offset = doff;
read_len = hoff -doff;
process();
doff = hoff;
}

The goal is to make this as efficient as follows. Treating the last hole differently adds more code for no benefit.

Quoted 9 lines
Quoted 4 lines

Mmmm.....It seems that Josef has to be clear in this point. However I looked for the seek hole test in xfs test suite, but I didn't find anything. Btrfs guys, how have you got tested the implementation? What do you think about this corner case? Al, what do you think about it?

The following test was used to test the early implementations.
http://oss.oracle.com/~smushran/seek_data/

Quoted 8 lines

Thank you very much!! I found another point. Your test fails with my implementation because here
(http://www.austingroupbugs.net/view.php?id=415) says: "If whence is SEEK_DATA, the file offset shall be set to the smallest location of a byte not within a hole and not less than offset. It shall be an error if no such byte exists." So in this case I return ENXIO but the test expects another value. I have to say that there is a bit of confusion about the real behavior of this new feature :)

Which is exactly why I'm trying to get the definitions clarified first, then the behaviour codified in a single test suite we can call the 'authoritive test'.

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]

A message that is not in the archive (sent off-list or not yet received): CAGpXXZ+xjhadprkc_LiP3qUypLLkCxdeEmo8+K+6mOnBuNhmLg@mail.gmail.com

#46 lore raw
Quoted 7 lines · Marco Stornelli

Hi,

Il 28/06/2011 17:33, Josef Bacik ha scritto:

Quoted 2 lines

This just gets us ready to support the SEEK_HOLE and SEEK_DATA flags.

Turns out

Quoted 1 line
Quoted 1 line

using fiemap in things like cp cause more problems than it solves, so

lets try

Quoted 1 line
Quoted 1 line

and give userspace an interface that doesn't suck. We need to match

solaris

Quoted 7 lines
Quoted 7 lines

here, and the definitions are

*o* If /whence/ is SEEK_HOLE, the offset of the start of the next hole greater than or equal to the supplied offset is returned. The definition of a hole is provided near the end of the DESCRIPTION.

Quoted 6 lines
Quoted 4 lines

*o* If /whence/ is SEEK_DATA, the file pointer is set to the start of the next non-hole file region greater than or equal to the supplied offset.

I'm implementing the SEEK_DATA/SEEK_HOLE management for pramfs and I've

got some doubts about the right behavior:

Quoted 2 lines

1) when we use SEEK_DATA/SEEK_HOLE, the offset used in lseek means always

the offset from the start of the file, right?

Quoted 2 lines

2) in case of a file with hole at the beginning and data at the end, if I

do lseek(fd, 0, SEEK_HOLE) I should receive the end of the file because the idea is to search the *next* hole and we have always a virtual hole at the end of the file, right?

Quoted 2 lines

3) about the last sentence of point 2), is it always true even if we have

a case of block allocation beyond the end of file (fallocate with keep size option)?

Quoted 1 line

Marco,

You may want to enable the xfstests test(s) for SEEK_HOLE and SEEK_DATA for pramfs. That should give you some confidence your implementing the api like other filesystems are.

Greg

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs