Ignore:
Timestamp:
Oct 10, 2020, 4:50:41 PM (21 months ago)
Author:
alain
Message:

Introduce the ksocket.h & ksocket.c files in kernel/kern.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/process.h

    r657 r662  
    7070/*********************************************************************************************
    7171 * This structure defines an array of extended pointers on the open file descriptors
    72  * for a given process. We use an extended pointer because the open file descriptors
    73  * are always stored in the same cluster as the inode associated to the file.
    74  * A free entry in this array contains the XPTR_NULL value.
     72 * for a given process. The file descriptors are always stored in the same cluster
     73 * as the inode associated to the file. A free entry in this array contains XPTR_NULL.
    7574 * The array size is defined by the CONFIG_PROCESS_FILE_MAX_NR parameter.
    7675 *
    77  * NOTE: - Only the fd_array[] in the reference process contains a complete list of open
     76 * NOTE: - Only the fd_array[] in the reference process contains the complete list of open
    7877 *         files, and is protected by the lock against concurrent access.
    79  *       - the fd_array[] in a process copy is simply a cache containing a subset of the
    80  *         open files to speed the fdid to xptr translation, but the "lock" and "current
     78 *       - the fd_array[] in a process copy is not used.
     79 *         open files to speed the fdid to xptr translation, but the "lock" and "max"
    8180 *         fields are not significant for these copies.
    82  *       - the modifications made by the process_fd_remove() function are done in the
    83  *         reference cluster in all process_copies.
    84  *       - The modifications made by the process_fd_register() function are done in the
    85  *         reference cluster, and in the cluster containing the calling thread.
     81 *       - The modifications made by the process_fd_register() function are only done
     82 *         in the owner cluster.
     83 *       - The modifications made by the process_fd_remove() function are done in the
     84 *         owner cluster, and in all process_copies.
     85 *       - In case of miss on the local fd_array, the process_fd_get_xptr() access the
     86 *         owner cluster fd_array, and update the fd_array local copy.
    8687 ********************************************************************************************/
    8788
     
    8990{
    9091        remote_queuelock_t lock;                              /*! lock protecting fd_array      */
    91     uint32_t           current;                           /*! current number of open files  */
     92    uint32_t           max;                               /*! max non-free slot index       */
    9293        xptr_t             array[CONFIG_PROCESS_FILE_MAX_NR]; /*! open file descriptors         */
    9394}
     
    278279/*********************************************************************************************
    279280 * This function releases all memory allocated for a process descriptor in the local cluster,
    280  * including memory allocated for embedded substructures (fd_array, vmm, etc).
     281 * including memory allocated for embedded sub-structures (fd_array, vmm, etc).
    281282 * The local th_tbl[] array must be empty.
    282283 *********************************************************************************************
     
    428429
    429430
    430 /********************   File Management Operations   ****************************************/
     431/********************     fd_array  operations       ****************************************/
     432
     433
     434/*********************************************************************************************
     435 * This function returns a printable string for a file descriptor type.
     436 * These file types are defined in the <vfs.h> file.
     437 *********************************************************************************************
     438 * @ type     : [in] file type.
     439 ********************************************************************************************/
     440char * process_fd_type_str( uint32_t type );
    431441
    432442/*********************************************************************************************
    433443 * This function initializes all entries of the local fd_array as empty.
    434444 *********************************************************************************************
    435  * @ process  : pointer on the local process descriptor.
     445 * @ process  : [in] pointer on the local process descriptor.
    436446 ********************************************************************************************/
    437447void process_fd_init( process_t * process );
    438448
    439449/*********************************************************************************************
    440  * This function allocates a free slot in the fd_array of the reference process descriptor
    441  * identified by the <process_xp> argument, register the <file_xp> argument in the
    442  * allocated slot, and return the slot index in the <fdid> buffer.
    443  * Note: we must use the reference process descriptor, because the reference fd_array is
    444  * contained in the reference cluster.  It can be called by any thread in any cluster.
    445  * It takes the lock protecting the reference fd_array against concurrent accesses.
     450 * This function allocates a free slot in the owner cluster process fd_array identified
     451 * by the <process_xp> argument, register the <file_xp> argument in the allocated slot,
     452 * and return the slot index in the <fdid> buffer.
     453 * It can be called by any thread in any cluster.
     454 * It takes the lock protecting the fd_array against concurrent accesses.
     455 * Note: we must use the owner process descriptor, because this fd_array must
     456 * contain all files open by a given process.
    446457 *********************************************************************************************
    447458 * @ process_xp : [in]  extended pointer on client reference process.
    448459 * @ file_xp    : [in]  extended pointer on the file descriptor to be registered.
    449  * @ fdid       : [out] buffer for fd_array slot index.
    450  * @ return 0 if success / return EMFILE if array full.
     460 * @ fdid       : [out] buffer for allocated fd_array slot index.
     461 * @ return 0 if success / return -1 if array full.
    451462 ********************************************************************************************/
    452463error_t process_fd_register( xptr_t      process_xp,
     
    455466
    456467/*********************************************************************************************
    457  * This function uses as many remote accesses as required, to reset an entry in fd_array[],
     468 * This function uses as many remote accesses as required, to reset one fd_array[] entry,
    458469 * identified by the <fdid> argument, in all clusters containing a copy of the
    459470 * process descriptor, identified by the <process_xp> argument.
     471 * It can be called by any thread in any cluster.
     472 * It takes the lock protecting the fd_array against concurrent accesses.
    460473 * Note: we must use the owner process descriptor, because only this owner cluster contains
    461  * the list of process copies. It can be called by any thread in any cluster.
    462  * It takes the lock protecting the reference fd_array against concurrent accesses.
    463  *********************************************************************************************
    464  * @ process  : [in] pointer on the local process descriptor.
    465  * @ fdid     : [in] file descriptor index in the fd_array.
     474 * the complete list of process copies.
     475 *********************************************************************************************
     476 * @ process_xp  : [in] extended pointer on the owner process descriptor.
     477 * @ fdid        : [in] file descriptor index in the fd_array.
    466478 ********************************************************************************************/
    467479void process_fd_remove( xptr_t     process_xp,
     
    469481
    470482/*********************************************************************************************
    471  * This function returns an extended pointer on a file descriptor identified by its index
    472  * in fd_array. It can be called by any thread running in any cluster.
     483 * This function scan the fd_array to close all files (or sockets) registered in the process
     484 * fd_array identified by the <process_xp> argument. It call the sys_close() function for
     485 * each registered entry, to release all allocated memory, and reset this entry in all
     486 * process descriptors copies.
     487 * It takes the lock protecting the fd_array against concurrent accesses.
     488 * Note: we must use the owner process descriptor, because only this owner cluster contains
     489 * the complete list of process copies.
     490 *********************************************************************************************
     491 * @ process_xp  : [in] extended pointer on the owner process descriptor.
     492 ********************************************************************************************/
     493void process_fd_clean_all( xptr_t process_xp );
     494
     495/*********************************************************************************************
     496 * This function returns an extended pointer on a file descriptor identified by its <fdid>
     497 * index in fd_array of the local process, identified by the <process> argument.
     498 * It can be called by any thread running in any cluster.
    473499 * It accesses first the local process descriptor. In case of local miss, it takes
    474500 * the lock protecting the reference fd_array, and access the reference process descriptor.
    475  * It updates the local fd_array when the file descriptor exists in reference cluster.
    476  * It takes the lock protecting the reference fd_array against concurrent accesses.
    477  * The file descriptor refcount is not incremented.
    478  *********************************************************************************************
    479  * @ process  : pointer on the local process descriptor.
     501 * It updates the local fd_array when the file descriptor exists in owner cluster.
     502 * It release the lock protecting the reference fd_array.
     503 *********************************************************************************************
     504 * @ process  : local pointer on local process descriptor.
    480505 * @ fdid     : file descriptor index in the fd_array.
    481506 * @ return extended pointer on file descriptor if success / return XPTR_NULL if not found.
    482507 ********************************************************************************************/
    483 xptr_t process_fd_get_xptr( process_t * process,
    484                             uint32_t    fdid );
     508xptr_t process_fd_get_xptr_from_local( process_t * process,
     509                                       uint32_t    fdid );
     510
     511/*********************************************************************************************
     512 * This function returns an extended pointer on a file descriptor identified by its <fdid>
     513 * index in the fd_array of the owner process, identified by the <process_xp> argument,
     514 * accessing directly the fd_array in owner cluster. It can be called by any thread running
     515 * in any cluster, but the local fd_array copy is not updated.
     516 *********************************************************************************************
     517 * @ process_xp  : extended pointer on the owner process descriptor.
     518 * @ fdid        : file descriptor index in the fd_array.
     519 * @ return extended pointer on file descriptor if success / return XPTR_NULL if not found.
     520 ********************************************************************************************/
     521xptr_t process_fd_get_xptr_from_owner( xptr_t      process_xp,
     522                                       uint32_t    fdid );
    485523
    486524/*********************************************************************************************
     
    508546bool_t process_fd_array_full( void );
    509547
    510 
     548/*********************************************************************************************
     549 * This debug function diplays on the kernel terminal TXT0 detailed informations on the
     550 * set of file descriptors registered in the fd_array of a process descriptor identified
     551 * by the <process_xp> argument.
     552 *********************************************************************************************
     553 * @ process_xp    : [in] extended pointer on process descriptor.
     554 ********************************************************************************************/
     555void process_fd_display( xptr_t process_xp );
    511556
    512557/********************   Thread Related Operations   *****************************************/
Note: See TracChangeset for help on using the changeset viewer.