This is some really bad code, and needs to be rewritten!
| 1263 | |
| 1264 | // This is some really bad code, and needs to be rewritten! |
| 1265 | int |
| 1266 | create_volume(int volume_number, off_t size_in_blocks, int scheme, CacheVol *cp) |
| 1267 | { |
| 1268 | static int curr_vol = 0; // FIXME: this will not reinitialize correctly |
| 1269 | off_t to_create = size_in_blocks; |
| 1270 | off_t blocks_per_vol = STRIPE_BLOCK_SIZE >> STORE_BLOCK_SHIFT; |
| 1271 | int full_disks = 0; |
| 1272 | |
| 1273 | cp->vol_number = volume_number; |
| 1274 | cp->scheme = scheme; |
| 1275 | if (fillExclusiveDisks(cp)) { |
| 1276 | Dbg(dbg_ctl_cache_init, "volume successfully filled from forced disks: volume_number=%d", volume_number); |
| 1277 | return 0; |
| 1278 | } |
| 1279 | |
| 1280 | int *sp = new int[gndisks]; |
| 1281 | memset(sp, 0, gndisks * sizeof(int)); |
| 1282 | |
| 1283 | int i = curr_vol; |
| 1284 | while (size_in_blocks > 0) { |
| 1285 | if (gdisks[i]->free_space >= (sp[i] + blocks_per_vol)) { |
| 1286 | sp[i] += blocks_per_vol; |
| 1287 | size_in_blocks -= blocks_per_vol; |
| 1288 | full_disks = 0; |
| 1289 | } else { |
| 1290 | full_disks += 1; |
| 1291 | if (full_disks == gndisks) { |
| 1292 | char config_file[PATH_NAME_MAX]; |
| 1293 | REC_ReadConfigString(config_file, "proxy.config.cache.volume_filename", PATH_NAME_MAX); |
| 1294 | if (cp->size) { |
| 1295 | Warning("not enough space to increase volume: [%d] to size: [%" PRId64 "]", volume_number, |
| 1296 | (int64_t)((to_create + cp->size) >> (20 - STORE_BLOCK_SHIFT))); |
| 1297 | } else { |
| 1298 | Warning("not enough space to create volume: [%d], size: [%" PRId64 "]", volume_number, |
| 1299 | (int64_t)(to_create >> (20 - STORE_BLOCK_SHIFT))); |
| 1300 | } |
| 1301 | |
| 1302 | Note("edit the %s file and restart traffic_server", config_file); |
| 1303 | delete[] sp; |
| 1304 | return -1; |
| 1305 | } |
| 1306 | } |
| 1307 | i = (i + 1) % gndisks; |
| 1308 | } |
| 1309 | cp->vol_number = volume_number; |
| 1310 | cp->scheme = scheme; |
| 1311 | curr_vol = i; |
| 1312 | for (i = 0; i < gndisks; i++) { |
| 1313 | if (sp[i] > 0) { |
| 1314 | while (sp[i] > 0) { |
| 1315 | DiskStripeBlock *p = gdisks[i]->create_volume(volume_number, sp[i], scheme); |
| 1316 | ink_assert(p && (p->len >= (unsigned int)blocks_per_vol)); |
| 1317 | sp[i] -= p->len; |
| 1318 | cp->num_vols++; |
| 1319 | cp->size += p->len; |
| 1320 | } |
| 1321 | if (!cp->disk_stripes[i]) { |
| 1322 | cp->disk_stripes[i] = gdisks[i]->get_diskvol(volume_number); |
no test coverage detected