Changeset 204 for trunk/kernel


Ignore:
Timestamp:
Jul 17, 2017, 8:42:59 AM (7 years ago)
Author:
alain
Message:

Bug fix in kernel_init
-This line, and those below, will be ignored--

M params.mk
M kernel_config.h
M Makefile
M hdd/virt_hdd.dmg
M tools/bootloader_tsar/boot.c
M kernel/libk/bits.h
M kernel/libk/elf.c
M kernel/libk/xhtab.c
M kernel/libk/elf.h
M kernel/libk/xhtab.h
M kernel/devices/dev_pic.c
M kernel/mm/vmm.c
M kernel/mm/mapper.c
M kernel/mm/mapper.h
M kernel/vfs/devfs.h
M kernel/vfs/vfs.c
M kernel/vfs/vfs.h
M kernel/vfs/devfs.c
M kernel/kern/chdev.h
M kernel/kern/kernel_init.c
M kernel/kern/process.c
M kernel/kern/process.h
M hal/tsar_mips32/core/hal_remote.c
M hal/tsar_mips32/drivers/soclib_pic.c

Location:
trunk/kernel
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/devices/dev_pic.c

    r201 r204  
    2626#include <chdev.h>
    2727#include <printk.h>
    28 #include <hal_drivers.h>
     28#include <soclib_pic.h>
    2929#include <dev_pic.h>
    3030#include <cluster.h>
     
    5050    {
    5151        // call the PIC SOCLIB driver
    52         hal_drivers_pic_init( pic );
     52        soclib_pic_init( pic );
     53
     54        // update the PIC chdev extension
     55        pic->ext.pic.enable_timer = &soclib_pic_enable_timer;
     56        pic->ext.pic.enable_irq   = &soclib_pic_enable_irq;
     57        pic->ext.pic.disable_irq  = &soclib_pic_disable_irq;
     58        pic->ext.pic.bind_irq     = &soclib_pic_bind_irq;
     59        pic->ext.pic.send_ipi     = &soclib_pic_send_ipi;
     60        pic->ext.pic.extend_init  = &soclib_pic_extend_init;
    5361    }
    5462    else if( impl == IMPL_PIC_I86 )
     
    7078
    7179    // get pointer on extend_init function
    72     pic_init_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.extend_init ) );
     80    pic_init_t * f = hal_remote_lpt( XPTR( pic_cxy , &pic_ptr->ext.pic.extend_init ) ); 
    7381
    7482    // call relevant driver function
  • trunk/kernel/kern/chdev.h

    r188 r204  
    4848 * Therefore a given I/O operation involve generally three clusters:
    4949 * - the client cluster, containing the client thread,
    50  * - the server cluster, containing the chdev and the client thread,
    51  * - the I/O cluster containing the physical device.
     50 * - the server cluster, containing the chdev and the server thread,
     51 * - the I/O cluster, containing the physical device.
    5252 *****************************************************************************************/
    5353
     
    6666
    6767/******************************************************************************************
    68  * This define the generic prototypes for the three functions that must be defined
     68 * This define the generic prototypes for the two functions that must be defined
    6969 * by all drivers implementing a generic device:
    70  * - "init"    : device initialisation.
    7170 * - "cmd"     : start an I/O operation.
    7271 * - "isr"     : complete an I/O operation.
    73  * The "init" function is called by kernel_init() to initialise the hardware device.
    74  * The "cmd" and "isr" are registered in the generic chdev descriptor by kernel_init(),
     72 * The "cmd" and "isr" are registered in the generic chdev descriptor at kernel init,
    7573 * and are called to start and complete an I/O operation. 
    7674*****************************************************************************************/
     
    8583 * provide the same set of operations and the same driver API.
    8684 * This enum must be consistent with the enum in files arch_info.h, and arch_class.py.
     85 *
     86 * WARNING : The ICU device exist in boot_info to specify the base address of the
     87 *           distributed LAPIC controler, but it does not exist as a chdev in the kernel,
     88 *           as it is hidden in the driver associated to the PIC device.
    8789 *****************************************************************************************/
    8890 
     
    99101        DEV_FUNC_TIM   =  8,
    100102        DEV_FUNC_TXT   =  9,
    101     DEV_FUNC_ICU   = 10,
     103    DEV_FUNC_ICU   = 10,   
    102104    DEV_FUNC_PIC   = 11,
    103105
  • trunk/kernel/kern/kernel_init.c

    r188 r204  
    3333#include <list.h>
    3434#include <xlist.h>
     35#include <xhtab.h>
    3536#include <thread.h>
    3637#include <scheduler.h>
     
    245246        func        = FUNC_FROM_TYPE( dev_tbl[i].type );
    246247        impl        = IMPL_FROM_TYPE( dev_tbl[i].type );
    247 
     248 
    248249        //////////////////////////
    249250        if( func == DEV_FUNC_MMC ) 
     
    553554    }
    554555
    555     kinit_dmsg("\n[INFO] %s created IOPIC chdev in cluster %x at cycle %d\n",
     556    kinit_dmsg("\n[INFO] %s created PIC chdev in cluster %x at cycle %d\n",
    556557               __FUNCTION__ , local_cxy , (uint32_t)hal_time_stamp() );
    557558   
     
    672673void kernel_init( boot_info_t * info )
    673674{
    674     lid_t        core_lid = -1;        // running core local index
    675     cxy_t        core_cxy = -1;        // running core cluster identifier
    676     gid_t        core_gid;             // running core hardware identifier
    677     cluster_t  * cluster;              // pointer on local cluster manager
    678     core_t     * core;                 // pointer on running core descriptor
    679     thread_t   * thread;               // pointer on idle thread descriptor
    680     xptr_t       vfs_root_inode_xp;    // extended pointer on VFS root inode
    681 //  xptr_t       devfs_root_inode_xp;  // extended pointer on DEVFS root inode
     675    lid_t        core_lid = -1;             // running core local index
     676    cxy_t        core_cxy = -1;             // running core cluster identifier
     677    gid_t        core_gid;                  // running core hardware identifier
     678    cluster_t  * cluster;                   // pointer on local cluster manager
     679    core_t     * core;                      // pointer on running core descriptor
     680    thread_t   * thread;                    // pointer on idle thread descriptor
     681
     682    xptr_t       vfs_root_inode_xp;         // extended pointer on VFS root inode
     683    xptr_t       devfs_dev_inode_xp;        // extended pointer on DEVFS dev inode   
     684    xptr_t       devfs_external_inode_xp;   // extended pointer on DEVFS external inode       
     685    xptr_t       devfs_internal_inode_xp;   // extended pointer on DEVFS internal inode       
     686
    682687    error_t      error;
    683688
     
    958963
    959964    /////////////////////////////////////////////////////////////////////////////////
    960     // global &local synchro to protect File System initialisation
    961965    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ),
    962966                                        (info->x_size * info->y_size) );
    963967    barrier_wait( &local_barrier , info->cores_nr );
     968    /////////////////////////////////////////////////////////////////////////////////
    964969
    965970    if( (core_lid ==  0) && (local_cxy == 0) )
     
    970975    /////////////////////////////////////////////////////////////////////////////////
    971976    // STEP 6 : CP0 in cluster IO makes the global DEVFS tree initialisation:
    972     //          It creates the DEVFS root directory and the DEVFS "external"
    973     //          diretory in cluster IO and mount these inodes into VFS.
     977    //          It creates the DEVFS directory "dev", and the DEVFS "external"
     978    //          directory in cluster IO and mount these inodes into VFS.
    974979    /////////////////////////////////////////////////////////////////////////////////
    975980
    976981    if( (core_lid ==  0) && (local_cxy == io_cxy) )
    977982    {
    978         xptr_t  devfs_root_inode_xp;       // extended pointer on DEVFS root directory
    979         xptr_t  devfs_external_inode_xp;   // extended pointer on DEVFS external directory   
    980 
    981983        // create "dev" and "external" directories.
    982984        devfs_global_init( process_zero.vfs_root_xp,
    983                            &devfs_root_inode_xp,
     985                           &devfs_dev_inode_xp,
    984986                           &devfs_external_inode_xp );
    985987
     
    991993
    992994        // register DEVFS root and external directories
    993         devfs_ctx_init( devfs_ctx, devfs_root_inode_xp, devfs_external_inode_xp );
     995        devfs_ctx_init( devfs_ctx, devfs_dev_inode_xp, devfs_external_inode_xp );
    994996    }   
    995997
    996998    /////////////////////////////////////////////////////////////////////////////////
    997     // global &local synchro to protect File System initialisation
    998999    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ),
    9991000                                        (info->x_size * info->y_size) );
    10001001    barrier_wait( &local_barrier , info->cores_nr );
     1002    /////////////////////////////////////////////////////////////////////////////////
    10011003
    10021004    if( (core_lid ==  0) && (local_cxy == 0) )
     
    10071009    // STEP 7 : All CP0s complete in parallel the DEVFS tree initialization.
    10081010    //          Each CP0 get the "dev" and "external" extended pointers from
    1009     //          values storred in cluster IO. Then CP0 in cluster(i) creates the
    1010     //          DEVFS "internal directory, and creates the pseudo-files for all
    1011     //          chdevs contained in cluster (i).
     1011    //          values stored in cluster IO.
     1012    //          Then CP0 in cluster(i) creates the DEVFS "internal directory,
     1013    //          and creates the pseudo-files for all chdevs in cluster (i).
    10121014    /////////////////////////////////////////////////////////////////////////////////
    10131015
    10141016    if( core_lid == 0 )
    10151017    {
    1016         xptr_t  root_inode_xp;       // extended pointer on DEVFS root directory
    1017         xptr_t  external_inode_xp;   // extended pointer on DEVFS external directory   
    1018 
    10191018        // get extended pointer on "extend" field of VFS context for DEVFS in cluster IO
    10201019        xptr_t  extend_xp = XPTR( io_cxy , &fs_context[FS_TYPE_DEVFS].extend );
     
    10231022        devfs_ctx_t * devfs_ctx = hal_remote_lpt( extend_xp );
    10241023       
    1025         root_inode_xp     = hal_remote_lwd( XPTR( io_cxy , &devfs_ctx->root_inode_xp ) );
    1026         external_inode_xp = hal_remote_lwd( XPTR( io_cxy , &devfs_ctx->external_inode_xp ) );
    1027 
    1028         devfs_local_init( root_inode_xp,
    1029                           external_inode_xp );
    1030     }
    1031 
    1032     /////////////////////////////////////////////////////////////////////////////////
    1033     // global &local synchro to protect File System initialisation
     1024        devfs_dev_inode_xp      = hal_remote_lwd( XPTR( io_cxy ,
     1025                                                        &devfs_ctx->dev_inode_xp ) );
     1026        devfs_external_inode_xp = hal_remote_lwd( XPTR( io_cxy ,
     1027                                                        &devfs_ctx->external_inode_xp ) );
     1028
     1029        // populate DEVFS in all clusters
     1030        devfs_local_init( devfs_dev_inode_xp,
     1031                          devfs_external_inode_xp,
     1032                          &devfs_internal_inode_xp );
     1033    }
     1034
     1035    /////////////////////////////////////////////////////////////////////////////////
    10341036    if( core_lid == 0 ) remote_barrier( XPTR( io_cxy , &global_barrier ),
    10351037                                        (info->x_size * info->y_size) );
    10361038    barrier_wait( &local_barrier , info->cores_nr );
     1039    /////////////////////////////////////////////////////////////////////////////////
    10371040
    10381041    if( (core_lid ==  0) && (local_cxy == 0) )
     
    10401043               __FUNCTION__, (uint32_t)hal_time_stamp());
    10411044
    1042     /////////////////////////////////////////////////////////////////////////////////
    1043     // STEP 8 : CP0 in I/O cluster creates the process_init and print banner.
     1045    #if CONFIG_KINIT_DEBUG
     1046    vfs_display( vfs_root_inode_xp );
     1047    #endif
     1048
     1049    /////////////////////////////////////////////////////////////////////////////////
     1050    // STEP 8 : CP0 in I/O cluster creates the first user process (process_init)
    10441051    /////////////////////////////////////////////////////////////////////////////////
    10451052
     
    10501057
    10511058    /////////////////////////////////////////////////////////////////////////////////
    1052     // global syncho to protect access to File System
    10531059    if( core_lid == 0 ) remote_barrier( XPTR( info->io_cxy , &global_barrier ),
    10541060                                        (info->x_size * info->y_size) );
    10551061    barrier_wait( &local_barrier , info->cores_nr );
     1062    /////////////////////////////////////////////////////////////////////////////////
    10561063
    10571064    if( (core_lid ==  0) && (local_cxy == 0) )
  • trunk/kernel/kern/process.c

    r188 r204  
    112112    }
    113113
     114    // initialize PID and PPID
     115        process->pid   = pid;
     116    process->ppid  = parent_pid;
     117
    114118    // reset reference process vmm (not for kernel process)
    115119    if( pid ) vmm_init( process );
     
    152156    spinlock_init( &process->th_lock );
    153157
    154     // initialize PID and PPID
    155         process->pid   = pid;
    156     process->ppid  = parent_pid;
    157 
    158158    // set ref_xp field
    159159    process->ref_xp = XPTR( local_cxy , process );
     
    171171    process_dmsg("\n[INFO] %s : exit for process %x in cluster %x\n",
    172172                 __FUNCTION__ , pid );
    173 }
     173
     174}  // process_reference init()
    174175
    175176/////////////////////////////////////////////////////
     
    230231
    231232    return 0;
    232 }
     233
     234} // end process_copy_init()
    233235
    234236///////////////////////////////////////////
     
    578580
    579581    return (found) ? 0 : ENOMEM;
    580 }
     582
     583}  // end process_register_thread()
     584
    581585///////////////////////////////////////////////
    582586void process_remove_thread( thread_t * thread )
     
    596600    process->th_tbl[ltid] = NULL;
    597601    process->th_nr--;
    598 }
     602
     603}  // process_remove_thread()
    599604
    600605/////////////////////////////////////////////////////
     
    623628    parent_pid = hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) );
    624629
    625     exec_dmsg("\n[INFO] %s enters in cluster %x for path = %s\n",
     630    exec_dmsg("\n[INFO] %s : enters in cluster %x for path = %s\n",
    626631                __FUNCTION__ , local_cxy , path );
    627632
     
    650655    process_reference_init( process , pid , parent_xp );
    651656
    652     exec_dmsg("\n[INFO] %s created process %x cluster %x / path = %s\n",
    653                 __FUNCTION__, parent_pid , local_cxy , path );
     657    exec_dmsg("\n[INFO] %s : created process %x in cluster %x / path = %s\n",
     658                __FUNCTION__, pid , local_cxy , path );
    654659
    655660    // initialize vfs_root and vfs_cwd from parent process
     
    663668
    664669    // initialize embedded fd_array from parent process
    665     process_fd_remote_copy( XPTR( local_cxy , &process->fd_array ),
     670    process_fd_remote_copy( XPTR( local_cxy  , &process->fd_array ),
    666671                            XPTR( parent_cxy , &parent_ptr->fd_array) );
     672
     673    exec_dmsg("\n[INFO] %s : fd_array copied from process %x to process %x\n",
     674                __FUNCTION__, parent_pid , pid );
    667675
    668676        // initialize signal manager TODO ??? [AG]
    669677        // signal_manager_init( process );
    670 
    671     // initialize process VMM
    672         vmm_init( process );
    673 
    674     exec_dmsg("\n[INFO] %s initialized VMM in cluster %x for process %x / path = %s\n",
    675                 __FUNCTION__ , local_cxy , pid , path );
    676678
    677679    // register "code" and "data" vsegs as well as the process entry-point in VMM,
     
    687689        }
    688690
    689     // register "heap" vseg descriptor in VMM
    690     vseg_t * heap_vseg = vmm_create_vseg( process,
    691                                           CONFIG_VMM_HEAP_BASE,
    692                                           CONFIG_VMM_HEAP_SIZE,
    693                                           VSEG_TYPE_HEAP );
    694     if( heap_vseg == NULL )
    695         {
    696                 printk("\n[ERROR] in %s : cannot create heap vseg for process %x / path = %s\n",
    697                        __FUNCTION__, pid , path );
    698         process_destroy( process );
    699         return error;
    700         }
     691    exec_dmsg("\n[INFO] %s : code and data vsegs from <%s> registered for process %x\n",
     692                __FUNCTION__ , path , pid );
    701693
    702694    // select a core in cluster
     
    718710        {
    719711                printk("\n[ERROR] in %s : cannot create thread for process %x / path = %s\n",
    720                        __FUNCTION__, pid , path );
     712                       __FUNCTION__, pid );
    721713        process_destroy( process );
    722714        return error;
    723715        }
     716
     717        exec_dmsg("\n[INFO] %s : thread created for process %x on core %d in cluster %x\n",
     718               __FUNCTION__ , pid , core->lid , local_cxy );
    724719
    725720    // update children list in parent process
     
    731726        sched_register_thread( core , thread );
    732727
    733         exec_dmsg("\n[INFO] %s created thread for process %x on core %d in cluster %x\n",
    734                __FUNCTION__ , pid , core->lid , local_cxy );
    735 
    736728    // activate new thread
    737729        thread_unblock( XPTR( local_cxy , thread ) , THREAD_BLOCKED_GLOBAL );
    738730
     731    exec_dmsg("\n[INFO] %s : exit for process %x\n",
     732                __FUNCTION__, process->pid );
     733
    739734        return 0;
    740 }
     735
     736}  // end proces_make_exec()
    741737
    742738//////////////////////////
     
    755751    uint32_t  stderr_id;
    756752
    757         process_dmsg("\n[INFO] %s enters in cluster %x\n", __FUNCTION__ , local_cxy );
     753        process_dmsg("\n[INFO] %s : enters in cluster %x\n", __FUNCTION__ , local_cxy );
    758754
    759755    // open stdin / stdout / stderr pseudo-files
     
    762758        error3 = vfs_open( XPTR_NULL, CONFIG_DEV_STDERR, O_WRONLY, 0, &stderr_xp, &stderr_id );
    763759
    764         if( error1 || error2 || error3 )
    765         {
    766                 if( !error1 ) vfs_close( stdin_xp  , stdin_id );
    767                 if( !error2 ) vfs_close( stdout_xp , stdout_id );
    768                 if( !error3 ) vfs_close( stderr_xp , stderr_id );
    769                 printk("\n[PANIC] in %s : cannot open stdin/stdout/stderr in cluster %x\n",
    770                __FUNCTION__ , local_cxy );
    771         hal_core_sleep();
    772         }
    773 
    774     // check stdin / stdout / stderr indexes
    775     if( (stdin_id != 0) || (stdout_id != 1) || (stderr_id != 2) )
    776     {
    777                 vfs_close( stdin_xp  , stdin_id );
    778                 vfs_close( stdout_xp , stdout_id );
    779                 vfs_close( stderr_xp , stderr_id );
    780                 printk("\n[PANIC] in %s : bad indexes for stdin/stdout/stderr in cluster %x\n",
    781             __FUNCTION__ , local_cxy );
    782         hal_core_sleep();
    783     }
     760        assert( ((error1 == 0) && (error2 == 0) && (error3 == 0)) , __FUNCTION__ ,
     761            "cannot open stdin/stdout/stderr pseudo files\n");
     762
     763    assert( ((stdin_id == 0) && (stdout_id == 1) && (stderr_id == 2)) , __FUNCTION__ ,
     764            "bad indexes for stdin/stdout/stderr\n");
    784765
    785766    // initialize the exec_info structure
     
    792773        error1 = process_make_exec( &exec_info );
    793774
    794         if( error1 )
    795         {
    796         printk("\n[PANIC] in %s : cannot create main thread in cluster %x\n",
    797                __FUNCTION__ , local_cxy );
    798                 hal_core_sleep();
    799     }
    800 
    801         process_dmsg("\n[INFO] %s successfully exit in cluster %x\n", __FUNCTION__ , local_cxy );
     775        assert( (error1 == 0) , __FUNCTION__ , "cannot create process_init\n");
     776
     777        process_dmsg("\n[INFO] %s : exit in cluster %x\n", __FUNCTION__ , local_cxy );
    802778               
    803779    hal_fence();
    804 }
    805 
     780
     781}  // end process_init_create()
     782
  • trunk/kernel/kern/process.h

    r173 r204  
    144144    xptr_t             parent_xp;      /*! extended pointer on parent process descriptor    */
    145145
    146     xptr_t             stdin_xp;       /*! extended pointer on stdin  pseudo-file           */
    147146    char               path[CONFIG_VFS_MAX_PATH_LENGTH];   /*!  .elf file path              */
    148147
  • trunk/kernel/libk/bits.h

    r23 r204  
    3030
    3131/*********************************************************************************************
    32  * These macros are NOT used by the bitmat, but can be useful in other contexts... [AG]
     32 * These macros are NOT used by the bitmap, but can be useful in other contexts... [AG]
    3333 *********************************************************************************************/
    3434
  • trunk/kernel/libk/elf.c

    r157 r204  
    7575///////////////////////////////////////////////////////////////////////////////////////
    7676// This function loads the .elf header in the buffer allocated by the caller.
     77///////////////////////////////////////////////////////////////////////////////////////
    7778// @ file   : extended pointer on the remote file descriptor.
    7879// @ buffer : pointer on buffer allocated by the caller.
    7980// @ size   : number of bytes to read.
    8081///////////////////////////////////////////////////////////////////////////////////////
    81 static error_t elf_header_read( xptr_t   file_xp,
     82static error_t elf_header_load( xptr_t   file_xp,
    8283                                void   * buffer,
    8384                                uint32_t size )
     
    114115        }
    115116        return 0;
    116 }
     117
     118} // end elf_header_load()
    117119
    118120///////////////////////////////////////////////////////////////////////////////////////
    119121// This function registers in the process VMM the CODE and DATA segments.
     122///////////////////////////////////////////////////////////////////////////////////////
    120123// @ file      : extended pointer on the remote file descriptor.
    121124// @ segs_base : local pointer on buffer containing the segments descriptors array
     
    212215
    213216        return 0;
    214 }
     217
     218} // end elf_segments_load()
    215219
    216220///////////////////////////////////////////////
     
    218222                          process_t * process)
    219223{
    220         char         path_copy[CONFIG_VFS_MAX_PATH_LENGTH];
    221224        kmem_req_t   req;              // kmem request for program header
    222         uint32_t     length;           // actual path length
    223225        Elf32_Ehdr   header;           // local buffer for .elf header
    224226        void       * segs_base;        // pointer on buffer for segment descriptors array
     
    229231        error_t      error;
    230232
    231         // get path length from user space
    232         length = hal_strlen_from_uspace( pathname );
    233 
    234         if( length >= CONFIG_VFS_MAX_PATH_LENGTH )
    235         {
    236                 printk("\n[ERROR] in %s : pathname length too long\n", __FUNCTION__ );
    237                 return -1;
    238         }
    239 
    240         // make a local copy for pathname
    241         hal_copy_from_uspace( path_copy , pathname , length+1 );
     233    elf_dmsg("\n[INFO] %s : enter for %s\n", __FUNCTION__ , pathname );
     234
     235    // avoid GCC warning
     236        file_xp = XPTR_NULL; 
     237        file_id = -1;
    242238
    243239        // open file
    244         file_xp = XPTR_NULL;  // avoid GCC warning
    245         file_id = -1;
    246 
    247240        error = vfs_open( process->vfs_cwd_xp,
    248                           path_copy,
     241                          pathname,
    249242                          O_RDONLY,
    250243                          0,
     
    253246        if( error )
    254247        {
    255                 printk("\n[ERROR] in %s : failed to open executable file %s\n",
    256                        __FUNCTION__ , path_copy );
    257                 return -1;
    258         }
     248                printk("\n[ERROR] in %s : failed to open file %s\n", __FUNCTION__ , pathname );
     249                return -1;
     250        }
     251
     252    elf_dmsg("\n[INFO] %s : file %s open\n", __FUNCTION__ , pathname );
    259253
    260254        // load header in local buffer
    261         error = elf_header_read( file_xp ,
     255        error = elf_header_load( file_xp ,
    262256                                 &header,
    263257                                 sizeof(Elf32_Ehdr) );
    264258        if( error )
    265259        {
    266                 vfs_close( file_xp , file_id );
    267                 return -1;
    268         }
    269 
    270         elf_dmsg("\n[INFO] %s loaded elf header for %s\n", __FUNCTION__ , path_copy );
     260                printk("\n[ERROR] in %s : cannot get header file %s\n", __FUNCTION__ , pathname );
     261                vfs_close( file_xp , file_id );
     262                return -1;
     263        }
     264
     265        elf_dmsg("\n[INFO] %s : loaded elf header for %s\n", __FUNCTION__ , pathname );
    271266
    272267        if( header.e_phnum == 0 )
     
    320315        }
    321316
    322         elf_dmsg("\n[INFO] %s loaded segments descriptors for %s \n", __FUNCTION__ , path_copy );
     317        elf_dmsg("\n[INFO] %s loaded segments descriptors for %s \n", __FUNCTION__ , pathname );
    323318
    324319        // register loadable segments in process VMM
     
    346341
    347342        elf_dmsg("\n[INFO] %s successfully completed / entry point = %x for %s]\n",
    348                  __FUNCTION__, (uint32_t) header.e_entry , path_copy );
     343                 __FUNCTION__, (uint32_t) header.e_entry , pathname );
    349344
    350345        return 0;
    351 }
    352 
     346
     347}  // end elf_load_process()
     348
  • trunk/kernel/libk/elf.h

    r158 r204  
    182182 * It also registers the process entry point in VMM.
    183183 ****************************************************************************************
    184  * @ pathname : .elf file pathname (in user space => must use hal_uspace API).
     184 * @ pathname : local pointer on .elf file pathname (in kernel space).
    185185 * @ process  : local pointer on target process descriptor.
    186186 ***************************************************************************************/
  • trunk/kernel/libk/xhtab.c

    r188 r204  
    7676// returns true if given name matches directory entry name.
    7777////////////////////////////////////////////////////////////////////////////////////////////
    78 static bool_t xhtab_dentry_item_match_key( xptr_t item_xp,
     78static bool_t xhtab_dentry_item_match_key( xptr_t    item_xp,
    7979                                           void    * key )
    8080{
    81     vfs_dentry_t * dentry_ptr;
    82     cxy_t          dentry_cxy;
    83 
    84     char           name[CONFIG_VFS_MAX_NAME_LENGTH];
     81    char name[CONFIG_VFS_MAX_NAME_LENGTH];
    8582
    8683    // get dentry cluster and local pointer
    87     dentry_cxy = GET_CXY( item_xp );
    88     dentry_ptr = (vfs_dentry_t *)GET_PTR( item_xp );
     84    cxy_t          dentry_cxy = GET_CXY( item_xp );
     85    vfs_dentry_t * dentry_ptr = (vfs_dentry_t *)GET_PTR( item_xp );
    8986
    9087    // make a local copy of directory entry name
     
    9491    return( strcmp( name , (char*)key ) == 0 );
    9592}
    96                        
     93
     94////////////////////////////////////////////////////////////////////////////////////////////
     95// This function print the item key, that is the name for a vfs_entry_t,
     96////////////////////////////////////////////////////////////////////////////////////////////
     97// @ item_xp   : extended pointer on item.
     98////////////////////////////////////////////////////////////////////////////////////////////
     99static void xhtab_dentry_item_print_key( xptr_t item_xp )
     100{
     101    char name[CONFIG_VFS_MAX_NAME_LENGTH];
     102
     103    // get dentry cluster and local pointer
     104    cxy_t          dentry_cxy = GET_CXY( item_xp );
     105    vfs_dentry_t * dentry_ptr = (vfs_dentry_t *)GET_PTR( item_xp );
     106   
     107    // make a local copy of directory entry name
     108    hal_remote_strcpy( XPTR( local_cxy , name ) ,
     109                       XPTR( dentry_cxy , &dentry_ptr->name ) );
     110
     111    // print dentry name
     112    printk("%s , ", name );
     113}                       
     114
    97115////////////////////////////////////////////////////////////////////////////////////////
    98116//         Generic access functions
     
    108126    remote_rwlock_init( XPTR( local_cxy , &xhtab->lock) );
    109127
    110     xhtab->items  = 0;
     128    xhtab->items            = 0;
     129    xhtab->current_index    = 0;
     130    xhtab->current_xlist_xp = XPTR_NULL;
    111131
    112132    if( type == XHTAB_DENTRY_TYPE )
     
    115135        xhtab->index_from_key  = &xhtab_dentry_index_from_key;
    116136        xhtab->item_from_xlist = &xhtab_dentry_item_from_xlist;
     137        xhtab->item_print_key  = &xhtab_dentry_item_print_key;
    117138    }
    118139    else
     
    134155                   void    * key )
    135156{
    136     xptr_t    xlist_xp;                                 // xlist_entry_t (iterator)
    137     xptr_t    item_xp;                                  // associated item
    138     xhtab_t * xhtab_ptr;                                // hash table local pointer
    139     cxy_t     xhtab_cxy;                                // hash table cluster
     157    xptr_t              xlist_xp;           // xlist_entry_t (iterator)
     158    xptr_t              item_xp;            // associated item
     159    xhtab_t           * xhtab_ptr;          // hash table local pointer
     160    cxy_t               xhtab_cxy;          // hash table cluster
     161    item_from_xlist_t * item_from_xlist;    // function pointer
     162    item_match_key_t  * item_match_key;     // function pointer
    140163
    141164    // get hash table cluster and local pointer
    142165    xhtab_cxy = GET_CXY( xhtab_xp );
    143166    xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
     167
     168    // get pointer on "item_from_xlist" function
     169    item_from_xlist = (item_from_xlist_t *)hal_remote_lpt( XPTR( xhtab_cxy ,
     170                                                           &xhtab_ptr->item_from_xlist ) );
     171    // get pointer on "item_match_key" function
     172    item_match_key = (item_match_key_t *)hal_remote_lpt( XPTR( xhtab_cxy ,
     173                                                         &xhtab_ptr->item_match_key ) );
    144174
    145175    // scan sub-list[index]
     
    147177    {
    148178        // get extended pointer on item containing the xlist entry
    149             item_xp = xhtab_ptr->item_from_xlist( xlist_xp );
     179            item_xp = item_from_xlist( xlist_xp );
    150180
    151181        // check matching
    152         if( xhtab_ptr->item_match_key( item_xp , key ) ) return item_xp;
     182        if( item_match_key( item_xp , key ) ) return item_xp;
    153183    }
    154184
    155185    // No matching item found
    156186    return XPTR_NULL;
    157 }
     187
     188}  // end xhtab_scan()
    158189
    159190///////////////////////////////////////
     
    162193                      xptr_t   xlist_xp )
    163194{
    164     // get xhtab cluster and local pointer
    165     cxy_t     xhtab_cxy = GET_CXY( xhtab_xp );
    166     xhtab_t * xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
    167 
     195    xptr_t             item_xp;
     196    uint32_t           index;
     197    cxy_t              xhtab_cxy;
     198    xhtab_t          * xhtab_ptr;
     199    index_from_key_t * index_from_key;     // function pointer
     200   
     201    // get xhtab cluster and local pointer
     202    xhtab_cxy = GET_CXY( xhtab_xp );
     203    xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
     204
     205    // get pointer on "index_from_key" function
     206    index_from_key = (index_from_key_t *)hal_remote_lpt( XPTR( xhtab_cxy ,
     207                                                         &xhtab_ptr->index_from_key ) );
    168208    // compute index from key
    169         uint32_t index = xhtab_ptr->index_from_key( key );
     209        index = index_from_key( key );
    170210
    171211    // take the lock protecting hash table
     
    173213
    174214    // search a matching item
    175     xptr_t item_xp = xhtab_scan( xhtab_xp , index , key );
     215    item_xp = xhtab_scan( xhtab_xp , index , key );
    176216
    177217    if( item_xp != XPTR_NULL )    // error if found
     
    202242                      xptr_t   xlist_entry_xp )
    203243{
    204     // get xhtab cluster and local pointer
    205     cxy_t     xhtab_cxy = GET_CXY( xhtab_xp );
    206     xhtab_t * xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
    207 
     244    xptr_t             item_xp;
     245    uint32_t           index;
     246    cxy_t              xhtab_cxy;
     247    xhtab_t          * xhtab_ptr;
     248    index_from_key_t * index_from_key;     // function pointer
     249
     250    // get xhtab cluster and local pointer
     251    xhtab_cxy = GET_CXY( xhtab_xp );
     252    xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
     253
     254    // get pointer on "index_from_key" function
     255    index_from_key = (index_from_key_t *)hal_remote_lpt( XPTR( xhtab_cxy ,
     256                                                         &xhtab_ptr->index_from_key ) );
    208257    // compute index from key
    209         uint32_t index = xhtab_ptr->index_from_key( key );
     258        index = index_from_key( key );
    210259
    211260    // take the lock protecting hash table
     
    213262
    214263    // get extended pointer on item to remove
    215     xptr_t item_xp = xhtab_scan( xhtab_xp , index , key );
     264    item_xp = xhtab_scan( xhtab_xp , index , key );
    216265
    217266    if( item_xp == XPTR_NULL )    // error if not found
     
    241290                      void    * key )
    242291{
    243     xptr_t  item_xp;
    244 
    245     // get xhtab cluster and local pointer
    246     cxy_t     xhtab_cxy = GET_CXY( xhtab_xp );
    247     xhtab_t * xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
    248 
     292    xptr_t             item_xp;
     293    uint32_t           index;
     294    cxy_t              xhtab_cxy;
     295    xhtab_t          * xhtab_ptr;
     296    index_from_key_t * index_from_key;     // function pointer
     297
     298    // get xhtab cluster and local pointer
     299    xhtab_cxy = GET_CXY( xhtab_xp );
     300    xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
     301
     302    // get pointer on "index_from_key" function
     303    index_from_key = (index_from_key_t *)hal_remote_lpt( XPTR( xhtab_cxy ,
     304                                                         &xhtab_ptr->index_from_key ) );
    249305    // compute index from key
    250         uint32_t index = xhtab_ptr->index_from_key( key );
     306        index = index_from_key( key );
    251307
    252308    // take the lock protecting hash table
     
    288344xptr_t xhtab_get_first( xptr_t xhtab_xp )
    289345{
    290     uint32_t index;
    291     xptr_t   xlist_xp;
    292     xptr_t   item_xp;
    293     xptr_t   root_xp;
    294 
    295     // get xhtab cluster and local pointer
    296     cxy_t     xhtab_cxy = GET_CXY( xhtab_xp );
    297     xhtab_t * xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
    298 
     346    uint32_t            index;
     347    cxy_t               xhtab_cxy;
     348    xhtab_t           * xhtab_ptr;
     349    xptr_t              xlist_xp;
     350    xptr_t              item_xp;
     351    xptr_t              root_xp;
     352    item_from_xlist_t * item_from_xlist;   // function pointer
     353
     354    // get xhtab cluster and local pointer
     355    xhtab_cxy = GET_CXY( xhtab_xp );
     356    xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
     357
     358    // get pointer on "item_from_xlist" function
     359    item_from_xlist = (item_from_xlist_t *)hal_remote_lpt( XPTR( xhtab_cxy ,
     360                                                           &xhtab_ptr->item_from_xlist ) );
    299361    //loop on subsets
    300362    for( index = 0 ; index < XHASHTAB_SIZE ; index++ )
     
    309371        {
    310372            // get extended pointer on item containing the xlist entry
    311                 item_xp = xhtab_ptr->item_from_xlist( xlist_xp );
     373                item_xp = item_from_xlist( xlist_xp );
    312374
    313375            // register item in hash table header
     
    327389xptr_t xhtab_get_next( xptr_t xhtab_xp )
    328390{
    329     uint32_t index;
    330     xptr_t   xlist_xp;
    331     xptr_t   item_xp;
    332     xptr_t   root_xp;
     391    uint32_t            index;
     392    cxy_t               xhtab_cxy;
     393    xhtab_t           * xhtab_ptr;
     394    xptr_t              xlist_xp;
     395    xptr_t              item_xp;
     396    xptr_t              root_xp;
     397    item_from_xlist_t * item_from_xlist;   // function pointer
    333398
    334399    uint32_t current_index;
     
    336401
    337402    // get xhtab cluster and local pointer
    338     cxy_t     xhtab_cxy = GET_CXY( xhtab_xp );
    339     xhtab_t * xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
     403    xhtab_cxy = GET_CXY( xhtab_xp );
     404    xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
    340405
    341406    // get current item pointers
     
    343408    current_xlist_xp = hal_remote_lwd( XPTR( xhtab_cxy , &xhtab_ptr->current_xlist_xp ) );
    344409
     410    // get pointer on "item_from_xlist" function
     411    item_from_xlist = (item_from_xlist_t *)hal_remote_lpt( XPTR( xhtab_cxy ,
     412                                                           &xhtab_ptr->item_from_xlist ) );
    345413    //loop on subsets
    346414    for( index = current_index ; index < XHASHTAB_SIZE ; index++ )
     
    350418
    351419        // get next item
    352         xlist_xp = xlist_next( root_xp , current_xlist_xp );
     420        if( index == current_index ) xlist_xp = xlist_next( root_xp , current_xlist_xp );
     421        else                         xlist_xp = xlist_next( root_xp , root_xp );
    353422
    354423        if( xlist_xp != XPTR_NULL )  // next item found
    355424        {
    356425            // get extended pointer on item containing the xlist entry
    357                 item_xp = xhtab_ptr->item_from_xlist( xlist_xp );
     426                item_xp = item_from_xlist( xlist_xp );
    358427
    359428            // register item in hash table header
     
    370439} // end xhtab_get_next()
    371440
    372 
     441/////////////////////////////////////
     442void xhtab_display( xptr_t xhtab_xp )
     443{
     444    uint32_t            index;
     445    cxy_t               xhtab_cxy;
     446    xhtab_t           * xhtab_ptr;
     447    xptr_t              root_xp;
     448    xptr_t              iter_xp;
     449    xptr_t              item_xp;
     450    item_from_xlist_t * item_from_xlist;   // function pointer
     451    item_print_key_t  * item_print_key;    // function pointer
     452
     453    // get xhtab cluster and local pointer
     454    xhtab_cxy = GET_CXY( xhtab_xp );
     455    xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
     456
     457    // get pointer on "item_from_xlist" function
     458    item_from_xlist = (item_from_xlist_t *)hal_remote_lpt( XPTR( xhtab_cxy ,
     459                                                           &xhtab_ptr->item_from_xlist ) );
     460    // get pointer on "item_print_key" function
     461    item_print_key = (item_print_key_t *)hal_remote_lpt( XPTR( xhtab_cxy ,
     462                                                         &xhtab_ptr->item_print_key ) );
     463    //loop on subsets
     464    for( index = 0 ; index < XHASHTAB_SIZE ; index++ )
     465    {
     466        printk(" index = %d : ", index );
     467
     468        // get root of subset
     469        root_xp = XPTR( xhtab_cxy , &xhtab_ptr->roots[index] );
     470
     471        // loop on xlist
     472        XLIST_FOREACH( root_xp , iter_xp )
     473        {
     474            // get item from xlist
     475            item_xp = item_from_xlist( iter_xp );
     476           
     477            // print item identifier
     478            item_print_key( item_xp );
     479        }
     480
     481        printk("\n");
     482    }
     483}  // end xhtab_display()
  • trunk/kernel/libk/xhtab.h

    r188 r204  
    3636// It can be accessed by any thread, running in any cluster.
    3737// It is generic as it can be used to register various types of items.
    38 // The main goal is to speedup search by key for a large number of items of same type.
     38// The main goal is to speedup search by key in a large number of items of same type.
    3939// For this purpose the set of all registered items is split in several subsets.
    4040// Each subset is organised as an embedded double linked lists.
    4141// - an item is uniquely identified by a <key>, that is a single uint32_t value.
    42 // - From the <key> value,the hash table uses an item type specific xhtab_index() function,
    43 //   to compute an <index> value, defining a subset of registered items.
     42// - From the <key> value, the hash table uses an item type specific xhtab_index()
     43//   function, to compute an <index> value, defining a subset of registered items.
    4444// - to discriminate between items that have the same <index>, the hash table makes
    45 //   an associative search in subset.
     45//   an associative search on the key in subset.
    4646// - Each registered item is a structure, that must contain an embedded xlist_entry,
    4747//   that is part of the xlist implementing the subset.
    4848//
    49 // A total order is defined for all registered items by the increasing index values,
    50 // and for each index value by the position in the partial xlist.
     49// For all registered items, a total order is defined by the increasing index values,
     50// and for each index value, by the position in the partial xlist.
    5151// This order is used by the two functions xhtab_get_first() and xhtab_get_next(), that
    5252// are used to scan all registered items. The two "current_index" and "current_xlist_xp"
     
    5454//
    5555// Implementation Note:
    56 // For each supported item type ***, you must define the three item-type-specific
     56// For each supported item type ***, you must define four item-type-specific
    5757// functions specified below, and you must update the xhtab_init() function
    5858// and the xhtab_item_type_t.
    5959///////////////////////////////////////////////////////////////////////////////////////////
    6060
    61 #define XHASHTAB_SIZE    64   // number of subsets
     61#define XHASHTAB_SIZE    8   // number of subsets
    6262
    6363/******************************************************************************************
    64  * This define the three item type specific function prototypes.
     64 * This define the four item_type_specific function prototypes that must be defined
     65 * for each item type.
    6566 *****************************************************************************************/
    6667
    67 typedef  bool_t    xhtab_match_t ( xptr_t item_xp , void * key );
    68 typedef  xptr_t    xhtab_item_t  ( xptr_t xlist_xp );
    69 typedef  uint32_t  xhtab_index_t ( void * key );
     68typedef  bool_t    (item_match_key_t)   ( xptr_t item_xp , void * key );
     69typedef  xptr_t    (item_from_xlist_t)  ( xptr_t xlist_xp );
     70typedef  uint32_t  (index_from_key_t)   ( void * key );
     71typedef  void      (item_print_key_t)   ( xptr_t item_xp );
    7072
    7173/******************************************************************************************
     
    8587typedef struct xhtab_s
    8688{
    87         xlist_entry_t      roots[XHASHTAB_SIZE];  /*! array of roots of xlist                */
    88     xhtab_index_t    * index_from_key;        /*! item specific function                 */
    89     xhtab_match_t    * item_match_key;        /*! item specific function                 */
    90     xhtab_item_t     * item_from_xlist;       /*! item specific function                 */
    91     uint32_t           items;                 /*! number of registered items             */
    92     remote_rwlock_t    lock;                  /*! lock protecting hash table accesses    */
    93     uint32_t           current_index;         /*! current item subset index              */
    94     xptr_t           * current_xlist_xp;      /*! xptr on current item xlist entry       */
     89        xlist_entry_t       roots[XHASHTAB_SIZE];  /*! array of roots of xlist               */
     90    index_from_key_t  * index_from_key;        /*! item specific function pointer        */
     91    item_match_key_t  * item_match_key;        /*! item specific function pointer        */
     92    item_from_xlist_t * item_from_xlist;       /*! item specific function pointer        */
     93    item_print_key_t  * item_print_key;        /*! item specific function pointer        */
     94    uint32_t            items;                 /*! number of registered items            */
     95    remote_rwlock_t     lock;                  /*! lock protecting hash table accesses   */
     96    uint32_t            current_index;         /*! current item subset index             */
     97    xptr_t              current_xlist_xp;      /*! xptr on current item xlist entry      */
    9598}
    9699xhtab_t;
     
    100103 * The initialisation must be done by a thread running in cluster containing the table.
    101104 ******************************************************************************************
    102  * @ xhtab   : local pointer on local xhtab to be initialized.
    103  * @ type    : item type (see above).
     105 * @ xhtab    : local pointer on local xhtab to be initialized.
     106 * @ type     : item type (see above).
    104107 *****************************************************************************************/
    105108void xhtab_init( xhtab_t           * xhtab,
     
    176179xptr_t xhtab_get_next( xptr_t xhtab_xp );
    177180
    178 
     181/******************************************************************************************
     182 * This function displays the full content of an xhtab.
     183 ******************************************************************************************
     184 * @ xhtab_xp  : extended pointer on hash table.
     185 *****************************************************************************************/
     186void xhtab_display( xptr_t  xhtab_xp );
    179187
    180188#endif  /* _XHTAB_H_ */
  • trunk/kernel/mm/mapper.c

    r183 r204  
    8888
    8989    return mapper;
    90 }
     90
     91}  // end mapper_create()
    9192
    9293///////////////////////////////////////////
     
    127128
    128129    return 0;
    129 }
     130
     131}  // end mapper_destroy()
    130132
    131133////////////////////////////////////////////
     
    137139    error_t       error;
    138140
     141    mapper_dmsg("\n[INFO] %s : enter for page %d / mapper = %x\n",
     142                __FUNCTION__ , index , mapper );
     143
    139144    thread_t * this = CURRENT_THREAD;
    140145
     
    148153    if( ( page == NULL) || page_is_flag( page , PG_INLOAD ) )  // page not available
    149154    {
     155
    150156        // release the lock in READ_MODE and take it in WRITE_MODE
    151157        rwlock_rd_unlock( &mapper->lock );
     
    160166        if ( page == NULL )   // missing page => load it from file system
    161167        {
     168            mapper_dmsg("\n[INFO] %s : missing page => load from FS\n", __FUNCTION__ );
     169
    162170            // allocate one page from PPM
    163171            req.type  = KMEM_PAGE;
     
    237245                sched_yield();
    238246            }
    239 
    240         }
    241 
    242         return page;
    243     }
    244     else
    245     {
    246          // release lock from READ_MODE
    247          rwlock_rd_unlock( &mapper->lock );
    248 
    249          return page;
    250     }
    251 }
     247        }
     248    }
     249    else                          // page available in mapper
     250    {
     251
     252        rwlock_rd_unlock( &mapper->lock );
     253    }
     254
     255    mapper_dmsg("\n[INFO] %s : exit for page %d / page desc = %x\n",
     256                __FUNCTION__ , index , page );
     257
     258    return page;
     259
     260}  // end mapper_get_page()
    252261
    253262///////////////////////////////////////////////
     
    282291
    283292    return 0;
    284 }
     293
     294}  // end mapper_release_page()
    285295
    286296/////////////////////////////////////////
     
    298308    uint8_t  * map_ptr;        // current mapper  address
    299309    uint8_t  * buf_ptr;        // current buffer  address
     310 
     311    mapper_dmsg("\n[INFO] %s : enter / to_buf = %d / buffer = %x\n",
     312                __FUNCTION__ , to_buffer , buffer );
    300313
    301314    // compute offsets of first and last bytes in file
     
    347360    }
    348361
     362    mapper_dmsg("\n[INFO] %s : exit for buffer %x\n",
     363                __FUNCTION__, buffer );
     364
    349365    return 0;
    350 }
    351 
     366
     367}  // end mapper_move()
     368
  • trunk/kernel/mm/mapper.h

    r23 r204  
    5050 *   readers, and only one writer. This lock implement a busy waiting policy.
    5151 * - The two functions vfs_move_page_to_mapper() and vfs_move_page_from_mapper() define
    52  *   the generic API used to move pages to or from the relevant file system on IOC device.
     52 *   the generic API used to move pages to or from the relevant file system.
    5353 * - the mapper_move() function is used to move data to or from a, possibly distributed
    5454 *   user buffer in user space.
     
    122122 * The offset in the file descriptor is not modified by this function.
    123123 *******************************************************************************************
    124  * @ mapper       : extended pointer on local mapper.
     124 * @ mapper       : local pointer on local mapper.
    125125 * @ to_buffer    : move data from mapper to buffer if true.
    126126 * @ file_offset  : first byte to move in file.
  • trunk/kernel/mm/vmm.c

    r179 r204  
    6262    intptr_t  size;
    6363
     64    vmm_dmsg("\n[INFO] %s : enter for process %x\n", __FUNCTION__ , process->pid );
     65
    6466    // get pointer on VMM
    6567    vmm_t   * vmm = &process->vmm;
    6668
    67     // check UTILS zone size
    68     if( (CONFIG_VMM_KENTRY_SIZE + CONFIG_VMM_ARGS_SIZE + CONFIG_VMM_ENVS_SIZE ) >
    69         CONFIG_VMM_ELF_BASE )
    70     {
    71         printk("\n[PANIC] in %s : UTILS zone too small for process %x\n",
    72                __FUNCTION__ , process->pid );
    73         hal_core_sleep();
    74     }
    75 
    76     // check max number of stacks slots
    77     if( CONFIG_THREAD_MAX_PER_CLUSTER > 32 )
    78     {
    79         printk("\n[PANIC] in %s : max number of threads per cluster for a single process"
    80                " cannot be larger than 32\n", __FUNCTION__ );
    81         hal_core_sleep();
    82     }
    83 
    84     // check STACK zone size
    85     if( (CONFIG_VMM_STACK_SIZE * CONFIG_THREAD_MAX_PER_CLUSTER) >
    86         (CONFIG_VMM_VSPACE_SIZE - CONFIG_VMM_STACK_BASE) )
    87     {
    88         printk("\n[PANIC] in %s : STACK zone too small for process %x\n",
    89                __FUNCTION__ , process->pid );
    90         hal_core_sleep();
    91     }
     69    assert( ((CONFIG_VMM_KENTRY_SIZE + CONFIG_VMM_ARGS_SIZE + CONFIG_VMM_ENVS_SIZE)
     70            <= CONFIG_VMM_ELF_BASE) , __FUNCTION__ , "UTILS zone too small\n" );
     71
     72    assert( (CONFIG_THREAD_MAX_PER_CLUSTER <= 32) , __FUNCTION__ ,
     73            "no more than 32 threads per cluster for a single process\n");
     74
     75    assert( ((CONFIG_VMM_STACK_SIZE * CONFIG_THREAD_MAX_PER_CLUSTER) <=
     76             (CONFIG_VMM_VSPACE_SIZE - CONFIG_VMM_STACK_BASE)) , __FUNCTION__ ,
     77             "STACK zone too small\n");
    9278
    9379    // initialize the rwlock protecting the vsegs list
     
    10187                        CONFIG_VMM_GRDXT_W2,
    10288                        CONFIG_VMM_GRDXT_W3 );
    103     if( error )
    104     {
    105         printk("\n[PANIC] in %s : cannot initialize radix tree for process %x\n",
    106                __FUNCTION__ , process->pid );
    107         hal_core_sleep();
    108     }
     89 
     90    assert( (error == 0) , __FUNCTION__ , "cannot initialize radix tree\n" );
    10991
    11092    // register kentry vseg in VMM
     
    11294    size = CONFIG_VMM_KENTRY_SIZE << CONFIG_PPM_PAGE_SHIFT;
    11395    vseg_kentry = vmm_create_vseg( process , base , size , VSEG_TYPE_CODE );
    114     if( vseg_kentry == NULL )
    115     {
    116         printk("\n[PANIC] in %s : cannot register kent vseg for process %x\n",
    117                __FUNCTION__ , process->pid );
    118         hal_core_sleep();
    119     }
     96
     97    assert( (vseg_kentry != NULL) , __FUNCTION__ , "cannot register kentry vseg\n" );
     98
    12099    vmm->kent_vpn_base = 1;
    121100
     
    124103    size = CONFIG_VMM_ARGS_SIZE << CONFIG_PPM_PAGE_SHIFT;
    125104    vseg_args = vmm_create_vseg( process , base , size , VSEG_TYPE_DATA );
    126     if( vseg_args == NULL )
    127     {
    128         printk("\n[PANIC] in %s : cannot register args vseg for process %x\n",
    129                __FUNCTION__ , process->pid );
    130         hal_core_sleep();
    131     }
     105
     106    assert( (vseg_args != NULL) , __FUNCTION__ , "cannot register args vseg\n" );
     107
    132108    vmm->args_vpn_base = CONFIG_VMM_KENTRY_SIZE + 1;
    133109
     
    136112    size = CONFIG_VMM_ENVS_SIZE << CONFIG_PPM_PAGE_SHIFT;
    137113    vseg_envs = vmm_create_vseg( process , base , size , VSEG_TYPE_DATA );
    138     if( vseg_envs == NULL )
    139     {
    140         printk("\n[PANIC] in %s : cannot register envs vseg for process %x\n",
    141                __FUNCTION__ , process->pid );
    142         hal_core_sleep();
    143     }
     114
     115    assert( (vseg_envs != NULL) , __FUNCTION__ , "cannot register envs vseg\n" );
     116
    144117    vmm->envs_vpn_base = CONFIG_VMM_KENTRY_SIZE + CONFIG_VMM_ARGS_SIZE + 1;
    145118
     
    148121    size = (CONFIG_VMM_MMAP_BASE-CONFIG_VMM_HEAP_BASE) << CONFIG_PPM_PAGE_SHIFT;
    149122    vseg_heap = vmm_create_vseg( process , base , size , VSEG_TYPE_HEAP );
    150     if( vseg_heap == NULL )
    151     {
    152         printk("\n[PANIC] in %s : cannot register heap vseg in for process %x\n",
    153                __FUNCTION__ , process->pid );
    154         hal_core_sleep();
    155     }
     123
     124    assert( (vseg_heap != NULL) , __FUNCTION__ , "cannot register heap vseg\n" );
     125
    156126    vmm->heap_vpn_base = CONFIG_VMM_HEAP_BASE;
    157127
    158128    // initialize generic page table
    159129    error = hal_gpt_create( &vmm->gpt );
    160     if( error )
    161     {
    162         printk("PANIC in %s : cannot initialize page table\n", __FUNCTION__ );
    163         hal_core_sleep();
    164     }
     130
     131    assert( (error == 0) , __FUNCTION__ , "cannot initialize page table\n");
    165132
    166133    // initialize STACK allocator
     
    181148
    182149    hal_fence();
    183 }
     150
     151    vmm_dmsg("\n[INFO] %s : exit for process %x\n", __FUNCTION__ , process->pid );
     152
     153}  // end vmm_init()
    184154
    185155//////////////////////////////////////////
     
    301271
    302272    return 0;
    303 }
     273
     274}  // vmm_copy()
    304275
    305276///////////////////////////////////////
     
    342313    // release memory allocated to the local page table
    343314    hal_gpt_destroy( &vmm->gpt );
    344 }
     315
     316}  // end vmm_destroy()
    345317
    346318/////////////////////////////////////////////////
     
    357329        {
    358330                vseg = LIST_ELEMENT( iter , vseg_t , list );
     331
    359332                if( ((vpn_base + vpn_size) > vseg->vpn_base) &&
    360333             (vpn_base < (vseg->vpn_base + vseg->vpn_size)) ) return vseg;
    361334        }
    362335    return NULL;
    363 }
     336
     337}  // end vmm_check_conflict()
    364338
    365339////////////////////////////////////////////////////////////////////////////////////////////
     
    399373    *vpn_size = CONFIG_VMM_STACK_SIZE - 1;
    400374    return 0;
    401 }
     375
     376} // end vmm_stack_alloc()
    402377
    403378////////////////////////////////////////////////////////////////////////////////////////////
     
    464439    *vpn_size = size;
    465440    return 0;
    466 }
     441
     442}  // end vmm_mmap_alloc()
    467443
    468444//////////////////////////////////////////////
     
    473449{
    474450    vseg_t     * vseg;          // created vseg pointer
    475     vpn_t        vpn_base;      // vseg first page
     451    vpn_t        vpn_base;      // first page index
    476452    vpn_t        vpn_size;      // number of pages
    477453        error_t      error;
     
    480456        vmm_t * vmm = &process->vmm;
    481457
    482         vmm_dmsg("\n[INFO] %s enter for process %x / base = %x / size = %x / type = %s\n",
     458        vmm_dmsg("\n[INFO] %s : enter for process %x / base = %x / size = %x / type = %s\n",
    483459                     __FUNCTION__ , process->pid , base , size , vseg_type_str(type) );
    484460
    485     // compute base, size, vpn_base, vpn_size, depending on type
     461    // compute base, size, vpn_base, vpn_size, depending on vseg type
    486462    // we use the VMM specific allocators for STACK and MMAP vsegs
    487463    if( type == VSEG_TYPE_STACK )
     
    520496    else
    521497    {
    522         vpn_base = ARROUND_DOWN( base , CONFIG_PPM_PAGE_SIZE ) >> CONFIG_PPM_PAGE_SHIFT;
    523             vpn_size = ARROUND_UP( base + size , CONFIG_PPM_PAGE_SIZE ) >> CONFIG_PPM_PAGE_SHIFT;
     498        uint32_t vpn_min = base >> CONFIG_PPM_PAGE_SHIFT;
     499        uint32_t vpn_max = (base + size - 1) >> CONFIG_PPM_PAGE_SHIFT;
     500
     501        vpn_base = vpn_min;
     502            vpn_size = vpn_max - vpn_min + 1;
    524503    }
    525504
     
    555534        rwlock_wr_unlock( &vmm->vsegs_lock );
    556535
    557         vmm_dmsg("\n[INFO] : %s exit for process %x, vseg [%x, %x] has been mapped\n",
     536        vmm_dmsg("\n[INFO] %s : exit for process %x / vseg [%x, %x] has been mapped\n",
    558537                     __FUNCTION__ , process->pid , vseg->min , vseg->max );
    559538
  • trunk/kernel/vfs/devfs.c

    r188 r204  
    5353/////////////////////////////////////////////
    5454void devfs_ctx_init( devfs_ctx_t * devfs_ctx,
    55                      xptr_t        devfs_root_inode_xp,
     55                     xptr_t        devfs_dev_inode_xp,
    5656                     xptr_t        devfs_external_inode_xp )
    5757{
    58     devfs_ctx->root_inode_xp     = devfs_root_inode_xp;
     58    devfs_ctx->dev_inode_xp      = devfs_dev_inode_xp;
    5959    devfs_ctx->external_inode_xp = devfs_external_inode_xp;
    6060
     
    7474///////////////////////////////////////////////////
    7575void devfs_global_init( xptr_t   parent_inode_xp,
    76                         xptr_t * devfs_root_inode_xp,
     76                        xptr_t * devfs_dev_inode_xp,
    7777                        xptr_t * devfs_external_inode_xp )
    7878{
     
    8686                                     "dev",
    8787                                     NULL,
    88                                      devfs_root_inode_xp );
     88                                     devfs_dev_inode_xp );
    8989
    9090    nolock_assert( (error == 0) , __FUNCTION__ , "cannot create <dev>\n" );
     
    9494                                     INODE_TYPE_DIR,
    9595                                     FS_TYPE_DEVFS,
    96                                      *devfs_root_inode_xp,
    97                                      "dev",
     96                                     *devfs_dev_inode_xp,
     97                                     "external",
    9898                                     NULL,
    9999                                     devfs_external_inode_xp );
     
    102102}
    103103
    104 //////////////////////////////////////////////////
    105 void devfs_local_init( xptr_t devfs_root_inode_xp,
    106                        xptr_t devfs_external_inode_xp )
     104///////////////////////////////////////////////////
     105void devfs_local_init( xptr_t   devfs_dev_inode_xp,
     106                       xptr_t   devfs_external_inode_xp,
     107                       xptr_t * devfs_internal_inode_xp )
    107108{
    108109    char          node_name[16];
     
    110111    cxy_t         chdev_cxy;
    111112    xptr_t        inode_xp;
    112     xptr_t        internal_inode_xp;
    113113    uint32_t      channel;
    114114
     
    118118                             INODE_TYPE_DIR,
    119119                             FS_TYPE_DEVFS,
    120                              devfs_root_inode_xp,
     120                             devfs_dev_inode_xp,
    121121                             node_name,
    122122                             NULL,
    123                              &internal_inode_xp );
    124 
    125     // create ICU chdev inode
    126     chdev_xp = chdev_dir.icu[local_cxy];
    127     if( chdev_xp != XPTR_NULL) 
     123                             devfs_internal_inode_xp );
     124
     125    // create MMC chdev inode
     126    chdev_xp = chdev_dir.mmc[local_cxy];
     127    if( chdev_xp != XPTR_NULL)
    128128    {
    129129        vfs_add_child_in_parent( local_cxy,
    130130                                 INODE_TYPE_DEV,
    131131                                 FS_TYPE_DEVFS,
    132                                  internal_inode_xp,
    133                                  "icu",
    134                                  GET_PTR( chdev_xp ),
    135                                  &inode_xp );
    136     }
    137 
    138     // create MMC chdev inode
    139     chdev_xp = chdev_dir.mmc[local_cxy];
    140     if( chdev_xp != XPTR_NULL)
    141     {
    142         vfs_add_child_in_parent( local_cxy,
    143                                  INODE_TYPE_DEV,
    144                                  FS_TYPE_DEVFS,
    145                                  internal_inode_xp,
     132                                 *devfs_internal_inode_xp,
    146133                                 "mmc",
    147134                                 GET_PTR( chdev_xp ),
     
    159146                                     INODE_TYPE_DEV,
    160147                                     FS_TYPE_DEVFS,
    161                                      internal_inode_xp,
     148                                     *devfs_internal_inode_xp,
    162149                                     node_name,
    163150                                     GET_PTR( chdev_xp ),
  • trunk/kernel/vfs/devfs.h

    r188 r204  
    5151typedef struct devfs_ctx_s
    5252{
    53     xptr_t   root_inode_xp;              /*! extended pointer on DEVFS root inode       */
     53    xptr_t   dev_inode_xp;               /*! extended pointer on DEVFS root inode       */
    5454    xptr_t   external_inode_xp;          /*! extended pointer on DEVFS external inode   */
    5555}
     
    6969 *****************************************************************************************
    7070 * @ devfs_ctx               : local pointer on DEVFS context.
    71  * @ devfs_root_inode_xp     : [out] extended pointer on created <dev> inode.
    72  * @ devfs_external_inode_xp : [out] extended pointer on created <external> inode.
     71 * @ devfs_dev_inode_xp      : [out] extended pointer on <dev> inode.
     72 * @ devfs_external_inode_xp : [out] extended pointer on <external> inode.
    7373 ****************************************************************************************/
    7474void devfs_ctx_init( devfs_ctx_t * devfs_ctx,
    75                      xptr_t        devfs_root_inode_xp,
     75                     xptr_t        devfs_dev_inode_xp,
    7676                     xptr_t        devfs_external_inode_xp );
    7777
     
    9191 *****************************************************************************************
    9292 * @ parent_inode_xp         : extended pointer on the parent VFS inode.
    93  * @ devfs_root_inode_xp     : [out] extended pointer on created <dev> inode.
     93 * @ devfs_dev_inode_xp      : [out] extended pointer on created <dev> inode.
    9494 * @ devfs_external_inode_xp : [out] extended pointer on created <external> inode.
    9595 ****************************************************************************************/
    9696void devfs_global_init( xptr_t   parent_inode_xp,
    97                         xptr_t * devfs_root_inode_xp,
     97                        xptr_t * devfs_dev_inode_xp,
    9898                        xptr_t * devfs_external_inode_xp );
    9999
     
    108108 *    a pseudo-file, linked to the DEVFS "internal" parent directory.
    109109 *****************************************************************************************
    110  * @ devfs_root_inode_xp     : extended pointer on DEVFS root inode.
     110 * @ devfs_dev_inode_xp      : extended pointer on DEVFS root inode.
    111111 * @ devfs_external_inode_xp : extended pointer on DEVFS external inode.
     112 * @ devfs_internal_inode_xp : [out] extended pointer on created <internal> inode.
    112113 ****************************************************************************************/
    113 void devfs_local_init( xptr_t devfs_root_inode_xp,
    114                        xptr_t devfs_external_inode_xp );
     114void devfs_local_init( xptr_t   devfs_dev_inode_xp,
     115                       xptr_t   devfs_external_inode_xp,
     116                       xptr_t * devfs_internal_inode_xp );
    115117                       
    116118#endif  /* _DEVFS_H_ */
  • trunk/kernel/vfs/vfs.c

    r188 r204  
    215215    xlist_root_init( XPTR( local_cxy , &inode->wait_root ) );
    216216
    217     // initialize dentries hash table, if new inode is a directory
    218     if( inode_type == INODE_TYPE_DIR ) xhtab_init( &inode->children , XHTAB_DENTRY_TYPE );
     217    // initialize dentries hash table
     218    xhtab_init( &inode->children , XHTAB_DENTRY_TYPE );
    219219
    220220    // initialize inode locks
     
    329329}
    330330
    331 //////////////////////////////////////////////////////////////////////////////////////////
     331/////////////////////////////////////////
     332void vfs_inode_display( xptr_t inode_xp )
     333{
     334    cxy_t          inode_cxy;
     335    vfs_inode_t  * inode_ptr;
     336    xptr_t         dentry_xp;
     337    cxy_t          dentry_cxy;
     338    vfs_dentry_t * dentry_ptr;
     339   
     340    char           name[CONFIG_VFS_MAX_NAME_LENGTH];
     341
     342    // get inode cluster and local pointer
     343    inode_cxy = GET_CXY( inode_xp );
     344    inode_ptr = (vfs_inode_t *)GET_PTR( inode_xp );
     345
     346    // get parent dentry
     347    dentry_xp  = hal_remote_lwd( XPTR( inode_cxy , &inode_ptr->parent_xp ) );
     348
     349    // get local copy of name
     350    if( dentry_xp == XPTR_NULL )  // it is the VFS root
     351    {
     352        strcpy( name , "/" );
     353    }
     354    else                          // not the VFS root
     355    {
     356        dentry_cxy = GET_CXY( dentry_xp );
     357        dentry_ptr = (vfs_dentry_t *)GET_PTR( dentry_xp );
     358
     359        hal_remote_strcpy( XPTR( local_cxy  , name ) ,
     360                           XPTR( dentry_cxy , &dentry_ptr->name ) );
     361    }
     362
     363    // display inode header
     364    printk("\n*** inode <%s> / inode_xp = %l / dentry_xp = %l ***\n",
     365           name , inode_xp , dentry_xp );
     366
     367    // display children from xhtab
     368    xhtab_display( XPTR( inode_cxy , &inode_ptr->children ) );
     369
     370}  // end vfs_inode_display()
     371
     372////////////////////////////////////////////////////////////////////////////////////////////
    332373//           Dentry related functions
    333374//////////////////////////////////////////////////////////////////////////////////////////
     
    509550
    510551    vfs_dmsg("\n[INFO] %s : enters for <%s> at cycle %d\n",
    511              __FUNCTION__ , path , hal_get_cycles() );
     552             __FUNCTION__ , path , (uint32_t)hal_time_stamp() );
    512553
    513554    // compute lookup working mode
     
    619660    else if (inode_type == INODE_TYPE_DEV )
    620661    {
    621         // TODO
     662        // TODO  [AG]
    622663        return 0;
    623664    }
     
    628669        return -1;
    629670    }
    630 }  // end vfs_access()
     671}  // end vfs_move()
    631672
    632673//////////////////////////////////////
     
    857898static void vfs_recursive_display( xptr_t   inode_xp,
    858899                                   xptr_t   name_xp,
     900                                   xptr_t   dentry_xp,
    859901                                   uint32_t indent )
    860902{
     
    862904    vfs_inode_t      * inode_ptr;
    863905    vfs_inode_type_t   inode_type;
    864     xptr_t             inode_children_xp;    // extended pointer on children xhtab
    865 
    866     xptr_t             dentry_xp;
    867     cxy_t              dentry_cxy;
    868     vfs_dentry_t     * dentry_ptr;
     906    xptr_t             children_xp;    // extended pointer on children xhtab
     907
     908    xptr_t             child_dentry_xp;
     909    cxy_t              child_dentry_cxy;
     910    vfs_dentry_t     * child_dentry_ptr;
     911    xptr_t             child_inode_xp;
     912    xptr_t             child_dentry_name_xp;
    869913
    870914    char               name[CONFIG_VFS_MAX_NAME_LENGTH];
    871 
    872     xptr_t             child_inode_xp;
    873     xptr_t             dentry_name_xp;
    874915
    875916    char *             indent_str[] = { "",                                  // level 0
     
    905946
    906947    // display inode
    907     printk(" %s %s : %s\n", indent_str[indent], vfs_inode_type_str( inode_type ), name );
     948    printk("%s%s <%s> inode_xp = %l / dentry_xp = %l\n",
     949           indent_str[indent], vfs_inode_type_str( inode_type ),
     950           name , inode_xp , dentry_xp );
    908951
    909952    // scan directory entries 
     
    911954    {
    912955        // get extended pointer on directory entries xhtab
    913         inode_children_xp = hal_remote_lwd( XPTR( inode_cxy , &inode_ptr->children ) );
     956        children_xp =  XPTR( inode_cxy , &inode_ptr->children );
    914957
    915958        // get xhtab lock
    916         xhtab_read_lock( inode_children_xp );
     959        xhtab_read_lock( children_xp );
    917960
    918961        // get first dentry from xhtab
    919         dentry_xp = xhtab_get_first( inode_children_xp );
    920 
    921         while( dentry_xp != XPTR_NULL )
     962        child_dentry_xp = xhtab_get_first( children_xp );
     963
     964        while( child_dentry_xp != XPTR_NULL )
    922965        {
    923966            // get dentry cluster and local pointer
    924             dentry_cxy = GET_CXY( dentry_xp );
    925             dentry_ptr = (vfs_dentry_t *)GET_PTR( dentry_xp );
     967            child_dentry_cxy = GET_CXY( child_dentry_xp );
     968            child_dentry_ptr = (vfs_dentry_t *)GET_PTR( child_dentry_xp );
    926969
    927970            // get extended pointer on child inode
    928             child_inode_xp = hal_remote_lwd( XPTR( dentry_cxy , &dentry_ptr->child_xp ) );
     971            child_inode_xp = hal_remote_lwd( XPTR( child_dentry_cxy,
     972                                                   &child_dentry_ptr->child_xp ) );
    929973
    930974            // get extended pointer on dentry name
    931             dentry_name_xp = XPTR( dentry_cxy , &dentry_ptr->name );
     975            child_dentry_name_xp = XPTR( child_dentry_cxy , &child_dentry_ptr->name );
    932976
    933977            // recursive call on child inode
    934             vfs_recursive_display( child_inode_xp , dentry_name_xp , indent+1 );
     978            vfs_recursive_display( child_inode_xp,
     979                                   child_dentry_name_xp,
     980                                   child_dentry_xp,
     981                                   indent+1 );
    935982
    936983            // get next dentry
    937             dentry_xp = xhtab_get_next( inode_children_xp );
     984            child_dentry_xp = xhtab_get_next( children_xp );
    938985        }
    939986
    940987        // release xhtab lock
    941         xhtab_read_unlock( inode_children_xp );
     988        xhtab_read_unlock( children_xp );
    942989    }
    943990}  // end vfs_recursive_display()
     
    946993void vfs_display( xptr_t inode_xp )
    947994{
    948     xptr_t         name_xp;      // extended pointer on string containing the inode name
     995    xptr_t         name_xp;
    949996    xptr_t         dentry_xp;
    950997    cxy_t          dentry_cxy;
    951998    vfs_dentry_t * dentry_ptr;
    952999
    953 printk("\n@@@ %s enters\n", __FUNCTION__ );
    954 
    9551000    // get target inode cluster and local pointer
    9561001    cxy_t         inode_cxy = GET_CXY( inode_xp );
     
    9771022
    9781023    // print header
    979     printk("\n*** Current VFS content ***\n");
     1024    printk("\n*** VFS ***\n");
    9801025
    9811026    // call recursive function
    982     vfs_recursive_display( inode_xp , name_xp , 0 );
    983 
    984 }  // end vfs_diplay()
     1027    vfs_recursive_display( inode_xp , name_xp , dentry_xp , 0 );
     1028
     1029}  // end vfs_display()
    9851030
    9861031//////////////////////////////////////////////////////////////////////////////////////////
     
    10151060//////////////////////////////////////////////////////////////////////////////////////////
    10161061// This static function is used by the vfs_lookup() function.
    1017 // It takes an extended pointer on a remote inode (parent directory inode), a directory
     1062// It takes an extended pointer on a remote parent directory inode, a directory
    10181063// entry name, and returns an extended pointer on the child inode.
    10191064// It can be used by any thread running in any cluster.
     
    10501095    *child_xp = (xptr_t)hal_remote_lwd( XPTR( dentry_cxy , &dentry_ptr->child_xp ) );
    10511096    return true;
    1052 }
     1097
     1098}  // end vfs_get_child()
    10531099
    10541100//////////////////////////////////////////////////////////////////////////////////////////
     
    10831129    while( (*ptr != 0) && (*ptr !='/') )  *(name++) = *(ptr++);
    10841130
     1131    // set NUL terminating character in name buffer
     1132    *(name++) = 0;
     1133
    10851134    // return last an next
    10861135    if( *ptr == 0 )             // last found character is NUL => last name in path
     
    10951144
    10961145    return 0;
    1097 }
     1146
     1147}  // end vfs_get name_from_path()
    10981148   
    10991149//////////////////////////////////////////////
     
    11221172    error_t            error;
    11231173
    1124     vfs_dmsg("\n[INFO] %s : enters for <%s>\n",
    1125              __FUNCTION__ , pathname );
     1174    vfs_dmsg("\n[INFO] %s : enters for <%s> at cycle %d\n",
     1175             __FUNCTION__ , pathname , (uint32_t)hal_time_stamp() );
    11261176
    11271177    this    = CURRENT_THREAD;
     
    11421192
    11431193    // load from device if one intermediate node not found
    1144     // exit when last name found (i.e. last == true)
     1194    // exit while loop when last name found (i.e. last == true)
    11451195    do
    11461196    {
     
    11481198        vfs_get_name_from_path( current , name , &next , &last );
    11491199
    1150         vfs_dmsg("\n[INFO] %s : looking for node <%s> / last = %d\n",
     1200        vfs_dmsg("\n[INFO] %s : looking for <%s> / last = %d\n",
    11511201                 __FUNCTION__ , name , last );
    11521202
    1153         // search a child dentry matching name for parent inode
     1203        // search a child dentry matching name in parent inode
    11541204        found = vfs_get_child( parent_xp,
    11551205                               name,
     
    11581208        if( found == false ) // child inode not found in inode tree => try to load it
    11591209        {
    1160             vfs_dmsg("\n[INFO] %s : node <%s> not found, try to load it\n",
     1210            vfs_dmsg("\n[INFO] %s : <%s> not found, try to load it\n",
    11611211                     __FUNCTION__ , name );
    11621212
     
    11681218            parent_ptr = (vfs_inode_t *)GET_PTR( parent_xp );
    11691219
     1220            // get local pointer on parent inode context
     1221            ctx_ptr = (vfs_ctx_t *)hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->ctx ) );
     1222
    11701223            // get parent inode FS type
    1171             ctx_ptr = (vfs_ctx_t *)hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->ctx ) );
    1172             fs_type = ctx_ptr->type;
     1224            fs_type = hal_remote_lw( XPTR( parent_cxy , &ctx_ptr->type ) );
    11731225
    11741226            // get child inode type
     
    11791231            cxy_t child_cxy = vfs_cluster_random_select();
    11801232                     
     1233printk("\n@@@ name not found : <%s>\n", name );
     1234
    11811235            // insert a new child dentry/inode in parent inode
    11821236            error = vfs_add_child_in_parent( child_cxy,
     
    11871241                                             name,
    11881242                                             &child_xp );
    1189 
    11901243            if( error )
    11911244            {
     
    11991252        }
    12001253
    1201         vfs_dmsg("\n[INFO] %s : node <%s> found / parent = %l / child = %l / last = %d\n",
     1254vfs_inode_display( child_xp );
     1255
     1256vfs_display( parent_xp );
     1257
     1258        vfs_dmsg("\n[INFO] %s : found <%s> / parent = %l / child = %l / last = %d\n",
    12021259                 __FUNCTION__ , name , parent_xp , child_xp , last );
    12031260
     
    13341391    parent_ptr = (vfs_inode_t *)GET_PTR( parent_xp );
    13351392
    1336     // get parent inode context local pointer
    1337     parent_ctx = (vfs_ctx_t *)hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->ctx ) );
    1338 
    1339     // create dentry
     1393    // 1. create dentry
    13401394    if( parent_cxy == local_cxy )      // parent cluster is the local cluster
    13411395    {
     
    13591413        printk("\n[ERROR] in %s : cannot create dentry in cluster %x\n",
    13601414               __FUNCTION__ , parent_cxy );
    1361         return error;
    1362     }
    1363 
    1364     // create child inode TODO : define attr / mode / uid / gid
     1415        return ENOMEM;
     1416    }
     1417
     1418    // 2. create child inode TODO : define attr / mode / uid / gid
    13651419    uint32_t attr = 0;
    13661420    uint32_t mode = 0;
     
    14031457        if( parent_cxy == local_cxy ) vfs_dentry_destroy( dentry );
    14041458        else rpc_vfs_dentry_destroy_client( parent_cxy , dentry );
    1405         return error;
    1406     }
     1459        return ENOMEM;
     1460    }
     1461
     1462    // 3. update extended pointer on inode in dentry
     1463    cxy_t          dentry_cxy = GET_CXY( dentry_xp );
     1464    vfs_dentry_t * dentry_ptr = (vfs_dentry_t *)GET_PTR( dentry_xp );
     1465    hal_remote_swd( XPTR( dentry_cxy , &dentry_ptr->child_xp ) , inode_xp );
    14071466
    14081467    // success : return extended pointer on child inode
     
    14221481error_t vfs_move_page_to_mapper( page_t * page )
    14231482{
    1424     error_t         error = 0;
     1483    error_t error = 0;
    14251484
    14261485    assert( (page != NULL) , __FUNCTION__ , "page pointer is NULL\n" );
  • trunk/kernel/vfs/vfs.h

    r188 r204  
    450450
    451451/******************************************************************************************
     452 * This debug function diplays the name of the inode identified by the <inode_xp>
     453 * argument, and all children names for a directory.
     454 *****************************************************************************************
     455 * @ inode_xp  : extended pointer on the remote inode.
     456 *****************************************************************************************/
     457void vfs_inode_display( xptr_t inode_xp );
     458
     459
     460
     461
     462
     463
     464/******************************************************************************************
    452465 * This function TODO                                                         
    453466 *****************************************************************************************/
     
    617630 * It can be executed by any thread running in any cluster, as this function
    618631 * uses the rpc_dentry_create_client() and rpc_inode_create client() if required.
    619  * - The dentry is created in the cluster containing the existing <parent_xp> inode.
    620  * - the inode and its associated mapper are created in cluster identified by <child_cxy>.
    621  * - The new dentry name is defined by the <name> argument.
    622  * - The new inode and the parent inode can have different FS types.
     632 * This is done in three steps:
     633 * 1) The dentry is created in the cluster containing the existing <parent_xp> inode.
     634 *    The new dentry name is defined by the <name> argument.
     635 * 2) The inode and its associated mapper are created in cluster identified by <child_cxy>.
     636 *    The new inode and the parent inode can have different FS types.
     637 * 3) The "child_xp" field in created dentry (pointing on thecreated inode) is updated.
    623638 ******************************************************************************************
    624639 * @ child_cxy  : target cluster for child inode.
     
    629644 * @ extend     : fs_type_specific inode extension.
    630645 * @ child_xp   : [out] buffer for extended pointer on child inode.
    631  * @ return 0 if success / ENOENT if entry not found in parent directory
     646 * @ return 0 if success / ENOMEM if dentry or inode cannot be created.
    632647 *****************************************************************************************/
    633648error_t vfs_add_child_in_parent( cxy_t              child_cxy,
Note: See TracChangeset for help on using the changeset viewer.