From: acevest Date: Fri, 20 Oct 2023 12:50:49 +0000 (+0800) Subject: ... X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=321185a3bfcf39fa757f0f5f3142a644135bec21;p=kernel.git ... --- diff --git a/fs/buffer.c b/fs/buffer.c index 62cd0c1..5d98a22 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -108,7 +108,7 @@ again: assert(NULL != t); assert(t->block_size == size); - if (t->ref_count == 0 && t->locked == 0) { + if (t->ref_count == 0) { b = t; break; } @@ -123,11 +123,13 @@ again: goto again; } - // 此时b->locked不一定为0 + // 把它从free_list上删掉 + list_del_init(&b->node); + + // 虽然此时该bbuffer_t上的ref_count为0但其可能还有I/O操作没有完成 // 因为可能有的进程调用了write、read后再直接调用brelse - // 虽然此时ref_count为0,但io操作标记的b->locked并未结束 // 所以需要在此等待其结束 - wait_event(&b->waitq_lock, b->locked == 0); + wait_completion(&b->io_done); // 找到了 b->block = block; @@ -188,8 +190,7 @@ void init_buffer() { b->dev = 0; b->page = page; b->uptodate = 0; - b->locked = 0; - init_wait_queue_head(&b->waitq_lock); + init_completion(&b->io_done); list_init(&b->node); assert(NULL != b->data); diff --git a/include/buffer.h b/include/buffer.h index f58b695..c64a3a8 100644 --- a/include/buffer.h +++ b/include/buffer.h @@ -10,12 +10,11 @@ #pragma once #include +#include #include #include #include #include -#include - typedef struct bbuffer { uint32_t block; // block number void *data; // @@ -23,9 +22,7 @@ typedef struct bbuffer { dev_t dev; page_t *page; list_head_t node; - wait_queue_head_t waitq_lock; + completion_t io_done; uint16_t block_size; // block size uint16_t uptodate : 1; - uint16_t locked : 1; - uint16_t dirt : 1; // 还不支持 } bbuffer_t; diff --git a/include/completion.h b/include/completion.h index 291f73a..93afe91 100644 --- a/include/completion.h +++ b/include/completion.h @@ -9,7 +9,6 @@ #pragma once -#if 0 #include typedef struct completion { @@ -24,4 +23,3 @@ void wait_completion(completion_t *x); void init_completion(completion_t *x); void complete(completion_t *x); -#endif diff --git a/kernel/completion.c b/kernel/completion.c index d556f31..78c191c 100644 --- a/kernel/completion.c +++ b/kernel/completion.c @@ -7,7 +7,6 @@ * ------------------------------------------------------------------------ */ -#if 0 #include #include @@ -25,4 +24,3 @@ void init_completion(completion_t *x) { x->done = 0; init_wait_queue_head(&x->wait); } -#endif