captive_privbcb_flush_{,un}ordered(): +Return whether anything was flushed.
authorshort <>
Mon, 14 Jul 2003 14:12:53 +0000 (14:12 +0000)
committershort <>
Mon, 14 Jul 2003 14:12:53 +0000 (14:12 +0000)
captive_cc_flush(): More robust against buffer dirtying by buffer flushes.
captive_privbcb_flush_unordered(): Allow the same LSN to be written twice.
CcUnpinRepinnedBcb(): Set the buffer dirty (not sure if it is right).

src/libcaptive/cc/map.c

index b4dd04f..4b335a0 100644 (file)
@@ -649,13 +649,15 @@ BOOLEAN r=TRUE;
 }
 
 
-static void captive_privbcb_flush_unordered(struct private_bcb *privbcb);
+static gboolean captive_privbcb_flush_unordered(struct private_bcb *privbcb);
 
 static void captive_cc_flush_private_bcb_hash_foreach(
                PUBLIC_BCB *PublicBcb,  /* key */
                struct private_bcb *privbcb,  /* value */
                gboolean *flushedp)     /* user_data */
 {
+gboolean errbool;
+
        g_return_if_fail(validate_Bcb(PublicBcb));
        g_return_if_fail(privbcb!=NULL);
        g_return_if_fail(PublicBcb==privbcb->PublicBcb);
@@ -669,10 +671,11 @@ static void captive_cc_flush_private_bcb_hash_foreach(
        g_assert(!privbcb->lsn_valid);
 
        *flushedp=TRUE;
-       captive_privbcb_flush_unordered(privbcb);
+       errbool=captive_privbcb_flush_unordered(privbcb);
+       g_assert(errbool==TRUE);
 }
 
-static void captive_privbcb_flush_ordered(struct private_bcb *privbcb_req);
+static gboolean captive_privbcb_flush_ordered(struct private_bcb *privbcb_req);
 
 void captive_cc_flush(void)
 {
@@ -683,8 +686,7 @@ gboolean flushed;
 
        do {
                /* Trace it by g_tree first to attempt to keep LSN ordering */
-               captive_privbcb_flush_ordered(NULL);
-               flushed=FALSE;
+               flushed=captive_privbcb_flush_ordered(NULL);
                g_hash_table_foreach(
                                private_bcb_hash,       /* hash_table */
                                (GHFunc)captive_cc_flush_private_bcb_hash_foreach,      /* func */
@@ -1295,7 +1297,9 @@ struct private_bcb *privbcb;
 
 static void logging_notify_privbcb_flush(struct private_bcb *privbcb);
 
-static void captive_privbcb_flush_unordered(struct private_bcb *privbcb)
+/* Returns: The block was dirty and it was flushed to disk.
+ */
+static gboolean captive_privbcb_flush_unordered(struct private_bcb *privbcb)
 {
 MDL *Mdl;
 KEVENT Event;
@@ -1312,7 +1316,7 @@ static gint64 last_written_lsn=G_MININT64;
        g_assert(privbcb->ref_count>0);
 
        if (!privbcb->dirty)
-               return;
+               return FALSE;
 
        privbcb_set(privbcb,PRIVBCB_ITEM_REF_COUNT_DESTRUCTOR,+1);
        logging_notify_privbcb_flush(privbcb);
@@ -1320,8 +1324,8 @@ static gint64 last_written_lsn=G_MININT64;
        privbcb_set(privbcb,PRIVBCB_ITEM_REF_COUNT_DESTRUCTOR,-1);
 
        if (privbcb->lsn_valid) {
-               if (!(last_written_lsn<privbcb->lsn.QuadPart))
-                       g_error("%s: last_written_lsn=%" G_GINT64_FORMAT " !< privbcb->lsn=%" G_GINT64_FORMAT,G_STRLOC,
+               if (!(last_written_lsn<=privbcb->lsn.QuadPart))
+                       g_error("%s: last_written_lsn=%" G_GINT64_FORMAT " !<= privbcb->lsn=%" G_GINT64_FORMAT,G_STRLOC,
                                        last_written_lsn,(gint64)privbcb->lsn.QuadPart);
                g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"%s: LSN write: last_written_lsn was %" G_GINT64_FORMAT ", is %" G_GINT64_FORMAT,
                                G_STRLOC,last_written_lsn,(gint64)privbcb->lsn.QuadPart);
@@ -1414,6 +1418,7 @@ REACTOS_COMMON_FCB_HEADER *CommonFcb=(REACTOS_COMMON_FCB_HEADER *)privbcb->FileO
                        (gulong)IoStatus.Information);
 
        privbcb_set(privbcb,PRIVBCB_ITEM_DIRTY,FALSE);
+       return TRUE;
 }
 
 struct captive_privbcb_flush_ordered_param {
@@ -1447,18 +1452,22 @@ static gboolean captive_privbcb_flush_ordered_foreach_get_first(struct private_b
 
 /* Use 'privbcb==NULL' to flush all LSNed entries of cache.
  * WARNING: Non-LSNed entries will NOT be flushed!
+ * Returns: Anything was really flushed to disk.
  */
-static void captive_privbcb_flush_ordered(struct private_bcb *privbcb_req)
+static gboolean captive_privbcb_flush_ordered(struct private_bcb *privbcb_req)
 {
 struct private_bcb *privbcb;
 struct captive_privbcb_flush_ordered_param captive_privbcb_flush_ordered_param;
+gboolean errbool;
+gboolean r=FALSE;
 
        if ((privbcb=privbcb_req) && !privbcb->dirty)
-               return;
+               return FALSE;
 
        if ((privbcb=privbcb_req) && !privbcb->lsn_valid) {
-               captive_privbcb_flush_unordered(privbcb);
-               return;
+               r=captive_privbcb_flush_unordered(privbcb);
+               g_assert(r==TRUE);
+               return r;
                }
 
        private_bcb_lsn_tree_init();
@@ -1482,7 +1491,9 @@ struct captive_privbcb_flush_ordered_param captive_privbcb_flush_ordered_param;
                                (int)privbcb->leave_func_pending);
 
                if (privbcb->dirty) {
-                       captive_privbcb_flush_unordered(privbcb);
+                       errbool=captive_privbcb_flush_unordered(privbcb);
+                       g_assert(errbool==TRUE);
+                       r=TRUE;
                        continue;       /* Restart as anything could change by calling W32 hassle. */
                        }
 
@@ -1493,7 +1504,8 @@ struct captive_privbcb_flush_ordered_param captive_privbcb_flush_ordered_param;
                break;
                }
 
-       g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"%s: return",G_STRLOC);
+       g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"%s: return %d",G_STRLOC,(int)r);
+       return r;
 }
 
 
@@ -1621,8 +1633,14 @@ struct private_bcb *privbcb;
        g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"%s: Bcb=%p,WriteThrough=%d,IoStatus=%p; privbcb->FileObject=%p",G_STRLOC,
                        Bcb,(gint)WriteThrough,IoStatus,privbcb->FileObject);
 
+       /* FIXME: Should we really mark it as dirty by this function?
+        * Undocumented by W32.
+        */
+       privbcb_set(privbcb,PRIVBCB_ITEM_DIRTY,TRUE);
+
        /* FIXME: Should we really flush the whole 'Bcb'?
         * Or maybe just some writes between CcRepinBcb(Bcb) and now? Who knows?
+        * Undocumented by W32.
         */
        if (WriteThrough)
                captive_privbcb_flush_ordered(privbcb);