/* open for creating */ storeIOState * storeAufsCreate(SwapDir * SD, StoreEntry * e, STFNCB * file_callback, STIOCB * callback, void *callback_data) { char *path; storeIOState *sio; sfileno filn; sdirno dirn; #if !ASYNC_CREATE int fd; #endif /* Allocate a number */ dirn = SD->index; filn = storeAufsDirMapBitAllocate(SD); path = storeAufsDirFullPath(SD, filn, NULL); debug(79, 3) ("storeAufsCreate: fileno %08X\n", filn); /* * we should detect some 'too many files open' condition and return * NULL here. */ #ifdef MAGIC2 if (aioQueueSize() > MAGIC2) return NULL; #endif #if !ASYNC_CREATE fd = file_open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY); if (fd < 0) { debug(79, 3) ("storeAufsCreate: got failure (%d)\n", errno); return NULL; } #endif CBDATA_INIT_TYPE_FREECB(storeIOState, storeAufsIOFreeEntry); sio = cbdataAlloc(storeIOState); sio->fsstate = memPoolAlloc(squidaio_state_pool); ((squidaiostate_t *) (sio->fsstate))->fd = -1; ((squidaiostate_t *) (sio->fsstate))->flags.opening = 1; sio->swap_filen = filn; sio->swap_dirn = dirn; sio->mode = O_WRONLY | O_BINARY; sio->callback = callback; sio->callback_data = callback_data; sio->e = (StoreEntry *) e; cbdataLock(callback_data); Opening_FD++; statCounter.syscalls.disk.opens++; #if ASYNC_CREATE aioOpen(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644, storeAufsOpenDone, sio, INDEX_OF_SD(SD)); #else storeAufsOpenDone(fd, sio, fd, 0); #endif /* now insert into the replacement policy */ storeAufsDirReplAdd(SD, e); return sio; }
/* open for reading */ storeIOState * storeAufsOpen(SwapDir * SD, StoreEntry * e, STFNCB * file_callback, STIOCB * callback, void *callback_data) { sfileno f = e->swap_filen; char *path = storeAufsDirFullPath(SD, f, NULL); storeIOState *sio; #if !ASYNC_OPEN int fd; #endif debug(79, 3) ("storeAufsOpen: fileno %08X\n", f); /* * we should detect some 'too many files open' condition and return * NULL here. */ #ifdef MAGIC2 #ifndef CC_FRAMEWORK if (aioQueueSize() > MAGIC2) return NULL; #endif #endif #if !ASYNC_OPEN fd = file_open(path, O_RDONLY | O_BINARY | O_NOATIME); if (fd < 0) { debug(79, 3) ("storeAufsOpen: got failure (%d)\n", errno); return NULL; } #endif CBDATA_INIT_TYPE_FREECB(storeIOState, storeAufsIOFreeEntry); sio = cbdataAlloc(storeIOState); sio->fsstate = memPoolAlloc(squidaio_state_pool); ((squidaiostate_t *) (sio->fsstate))->fd = -1; ((squidaiostate_t *) (sio->fsstate))->flags.opening = 1; sio->swap_filen = f; sio->swap_dirn = SD->index; sio->mode = O_RDONLY | O_BINARY; sio->callback = callback; sio->callback_data = callback_data; sio->e = e; cbdataLock(callback_data); Opening_FD++; statCounter.syscalls.disk.opens++; #if ASYNC_OPEN aioOpen(path, O_RDONLY | O_BINARY | O_NOATIME, 0644, storeAufsOpenDone, sio, INDEX_OF_SD(SD)); #else storeAufsOpenDone(fd, sio, fd, 0); #endif return sio; }
void cfgUpdate() { extern int frame; if(frame % 5 != 0) return; for(std::map<std::string, time_t>::iterator i = filenamesModified.begin(); i != filenamesModified.end(); i++) { int fd; AioStat stat; if(Succeeded != aioOpen(i->first.c_str(), AioRead, &fd, 0)) continue; if(Succeeded != aioStat(fd, &stat)) continue; if(Succeeded != aioClose(fd)) continue; if(i->second < stat.modified) { cfgReadConfig(i->first.c_str()); filenamesModified[i->first] = stat.modified; } } }