Ticket #8889: 0001-Code-to-reproduce-block-cache-problem-with-discarded.patch

File 0001-Code-to-reproduce-block-cache-problem-with-discarded.patch, 1.9 KB (added by ahenriksson, 7 years ago)
  • src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp

    From 023e4e0b10a9384dd40ad397015570c630decf6a Mon Sep 17 00:00:00 2001
    From: ahenriksson <sausageboy@gmail.com>
    Date: Wed, 15 Aug 2012 19:12:08 +0200
    Subject: [PATCH] Code to reproduce block cache problem with discarded blocks
    
    ---
     .../kernel/file_systems/bfs/kernel_interface.cpp   | 35 ++++++++++++++++++++++
     1 fil ändrad, 35 tillägg(+)
    
    diff --git a/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp b/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp
    index ad9b887..8a0d045 100644
    a b bfs_ioctl(fs_volume* _volume, fs_vnode* _node, void* _cookie, uint32 cmd,  
    623623    Volume* volume = (Volume*)_volume->private_volume;
    624624
    625625    switch (cmd) {
     626        case 56743:
     627        {
     628            const char string1[] = "wrote in transaction";
     629            const char string2[] = "wrote with write_pos";
     630
     631            // pick a block, any block (preferrably one you're not too fond of)
     632            off_t block = 6000;
     633
     634            // write something to it
     635            Transaction transaction(volume, 0);
     636
     637            CachedBlock cached(volume);
     638            uint8* cachedData = cached.SetToWritable(transaction, block);
     639            memcpy(cachedData, string1, sizeof(string1));
     640            cached.Unset();
     641
     642            transaction.Done();
     643
     644            // if this is uncommented, string2 is read
     645            //volume->GetJournal(0)->FlushLogAndBlocks();
     646
     647            // this is supposed to be equivalent to freeing the block and
     648            // allocating it again
     649            block_cache_discard(volume->BlockCache(), block, 1);
     650
     651            // write something else to the block
     652            write_pos(volume->Device(), block << volume->BlockShift(),
     653                string2, sizeof(string2));
     654
     655            // read the block (prints "wrote in transaction")
     656            cached.SetTo(block);
     657            INFORM(("string read from block: \"%s\"\n", cached.Block()));
     658
     659            return B_OK;
     660        }
    626661        case BFS_IOCTL_VERSION:
    627662        {
    628663            uint32 version = 0x10000;