On 28.07.2016 07:55, Kent Overstreet wrote: > On Wed, Jul 27, 2016 at 05:16:36PM +0200, Stefan Bader wrote: >> So here is another attempt which does half the proposed changes. And before you >> point out that it looks still ugly, let me explain some reasons. The goal for me >> would be to have something as small as possible to be acceptable as stable change. >> And the part about putting a bio on the stack and using submit_bio_wait: I >> believe you meant in read_super to replace the __bread. I was thinking about >> that but in the end it seemed to make the change unnecessary big. Whether using >> __bread or submit_bio_wait, in both cases and without needing to make more >> changes on the write side, read_super has to return the in-memory and on-disk >> variant of the superblock. So as long as nothing that is related to __bread is >> leaked out of read_super, it is much better than what is there now. And I remain >> as small as possible for the delta. > > I like that approach much better. I suppose it's not _strictly_ necessary to rip > out the __bread()... > > Only other comment is that you shouldn't have to pass the buffer to > __write_super() - I'd just move the bch_bio_map() call to when the struct > cache/cached_dev is being initialized (or rip it out and initialize the bvec by > hand) and never touch it after that. Hm, doing that would save three simple changes to add a new argument to that private functions at the cost of haven the map call twice and a (more) complicated calculation of the > >> So there is one part of the patch which I find hard to do in a better manner but >> is a bit ugly: and that is to sanely free the sb_disk_data blob on all error >> paths but not on success when it is assigned to either cache or cached_dev. >> Could possibly pass the address of the pointer and then clear it inside the >> called functions. Not sure that would be much less strange... > > Yeah that is a hassle - that's why in the 4k superblocks patch in bcache-dev I > added that "disk_sb" struct - it owns the buffer and random other crap. You > could read that patch for ideas if you want, look at how it transfers ownership > of the disk_sb. > I had a look but it felt like I could get into too much follow-up changes going that path. But I think I got it simpler now. One note about that area: both register calls can run into problems but only one actually returns that status. And both do not seem to free the allocated structures (cache or cache_dev). It is at least not obvious whether this is ever done. I working around this by moving the assignment of the buffer page and the mapping to a place where an error exit no longer is possible. So the release functions will only see a non NULL pointer if things went well (reality required to revise that a little bit as one of the register calls that can fail is actually doing the write). So now there is just one oddness: when I am testing this (unfortunately right now I only have a normal 4k case), after calling make-bache with cache and backing device, this all looks great and debugging shows the __write_super being called. But reading the from userspace will return the old data until I stop the bcache device and unregister the cache (which does not show any further writes). I cannot decide what I should think here... -Stefan