code: libextents

Download patch

ref: fb7898cf13af74d49c56e7f04273b82b281b0515
parent: 3c6fc2e1b4e18a7766df058dba1d1e5a26230f5a
author: 9ferno <[email protected]>
date: Tue Jan 3 14:18:49 EST 2023

cosmetic changes

--- a/extents.h
+++ b/extents.h
@@ -4,7 +4,7 @@
 	This is similar in functionality to pool(2).
 
  Extents are used to manage contiguous space (such as memory space and disk space).
- 	The space is is split into units of the same size (quantum).
+	The space is is split into units of the same size (quantum).
 
  All space is split into a sequence of units. Each such sequence of units
 	is called an Extent. The data structure Extents is used to contain this
@@ -47,16 +47,6 @@
 
 When freeing blocks, it tries to merge with the neighbours to become bigger extents.
 */
-struct Extent {
-	struct Extent *low, *high;	/* sorted by start */
-	struct Extent *small, *big;	/* sorted by the number of blocks in this extent */
-	u64 start;					/* where this extent starts from */
-	u64 len; 					/* how many units in this extent */
-
-	/* circular least recently used linked list limited to Nlru items */
-	struct Extent *prev, *next;
-};
-
 struct Extents {
 	char name[32];
 	u64 quantum;	/* allocations are a multiple of quantum */
@@ -69,7 +59,7 @@
 	void (*panic)(char *fmt, ...);
 	void *(*malloc)(u32 sz);
 
-	/* private stuff */
+	/* private */
 	Extent *lowest;	/* find the first block number in a jiffy */
 	QLock lck;
 	u64 n;			/* number of extents */
@@ -79,6 +69,22 @@
 	Extent *lru;	/* least recently used extent in the circular lru linked list */
 };
 
+struct Extent {
+	struct Extent *low, *high;	/* sorted by start */
+	struct Extent *small, *big;	/* sorted by the number of blocks in this extent */
+	u64 start;					/* where this extent starts from */
+	u64 len; 					/* how many units in this extent */
+
+	/* circular least recently used linked list limited to Nlru items */
+	struct Extent *prev, *next;
+};
+
+void	initextents(Extents *es, char *name, u64 quantum, u8 loglevel, u32 logfd, void (*flush)(void), void (*log)(int fd, char *fmt, ...), void (*panic)(char *fmt, ...), void *(*malloc)(u32 sz));
+u64	 qalloc(Extents *es, u64 len);			/* allocate len*quantum */
+void qfree(Extents *es, u64 start, u64 len);/* free len*quantum starting from start */
+u64	 nfrees(Extents *es);
+Extents *holes(Extents *es, Extents *inv);
+
 void	showblocknos(int fd, Extents *es);
 void	showextents(int fd, char *msg, Extents *es);
 void	showextentslists(int fd, char *msg, Extents *es);
@@ -86,10 +92,3 @@
 s32	sizeofextents(Extents *es);
 s32	saveextents(Extents *es, s8 *buf, u32 nbuf);
 s32	loadextents(Extents *es, s8 *buf, u32 nbuf);
-
-u64	 qalloc(Extents *es, u64 len);			/* allocate len*quantum */
-void qfree(Extents *es, u64 start, u64 len);/* free len*quantum starting from start */
-u64	 nfrees(Extents *es);
-Extents *holes(Extents *es, Extents *inv);
-
-void	initextents(Extents *es, char *name, u64 quantum, u8 loglevel, u32 logfd, void (*flush)(void), void (*log)(int fd, char *fmt, ...), void (*panic)(char *fmt, ...), void *(*malloc)(u32 sz));