We currently do not set csi_aio for DIO and use this to
control when we free the aio struct. (For AIO, we must
free it in cl_sync_io_note, but for other users, we have to
wait until after cl_sync_io_wait has been called.)
The lack of csi_aio causes trouble for the implementation
of the next patch, so instead we always set it and control
freeing by checking at that time if we are doing DIO.
Signed-off-by: Patrick Farrell <pfarrell@whamcloud.com>
Change-Id: I2122a6a2dad33179e9114494b53c09d0b64f0fa6
Reviewed-on: https://review.whamcloud.com/44153
Reviewed-by: Wang Shilong <wangshilong1991@gmail.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
* Hold one ref so that it won't be released until
* every pages is added.
*/
* Hold one ref so that it won't be released until
* every pages is added.
*/
- cl_sync_io_init_notify(&aio->cda_sync, 1, is_sync_kiocb(iocb) ?
- NULL : aio, cl_aio_end);
+ cl_sync_io_init_notify(&aio->cda_sync, 1, aio, cl_aio_end);
cl_page_list_init(&aio->cda_pages);
aio->cda_iocb = iocb;
if (is_sync_kiocb(iocb))
cl_page_list_init(&aio->cda_pages);
aio->cda_iocb = iocb;
if (is_sync_kiocb(iocb))
wake_up_locked(&anchor->csi_waitq);
if (end_io)
end_io(env, anchor);
wake_up_locked(&anchor->csi_waitq);
if (end_io)
end_io(env, anchor);
- if (anchor->csi_aio)
- aio = anchor->csi_aio;
+
+ aio = anchor->csi_aio;
spin_unlock(&anchor->csi_waitq.lock);
/**
spin_unlock(&anchor->csi_waitq.lock);
/**
- * If anchor->csi_aio is set, we are responsible for freeing
- * memory here rather than when cl_sync_io_wait() completes.
+ * For AIO (!is_sync_kiocb), we are responsible for freeing
+ * memory here. This is because we are the last user of this
+ * aio struct, whereas in other cases, we will call
+ * cl_sync_io_wait to wait after this, and so the memory is
+ * freed after that call.
+ if (aio && !is_sync_kiocb(aio->cda_iocb))
+ cl_aio_free(env, aio);