Here is a description of the problem and my proposed
sollution. Lifted this right out of my source code,
where I originally documented it.
FIXME: One problem, what happens if the stage seg
fills up and ana lloc request comes in
but we have a block in the stage seg thats been
alloced but not writen to yet. We should
change this system! We need to request_block(), then
write to that block and when we are
all done, a release_block() should happen. All
writes shoud be done almost immediately AFTER
requesting a block and a release should be done
immediately after the write so we dont hold up
the block for any length of time! This will work as
long as we wont deadlock when we need
to alloc a new block (but seg has none free) in order
to write a block... this is... before we
release it. See the circular dependency? One
function has a block, but allocs another (or calls
a fn that allocs another) before release the one it has!
As long as the above condition is met, we can simply
give out block numbers and then keep track of
how many are currently "out for writing", When an
alloc request comes in but the segis full, as soon as
that number hits 0 we can write it to disk, start a
new stage segment, and then satisfy the blocking alloc
request from earlier.
UPDATE: This plan is not going to work in its current
state bacsue the block indirection code
needs to be able to alloc multiple blocks without
writing them. Something is going to need to be
reworked here :( Block indirection code seems to
work, so I hate to mess with it.... and stage seg
stuff is still fairly simple, and simplicity is
good.. so I hate to change that :( What to do??
UPDATE: I think I've figured out a decent plan for
this. Protect file block additions with a single
lock, so only ONE addition can be happening at once.
Will have to use a semaphore as block io could
cause sleeping. Add a function to stageseg lib that
wil tell use how many free blocks are left. Use it
before starting the addition to make sure that we
have enough free blocks to ask for even if we have to ask
for one per indirection level (+1 for the data
block). If we dont have eno, force flushing of the
segment, then
create a new one. Then we will have enough. Once we
have enough blocks to ensure file creation, go ahead and
do it. Then release the lock.