MCPcopy Create free account
hub / github.com/apache/trafficserver / create_volume

Method create_volume

src/iocore/cache/CacheDisk.cc:253–345  ·  view source on GitHub ↗

size is in store blocks */

Source from the content-addressed store, hash-verified

251
252/* size is in store blocks */
253DiskStripeBlock *
254CacheDisk::create_volume(int number, off_t size_in_blocks, int scheme)
255{
256 if (size_in_blocks == 0) {
257 return nullptr;
258 }
259
260 DiskStripeBlockQueue *q = free_blocks->dpb_queue.head;
261 DiskStripeBlockQueue *closest_match = q;
262
263 if (!q) {
264 return nullptr;
265 }
266
267 off_t max_blocks = MAX_STRIPE_SIZE >> STORE_BLOCK_SHIFT;
268 size_in_blocks = (size_in_blocks <= max_blocks) ? size_in_blocks : max_blocks;
269
270 int blocks_per_vol = STORE_BLOCKS_PER_STRIPE;
271 // ink_assert(!(size_in_blocks % blocks_per_vol));
272 DiskStripeBlock *p = nullptr;
273 for (; q; q = q->link.next) {
274 if (static_cast<off_t>(q->b->len) >= size_in_blocks) {
275 p = q->b;
276 q->new_block = 1;
277 break;
278 } else {
279 if (closest_match->b->len < q->b->len) {
280 closest_match = q;
281 }
282 }
283 }
284
285 if (!p && closest_match) {
286 /* allocate from the closest match */
287 q = closest_match;
288 p = q->b;
289 q->new_block = 1;
290 ink_assert(size_in_blocks > (off_t)p->len);
291 /* allocate in 128 megabyte chunks. The Remaining space should
292 be thrown away */
293 size_in_blocks = (p->len - (p->len % blocks_per_vol));
294 wasted_space += p->len % blocks_per_vol;
295 }
296
297 free_blocks->dpb_queue.remove(q);
298 free_space -= p->len;
299 free_blocks->size -= p->len;
300
301 size_t new_size = p->len - size_in_blocks;
302 if (new_size >= static_cast<size_t>(blocks_per_vol)) {
303 /* create a new volume */
304 DiskStripeBlock *dpb = &header->vol_info[header->num_diskvol_blks];
305 *dpb = *p;
306 dpb->len -= size_in_blocks;
307 dpb->offset += (size_in_blocks * STORE_BLOCK_SIZE);
308
309 DiskStripeBlockQueue *new_q = new DiskStripeBlockQueue();
310 new_q->b = dpb;

Callers 3

cplist_reconfigureFunction · 0.80
create_volumeFunction · 0.80
fillExclusiveDisksFunction · 0.80

Calls 2

removeMethod · 0.45
enqueueMethod · 0.45

Tested by

no test coverage detected