Changeset 9190
- Timestamp:
- 02/10/12 12:06:33 (16 months ago)
- Files:
-
- 1 modified
-
trunk/src/apps/ucache/ucached.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/apps/ucache/ucached.c
r9178 r9190 204 204 int rc = 0; 205 205 206 int old_ locks_present = 0;206 int old_aux_present = 0; 207 207 208 208 /* attempt setup of shmem region for locks (inlcude SYSV later? */ 209 209 int id = SHM_ID1; 210 210 key_t key = ftok(KEY_FILE, id); 211 size_t size = LOCKS_SIZE;211 size_t size = UCACHE_AUX_SIZE; 212 212 int shmflg = SVSHM_MODE; 213 int lock_shmid = shmget(key, size, shmflg);214 215 if( lock_shmid == -1)213 int aux_shmid = shmget(key, size, shmflg); 214 215 if(aux_shmid == -1) 216 216 { 217 217 gossip_debug(GOSSIP_UCACHED_DEBUG, 218 "INFO: shmget on lock_shmid returned -1 on first try\n");219 220 /* Shared memory segment used for lockswas not previosly created,218 "INFO: shmget on aux_shmid returned -1 on first try\n"); 219 220 /* Shared memory segment used for aux data was not previosly created, 221 221 * so create it. 222 222 */ 223 223 shmflg = shmflg | IPC_CREAT | IPC_EXCL; 224 lock_shmid = shmget(key, size, shmflg);225 if( lock_shmid == -1)224 aux_shmid = shmget(key, size, shmflg); 225 if(aux_shmid == -1) 226 226 { 227 227 gossip_debug(GOSSIP_UCACHED_DEBUG, 228 228 "ERROR: shmget (IPC_CREATE, IPC_EXCL)" 229 " on lock_shmid returned -1\n");229 " on aux_shmid returned -1\n"); 230 230 /* Couldn't create the required segment */ 231 231 return -1; … … 235 235 gossip_debug(GOSSIP_UCACHED_DEBUG, 236 236 "INFO: shmget (using IPC_CREATE, IPC_EXCL)" 237 " on lock_shmid returned shmid = %d\n", lock_shmid);238 239 /* Attach to shmem and initialize all the locks*/237 " on aux_shmid returned shmid = %d\n", aux_shmid); 238 239 /* Attach to shmem and initialize all the aux struct */ 240 240 shmflg = 0; 241 /* ucache_ locksis defined in src/client/usrint/ucache.h */242 ucache_ locks = shmat(lock_shmid, NULL, shmflg);243 if (!ucache_ locks)241 /* ucache_aux is defined in src/client/usrint/ucache.h */ 242 ucache_aux = shmat(aux_shmid, NULL, shmflg); 243 if (!ucache_aux) 244 244 { 245 245 gossip_debug(GOSSIP_UCACHED_DEBUG, 246 "ERROR: shmat on lock_shmid returned NULL");246 "ERROR: shmat on aux_shmid returned NULL"); 247 247 return -1; 248 248 } 249 249 250 ucache_locks = ucache_aux->ucache_locks; 251 250 252 int i; 251 /* Initialize Block Level Locks */253 /* Initialize Shared Block Level Locks */ 252 254 for(i = 0; i < (BLOCKS_IN_CACHE + 1); i++) 253 255 { … … 265 267 { 266 268 gossip_debug(GOSSIP_UCACHED_DEBUG, 267 "INFO: first shmget on lock_shmid found segment"268 ": shmid = %d\n", lock_shmid);269 old_ locks_present = 1;270 /* Shmem for lockswas already created, so just attach to it */269 "INFO: first shmget on aux_shmid found segment" 270 ": shmid = %d\n", aux_shmid); 271 old_aux_present = 1; 272 /* Shmem for ucache_aux was already created, so just attach to it */ 271 273 shmflg = 0; 272 ucache_ locks = shmat(lock_shmid, NULL, shmflg);273 if (!ucache_ locks)274 { 275 gossip_debug(GOSSIP_UCACHED_DEBUG, 276 "ERROR: shmat on lock_shmid returned NULL\n");274 ucache_aux = shmat(aux_shmid, NULL, shmflg); 275 if (!ucache_aux) 276 { 277 gossip_debug(GOSSIP_UCACHED_DEBUG, 278 "ERROR: shmat on aux_shmid returned NULL\n"); 277 279 return -1; 278 280 } … … 290 292 gossip_debug(GOSSIP_UCACHED_DEBUG, 291 293 "INFO: lock segment successfully retrieved and global lock locked.\n"); 294 295 /* Set and zero out global ucache stats struct */ 296 ucache_stats = &(ucache_aux->ucache_stats); 297 *ucache_stats = (struct ucache_stats_s){ 0, 0, 0, 0, 0 }; 292 298 293 299 /* Try to get/create the shmem required for the ucache */ … … 304 310 305 311 /* Remember if there was an old lock region detected */ 306 if(old_ locks_present)307 { 308 gossip_debug(GOSSIP_UCACHED_DEBUG, 309 "INFO: old locks discovered, attempting destruction of old"312 if(old_aux_present) 313 { 314 gossip_debug(GOSSIP_UCACHED_DEBUG, 315 "INFO: old ucache_aux found, attempting destruction of old" 310 316 " locks and starting\n"); 311 317 312 /* Destroy old lockregion and start function over */313 rc = shmctl( lock_shmid, IPC_RMID, (struct shmid_ds *) NULL);318 /* Destroy old aux region and start function over */ 319 rc = shmctl(aux_shmid, IPC_RMID, (struct shmid_ds *) NULL); 314 320 315 321 /* Let this child process exit, since exiting is required to get … … 570 576 571 577 /* Daemonize! */ 572 rc = daemon( 1, 1);578 rc = daemon(0, 0); 573 579 574 580 if(rc != 0)
