Ignore:
Timestamp:
Jan 15, 2019, 1:59:32 PM (3 years ago)
Author:
alain
Message:

1) introduce a dev_ioc_sync_write() function in IOC API,

to improve the DEVFS synchronous update.

2) fix a big bug in both the user_dir_create() and user_dir_destroy()

functions: add an extended pointer on the reference client process
in the function's arguments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/libk/user_dir.c

    r613 r614  
    8080}  // end user_dir_from_ident()
    8181
    82 ///////////////////////////////////////////////////
    83 user_dir_t * user_dir_create( vfs_inode_t * inode )
     82//////////////////////////////////////////////////
     83user_dir_t * user_dir_create( vfs_inode_t * inode,
     84                              xptr_t        ref_xp )
    8485{
    8586    user_dir_t    * dir;               // local pointer on created user_dir_t
    8687    vseg_t        * vseg;              // local pointer on dirent array vseg
    8788    uint32_t        vseg_size;         // size of vseg in bytes
    88     process_t     * process;           // local pointer on calling process
    89     xptr_t          ref_xp;            // extended pointer on reference process
    9089    process_t     * ref_ptr;           // local pointer on reference process
    9190    cxy_t           ref_cxy;           // reference process cluster identifier
     91    pid_t           ref_pid;           // reference process PID
    9292    xptr_t          gpt_xp;            // extended pointer on reference process GPT
    9393    uint32_t        gpt_attributes;    // attributes for all mapped gpt entries
     
    109109    error_t         error;
    110110
    111     // get pointer on local process descriptor
    112     process = CURRENT_THREAD->process;
     111    // get cluster, local pointer, and pid of reference user process
     112    ref_cxy = GET_CXY( ref_xp );
     113    ref_ptr = GET_PTR( ref_xp );
     114    ref_pid = hal_remote_l32( XPTR( ref_cxy , &ref_ptr->pid ) );
    113115
    114116#if DEBUG_USER_DIR
     
    116118thread_t * this = CURRENT_THREAD;
    117119if( cycle > DEBUG_USER_DIR )
    118 printk("\n[%s] thread[%x,%x] enter for inode (%x,%x) / cycle %d\n",
    119 __FUNCTION__, process->pid, this->trdid, local_cxy, inode, cycle );
     120printk("\n[%s] thread[%x,%x] enter for inode (%x,%x) and process %x / cycle %d\n",
     121__FUNCTION__, this->process->pid, this->trdid, local_cxy, inode, ref_pid, cycle );
    120122#endif
    121123
     
    128130    // initialise temporary list of pages
    129131    list_root_init( &root );
    130 
    131     // get pointers on reference process
    132     ref_xp  = process->ref_xp;
    133     ref_cxy = GET_CXY( ref_xp );
    134     ref_ptr = GET_PTR( ref_xp );
    135132
    136133    // allocate memory for a local user_dir descriptor
     
    207204    } // end while
    208205       
     206#if DEBUG_USER_DIR
     207if( cycle > DEBUG_USER_DIR )
     208printk("\n[%s] thread[%x,%x] initialised dirent array / %d entries\n",
     209__FUNCTION__, this->process->pid, this->trdid, total_dirents, cycle );
     210#endif
     211
    209212    // compute required vseg size for a 64 bytes dirent
    210213    vseg_size = total_dirents << 6;
     
    213216    if( local_cxy == ref_cxy )
    214217    {
    215         vseg = vmm_create_vseg( process,
     218        vseg = vmm_create_vseg( ref_ptr,
    216219                                VSEG_TYPE_ANON,
    217220                                0,                      // vseg base (unused)
     
    220223                                0,                      // file_size (unused)
    221224                                XPTR_NULL,              // mapper (unused)
    222                                 ref_cxy );
     225                                local_cxy );
    223226    }
    224227    else
     
    232235                                    0,                     // file size (unused)
    233236                                    XPTR_NULL,             // mapper (unused)
    234                                     ref_cxy,
     237                                    local_cxy,
    235238                                    &vseg );
    236239    }
     240
    237241    if( vseg == NULL )
    238242    {
    239         printk("\n[ERROR] in %s : cannot create vseg for DIR in cluster %x\n",
     243        printk("\n[ERROR] in %s : cannot create vseg for user_dir in cluster %x\n",
    240244        __FUNCTION__, ref_cxy);
    241245        goto user_dir_create_failure;
    242246    }
    243247
    244 #if (DEBUG_USER_DIR & 1)
     248#if DEBUG_USER_DIR
    245249if( cycle > DEBUG_USER_DIR )
    246250printk("\n[%s] thread[%x,%x] allocated vseg ANON / base %x / size %x\n",
    247 __FUNCTION__, process->pid, this->trdid, vseg->min, vseg->max - vseg->min );
     251__FUNCTION__, this->process->pid, this->trdid, vseg->min, vseg->max - vseg->min );
    248252#endif
    249253
     
    289293            desc.lid       = CURRENT_THREAD->core->lid;
    290294            desc.blocking  = true;
    291             desc.args[0]   = process->pid;
     295            desc.args[0]   = ref_pid;
    292296            desc.args[1]   = vpn << CONFIG_PPM_PAGE_SHIFT;
    293297            rpc_vmm_delete_vseg_client( ref_cxy , &desc );
     
    299303        }
    300304
    301 #if (DEBUG_USER_DIR & 1)
     305#if DEBUG_USER_DIR
    302306if( cycle > DEBUG_USER_DIR )
    303307printk("\n[%s] thread[%x,%x] mapped vpn %x to ppn %x\n",
    304 __FUNCTION__, process->pid, this->trdid, vpn + page_id, ppn );
     308__FUNCTION__, this->process->pid, this->trdid, vpn + page_id, ppn );
    305309#endif
    306310
     
    340344if( cycle > DEBUG_USER_DIR )
    341345printk("\n[%s] thread[%x,%x] created user_dir (%x,%x) / %d entries / cycle %d\n",
    342 __FUNCTION__, process->pid, this->trdid, local_cxy, dir, total_dirents, cycle );
     346__FUNCTION__, this->process->pid, this->trdid, local_cxy, dir, total_dirents, cycle );
    343347#endif
    344348
     
    365369}  // end user_dir_create()
    366370
    367 /////////////////////////////////////////
    368 void user_dir_destroy( user_dir_t * dir )
     371////////////////////////////////////////
     372void user_dir_destroy( user_dir_t * dir,
     373                       xptr_t       ref_xp )
    369374{
    370     process_t    * process;    // local pointer on client process
    371     thread_t     * this;       // local pointer on client thread
     375    thread_t     * this;       // local pointer on calling thread
     376    process_t    * process;    // local pointer on calling process
    372377    cluster_t    * cluster;    // local pointer on local cluster
    373378    intptr_t       ident;      // user pointer on dirent array
    374     xptr_t         ref_xp;     // extended pointer on reference process
     379    xptr_t         ref_pid;    // reference process PID
    375380    cxy_t          ref_cxy;    // reference process cluster identifier
    376381    process_t    * ref_ptr;    // local pointer on reference process
     
    379384    xptr_t         iter_xp;    // iteratot in xlist
    380385    reg_t          save_sr;    // for critical section
    381     pid_t          pid;        // process descriptor
    382386    cxy_t          owner_cxy;  // owner process cluster
    383387    lpid_t         lpid;       // process local index
    384388    rpc_desc_t     rpc;        // rpc descriptor
    385389     
    386     // get pointers on client process & thread
     390    // get pointers on calling process & thread
    387391    this    = CURRENT_THREAD;
    388392    process = this->process;
    389393    cluster = LOCAL_CLUSTER;
    390394
     395    // get cluster, local pointer, and PID of reference user process
     396    ref_cxy = GET_CXY( ref_xp );
     397    ref_ptr = GET_PTR( ref_xp );
     398    ref_pid = hal_remote_l32( XPTR( ref_cxy , &ref_ptr->pid ) );
     399
    391400#if DEBUG_USER_DIR
    392401uint32_t cycle = (uint32_t)hal_get_cycles();
    393402if( cycle > DEBUG_USER_DIR )
    394 printk("\n[%s] thread[%x,%x] enter for user_dir (%x,%x) / cycle %d\n",
    395 __FUNCTION__, process->pid, this->trdid, local_cxy, dir, cycle );
     403printk("\n[%s] thread[%x,%x] enter for user_dir (%x,%x) and process %x / cycle %d\n",
     404__FUNCTION__, process->pid, this->trdid, local_cxy, dir, ref_pid, cycle );
    396405#endif
    397406
    398407    // get user pointer on dirent array
    399408    ident = dir->ident;
    400 
    401     // get pointers on reference process
    402     ref_xp  = process->ref_xp;
    403     ref_cxy = GET_CXY( ref_xp );
    404     ref_ptr = GET_PTR( ref_xp );
    405409
    406410    // build extended pointer on lock protecting open directories list
     
    424428
    425429    // get owner cluster identifier and process lpid
    426     pid       = process->pid;
    427     owner_cxy = CXY_FROM_PID( pid );
    428     lpid      = LPID_FROM_PID( pid );
     430    owner_cxy = CXY_FROM_PID( ref_pid );
     431    lpid      = LPID_FROM_PID( ref_pid );
    429432
    430433    // get root of list of copies and lock from owner cluster
     
    444447    rpc.thread    = this;
    445448    rpc.lid       = this->core->lid;
    446     rpc.args[0]   = process->pid;
     449    rpc.args[0]   = ref_pid;
    447450    rpc.args[1]   = ident;
    448451
Note: See TracChangeset for help on using the changeset viewer.