private FSVolume getNextVolume(long blockSize) throws IOException {
FSVolume[] volumes = this.getVolumes();
if(volumes.length < 1) {
throw new DiskOutOfSpaceException("No more available volumes");
}
// since volumes could've been removed because of the failure
// make sure we are not out of bounds
if (curVolume >= volumes.length) {
curVolume = 0;
}
int startVolume = curVolume;
while (true) {
FSVolume volume = volumes[curVolume];
curVolume = (curVolume + 1) % volumes.length;
if (volume.getAvailable() > blockSize) {
return volume;
}
if (curVolume == startVolume) {
throw new DiskOutOfSpaceException(
"Insufficient space for an additional block");
}
}
}