git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
feat: (iso9660) rock ridge extension
[lunaix-os.git]
/
lunaix-os
/
kernel
/
fs
/
pcache.c
diff --git
a/lunaix-os/kernel/fs/pcache.c
b/lunaix-os/kernel/fs/pcache.c
index 03f7502072d9acab6c98fd688b0ecb4e708bb1e2..a6c4c31d34993b9ba9b8da91a195f51b886ad655 100644
(file)
--- a/
lunaix-os/kernel/fs/pcache.c
+++ b/
lunaix-os/kernel/fs/pcache.c
@@
-11,13
+11,21
@@
static struct lru_zone* pcache_zone;
static struct lru_zone* pcache_zone;
+static int
+__pcache_try_evict(struct lru_node* obj)
+{
+ struct pcache_pg* page = container_of(obj, struct pcache_pg, lru);
+ pcache_invalidate(page->holder, page);
+ return 1;
+}
+
void
pcache_init(struct pcache* pcache)
{
btrie_init(&pcache->tree, PG_SIZE_BITS);
llist_init_head(&pcache->dirty);
llist_init_head(&pcache->pages);
void
pcache_init(struct pcache* pcache)
{
btrie_init(&pcache->tree, PG_SIZE_BITS);
llist_init_head(&pcache->dirty);
llist_init_head(&pcache->pages);
- pcache_zone = lru_new_zone();
+ pcache_zone = lru_new_zone(
__pcache_try_evict
);
}
void
}
void
@@
-32,18
+40,6
@@
pcache_release_page(struct pcache* pcache, struct pcache_pg* page)
pcache->n_pages--;
}
pcache->n_pages--;
}
-void
-pcache_evict(struct pcache* pcache)
-{
- struct pcache_pg* page =
- container_of(lru_evict_one(pcache_zone), struct pcache_pg, lru);
-
- if (!page)
- return;
-
- pcache_invalidate(pcache, page);
-}
-
struct pcache_pg*
pcache_new_page(struct pcache* pcache, uint32_t index)
{
struct pcache_pg*
pcache_new_page(struct pcache* pcache, uint32_t index)
{
@@
-51,7
+47,7
@@
pcache_new_page(struct pcache* pcache, uint32_t index)
void* pg = valloc(PG_SIZE);
if (!ppg || !pg) {
void* pg = valloc(PG_SIZE);
if (!ppg || !pg) {
-
pcache_evict(pcach
e);
+
lru_evict_one(pcache_zon
e);
if (!ppg && !(ppg = vzalloc(sizeof(struct pcache_pg)))) {
return NULL;
}
if (!ppg && !(ppg = vzalloc(sizeof(struct pcache_pg)))) {
return NULL;
}
@@
-62,6
+58,7
@@
pcache_new_page(struct pcache* pcache, uint32_t index)
}
ppg->pg = pg;
}
ppg->pg = pg;
+ ppg->holder = pcache;
llist_append(&pcache->pages, &ppg->pg_list);
btrie_set(&pcache->tree, index, ppg);
llist_append(&pcache->pages, &ppg->pg_list);
btrie_set(&pcache->tree, index, ppg);
@@
-79,7
+76,7
@@
pcache_set_dirty(struct pcache* pcache, struct pcache_pg* pg)
}
}
}
}
-struct pcache_pg*
+int
pcache_get_page(struct pcache* pcache,
uint32_t index,
uint32_t* offset,
pcache_get_page(struct pcache* pcache,
uint32_t index,
uint32_t* offset,
@@
-87,9
+84,10
@@
pcache_get_page(struct pcache* pcache,
{
struct pcache_pg* pg = btrie_get(&pcache->tree, index);
int is_new = 0;
{
struct pcache_pg* pg = btrie_get(&pcache->tree, index);
int is_new = 0;
- *offset = index & ((1 << pcache->tree.truncated) - 1);
+ u32_t mask = ((1 << pcache->tree.truncated) - 1);
+ *offset = index & mask;
if (!pg && (pg = pcache_new_page(pcache, index))) {
if (!pg && (pg = pcache_new_page(pcache, index))) {
- pg->fpos = index
- *offset
;
+ pg->fpos = index
& ~mask
;
pcache->n_pages++;
is_new = 1;
}
pcache->n_pages++;
is_new = 1;
}
@@
-117,6
+115,7
@@
pcache_write(struct v_inode* inode, void* data, uint32_t len, uint32_t fpos)
pcache_set_dirty(pcache, pg);
pcache_set_dirty(pcache, pg);
+ pg->len = pg_off + wr_bytes;
buf_off += wr_bytes;
fpos += wr_bytes;
}
buf_off += wr_bytes;
fpos += wr_bytes;
}
@@
-140,15
+139,21
@@
pcache_read(struct v_inode* inode, void* data, uint32_t len, uint32_t fpos)
}
// Filling up the page
}
// Filling up the page
- errno = inode->default_fops.read(inode, pg->pg, PG_SIZE, pg->fpos);
+ errno =
+ inode->default_fops->read_page(inode, pg->pg, PG_SIZE, pg->fpos);
if (errno >= 0 && errno < PG_SIZE) {
// EOF
if (errno >= 0 && errno < PG_SIZE) {
// EOF
- len =
buf_off + errno
;
+ len =
MIN(len, buf_off + errno)
;
} else if (errno < 0) {
break;
}
} else if (errno < 0) {
break;
}
+ pg->len = errno;
}
}
- uint32_t rd_bytes = MIN(PG_SIZE - pg_off, len - buf_off);
+ uint32_t rd_bytes = MIN(pg->len - pg_off, len - buf_off);
+
+ if (!rd_bytes)
+ break;
+
memcpy((data + buf_off), pg->pg + pg_off, rd_bytes);
buf_off += rd_bytes;
memcpy((data + buf_off), pg->pg + pg_off, rd_bytes);
buf_off += rd_bytes;
@@
-164,7
+169,7
@@
pcache_release(struct pcache* pcache)
struct pcache_pg *pos, *n;
llist_for_each(pos, n, &pcache->pages, pg_list)
{
struct pcache_pg *pos, *n;
llist_for_each(pos, n, &pcache->pages, pg_list)
{
- lru_remove(&pos->lru);
+ lru_remove(
pcache_zone,
&pos->lru);
vfree(pos);
}
vfree(pos);
}
@@
-178,7
+183,8
@@
pcache_commit(struct v_inode* inode, struct pcache_pg* page)
return;
}
return;
}
- int errno = inode->default_fops.write(inode, page->pg, PG_SIZE, page->fpos);
+ int errno =
+ inode->default_fops->write_page(inode, page->pg, PG_SIZE, page->fpos);
if (!errno) {
page->flags &= ~PCACHE_DIRTY;
if (!errno) {
page->flags &= ~PCACHE_DIRTY;
@@
-192,6
+198,10
@@
pcache_commit(struct v_inode* inode, struct pcache_pg* page)
void
pcache_commit_all(struct v_inode* inode)
{
void
pcache_commit_all(struct v_inode* inode)
{
+ if (!inode->pg_cache) {
+ return;
+ }
+
struct pcache* cache = inode->pg_cache;
struct pcache_pg *pos, *n;
struct pcache* cache = inode->pg_cache;
struct pcache_pg *pos, *n;