/* * submit a request to create a cache object for writing. * The StoreEntry structure is sent as a hint to the filesystem * to what will be stored in this object, to allow the filesystem * to select different polices depending on object size or type. */ storeIOState * storeCreate(StoreEntry * e, STIOCB * file_callback, STIOCB * close_callback, void *callback_data) { size_t objsize; sdirno dirn; SwapDir *SD; storeIOState *sio; store_io_stats.create.calls++; /* This is just done for logging purposes */ objsize = objectLen(e); if (objsize != -1) objsize += e->mem_obj->swap_hdr_sz; /* * Pick the swapdir * We assume that the header has been packed by now .. */ dirn = storeDirSelectSwapDir(e); if (dirn == -1) { debug(20, 2) ("storeCreate: no valid swapdirs for this object\n"); store_io_stats.create.select_fail++; return NULL; } debug(20, 2) ("storeCreate: Selected dir '%d' for obj size '%ld'\n", dirn, (long int) objsize); SD = &Config.cacheSwap.swapDirs[dirn]; /* Now that we have a fs to use, call its storeCreate function */ sio = SD->obj.create(SD, e, file_callback, close_callback, callback_data); if (NULL == sio) store_io_stats.create.create_fail++; else store_io_stats.create.success++; return sio; }
int storeDirMapAllocate(void) { int dirn = storeDirSelectSwapDir(); SwapDir *SD = &Config.cacheSwap.swapDirs[dirn]; int filn = file_map_allocate(SD->map, SD->suggest); SD->suggest = filn + 1; return (dirn << SWAP_DIR_SHIFT) | (filn & SWAP_FILE_MASK); }