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.
This commit is contained in:
Augustin Cavalier 2024-11-20 15:47:02 -05:00
parent 8f88247e04
commit e829154ffe

View File

@ -301,8 +301,14 @@ do_synchronous_iterative_vnode_io(struct vnode* vnode, void* openCookie,
while (error == B_OK && vecLength > 0) { while (error == B_OK && vecLength > 0) {
file_io_vec fileVecs[8]; file_io_vec fileVecs[8];
size_t fileVecCount = 8; size_t fileVecCount = 8;
error = getVecs(cookie, request, offset, vecLength, fileVecs, if (getVecs != NULL) {
&fileVecCount); 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) if (error != B_OK || fileVecCount == 0)
break; break;
@ -330,7 +336,8 @@ do_synchronous_iterative_vnode_io(struct vnode* vnode, void* openCookie,
bool partial = length > 0; bool partial = length > 0;
size_t bytesTransferred = request->Length() - length; size_t bytesTransferred = request->Length() - length;
request->SetTransferredBytes(partial, bytesTransferred); request->SetTransferredBytes(partial, bytesTransferred);
finished(cookie, request, error, partial, bytesTransferred); if (finished != NULL)
finished(cookie, request, error, partial, bytesTransferred);
request->SetStatusAndNotify(error); request->SetStatusAndNotify(error);
return error; return error;
} }
@ -469,16 +476,7 @@ vfs_asynchronous_write_pages(struct vnode* vnode, void* cookie, off_t pos,
status_t status_t
do_fd_io(int fd, io_request* request) do_fd_io(int fd, io_request* request)
{ {
struct vnode* vnode; return do_iterative_fd_io(fd, request, NULL, NULL, NULL);
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);
} }
@ -493,7 +491,8 @@ do_iterative_fd_io(int fd, io_request* request, iterative_io_get_vecs getVecs,
struct vnode* vnode; struct vnode* vnode;
file_descriptor* descriptor = get_fd_and_vnode(fd, &vnode, true); file_descriptor* descriptor = get_fd_and_vnode(fd, &vnode, true);
if (descriptor == NULL) { 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); request->SetStatusAndNotify(B_FILE_ERROR);
return 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); &iterationCookie->next_finished_cookie);
request->SetFinishedCallback(&do_iterative_fd_io_finish, iterationCookie); 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(); descriptorPutter.Detach();
// From now on the descriptor is put by our finish callback. // From now on the descriptor is put by our finish callback.
bool partialTransfer = false; if (getVecs != NULL) {
status_t error = do_iterative_fd_io_iterate(iterationCookie, request, bool partialTransfer = false;
&partialTransfer); status_t error = do_iterative_fd_io_iterate(iterationCookie, request,
if (error != B_OK || partialTransfer) { &partialTransfer);
if (partialTransfer) { if (error != B_OK || partialTransfer) {
request->SetTransferredBytes(partialTransfer, if (partialTransfer) {
request->TransferredBytes()); request->SetTransferredBytes(partialTransfer,
} request->TransferredBytes());
}
request->SetStatusAndNotify(error); request->SetStatusAndNotify(error);
return error; return error;
}
} else {
return vfs_vnode_io(vnode, descriptor->cookie, request);
} }
return B_OK; return B_OK;