Skip to contentSkip to conversation

PATCH [2.4.0test10]: Kiobuf#01, expand IO return codes from iobufs

PATCH Stephen C. Tweedie 2 participants 2 messages Nov 2, 2000

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

Hi,

Kiobuf diff 01: allow for both the errno and the number of bytes transferred to be returned in a kiobuf after IO. We need both in order to know how many pages have been dirtied after a failed IO.

Also includes a fix to the brw_kiovec code to make sure that EIO is returned if no bytes were transferred successfully.

--Stephen

drivers/char/raw.c +3 -3
diff -ru linux-2.4.0-test10.kio.00/drivers/char/raw.c linux-2.4.0-test10.kio.01/drivers/char/raw.c
@@ -321,10 +321,10 @@
 		
 		err = brw_kiovec(rw, 1, &iobuf, dev, b, sector_size);
 
+		transferred += iobuf->retval;
 		if (err >= 0) {
-			transferred += err;
-			size -= err;
-			buf += err;
+			size -= iobuf->retval;
+			buf += iobuf->retval;
 		}
 
 		unmap_kiobuf(iobuf); /* The unlock_kiobuf is implicit here */
fs/buffer.c +7 -0
diff -ru linux-2.4.0-test10.kio.00/fs/buffer.c linux-2.4.0-test10.kio.01/fs/buffer.c
@@ -1924,6 +1924,8 @@
 	
 	spin_unlock(&unused_list_lock);
 
+	if (!iosize)
+		return -EIO;
 	return iosize;
 }
 
@@ -2049,6 +2051,11 @@
 	}
 
  finished:
+
+	iobuf->retval = transferred;
+	if (err < 0)
+		iobuf->errno = err;
+	
 	if (transferred)
 		return transferred;
 	return err;
include/linux/iobuf.h +6 -1
diff -ru linux-2.4.0-test10.kio.00/include/linux/iobuf.h linux-2.4.0-test10.kio.01/include/linux/iobuf.h
@@ -52,7 +52,12 @@
 
 	/* Dynamic state for IO completion: */
 	atomic_t	io_count;	/* IOs still in progress */
-	int		errno;		/* Status of completed IO */
+
+	/* Equivalent to the return value and "errno" after a syscall: */
+	int		errno;		/* Error from completed IO (usual
+					   kernel negative values) */
+	int		retval;		/* Return value of completed IO */
+
 	void		(*end_io) (struct kiobuf *); /* Completion callback */
 	wait_queue_head_t wait_queue;
 };
#1 lore raw
Quoted 3 lines · Stephen C. Tweedie

Kiobuf diff 01: allow for both the errno and the number of bytes transferred to be returned in a kiobuf after IO. We need both in order to know how many pages have been dirtied after a failed IO.

[...]

include/linux/iobuf.h line 58

Quoted 5 lines
include/linux/iobuf.h +4 -1
-	int		errno;		/* Status of completed IO */
+
+	/* Equivalent to the return value and "errno" after a syscall: */
+	int		errno;		/* Error from completed IO (usual
+					   kernel negative values) */

Although it's nicely commented that errno holds a negative value, wouldn't it be better to use the usual kernel convention that "err" holds negative error numbers and "errno" holds positive userland-like ones? (There are a few places in the kernel which use things called errno to hold negative numbers but very few). It would just be one extra little way to help the brain distinguish between the conventions when using kiobuf and maybe prevent someone beating their head against a brick wall for a day or two because "if (foo.errno == EIO)" looked too normal.

--Malcolm

Signature · 7 lines
Malcolm Beattie <[email protected]>
Unix Systems Programmer
Oxford University Computing Services
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/