* Introduced new call get_next_removed_vnode() to be able to iterate over

removed but not yet deleted vnodes.
* Simplified get_vnode_removed().
* Header cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30176 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-04-15 16:14:04 +00:00
parent 5193237f1f
commit 4e98292b8e
2 changed files with 254 additions and 203 deletions
+6 -4
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2004-2008, Haiku Inc. All Rights Reserved.
* Copyright 2004-2009, Haiku Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _FS_INTERFACE_H
@@ -84,7 +84,7 @@ struct fs_volume_ops {
int* _type, uint32* _flags, bool reenter);
/* index directory & index operations */
status_t (*open_index_dir)(fs_volume *volume, void **cookie);
status_t (*open_index_dir)(fs_volume* volume, void** _cookie);
status_t (*close_index_dir)(fs_volume* volume, void* cookie);
status_t (*free_index_dir_cookie)(fs_volume* volume, void* cookie);
status_t (*read_index_dir)(fs_volume* volume, void* cookie,
@@ -250,7 +250,7 @@ struct file_system_module_info {
/* scanning (the device is write locked) */
float (*identify_partition)(int fd, partition_data* partition,
void **cookie);
void** _cookie);
status_t (*scan_partition)(int fd, partition_data* partition,
void* cookie);
void (*free_identify_partition_cookie)(partition_data* partition,
@@ -316,7 +316,9 @@ extern status_t acquire_vnode(fs_volume *volume, ino_t vnodeID);
extern status_t remove_vnode(fs_volume* volume, ino_t vnodeID);
extern status_t unremove_vnode(fs_volume* volume, ino_t vnodeID);
extern status_t get_vnode_removed(fs_volume* volume, ino_t vnodeID,
bool *removed);
bool* _removed);
extern status_t get_next_removed_vnode(fs_volume* volume, ino_t* _vnodeID,
void** _privateNode);
extern fs_volume* volume_for_vnode(fs_vnode* vnode);
extern status_t read_pages(int fd, off_t pos, const struct iovec* vecs,
+65 -16
View File
@@ -3539,10 +3539,6 @@ new_vnode(fs_volume* volume, ino_t vnodeID, void* privateNode,
// file system integrity check:
// test if the vnode already exists and bail out if this is the case!
// ToDo: the R5 implementation obviously checks for a different cookie
// and doesn't panic if they are equal
struct vnode* vnode = lookup_vnode(volume->id, vnodeID);
if (vnode != NULL) {
panic("vnode %ld:%Ld already exists (node = %p, vnode->node = %p)!",
@@ -3653,7 +3649,7 @@ get_vnode(fs_volume* volume, ino_t vnodeID, void** _privateNode)
return B_BAD_VALUE;
status_t status = get_vnode(volume->id, vnodeID, &vnode, true, true);
if (status < B_OK)
if (status != B_OK)
return status;
// If this is a layered FS, we need to get the node cookie for the requested
@@ -3764,21 +3760,74 @@ unremove_vnode(fs_volume* volume, ino_t vnodeID)
extern "C" status_t
get_vnode_removed(fs_volume* volume, ino_t vnodeID, bool* removed)
get_vnode_removed(fs_volume* volume, ino_t vnodeID, bool* _removed)
{
mutex_lock(&sVnodeMutex);
status_t result;
MutexLocker _(sVnodeMutex);
if (struct vnode* vnode = lookup_vnode(volume->id, vnodeID)) {
if (removed)
*removed = vnode->remove;
result = B_OK;
} else
result = B_BAD_VALUE;
if (_removed != NULL)
*_removed = vnode->remove;
return B_OK;
}
mutex_unlock(&sVnodeMutex);
return result;
return B_BAD_VALUE;
}
/*! Iterates over all removed vnodes of the volume. You own a reference to the
vnode when this call returns; you must initialize *_parentNode with NULL when
calling this function the first time, subsequent calls will automatically
put the previous reference again.
*/
extern "C" status_t
get_next_removed_vnode(fs_volume* volume, ino_t* _vnodeID, void** _privateNode)
{
fs_mount* mount;
status_t status = get_mount(volume->id, &mount);
if (status != B_OK)
return status;
// Retrieve the previous vnode
struct vnode* vnode = NULL;
if (*_privateNode != NULL) {
MutexLocker _(sVnodeMutex);
vnode = lookup_vnode(volume->id, *_vnodeID);
// we already have a reference, so this vnode won't get away
}
// Determine the ID of the next one
RecursiveLocker locker(mount->rlock);
struct vnode* nextVnode;
if (vnode == NULL)
nextVnode = mount->vnodes.First();
else {
nextVnode = mount->vnodes.GetNext(vnode);
dec_vnode_ref_count(vnode, false, true);
}
while (nextVnode != NULL && !nextVnode->remove) {
nextVnode = mount->vnodes.GetNext(nextVnode);
}
if (nextVnode == NULL)
return B_ENTRY_NOT_FOUND;
*_vnodeID = nextVnode->id;
locker.Unlock();
// Try to retrieve the vnode by ID, and return it's private node on success
status = get_vnode(volume->id, *_vnodeID, &vnode, true, true);
if (status != B_OK)
return status;
*_privateNode = vnode->private_node;
return B_OK;
}