Skip to content

Commit b131f48

Browse files
plugins/posix: minimized IO queue abstraction
This patch set minimizes the IO queue abstraction, making it as low- level as possible. It now only wraps the lowest-level IO-related API. It works with a set of IOs (writes or reads) while leaving the Xfer level logic to the upper layer (posix_backend). This patch set allows the posix_backend to implement the common logic, while only offloading the details of specific file access API to the IO queue abstraction. This patch set prepares the code for the POSIX plugin threading model implementation. With it, the threading will be implemented once, in the posix_backend. Signed-off-by: Anton Nayshtut <[email protected]>
1 parent 51385f9 commit b131f48

17 files changed

+862
-914
lines changed

src/plugins/posix/aio_queue.cpp

Lines changed: 0 additions & 151 deletions
This file was deleted.

src/plugins/posix/aio_queue.h

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/plugins/posix/io_queue.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "io_queue.h"
19+
20+
nixlPosixIOQueue::nixlPosixIOQueueCreateFn
21+
DEFINE_NIXL_POSIX_IO_QUEUE_FACTORY_NAME(nixlPosixAioIOQueue);
22+
nixlPosixIOQueue::nixlPosixIOQueueCreateFn
23+
DEFINE_NIXL_POSIX_IO_QUEUE_FACTORY_NAME(nixlPosixIoUringIOQueue);
24+
nixlPosixIOQueue::nixlPosixIOQueueCreateFn
25+
DEFINE_NIXL_POSIX_IO_QUEUE_FACTORY_NAME(nixlPosixLinuxAioIOQueue);
26+
27+
static const struct {
28+
const char *name;
29+
nixlPosixIOQueue::nixlPosixIOQueueCreateFn createFn;
30+
} factories[] = {
31+
#ifdef HAVE_LIBAIO
32+
{"POSIXAIO", DEFINE_NIXL_POSIX_IO_QUEUE_FACTORY_NAME(nixlPosixAioIOQueue)},
33+
#endif
34+
#ifdef HAVE_LIBURING
35+
{"URING", DEFINE_NIXL_POSIX_IO_QUEUE_FACTORY_NAME(nixlPosixIoUringIOQueue)},
36+
#endif
37+
#ifdef HAVE_LINUXAIO
38+
{"AIO", DEFINE_NIXL_POSIX_IO_QUEUE_FACTORY_NAME(nixlPosixLinuxAioIOQueue)},
39+
#endif
40+
{nullptr, nullptr}};
41+
42+
const uint32_t nixlPosixIOQueue::MIN_IOS = 64;
43+
const uint32_t nixlPosixIOQueue::MAX_IOS = 1024 * 64;
44+
45+
std::unique_ptr<nixlPosixIOQueue>
46+
nixlPosixIOQueue::instantiate(std::string_view io_queue_type, uint32_t max_ios) {
47+
for (const auto &factory : factories) {
48+
if (factory.name == io_queue_type.data()) {
49+
return factory.createFn(max_ios);
50+
}
51+
}
52+
return nullptr;
53+
}

src/plugins/posix/io_queue.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef POSIX_IO_QUEUE_H
19+
#define POSIX_IO_QUEUE_H
20+
21+
#include <stdint.h>
22+
#include <map>
23+
#include <string>
24+
#include <memory>
25+
#include "backend_aux.h"
26+
27+
typedef void (*nixlPosixIOQueueDoneCb)(void *ctx, uint32_t data_size, int error);
28+
29+
class nixlPosixIOQueue {
30+
public:
31+
typedef std::unique_ptr<nixlPosixIOQueue> (*nixlPosixIOQueueCreateFn)(uint32_t max_ios);
32+
33+
nixlPosixIOQueue(uint32_t max_ios) : max_ios_(normalizedMaxIOS(max_ios)) {}
34+
35+
virtual ~nixlPosixIOQueue() {}
36+
37+
virtual nixl_status_t
38+
enqueue(int fd,
39+
void *buf,
40+
size_t len,
41+
off_t offset,
42+
bool read,
43+
nixlPosixIOQueueDoneCb clb,
44+
void *ctx) = 0;
45+
virtual nixl_status_t
46+
post(void) = 0;
47+
virtual nixl_status_t
48+
poll(void) = 0;
49+
50+
static std::unique_ptr<nixlPosixIOQueue>
51+
instantiate(std::string_view io_queue_type, uint32_t max_ios);
52+
53+
protected:
54+
static uint32_t
55+
normalizedMaxIOS(uint32_t max_ios) {
56+
uint32_t m = std::max(MIN_IOS, max_ios);
57+
m = std::min(m, MAX_IOS);
58+
return m;
59+
}
60+
61+
uint32_t max_ios_;
62+
static const uint32_t MIN_IOS;
63+
static const uint32_t MAX_IOS;
64+
};
65+
66+
#define DEFINE_NIXL_POSIX_IO_QUEUE_FACTORY_NAME(class_name) class_name##Create
67+
68+
#define DEFINE_NIXL_POSIX_IO_QUEUE_FACTORY(class_name) \
69+
std::unique_ptr<nixlPosixIOQueue> DEFINE_NIXL_POSIX_IO_QUEUE_FACTORY_NAME(class_name)( \
70+
uint32_t max_ios) { \
71+
return std::make_unique<class_name>(max_ios); \
72+
}
73+
74+
#endif // POSIX_IO_QUEUE_H

0 commit comments

Comments
 (0)