Skip to contentSkip to conversation

reiser4: FITRIM ioctl -- how to grab the space?

DISCUSSION Ivan Shapovalov 1 participant 1 message Jul 31, 2014

lore
Share & tools
lore
#0 lore raw

(resend -- forgot the Cc:, sorry for spamming)

...and here is volume 2 of my neverending question series :)

A stub ioctl, placed as I described, seems to work and log a warning each time I invoke fstrim on anything mounted.

Now on to space allocation. This seems pretty easy in the first approximation:
reiser4_alloc_blocks_bitmap() seems to do what's needed, finding the nearest free extent, not the biggest one. So we could just call reiser4_alloc_blocks() plus reiser4_dealloc_blocks(BA_DEFER) repeatedly, while allocations succeed.

However, I suppose we need to grab all free space before proceeding. There is no primitive for grabbing all free space, so we need to read block counters, calculate amount of space to grab and then call reiser4_grab_reserved() (as we want to allocate everything, including the reserved space. This creates two problems (as I see it):
- there is a race between reading block counters (under sb spinlock) and performing the grab (which takes the spinlock on its own);
- if anything will try to grab space during discarding, it will get an ENOSPC, while it's better to make the process wait until discarding is completed.

I'm not sure whether the last problem really exists (there is BA_CAN_COMMIT, but I don't know whether is it used consistently where possible).

Could you explain these things?

Thanks,

Signature · 1 line
Ivan Shapovalov / intelfx /