summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/include/sys/disk.h24
-rw-r--r--sys/kern/kern_disk.c14
2 files changed, 36 insertions, 2 deletions
diff --git a/sys/include/sys/disk.h b/sys/include/sys/disk.h
index f6ed126..e503e21 100644
--- a/sys/include/sys/disk.h
+++ b/sys/include/sys/disk.h
@@ -33,9 +33,33 @@
#include <sys/syscall.h>
#include <sys/queue.h>
#include <sys/device.h>
+#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/limits.h>
#include <sys/cdefs.h>
+#if defined(_KERNEL)
+#include <dev/dcdr/cache.h>
+#endif /* _KERNEL */
+
+/*
+ * V_BSIZE is the virtual block size in bytes used
+ * by the disk framework. The virtual block size is a
+ * multiple of the hardware block size and defines
+ * how many bytes a virtual block is made up of.
+ *
+ * A virtual block is simply a unit specific to
+ * the disk framework that represents multiple
+ * hardware disk blocks.
+ */
+#if defined(__V_BSIZE)
+#define V_BSIZE __V_BSIZE
+#else
+#define V_BSIZE 4096
+#endif /* __V_BSIZE */
+
+/* Sanitize the silly human's input */
+_Static_assert(V_BSIZE > 512, "V_BSIZE must be > 512");
+_Static_assert((V_BSIZE & 1) == 0, "V_BSIZE must be a power of two");
#define DISK_PRIMARY 0 /* ID of primary disk */
diff --git a/sys/kern/kern_disk.c b/sys/kern/kern_disk.c
index b956c02..af2aa13 100644
--- a/sys/kern/kern_disk.c
+++ b/sys/kern/kern_disk.c
@@ -171,6 +171,10 @@ __disk_get_id(diskid_t id)
* @buf: Buffer to read data into
* @len: Number of bytes to read
* @write: If true, do a write
+ *
+ * XXX: The size in which blocks are read at is in
+ * virtual blocks which is defined by V_BSIZE
+ * in sys/disk.h
*/
static ssize_t
disk_rw(diskid_t id, blkoff_t blk, void *buf, size_t len, bool write)
@@ -180,6 +184,8 @@ disk_rw(diskid_t id, blkoff_t blk, void *buf, size_t len, bool write)
struct disk *dp;
int error;
+ len = ALIGN_UP(len, V_BSIZE);
+
/* Attempt to grab the disk object */
error = disk_get_id(id, &dp);
if (error < 0) {
@@ -268,6 +274,10 @@ disk_add(const char *name, dev_t dev, const struct bdevsw *bdev, int flags)
dp->id = disk_count++;
dp->bsize = DEFAULT_BSIZE;
+ if ((V_BSIZE & (dp->bsize - 1)) != 0) {
+ panic("virtual block size not hw bsize aligned\n");
+ }
+
/* Now we can add it to the queue */
spinlock_acquire(&diskq_lock);
TAILQ_INSERT_TAIL(&diskq, dp, link);
@@ -343,9 +353,9 @@ disk_buf_alloc(diskid_t id, size_t len)
/*
* Here we will align the buffer size by the
- * disk's block size to ensure it is big enough.
+ * virtual block size to ensure it is big enough.
*/
- len = ALIGN_UP(len, dp->bsize);
+ len = ALIGN_UP(len, V_BSIZE);
buf = dynalloc(len);
return buf;
}