On Fri, May 27, 2022 at 11:44:02AM +0100, David Howells wrote: > Copy cifs's setup_aio_ctx_iter() and to lib/iov_iter.c and generalise it as > extract_iter_to_iter(). This allocates and sets up an array of bio_vecs > for all the page fragments in an I/O iterator and sets a second supplied > iterator to bvec-type pointing to the array. > > This is can be used when setting up for a direct I/O or an asynchronous I/O > to set up a record of the page fragments that are going to contribute to > the buffer, paging them all in to prevent DIO->mmap loops and allowing the > original iterator to be deallocated (it may be on the stack of the caller). > > Note that extract_iter_to_iter() doesn't actually need to make a separate > allocation for the page array. It can place the page array at the end of > the bvec array storage, provided it traverses both arrays from the 0th > element forwards. I really do not like this as a general purpose helper. This is an odd quirk that we really generally should not needed unless you have very convoluted locking. So please keep it inside of cifs.