aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>2014-04-08 09:32:38 +0900
committerDaniel Phillips <daniel@tux3.org>2014-04-08 09:32:38 +0900
commit3351d81d41fd072518c435a937e22815909b1f97 (patch)
treec646db4d75f990a8968e17480ebccf4a5d41bfe3
parent1dcad62578cc51072e7adb8d9d8f6caef384337c (diff)
downloadlinux-tux3-3351d81d41fd072518c435a937e22815909b1f97.tar.gz
tux3: Remove malloc()/free() wrapper
Now, we are using malloc()/free() wrapper to share codes with userland. However, kernel APIs has more features than userland. So, this uses kernel APIs directly, and instead, emulates kernel APIs in userland. Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
-rw-r--r--fs/tux3/btree.c15
-rw-r--r--fs/tux3/filemap.c4
-rw-r--r--fs/tux3/inode_defer.c4
-rw-r--r--fs/tux3/orphan.c4
-rw-r--r--fs/tux3/replay.c4
-rw-r--r--fs/tux3/tux3.h11
-rw-r--r--fs/tux3/xattr.c8
7 files changed, 19 insertions, 31 deletions
diff --git a/fs/tux3/btree.c b/fs/tux3/btree.c
index 3b4ece31dc528c..3496b9b67da9b8 100644
--- a/fs/tux3/btree.c
+++ b/fs/tux3/btree.c
@@ -247,8 +247,9 @@ static inline int alloc_cursor_size(int count)
struct cursor *alloc_cursor(struct btree *btree, int extra)
{
int maxlevel = btree->root.depth + extra;
- struct cursor *cursor = malloc(alloc_cursor_size(maxlevel + 1));
+ struct cursor *cursor;
+ cursor = kmalloc(alloc_cursor_size(maxlevel + 1), GFP_NOFS);
if (cursor) {
cursor->btree = btree;
cursor->level = -1;
@@ -268,7 +269,7 @@ void free_cursor(struct cursor *cursor)
#ifdef CURSOR_DEBUG
assert(cursor->level == -1);
#endif
- free(cursor);
+ kfree(cursor);
}
/* Lookup the index entry contains key */
@@ -808,17 +809,15 @@ int btree_chop(struct btree *btree, tuxkey_t start, u64 len)
/* Chop all range if len >= TUXKEY_LIMIT */
limit = (len >= TUXKEY_LIMIT) ? TUXKEY_LIMIT : start + len;
- prev = malloc(sizeof(*prev) * btree->root.depth);
+ prev = kzalloc(sizeof(*prev) * btree->root.depth, GFP_NOFS);
if (prev == NULL)
return -ENOMEM;
- memset(prev, 0, sizeof(*prev) * btree->root.depth);
- cii = malloc(sizeof(*cii) * btree->root.depth);
+ cii = kzalloc(sizeof(*cii) * btree->root.depth, GFP_NOFS);
if (cii == NULL) {
ret = -ENOMEM;
goto error_cii;
}
- memset(cii, 0, sizeof(*cii) * btree->root.depth);
cursor = alloc_cursor(btree, 0);
if (!cursor) {
@@ -962,9 +961,9 @@ error_btree_probe:
free_cursor(cursor);
error_alloc_cursor:
- free(cii);
+ kfree(cii);
error_cii:
- free(prev);
+ kfree(prev);
return ret;
}
diff --git a/fs/tux3/filemap.c b/fs/tux3/filemap.c
index 56978e5f672369..678c217d5815ab 100644
--- a/fs/tux3/filemap.c
+++ b/fs/tux3/filemap.c
@@ -280,7 +280,7 @@ static int map_region1(struct inode *inode, block_t start, unsigned count,
struct dleaf *tail = NULL;
tuxkey_t tailkey = 0; // probably can just use limit instead
if (!dwalk_end(walk)) {
- tail = malloc(sb->blocksize); // error???
+ tail = kmalloc(sb->blocksize, GFP_NOFS); // error???
dleaf_init(btree, tail);
tailkey = dwalk_index(walk);
dwalk_copy(walk, tail);
@@ -346,7 +346,7 @@ static int map_region1(struct inode *inode, block_t start, unsigned count,
mark_buffer_dirty_non(cursor_leafbuf(cursor));
out_create:
if (tail)
- free(tail);
+ kfree(tail);
out_release:
if (cursor)
release_cursor(cursor);
diff --git a/fs/tux3/inode_defer.c b/fs/tux3/inode_defer.c
index 2acf9f187c39ea..a508a73697aa0a 100644
--- a/fs/tux3/inode_defer.c
+++ b/fs/tux3/inode_defer.c
@@ -34,7 +34,7 @@ struct tux3_idefer_map *tux3_alloc_idefer_map(void)
{
struct tux3_idefer_map *map;
- map = malloc(sizeof(*map));
+ map = kmalloc(sizeof(*map), GFP_NOFS);
if (map) {
int i;
for (i = 0; i < NODE_HASH_SIZE; i++)
@@ -49,7 +49,7 @@ void tux3_free_idefer_map(struct tux3_idefer_map *map)
int i;
for (i = 0; i < NODE_HASH_SIZE; i++)
assert(hlist_empty(&map->heads[i]));
- free(map);
+ kfree(map);
}
}
diff --git a/fs/tux3/orphan.c b/fs/tux3/orphan.c
index 916bb4ea0267aa..068e1191a7c408 100644
--- a/fs/tux3/orphan.c
+++ b/fs/tux3/orphan.c
@@ -35,7 +35,7 @@ struct orphan {
static struct orphan *alloc_orphan(inum_t inum)
{
- struct orphan *orphan = malloc(sizeof(struct orphan));
+ struct orphan *orphan = kmalloc(sizeof(struct orphan), GFP_NOFS);
if (!orphan)
return ERR_PTR(-ENOMEM);
@@ -46,7 +46,7 @@ static struct orphan *alloc_orphan(inum_t inum)
static void free_orphan(struct orphan *orphan)
{
- free(orphan);
+ kfree(orphan);
}
/* Caller must care about locking if needed */
diff --git a/fs/tux3/replay.c b/fs/tux3/replay.c
index 079bb8c18e4258..1738595eb1bf6c 100644
--- a/fs/tux3/replay.c
+++ b/fs/tux3/replay.c
@@ -37,7 +37,7 @@ static struct replay *alloc_replay(struct sb *sb, unsigned logcount)
{
struct replay *rp;
- rp = malloc(sizeof(*rp) + logcount * sizeof(block_t));
+ rp = kmalloc(sizeof(*rp) + logcount * sizeof(block_t), GFP_NOFS);
if (!rp)
return ERR_PTR(-ENOMEM);
@@ -56,7 +56,7 @@ static void free_replay(struct replay *rp)
{
assert(list_empty(&rp->log_orphan_add));
assert(list_empty(&rp->orphan_in_otree));
- free(rp);
+ kfree(rp);
}
static int replay_check_log(struct replay *rp, struct buffer_head *logbuf)
diff --git a/fs/tux3/tux3.h b/fs/tux3/tux3.h
index a9b9eff8148c7e..4a5aaf091d9d33 100644
--- a/fs/tux3/tux3.h
+++ b/fs/tux3/tux3.h
@@ -461,17 +461,6 @@ static inline map_t *mapping(struct inode *inode)
return inode->i_mapping;
}
-static inline void *malloc(size_t size)
-{
- might_sleep();
- return kmalloc(size, GFP_NOFS);
-}
-
-static inline void free(void *ptr)
-{
- kfree(ptr);
-}
-
static inline struct block_device *sb_dev(struct sb *sb)
{
return sb->vfs_sb->s_bdev;
diff --git a/fs/tux3/xattr.c b/fs/tux3/xattr.c
index 4b0d8414a8fe08..8ccebe162c4bdb 100644
--- a/fs/tux3/xattr.c
+++ b/fs/tux3/xattr.c
@@ -463,7 +463,7 @@ struct xcache {
void free_xcache(struct inode *inode)
{
if (tux_inode(inode)->xcache) {
- free(tux_inode(inode)->xcache);
+ kfree(tux_inode(inode)->xcache);
tux_inode(inode)->xcache = NULL;
}
}
@@ -473,7 +473,7 @@ int new_xcache(struct inode *inode, unsigned size)
{
struct xcache *xcache;
- xcache = malloc(sizeof(*xcache) + size);
+ xcache = kmalloc(sizeof(*xcache) + size, GFP_NOFS);
if (!xcache)
return -ENOMEM;
@@ -502,7 +502,7 @@ static int expand_xcache(struct inode *inode, unsigned size)
assert(size);
assert(size <= USHRT_MAX);
- xcache = malloc(sizeof(*xcache) + size);
+ xcache = kmalloc(sizeof(*xcache) + size, GFP_NOFS);
if (!xcache)
return -ENOMEM;
@@ -511,7 +511,7 @@ static int expand_xcache(struct inode *inode, unsigned size)
else {
xcache->size = old->size;
memcpy(xcache->xattrs, old->xattrs, old->size);
- free(old);
+ kfree(old);
}
xcache->maxsize = size;