Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F109562853
D12850.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D12850.diff
View Options
Index: head/sys/boot/zfs/zfs.c
===================================================================
--- head/sys/boot/zfs/zfs.c
+++ head/sys/boot/zfs/zfs.c
@@ -368,17 +368,61 @@
}
static int
-vdev_read(vdev_t *vdev, void *priv, off_t offset, void *buf, size_t size)
+vdev_read(vdev_t *vdev, void *priv, off_t offset, void *buf, size_t bytes)
{
- int fd;
+ int fd, ret;
+ size_t res, size, remainder, rb_size, blksz;
+ unsigned secsz;
+ off_t off;
+ char *bouncebuf, *rb_buf;
fd = (uintptr_t) priv;
- lseek(fd, offset, SEEK_SET);
- if (read(fd, buf, size) == size) {
- return 0;
- } else {
- return (EIO);
+ bouncebuf = NULL;
+
+ ret = ioctl(fd, DIOCGSECTORSIZE, &secsz);
+ if (ret != 0)
+ return (ret);
+
+ off = offset / secsz;
+ remainder = offset % secsz;
+ if (lseek(fd, off * secsz, SEEK_SET) == -1)
+ return (errno);
+
+ rb_buf = buf;
+ rb_size = bytes;
+ size = roundup2(bytes + remainder, secsz);
+ blksz = size;
+ if (remainder != 0 || size != bytes) {
+ bouncebuf = zfs_alloc(secsz);
+ if (bouncebuf == NULL) {
+ printf("vdev_read: out of memory\n");
+ return (ENOMEM);
+ }
+ rb_buf = bouncebuf;
+ blksz = rb_size - remainder;
}
+
+ while (bytes > 0) {
+ res = read(fd, rb_buf, rb_size);
+ if (res != rb_size) {
+ ret = EIO;
+ goto error;
+ }
+ if (bytes < blksz)
+ blksz = bytes;
+ if (bouncebuf != NULL)
+ memcpy(buf, rb_buf + remainder, blksz);
+ buf = (void *)((uintptr_t)buf + blksz);
+ bytes -= blksz;
+ remainder = 0;
+ blksz = rb_size;
+ }
+
+ ret = 0;
+error:
+ if (bouncebuf != NULL)
+ zfs_free(bouncebuf, secsz);
+ return (ret);
}
static int
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Feb 7, 6:14 PM (18 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16514854
Default Alt Text
D12850.diff (1 KB)
Attached To
Mode
D12850: zfs.c:vdev_read() needs to be careful about large sectors
Attached
Detach File
Event Timeline
Log In to Comment