Skip to contentSkip to conversation

xfs_io: actually issue 0 size writes

PATCH In review Eric Sandeen 3 participants 5 messages Aug 13, 2009 – Aug 26, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs_io: actually issue 0 size writes

While testing some stuff in generic_write_checks() in the kernel I realized that you can't actually use xfs_io to send a 0-byte write in. This is actually a condition worth testing:

If count is zero and fd refers to a regular file, then write() may return a failure status if one of the errors below is detected. If no errors are detected, 0 will be returned without causing any other effect.

So fix that up.

---

iff --git a/io/pwrite.c b/io/pwrite.c
index 54c3f78..26a7850 100644

io/pwrite.c +3 -1
@@ -163,7 +163,7 @@ write_buffer(
 	int		ops = 0;
 
 	*total = 0;
-	while (count > 0) {
+	while (count >= 0) {
 		if (fd > 0) {	/* input file given, read buffer first */
 			if (read_buffer(fd, skip + *total, bs, &bar, 0, 1) < 0)
 				break;
@@ -182,6 +182,8 @@ write_buffer(
 			break;
 		offset += bytes;
 		count -= bytes;
+		if (count == 0)
+			break;
 	}
 	return ops;
 }

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

#1 lore raw
Quoted 9 lines · Eric Sandeen

While testing some stuff in generic_write_checks() in the kernel I realized that you can't actually use xfs_io to send a 0-byte write in. This is actually a condition worth testing:

If count is zero and fd refers to a regular file, then write() may return a failure status if one of the errors below is detected. If no errors are detected, 0 will be returned without causing any other effect.

As I understand the desire to be able to issue 0 size writes from xfs_io is to test the possibility of writing to a given fd. What kind of errors would you expect to test for?

Otherwise looks good.

Felix

Quoted 30 lines

So fix that up.

---

iff --git a/io/pwrite.c b/io/pwrite.c
index 54c3f78..26a7850 100644

io/pwrite.c +3 -1
@@ -163,7 +163,7 @@ write_buffer(
 	int		ops = 0;
 
 	*total = 0;
-	while (count > 0) {
+	while (count >= 0) {
 		if (fd > 0) {	/* input file given, read buffer first */
 			if (read_buffer(fd, skip + *total, bs, &bar, 0, 1) < 0)
 				break;
@@ -182,6 +182,8 @@ write_buffer(
 			break;
 		offset += bytes;
 		count -= bytes;
+		if (count == 0)
+			break;
 	}
 	return ops;
 }
Quoted 4 lines

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

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

#2 lore raw
Quoted 12 lines · Felix Blyakher
Quoted 9 lines · Eric Sandeen

While testing some stuff in generic_write_checks() in the kernel I realized that you can't actually use xfs_io to send a 0-byte write in. This is actually a condition worth testing:

If count is zero and fd refers to a regular file, then write() may return a failure status if one of the errors below is detected. If no errors are detected, 0 will be returned without causing any other effect.

Quoted 3 lines

As I understand the desire to be able to issue 0 size writes from xfs_io is to test the possibility of writing to a given fd. What kind of errors would you expect to test for?

In general EFBIG or ENOSPC.

This sort of thing in generic_write_checks():

        if (unlikely(*pos >= inode->i_sb->s_maxbytes)) {
                if (*count || *pos > inode->i_sb->s_maxbytes) {
                     return -EFBIG;
                }
                /* zero-length writes at ->s_maxbytes are OK */
        }

Although I'm a little confused about why "*pos == s_maxbytes" is ok; I thought s_maxbytes was a count/size whereas pos is an offset, so it seems to me that pos == s_maxbytes is one past the max. But anyway, that's mostly unrelated to the patch in this thread. :)

-Eric

Quoted 3 lines

Otherwise looks good.

Felix

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

#3 lore raw
In reply to Eric Sandeen
Quoted 10 lines · Eric Sandeen

While testing some stuff in generic_write_checks() in the kernel I realized that you can't actually use xfs_io to send a 0-byte write in. This is actually a condition worth testing:

If count is zero and fd refers to a regular file, then write() may return a failure status if one of the errors below is detected. If no errors are detected, 0 will be returned without causing any other effect.

Quoted 3 lines

So fix that up.

Any reason you didn't put this in despite two positive reviews?

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

#4 lore raw
Quoted 11 lines · Christoph Hellwig
Quoted 10 lines · Eric Sandeen

While testing some stuff in generic_write_checks() in the kernel I realized that you can't actually use xfs_io to send a 0-byte write in. This is actually a condition worth testing:

If count is zero and fd refers to a regular file, then write() may return a failure status if one of the errors below is detected. If no errors are detected, 0 will be returned without causing any other effect.

Quoted 5 lines
Quoted 3 lines

So fix that up.

Any reason you didn't put this in despite two positive reviews?

Just general busyness and a vacation :)

Will do it soon.

-Eric

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