Changeset 662 for trunk/kernel/kern/process.h
- Timestamp:
- Oct 10, 2020, 4:50:41 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/process.h
r657 r662 70 70 /********************************************************************************************* 71 71 * 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. 75 74 * The array size is defined by the CONFIG_PROCESS_FILE_MAX_NR parameter. 76 75 * 77 * NOTE: - Only the fd_array[] in the reference process contains acomplete list of open76 * NOTE: - Only the fd_array[] in the reference process contains the complete list of open 78 77 * 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 the80 * open files to speed the fdid to xptr translation, but the "lock" and " current78 * - 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" 81 80 * 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. 86 87 ********************************************************************************************/ 87 88 … … 89 90 { 90 91 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 */ 92 93 xptr_t array[CONFIG_PROCESS_FILE_MAX_NR]; /*! open file descriptors */ 93 94 } … … 278 279 /********************************************************************************************* 279 280 * This function releases all memory allocated for a process descriptor in the local cluster, 280 * including memory allocated for embedded sub structures (fd_array, vmm, etc).281 * including memory allocated for embedded sub-structures (fd_array, vmm, etc). 281 282 * The local th_tbl[] array must be empty. 282 283 ********************************************************************************************* … … 428 429 429 430 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 ********************************************************************************************/ 440 char * process_fd_type_str( uint32_t type ); 431 441 432 442 /********************************************************************************************* 433 443 * This function initializes all entries of the local fd_array as empty. 434 444 ********************************************************************************************* 435 * @ process : pointer on the local process descriptor.445 * @ process : [in] pointer on the local process descriptor. 436 446 ********************************************************************************************/ 437 447 void process_fd_init( process_t * process ); 438 448 439 449 /********************************************************************************************* 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. 446 457 ********************************************************************************************* 447 458 * @ process_xp : [in] extended pointer on client reference process. 448 459 * @ 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 EMFILEif array full.460 * @ fdid : [out] buffer for allocated fd_array slot index. 461 * @ return 0 if success / return -1 if array full. 451 462 ********************************************************************************************/ 452 463 error_t process_fd_register( xptr_t process_xp, … … 455 466 456 467 /********************************************************************************************* 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, 458 469 * identified by the <fdid> argument, in all clusters containing a copy of the 459 470 * 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. 460 473 * 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. 466 478 ********************************************************************************************/ 467 479 void process_fd_remove( xptr_t process_xp, … … 469 481 470 482 /********************************************************************************************* 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 ********************************************************************************************/ 493 void 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. 473 499 * It accesses first the local process descriptor. In case of local miss, it takes 474 500 * 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. 480 505 * @ fdid : file descriptor index in the fd_array. 481 506 * @ return extended pointer on file descriptor if success / return XPTR_NULL if not found. 482 507 ********************************************************************************************/ 483 xptr_t process_fd_get_xptr( process_t * process, 484 uint32_t fdid ); 508 xptr_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 ********************************************************************************************/ 521 xptr_t process_fd_get_xptr_from_owner( xptr_t process_xp, 522 uint32_t fdid ); 485 523 486 524 /********************************************************************************************* … … 508 546 bool_t process_fd_array_full( void ); 509 547 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 ********************************************************************************************/ 555 void process_fd_display( xptr_t process_xp ); 511 556 512 557 /******************** Thread Related Operations *****************************************/
Note: See TracChangeset
for help on using the changeset viewer.