]> Zhao Yanbai Git Server - kernel.git/commitdiff
...
authoracevest <zhaoyanbai@126.com>
Fri, 20 Oct 2023 12:50:49 +0000 (20:50 +0800)
committeracevest <zhaoyanbai@126.com>
Fri, 20 Oct 2023 12:50:49 +0000 (20:50 +0800)
fs/buffer.c
include/buffer.h
include/completion.h
kernel/completion.c

index 62cd0c19cc5bb167489685436f859ad5c4a0c57f..5d98a227b66097ed726f15bb1f37c58c4a74b809 100644 (file)
@@ -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);
index f58b695daace3fee813411d6b2c74230252b152b..c64a3a88c44aed7e7ad452f490f2d048c88afed8 100644 (file)
 #pragma once
 
 #include <atomic.h>
+#include <completion.h>
 #include <fs.h>
 #include <mm.h>
 #include <page.h>
 #include <system.h>
-#include <wait.h>
-
 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;
index 291f73ae122e7439d9d1c5885a105b77f3f6642f..93afe91a6133401f3e9eac1ba850b7f1b1ff8e0b 100644 (file)
@@ -9,7 +9,6 @@
 
 #pragma once
 
-#if 0
 #include <wait.h>
 
 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
index d556f3192fc99c02422a932782a806d9d34e7aaa..78c191c03320d389220f6ed0e910f6266bea04e8 100644 (file)
@@ -7,7 +7,6 @@
  * ------------------------------------------------------------------------
  */
 
-#if 0
 #include <completion.h>
 #include <sched.h>
 
@@ -25,4 +24,3 @@ void init_completion(completion_t *x) {
     x->done = 0;
     init_wait_queue_head(&x->wait);
 }
-#endif