Spinlock save cpu flags

This commit is contained in:
2026-03-12 22:48:34 +01:00
parent 19793e9126
commit 4760818118
50 changed files with 704 additions and 461 deletions

View File

@@ -22,14 +22,16 @@
static struct vfs_volume_table volume_table;
static struct vfs_volume* vfs_find_volume (const char* volume) {
uint64_t fvt;
struct hash_node_link* found_link = NULL;
size_t volume_len = strlen_null (volume);
uint32_t hash = hash_fnv32 (volume, volume_len);
spin_lock (&volume_table.lock);
spin_lock (&volume_table.lock, &fvt);
hash_find (&volume_table, volume, volume_len, hash, lengthof (volume_table.volume_buckets),
volume_buckets, struct vfs_volume, volume_table_link, key, found_link);
spin_unlock (&volume_table.lock);
spin_unlock (&volume_table.lock, fvt);
if (found_link == NULL)
return NULL;
@@ -39,6 +41,8 @@ static struct vfs_volume* vfs_find_volume (const char* volume) {
int vfs_create_volume (struct proc* proc, struct reschedule_ctx* rctx, const char* key, int fs_type,
struct device* back_device, bool format) {
uint64_t fvt;
if (strlen_null (key) > VOLUME_MAX)
return -ST_OOB_ERROR;
@@ -102,49 +106,53 @@ int vfs_create_volume (struct proc* proc, struct reschedule_ctx* rctx, const cha
uint32_t mp_hash = hash_fnv32 (volume->key, strlen_null (volume->key));
spin_lock (&volume_table.lock);
spin_lock (&volume_table.lock, &fvt);
hash_insert (&volume_table, &volume->volume_table_link, mp_hash,
lengthof (volume_table.volume_buckets), volume_buckets);
spin_unlock (&volume_table.lock);
spin_unlock (&volume_table.lock, fvt);
return ST_OK;
}
int vfs_volume_open (struct proc* proc, const char* volume_name, struct reschedule_ctx* rctx) {
uint64_t fv;
struct vfs_volume* volume = vfs_find_volume (volume_name);
if (volume == NULL)
return -ST_NOT_FOUND;
spin_lock (&volume->lock);
spin_lock (&volume->lock, &fv);
if (!volume->locked) {
volume->locked = true;
volume->owner = proc;
spin_unlock (&volume->lock);
spin_unlock (&volume->lock, fv);
return ST_OK;
} else {
proc_sq_suspend (proc, &volume->sq, &volume->lock, rctx);
proc_sq_suspend (proc, &volume->sq, &volume->lock, fv, rctx);
return ST_OK;
}
}
int vfs_volume_close (struct proc* proc, const char* volume_name, struct reschedule_ctx* rctx) {
uint64_t fv, fvsq;
struct vfs_volume* volume = vfs_find_volume (volume_name);
if (volume == NULL)
return -ST_NOT_FOUND;
spin_lock (&volume->lock);
spin_lock (&volume->lock, &fv);
if (volume->locked && volume->owner != proc) {
spin_unlock (&volume->lock);
spin_unlock (&volume->lock, fv);
return -ST_PERMISSION_ERROR;
}
spin_lock (&volume->sq.lock);
spin_lock (&volume->sq.lock, &fvsq);
struct list_node_link* node = volume->sq.proc_list;
@@ -155,8 +163,8 @@ int vfs_volume_close (struct proc* proc, const char* volume_name, struct resched
volume->owner = resumed_proc;
volume->locked = true;
spin_unlock (&volume->sq.lock);
spin_unlock (&volume->lock);
spin_unlock (&volume->sq.lock, fvsq);
spin_unlock (&volume->lock, fv);
proc_sq_resume (resumed_proc, sq_entry, rctx);
return ST_OK;
@@ -165,159 +173,175 @@ int vfs_volume_close (struct proc* proc, const char* volume_name, struct resched
volume->locked = false;
volume->owner = NULL;
spin_unlock (&volume->sq.lock);
spin_unlock (&volume->lock);
spin_unlock (&volume->sq.lock, fvsq);
spin_unlock (&volume->lock, fv);
return ST_OK;
}
int vfs_format (struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name) {
uint64_t fv;
struct vfs_volume* volume = vfs_find_volume (volume_name);
if (volume == NULL)
return -ST_NOT_FOUND;
spin_lock (&volume->lock);
spin_lock (&volume->lock, &fv);
if (volume->locked && volume->owner != proc) {
spin_unlock (&volume->lock);
spin_unlock (&volume->lock, fv);
return -ST_PERMISSION_ERROR;
}
spin_unlock (&volume->lock);
spin_unlock (&volume->lock, fv);
return volume->driver_ops.format (volume, proc, rctx);
}
int vfs_read_file (struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name,
const char* path, uint8_t* buffer, size_t off, size_t size) {
uint64_t fv;
struct vfs_volume* volume = vfs_find_volume (volume_name);
if (volume == NULL)
return -ST_NOT_FOUND;
spin_lock (&volume->lock);
spin_lock (&volume->lock, &fv);
if (volume->locked && volume->owner != proc) {
spin_unlock (&volume->lock);
spin_unlock (&volume->lock, fv);
return -ST_PERMISSION_ERROR;
}
spin_unlock (&volume->lock);
spin_unlock (&volume->lock, fv);
return volume->driver_ops.read_file (volume, proc, rctx, path, buffer, off, size);
}
int vfs_write_file (struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name,
const char* path, uint8_t* buffer, size_t off, size_t size, uint32_t flags) {
uint64_t fv;
struct vfs_volume* volume = vfs_find_volume (volume_name);
if (volume == NULL)
return -ST_NOT_FOUND;
spin_lock (&volume->lock);
spin_lock (&volume->lock, &fv);
if (volume->locked && volume->owner != proc) {
spin_unlock (&volume->lock);
spin_unlock (&volume->lock, fv);
return -ST_PERMISSION_ERROR;
}
spin_unlock (&volume->lock);
spin_unlock (&volume->lock, fv);
return volume->driver_ops.write_file (volume, proc, rctx, path, buffer, off, size, flags);
}
int vfs_create_file (struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name,
const char* path) {
uint64_t fv;
struct vfs_volume* volume = vfs_find_volume (volume_name);
if (volume == NULL)
return -ST_NOT_FOUND;
spin_lock (&volume->lock);
spin_lock (&volume->lock, &fv);
if (volume->locked && volume->owner != proc) {
spin_unlock (&volume->lock);
spin_unlock (&volume->lock, fv);
return -ST_PERMISSION_ERROR;
}
spin_unlock (&volume->lock);
spin_unlock (&volume->lock, fv);
return volume->driver_ops.create_file (volume, proc, rctx, path);
}
int vfs_describe (struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name,
const char* path, struct desc* desc) {
uint64_t fv;
struct vfs_volume* volume = vfs_find_volume (volume_name);
if (volume == NULL)
return -ST_NOT_FOUND;
spin_lock (&volume->lock);
spin_lock (&volume->lock, &fv);
if (volume->locked && volume->owner != proc) {
spin_unlock (&volume->lock);
spin_unlock (&volume->lock, fv);
return -ST_PERMISSION_ERROR;
}
spin_unlock (&volume->lock);
spin_unlock (&volume->lock, fv);
return volume->driver_ops.describe (volume, proc, rctx, path, desc);
}
int vfs_read_dir_entry (struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name,
const char* path, struct dir_entry* entry, size_t entry_num) {
uint64_t fv;
struct vfs_volume* volume = vfs_find_volume (volume_name);
if (volume == NULL)
return -ST_NOT_FOUND;
spin_lock (&volume->lock);
spin_lock (&volume->lock, &fv);
if (volume->locked && volume->owner != proc) {
spin_unlock (&volume->lock);
spin_unlock (&volume->lock, fv);
return -ST_PERMISSION_ERROR;
}
spin_unlock (&volume->lock);
spin_unlock (&volume->lock, fv);
return volume->driver_ops.read_dir_entry (volume, proc, rctx, path, entry, entry_num);
}
int vfs_create_dir (struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name,
const char* path) {
uint64_t fv;
struct vfs_volume* volume = vfs_find_volume (volume_name);
if (volume == NULL)
return -ST_NOT_FOUND;
spin_lock (&volume->lock);
spin_lock (&volume->lock, &fv);
if (volume->locked && volume->owner != proc) {
spin_unlock (&volume->lock);
spin_unlock (&volume->lock, fv);
return -ST_PERMISSION_ERROR;
}
spin_unlock (&volume->lock);
spin_unlock (&volume->lock, fv);
return volume->driver_ops.create_dir (volume, proc, rctx, path);
}
int vfs_remove (struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name,
const char* path) {
uint64_t fv;
struct vfs_volume* volume = vfs_find_volume (volume_name);
if (volume == NULL)
return -ST_NOT_FOUND;
spin_lock (&volume->lock);
spin_lock (&volume->lock, &fv);
if (volume->locked && volume->owner != proc) {
spin_unlock (&volume->lock);
spin_unlock (&volume->lock, fv);
return -ST_PERMISSION_ERROR;
}
spin_unlock (&volume->lock);
spin_unlock (&volume->lock, fv);
return volume->driver_ops.remove (volume, proc, rctx, path);
}