Added block_cache_sync_etc() that allows you to sync single blocks.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20811 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
/* File System File and Block Caches
|
||||
*
|
||||
* Copyright 2004-2005, Haiku Inc. All Rights Reserved.
|
||||
/*
|
||||
* Copyright 2004-2007, Haiku Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _FS_CACHE_H
|
||||
#define _FS_CACHE_H
|
||||
|
||||
//! File System File and Block Caches
|
||||
|
||||
|
||||
#include <fs_interface.h>
|
||||
|
||||
@@ -37,7 +38,8 @@ extern void block_cache_delete(void *_cache, bool allowWrites);
|
||||
extern void *block_cache_create(int fd, off_t numBlocks, size_t blockSize,
|
||||
bool readOnly);
|
||||
extern status_t block_cache_sync(void *_cache);
|
||||
|
||||
extern status_t block_cache_sync_etc(void *_cache, off_t blockNumber,
|
||||
size_t numBlocks);
|
||||
extern status_t block_cache_make_writable(void *_cache, off_t blockNumber,
|
||||
int32 transaction);
|
||||
extern void *block_cache_get_writable_etc(void *_cache, off_t blockNumber,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2004-2006, Axel Dörfler, [email protected]. All rights reserved.
|
||||
* Copyright 2004-2007, Axel Dörfler, [email protected]. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "haiku_hash.h"
|
||||
#include "kernel_emu.h"
|
||||
|
||||
// ToDo: this is a naive but growing implementation to test the API:
|
||||
// TODO: this is a naive but growing implementation to test the API:
|
||||
// 1) block reading/writing is not at all optimized for speed, it will
|
||||
// just read and write single blocks.
|
||||
// 2) the locking could be improved; getting a block should not need to
|
||||
@@ -1060,6 +1060,39 @@ block_cache_sync(void *_cache)
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
block_cache_sync_etc(void *_cache, off_t blockNumber, size_t numBlocks)
|
||||
{
|
||||
block_cache *cache = (block_cache *)_cache;
|
||||
|
||||
// we will sync all dirty blocks to disk that have a completed
|
||||
// transaction or no transaction only
|
||||
|
||||
if (blockNumber < 0 || blockNumber >= cache->max_blocks) {
|
||||
panic("block_cache_sync_etc: invalid block number %Ld (max %Ld)",
|
||||
blockNumber, cache->max_blocks - 1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BenaphoreLocker locker(&cache->lock);
|
||||
|
||||
for (; numBlocks > 0; numBlocks--, blockNumber++) {
|
||||
cached_block *block = (cached_block *)hash_lookup(cache->hash,
|
||||
&blockNumber);
|
||||
if (block == NULL)
|
||||
continue;
|
||||
if (block->previous_transaction != NULL
|
||||
|| (block->transaction == NULL && block->is_dirty)) {
|
||||
status_t status = write_cached_block(cache, block);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
block_cache_make_writable(void *_cache, off_t blockNumber, int32 transaction)
|
||||
{
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
/* File System File and Block Caches
|
||||
*
|
||||
* Copyright 2004-2005, Haiku Inc. All Rights Reserved.
|
||||
/*
|
||||
* Copyright 2004-2007, Haiku Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef USERLAND_FS_HAIKU_FS_CACHE_H
|
||||
#define USERLAND_FS_HAIKU_FS_CACHE_H
|
||||
|
||||
//! File System File and Block Caches
|
||||
|
||||
|
||||
#include <fs_cache.h>
|
||||
|
||||
@@ -37,6 +38,8 @@ extern void block_cache_delete(void *_cache, bool allowWrites);
|
||||
extern void *block_cache_create(int fd, off_t numBlocks, size_t blockSize,
|
||||
bool readOnly);
|
||||
extern status_t block_cache_sync(void *_cache);
|
||||
extern status_t block_cache_sync_etc(void *_cache, off_t blockNumber,
|
||||
size_t numBlocks);
|
||||
|
||||
extern status_t block_cache_make_writable(void *_cache, off_t blockNumber,
|
||||
int32 transaction);
|
||||
|
||||
@@ -265,6 +265,14 @@ block_cache_sync(void *_cache)
|
||||
return UserlandFS::HaikuKernelEmu::block_cache_sync(_cache);
|
||||
}
|
||||
|
||||
// block_cache_sync_etc
|
||||
status_t
|
||||
block_cache_sync_etc(void *_cache, off_t blockNumber, size_t numBlocks)
|
||||
{
|
||||
return UserlandFS::HaikuKernelEmu::block_cache_sync_etc(_cache,
|
||||
blockNumber, numBlocks);
|
||||
}
|
||||
|
||||
// block_cache_make_writable
|
||||
status_t
|
||||
block_cache_make_writable(void *_cache, off_t blockNumber, int32 transaction)
|
||||
|
||||
+34
-1
@@ -23,7 +23,7 @@
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
// ToDo: this is a naive but growing implementation to test the API:
|
||||
// TODO: this is a naive but growing implementation to test the API:
|
||||
// 1) block reading/writing is not at all optimized for speed, it will
|
||||
// just read and write single blocks.
|
||||
// 2) the locking could be improved; getting a block should not need to
|
||||
@@ -1171,6 +1171,39 @@ block_cache_sync(void *_cache)
|
||||
}
|
||||
|
||||
|
||||
extern "C" status_t
|
||||
block_cache_sync_etc(void *_cache, off_t blockNumber, size_t numBlocks)
|
||||
{
|
||||
block_cache *cache = (block_cache *)_cache;
|
||||
|
||||
// we will sync all dirty blocks to disk that have a completed
|
||||
// transaction or no transaction only
|
||||
|
||||
if (blockNumber < 0 || blockNumber >= cache->max_blocks) {
|
||||
panic("block_cache_sync_etc: invalid block number %Ld (max %Ld)",
|
||||
blockNumber, cache->max_blocks - 1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BenaphoreLocker locker(&cache->lock);
|
||||
|
||||
for (; numBlocks > 0; numBlocks--, blockNumber++) {
|
||||
cached_block *block = (cached_block *)hash_lookup(cache->hash,
|
||||
&blockNumber);
|
||||
if (block == NULL)
|
||||
continue;
|
||||
if (block->previous_transaction != NULL
|
||||
|| (block->transaction == NULL && block->is_dirty)) {
|
||||
status_t status = write_cached_block(cache, block);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
extern "C" status_t
|
||||
block_cache_make_writable(void *_cache, off_t blockNumber, int32 transaction)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user