From: John Hodge Date: Sat, 14 Jul 2012 05:08:11 +0000 (+0800) Subject: Kernel - Added return value to module cleanup, fixed LVM bugs X-Git-Tag: rel0.15~611^2~41^2~1 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=25b02822ad95feb8f82f7b8fef44a58e29afb79b;p=tpg%2Facess2.git Kernel - Added return value to module cleanup, fixed LVM bugs --- diff --git a/KernelLand/Kernel/Makefile b/KernelLand/Kernel/Makefile index 42b47dcf..2512f64b 100644 --- a/KernelLand/Kernel/Makefile +++ b/KernelLand/Kernel/Makefile @@ -54,7 +54,7 @@ OBJ := $(addprefix arch/$(ARCHDIR)/,$(A_OBJ)) OBJ += heap.o logging.o debug.o lib.o libc.o adt.o time.o OBJ += drvutil_video.o drvutil_disk.o OBJ += messages.o modules.o syscalls.o system.o -OBJ += threads.o mutex.o semaphore.o workqueue.o events.o +OBJ += threads.o mutex.o semaphore.o workqueue.o events.o rwlock.o OBJ += drv/proc.o drv/fifo.o drv/iocache.o drv/pci.o OBJ += drv/vterm.o drv/vterm_font.o drv/vterm_vt100.o drv/vterm_output.o drv/vterm_input.o drv/vterm_termbuf.o OBJ += binary.o bin/elf.o bin/pe.o diff --git a/KernelLand/Kernel/include/modules.h b/KernelLand/Kernel/include/modules.h index d7281336..1c561463 100644 --- a/KernelLand/Kernel/include/modules.h +++ b/KernelLand/Kernel/include/modules.h @@ -73,7 +73,7 @@ typedef struct sModule struct sModule *Next; //!< Next module in list (not to be touched by the driver) const char *Name; //!< Module Name/Identifier int (*Init)(char **Arguments); //!< Module initialiser / entrypoint - void (*Deinit)(void); //!< Cleanup Function + int (*Deinit)(void); //!< Cleanup Function const char **Dependencies; //!< NULL terminated list of dependencies } PACKED tModule; diff --git a/KernelLand/Kernel/include/threads_int.h b/KernelLand/Kernel/include/threads_int.h index 6e345d02..2f15a729 100644 --- a/KernelLand/Kernel/include/threads_int.h +++ b/KernelLand/Kernel/include/threads_int.h @@ -100,6 +100,7 @@ enum { THREAD_STAT_ACTIVE, // Running and schedulable process THREAD_STAT_SLEEPING, // Message Sleep THREAD_STAT_MUTEXSLEEP, // Mutex Sleep + THREAD_STAT_RWLOCKSLEEP, // Read-Writer lock Sleep THREAD_STAT_SEMAPHORESLEEP, // Semaphore Sleep THREAD_STAT_QUEUESLEEP, // Queue THREAD_STAT_EVENTSLEEP, // Event sleep diff --git a/KernelLand/Modules/Filesystems/Ext2/ext2.c b/KernelLand/Modules/Filesystems/Ext2/ext2.c index 6379a9d0..f40689e0 100644 --- a/KernelLand/Modules/Filesystems/Ext2/ext2.c +++ b/KernelLand/Modules/Filesystems/Ext2/ext2.c @@ -15,7 +15,7 @@ extern tVFS_NodeType gExt2_DirType; // === PROTOTYPES === int Ext2_Install(char **Arguments); -void Ext2_Cleanup(void); + int Ext2_Cleanup(void); // - Interface Functions tVFS_Node *Ext2_InitDevice(const char *Device, const char **Options); void Ext2_Unmount(tVFS_Node *Node); @@ -48,9 +48,9 @@ int Ext2_Install(char **Arguments) /** * \brief Clean up driver state before unload */ -void Ext2_Cleanup(void) +int Ext2_Cleanup(void) { - + return 0; } /** diff --git a/KernelLand/Modules/Filesystems/FAT/fat.c b/KernelLand/Modules/Filesystems/FAT/fat.c index bb90c3cf..d6025104 100644 --- a/KernelLand/Modules/Filesystems/FAT/fat.c +++ b/KernelLand/Modules/Filesystems/FAT/fat.c @@ -105,6 +105,7 @@ tVFS_Node *FAT_InitDevice(const char *Device, const char **Options) if(bs->bps == 0 || bs->spc == 0) { Log_Notice("FAT", "Error in FAT Boot Sector (zero BPS/SPC)"); + VFS_Close(diskInfo->fileHandle); return NULL; } @@ -185,6 +186,7 @@ tVFS_Node *FAT_InitDevice(const char *Device, const char **Options) diskInfo->FATCache = (Uint32*)malloc(sizeof(Uint32)*diskInfo->ClusterCount); if(diskInfo->FATCache == NULL) { Log_Warning("FAT", "Heap Exhausted"); + VFS_Cose(diskInfo->fileHandle); return NULL; } Ofs = bs->resvSectCount*512; diff --git a/KernelLand/Modules/Input/Keyboard/main.c b/KernelLand/Modules/Input/Keyboard/main.c index 93d8c6a3..83481064 100644 --- a/KernelLand/Modules/Input/Keyboard/main.c +++ b/KernelLand/Modules/Input/Keyboard/main.c @@ -28,7 +28,7 @@ extern void Heap_Stats(void); // === PROTOTYPES === int Keyboard_Install(char **Arguments); -void Keyboard_Cleanup(void); + int Keyboard_Cleanup(void); // - Internal tKeymap *Keyboard_LoadMap(const char *Name); void Keyboard_FreeMap(tKeymap *Keymap); @@ -67,9 +67,10 @@ int Keyboard_Install(char **Arguments) /** * \brief Pre-unload cleanup function */ -void Keyboard_Cleanup(void) +int Keyboard_Cleanup(void) { // TODO: Do I need this? + return 0; } // --- Map Management --- diff --git a/KernelLand/Modules/Input/Mouse/main.c b/KernelLand/Modules/Input/Mouse/main.c index 5e6a9a2d..56bf9b52 100644 --- a/KernelLand/Modules/Input/Mouse/main.c +++ b/KernelLand/Modules/Input/Mouse/main.c @@ -15,7 +15,7 @@ // === PROTOTYPES === int Mouse_Install(char **Arguments); -void Mouse_Cleanup(void); + int Mouse_Cleanup(void); // - "User" side char *Mouse_Root_ReadDir(tVFS_Node *Node, int Pos); tVFS_Node *Mouse_Root_FindDir(tVFS_Node *Node, const char *Name); @@ -62,8 +62,9 @@ int Mouse_Install(char **Arguments) /** * \brief Pre-unload cleanup function */ -void Mouse_Cleanup(void) +int Mouse_Cleanup(void) { + return 0; } // --- VFS Interface --- diff --git a/KernelLand/Modules/Storage/LVM/include/lvm.h b/KernelLand/Modules/Storage/LVM/include/lvm.h index 5576e8ee..c106f771 100644 --- a/KernelLand/Modules/Storage/LVM/include/lvm.h +++ b/KernelLand/Modules/Storage/LVM/include/lvm.h @@ -16,8 +16,9 @@ struct sLVM_VolType { const char *Name; - int (*Read)(void *, Uint64, size_t, void *); - int (*Write)(void *, Uint64, size_t, const void *); + int (*Read)(void *, Uint64, size_t, void *); + int (*Write)(void *, Uint64, size_t, const void *); + void (*Cleanup)(void *); }; diff --git a/KernelLand/Modules/Storage/LVM/main.c b/KernelLand/Modules/Storage/LVM/main.c index d6845e19..44c2e579 100644 --- a/KernelLand/Modules/Storage/LVM/main.c +++ b/KernelLand/Modules/Storage/LVM/main.c @@ -5,7 +5,7 @@ * lvm.h * - LVM Core definitions */ -#define DEBUG 0 +#define DEBUG 1 #define VERSION VER2(0,1) #include "lvm_int.h" #include @@ -15,7 +15,7 @@ // === PROTOTYPES === // --- int LVM_Initialise(char **Arguments); -void LVM_Cleanup(void); + int LVM_Cleanup(void); // --- char *LVM_Root_ReadDir(tVFS_Node *Node, int ID); tVFS_Node *LVM_Root_FindDir(tVFS_Node *Node, const char *Name); @@ -60,9 +60,58 @@ int LVM_Initialise(char **Arguments) return 0; } -void LVM_Cleanup(void) +int LVM_Cleanup(void) { + // Attempt to destroy all volumes + tLVM_Vol *vol, *prev = NULL, *next; + // TODO: Locks? + for( vol = gpLVM_FirstVolume; vol; prev = vol, vol = next ) + { + next = vol->Next; + int nFree = 0; + + for( int i = 0; i < vol->nSubVolumes; i ++ ) + { + tLVM_SubVolume *sv; + sv = vol->SubVolumes[i]; + if( sv == NULL ) { + nFree ++; + continue; + } + + Mutex_Acquire(&sv->Node.Lock); + if(sv->Node.ReferenceCount == 0) { + nFree ++; + vol->SubVolumes[i] = NULL; + } + Mutex_Release(&sv->Node.Lock); + + Mutex_Acquire(&sv->Node.Lock); + LOG("Removed subvolume %s:%s", vol->Name, sv->Name); + free(sv); + } + + if( nFree != vol->nSubVolumes ) + continue ; + + if(prev) + prev->Next = next; + else + gpLVM_FirstVolume = next; + + Mutex_Acquire(&vol->DirNode.Lock); + Mutex_Acquire(&vol->VolNode.Lock); + if( vol->Type->Cleanup ) + vol->Type->Cleanup( vol->Ptr ); + LOG("Removed volume %s", vol->Name); + free(vol); + } + + if( gpLVM_FirstVolume ) + return EBUSY; + + return EOK; } // -------------------------------------------------------------------- diff --git a/KernelLand/Modules/Storage/LVM/volumes.c b/KernelLand/Modules/Storage/LVM/volumes.c index 567d26f8..f15b1b0a 100644 --- a/KernelLand/Modules/Storage/LVM/volumes.c +++ b/KernelLand/Modules/Storage/LVM/volumes.c @@ -52,6 +52,7 @@ int LVM_AddVolume(const tLVM_VolType *Type, const char *Name, void *Ptr, size_t real_vol->Next = NULL; real_vol->Type = Type; real_vol->Ptr = Ptr; + real_vol->BlockSize = BlockSize; real_vol->BlockCount = BlockCount; real_vol->nSubVolumes = dummy_vol.nSubVolumes; real_vol->SubVolumes = (void*)( real_vol->Name + strlen(Name) + 1 ); diff --git a/KernelLand/Modules/USB/MSC/main.c b/KernelLand/Modules/USB/MSC/main.c index 40231b44..94d258a6 100644 --- a/KernelLand/Modules/USB/MSC/main.c +++ b/KernelLand/Modules/USB/MSC/main.c @@ -14,7 +14,7 @@ // === PROTOTYPES === int MSC_Initialise(char **Arguments); -void MSC_Cleanup(void); + int MSC_Cleanup(void); void MSC_DeviceConnected(tUSBInterface *Dev, void *Descriptors, size_t DescriptorsLen); void MSC_DataIn(tUSBInterface *Dev, int EndPt, int Length, void *Data); // --- Internal Helpers @@ -43,8 +43,9 @@ int MSC_Initialise(char **Arguments) return 0; } -void MSC_Cleanup(void) +int MSC_Cleanup(void) { + return 0; } void MSC_DeviceConnected(tUSBInterface *Dev, void *Descriptors, size_t DescriptorsLen)