[Tux3] Patch: Crude smp locking for btrees

Daniel Phillips phillips at phunq.net
Tue Dec 23 23:59:58 PST 2008


diff -r be00799ecef0 user/kernel/btree.c
--- a/user/kernel/btree.c	Wed Dec 24 16:44:17 2008 +0900
+++ b/user/kernel/btree.c	Tue Dec 23 23:58:24 2008 -0800
@@ -601,6 +601,7 @@ struct btree new_btree(struct sb *sb, st
 	printf("leaf at %Lx\n", (L)bufindex(leafbuf));
 	brelse_dirty(rootbuf);
 	brelse_dirty(leafbuf);
+	init_rwsem(&btree.lock);
 	return btree;
 eek:
 	if (rootbuf)
diff -r be00799ecef0 user/kernel/filemap.c
--- a/user/kernel/filemap.c	Wed Dec 24 16:44:17 2008 +0900
+++ b/user/kernel/filemap.c	Tue Dec 23 23:58:24 2008 -0800
@@ -214,6 +214,10 @@ static int get_segs(struct inode *inode,
 	if (!cursor)
 		return -ENOMEM;
 
+	if (create)
+		down_write(&cursor->btree->lock);
+	else
+		down_read(&cursor->btree->lock);
 	unsigned overlap[2];
 	struct dwalk seek[2] = { };
 	int segs = find_segs(cursor, start, start + count, segvec, max_segs, seek, overlap);
@@ -221,6 +225,10 @@ static int get_segs(struct inode *inode,
 		segs = fill_segs(cursor, start, start + count, segvec, segs, seek, overlap);
 	if (segs >= 0)
 		release_cursor(cursor);
+	if (create)
+		up_write(&cursor->btree->lock);
+	else
+		up_read(&cursor->btree->lock);
 	free_cursor(cursor);
 	return segs;
 }
@@ -334,7 +342,7 @@ int tux3_get_block(struct inode *inode, 
 	struct btree *btree = &tux_inode(inode)->btree;
 	int depth = btree->root.depth;
 	if (!depth) {
-		warn("Uninitialied inode %lx", inode->i_ino);
+		warn("Uninitialized inode %lx", inode->i_ino);
 		return 0;
 	}
 
diff -r be00799ecef0 user/kernel/tux3.h
--- a/user/kernel/tux3.h	Wed Dec 24 16:44:17 2008 +0900
+++ b/user/kernel/tux3.h	Tue Dec 23 23:58:24 2008 -0800
@@ -170,6 +170,7 @@ struct btree {
 	struct btree_ops *ops;	/* Generic btree low level operations */
 	struct root root;	/* Cached description of btree root */
 	u16 entries_per_leaf;	/* Used in btree leaf splitting */
+	struct rw_semaphore lock;
 };
 
 /* Define layout of btree root on disk, endian conversion is elsewhere. */
diff -r be00799ecef0 user/tux3.h
--- a/user/tux3.h	Wed Dec 24 16:44:17 2008 +0900
+++ b/user/tux3.h	Tue Dec 23 23:58:24 2008 -0800
@@ -52,6 +52,14 @@ typedef uint64_t u64;
 typedef uint64_t u64;
 
 typedef int fd_t;
+
+struct rw_semaphore { };
+
+static inline void down_read(struct rw_semaphore *sem) { };
+static inline void down_write(struct rw_semaphore *sem) { };
+static inline void up_read(struct rw_semaphore *sem) { };
+static inline void up_write(struct rw_semaphore *sem) { };
+static inline void init_rwsem(struct rw_semaphore *sem) { };
 
 /* Bitmaps */
 

_______________________________________________
Tux3 mailing list
Tux3 at tux3.org
http://mailman.tux3.org/cgi-bin/mailman/listinfo/tux3



More information about the Tux3 mailing list