From kevin at tyndur.org Wed Jan 1 23:11:57 2014 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 1 Jan 2014 23:11:57 +0100 Subject: [tyndur-devel] [PATCH libext2 0/8] Bootloader nicht kaputtmachen (und Patches zum Entstauben) In-Reply-To: <1388274569-12096-1-git-send-email-kevin@tyndur.org> References: <1388274569-12096-1-git-send-email-kevin@tyndur.org> Message-ID: <20140101221156.GA23357@silvanus> On Sun, Dec 29, 2013 at 12:49:21AM +0100, Kevin Wolf wrote: > Eigentlich ist es nur ein kleiner Bug, den diese Serie fixen will (die ersten > 1024 Bytes werden beim Superblock-Update nicht erhalten, sondern mit 0xc4 > überschrieben), aber bevor das gemacht werden kann, muss das alles erstmal > wieder kompilieren und konsistent mit tyndur sein. > > Also kommt hier einmal eine Runde diverses libext2-Zeug. > > Kevin Wolf (8): > etool: Fehler in ls nicht verschlucken > 10: Strict-Aliasing-Zeug gefixt > 20: Uninitialisierte Dereferenzierung gefixt > Makefile: Ausgabe für kompilierte Dateien > testlib: CDI-Cache aktualisiert > libext2: Bootloader nicht zerstören > 67: Bootloader muss beim Superblock-Update erhalten werden > .gitignore hinzugefügt Offensichtlich schweigende Zustimmung, ist jetzt gepusht. Kevin From kevin at tyndur.org Wed Jan 1 23:35:41 2014 From: kevin at tyndur.org (Kevin Wolf) Date: Wed, 1 Jan 2014 23:35:41 +0100 Subject: [tyndur-devel] =?iso-8859-1?q?=5BPATCH_0/3=5D_shell/libc=3A_Fixes?= =?iso-8859-1?q?_f=FCr_nichtkanonische_Pfade?= In-Reply-To: <1388341025-8144-1-git-send-email-kevin@tyndur.org> References: <1388341025-8144-1-git-send-email-kevin@tyndur.org> Message-ID: <20140101223541.GB23357@silvanus> On Sun, Dec 29, 2013 at 07:17:02PM +0100, Kevin Wolf wrote: > Teilweise sind die Fixes erst mit LIOv2 nötig, weil LIOv1 keine > Verzeichniseinträge für . und .. zurückgibt. Schaden können sie auf > keinen Fall. > > Kevin Wolf (3): > shell: cp -r überspringt . und .. > libc: io_split_filename() mit nicht-kanonischen Pfaden > shell: . und .. als Vervollständigungsoptionen ausschließen Ebenfalls gepusht. Kevin From particleflux at gmail.com Thu Jan 2 00:55:24 2014 From: particleflux at gmail.com (Stefan Linke) Date: Thu, 2 Jan 2014 00:55:24 +0100 Subject: [tyndur-devel] [PATCH] fix cross-gcc build for texinfo >= 5 Message-ID: <1388620524-18009-1-git-send-email-particleflux@gmail.com> ! cross-gcc build mit texinfo >= 5 repariert indem info-file Generierung abgeschaltet (wer braucht schon doc fuer cross-gcc?) Signed-off-by: Stefan Linke --- scripts/build_crosstools | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/build_crosstools b/scripts/build_crosstools index d44873d..2635952 100755 --- a/scripts/build_crosstools +++ b/scripts/build_crosstools @@ -193,6 +193,7 @@ echo "[gcc] Patch anwenden..." patch -p0 -d gcc-${GCC_VERSION}/ < ${PATCHES}/gcc/${GCC_VERSION}/gcc-${GCC_VERSION}.patch >${LOGS}/gcc.log || die "Fehler beim Anwenden des Patches.\nSiehe tmp/gcc.log für Details." cd build echo "[gcc] Konfigurieren..." +export MAKEINFO=missing ../gcc-${GCC_VERSION}/configure --prefix="${PREFIX}" --target=${TARGET} --disable-nls --enable-languages=c,c++ --disable-shared --disable-libssp ${GCC_CONFIGURE_PARAMS} >>${LOGS}/gcc.log 2>>${LOGS}/gcc.log|| die "Fehler beim Konfigurieren.\nSiehe tmp/gcc.log für Details." echo "[gcc] Kompilieren..." make all-gcc ${MAKEOPTS} >>${LOGS}/gcc.log 2>>${LOGS}/gcc.log || die "Fehler beim Kompilieren.\nSiehe tmp/gcc.log für Details." -- 1.8.4.4 From particleflux at gmail.com Thu Jan 2 01:12:39 2014 From: particleflux at gmail.com (Stefan Linke) Date: Thu, 2 Jan 2014 01:12:39 +0100 Subject: [tyndur-devel] [PATCH] typos in codestil.txt ausgebessert Message-ID: <1388621559-25014-1-git-send-email-particleflux@gmail.com> ! fix typos in doc/codestil.txt Signed-off-by: Stefan Linke --- doc/codestil.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/codestil.txt b/doc/codestil.txt index da5c05b..2dd0e03 100644 --- a/doc/codestil.txt +++ b/doc/codestil.txt @@ -9,9 +9,9 @@ Code einigermassen einheitlich bleibt. Einrueckung -Eingerueckt wird grunsaetzlich mit 4 Leerzeichen. Das fuehrt zu einer +Eingerueckt wird grundsaetzlich mit 4 Leerzeichen. Das fuehrt zu einer einheitlichen Darstellung auf allen Plattformen. Diese Entscheidung wurde zu -Beginn der Entwicklung gefaellt, und eine Umstellung steht nicht zur Diskusion. +Beginn der Entwicklung gefaellt, und eine Umstellung steht nicht zur Diskussion. Beim switch sind die case-Marken einmal, der enthaltene Code zweimal einzuruecken: @@ -69,7 +69,7 @@ Das ist ein weiteres Thema, bei dem es immer wieder zu heftigen Diskusionen kommt, welche Technik denn da nun die bessere sei. Bei tyndur hat sich die Folgende durchgesetzt: Bei Blocks kommt die oeffnende geschweifte Klammer grundsaetzlich auf die selbe Zeile wie das Konstrukt, dem der Block angehoert. -So wird der Anteil der nahezu leeren Zeilen bei groesstmoeglicher lesbarkeit +So wird der Anteil der nahezu leeren Zeilen bei groesstmoeglicher Lesbarkeit minimiert. Die Schliessende Klammer kommt auf eine eigene Zeile: if (file == NULL) { @@ -79,7 +79,7 @@ minimiert. Die Schliessende Klammer kommt auf eine eigene Zeile: Dies gilt nicht, falls die Bedingung im if so lang ist, dass sie umgebrochen werden muss. In diesem Fall sollen die umgebrochenen Zeilen auf die selbe Stufe eingerueckt werden, wie der Code der im Block stehen wird. Die oeffnende -geschweifte Klammer wird jedoch auf die Selbe hoehe wie das if geschrieben: +geschweifte Klammer wird jedoch auf die selbe Hoehe wie das if geschrieben: if (fseek(root_handle->device, block * ext2_block_size(root_handle), SEEK_SET) != 0) @@ -87,7 +87,7 @@ geschweifte Klammer wird jedoch auf die Selbe hoehe wie das if geschrieben: return -2; } -Eine Ausnahme bilden hier die Funktonsdefinitionen. Bei diesen kommt die +Eine Ausnahme bilden hier die Funktionsdefinitionen. Bei diesen kommt die oeffnende geschweifte Klammer ebenfalls auf eine neue Zeile. Diese Variante kann auch bei sehr langen (definitiv nicht unter 5 Zeilen) Schleifen oder if-Bloecken gewaehlt werden: @@ -97,7 +97,7 @@ if-Bloecken gewaehlt werden: // Mach was } -Bei Konstukten, die von einem weiteren Ausdruck, wie zum +Bei Konstrukten, die von einem weiteren Ausdruck, wie zum Beispiel else oder das while bei einer do-while-Schleife, wird dieser Ausdruck auf die gleiche Zeile wie die schliessende Klammer des ersten Blocks geschrieben: -- 1.8.4.4 From particleflux at gmail.com Thu Jan 2 03:47:17 2014 From: particleflux at gmail.com (Stefan Linke) Date: Thu, 2 Jan 2014 03:47:17 +0100 Subject: [tyndur-devel] [PATCH] updated GRUB2 hd image script Message-ID: <1388630837-350-1-git-send-email-particleflux@gmail.com> * veraltetes grub-setup mit grub-install ersetzt (grub-setup nur bis grub 1.99) * grub2 executables variabel gemacht (manche Systeme nutzen grub2-* anstatt grub-*, kann man nun schoen in der myconf.sh ueberschreiben wenn man moechte) Signed-off-by: Stefan Linke --- build/scripts/image_hd_grub2 | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/build/scripts/image_hd_grub2 b/build/scripts/image_hd_grub2 index cddc78b..bff0e62 100755 --- a/build/scripts/image_hd_grub2 +++ b/build/scripts/image_hd_grub2 @@ -39,6 +39,8 @@ ROOT_HD=build/root-hd ROOT_LOCAL=build/root-local MOUNT=build/mnt SUDO=sudo +GRUB_MKIMAGE=grub-mkimage +GRUB_INSTALL=grub-install export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin @@ -130,11 +132,6 @@ if [ $NEW -ne 0 ]; then EOF fi -# Partition unmounten und loopback-Device freigeben -while fuser -m $MOUNT; do true; done -$SUDO umount $MOUNT -rmdir $MOUNT - # Grub installieren if [ $NEW -ne 0 ]; then @@ -144,12 +141,25 @@ if [ $NEW -ne 0 ]; then fi mkdir -p build/grub2 - echo "(img) $LOOP_DEV" > build/grub2/device.map + echo "(hd0) $LOOP_DEV" > build/grub2/device.map cp $LOST_GRUB2_MODULESDIR/boot.img build/grub2/ - grub-mkimage --directory=$LOST_GRUB2_MODULESDIR -O i386-pc -o build/grub2/core.img ext2 biosdisk part_msdos minicmd - $SUDO grub-setup -m build/grub2/device.map -d build/grub2 -r "(img,1)" "(img)" + $SUDO $GRUB_INSTALL \ + --root-directory=$MOUNT \ + --no-floppy \ + --grub-mkdevicemap=build/grub2/device.map \ + --modules="part_msdos biosdisk ext2 minicmd" \ + $LOOP_DEV + if [ $? -ne 0 ]; then + rm -f $IMAGE_PATH + die "Grub-Installation fehlgeschlagen" + fi $SUDO losetup -d $LOOP_DEV fi + +# Partition unmounten und loopback-Device freigeben +while fuser -m $MOUNT; do true; done +$SUDO umount $MOUNT +rmdir $MOUNT -- 1.8.4.4 From particleflux at gmail.com Thu Jan 2 04:38:38 2014 From: particleflux at gmail.com (Stefan Linke) Date: Thu, 2 Jan 2014 04:38:38 +0100 Subject: [tyndur-devel] [PATCH] make cross-build weniger verbose Message-ID: <1388633918-6950-1-git-send-email-particleflux@gmail.com> * make cross-build ist jetzt auch fluesterleise wie die anderen builds Signed-off-by: Stefan Linke --- scripts/build_crosstools | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/build_crosstools b/scripts/build_crosstools index 2635952..ff00c05 100755 --- a/scripts/build_crosstools +++ b/scripts/build_crosstools @@ -218,14 +218,15 @@ echo "[make] Herunterladen..." [ -f make-3.81.tar.bz2 ] || wget -q http://ftp.gnu.org/gnu/make/make-3.81.tar.bz2 || die "Fehler beim Herrunterladen." echo "[make] Entpacken..." -tar -xvf make-3.81.tar.bz2 -echo "[make] Kompilieren" +tar -xvf make-3.81.tar.bz2 &>>${LOGS}/make.log || die "Fehler beim Entpacken.\nSiehe tmp/make.log für Details." +echo "[make] Konfigurieren" cd make-3.81 -./configure --prefix=${TMP}/make/build -make +./configure --prefix=${TMP}/make/build &>>${LOGS}/make.log || die "Fehler beim Konfigurieren.\nSiehe tmp/make.log für Details." +echo "[make] Kompilieren" +make &>>${LOGS}/make.log || die "Fehler beim Kompilieren.\nSiehe tmp/make.log für Details." echo "[make] Installieren." -make install -echo "[make] Fertig." +make install &>>${LOGS}/make.log || die "Fehler beim Installieren.\nSiehe tmp/make.log für Details." +echo -e "[make] Fertig.\n" fi # -- 1.8.4.4 From kevin at tyndur.org Thu Jan 2 13:37:18 2014 From: kevin at tyndur.org (Kevin Wolf) Date: Thu, 2 Jan 2014 13:37:18 +0100 Subject: [tyndur-devel] [PATCH] updated GRUB2 hd image script In-Reply-To: <1388630837-350-1-git-send-email-particleflux@gmail.com> References: <1388630837-350-1-git-send-email-particleflux@gmail.com> Message-ID: <20140102123717.GA4080@silvanus> On Thu, Jan 02, 2014 at 03:47:17AM +0100, Stefan Linke wrote: > * veraltetes grub-setup mit grub-install ersetzt (grub-setup nur bis grub > 1.99) > * grub2 executables variabel gemacht (manche Systeme nutzen grub2-* > anstatt grub-*, kann man nun schoen in der myconf.sh ueberschreiben wenn > man moechte) > > Signed-off-by: Stefan Linke Funktioniert bei mir nur teilweise. Zum einen brauche ich auch grub2-* wie du angemerkt hast. Da wäre es wahrscheinlich schöner, ein GRUB2_MKIMAGE/INSTALL direkt nach config.sh zu packen und Erkennungsmagie einzubauen wie für LOST_SYSLINUX_DIR. Aber gut, der Teil war ja dokumentiert. Das größere Problem ist, dass ich kein Bootmenü bekommen habe, sondern nur eine Shell. Ich brauche anscheinend auf dem Image boot/grub2/ für die Module und grub.cfg anstatt der boot/grub/, die im Moment erstellt wird. Die große Frage ist natürlich, ob das auch auf anderen Setups tut, oder ob es eine Option gibt, um das fest zu konfigurieren. Ich glaube, solche Probleme waren es auch, warum ich von Anfang an auf grub-install verzichtet habe. Das alte grub-setup heißt jetzt grub-bios-setup, sollte aber ansonsten auch noch tun. (Tut es bei mir auch.) Kevin From kevin at tyndur.org Fri Jan 3 01:26:42 2014 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 3 Jan 2014 01:26:42 +0100 Subject: [tyndur-devel] [PATCH 00/11] LostIOv2: cdi/storage als Userspace-Treiber Message-ID: <1388708813-23390-1-git-send-email-kevin@tyndur.org> Diese Serie legt die Grundlagen für LIOv2-Services im Userspace und konvertiert als erstes Opfer cdi/storage. Nach dieser Serie läuft ext2 wie gehab auf LIOv1, benutzt aber ein LIOv2-ata als Quelle. CD-ROM ist noch kaputt, das sollte man vielleicht noch fixen bevor die Serie gemergt wird, aber ansonsten scheint das zu tun. Kevin Wolf (11): kernel2: pm_thread_get() kernel2: Fix für Stackunderflow bei neuem Thread kernel2: Maximale Stackgröße für Threads erhöht kernel2: Privilegierte Syscalls kernel2: pm_scheduler_kern_yield() kernel2: on_destroy-Handler für Threads kernel2: pm_thread_block() mit wartenden Threads libc: LIOv2-Server im Userspace kernel2: LIOv2-Server im Userspace init: Unterstützung für LIOv2-Pipequellen cdi/storage: Auf LIOv2 umstellen src/include/arch/i386/page.h | 1 + src/include/syscall_structs.h | 353 ++++++++++++ src/include/syscallno.h | 18 +- src/kernel2/include/syscall.h | 39 ++ src/kernel2/include/tasks.h | 26 +- src/kernel2/src/arch/i386/syscall.c | 13 +- src/kernel2/src/lostio/include/lostio_int.h | 3 + src/kernel2/src/syscall.c | 20 + src/kernel2/src/syscalls/lio_server.c | 810 +++++++++++++++++++++++++++ src/kernel2/src/syscalls/lostio.c | 26 + src/kernel2/src/syscalls/pm.c | 27 + src/kernel2/src/syscalls/rpc.c | 4 +- src/kernel2/src/tasks/scheduler.c | 21 + src/kernel2/src/tasks/thread.c | 95 +++- src/modules/cdi/ata/device.c | 1 + src/modules/cdi/floppy/device.c | 1 + src/modules/cdi/include/cdi-osdep.h | 5 + src/modules/cdi/include/cdi/storage.h | 7 + src/modules/cdi/lib/cdi.c | 9 +- src/modules/cdi/lib/scsi/disk.c | 13 + src/modules/cdi/lib/storage.c | 225 ++++---- src/modules/include/lostio.h | 150 +++++ src/modules/include/syscall.h | 89 +++ src/modules/init/io.c | 52 ++ src/modules/lib/lostio/lio_server.c | 499 +++++++++++++++++ src/modules/lib/syscalls/lio_server.c | 204 +++++++ src/modules/lib/syscalls/lostio.c | 34 ++ 27 files changed, 2612 insertions(+), 133 deletions(-) create mode 100644 src/kernel2/src/syscalls/lio_server.c create mode 100644 src/modules/lib/lostio/lio_server.c create mode 100644 src/modules/lib/syscalls/lio_server.c -- 1.7.7 From kevin at tyndur.org Fri Jan 3 01:26:43 2014 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 3 Jan 2014 01:26:43 +0100 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH_01/11=5D_kernel2=3A_pm=5Fthread?= =?utf-8?b?X2dldCgp?= In-Reply-To: <1388708813-23390-1-git-send-email-kevin@tyndur.org> References: <1388708813-23390-1-git-send-email-kevin@tyndur.org> Message-ID: <1388708813-23390-2-git-send-email-kevin@tyndur.org> + kernel2: Funktion, um Threads anhand von Prozess und TID zu suchen Signed-off-by: Kevin Wolf --- src/kernel2/include/tasks.h | 3 ++ src/kernel2/src/tasks/thread.c | 53 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 0 deletions(-) diff --git a/src/kernel2/include/tasks.h b/src/kernel2/include/tasks.h index f31b4b6..7bcebb3 100644 --- a/src/kernel2/include/tasks.h +++ b/src/kernel2/include/tasks.h @@ -202,6 +202,9 @@ void pm_thread_destroy(pm_thread_t* thread); /// Thread blockieren bool pm_thread_block(pm_thread_t* thread); +/// Thread anhand der TID (und ggf. Prozess) suchen +pm_thread_t* pm_thread_get(pm_process_t* process, tid_t tid); + /// Thread entblocken bool pm_thread_unblock(pm_thread_t* thread); diff --git a/src/kernel2/src/tasks/thread.c b/src/kernel2/src/tasks/thread.c index 961fe31..b916e74 100644 --- a/src/kernel2/src/tasks/thread.c +++ b/src/kernel2/src/tasks/thread.c @@ -203,6 +203,59 @@ void pm_thread_destroy(pm_thread_t* thread) } /** + * Thread innerhalb eines Prozesses suchen + * + * @process Prozess, zu dem der gesuchte Thread gehört + * @tid Thread-ID des Threads + * + * @return Der Thread mit der passenden TID, oder NULL, wenn der Thread nicht + * existiert oder nicht zum gegebenen Prozess gehört. + */ +static pm_thread_t* pm_thread_get_in_proc(pm_process_t* process, tid_t tid) +{ + pm_thread_t* thread; + int i; + + for (i = 0; (thread = list_get_element_at(process->threads, i)); i++) { + if (thread->tid == tid) { + return thread; + } + } + + return NULL; +} + +/** + * Thread anhand der TID suchen + * + * @process Prozess, zu dem der gesuchte Thread gehört, oder NULL, wenn in + * allen Prozessen gesucht werden soll + * + * @tid Thread-ID des Threads + * + * @return Der Thread mit der passenden TID, oder NULL, wenn der Thread nicht + * existiert oder nicht zum gegebenen Prozess gehört. + */ +pm_thread_t* pm_thread_get(pm_process_t* process, tid_t tid) +{ + pm_thread_t* thread; + int i; + + if (process) { + return pm_thread_get_in_proc(process, tid); + } + + for (i = 0; (process = list_get_element_at(process_list, i)); i++) { + thread = pm_thread_get_in_proc(process, tid); + if (thread) { + return thread; + } + } + + return NULL; +} + +/** * Thread blockieren * * @param thread Pointer auf die Thread-Struktur -- 1.7.7 From kevin at tyndur.org Fri Jan 3 01:26:44 2014 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 3 Jan 2014 01:26:44 +0100 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH_02/11=5D_kernel2=3A_Fix_f=C3=BC?= =?utf-8?q?r_Stackunderflow_bei_neuem_Thread?= In-Reply-To: <1388708813-23390-1-git-send-email-kevin@tyndur.org> References: <1388708813-23390-1-git-send-email-kevin@tyndur.org> Message-ID: <1388708813-23390-3-git-send-email-kevin@tyndur.org> ! kernel2: Das Argument für den neuen Thread gehört als erstes auf den Stack gelegt, aber innerhalb des Stacks sollte es schon noch sein. Signed-off-by: Kevin Wolf --- src/kernel2/src/syscalls/pm.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/src/kernel2/src/syscalls/pm.c b/src/kernel2/src/syscalls/pm.c index f2f869c..2bcabef 100644 --- a/src/kernel2/src/syscalls/pm.c +++ b/src/kernel2/src/syscalls/pm.c @@ -394,8 +394,11 @@ tid_t syscall_pm_create_thread(vaddr_t start, void *arg) interrupt_stack_frame_t *isf = (interrupt_stack_frame_t *)thread->user_isf; + /* Parameter auf den Userspace-Stack kopieren */ + isf->esp -= sizeof(void *); *((void **)(isf->esp)) = arg; + /* Rücksprungadresse leer lassen */ isf->esp -= sizeof(void *); while (pm_thread_unblock(thread) == true); -- 1.7.7 From kevin at tyndur.org Fri Jan 3 01:26:45 2014 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 3 Jan 2014 01:26:45 +0100 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH_03/11=5D_kernel2=3A_Maximale_St?= =?utf-8?b?YWNrZ3LDtsOfZSBmw7xyIFRocmVhZHMgZXJow7ZodA==?= In-Reply-To: <1388708813-23390-1-git-send-email-kevin@tyndur.org> References: <1388708813-23390-1-git-send-email-kevin@tyndur.org> Message-ID: <1388708813-23390-4-git-send-email-kevin@tyndur.org> * kernel2: 4k Stack insgesamt pro Thread sind schon arg wenig. Mit diesem Patch bleibt es dabei, dass wir mit 4k starten, aber es wird virtueller Speicher für 1 MB freigehalten. Die normale Stackvergrößerungsmagie funktioniert für jeden Thread und erlaubt den Threads, den vollen Platz zu nutzen wenn nötig. Wenn ein Thread mehr Platz braucht, wird das noch nicht abgefangen, sondern der Stack wächst einfach in den nächsten Stack hinein. Signed-off-by: Kevin Wolf --- src/include/arch/i386/page.h | 1 + src/kernel2/src/tasks/thread.c | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/include/arch/i386/page.h b/src/include/arch/i386/page.h index a4ed66d..19d3dc3 100644 --- a/src/include/arch/i386/page.h +++ b/src/include/arch/i386/page.h @@ -52,6 +52,7 @@ #define USER_STACK_START 0 #define USER_STACK_SIZE 0x1000 +#define USER_MAX_STACK_SIZE 0x100000 // Die Anzahl der Pages, die von n Bytes belegt werden. diff --git a/src/kernel2/src/tasks/thread.c b/src/kernel2/src/tasks/thread.c index b916e74..a2d01bf 100644 --- a/src/kernel2/src/tasks/thread.c +++ b/src/kernel2/src/tasks/thread.c @@ -126,9 +126,11 @@ pm_thread_t* pm_thread_create(pm_process_t* process, vaddr_t entry) thread->user_stack_bottom = (vaddr_t) (isf->rsp - USER_STACK_SIZE); #endif - + + /* TODO Irgendeine Art von Größenbeschränkung mit Guard Page, dass der + * Stack nicht in den nächsten Stack reinwächst */ process->next_stack = (vaddr_t) ((uintptr_t) process->next_stack - - USER_STACK_SIZE); + USER_MAX_STACK_SIZE); // Page fuer den Userspace-Stack allozieren paddr_t stack_phys = pmm_alloc(NUM_PAGES(USER_STACK_SIZE)); -- 1.7.7 From kevin at tyndur.org Fri Jan 3 01:26:46 2014 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 3 Jan 2014 01:26:46 +0100 Subject: [tyndur-devel] [PATCH 04/11] kernel2: Privilegierte Syscalls In-Reply-To: <1388708813-23390-1-git-send-email-kevin@tyndur.org> References: <1388708813-23390-1-git-send-email-kevin@tyndur.org> Message-ID: <1388708813-23390-5-git-send-email-kevin@tyndur.org> + kernel2: Eine neue Art von Syscalls, die nur aus dem Kernel aufgerufen werden dürfen ! kernel2: Syscalls aus dem Kernel funktionieren jetzt auch mit Parametern, weil der richtige Stack benutzt wird Signed-off-by: Kevin Wolf --- src/kernel2/include/syscall.h | 3 +++ src/kernel2/src/arch/i386/syscall.c | 13 ++++++++++++- src/kernel2/src/syscall.c | 1 + 3 files changed, 16 insertions(+), 1 deletions(-) diff --git a/src/kernel2/include/syscall.h b/src/kernel2/include/syscall.h index a359f22..f4fcb57 100644 --- a/src/kernel2/include/syscall.h +++ b/src/kernel2/include/syscall.h @@ -54,6 +54,9 @@ typedef struct { /// Anzahl der Argumente die der Syscall benoetigt size_t arg_count; + + /// true, wenn der Syscall nur aus dem Kernelspace aufgerufen werden darf + bool privileged; } syscall_t; /// In diesem Array werden alle Syscalls gespeichert. diff --git a/src/kernel2/src/arch/i386/syscall.c b/src/kernel2/src/arch/i386/syscall.c index 4c1bba4..892c5e1 100644 --- a/src/kernel2/src/arch/i386/syscall.c +++ b/src/kernel2/src/arch/i386/syscall.c @@ -64,7 +64,7 @@ void syscall_arch(machine_state_t* isf) // "Kompatibel" zu kernel1 void syscall_arch(machine_state_t* isf) { - uint32_t* stack = (uint32_t*) isf->esp; + uint32_t* stack; uint32_t number = isf->eax; //kprintf("Syscall %d", number); @@ -74,6 +74,17 @@ void syscall_arch(machine_state_t* isf) } void* handler = syscalls[number].handler; + if (isf_is_userspace(isf)) { + if (syscalls[number].privileged) { + // FIXME: Hier sollte nur der Prozess beendet werden + panic("Privilegierter Syscall %d", number); + } + stack = (uint32_t*) isf->esp; + } else { + /* esp wird bei Interrupt in Ring 0 nicht gepusht, das ist also der + * erste "alte" Stackinhalt */ + stack = (uint32_t*) &isf->esp; + } if (debug_test_flag(DEBUG_FLAG_SYSCALL)) { kprintf("[PID %d] Syscall:%d\n", current_process->pid, isf->eax); diff --git a/src/kernel2/src/syscall.c b/src/kernel2/src/syscall.c index f401ea0..f663915 100644 --- a/src/kernel2/src/syscall.c +++ b/src/kernel2/src/syscall.c @@ -143,4 +143,5 @@ void syscall_register(syscall_arg_t number, void* handler, size_t arg_count) } syscalls[number].handler = handler; syscalls[number].arg_count = arg_count; + syscalls[number].privileged = false; } -- 1.7.7 From kevin at tyndur.org Fri Jan 3 01:26:47 2014 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 3 Jan 2014 01:26:47 +0100 Subject: [tyndur-devel] [PATCH 05/11] kernel2: pm_scheduler_kern_yield() In-Reply-To: <1388708813-23390-1-git-send-email-kevin@tyndur.org> References: <1388708813-23390-1-git-send-email-kevin@tyndur.org> Message-ID: <1388708813-23390-6-git-send-email-kevin@tyndur.org> + kernel2: Neue Funktion, um den aktuellen Thread aus dem Kernel schlafen zu legen, mit optionalem neuen Thread und Status für den alten Thread. Nutzt einen neuen privilegierten Syscall. Signed-off-by: Kevin Wolf --- src/include/syscallno.h | 4 ++-- src/kernel2/include/syscall.h | 3 +++ src/kernel2/include/tasks.h | 3 +++ src/kernel2/src/syscall.c | 6 ++++++ src/kernel2/src/syscalls/pm.c | 24 ++++++++++++++++++++++++ src/kernel2/src/tasks/scheduler.c | 21 +++++++++++++++++++++ 6 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/include/syscallno.h b/src/include/syscallno.h index 917e58b..2a2f909 100644 --- a/src/include/syscallno.h +++ b/src/include/syscallno.h @@ -52,7 +52,7 @@ #define SYSCALL_PM_SET_UID 8 #define SYSCALL_PM_REQUEST_PORT 9 #define SYSCALL_PM_RELEASE_PORT 10 -#define SYSCALL_PM_SLEEP 6 +#define KERN_SYSCALL_PM_SLEEP 124 #define SYSCALL_VM86 81 #define SYSCALL_VM86_BIOS_INT 83 @@ -119,6 +119,6 @@ #define SYSCALL_LIO_SRV_NODE_REMOVE 118 //ACHTUNG: Muss eine Zahl groesser als die Groesste Syscall-Nummer sein -#define SYSCALL_MAX 124 +#define SYSCALL_MAX 125 #endif diff --git a/src/kernel2/include/syscall.h b/src/kernel2/include/syscall.h index f4fcb57..51f0ff1 100644 --- a/src/kernel2/include/syscall.h +++ b/src/kernel2/include/syscall.h @@ -114,6 +114,9 @@ int syscall_pm_v_and_wait_for_rpc(void); /// Die Kontrolle an einen anderen Task abgeben void syscall_pm_sleep(void); +/// Die Kontrolle an einen anderen Task abgeben +void kern_syscall_pm_sleep(tid_t yield_to, int status); + /// Warten, bis ein RPC zu bearbeiten ist void syscall_pm_wait_for_rpc(void); diff --git a/src/kernel2/include/tasks.h b/src/kernel2/include/tasks.h index 7bcebb3..55caae6 100644 --- a/src/kernel2/include/tasks.h +++ b/src/kernel2/include/tasks.h @@ -232,6 +232,9 @@ void pm_scheduler_push(pm_thread_t* thread); /// Kontrolle vom aktuellen Kernelthread an einen anderen Thread abgeben void pm_scheduler_yield(void); +/// Kontrolle an einen bestimmten Thread abgeben, mit Folgezustand +void pm_scheduler_kern_yield(tid_t tid, int status); + /// Versucht einen Taskwechsel zum übergebenen Thread void pm_scheduler_try_switch(pm_thread_t* thread); diff --git a/src/kernel2/src/syscall.c b/src/kernel2/src/syscall.c index f663915..b6b06c5 100644 --- a/src/kernel2/src/syscall.c +++ b/src/kernel2/src/syscall.c @@ -123,6 +123,12 @@ void syscall_init() syscall_register(SYSCALL_LIO_STAT, &syscall_lio_stat, 2); syscall_register(SYSCALL_LIO_UNLINK, &syscall_lio_unlink, 3); syscall_register(SYSCALL_LIO_SYNC_ALL, &syscall_lio_sync_all, 0); + + syscalls[KERN_SYSCALL_PM_SLEEP] = (syscall_t) { + .handler = &kern_syscall_pm_sleep, + .arg_count = 2, + .privileged = true, + }; } /** diff --git a/src/kernel2/src/syscalls/pm.c b/src/kernel2/src/syscalls/pm.c index 2bcabef..c316884 100644 --- a/src/kernel2/src/syscalls/pm.c +++ b/src/kernel2/src/syscalls/pm.c @@ -265,6 +265,30 @@ void syscall_pm_sleep(void) } /** + * Privilegierte Version von syscall_pm_sleep, die dem alten Task einen + * spezifischen neuen Zustand gibt und zu einem bestimmten anderen Task + * wechseln kann. + */ +void kern_syscall_pm_sleep(tid_t yield_to, int status) +{ + pm_thread_t* thread = NULL; + + current_thread->status = status; + + if (yield_to) { + thread = pm_thread_get(NULL, yield_to); + } + + if (thread) { + pm_scheduler_get(thread); + thread->status = PM_STATUS_RUNNING; + current_thread = thread; + } else { + current_thread = pm_scheduler_pop(); + } +} + +/** * Die Kontrolle an einen anderen Task abgeben und erst wieder aufwachen, * wenn ein RPC zu bearbeiten ist */ diff --git a/src/kernel2/src/tasks/scheduler.c b/src/kernel2/src/tasks/scheduler.c index de95d83..d63ef13 100644 --- a/src/kernel2/src/tasks/scheduler.c +++ b/src/kernel2/src/tasks/scheduler.c @@ -239,6 +239,27 @@ void pm_scheduler_yield(void) } /** + * Kontrolle vom aktuellen Kernelthread an einen anderen Thread abgeben + * + * @tid TID des Threads, an den die Kontrolle übergeben werden soll, oder 0 + * @status Thread-Status des alten Threads + */ +void pm_scheduler_kern_yield(tid_t tid, int status) +{ + asm volatile( + "push %2;" + "push %1;" + "int $0x30;" + "add $8, %%esp;" + : : "a" (KERN_SYSCALL_PM_SLEEP), "r" (tid), "r" (status)); + + // Es kann passieren, dass zwei Tasks im Kernel hin- und heryielden und + // auf irgendetwas warten, was von einem IRQ abhängt. Deshalb müssen wir + // dem IRQ eine Chance geben, anzukommen. + asm volatile("sti; nop; cli"); +} + +/** * Macht den übergebenen Thread zum aktuellen Thread dieser CPU, wenn er * momentan lauffähig ist. Wenn nicht, bleibt der bisherige Thread aktiv. */ -- 1.7.7 From kevin at tyndur.org Fri Jan 3 01:26:48 2014 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 3 Jan 2014 01:26:48 +0100 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH_06/11=5D_kernel2=3A_on=5Fdestro?= =?utf-8?q?y-Handler_f=C3=BCr_Threads?= In-Reply-To: <1388708813-23390-1-git-send-email-kevin@tyndur.org> References: <1388708813-23390-1-git-send-email-kevin@tyndur.org> Message-ID: <1388708813-23390-7-git-send-email-kevin@tyndur.org> + kernel2: Eventhandler für das Beenden von Threads, analog zum schon bestehenden on_destroy für Prozesse Signed-off-by: Kevin Wolf --- src/kernel2/include/tasks.h | 11 +++++++++++ src/kernel2/src/tasks/thread.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 0 deletions(-) diff --git a/src/kernel2/include/tasks.h b/src/kernel2/include/tasks.h index 55caae6..d4096bb 100644 --- a/src/kernel2/include/tasks.h +++ b/src/kernel2/include/tasks.h @@ -146,9 +146,16 @@ typedef struct { /// Gesetzt, wenn der Thread beim Beenden den gesamten Prozess beendet bool is_main_thread; + + /** + * Eine Liste von Eventhandlern, die beim Loeschen des Threads + * aufgerufen werden + */ + list_t* on_destroy; } pm_thread_t; typedef void (*pm_process_destroy_handler)(pm_process_t* process, void* prv); +typedef void (*pm_thread_destroy_handler)(pm_thread_t* thread, void* prv); extern list_t* process_list; @@ -187,6 +194,10 @@ bool pm_unblock_rpc(pm_process_t* task, pid_t blocked_by); void pm_register_on_destroy(pm_process_t* process, pm_process_destroy_handler handler, void* prv); +/// Handler fuer das Loeschen des Threads registrieren +void pm_thread_register_on_destroy(pm_thread_t* thread, + pm_thread_destroy_handler handler, void* prv); + /// Entfernt den gegebenen Task aus allen RPC-Backlinks void rpc_destroy_task_backlinks(pm_process_t* destroyed_process); diff --git a/src/kernel2/src/tasks/thread.c b/src/kernel2/src/tasks/thread.c index a2d01bf..676a930 100644 --- a/src/kernel2/src/tasks/thread.c +++ b/src/kernel2/src/tasks/thread.c @@ -44,6 +44,11 @@ #include "lock.h" #include "cpu.h" +struct on_destroy_info { + pm_thread_destroy_handler handler; + void* prv; +}; + static tid_t next_tid = 1; static tid_t generate_tid(void) @@ -80,6 +85,9 @@ pm_thread_t* pm_thread_create(pm_process_t* process, vaddr_t entry) // Ein Pointer auf den Prozess im Thread hinterlegen thread->process = process; + + // Eventhandlerlisten anlegen + thread->on_destroy = list_create(); // Der Lock wird gesperrt initialisiert thread->lock = 1; @@ -158,6 +166,7 @@ pm_thread_t* pm_thread_create(pm_process_t* process, vaddr_t entry) */ void pm_thread_destroy(pm_thread_t* thread) { + struct on_destroy_info* info; // TODO Andere Threads beenden, falls thread->is_main_thread // Zuerst muss der Thread angehalten werden @@ -169,6 +178,13 @@ void pm_thread_destroy(pm_thread_t* thread) // Beim Scheduler abmelden pm_scheduler_delete(thread); + // Eventhandler ausfuehren + while ((info = list_pop(thread->on_destroy))) { + info->handler(thread, info->prv); + free(info); + } + list_destroy(thread->on_destroy); + // Wir brauchen immer einen gueltigen aktiven Thread, sonst kommt der // Interrupthandler durcheinander und kann bei Exceptions im Kernel keine // ordentliche Meldung mehr anzeigen. @@ -313,3 +329,17 @@ bool pm_thread_unblock(pm_thread_t* thread) unlock(&thread->lock); return result; } + +/** + * Handler fuer das Loeschen des Threads registrieren + */ +void pm_thread_register_on_destroy(pm_thread_t* thread, + pm_thread_destroy_handler handler, void* prv) +{ + struct on_destroy_info* info = malloc(sizeof(*info)); + + info->handler = handler; + info->prv = prv; + + list_push(thread->on_destroy, info); +} -- 1.7.7 From kevin at tyndur.org Fri Jan 3 01:26:49 2014 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 3 Jan 2014 01:26:49 +0100 Subject: [tyndur-devel] [PATCH 07/11] kernel2: pm_thread_block() mit wartenden Threads In-Reply-To: <1388708813-23390-1-git-send-email-kevin@tyndur.org> References: <1388708813-23390-1-git-send-email-kevin@tyndur.org> Message-ID: <1388708813-23390-8-git-send-email-kevin@tyndur.org> ! kernel2: pm_thread_block() hat bisher gewartet, bis ein Thread irgendwann in READY landet. Das passiert dummerweise nie, wenn der Thread gar nicht läuft, sondern auf RPC oder LIO wartet. Deswegen wird jetzt auf !RUNNING geprüft. Damit kann es passieren, dass ein Thread nach dem Entblocken plötzlich READY ist, obwohl er vorher gewartet hat, aber das ist okay. Dann dreht er eben unnötigerweise eine Runde in der Schleife des Aufrufers. Signed-off-by: Kevin Wolf --- src/kernel2/src/tasks/thread.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/kernel2/src/tasks/thread.c b/src/kernel2/src/tasks/thread.c index 676a930..06a2e9e 100644 --- a/src/kernel2/src/tasks/thread.c +++ b/src/kernel2/src/tasks/thread.c @@ -293,7 +293,7 @@ bool pm_thread_block(pm_thread_t* thread) lock(&thread->lock); - if (thread->status == PM_STATUS_READY) { + if (thread->status != PM_STATUS_RUNNING) { thread->status = PM_STATUS_BLOCKED; } -- 1.7.7 From kevin at tyndur.org Fri Jan 3 01:26:50 2014 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 3 Jan 2014 01:26:50 +0100 Subject: [tyndur-devel] [PATCH 08/11] libc: LIOv2-Server im Userspace In-Reply-To: <1388708813-23390-1-git-send-email-kevin@tyndur.org> References: <1388708813-23390-1-git-send-email-kevin@tyndur.org> Message-ID: <1388708813-23390-9-git-send-email-kevin@tyndur.org> + libc: Definitionen der Syscallnummern und Datenstrukturen, die für LIOv2-Userspace-Services benutzt werden. Der Kernel kommuniziert dabei zum Service, indem er Befehle in einen Ringpuffer schreibt, während der Service sich dem Kernel über Syscalls mitteilt. Die Kommunikation geht (bis auf die Service-Registrierung) dabei immer vom Kernel aus. + libc: Bibliothek mit Hilfsfunktionen zur Implemenierung von Userspace- Services. Damit muss ein Service nur noch eine struct (hauptsächlich) mit Funktionspointern befüllen und sich damit registrieren. Signed-off-by: Kevin Wolf --- src/include/syscall_structs.h | 353 +++++++++++++++++++++++ src/include/syscallno.h | 13 +- src/modules/include/lostio.h | 150 ++++++++++ src/modules/include/syscall.h | 74 +++++ src/modules/lib/lostio/lio_server.c | 499 +++++++++++++++++++++++++++++++++ src/modules/lib/syscalls/lio_server.c | 204 ++++++++++++++ 6 files changed, 1286 insertions(+), 7 deletions(-) create mode 100644 src/modules/lib/lostio/lio_server.c create mode 100644 src/modules/lib/syscalls/lio_server.c diff --git a/src/include/syscall_structs.h b/src/include/syscall_structs.h index 90eec14..060d82e 100644 --- a/src/include/syscall_structs.h +++ b/src/include/syscall_structs.h @@ -75,6 +75,7 @@ typedef struct } vm86_regs_t; // LIO2 +#define LIO_OFFSET_SPARSE (-1ULL) /** ID eines LostIO-Streams */ typedef int64_t lio_usp_stream_t; @@ -204,4 +205,356 @@ struct lio_usp_dir_entry { struct lio_stat stat; } __attribute__((packed)); +/// Opcodes fuer Server-Operationen +enum lio_opcode { + /** + * Diese Operation ist ungueltig (und somit existieren auch keine weiteren) + */ + LIO_OP_INVALID = 0, + + /** + * NOP, kann fuer Padding im Ringpuffer benutzt werden + */ + LIO_OP_NOP = 1, + + /** + * Root-Ressource eines Dateisystems laden + */ + LIO_OP_LOAD_ROOT = 2, + + /** + * Kind-Ressourcen einer Ressource laden + */ + LIO_OP_LOAD_CHILDREN = 3, + + /** + * Datenbloecke von Ressource lesen + */ + LIO_OP_READ = 4, + + /** + * Datenbloecke in Ressource schreiben + */ + LIO_OP_WRITE = 5, + + /** + * Neue Datei erstellen + */ + LIO_OP_MAKE_FILE = 6, + + /** + * Neues Verzeichnis erstellen + */ + LIO_OP_MAKE_DIR = 7, + + /** + * Dateigroesse setzen + */ + LIO_OP_TRUNCATE = 8, + + /** + * Verzeichniseintrag loeschen + */ + LIO_OP_UNLINK = 9, + + /** + * Pipe erstellen + */ + LIO_OP_PIPE = 10, + + /** + * Symlink erstellen + */ + LIO_OP_MAKE_SYMLINK = 11, + + /** + * Blockbereich allozieren + */ + LIO_OP_ALLOCATE = 12, + + /** + * Ggf. vorhandene Caches zurückschreiben + */ + LIO_OP_SYNC = 13, + + /** + * Uebersetzungstabelle befuellen + */ + LIO_OP_MAP = 14, +}; + +/// Flags fuer Operationen +enum lio_op_flags { + /** + * Die Operation gehoert dem Userspace, sobald sie fertig abgearbeitet ist, + * muss das Flag geloescht werden. Nachdem es geloescht worden ist, darf die + * Operation nicht mehr veraendert werden vom Userspace + */ + LIO_OPFL_USP = 1, + + /** + * Dieses Flag soll gesetzt werden, wenn beim abarbeiten der Operation ein + * Fehler aufgetreten ist. + */ + LIO_OPFL_ERROR = 2, + + /** + * Die Operation wird momentan benutzt. Sobald dieses Flag geloescht wird, + * darf die Operation wieder neu benutzt werden. + */ + LIO_OPFL_USED = 4, +}; + +struct lio_op { + /// Opcode dieser Operation + int opcode; + + /** + * Flags + * @see enum lio_op_flags + */ + volatile uint32_t flags; +} __attribute__((packed)); + +struct lio_op_load_root { + struct lio_op op; + + /// Quellhandle fuer Dateisystem oder -1 wenn keins vorhanden + lio_usp_stream_t source; + + lio_usp_tree_t tree; + + /// Ressourcennummer der Root-Ressource (rueckgabe) + lio_usp_resource_t result; +} __attribute__((packed)); + +struct lio_op_load_children { + struct lio_op op; + + /// Nummer der Ressource deren Kindressourcen geladen werden sollen + lio_usp_resource_t resource; + + /// Wert des Opaque-Felds der betreffenden Ressource + void* opaque; +} __attribute__((packed)); + +struct lio_op_read { + struct lio_op op; + + /// Nummer der Ressource deren Datenbloecke eingelesen werden sollen + lio_usp_resource_t resource; + + /// Wert des Opaque-Felds der betreffenden Ressource + void* opaque; + + /// Offset von dem an gelesen werden soll + uint64_t offset; + + /// Anzahl der zu lesenden Bytes + size_t size; + + /// Userspace-Puffer, in den gelesen werden soll + void* buf; +} __attribute__((packed)); + +struct lio_op_write { + struct lio_op op; + + /// Nummer der Ressource in die Datenblocke geschrieben werden sollen + lio_usp_resource_t resource; + + /// Groesse der Ressource + uint64_t res_size; + + /// Wert des Opaque-Felds der betreffenden Ressource + void* opaque; + + /// Offset an den geschrieben werden soll + uint64_t offset; + + /// Anzahl der zu schreibenden Bytes + size_t size; + // + /// Userspace-Puffer, der geschrieben werden soll + void* buf; +} __attribute__((packed)); + +struct lio_op_make_file { + struct lio_op op; + + /// Nummer der Elternressource + lio_usp_resource_t parent; + + /// Wert des Opaque-Feldes der Elternressource + void* opaque; + + /// Ressourcennummer der neu erstellten ressource + lio_usp_resource_t result; + + /// Name der Datei (garantiert \0 terminiert) + char name[]; +} __attribute__((packed)); + +struct lio_op_make_dir { + struct lio_op op; + + /// Nummer der Elternressource + lio_usp_resource_t parent; + + /// Wert des Opaque-Feldes der Elternressource + void* opaque; + + /// Ressourcennummer der neu erstellten ressource + lio_usp_resource_t result; + + /// Name der Datei (garantiert \0 terminiert) + char name[]; +} __attribute__((packed)); + +struct lio_op_make_symlink { + struct lio_op op; + + /// Nummer der Elternressource + lio_usp_resource_t parent; + + /// Wert des Opaque-Feldes der Elternressource + void* opaque; + + /// Laenge des gewuenschten Namens inklusive 0-Byte + size_t name_len; + + /// Ressourcennummer der neu erstellten ressource + lio_usp_resource_t result; + + /// Name des Symlinks und bei strings + name_len das target + char strings[]; +} __attribute__((packed)); + + +struct lio_op_truncate { + struct lio_op op; + + /// Nummer der Ressource deren Kindressourcen geladen werden sollen + lio_usp_resource_t resource; + + /// Wert des Opaque-Felds der betreffenden Ressource + void* opaque; + + /// Neue Dateigroesse + uint64_t size; +} __attribute__((packed)); + +struct lio_op_map { + struct lio_op op; + + /// Nummer der Ressource deren Uebersetzungstabelle befuellt werden soll + lio_usp_resource_t resource; + + /// Wert des Opaque-Felds der betreffenden Ressource + void* opaque; + + /// Start des Bereichs + uint64_t offset; + + /// Groesse des Bereichs + uint64_t size; +} __attribute__((packed)); + +struct lio_op_allocate { + struct lio_op op; + + /// Nummer der Ressource deren Blocks alloziert werden sollen + lio_usp_resource_t resource; + + /// Wert des Opaque-Felds der betreffenden Ressource + void* opaque; + + /// Start des Bereichs + uint64_t offset; + + /// Groesse des Bereichs + uint64_t size; +} __attribute__((packed)); + +struct lio_op_unlink { + struct lio_op op; + + /// Nummer der Elternressource + lio_usp_resource_t parent; + + /// Wert des Opaque-Feldes der Elternressource + void* opaque; + + /// Name der Datei (garantiert \0 terminiert) + char name[]; +} __attribute__((packed)); + +struct lio_op_pipe { + struct lio_op op; + + /// Nummer der Ressource, die geoeffnet wurde + lio_usp_resource_t res; + + /// Wert des Opaque-Felds der betreffenden Ressource + void* opaque; + + /// Stream fuer den Serverseitigen Zugriff auf die Pipe + lio_usp_stream_t pipe_end; + + /// Flags des Streams + int flags; +} __attribute__((packed)); + +struct lio_op_sync { + struct lio_op op; + + /// Nummer der Ressource, die geoeffnet wurde + lio_usp_resource_t res; + + /// Wert des Opaque-Felds der betreffenden Ressource + void* opaque; +} __attribute__((packed)); + + +/// Flags fuer Server-Ressourcen +enum lio_server_flags { + LIO_SRV_READABLE = 1, + LIO_SRV_WRITABLE = 2, + LIO_SRV_SEEKABLE = 4, + LIO_SRV_MOREDATA = 8, + LIO_SRV_BROWSABLE = 16, + LIO_SRV_CHANGEABLE = 32, + LIO_SRV_RESOLVABLE = 64, + LIO_SRV_RETARGETABLE = 128, + LIO_SRV_PIPE = 256, + LIO_SRV_TRANSLATED = 512, +}; + + +struct lio_server_resource { + /// Groesse der Ressource (als Datei/Symlink) + uint64_t size; + + /// Blockgroesse + uint32_t blocksize; + + /** + * Flags + * @see enum lio_server_flags + */ + uint32_t flags; + + /// Ressourcennummer (wird vom Kernel vergeben) + lio_usp_resource_t id; + + /// Tree-ID + lio_usp_tree_t tree; + + /** + * Private Daten des Services zu dieser Ressource, dieser Wert wird bei den + * Operationen jeweils mit angegeben. + */ + void* opaque; +} __attribute__((packed)); + #endif diff --git a/src/include/syscallno.h b/src/include/syscallno.h index 2a2f909..ad25dc3 100644 --- a/src/include/syscallno.h +++ b/src/include/syscallno.h @@ -109,14 +109,13 @@ #define SYSCALL_LIO_SYNC_ALL 99 #define SYSCALL_LIO_SRV_SERVICE_REGISTER 110 -#define SYSCALL_LIO_SRV_RES_UPLOAD 111 -#define SYSCALL_LIO_SRV_NODE_ADD 112 -#define SYSCALL_LIO_SRV_OP_DONE 113 -#define SYSCALL_LIO_SRV_WAIT 114 -#define SYSCALL_LIO_SRV_REQUEST_CACHE_BLOCKS 115 +#define SYSCALL_LIO_SRV_TREE_SET_RING 111 +#define SYSCALL_LIO_SRV_RES_UPLOAD 112 +#define SYSCALL_LIO_SRV_NODE_ADD 113 +#define SYSCALL_LIO_SRV_OP_DONE 114 +#define SYSCALL_LIO_SRV_WAIT 115 #define SYSCALL_LIO_SRV_REQUEST_TRANSLATED_BLOCKS 116 -#define SYSCALL_LIO_SRV_UNBLOCK_CACHE_BLOCKS 117 -#define SYSCALL_LIO_SRV_NODE_REMOVE 118 +#define SYSCALL_LIO_SRV_NODE_REMOVE 117 //ACHTUNG: Muss eine Zahl groesser als die Groesste Syscall-Nummer sein #define SYSCALL_MAX 125 diff --git a/src/modules/include/lostio.h b/src/modules/include/lostio.h index 066b666..1357ca3 100644 --- a/src/modules/include/lostio.h +++ b/src/modules/include/lostio.h @@ -239,6 +239,156 @@ int lio_compat_eof(io_resource_t* io_res); /// Stream-Position setzen bool lio_compat_seek(io_resource_t* io_res, uint64_t offset, int origin); + +/****************************************************************************** + * LIO2-Server * + ******************************************************************************/ + +/** + * LIO-Operationen durchfuehren, falls pendente vorhanden sind. + */ +void lio_dispatch(void); + +struct lio_tree; +struct lio_driver { + /// Root-Ressource eines Baums laden + struct lio_resource* (*load_root)(struct lio_tree* tree); + + /// Kindressoucren einer Ressource laden + int (*load_children)(struct lio_resource* res); + + /// Daten aus einer Ressource in den Cache laden + int (*read)(struct lio_resource* res, uint64_t offset, + size_t bytes, void* buf); + + /// Daten aus dem Cache in eine Ressource zurückschreiben + int (*write)(struct lio_resource* res, uint64_t offset, + size_t bytes, void* buf); + + /// Groesse einer Ressource aendern + int (*resize)(struct lio_resource* res, uint64_t size); + + /// Neue Datei erstellen + struct lio_resource* (*make_file)(struct lio_resource* parent, + const char* name); + + /// Neues Verzeichnis erstellen + struct lio_resource* (*make_dir)(struct lio_resource* parent, + const char* name); + + /// Neuen Symlink erstellen + struct lio_resource* (*make_symlink)(struct lio_resource* parent, + const char* name, const char* target); + + /// Blocktabelle einlesen + int (*map)(struct lio_resource* res, uint64_t offset, uint64_t size); + + /// Sparse-Blocks allozieren + int (*allocate)(struct lio_resource* res, uint64_t offset, uint64_t size); + + /// Verzeichniseintrag loeschen + int (*unlink)(struct lio_resource* parent, const char* name); + + /// Neue Pipe erstellen + int (*pipe)(struct lio_resource* res, lio_stream_t pipe_end, int flags); + + /// Caches zurückschreiben + int (*sync)(struct lio_resource* res); +}; + +struct lio_service { + const char* name; + struct lio_driver lio_ops; + void* opaque; + + // Intern + struct shared_ring* ring; +}; + +struct lio_node; +struct lio_tree { + struct lio_node* root; + struct lio_service* service; + lio_stream_t source; + void* opaque; + + // Intern + lio_usp_tree_t id; + tid_t service_thread; + struct shared_ring* ring; +}; + +struct lio_resource { + list_t* children; + uint64_t size; + uint32_t blocksize; + + bool readable; + bool writable; + bool seekable; + bool moredata; + bool browsable; + bool changeable; + bool resolvable; + bool retargetable; + bool ispipe; + bool translated; + + struct lio_tree* tree; + void* opaque; + + // Intern + struct lio_server_resource server; +}; + +struct lio_node { + struct lio_resource* res; + char* name; +}; + +/** + * Neuen Service registrieren + */ +int lio_add_service(struct lio_service* service); + + +/** + * Neue Ressource anlegen + */ +struct lio_resource* lio_resource_create(struct lio_tree* tree); + +/** + * Aenderungen an der Ressource publizieren + */ +void lio_resource_modified(struct lio_resource* res); + +/** + * Kindknoten einer Ressource suchen + */ +struct lio_node* lio_resource_get_child(struct lio_resource* parent, + const char* name); + +/** + * Kindknoten einer Ressource entfernen + */ +void lio_resource_remove_child(struct lio_resource* parent, + struct lio_node* child); + +/** + * Neuen Knoten anlegen und bei Elternressource als Kind eintragen. Wird NULL + * als Elternressource uebergeben, dann wird die Ressource als root in den Tree + * eingetragen. + */ +void lio_node_create(struct lio_resource* parent, struct lio_resource* res, + const char* name); + +/** + * Uebersetzte Cache-Blocks anfordern + */ +int lio_request_translated_blocks(struct lio_resource* res, uint64_t offset, + size_t num, uint64_t* translation_table); + + /** @} */ #endif diff --git a/src/modules/include/syscall.h b/src/modules/include/syscall.h index 0679631..298e737 100644 --- a/src/modules/include/syscall.h +++ b/src/modules/include/syscall.h @@ -112,6 +112,7 @@ tid_t get_tid(void); typedef lio_usp_stream_t lio_stream_t; typedef lio_usp_resource_t lio_resource_t; +typedef lio_usp_tree_t lio_tree_t; /* FIXME Duplikat von lio_usp_dir_entry in syscall_structs.h */ struct lio_dir_entry { @@ -323,4 +324,77 @@ int lio_unlink(lio_resource_t parent, const char* name); */ int lio_sync_all(void); +// LIO2-Server + +/** + * Neuen LIO-Service registrieren. + * + * @param name Service-Name + * @param buffer Zeiger auf den zu benutzenden Ringpuffer fuer die Operationen. + * Dieser sollte mit sinnvollen Werten initialisiert sein (z.B + * memset(buffer, 0, buffer_size) + * @param size Groesse des Puffers + * + * @return 0 bei Erfolg, < 0 im Fehlerfall + */ +int lio_srv_service_register(const char* name, void* buffer, size_t size); + +/** + * LIO-Befehlsring für einen gegebenen Tree einrichten + * + * @param tree ID des Trees + * @param tid TID des Threads, der den Ring abarbeitet + * @param buffer Zeiger auf den zu benutzenden Ringpuffer fuer die Operationen. + * Dieser sollte mit sinnvollen Werten initialisiert sein (z.B + * memset(buffer, 0, buffer_size) + * @param size Groesse des Puffers + * + * @return 0 bei Erfolg, < 0 im Fehlerfall + */ +int lio_srv_tree_set_ring(lio_usp_tree_t tree, tid_t tid, + void* buffer, size_t size); + +/** + * Ressource fuer Kernel bereitstellen, dabei wird der id-Member eingefuellt. + * + * @return 0 bei Erfolg, < 0 im Fehlerfall + */ +int lio_srv_res_upload(struct lio_server_resource* resource); + +/** + * Neuen Knoten erstellen. + * + * @param parent Elternressource in der der Knoten angelegt werden soll + * @param resource Ressource auf die der Knoten verweisen soll + * @param name Namen des neuen Knoten + */ +int lio_srv_node_add(lio_usp_resource_t parent, lio_usp_resource_t resource, + const char* name); + +/** + * Knoten loeschen. + * + * @param parent Elternressource in der der Kindknoten geloescht werden soll + * @param name Name des zu loeschenden Knotens + * + * @return 0 bei Erfolg, < 0 im Fehlerfall + */ +int lio_srv_node_remove(lio_usp_resource_t parent, const char* name); + +/** + * Kernel ueber abgearbeitete Operation informieren. Das USP-Bit in der + * Operation muss geloescht sein. + * + * @param op Fertig abgearbeitete Operation + * @param status 0 im Erfolg, -errno im Fehlerfall + * @param result Operationsabhaengig ein Rueckgabewert (z.B. Ressourcen-ID) + */ +void lio_srv_op_done(struct lio_op* op, int status, uint64_t result); + +/** + * Auf LIO-Operationen fuer diesen Prozess warten. Solange noch unbearbeitete + * Operationen existieren, kehrt der Aufruf sofort zurueck. + */ +void lio_srv_wait(void); + #endif diff --git a/src/modules/lib/lostio/lio_server.c b/src/modules/lib/lostio/lio_server.c new file mode 100644 index 0000000..e1b919a --- /dev/null +++ b/src/modules/lib/lostio/lio_server.c @@ -0,0 +1,499 @@ +/* + * Copyright (c) 2010 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +/** Ausstehende Operationen dieses Trees abarbeiten. */ +static void tree_dispatch(struct lio_tree* tree); + +/** Operation verarbeiten */ +static void process_op(struct lio_service* service, struct lio_op* op); + +// Operationen +static void op_load_root(struct lio_service* service, struct lio_op* op); +static void op_load_children(struct lio_service* service, struct lio_op* op); +static void op_read(struct lio_service* service, struct lio_op* op); +static void op_write(struct lio_service* service, struct lio_op* op); +static void op_make_file(struct lio_service* service, struct lio_op* op); +static void op_make_dir(struct lio_service* service, struct lio_op* op); +static void op_make_symlink(struct lio_service* service, struct lio_op* op); +static void op_truncate(struct lio_service* service, struct lio_op* op); +static void op_map(struct lio_service* service, struct lio_op* op); +static void op_allocate(struct lio_service* service, struct lio_op* op); +static void op_unlink(struct lio_service* service, struct lio_op* op); +static void op_pipe(struct lio_service* service, struct lio_op* op); +static void op_sync(struct lio_service* service, struct lio_op* op); + + +static list_t* services = NULL; + +void lio_dispatch(void) +{ + struct lio_service* s; + int i; + + for (i = 0; (s = list_get_element_at(services, i)); i++) { + void* buf; + struct lio_op* op; + ssize_t size; + + while (1) { + size = ring_read_ptr(s->ring, &buf); + if (size <= 0) { + break; + } + + op = buf; + switch (op->opcode) { + case LIO_OP_NOP: + lio_srv_op_done(op, 0, 0); + break; + + case LIO_OP_LOAD_ROOT: + op_load_root(s, op); + break; + + default: + printf("lio_dispatch: Fehler, unerwarteter Opcode 0x%x\n", + op->opcode); + op->flags |= LIO_OPFL_ERROR; + break; + } + + ring_read_complete(s->ring); + } + } +} + +/** + * Ausstehende Operationen dieses Trees abarbeiten. + */ +static void tree_dispatch(struct lio_tree* tree) +{ + void* buf; + struct lio_op* op; + ssize_t size; + + while (1) { + while (1) { + size = ring_read_ptr(tree->ring, &buf); + if (size <= 0) { + break; + } + + op = buf; + process_op(tree->service, op); + + ring_read_complete(tree->ring); + } + lio_srv_wait(); + } +} + +/** + * Operation verarbeiten + */ +static void process_op(struct lio_service* service, struct lio_op* op) +{ + switch (op->opcode) { + case LIO_OP_NOP: + lio_srv_op_done(op, 0, 0); + break; + + case LIO_OP_LOAD_CHILDREN: + op_load_children(service, op); + break; + + case LIO_OP_READ: + op_read(service, op); + break; + + case LIO_OP_WRITE: + op_write(service, op); + break; + + case LIO_OP_MAKE_FILE: + op_make_file(service, op); + break; + + case LIO_OP_MAKE_DIR: + op_make_dir(service, op); + break; + + case LIO_OP_MAKE_SYMLINK: + op_make_symlink(service, op); + break; + + case LIO_OP_TRUNCATE: + op_truncate(service, op); + break; + + case LIO_OP_MAP: + op_map(service, op); + break; + + case LIO_OP_ALLOCATE: + op_allocate(service, op); + break; + + case LIO_OP_UNLINK: + op_unlink(service, op); + break; + + case LIO_OP_PIPE: + op_pipe(service, op); + break; + + case LIO_OP_SYNC: + op_sync(service, op); + break; + + default: + printf("process_op: Fehler, unerwarteter Opcode 0x%x\n", + op->opcode); + op->flags |= LIO_OPFL_ERROR; + break; + } + + op->flags &= ~LIO_OPFL_USP; +} + +static void op_load_root(struct lio_service* service, struct lio_op* op) +{ + struct lio_op_load_root* olr = (struct lio_op_load_root*) op; + struct lio_resource* res; + struct lio_tree* tree; + + tree = calloc(sizeof(*tree), 1); + tree->service = service; + tree->source = olr->source; + tree->id = olr->tree; + + res = service->lio_ops.load_root(tree); + + if (res) { + void* buf; + size_t buf_size = 4096; + + buf = mem_allocate(buf_size, 0); + memset(buf, 0, buf_size); + tree->ring = ring_init_reader(buf, buf_size); + + // FIXME: Den richtigen Namen des Root-Knotens brauchen wir hier noch + // vom Kernel + lio_node_create(NULL, res, "/"); + tree->service_thread = create_thread((uint32_t) tree_dispatch, tree); + + lio_srv_tree_set_ring(tree->id, tree->service_thread, buf, buf_size); + lio_srv_op_done(op, 0, res->server.id); + } else { + free(tree); + lio_srv_op_done(op, -EIO, 0); + } +} + +static void op_load_children(struct lio_service* service, struct lio_op* op) +{ + struct lio_op_load_children* olc = (struct lio_op_load_children*) op; + struct lio_resource* res = (struct lio_resource*) olc->opaque; + int ret; + + ret = service->lio_ops.load_children(res); + lio_srv_op_done(op, ret, 0); +} + +static void op_read(struct lio_service* service, struct lio_op* op) +{ + struct lio_op_read* or = (struct lio_op_read*) op; + struct lio_resource* res = (struct lio_resource*) or->opaque; + int ret; + + ret = service->lio_ops.read(res, or->offset, or->size, or->buf); + lio_srv_op_done(op, ret, 0); +} + +static void op_write(struct lio_service* service, struct lio_op* op) +{ + struct lio_op_write* ow = (struct lio_op_write*) op; + struct lio_resource* res = (struct lio_resource*) ow->opaque; + int ret; + + if (res->size != ow->res_size) { + service->lio_ops.resize(res, ow->res_size); + } + + ret = service->lio_ops.write(res, ow->offset, ow->size, ow->buf); + lio_srv_op_done(op, ret, 0); +} + +static void op_make_file(struct lio_service* service, struct lio_op* op) +{ + struct lio_op_make_file* omf = (struct lio_op_make_file*) op; + struct lio_resource* parent = (struct lio_resource*) omf->opaque; + struct lio_resource* res; + + res = service->lio_ops.make_file(parent, omf->name); + + if (res == NULL) { + lio_srv_op_done(op, -EIO, 0); + } else { + lio_srv_op_done(op, 0, res->server.id); + } +} + +static void op_make_dir(struct lio_service* service, struct lio_op* op) +{ + struct lio_op_make_dir* omd = (struct lio_op_make_dir*) op; + struct lio_resource* parent = (struct lio_resource*) omd->opaque; + struct lio_resource* res; + + res = service->lio_ops.make_dir(parent, omd->name); + + if (res == NULL) { + lio_srv_op_done(op, -EIO, 0); + } else { + lio_srv_op_done(op, 0, res->server.id); + } +} + +static void op_make_symlink(struct lio_service* service, struct lio_op* op) +{ + struct lio_op_make_symlink* oms = (struct lio_op_make_symlink*) op; + struct lio_resource* parent = (struct lio_resource*) oms->opaque; + struct lio_resource* res; + + res = service->lio_ops.make_symlink(parent, oms->strings, + oms->strings + oms->name_len); + + if (res == NULL) { + lio_srv_op_done(op, -EIO, 0); + } else { + lio_srv_op_done(op, 0, res->server.id); + } +} + +static void op_truncate(struct lio_service* service, struct lio_op* op) +{ + struct lio_op_truncate* ot = (struct lio_op_truncate*) op; + struct lio_resource* res = (struct lio_resource*) ot->opaque; + int ret; + + if (service->lio_ops.resize) { + ret = service->lio_ops.resize(res, ot->size); + } else { + ret = -EINVAL; + } + + lio_srv_op_done(op, ret, 0); +} + +static void op_map(struct lio_service* service, struct lio_op* op) +{ + struct lio_op_map* om = (struct lio_op_map*) op; + struct lio_resource* res = (struct lio_resource*) om->opaque; + int ret; + + if (service->lio_ops.map) { + ret = service->lio_ops.map(res, om->offset, om->size); + } else { + ret = -EINVAL; + } + + lio_srv_op_done(op, ret, 0); +} + +static void op_allocate(struct lio_service* service, struct lio_op* op) +{ + struct lio_op_allocate* oa = (struct lio_op_allocate*) op; + struct lio_resource* res = (struct lio_resource*) oa->opaque; + int ret; + + if (service->lio_ops.allocate) { + ret = service->lio_ops.allocate(res, oa->offset, oa->size); + } else { + ret = -EINVAL; + } + + lio_srv_op_done(op, ret, 0); +} + +static void op_unlink(struct lio_service* service, struct lio_op* op) +{ + struct lio_op_unlink* oul = (struct lio_op_unlink*) op; + struct lio_resource* parent = (struct lio_resource*) oul->opaque; + int ret; + + ret = service->lio_ops.unlink(parent, oul->name); + lio_srv_op_done(op, ret, 0); +} + +static void op_pipe(struct lio_service* service, struct lio_op* op) +{ + struct lio_op_pipe* opi = (struct lio_op_pipe*) op; + struct lio_resource* res = (struct lio_resource*) opi->opaque; + int ret; + + ret = service->lio_ops.pipe(res, opi->pipe_end, opi->flags); + lio_srv_op_done(op, ret, 0); +} + +static void op_sync(struct lio_service* service, struct lio_op* op) +{ + struct lio_op_sync* ops = (struct lio_op_sync*) op; + struct lio_resource* res = (struct lio_resource*) ops->opaque; + int ret = 0; + + if (service->lio_ops.sync) { + ret = service->lio_ops.sync(res); + } + lio_srv_op_done(op, ret, 0); +} + +/** + * Neuen Service registrieren + */ +int lio_add_service(struct lio_service* service) +{ + void* buf; + size_t buf_size = 4096; + + if (!services) { + services = list_create(); + } + + buf = mem_allocate(buf_size, 0); + memset(buf, 0, buf_size); + service->ring = ring_init_reader(buf, buf_size); + + list_push(services, service); + + return lio_srv_service_register(service->name, buf, buf_size); +} + +/** + * Neue Ressource anlegen + */ +struct lio_resource* lio_resource_create(struct lio_tree* tree) +{ + struct lio_resource* res = calloc(sizeof(*res), 1); + res->tree = tree; + return res; +} + +/** + * Aenderungen an der Ressource publizieren + */ +void lio_resource_modified(struct lio_resource* res) +{ + res->server.size = res->size; + res->server.blocksize = res->blocksize; + res->server.flags = + (res->readable ? LIO_SRV_READABLE : 0) | + (res->writable ? LIO_SRV_WRITABLE : 0) | + (res->seekable ? LIO_SRV_SEEKABLE : 0) | + (res->moredata ? LIO_SRV_MOREDATA : 0) | + (res->browsable ? LIO_SRV_BROWSABLE : 0) | + (res->changeable ? LIO_SRV_CHANGEABLE : 0) | + (res->resolvable ? LIO_SRV_RESOLVABLE : 0) | + (res->retargetable ? LIO_SRV_RETARGETABLE : 0) | + (res->ispipe ? LIO_SRV_PIPE : 0) | + (res->translated ? LIO_SRV_TRANSLATED : 0); + res->server.tree = res->tree->id; + res->server.opaque = res; + + lio_srv_res_upload(&res->server); +} + +/** + * Neuen Knoten anlegen und bei Elternressource als Kind eintragen. Wird NULL + * als Elternressource uebergeben, dann wird die Ressource als root in den Tree + * eingetragen. + */ +void lio_node_create(struct lio_resource* parent, struct lio_resource* res, + const char* name) +{ + struct lio_node* node; + + node = malloc(sizeof(*node)); + node->res = res; + node->name = strdup(name); + + if (!parent) { + res->tree->root = node; + } else { + if (!parent->children) { + parent->children = list_create(); + } + list_push(parent->children, node); + + lio_srv_node_add(parent->server.id, res->server.id, name); + } + +} + +/** + * Kindknoten einer Ressource suchen + */ +struct lio_node* lio_resource_get_child(struct lio_resource* parent, + const char* name) +{ + struct lio_node* node; + size_t i; + + for (i = 0; (node = list_get_element_at(parent->children, i)); i++) { + if (!strcmp(node->name, name)) { + return node; + } + } + + return NULL; +} + +/** + * Kindknoten einer Ressource entfernen + */ +void lio_resource_remove_child(struct lio_resource* parent, + struct lio_node* child) +{ + lio_srv_node_remove(parent->server.id, child->name); +} diff --git a/src/modules/lib/syscalls/lio_server.c b/src/modules/lib/syscalls/lio_server.c new file mode 100644 index 0000000..6079f53 --- /dev/null +++ b/src/modules/lib/syscalls/lio_server.c @@ -0,0 +1,204 @@ +/* + * Copyright (c) 2010 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +/** + * Neuen LIO-Service registrieren. + * + * @param name Service-Name + * @param buffer Zeiger auf den zu benutzenden Ringpuffer fuer die Operationen. + * Dieser sollte mit sinnvollen Werten initialisiert sein (z.B + * memset(buffer, 0, buffer_size) + * @param size Groesse des Puffers + * + * @return 0 bei Erfolg, < 0 im Fehlerfall + */ +int lio_srv_service_register(const char* name, void* buffer, size_t size) +{ + int result; + size_t name_len; + + name_len = strlen(name); + asm volatile( + "pushl %5;" + "pushl %4;" + "pushl %3;" + "pushl %2;" + "mov %1, %%eax;" + "int $0x30;" + "add $0x10, %%esp;" + : "=a" (result) + : "i" (SYSCALL_LIO_SRV_SERVICE_REGISTER), "r" (name), "r" (name_len), + "r" (buffer), "r" (size)); + + return result; +} + +/** + * LIO-Befehlsring für einen gegebenen Tree einrichten + * + * @param tree ID des Trees + * @param tid TID des Threads, der den Ring abarbeitet + * @param buffer Zeiger auf den zu benutzenden Ringpuffer fuer die Operationen. + * Dieser sollte mit sinnvollen Werten initialisiert sein (z.B + * memset(buffer, 0, buffer_size) + * @param size Groesse des Puffers + * + * @return 0 bei Erfolg, < 0 im Fehlerfall + */ +int lio_srv_tree_set_ring(lio_usp_tree_t tree, tid_t tid, + void* buffer, size_t size) +{ + int result; + + asm volatile( + "pushl %5;" + "pushl %4;" + "pushl %3;" + "pushl %2;" + "mov %1, %%eax;" + "int $0x30;" + "add $0x10, %%esp;" + : "=a" (result) + : "i" (SYSCALL_LIO_SRV_TREE_SET_RING), "r" (&tree), + "r" (tid), "r" (buffer), "r" (size) : "memory"); + + return result; +} + +/** + * Ressource fuer Kernel bereitstellen, dabei wird der id-Member eingefuellt. + * + * @return 0 bei Erfolg, < 0 im Fehlerfall + */ +int lio_srv_res_upload(struct lio_server_resource* resource) +{ + int result; + + asm volatile( + "pushl %2;" + "mov %1, %%eax;" + "int $0x30;" + "add $0x4, %%esp;" + : "=a" (result) + : "i" (SYSCALL_LIO_SRV_RES_UPLOAD), "r" (resource)); + + return result; +} + +/** + * Neuen Knoten erstellen. + * + * @param parent Elternressource in der der Knoten angelegt werden soll + * @param resource Ressource auf die der Knoten verweisen soll + * @param name Namen des neuen Knoten + */ +int lio_srv_node_add(lio_usp_resource_t parent, lio_usp_resource_t resource, + const char* name) +{ + int result; + size_t name_len; + + name_len = strlen(name); + asm volatile( + "pushl %5;" + "pushl %4;" + "pushl %3;" + "pushl %2;" + "mov %1, %%eax;" + "int $0x30;" + "add $0x10, %%esp;" + : "=a" (result) + : "i" (SYSCALL_LIO_SRV_NODE_ADD), "r" (&parent), "r" (&resource), + "r" (name), "r" (name_len) : "memory"); + + return result; +} + +/** + * Knoten loeschen. + * + * @param parent Elternressource in der der Kindknoten geloescht werden soll + * @param name Name des zu loeschenden Knotens + * + * @return 0 bei Erfolg, < 0 im Fehlerfall + */ +int lio_srv_node_remove(lio_usp_resource_t parent, const char* name) +{ + int result; + size_t name_len; + + name_len = strlen(name); + asm volatile( + "pushl %4;" + "pushl %3;" + "pushl %2;" + "mov %1, %%eax;" + "int $0x30;" + "add $0xc, %%esp;" + : "=a" (result) + : "i" (SYSCALL_LIO_SRV_NODE_REMOVE), "r" (&parent), "r" (name), + "r" (name_len) : "memory"); + + return result; + +} + +/** + * Kernel ueber abgearbeitete Operation informieren. Das USP-Bit in der + * Operation muss geloescht sein. + * + * @param op Fertig abgearbeitete Operation + */ +void lio_srv_op_done(struct lio_op* op, int status, uint64_t result) +{ + asm volatile( + "pushl %3;" + "pushl %2;" + "pushl %1;" + "mov %0, %%eax;" + "int $0x30;" + "add $0x0c, %%esp;" + : : "i" (SYSCALL_LIO_SRV_OP_DONE), + "r" (op), "r" (status), "r" (&result) + : "memory"); +} + +/** + * Auf LIO-Operationen fuer diesen Prozess warten. Solange noch unbearbeitete + * Operationen existieren, kehrt der Aufruf sofort zurueck. + */ +void lio_srv_wait(void) +{ + asm volatile( + "mov %0, %%eax;" + "int $0x30;" + :: "i" (SYSCALL_LIO_SRV_WAIT)); +} -- 1.7.7 From kevin at tyndur.org Fri Jan 3 01:26:51 2014 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 3 Jan 2014 01:26:51 +0100 Subject: [tyndur-devel] [PATCH 09/11] kernel2: LIOv2-Server im Userspace In-Reply-To: <1388708813-23390-1-git-send-email-kevin@tyndur.org> References: <1388708813-23390-1-git-send-email-kevin@tyndur.org> Message-ID: <1388708813-23390-10-git-send-email-kevin@tyndur.org> + kernel2: Ein neuer LIOv2-Pseudoservice im Kernel, der in Wirklichkeit nur alle Requests in einen Ringpuffer für den Userspace-Server schreibt und Syscalls für diesen bereitstellt, um Ergebnisse zurückzumelden und Ressourcen im Kernel zu modifizieren (z.B. neue Dateien in den Verzeichnisbaum laden) Signed-off-by: Kevin Wolf --- src/kernel2/include/syscall.h | 30 + src/kernel2/include/tasks.h | 9 +- src/kernel2/src/lostio/include/lostio_int.h | 3 + src/kernel2/src/syscall.c | 12 + src/kernel2/src/syscalls/lio_server.c | 810 +++++++++++++++++++++++++++ src/kernel2/src/syscalls/rpc.c | 4 +- src/kernel2/src/tasks/thread.c | 4 +- 7 files changed, 869 insertions(+), 3 deletions(-) create mode 100644 src/kernel2/src/syscalls/lio_server.c diff --git a/src/kernel2/include/syscall.h b/src/kernel2/include/syscall.h index 51f0ff1..4ac87d0 100644 --- a/src/kernel2/include/syscall.h +++ b/src/kernel2/include/syscall.h @@ -250,6 +250,36 @@ int syscall_lio_unlink(lio_usp_resource_t* parent, const char* name, /// Alle Blocks rausschreiben, die sich im Cache befinden int syscall_lio_sync_all(int soft); +// LIO-Server +/// Neuen lio-Service registrieren +int syscall_lio_srv_service_register(const char* name, size_t name_len, + void* buffer, size_t size); + +/// Neuen Tree-Ring registrieren +int syscall_lio_srv_tree_set_ring(lio_usp_tree_t* tree_id, tid_t tid, + void* buffer, size_t size); + +/// Ressource fuer Kernel bereitstellen +int syscall_lio_srv_res_upload(struct lio_server_resource* resource); + +/// Neuen Knoten erstellen +int syscall_lio_srv_node_add(lio_usp_resource_t* parent, + lio_usp_resource_t* resource, const char* name, size_t name_len); + +/// Knoten loeschen +int syscall_lio_srv_node_remove(lio_usp_resource_t* parent, const char* name, + size_t name_len); + +/// Kernel ueber abgearbeitete Operation informieren +void syscall_lio_srv_op_done(struct lio_op* op, int status, uint64_t* result); + +/// Auf LIO-Operationen fuer diesen Prozess warten +void syscall_lio_srv_wait(void); + +/// Cache-Blocks mit Uebersetzungstabelle anfordern +int syscall_lio_srv_request_translated_blocks(lio_usp_resource_t* res, + uint64_t* offset, size_t num, uint64_t* table); + // Diverse /// Textausgabe ueber den Kernel diff --git a/src/kernel2/include/tasks.h b/src/kernel2/include/tasks.h index d4096bb..e17d22b 100644 --- a/src/kernel2/include/tasks.h +++ b/src/kernel2/include/tasks.h @@ -50,6 +50,8 @@ #define PM_STATUS_BLOCKED 1 #define PM_STATUS_RUNNING 2 #define PM_STATUS_WAIT_FOR_RPC 3 +#define PM_STATUS_WAIT_FOR_LIO 4 +#define PM_STATUS_WAIT_FOR_IO_REQUEST 5 typedef struct pm_process { /// Die eindeutige Prozessnummer @@ -110,7 +112,6 @@ typedef struct pm_process { /// Baum aller geoeffneten LostIO-Streams tree_t* lio_streams; - } pm_process_t; typedef struct { @@ -152,6 +153,12 @@ typedef struct { * aufgerufen werden */ list_t* on_destroy; + + /// Eine Liste der von diesem Thread angebotenen LIO-Services + list_t* lio_services; + + /// Eine Liste aller LIO-Trees, deren Ring dieser Thread verarbeitet + list_t* lio_trees; } pm_thread_t; typedef void (*pm_process_destroy_handler)(pm_process_t* process, void* prv); diff --git a/src/kernel2/src/lostio/include/lostio_int.h b/src/kernel2/src/lostio/include/lostio_int.h index b84bc13..a8d112a 100644 --- a/src/kernel2/src/lostio/include/lostio_int.h +++ b/src/kernel2/src/lostio/include/lostio_int.h @@ -197,6 +197,9 @@ struct lio_tree { lio_usp_tree_t usp_id; struct tree_item usp_item; + + /** Private Daten des Services */ + void* opaque; }; diff --git a/src/kernel2/src/syscall.c b/src/kernel2/src/syscall.c index b6b06c5..a5eda73 100644 --- a/src/kernel2/src/syscall.c +++ b/src/kernel2/src/syscall.c @@ -124,6 +124,18 @@ void syscall_init() syscall_register(SYSCALL_LIO_UNLINK, &syscall_lio_unlink, 3); syscall_register(SYSCALL_LIO_SYNC_ALL, &syscall_lio_sync_all, 0); + syscall_register(SYSCALL_LIO_SRV_SERVICE_REGISTER, + &syscall_lio_srv_service_register, 4); + syscall_register(SYSCALL_LIO_SRV_TREE_SET_RING, + &syscall_lio_srv_tree_set_ring, 4); + syscall_register(SYSCALL_LIO_SRV_RES_UPLOAD, + &syscall_lio_srv_res_upload, 1); + syscall_register(SYSCALL_LIO_SRV_NODE_ADD, &syscall_lio_srv_node_add, 4); + syscall_register(SYSCALL_LIO_SRV_NODE_REMOVE, + &syscall_lio_srv_node_remove, 3); + syscall_register(SYSCALL_LIO_SRV_OP_DONE, &syscall_lio_srv_op_done, 3); + syscall_register(SYSCALL_LIO_SRV_WAIT, &syscall_lio_srv_wait, 0); + syscalls[KERN_SYSCALL_PM_SLEEP] = (syscall_t) { .handler = &kern_syscall_pm_sleep, .arg_count = 2, diff --git a/src/kernel2/src/syscalls/lio_server.c b/src/kernel2/src/syscalls/lio_server.c new file mode 100644 index 0000000..5a7e6a9 --- /dev/null +++ b/src/kernel2/src/syscalls/lio_server.c @@ -0,0 +1,810 @@ +/* + * Copyright (c) 2010 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include "kernel.h" +#include "kprintf.h" +#include "tasks.h" +#include "lostio/userspace.h" +#include "../lostio/include/lostio_int.h" +#include "syscall.h" +#include "mm.h" + +/// Eintraege in der usp_mapped_blocks Liste der Services +struct cache_block_handle { + uint64_t offset; + size_t num; + void* mapped; +}; + +static struct lio_resource* load_root(struct lio_tree* tree); +static int load_children(struct lio_resource* res); +static int read(struct lio_resource* res, uint64_t offset, + size_t bytes, void* buf); +static int write(struct lio_resource* res, uint64_t offset, + size_t bytes, void* buf); +static int sync(struct lio_resource* res); +static struct lio_resource* make_file(struct lio_resource* parent, + const char* name); +static struct lio_resource* make_dir(struct lio_resource* parent, + const char* name); +static struct lio_resource* make_symlink(struct lio_resource* parent, + const char* name, const char* target); +static int truncate(struct lio_resource* res, uint64_t size); +static int unlink(struct lio_resource* parent, const char* name); + +struct lio_pending_op { + struct tree_item tinfo; + pm_thread_t* caller; + uint64_t op_addr; + int* status; + uint64_t* result; +}; + +struct lio_ring { + struct shared_ring* ring; + uintptr_t kern_base; + uintptr_t usp_base; + tree_t* pending; +}; + +struct lio_userspace_service { + struct lio_ring ring; + + /** Prozess des Services */ + pm_thread_t* provider; +}; + +struct lio_userspace_tree { + struct lio_ring ring; + pm_thread_t* thread; +}; + +static void service_on_thread_destroy(pm_thread_t* thread, void* prv) +{ + struct lio_service* s; + + while ((s = list_pop(thread->lio_services))) { + struct lio_userspace_service* us = s->opaque; + us->provider = NULL; + } + + list_destroy(thread->lio_services); +} + +static void tree_on_thread_destroy(pm_thread_t* thread, void* prv) +{ + struct lio_tree* t; + + while ((t = list_pop(thread->lio_trees))) { + struct lio_userspace_tree* ut = t->opaque; + if (ut) { + t->opaque = NULL; + free(ut); + } + } + + list_destroy(thread->lio_trees); +} + +/// Neuen lio-Service registrieren +int syscall_lio_srv_service_register(const char* name, size_t name_len, + void* buffer, size_t size) +{ + struct lio_service* service; + struct lio_userspace_service* s; + list_t* services; + void* buf; + + service = calloc(sizeof(*service), 1); + + // TODO: Ein paar is_userspace + service->name = strdup(name); + service->lio_ops.load_root = load_root; + service->lio_ops.load_children = load_children; + service->lio_ops.read = read; + service->lio_ops.write = write; + service->lio_ops.make_file = make_file; + service->lio_ops.make_dir = make_dir; + service->lio_ops.make_symlink = make_symlink; + service->lio_ops.truncate = truncate; + service->lio_ops.unlink = unlink; + service->lio_ops.sync = sync; + + buf = mmc_automap_user(&mmc_current_context(), + &mmc_current_context(), buffer, NUM_PAGES(size), KERNEL_MEM_START, + KERNEL_MEM_END, MM_FLAGS_KERNEL_DATA); + + + s = malloc(sizeof(*s)); + *s = (struct lio_userspace_service) { + .provider = current_thread, + .ring = (struct lio_ring) { + .ring = ring_init_writer(buf, size), + .kern_base = (uintptr_t) buf, + .usp_base = (uintptr_t) buffer, + .pending = tree_create(struct lio_pending_op, tinfo, op_addr), + }, + }; + + service->opaque = s; + + lio_add_service(service); + + services = current_thread->lio_services; + if (!services) { + services = current_thread->lio_services = list_create(); + pm_thread_register_on_destroy(current_thread, + service_on_thread_destroy, NULL); + } + list_push(services, service); + + return 0; +} + +/// Neuen Tree-Ring registrieren +int syscall_lio_srv_tree_set_ring(lio_usp_tree_t* ptree_id, tid_t tid, + void* buffer, size_t size) +{ + lio_usp_tree_t tree_id; + struct lio_tree* tree; + struct lio_userspace_tree* t; + pm_thread_t* thread; + void* buf; + + // TODO is_userspace + tree_id = *ptree_id; + + thread = pm_thread_get(current_process, tid); + if (thread == NULL) { + return -EINVAL; + } + + tree = lio_usp_get_tree(tree_id); + if (tree == NULL) { + return -EBADF; + } + + // TODO: Ein paar is_userspace + if ((uintptr_t) buffer & (PAGE_SIZE - 1)) { + return -EINVAL; + } + buf = mmc_automap_user(&mmc_current_context(), + &mmc_current_context(), buffer, NUM_PAGES(size), KERNEL_MEM_START, + KERNEL_MEM_END, MM_FLAGS_KERNEL_DATA); + + + t = malloc(sizeof(*t)); + *t = (struct lio_userspace_tree) { + .thread = thread, + .ring = { + .ring = ring_init_writer(buf, size), + .kern_base = (uintptr_t) buf, + .usp_base = (uintptr_t) buffer, + .pending = tree_create(struct lio_pending_op, tinfo, op_addr), + }, + }; + + tree->opaque = t; + + if (!thread->lio_trees) { + thread->lio_trees = list_create(); + pm_thread_register_on_destroy(thread, tree_on_thread_destroy, NULL); + } + list_push(thread->lio_trees, tree); + + return 0; +} + +static inline bool is_power_of_two(size_t n) +{ + return !(n & (n - 1)); +} + +/// Ressource fuer Kernel bereitstellen +int syscall_lio_srv_res_upload(struct lio_server_resource* resource) +{ + struct lio_resource* res; + bool translated = ((resource->flags & LIO_SRV_TRANSLATED) ? 1 : 0); + + // TODO: is_userspace + if (resource->id) { + res = lio_usp_get_resource(resource->id); + } else { + res = lio_create_resource(); + resource->id = res->usp_id; + } + + if (!res) { + return -1; + } + + /* Die Blockgroesse muss ein Zweierpotenz sein */ + if (!is_power_of_two(resource->blocksize)) { + return -EINVAL; + } + + res->tree = lio_usp_get_tree(resource->tree); + res->size = resource->size; + res->blocksize = resource->blocksize; + res->readable = ((resource->flags & LIO_SRV_READABLE) ? 1 : 0); + res->writable = ((resource->flags & LIO_SRV_WRITABLE) ? 1 : 0); + res->seekable = ((resource->flags & LIO_SRV_SEEKABLE) ? 1 : 0); + res->moredata = ((resource->flags & LIO_SRV_MOREDATA) ? 1 : 0); + res->browsable = ((resource->flags & LIO_SRV_BROWSABLE) ? 1 : 0); + res->changeable = ((resource->flags & LIO_SRV_CHANGEABLE) ? 1 : 0); + res->resolvable = ((resource->flags & LIO_SRV_RESOLVABLE) ? 1 : 0); + res->retargetable = ((resource->flags & LIO_SRV_RETARGETABLE) ? 1 : 0); + res->ispipe = ((resource->flags & LIO_SRV_PIPE) ? 1 : 0); + if (translated) { + return -EINVAL; + } + res->opaque = resource->opaque; + + return 0; +} + +/// Neuen Knoten erstellen +int syscall_lio_srv_node_add(lio_usp_resource_t* parent, + lio_usp_resource_t* resource, const char* name, size_t name_len) +{ + struct lio_resource* par; + struct lio_resource* res; + + // TODO: Ein paar is_userspace + par = lio_usp_get_resource(*parent); + res = lio_usp_get_resource(*resource); + + if (!par || !res) { + return -1; + } + + lio_create_node(par, res, name); + + return 0; +} + +/// Knoten loeschen +int syscall_lio_srv_node_remove(lio_usp_resource_t* parent, const char* name, + size_t name_len) +{ + struct lio_resource* par; + struct lio_node* node; + + // TODO: Ein paar is_userspace + par = lio_usp_get_resource(*parent); + if (!par || !(node = lio_resource_get_child(par, name))) { + return -1; + } + + lio_resource_remove_child(par, node); + return 0; +} + +static void op_done(struct lio_op* op, tree_t* pending_ops, + int status, uint64_t result) +{ + struct lio_pending_op* pending; + + pending = tree_search(pending_ops, (uint64_t)(uintptr_t) op); + if (pending != NULL) { + *pending->status = status; + if (pending->result) { + *pending->result = result; + } + + if (pending->caller->status == PM_STATUS_WAIT_FOR_IO_REQUEST) { + pending->caller->status = PM_STATUS_READY; + } else { + panic("LIO-Request beendet fuer Thread, der gar nicht wartet"); + } + + tree_remove(pending_ops, pending); + free(pending); + } +} + +/// Kernel ueber abgearbeitete Operation informieren +void syscall_lio_srv_op_done(struct lio_op* op, int status, uint64_t* result) +{ + + struct lio_service* serv; + struct lio_userspace_service* s; + struct lio_tree* tree; + struct lio_userspace_tree* t; + int i; + + for (i = 0; + (serv = list_get_element_at(current_thread->lio_services, i)); + i++) + { + s = serv->opaque; + // TODO is_userspace + op_done(op, s->ring.pending, status, *result); + } + + for (i = 0; + (tree = list_get_element_at(current_thread->lio_trees, i)); + i++) + { + t = tree->opaque; + // TODO is_userspace + op_done(op, t->ring.pending, status, *result); + } +} + +/** + * Prueft ob der Prozess noch abzuarbeitende LIO-Operationen hat. + * + * @return 1 wenn ja, 0 sonst + */ +bool has_ops_todo(void) +{ + size_t i; + struct lio_service* s; + struct lio_userspace_service* us; + struct lio_tree* t; + struct lio_userspace_tree* ut; + + for (i = 0; (s = list_get_element_at(current_thread->lio_services, i)); i++) { + us = s->opaque; + if (!ring_empty(us->ring.ring)) { + return true; + } + } + + for (i = 0; (t = list_get_element_at(current_thread->lio_trees, i)); i++) { + ut = t->opaque; + if (!ring_empty(ut->ring.ring)) { + return true; + } + } + + return false; +} + +/// Auf LIO-Operationen fuer diesen Prozess warten +void syscall_lio_srv_wait(void) +{ + if (has_ops_todo()) { + return; + } + + pm_scheduler_push(current_thread); + current_thread->status = PM_STATUS_WAIT_FOR_LIO; + current_thread = pm_scheduler_pop(); +} + +/** + * Sucht ein Plaetzchen fuer eine Operation der angegebenen Groesse. Die + * Operation wird als NOP mit der passenden Groesse und USED als Flags + * initialisiert. + */ +static struct lio_op* alloc_ring_op(struct lio_ring* ring, size_t size) +{ + struct lio_op* op; + void* buf; + int ret; + + ret = ring_write_ptr(ring->ring, &buf, size); + + while (ret == -EBUSY) { + pm_scheduler_yield(); + ret = ring_write_ptr(ring->ring, &buf, size); + } + + op = buf; + op->flags = LIO_OPFL_USED; + + return op; +} + +static struct lio_op* alloc_op(struct lio_resource* res, size_t size) +{ + struct lio_tree* tree = res->tree; + struct lio_userspace_tree* t = tree->opaque; + struct lio_service* serv = tree->service; + struct lio_userspace_service* s = serv->opaque; + + if (t == NULL || s->provider == NULL) { + return NULL; + } + + return alloc_ring_op(&t->ring, size); +} + +/** + * Entsperrt alle Threads die auf LIO-Operationen warten im angegebenen Prozess + * und setzt den Ringzeiger weiter. + */ +static int commit_ring_op(struct lio_ring* ring, pm_thread_t* thread, + struct lio_op* op, uint64_t* result) +{ + struct lio_pending_op *pending; + int ret, status; + + /* Operation in den Ring schreiben */ + ret = ring_write_complete(ring->ring); + if (ret < 0) { + panic("ring_write_complete fehlgeschlagen"); + } + + /* Service wieder laufen lassen, wenn er auf Requests wartet */ + if (thread->status == PM_STATUS_WAIT_FOR_LIO) { + thread->status = PM_STATUS_READY; + } + + /* Warten, bis der Request fertig ist */ + status = LIO_OPFL_USED; + + pending = malloc(sizeof(*pending)); + *pending = (struct lio_pending_op) { + .caller = current_thread, + .op_addr = (uintptr_t) op - ring->kern_base + ring->usp_base, + .status = &status, + .result = result, + }; + tree_insert(ring->pending, pending); + + while (status == LIO_OPFL_USED) { + pm_scheduler_kern_yield(thread->tid, PM_STATUS_WAIT_FOR_IO_REQUEST); + } + + return status; +} + +static int commit_op(struct lio_resource* res, struct lio_op* op, + uint64_t* result) +{ + struct lio_tree* tree = res->tree; + struct lio_userspace_tree* t = tree->opaque; + struct lio_userspace_service* s = tree->service->opaque; + + if (s->provider == NULL) { + return -EBADF; + } + + if (t == NULL) { + /* Noch nicht initialisiert */ + return -EBUSY; + } + + return commit_ring_op(&t->ring, t->thread, op, result); +} + +static struct lio_resource* load_root(struct lio_tree* tree) +{ + struct lio_resource* res = NULL; + struct lio_op_load_root* olr; + struct lio_service* serv = tree->service; + struct lio_userspace_service* s = serv->opaque; + uint64_t result; + int ret; + + if (s->provider == NULL) { + return NULL; + } + + olr = (struct lio_op_load_root*) alloc_ring_op(&s->ring, sizeof(*olr)); + + olr->op.opcode = LIO_OP_LOAD_ROOT; + olr->tree = tree->usp_id; + olr->op.flags |= LIO_OPFL_USP; + + /* FIXME Beim Unmount wieder freigeben */ + olr->source = -1; + if (tree->source) { + struct lio_usp_stream* fd = + lio_usp_add_stream(s->provider->process, tree->source); + if (fd) { + olr->source = fd->usp_id; + } + } + ret = commit_ring_op(&s->ring, s->provider, &olr->op, &result); + if (ret == 0) { + res = lio_usp_get_resource(result); + } + + return res; +} + +static int load_children(struct lio_resource* res) +{ + int result; + struct lio_op_load_children* olc; + + olc = (struct lio_op_load_children*) alloc_op(res, sizeof(*olc)); + if (olc == NULL) { + return -EBADF; + } + + olc->op.opcode = LIO_OP_LOAD_CHILDREN; + olc->resource = res->usp_id; + olc->opaque = res->opaque; + olc->op.flags |= LIO_OPFL_USP; + + result = commit_op(res, &olc->op, NULL); + + return result; +} + +static int read(struct lio_resource* res, uint64_t offset, + size_t bytes, void* buf) +{ + int result = 0; + struct lio_op_read* or; + struct lio_service* serv = res->tree->service; + struct lio_userspace_service* s = serv->opaque; + + void* user_buf; + void* buf_page = (void*) PAGE_ALIGN_ROUND_DOWN((uintptr_t) buf); + size_t num_pages = NUM_PAGES(buf - buf_page + bytes); + + or = (struct lio_op_read*) alloc_op(res, sizeof(*or)); + if (or == NULL) { + return -EBADF; + } + + user_buf = mmc_automap_user(&s->provider->process->context, + &mmc_current_context(), buf_page, num_pages, + MM_USER_START, MM_USER_END, MM_FLAGS_USER_CODE); + + if (user_buf == NULL) { + return -ENOMEM; + } + + or->op.opcode = LIO_OP_READ; + or->resource = res->usp_id; + or->opaque = res->opaque; + or->offset = offset; + or->size = bytes; + or->buf = user_buf + (buf - buf_page); + or->op.flags |= LIO_OPFL_USP; + + result = commit_op(res, &or->op, NULL); + + mmc_unmap(&s->provider->process->context, user_buf, num_pages); + + return result; +} + +static int write(struct lio_resource* res, uint64_t offset, + size_t bytes, void* buf) +{ + int result = 0; + struct lio_op_write* ow; + struct lio_service* serv = res->tree->service; + struct lio_userspace_service* s = serv->opaque; + + void* user_buf; + void* buf_page = (void*) PAGE_ALIGN_ROUND_DOWN((uintptr_t) buf); + size_t num_pages = NUM_PAGES(buf - buf_page + bytes); + + ow = (struct lio_op_write*) alloc_op(res, sizeof(*ow)); + if (ow == NULL) { + return -EBADF; + } + + user_buf = mmc_automap_user(&s->provider->process->context, + &mmc_current_context(), buf_page, num_pages, + MM_USER_START, MM_USER_END, MM_FLAGS_USER_CODE); + + if (user_buf == NULL) { + return -ENOMEM; + } + + ow->op.opcode = LIO_OP_WRITE; + ow->resource = res->usp_id; + ow->res_size = res->size; + ow->opaque = res->opaque; + ow->offset = offset; + ow->size = bytes; + ow->buf = user_buf + (buf - buf_page); + ow->op.flags |= LIO_OPFL_USP; + + result = commit_op(res, &ow->op, NULL); + + mmc_unmap(&s->provider->process->context, user_buf, num_pages); + + return result; +} + +static int sync(struct lio_resource* res) +{ + int result = 0; + struct lio_op_sync* os; + + os = (struct lio_op_sync*) alloc_op(res, sizeof(*os)); + if (os == NULL) { + return -EBADF; + } + + os->op.opcode = LIO_OP_SYNC; + os->res = res->usp_id; + os->opaque = res->opaque; + os->op.flags |= LIO_OPFL_USP; + + result = commit_op(res, &os->op, NULL); + + return result; +} + +static struct lio_resource* make_file(struct lio_resource* parent, + const char* name) +{ + struct lio_resource* result; + struct lio_op_make_file* omf; + size_t name_len = strlen(name) + 1; + uint64_t res_id; + int ret; + + omf = (struct lio_op_make_file*) alloc_op(parent, sizeof(*omf) + name_len); + if (omf == NULL) { + return NULL; + } + + omf->op.opcode = LIO_OP_MAKE_FILE; + omf->parent = parent->usp_id; + omf->opaque = parent->opaque; + strcpy(omf->name, name); + omf->op.flags |= LIO_OPFL_USP; + + ret = commit_op(parent, &omf->op, &res_id); + + if (ret < 0) { + result = NULL; + } else { + result = lio_usp_get_resource(res_id); + } + + return result; +} + +static struct lio_resource* make_dir(struct lio_resource* parent, + const char* name) +{ + struct lio_resource* result; + struct lio_op_make_file* omd; + size_t name_len = strlen(name) + 1; + uint64_t res_id; + int ret; + + omd = (struct lio_op_make_file*) alloc_op(parent, sizeof(*omd) + name_len); + if (omd == NULL) { + return NULL; + } + + + omd->op.opcode = LIO_OP_MAKE_DIR; + omd->parent = parent->usp_id; + omd->opaque = parent->opaque; + strcpy(omd->name, name); + omd->op.flags |= LIO_OPFL_USP; + + ret = commit_op(parent, &omd->op, &res_id); + + if (ret < 0) { + result = NULL; + } else { + result = lio_usp_get_resource(res_id); + } + + omd->op.flags &= ~LIO_OPFL_USED; + + return result; +} + +static struct lio_resource* make_symlink(struct lio_resource* parent, + const char* name, const char* target) +{ + struct lio_resource* result; + struct lio_op_make_symlink* oms; + size_t name_len = strlen(name) + 1; + size_t target_len = strlen(target) + 1; + uint64_t res_id; + int ret; + + oms = (struct lio_op_make_symlink*) + alloc_op(parent, sizeof(*oms) + name_len + target_len); + if (oms == NULL) { + return NULL; + } + + oms->op.opcode = LIO_OP_MAKE_SYMLINK; + oms->parent = parent->usp_id; + oms->opaque = parent->opaque; + oms->name_len = name_len; + strcpy(oms->strings, name); + strcpy(oms->strings + name_len, target); + oms->op.flags |= LIO_OPFL_USP; + + ret = commit_op(parent, &oms->op, &res_id); + + if (ret < 0) { + result = NULL; + } else { + result = lio_usp_get_resource(res_id); + } + + return result; + +} + +static int truncate(struct lio_resource* res, uint64_t size) +{ + int result = 0; + struct lio_op_truncate* otr; + + otr = (struct lio_op_truncate*) alloc_op(res, sizeof(*otr)); + if (otr == NULL) { + return -EBADF; + } + + otr->op.opcode = LIO_OP_TRUNCATE; + otr->resource = res->usp_id; + otr->opaque = res->opaque; + otr->size = size; + otr->op.flags |= LIO_OPFL_USP; + + result = commit_op(res, &otr->op, NULL); + + return result; +} + +static int unlink(struct lio_resource* parent, const char* name) +{ + int result = 0; + struct lio_op_unlink* oul; + size_t name_len = strlen(name) + 1; + + oul = (struct lio_op_unlink*) alloc_op(parent, sizeof(*oul) + name_len); + if (oul == NULL) { + return -EBADF; + } + + oul->op.opcode = LIO_OP_UNLINK; + oul->parent = parent->usp_id; + oul->opaque = parent->opaque; + strcpy(oul->name, name); + oul->op.flags |= LIO_OPFL_USP; + + result = commit_op(parent, &oul->op, NULL); + + return result; + +} diff --git a/src/kernel2/src/syscalls/rpc.c b/src/kernel2/src/syscalls/rpc.c index 1b57ae0..fe39cfc 100644 --- a/src/kernel2/src/syscalls/rpc.c +++ b/src/kernel2/src/syscalls/rpc.c @@ -277,7 +277,9 @@ int do_fastrpc(pid_t callee_pid, size_t metadata_size, void* metadata, // callee->process->pid); // Der aufgerufene Task darf wieder laufen - if (callee->status == PM_STATUS_WAIT_FOR_RPC) { + if (callee->status == PM_STATUS_WAIT_FOR_RPC || + callee->status == PM_STATUS_WAIT_FOR_LIO) + { callee->status = PM_STATUS_READY; } diff --git a/src/kernel2/src/tasks/thread.c b/src/kernel2/src/tasks/thread.c index 06a2e9e..3bb1e1d 100644 --- a/src/kernel2/src/tasks/thread.c +++ b/src/kernel2/src/tasks/thread.c @@ -73,7 +73,7 @@ pm_thread_t* pm_thread_create(pm_process_t* process, vaddr_t entry) { // Speicher fuer die Thread-Struktur allozieren, wenn das misslingt wird // abgebrochen. - pm_thread_t* thread = malloc(sizeof(pm_thread_t)); + pm_thread_t* thread = calloc(1, sizeof(pm_thread_t)); if (thread == NULL) { return NULL; } @@ -146,6 +146,8 @@ pm_thread_t* pm_thread_create(pm_process_t* process, vaddr_t entry) mmc_map(&process->context, thread->user_stack_bottom, stack_phys, MM_FLAGS_USER_DATA, NUM_PAGES(USER_STACK_SIZE)); + // Ein leerer Thread verarbeitet keine LIO-Trees + thread->lio_trees = NULL; // Thread in die Liste aufnehmen, und beim Scheduler regisrieren list_push(process->threads, thread); -- 1.7.7 From kevin at tyndur.org Fri Jan 3 01:26:52 2014 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 3 Jan 2014 01:26:52 +0100 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH_10/11=5D_init=3A_Unterst=C3=BCt?= =?utf-8?q?zung_f=C3=BCr_LIOv2-Pipequellen?= In-Reply-To: <1388708813-23390-1-git-send-email-kevin@tyndur.org> References: <1388708813-23390-1-git-send-email-kevin@tyndur.org> Message-ID: <1388708813-23390-11-git-send-email-kevin@tyndur.org> + init: Wenn eine Datei in einem LIOv1-Service geöffnet wird, der eine Pipe-Quelle hat, versucht init jetzt erst einmal die Quelle mit LIOv2 zu öffnen. Damit gehen LIOv1-Services auf LIOv2-Services (z.B. ext2 auf ata), aber nicht umgekehrt. Signed-off-by: Kevin Wolf --- src/include/syscallno.h | 1 + src/kernel2/include/syscall.h | 3 ++ src/kernel2/src/syscall.c | 1 + src/kernel2/src/syscalls/lostio.c | 26 ++++++++++++++++++ src/modules/include/syscall.h | 15 ++++++++++ src/modules/init/io.c | 52 +++++++++++++++++++++++++++++++++++++ src/modules/lib/syscalls/lostio.c | 34 ++++++++++++++++++++++++ 7 files changed, 132 insertions(+), 0 deletions(-) diff --git a/src/include/syscallno.h b/src/include/syscallno.h index ad25dc3..47ab453 100644 --- a/src/include/syscallno.h +++ b/src/include/syscallno.h @@ -107,6 +107,7 @@ #define SYSCALL_LIO_TRUNCATE 97 #define SYSCALL_LIO_UNLINK 98 #define SYSCALL_LIO_SYNC_ALL 99 +#define SYSCALL_LIO_PASS_FD 100 #define SYSCALL_LIO_SRV_SERVICE_REGISTER 110 #define SYSCALL_LIO_SRV_TREE_SET_RING 111 diff --git a/src/kernel2/include/syscall.h b/src/kernel2/include/syscall.h index 4ac87d0..9ff28f6 100644 --- a/src/kernel2/include/syscall.h +++ b/src/kernel2/include/syscall.h @@ -208,6 +208,9 @@ void syscall_lio_open(lio_usp_resource_t* resid, int flags, /// Stream schließen int syscall_lio_close(lio_usp_stream_t* stream_id); +/// Stream an anderen Prozess weitergeben +int syscall_lio_pass_fd(lio_usp_stream_t* stream_id, pid_t pid); + /// Aus Stream lesen void syscall_lio_read(lio_usp_stream_t* stream_id, uint64_t* offset, size_t bytes, void* buffer, int updatepos, ssize_t* result); diff --git a/src/kernel2/src/syscall.c b/src/kernel2/src/syscall.c index a5eda73..80fa605 100644 --- a/src/kernel2/src/syscall.c +++ b/src/kernel2/src/syscall.c @@ -123,6 +123,7 @@ void syscall_init() syscall_register(SYSCALL_LIO_STAT, &syscall_lio_stat, 2); syscall_register(SYSCALL_LIO_UNLINK, &syscall_lio_unlink, 3); syscall_register(SYSCALL_LIO_SYNC_ALL, &syscall_lio_sync_all, 0); + syscall_register(SYSCALL_LIO_PASS_FD, &syscall_lio_pass_fd, 2); syscall_register(SYSCALL_LIO_SRV_SERVICE_REGISTER, &syscall_lio_srv_service_register, 4); diff --git a/src/kernel2/src/syscalls/lostio.c b/src/kernel2/src/syscalls/lostio.c index 987d29c..1c978d4 100644 --- a/src/kernel2/src/syscalls/lostio.c +++ b/src/kernel2/src/syscalls/lostio.c @@ -129,6 +129,32 @@ int syscall_lio_close(lio_usp_stream_t* stream_id) return ret; } +/// Stream an anderen Prozess weitergeben +int syscall_lio_pass_fd(lio_usp_stream_t* stream_id, pid_t pid) +{ + struct lio_usp_stream* fd; + struct lio_stream* stream; + pm_process_t* process; + + process = pm_get(pid); + if (process == NULL) { + return -EINVAL; + } + + // TODO: is_userspace + fd = lio_usp_get_stream(current_process, *stream_id); + if (fd == NULL) { + return -EBADF; + } + + stream = fd->stream; + lio_usp_remove_stream(current_process, fd); + fd = lio_usp_add_stream(process, stream); + *stream_id = fd->usp_id; + + return 0; +} + /// Aus Stream lesen void syscall_lio_read(lio_usp_stream_t* stream_id, uint64_t* offset, size_t bytes, void* buffer, int updatepos, ssize_t* result) diff --git a/src/modules/include/syscall.h b/src/modules/include/syscall.h index 298e737..33cd98e 100644 --- a/src/modules/include/syscall.h +++ b/src/modules/include/syscall.h @@ -169,6 +169,21 @@ int lio_stat(lio_resource_t resource, struct lio_stat* sbuf); int lio_close(lio_stream_t s); /** + * Gibt einen Stream an einen anderen Prozess ab. Der Stream wird in diesem + * Prozess dabei ungültig. + * + * @param s Der abzugebenden Stream + * @param pid Zielprozess, der den Stream erhalten soll + * + * @return Stream-ID im Zielprozess bei Erfolg, negativ im Fehlerfall. + * Insbesondere: + * + * -EINVAL Es gibt keinen Prozess mit der gegebenen PID + * -EBADF Die Stream-ID ist ungültig + */ +lio_stream_t lio_pass_fd(lio_stream_t s, pid_t pid); + +/** * Liest aus dem Stream ab der aktuellen Position des Dateizeigers und bewegt * den Dateizeiger hinter das letzte gelesene Byte. * diff --git a/src/modules/init/io.c b/src/modules/init/io.c index 56df8b0..4ce8e76 100644 --- a/src/modules/init/io.c +++ b/src/modules/init/io.c @@ -34,6 +34,7 @@ */ #define MODULE_INIT +#include #include "types.h" #include "syscall.h" #include "string.h" @@ -51,9 +52,49 @@ void io_init() register_message_handler("IO_OPEN ", &rpc_io_open); } +io_resource_t* newio_open(const char* service_name, const char* path, + uint8_t attr, pid_t pid) +{ + char* p; + lio_resource_t r; + lio_stream_t s; + io_resource_t* result = NULL; + + // Nur fuer Pipequellen + if (attr != (IO_OPEN_MODE_READ | IO_OPEN_MODE_WRITE)) { + return NULL; + } + + asprintf(&p, "%s:%s", service_name, path); + r = lio_resource(p, 1); + if (r < 0) { + goto out; + } + + s = lio_open(r, LIO_READ | LIO_WRITE); + if (s < 0) { + goto out; + } + + result = malloc(sizeof(*result)); + *result = (io_resource_t) { + .lio2_stream = s, + .lio2_res = r, + .flags = IO_RES_FLAG_READAHEAD, + }; + +out: + free(p); + return result; +} + io_resource_t* io_open_res(const char* service_name, const char* path, io_resource_t* pipe_source, uint8_t attr, pid_t pid) { + io_resource_t* newres; + if ((newres = newio_open(service_name, path, attr, pid))) { + return newres; + } struct service_s* dest_service = NULL; dest_service = get_service_by_name(service_name); //printf("\nopen resource: service='%s' path='%s' => %x\n", service_name, path, dest_service); @@ -63,6 +104,15 @@ io_resource_t* io_open_res(const char* service_name, const char* path, io_resour return NULL; } + + // Pipequelle für den Service lesbar machen + if (pipe_source && IS_LIO2(pipe_source)) { + pipe_source->lio2_stream = + lio_pass_fd(pipe_source->lio2_stream, dest_service->pid); + if (pipe_source->lio2_stream < 0) { + return NULL; + } + } //Daten fuer den open-rpc an den Service zusammenflicken size_t open_request_size = strlen(path) + sizeof(io_resource_t) + sizeof(pid_t) + 6; @@ -136,6 +186,8 @@ void rpc_io_open(pid_t pid, uint32_t correlation_id, size_t data_size, void* dat if((pipe_source != NULL) && pipe_source->pid) { last_pid = pipe_source->pid; + } else if (pipe_source && IS_LIO2(pipe_source)) { + /* pipe_source bleibt gültig, aber es gibt keine PID */ } else { pipe_source = NULL; break; diff --git a/src/modules/lib/syscalls/lostio.c b/src/modules/lib/syscalls/lostio.c index 1961243..6cf8dc1 100644 --- a/src/modules/lib/syscalls/lostio.c +++ b/src/modules/lib/syscalls/lostio.c @@ -135,6 +135,40 @@ int lio_close(lio_stream_t s) return result; } +/** + * Gibt einen Stream an einen anderen Prozess ab. Der Stream wird in diesem + * Prozess dabei ungültig. + * + * @param s Der abzugebenden Stream + * @param pid Zielprozess, der den Stream erhalten soll + * + * @return Stream-ID im Zielprozess bei Erfolg, negativ im Fehlerfall. + * Insbesondere: + * + * -EINVAL Es gibt keinen Prozess mit der gegebenen PID + * -EBADF Die Stream-ID ist ungültig + */ +lio_stream_t lio_pass_fd(lio_stream_t s, pid_t pid) +{ + volatile lio_stream_t stream = s; + int result; + + asm( + "pushl %3;" + "pushl %2;" + "mov %1, %%eax;" + "int $0x30;" + "add $0x8, %%esp;" + : "=a" (result) : "i" (SYSCALL_LIO_PASS_FD), "r" (&stream), "r" (pid) + : "memory"); + + if (result < 0) { + return result; + } else { + return stream; + } +} + static ssize_t read_syscall(lio_stream_t s, uint64_t offset, size_t bytes, void* buf, int updatepos) { -- 1.7.7 From kevin at tyndur.org Fri Jan 3 01:26:53 2014 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 3 Jan 2014 01:26:53 +0100 Subject: [tyndur-devel] [PATCH 11/11] cdi/storage: Auf LIOv2 umstellen In-Reply-To: <1388708813-23390-1-git-send-email-kevin@tyndur.org> References: <1388708813-23390-1-git-send-email-kevin@tyndur.org> Message-ID: <1388708813-23390-12-git-send-email-kevin@tyndur.org> * cdi/storage: Das alte RPC-Interface durch einen LIOv2-Userspace- Service ersetzt. FIXME: CD-ROM ist jetzt kaputt. Signed-off-by: Kevin Wolf --- src/modules/cdi/ata/device.c | 1 + src/modules/cdi/floppy/device.c | 1 + src/modules/cdi/include/cdi-osdep.h | 5 + src/modules/cdi/include/cdi/storage.h | 7 + src/modules/cdi/lib/cdi.c | 9 ++- src/modules/cdi/lib/scsi/disk.c | 13 ++ src/modules/cdi/lib/storage.c | 225 ++++++++++++++++----------------- 7 files changed, 144 insertions(+), 117 deletions(-) diff --git a/src/modules/cdi/ata/device.c b/src/modules/cdi/ata/device.c index 9afa102..baedd72 100644 --- a/src/modules/cdi/ata/device.c +++ b/src/modules/cdi/ata/device.c @@ -234,6 +234,7 @@ void ata_init_controller(struct ata_controller* controller) if (dev->atapi == 0) { #endif dev->dev.storage.block_size = ATA_SECTOR_SIZE; + dev->dev.storage.optimal_count = 128; // Handler setzen dev->read_sectors = ata_drv_read_sectors; diff --git a/src/modules/cdi/floppy/device.c b/src/modules/cdi/floppy/device.c index c5c75a5..5c17a38 100755 --- a/src/modules/cdi/floppy/device.c +++ b/src/modules/cdi/floppy/device.c @@ -801,6 +801,7 @@ void floppy_init_device(struct cdi_device* device) dev->dev.block_size = FLOPPY_SECTOR_SIZE(dev); dev->dev.block_count = FLOPPY_SECTOR_COUNT(dev); + dev->dev.optimal_count = 1; cdi_storage_device_init(&dev->dev); } diff --git a/src/modules/cdi/include/cdi-osdep.h b/src/modules/cdi/include/cdi-osdep.h index 5bb3827..ed8cc5d 100644 --- a/src/modules/cdi/include/cdi-osdep.h +++ b/src/modules/cdi/include/cdi-osdep.h @@ -12,6 +12,7 @@ #define _CDI_OSDEP_H_ #include +#include #define CDI_STANDALONE #define TYNDUR @@ -92,4 +93,8 @@ typedef struct { FILE* device; } cdi_fs_osdep; +struct storage_drv_osdep { + struct lio_resource* root; +}; + #endif diff --git a/src/modules/cdi/include/cdi/storage.h b/src/modules/cdi/include/cdi/storage.h index c60e43c..46f2355 100644 --- a/src/modules/cdi/include/cdi/storage.h +++ b/src/modules/cdi/include/cdi/storage.h @@ -77,6 +77,11 @@ struct cdi_storage_device { * \endenglish */ uint64_t block_count; + + /** + * Beste Request-Groesse beim Lesen und Schreiben (Anzahl Blocks). + */ + size_t optimal_count; }; /** @@ -140,6 +145,8 @@ struct cdi_storage_driver { */ int (*write_blocks)(struct cdi_storage_device* device, uint64_t start, uint64_t count, void* buffer); + + struct storage_drv_osdep osdep; }; #ifdef __cplusplus diff --git a/src/modules/cdi/lib/cdi.c b/src/modules/cdi/lib/cdi.c index dd6e144..42a5ef0 100644 --- a/src/modules/cdi/lib/cdi.c +++ b/src/modules/cdi/lib/cdi.c @@ -185,7 +185,8 @@ static void cdi_tyndur_run_drivers(void) // Warten auf Ereignisse while (1) { - wait_for_rpc(); + lio_dispatch(); + lio_srv_wait(); } } @@ -232,6 +233,12 @@ void cdi_driver_register(struct cdi_driver* driver) } } +/** Gibt eine Liste aller Treiber zurueck */ +list_t* cdi_tyndur_get_drivers(void) +{ + return drivers; +} + /** * Wenn main nicht von einem Treiber ueberschrieben wird, ist hier der * Einsprungspunkt. Die Standardfunktion ruft nur cdi_init() auf. Treiber, die diff --git a/src/modules/cdi/lib/scsi/disk.c b/src/modules/cdi/lib/scsi/disk.c index e0eca2e..0e2534e 100644 --- a/src/modules/cdi/lib/scsi/disk.c +++ b/src/modules/cdi/lib/scsi/disk.c @@ -42,6 +42,7 @@ static int cdi_scsi_disk_write(struct cdi_storage_device* device, struct cdi_storage_driver cdi_scsi_disk_driver = { .drv = { + .name = "scsidisk", .type = CDI_STORAGE, }, .read_blocks = cdi_scsi_disk_read, @@ -226,11 +227,23 @@ static int cdi_scsi_disk_write(struct cdi_storage_device* device, return -1; } +static void driver_init(void) +{ + static int initialised = 0; + + if (!initialised) { + cdi_driver_register(&cdi_scsi_disk_driver.drv); + cdi_storage_driver_init(&cdi_scsi_disk_driver); + } +} + int cdi_scsi_disk_init(struct cdi_scsi_device* device) { struct cdi_storage_device* frontdev; uint32_t num_sectors = 0, sector_size = 0; + driver_init(); + if (cdrom_init(device)) { return -1; } diff --git a/src/modules/cdi/lib/storage.c b/src/modules/cdi/lib/storage.c index fbf2edc..15d51d3 100644 --- a/src/modules/cdi/lib/storage.c +++ b/src/modules/cdi/lib/storage.c @@ -17,37 +17,45 @@ #include "cdi/storage.h" #include "libpartition.h" -static void lostio_mst_if_init(void); int lostio_mst_if_newdev(struct partition* part); -static size_t lostio_mst_read_handler(lostio_filehandle_t* fh, - void* buf, size_t blocksize, size_t blockcount); -static size_t lostio_mst_write_handler(lostio_filehandle_t* fh, - size_t blocksize, size_t blockcount, void* data); -static int lostio_mst_seek_handler(lostio_filehandle_t* fh, uint64_t offset, - int origin); - -#define CDI_LOSTIO_TYPE_MST 255 -static typehandle_t lostio_mst_typehandle = { - .id = CDI_LOSTIO_TYPE_MST, - - .pre_open = NULL, - .post_open = NULL, - .not_found = NULL, - .close = NULL, - - .read = lostio_mst_read_handler, - .write = lostio_mst_write_handler, - .seek = lostio_mst_seek_handler -}; +static int read(struct lio_resource* res, uint64_t offset, + size_t size, void* buf); +static int write(struct lio_resource* res, uint64_t offset, + size_t size, void* buf); +static struct lio_resource* load_root(struct lio_tree* tree); +static int load_children(struct lio_resource* res); +int cdi_storage_read(struct cdi_storage_device* device, uint64_t pos, + size_t size, void* dest); /** * Initialisiert die Datenstrukturen fuer einen Massenspeichertreiber */ void cdi_storage_driver_init(struct cdi_storage_driver* driver) { + struct lio_resource* res; + struct lio_service* service; + driver->drv.type = CDI_STORAGE; cdi_driver_init((struct cdi_driver*) driver); + + res = lio_resource_create(NULL); + res->browsable = 1; + res->blocksize = 1024; + driver->osdep.root = res; + + service = malloc(sizeof(*service)); + *service = (struct lio_service) { + .name = driver->drv.name, + .lio_ops = { + .load_root = load_root, + .load_children = load_children, + .read = read, + .write = write, + }, + }; + + lio_add_service(service); } /** @@ -63,12 +71,6 @@ void cdi_storage_driver_destroy(struct cdi_storage_driver* driver) */ void cdi_storage_driver_register(struct cdi_storage_driver* driver) { - static int initialized = 0; - - if (initialized == 0) { - lostio_mst_if_init(); - initialized = 1; - } } /** @@ -212,140 +214,131 @@ int cdi_storage_write(struct cdi_storage_device* device, uint64_t pos, return 0; } - -/** - * Initialisiert die Massenspeichernschnittstelle fuer LostIO - */ -static void lostio_mst_if_init() -{ - lostio_register_typehandle(&lostio_mst_typehandle); -} - /** * Erstellt den Dateisystemknoten fuer ein Geraet. */ int lostio_mst_if_newdev(struct partition* part) { - static int has_cdrom = 0; +// static int has_cdrom = 0; struct cdi_storage_device* device = part->dev; + struct cdi_storage_driver* driver = (void*) device->dev.driver; + struct lio_resource* res; - // Slash vor Pfad anhaengen + // Dateinamen erzeugen char* path; if (part->number == (uint16_t) -1) { - asprintf(&path, "/%s", device->dev.name); + asprintf(&path, "%s", device->dev.name); } else { - asprintf(&path, "/%s_p%d", device->dev.name, part->number); + asprintf(&path, "%s_p%d", device->dev.name, part->number); } - if (vfstree_create_node(path, CDI_LOSTIO_TYPE_MST, device->block_size * - device->block_count, (void*) part, 0) == false) - { - free(path); - return -1; - } + // Neue Ressource anlegen + res = lio_resource_create(NULL); + res->readable = 1; + res->writable = 1; + res->seekable = 1; + res->blocksize = device->block_size; + res->size = part->size; + res->opaque = part; + lio_node_create(driver->osdep.root, res, path); + free(path); + +#if 0 + // TODO if (!has_cdrom && !strncmp(device->dev.name, "atapi", strlen("atapi"))) { has_cdrom = 1; vfstree_create_node("/cdrom", CDI_LOSTIO_TYPE_MST, device->block_size * device->block_count, (void*) part, 0); } +#endif - free(path); return 0; } -/** - * Lesehandler fuer LostIO - */ -static size_t lostio_mst_read_handler(lostio_filehandle_t* fh, - void* buf, size_t blocksize, size_t blockcount) + +extern list_t* cdi_tyndur_get_drivers(void); +static struct lio_resource* load_root(struct lio_tree* tree) { - struct partition* part = (struct partition*) fh->node->data; - struct cdi_storage_device* device = part->dev; - size_t size = blocksize * blockcount; + list_t* drivers = cdi_tyndur_get_drivers(); + struct cdi_driver* drv; + int i; - // Groesse anpassen, wenn ueber das Medium hinaus gelesen werden soll - if (size > (part->size - fh->pos)) { - size = part->size - fh->pos; - if (size == 0) { - fh->flags |= LOSTIO_FLAG_EOF; - return 0; - } + if (tree->source != -1) { + return NULL; } - // In den uebergebenen Buffer einlesen - if (cdi_storage_read(device, fh->pos + part->start, size, buf) != 0) { - return 0; + for (i = 0; (drv = list_get_element_at(drivers, i)); i++) { + if (drv->type == CDI_STORAGE) { + struct cdi_storage_driver* sdrv = (void*) drv; + if (!strcmp(tree->service->name, drv->name)) { + struct lio_resource* root = sdrv->osdep.root; + root->tree = tree; + lio_resource_modified(root); + return root; + } + } } - fh->pos += size; + return NULL; +} + +static int load_children(struct lio_resource* root) +{ + struct lio_node* it; + int j; + + for (j = 0; (it = list_get_element_at(root->children, j)); j++) + { + it->res->tree = root->tree; + lio_resource_modified(it->res); + lio_srv_node_add(root->server.id, it->res->server.id, + it->name); + } - return size; + return 0; } +#define NUM_BLOCKS(x) (((x) + res->blocksize - 1) / res->blocksize) + /** - * Schreibhandler fuer LostIO + * Lesehandler fuer LostIO */ -static size_t lostio_mst_write_handler(lostio_filehandle_t* fh, - size_t blocksize, size_t blockcount, void* data) +static int read(struct lio_resource* res, uint64_t offset, + size_t size, void* buf) { - struct partition* part = (struct partition*) fh->node->data; + struct partition* part = res->opaque; struct cdi_storage_device* device = part->dev; - size_t size = blocksize * blockcount; - size_t result = size; + int result; - // Groesse anpassen, wenn ueber das Medium hinaus geschrieben werden soll - if (size > (part->size - fh->pos)) { - size = part->size - fh->pos; + // Groesse anpassen, wenn ueber das Medium hinaus gelesen werden soll + if (size > (part->size - offset)) { + size = part->size - offset; } - // Daten schreiben - if (cdi_storage_write(device, fh->pos + part->start, size, data) != 0) { - result = 0; - } else { - fh->pos += size; - } + // In den uebergebenen Buffer einlesen + result = cdi_storage_read(device, offset + part->start, size, buf); - return result; + return (result ? -1 : 0); } /** - * Seek-Handler fuer LostIO + * Schreibhandler fuer LostIO */ -static int lostio_mst_seek_handler(lostio_filehandle_t* fh, uint64_t offset, - int origin) +static int write(struct lio_resource* res, uint64_t offset, + size_t size, void* buf) { - struct partition* part = (struct partition*) fh->node->data; - uint64_t new_pos = fh->pos; - uint64_t size = part->size; - - switch (origin) { - case SEEK_SET: - new_pos = offset; - break; - - case SEEK_CUR: - new_pos += offset; - break; - - case SEEK_END: - new_pos = size; - break; - } + struct partition* part = res->opaque; + struct cdi_storage_device* device = part->dev; + int result; - // Position nur aktualisieren, wenn sie nicht ausserhalb des Datentraegers - // liegt. - if (new_pos > size) { - return -1; - } else if (new_pos == size) { - // Gegebenen Falles noch EOF setzen - fh->flags |= LOSTIO_FLAG_EOF; - } else { - // Sonst EOF loeschen - fh->flags &= ~LOSTIO_FLAG_EOF; + // Groesse anpassen, wenn ueber das Medium hinaus geschrieben werden soll + if (size > (part->size - offset)) { + size = part->size - offset; } - fh->pos = new_pos; - return 0; -} + // Daten schreiben + result = cdi_storage_write(device, offset + part->start, size, buf); + return (result ? -1 : 0); +} -- 1.7.7 From particleflux at gmail.com Sat Jan 4 02:32:55 2014 From: particleflux at gmail.com (Stefan Linke) Date: Sat, 4 Jan 2014 02:32:55 +0100 Subject: [tyndur-devel] [PATCH] lutils: tar.xz entpacken Message-ID: <1388799175-1379-1-git-send-email-particleflux@gmail.com> * lutils.sh entpackt jetzt auch xz Dateien (installiertes xz utility vorausgesetzt) Signed-off-by: Stefan Linke --- lclasses/lutils.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lclasses/lutils.sh b/lclasses/lutils.sh index a2b2258..5709cb5 100644 --- a/lclasses/lutils.sh +++ b/lclasses/lutils.sh @@ -92,6 +92,10 @@ lunpack() { tar -xjf ${fn} ;; + *.tar.xz) + tar -xJf ${fn} + ;; + *.tar.lzma) lzma -dc ${fn} | tar -x ;; -- 1.8.4.4 From particleflux at gmail.com Sat Jan 4 22:57:12 2014 From: particleflux at gmail.com (Stefan Linke) Date: Sat, 4 Jan 2014 22:57:12 +0100 Subject: [tyndur-devel] [PATCH] ls: fix typo in help Message-ID: <1388872632-23266-1-git-send-email-particleflux@gmail.com> ! humals are not humans ;) Signed-off-by: Stefan Linke --- src/modules/c/shell/cmds/ls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/c/shell/cmds/ls.c b/src/modules/c/shell/cmds/ls.c index 105ad09..f382bf1 100644 --- a/src/modules/c/shell/cmds/ls.c +++ b/src/modules/c/shell/cmds/ls.c @@ -184,7 +184,7 @@ void ls_display_usage() "\nAufruf: ls [Optionen] [Verzeichnisse]\n\n" "Optionen:\n" " -a, --all zeige versteckte Dateien an\n" - " -h, --humal-readable zeige Dateigröße menschenlesbar an " + " -h, --human-readable zeige Dateigröße menschenlesbar an " "(z.B. 10M, 1G)\n" " --help diese Hilfe anzeigen\n")); } -- 1.8.4.4 From particleflux at gmail.com Sat Jan 4 23:59:54 2014 From: particleflux at gmail.com (Stefan Linke) Date: Sat, 4 Jan 2014 23:59:54 +0100 Subject: [tyndur-devel] [PATCH] ls: add color option Message-ID: <1388876394-30223-1-git-send-email-particleflux@gmail.com> + colorization option for built-in ls Signed-off-by: Stefan Linke --- src/modules/c/shell/cmds/ls.c | 27 ++++++++++++++++++++++++--- src/modules/c/shell/lang/lang_en.c | 1 + 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/modules/c/shell/cmds/ls.c b/src/modules/c/shell/cmds/ls.c index f382bf1..838ae9a 100644 --- a/src/modules/c/shell/cmds/ls.c +++ b/src/modules/c/shell/cmds/ls.c @@ -43,6 +43,12 @@ #include #include + +#define LS_COLOR_RESET_DEFAULT "00" +#define LS_COLOR_FILE_DEFAULT "00" +#define LS_COLOR_DIR_DEFAULT "01;34" +#define LS_COLOR_LINK_DEFAULT "01;36" + void ls_display_usage(void); char* format_size(size_t size, bool human_readable); @@ -57,6 +63,7 @@ char* format_size(size_t size, bool human_readable); bool success = true; bool show_hidden = false; bool human_readable = false; + bool colorize = false; list_t *dirs = list_create(); bool print_dirnames = false; @@ -65,13 +72,14 @@ char* format_size(size_t size, bool human_readable); { "all", no_argument, 0, 'a' }, { "help", no_argument, 0, 1 }, { "human-readable", no_argument, 0, 'h' }, + { "color", no_argument, 0, 'C' }, { 0, 0, 0, 0 } }; optind = 0; while (optind < argc) { - int result = getopt_long(argc, argv, "ah", long_options, NULL); + int result = getopt_long(argc, argv, "ahC", long_options, NULL); if (result == -1) { break; } @@ -82,6 +90,9 @@ char* format_size(size_t size, bool human_readable); case 'h': human_readable = true; break; + case 'C': + colorize = true; + break; case 1: ls_display_usage(); return EXIT_SUCCESS; @@ -116,19 +127,28 @@ char* format_size(size_t size, bool human_readable); char *formatted_size = format_size(direntry->size, human_readable); char flags[4] = " "; + const char *color = NULL; if (direntry->type & IO_DIRENTRY_FILE) { flags[0] = 'f'; + color = LS_COLOR_FILE_DEFAULT; } if (direntry->type & IO_DIRENTRY_DIR) { flags[1] = 'd'; + color = LS_COLOR_DIR_DEFAULT; } if (direntry->type & IO_DIRENTRY_LINK) { flags[2] = 'l'; + color = LS_COLOR_LINK_DEFAULT; } - printf(" [%s] %s %s\n", flags, formatted_size, - direntry->name); + if (colorize) { + printf(" [%s] %s \e[%sm%s\e[%sm\n", flags, formatted_size, + color, direntry->name, LS_COLOR_RESET_DEFAULT); + } else { + printf(" [%s] %s %s\n", flags, formatted_size, + direntry->name); + } free(formatted_size); } free(direntry); @@ -184,6 +204,7 @@ void ls_display_usage() "\nAufruf: ls [Optionen] [Verzeichnisse]\n\n" "Optionen:\n" " -a, --all zeige versteckte Dateien an\n" + " -C, --color zeige Ausgabe farbig\n" " -h, --human-readable zeige Dateigröße menschenlesbar an " "(z.B. 10M, 1G)\n" " --help diese Hilfe anzeigen\n")); diff --git a/src/modules/c/shell/lang/lang_en.c b/src/modules/c/shell/lang/lang_en.c index c16abcf..be52080 100644 --- a/src/modules/c/shell/lang/lang_en.c +++ b/src/modules/c/shell/lang/lang_en.c @@ -277,6 +277,7 @@ static const struct tms_strings dict[] = { "\nUsage: ls [options] [directories]\n\n" "Options:\n" " -a, --all show hidden files\n" + " -C, --color colorize output\n" " -h, --human-readable show filesize human-readable, (e.g. 10M, 1G)\n" " --help show this help\n", -- 1.8.4.4