From e829154ffe1a7f4b1e46e29bbf8ee681af959d1e Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Wed, 20 Nov 2024 15:47:02 -0500 Subject: [PATCH] kernel/fs: Implement do_fd_io using do_iterative_fd_io. We need to hold a reference to the file descriptor throughout the I/O operation, which do_iterative_fd_io already takes care of. So just modify it to handle not having the additional callbacks. Nothing actually uses do_fd_io at present, though it will be in the next commits. --- src/system/kernel/fs/vfs_request_io.cpp | 54 +++++++++++++------------ 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/src/system/kernel/fs/vfs_request_io.cpp b/src/system/kernel/fs/vfs_request_io.cpp index 57214cc41c..2b991c540d 100644 --- a/src/system/kernel/fs/vfs_request_io.cpp +++ b/src/system/kernel/fs/vfs_request_io.cpp @@ -301,8 +301,14 @@ do_synchronous_iterative_vnode_io(struct vnode* vnode, void* openCookie, while (error == B_OK && vecLength > 0) { file_io_vec fileVecs[8]; size_t fileVecCount = 8; - error = getVecs(cookie, request, offset, vecLength, fileVecs, - &fileVecCount); + if (getVecs != NULL) { + error = getVecs(cookie, request, offset, vecLength, fileVecs, + &fileVecCount); + } else { + fileVecs[0].offset = offset; + fileVecs[0].length = vecLength; + fileVecCount = 1; + } if (error != B_OK || fileVecCount == 0) break; @@ -330,7 +336,8 @@ do_synchronous_iterative_vnode_io(struct vnode* vnode, void* openCookie, bool partial = length > 0; size_t bytesTransferred = request->Length() - length; request->SetTransferredBytes(partial, bytesTransferred); - finished(cookie, request, error, partial, bytesTransferred); + if (finished != NULL) + finished(cookie, request, error, partial, bytesTransferred); request->SetStatusAndNotify(error); return error; } @@ -469,16 +476,7 @@ vfs_asynchronous_write_pages(struct vnode* vnode, void* cookie, off_t pos, status_t do_fd_io(int fd, io_request* request) { - struct vnode* vnode; - file_descriptor* descriptor = get_fd_and_vnode(fd, &vnode, true); - if (descriptor == NULL) { - request->SetStatusAndNotify(B_FILE_ERROR); - return B_FILE_ERROR; - } - - FileDescriptorPutter descriptorPutter(descriptor); - - return vfs_vnode_io(vnode, descriptor->cookie, request); + return do_iterative_fd_io(fd, request, NULL, NULL, NULL); } @@ -493,7 +491,8 @@ do_iterative_fd_io(int fd, io_request* request, iterative_io_get_vecs getVecs, struct vnode* vnode; file_descriptor* descriptor = get_fd_and_vnode(fd, &vnode, true); if (descriptor == NULL) { - finished(cookie, request, B_FILE_ERROR, true, 0); + if (finished != NULL) + finished(cookie, request, B_FILE_ERROR, true, 0); request->SetStatusAndNotify(B_FILE_ERROR); return B_FILE_ERROR; } @@ -526,22 +525,27 @@ do_iterative_fd_io(int fd, io_request* request, iterative_io_get_vecs getVecs, &iterationCookie->next_finished_cookie); request->SetFinishedCallback(&do_iterative_fd_io_finish, iterationCookie); - request->SetIterationCallback(&do_iterative_fd_io_iterate, iterationCookie); + if (getVecs != NULL) + request->SetIterationCallback(&do_iterative_fd_io_iterate, iterationCookie); descriptorPutter.Detach(); // From now on the descriptor is put by our finish callback. - bool partialTransfer = false; - status_t error = do_iterative_fd_io_iterate(iterationCookie, request, - &partialTransfer); - if (error != B_OK || partialTransfer) { - if (partialTransfer) { - request->SetTransferredBytes(partialTransfer, - request->TransferredBytes()); - } + if (getVecs != NULL) { + bool partialTransfer = false; + status_t error = do_iterative_fd_io_iterate(iterationCookie, request, + &partialTransfer); + if (error != B_OK || partialTransfer) { + if (partialTransfer) { + request->SetTransferredBytes(partialTransfer, + request->TransferredBytes()); + } - request->SetStatusAndNotify(error); - return error; + request->SetStatusAndNotify(error); + return error; + } + } else { + return vfs_vnode_io(vnode, descriptor->cookie, request); } return B_OK;