Changeset 9025
- Timestamp:
- 08/23/11 15:40:35 (21 months ago)
- Location:
- branches/Orange-Branch/src/client/usrint
- Files:
-
- 9 modified
-
iocommon.c (modified) (6 diffs)
-
iocommon.h (modified) (3 diffs)
-
openfile-util.c (modified) (5 diffs)
-
openfile-util.h (modified) (1 diff)
-
posix-ops.h (modified) (1 diff)
-
posix.c (modified) (1 diff)
-
socket.c (modified) (4 diffs)
-
ucache.c (modified) (10 diffs)
-
ucache.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/Orange-Branch/src/client/usrint/iocommon.c
r9016 r9025 418 418 struct stat sbuf; 419 419 /* try to open using glibc */ 420 rc = (*glibc_ops.open)(error_path, f lags & 01777777, mode);420 rc = (*glibc_ops.open)(error_path, fpvfs_alloc_descriptorlags & 01777777, mode); 421 421 IOCOMMON_RETURN_ERR(rc); 422 pd = pvfs_alloc_descriptor(&pvfs_ops, -1 );422 pd = pvfs_alloc_descriptor(&pvfs_ops, -1, NULL); 423 423 pd->is_in_use = PVFS_FS; /* indicate fd is valid! */ 424 424 pd->true_fd = rc; … … 462 462 } 463 463 } 464 464 465 /* If we get here the file was created and/or opened */ 465 466 466 /* Translate the pvfs reference into a file descriptor */ 467 467 /* Set the file information */ 468 468 /* create fd object */ 469 pd = pvfs_alloc_descriptor(&pvfs_ops, -1 );469 pd = pvfs_alloc_descriptor(&pvfs_ops, -1, &file_ref); 470 470 if (!pd) 471 471 { … … 836 836 } 837 837 838 /*The Wrapper Fuction calls to the "nocache" version of 839 * io_common_readorwrite (below) 840 */ 841 /** do a blocking read or write, possibly utilizing the user cache. 842 * 843 */ 844 int iocommon_readorwrite(enum PVFS_io_type which, 845 pvfs_descriptor *pd, 846 PVFS_size offset, 847 void *buf, 848 PVFS_Request mem_req, 849 PVFS_Request file_req) 850 { 851 #ifndef UCACHE_ENABLED 852 /* No cache */ 853 return iocommon_readorwrite_nocache(which, pd, offset, buf, mem_req, 854 file_req); 855 #endif /* UCACHE_ENABLED */ 856 857 //read 858 //readthedata(*filePtrToData) 859 //write 860 861 862 //Cache Routines 863 //Possibly Data Transfer 864 //Possibly More Cache Routines 865 } 866 838 867 /** do a blocking read or write 839 868 * 840 869 */ 841 int iocommon_readorwrite (enum PVFS_io_type which,870 int iocommon_readorwrite_nocache(enum PVFS_io_type which, 842 871 pvfs_descriptor *pd, 843 872 PVFS_size offset, … … 886 915 } 887 916 917 /** Do a nonblocking read or write, possibly utilizing the user cache. 918 * 919 * extra_offset = extra padding to the pd's offset, 920 * independent of the pd's offset 921 * Returns an op_id, response, and ret_mem_request 922 * (which represents an etype_req*count region) 923 * Note that the none of the PVFS_Requests are freed 924 */ 925 int iocommon_ireadorwrite(enum PVFS_io_type which, 926 pvfs_descriptor *pd, 927 PVFS_size extra_offset, 928 void *buf, 929 PVFS_Request etype_req, 930 PVFS_Request file_req, 931 size_t count, 932 PVFS_sys_op_id *ret_op_id, 933 PVFS_sysresp_io *ret_resp, 934 PVFS_Request *ret_memory_req) 935 { 936 #ifndef UCACHE_ENABLED 937 /* No cache */ 938 return iocommon_ireadorwrite_nocache(which, pd, extra_offset, buf, 939 etype_req, file_req, count, ret_op_id, ret_resp, ret_memory_req); 940 #endif /* UCACHE_ENABLED */ 941 942 //if read then check cache..if not there..then read from i/o node and store into correct location 943 //Possibly Data Transfer 944 //Possibly More Cache Routines 945 } 946 947 888 948 /** Do a nonblocking read or write 889 949 * … … 894 954 * Note that the none of the PVFS_Requests are freed 895 955 */ 896 int iocommon_ireadorwrite (enum PVFS_io_type which,956 int iocommon_ireadorwrite_nocache(enum PVFS_io_type which, 897 957 pvfs_descriptor *pd, 898 958 PVFS_size extra_offset, … … 1839 1899 } 1840 1900 1841 /** Imple lments an extended attribute delete or remove1901 /** Implements an extended attribute delete or remove 1842 1902 * 1843 1903 * The PVFS server enforces namespaces as prefixes on the -
branches/Orange-Branch/src/client/usrint/iocommon.h
r9016 r9025 104 104 PVFS_object_ref *newpdir, const char *newname); 105 105 106 /* R/W Wrapper Functions, possibly utilizing user cache */ 106 107 /* do a blocking read or write 107 * extra_offset = extra padding to the pd's offset, independent of the pd's offset */108 */ 108 109 int iocommon_readorwrite(enum PVFS_io_type which, 109 110 pvfs_descriptor *pd, … … 112 113 PVFS_Request mem_req, 113 114 PVFS_Request file_req); 114 //returned by nonblocking operations 115 116 /* 117 * [Do a nonblocking read or write] 118 * extra_offset = extra padding to the pd's offset, 119 * independent of the pd's offset 120 * Returns an op_id, response, and ret_mem_request 121 * (which represents an etype_req*count region) 122 * Note that the none of the PVFS_Requests are freed 123 */ 124 int iocommon_ireadorwrite(enum PVFS_io_type which, 115 116 117 /* [Do a nonblocking read or write] */ 118 int iocommon_ireadorwrite_nocache(enum PVFS_io_type which, 125 119 pvfs_descriptor *pd, 126 120 PVFS_size extra_offset, … … 133 127 PVFS_Request *ret_memory_req); 134 128 129 130 /* do a blocking read or write 131 * extra_offset = extra padding to the pd's offset, independent of the pd's offset */ 132 int iocommon_readorwrite_nocache(enum PVFS_io_type which, 133 pvfs_descriptor *pd, 134 PVFS_size offset, 135 void *buf, 136 PVFS_Request mem_req, 137 PVFS_Request file_req); 138 //returned by nonblocking operations 139 140 /* 141 * [Do a nonblocking read or write] 142 * extra_offset = extra padding to the pd's offset, 143 * independent of the pd's offset 144 * Returns an op_id, response, and ret_mem_request 145 * (which represents an etype_req*count region) 146 * Note that the none of the PVFS_Requests are freed 147 */ 148 int iocommon_ireadorwrite_nocache(enum PVFS_io_type which, 149 pvfs_descriptor *pd, 150 PVFS_size extra_offset, 151 void *buf, 152 PVFS_Request etype_req, 153 PVFS_Request file_req, 154 size_t count, 155 PVFS_sys_op_id *ret_op_id, 156 PVFS_sysresp_io *ret_resp, 157 PVFS_Request *ret_memory_req); 158 135 159 int iocommon_getattr(PVFS_object_ref obj, PVFS_sys_attr *attr, uint32_t mask); 136 160 -
branches/Orange-Branch/src/client/usrint/openfile-util.c
r9016 r9025 16 16 #include <openfile-util.h> 17 17 #include <posix-pvfs.h> 18 #include <ucache.h> 18 19 19 20 static struct glibc_redirect_s … … 396 397 * initialize fsops to the given set 397 398 */ 398 pvfs_descriptor *pvfs_alloc_descriptor(posix_ops *fsops, int fd) 399 pvfs_descriptor *pvfs_alloc_descriptor(posix_ops *fsops, int fd, 400 PVFS_object_ref *file_ref 401 ) 399 402 { 400 403 int newfd, rc, flags; … … 443 446 descriptor_table[newfd]->dpath = NULL; 444 447 descriptor_table[newfd]->is_in_use = PVFS_FS; 448 descriptor_table[newfd]->mtbl = NULL; 449 450 /* File reference won't always be passed in */ 451 if(file_ref != NULL) 452 { 453 /* We have the file identifiers, so insert file info into ucache */ 454 rc = ucache_open_file(&(file_ref->fs_id), &(file_ref->handle), 455 descriptor_table[newfd]->mtbl); 456 /* Unique Entry */ 457 if(rc > 0) 458 { 459 descriptor_table[newfd]->mtbl->ref_cnt = 1; 460 } 461 /* File already in Cache */ 462 else if(rc == 0){ 463 descriptor_table[newfd]->mtbl->ref_cnt++; 464 } 465 /* Could not insert */ 466 else 467 { 468 /* TODO: probably need modify this */ 469 } 470 } 445 471 446 472 return descriptor_table[newfd]; … … 519 545 pd->fsops = &glibc_ops; 520 546 pd->true_fd = fd; 521 pd-> pvfs_ref.fs_id = 0;547 pd->.fs_id = 0; 522 548 pd->pvfs_ref.handle = 0; 523 549 pd->flags = flags; … … 562 588 free(pd->dpath); 563 589 } 564 /* release cache opbjects here */ 590 /* release cache objects here */ 591 pd->mtbl->ref_cnt--; 592 if(pd->mtbl->ref_cnt == 0) 593 { 594 /* Flush dirty blocks before file removal from cache */ 595 ucache_flush(&(pd->pvfs_ref.fs_id), &(pd->pvfs_ref.handle)); 596 /* remove all of this file's associated data from cache */ 597 ucache_close_file(&(pd->pvfs_ref.fs_id), &(pd->pvfs_ref.handle)); 598 } 599 565 600 /* free descriptor - wipe memory first */ 566 601 memset(pd, 0, sizeof(pvfs_descriptor)); -
branches/Orange-Branch/src/client/usrint/openfile-util.h
r9016 r9025 44 44 PVFS_object_ref *ref); 45 45 46 pvfs_descriptor *pvfs_alloc_descriptor(posix_ops *fsops, int fd); 46 pvfs_descriptor *pvfs_alloc_descriptor(posix_ops *fsops, 47 int fd, 48 PVFS_object_ref *file_ref); 47 49 48 50 pvfs_descriptor *pvfs_find_descriptor(int fd); -
branches/Orange-Branch/src/client/usrint/posix-ops.h
r9016 r9025 165 165 int is_in_use; /**< PVFS_FS if this descriptor is valid */ 166 166 char *dpath; /**< path of an open directory for fchdir */ 167 struct mem_table_s *mtbl; /**< reference to cached objects */ 167 168 } pvfs_descriptor; 168 169 -
branches/Orange-Branch/src/client/usrint/posix.c
r9016 r9025 69 69 } 70 70 /* set up the descriptor manually */ 71 pd = pvfs_alloc_descriptor(&glibc_ops, rc );71 pd = pvfs_alloc_descriptor(&glibc_ops, rc, NULL); 72 72 if (!pd) 73 73 { -
branches/Orange-Branch/src/client/usrint/socket.c
r9016 r9025 30 30 return sockfd; 31 31 } 32 pd = pvfs_alloc_descriptor(&glibc_ops, sockfd );32 pd = pvfs_alloc_descriptor(&glibc_ops, sockfd, NULL); 33 33 pd->mode |= S_IFSOCK; 34 34 return pd->fd; … … 59 59 goto errorout; 60 60 } 61 pd = pvfs_alloc_descriptor(&glibc_ops, fd );61 pd = pvfs_alloc_descriptor(&glibc_ops, fd , NULL); 62 62 pd->mode |= S_IFSOCK; 63 63 rc = fd; … … 436 436 goto errorout; 437 437 } 438 pd0 = pvfs_alloc_descriptor(&glibc_ops, sv[0] );438 pd0 = pvfs_alloc_descriptor(&glibc_ops, sv[0], NULL); 439 439 if (!pd0) 440 440 { 441 441 goto errorout; 442 442 } 443 pd1 = pvfs_alloc_descriptor(&glibc_ops, sv[1] );443 pd1 = pvfs_alloc_descriptor(&glibc_ops, sv[1], NULL); 444 444 if (!pd1) 445 445 { … … 473 473 goto errorout; 474 474 } 475 f0 = pvfs_alloc_descriptor(&glibc_ops, fa[0] );475 f0 = pvfs_alloc_descriptor(&glibc_ops, fa[0], NULL); 476 476 if (!f0) 477 477 { 478 478 goto errorout; 479 479 } 480 f1 = pvfs_alloc_descriptor(&glibc_ops, fa[1] );480 f1 = pvfs_alloc_descriptor(&glibc_ops, fa[1], NULL); 481 481 if (!f1) 482 482 { -
branches/Orange-Branch/src/client/usrint/ucache.c
r9012 r9025 18 18 19 19 /* Global Variables */ 20 static FILE *out; /* For Logging Purposes */ 21 20 22 static union user_cache_u *ucache; 21 23 static int ucache_blk_cnt; 22 static ucache_lock_t *ucache_lock; /* For maintaining concurrency */ 23 static FILE *out; /* For Logging Purposes */ 24 25 static ucache_lock_t *ucache_locks; /* will refer to the shmem of all ucache locks */ 26 static ucache_lock_t *ucache_lock; /* Global Lock maintaining concurrency */ 27 static ucache_lock_t *ucache_block_lock; 24 28 25 29 /* Internal Only Function Declarations */ 26 30 27 /* Global Cache Lock*/31 /* Locking */ 28 32 static int lock_init(ucache_lock_t * lock); 29 33 static int lock_lock(ucache_lock_t * lock); … … 112 116 void ucache_initialize(void) 113 117 { 114 /* Aquire shared memory for ucache_lock */ 115 ucache_lock = shmat(shmget(ftok(GET_KEY_FILE, 'a'), 116 sizeof(ucache_lock_t), CACHE_FLAGS), NULL, AT_FLAGS); 118 int i = 0; 119 120 /* Aquire shared memory for ucache_locks */ 121 ucache_locks = shmat(shmget(ftok(GET_KEY_FILE, 'a'), (LOCK_SIZE 122 * (BLOCKS_IN_CACHE + 1)), CACHE_FLAGS), NULL, AT_FLAGS); 123 /* Global Cache lock stored in first LOCK_SIZE position */ 124 ucache_lock = ucache_locks; 125 126 /* Initialize Global Cache Lock */ 117 127 lock_init(ucache_lock); 118 128 lock_lock(ucache_lock); 119 #if LOCK_TYPE==0 120 int lockVal; 121 ucache_lock_getvalue(ucache_lock, &lockVal); 122 printf("lock value = %d\n", lockVal); 123 #endif 124 /* Aquire shared memory for lock for ucache */ 125 int key, id, i; 129 130 /* The next BLOCKS_IN_CACHE number of block locks follow the global lock */ 131 ucache_block_lock = ucache_locks + 1; 132 /* Initialize Block Level Locks */ 133 for(i = 0; i < BLOCKS_IN_CACHE; i++) 134 { 135 lock_init(get_block_lock(i)); 136 } 137 138 /* Aquire shared memory for ucache */ 139 int key; 140 int id; 126 141 char *key_file_path; 127 142 /* Direct output */ … … 172 187 } 173 188 174 int ucache_open_file(PVFS_fs_id *fs_id, PVFS_object_ref *handle) 189 int ucache_open_file(PVFS_fs_id *fs_id, PVFS_handle *handle, 190 struct mem_table_s *mtbl 191 ) 192 { 193 lock_lock(ucache_lock); 194 mtbl= lookup_file((uint32_t)(*fs_id), (uint64_t)(*handle), NULL, NULL, NULL, 195 NULL); 196 if((int)mtbl==NIL) 197 { 198 mtbl = insert_file((uint32_t)*fs_id, (uint64_t)*handle); 199 if((int)mtbl==NIL) 200 { /* Error - Could not insert */ 201 lock_unlock(ucache_lock); 202 return -1; 203 } 204 else 205 { 206 /* File Inserted*/ 207 lock_unlock(ucache_lock); 208 return 1; 209 } 210 } 211 else 212 { 213 /* File was previously Inserted */ 214 lock_unlock(ucache_lock); 215 return 0; 216 } 217 } 218 219 /** Returns ptr to block in cache based on file and offset */ 220 void *ucache_lookup(PVFS_fs_id *fs_id, PVFS_handle *handle, uint64_t offset) 221 { 222 lock_lock(ucache_lock); 223 struct mem_table_s *mtbl= lookup_file( 224 (uint32_t)(*fs_id), (uint64_t)(*handle), NULL, NULL, NULL, NULL); 225 if((int)mtbl!=NIL) 226 { 227 char *retVal = (char *)lookup_mem(mtbl, (uint64_t)offset, NULL, NULL, 228 NULL); 229 lock_unlock(ucache_lock); 230 return((void *)retVal); 231 } 232 lock_unlock(ucache_lock); 233 return (void *)NIL; 234 } 235 236 /** Prepares the data structures for block storage. 237 * On success, returns a pointer to where the block of data should be written. 238 * On failure, returns NIL. 239 */ 240 void *ucache_insert(PVFS_fs_id *fs_id, PVFS_handle *handle, uint64_t offset) 175 241 { 176 242 lock_lock(ucache_lock); … … 179 245 if((int)mtbl==NIL) 180 246 { 181 insert_file((uint32_t)*fs_id, (uint64_t)*handle);182 }183 lock_unlock(ucache_lock);184 return 1;185 }186 187 /** Returns ptr to block in cache based on file and offset */188 void *ucache_lookup(PVFS_fs_id *fs_id, PVFS_object_ref *handle, uint64_t offset)189 {190 lock_lock(ucache_lock);191 struct mem_table_s *mtbl= lookup_file(192 (uint32_t)(*fs_id), (uint64_t)(*handle), NULL, NULL, NULL, NULL);193 if((int)mtbl!=NIL)194 {195 char *retVal = (char *)lookup_mem(mtbl, (uint64_t)offset, NULL, NULL,196 NULL);197 lock_unlock(ucache_lock);198 return((void *)retVal);199 }200 lock_unlock(ucache_lock);201 return (void *)NIL;202 }203 204 /** Prepares the data structures for block storage.205 * On success, returns a pointer to where the block of data should be written.206 * On failure, returns NIL.207 */208 void *ucache_insert(PVFS_fs_id *fs_id, PVFS_object_ref *handle, uint64_t offset)209 {210 lock_lock(ucache_lock);211 struct mem_table_s *mtbl= lookup_file(212 (uint32_t)(*fs_id), (uint64_t)(*handle), NULL, NULL, NULL, NULL);213 if((int)mtbl==NIL)214 {215 247 lock_unlock(ucache_lock); 216 248 return (void *)NIL; … … 229 261 230 262 /** Removes a cached block of data from mtbl */ 231 int ucache_remove(PVFS_fs_id *fs_id, PVFS_ object_ref*handle, uint64_t offset)263 int ucache_remove(PVFS_fs_id *fs_id, PVFS_handle *handle, uint64_t offset) 232 264 { 233 265 lock_lock(ucache_lock); … … 245 277 246 278 /** Flushes dirty blocks to the I/O Nodes */ 247 int ucache_flush(PVFS_fs_id *fs_id, PVFS_ object_ref*handle)279 int ucache_flush(PVFS_fs_id *fs_id, PVFS_handle *handle) 248 280 { 249 281 lock_lock(ucache_lock); … … 273 305 * the cache. 274 306 */ 275 int ucache_close_file(PVFS_fs_id *fs_id, PVFS_ object_ref*handle)307 int ucache_close_file(PVFS_fs_id *fs_id, PVFS_handle *handle) 276 308 { 277 309 lock_lock(ucache_lock); … … 474 506 } 475 507 } 508 509 /** Returns a pointer to the block level lock corresponding to the block_index. 510 */ 511 ucache_lock_t * get_block_lock(int block_index) 512 { 513 return (ucache_block_lock + block_index); 514 } 515 476 516 /***************************************** End of Externally Visible API */ 477 517 … … 522 562 * Otherwise, returns -1 and sets errno. 523 563 */ 524 #if LOCK_TYPE==0564 #if (LOCK_TYPE == 0) 525 565 int ucache_lock_getvalue(ucache_lock_t * lock, int *sval) 526 566 { … … 534 574 static int lock_destroy(ucache_lock_t * lock) 535 575 { 536 #if LOCK_TYPE==0576 #if (LOCK_TYPE == 0) 537 577 return sem_destroy(lock); 538 #elif LOCK_TYPE==1578 #elif (LOCK_TYPE == 1) 539 579 return pthread_mutex_destroy(lock); 540 #elif LOCK_TYPE==2580 #elif (LOCK_TYPE == 2) 541 581 return pthread_spin_destroy(lock); 542 582 #endif -
branches/Orange-Branch/src/client/usrint/ucache.h
r9012 r9025 40 40 #define NIL (-1) 41 41 42 #define DBG 142 #define DBG 0 43 43 #define INTERNAL_TESTING 0 44 44 45 45 46 #define LOCK_TYPE 0/* 0 for Semaphore, 1 for Mutex, 2 for Spinlock */47 #if LOCK_TYPE==046 #define LOCK_TYPE 1 /* 0 for Semaphore, 1 for Mutex, 2 for Spinlock */ 47 #if (LOCK_TYPE == 0) 48 48 #define ucache_lock_t sem_t 49 #elif LOCK_TYPE==1 50 #define ucache_lock_t pthread_mutex_t 51 #elif LOCK_TYPE==2 49 #define LOCK_SIZE sizeof(sem_t) 50 #elif (LOCK_TYPE == 1) 51 #define ucache_lock_t pthread_mutex_t /* sizeof(pthread_mutex_t)=24 */ 52 #define LOCK_SIZE sizeof(pthread_mutex_t) 53 #elif (LOCK_TYPE == 2) 52 54 #define ucache_lock_t pthread_spinlock_t 55 #define LOCK_SIZE sizeof(pthread_spinlock_t) 53 56 #endif 54 57 55 58 typedef uint32_t PVFS_fs_id; 56 typedef uint64_t PVFS_ object_ref;59 typedef uint64_t PVFS_handle; 57 60 58 61 /** A link for one block of memory in a files hash table … … 134 137 }; 135 138 139 struct ucache_ref_s 140 { 141 union user_cache_u *ucache; /* pointer to ucache shmem */ 142 ucache_lock_t *ucache_locks; /* pointer to ucache locks */ 143 }; 144 136 145 /* externally visible API */ 137 146 void ucache_initialize(void); 138 int ucache_open_file(PVFS_fs_id *fs_id, PVFS_object_ref *handle); 139 void *ucache_lookup(PVFS_fs_id *fs_id, PVFS_object_ref *handle, uint64_t offset); 140 void *ucache_insert(PVFS_fs_id *fs_id, PVFS_object_ref *handle, uint64_t offset); 141 int ucache_remove(PVFS_fs_id *fs_id, PVFS_object_ref *handle, uint64_t offset); 142 int ucache_flush(PVFS_fs_id *fs_id, PVFS_object_ref *handle); 143 int ucache_close_file(PVFS_fs_id *fs_id, PVFS_object_ref *handle); 147 int ucache_open_file(PVFS_fs_id *fs_id, PVFS_handle *handle, 148 struct mem_table_s *mtbl); 149 int ucache_close_file(PVFS_fs_id *fs_id, PVFS_handle *handle); 150 void *ucache_lookup(PVFS_fs_id *fs_id, PVFS_handle *handle, uint64_t offset); 151 void *ucache_insert(PVFS_fs_id *fs_id, PVFS_handle *handle, uint64_t offset); 152 int ucache_remove(PVFS_fs_id *fs_id, PVFS_handle *handle, uint64_t offset); 153 int ucache_flush(PVFS_fs_id *fs_id, PVFS_handle *handle); 144 154 void ucache_dec_ref_cnt(struct mem_table_s * mtbl); 145 155 void ucache_inc_ref_cnt(struct mem_table_s * mtbl); … … 149 159 ucache_lock_t * ucache_lock 150 160 ); 161 ucache_lock_t * get_block_lock(int block_index); 151 162 152 163 #if LOCK_TYPE==0 153 164 int ucache_lock_getvalue(ucache_lock_t * lock, int *sval); 154 #endif 165 #endif /* LOCK_TYPE */ 155 166 /**************************************** End of Internal Only Functions */ 156 #endif 167 #endif /* UCACHE_H */ 157 168 /* 158 169 * Local variables:
