-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IO is now more prepared to be asynchronous. Some headers have been pulled apart. Signed-off-by: Pedro Falcato <[email protected]>
- Loading branch information
Showing
24 changed files
with
758 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (c) 2016 - 2023 Pedro Falcato | ||
* This file is part of Onyx, and is released under the terms of the MIT License | ||
* check LICENSE at the root directory for more information | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
#ifndef _ONYX_BDEV_BASE_TYPES_H | ||
#define _ONYX_BDEV_BASE_TYPES_H | ||
|
||
#include <onyx/list.h> | ||
#include <onyx/page_iov.h> | ||
#include <onyx/types.h> | ||
|
||
/* Keep basic bdev types that are universally used and exported to consumers here. Do not keep | ||
* blockdev nor io_queue here. | ||
*/ | ||
|
||
struct blockdev; | ||
struct io_queue; | ||
|
||
typedef u64 sector_t; | ||
|
||
#define BIO_REQ_OP_MASK (0xff) | ||
#define BIO_REQ_READ_OP 0 | ||
#define BIO_REQ_WRITE_OP 1 | ||
#define BIO_REQ_DEVICE_SPECIFIC 2 | ||
|
||
/* BIO flags start at bit 8 since bits 0 - 7 are reserved for operations */ | ||
/* Note that we still have 24 bits for flags, which should be More Than Enough(tm) */ | ||
#define BIO_REQ_DONE (1 << 8) | ||
#define BIO_REQ_EIO (1 << 9) | ||
#define BIO_REQ_TIMEOUT (1 << 10) | ||
#define BIO_REQ_NOT_SUPP (1 << 11) | ||
|
||
struct bio_req | ||
{ | ||
unsigned int b_ref; | ||
uint32_t flags; | ||
sector_t sector_number; | ||
struct page_iov *vec; | ||
size_t nr_vecs; | ||
size_t curr_vec_index; | ||
struct blockdev *bdev; | ||
struct io_queue *b_queue; | ||
struct list_head list_node; | ||
unsigned long device_specific[4]; | ||
void (*b_end_io)(struct bio_req *req); | ||
void *b_private; | ||
struct page_iov b_inline_vec[]; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (c) 2016 - 2023 Pedro Falcato | ||
* This file is part of Onyx, and is released under the terms of the MIT License | ||
* check LICENSE at the root directory for more information | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
#ifndef _ONYX_BIO_H | ||
#define _ONYX_BIO_H | ||
|
||
#include <onyx/bdev_base_types.h> | ||
#include <onyx/compiler.h> | ||
|
||
#define BIO_MAX_INLINE_VECS 8 | ||
|
||
/** | ||
* @brief Allocate a bio_req | ||
* The system will attempt to allocate a bio_req with an inline page_iov vector. If not possible, it | ||
* will allocate them on the heap. | ||
* | ||
* @param gfp_flags GFP flags | ||
* @param nr_vecs Number of vectors | ||
* @return The allocated, initialized bio_req | ||
*/ | ||
struct bio_req *bio_alloc(unsigned int gfp_flags, size_t nr_vectors); | ||
|
||
/** | ||
* @brief Free a bio_req | ||
* | ||
* @param req Request to free | ||
*/ | ||
void bio_free(struct bio_req *req); | ||
|
||
static inline void bio_init(struct bio_req *req) | ||
{ | ||
*req = {}; | ||
req->b_ref = 1; | ||
} | ||
|
||
static inline void bio_get(struct bio_req *req) | ||
{ | ||
__atomic_add_fetch(&req->b_ref, 1, __ATOMIC_ACQUIRE); | ||
} | ||
|
||
static inline void bio_put(struct bio_req *req) | ||
{ | ||
if (__atomic_sub_fetch(&req->b_ref, 1, __ATOMIC_RELEASE) == 0) | ||
bio_free(req); | ||
} | ||
|
||
/** | ||
* @brief Submit a bio_req and wait for it to end | ||
* | ||
* @param dev Block device | ||
* @param req Request | ||
* @return errno-like result of the bio_req | ||
*/ | ||
int bio_submit_req_wait(struct blockdev *dev, struct bio_req *req); | ||
|
||
/** | ||
* @brief Complete a bio req | ||
* Callable from softirq context, and lower | ||
* | ||
* @param req Request to complete | ||
*/ | ||
static inline void bio_do_complete(struct bio_req *req) | ||
{ | ||
req->flags |= BIO_REQ_DONE; | ||
if (req->b_end_io) | ||
req->b_end_io(req); | ||
bio_put(req); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.