kernel: final pieces needed (I think...) for external buffer support
authorAlan Cox <alan@linux.intel.com>
Thu, 12 Jul 2018 14:07:45 +0000 (15:07 +0100)
committerAlan Cox <alan@linux.intel.com>
Thu, 12 Jul 2018 14:07:45 +0000 (15:07 +0100)
Kernel/devio.c
Kernel/include/kernel.h

index 8052a4d..3ed6b31 100644 (file)
@@ -151,35 +151,39 @@ int bfree(regptr bufptr bp, uint8_t dirty)
 }
 
 /*
- * Allocate a buffer for scratch use by the kernel. This buffer can then
- * be freed with tmpfree.
- *
- * API note: Nothing guarantees a connection between a bufcache entry
- * and tmpbuf in future. Always free with tmpfree.
+ * Allocate an empty _disk cache_ buffer. We use this when dealing with file
+ * holes. It would be nice if this API could go way and readi just use uzero()
  */
-void *tmpbuf(void)
+bufptr zerobuf(void)
 {
        regptr bufptr bp;
 
        bp = freebuf();
        bp->bf_dev = NO_DEVICE;
        bp->bf_time = ++bufclock;       /* Time stamp it */
-       return bp->__bf_data;
+       blkzero(bp);
+       return bp;
 }
 
+#ifndef CONFIG_BLKBUF_EXTERNAL
 /*
- * Allocate an empty _disk cache_ buffer. We use this when dealing with file
- * holes. It would be nice if this API could go way and readi just use uzero()
+ * Allocate a buffer for scratch use by the kernel. This buffer can then
+ * be freed with tmpfree.
  *
- * This won't be able to use tmpbuf if we split disk and temporary buffers.
+ * API note: Nothing guarantees a connection between a bufcache entry
+ * and tmpbuf in future. Always free with tmpfree.
  */
-void *zerobuf(void)
+
+void *tmpbuf(void)
 {
-       void *b = tmpbuf();
-       memset(b, 0, 512);
+       regptr bufptr bp;
 
-       return b;
+       bp = freebuf();
+       bp->bf_dev = NO_DEVICE;
+       bp->bf_time = ++bufclock;       /* Time stamp it */
+       return bp->__bf_data;
 }
+#endif
 
 /*
  * Write back a buffer doing the locking outselves. This is called when
index 505cfe1..5b9611e 100644 (file)
@@ -211,6 +211,7 @@ typedef struct blkbuf {
     uget((uaddr),(buf)->__bf_data + (off), (len))
 #define blkptr(buf, off, len)  ((void *)((buf)->__bf_data + (off)))
 #define blkzero(buf)           memset(buf->__bf_data, 0, BLKSIZE)
+#define tmpfree(x)     brelse((void *)x)
 #else
 extern void blktok(void *kaddr, struct blkbuf *buf, uint16_t off, uint16_t len);
 extern void blkfromk(void *kaddr, struct blkbuf *buf, uint16_t off, uint16_t len);
@@ -219,6 +220,7 @@ extern void blkfromu(void *kaddr, struct blkbuf *buf, uint16_t off, uint16_t len
 /* Worst case is needing to copy over about 64 bytes */
 extern void *blkptr(struct blkbuf *buf, uint16_t offset, uint16_t len);
 extern void blkzero(struct blkbuf *buf);
+extern void tmpfree(void *p);
 #endif
 
 /* TODO: consider smaller inodes or clever caching. 2BSD uses small
@@ -855,12 +857,11 @@ extern void brelse(bufptr);
 extern void bawrite(bufptr);
 extern int bfree(bufptr bp, uint8_t dirty); /* dirty: 0=clean, 1=dirty (write back), 2=dirty+immediate write */
 extern void *tmpbuf(void);
-extern void *zerobuf(void);
+extern bufptr zerobuf(void);
 extern void bufsync(void);
 extern bufptr bfind(uint16_t dev, blkno_t blk);
 extern void bdrop(uint16_t dev);
 extern bufptr freebuf(void);
-#define tmpfree(x)     brelse((void *)x)
 extern void bufinit(void);
 extern void bufdiscard(bufptr bp);
 extern void bufdump (void);