Skip to content

Commit b607ba4

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 b607ba4

16 files changed

+861
-896
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/queue_factory_impl.h renamed to src/plugins/posix/io_queue.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18-
#ifndef QUEUE_FACTORY_IMPL_H
19-
#define QUEUE_FACTORY_IMPL_H
18+
#include "io_queue.h"
2019

21-
#include "posix_queue.h"
22-
23-
namespace QueueFactory {
24-
std::unique_ptr<nixlPosixQueue>
25-
createPosixAioQueue(int num_entries, nixl_xfer_op_t operation);
26-
27-
std::unique_ptr<nixlPosixQueue>
28-
createUringQueue(int num_entries, nixl_xfer_op_t operation);
29-
30-
std::unique_ptr<nixlPosixQueue>
31-
createLinuxAioQueue(int num_entries, nixl_xfer_op_t operation);
32-
33-
bool
34-
isLinuxAioAvailable();
35-
bool
36-
isUringAvailable();
37-
}; // namespace QueueFactory
38-
39-
#endif // QUEUE_FACTORY_IMPL_H
20+
std::map<std::string, nixlPosixIOQueue::nixlPosixIOQueueCreateFn> nixlPosixIOQueue::apis = {};
21+
const uint32_t nixlPosixIOQueue::MIN_IOS = 64;
22+
const uint32_t nixlPosixIOQueue::MAX_IOS = 1024 * 64;

src/plugins/posix/io_queue.h

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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)(void);
32+
33+
nixlPosixIOQueue() {}
34+
35+
virtual ~nixlPosixIOQueue() {}
36+
37+
virtual nixl_status_t
38+
init(uint32_t max_ios) = 0;
39+
virtual nixl_status_t
40+
enqueue(int fd,
41+
void *buf,
42+
size_t len,
43+
off_t offset,
44+
bool read,
45+
nixlPosixIOQueueDoneCb clb,
46+
void *ctx) = 0;
47+
virtual nixl_status_t
48+
post(void) = 0;
49+
virtual nixl_status_t
50+
poll(void) = 0;
51+
52+
static std::unique_ptr<nixlPosixIOQueue>
53+
getApi(const std::string &api_name) {
54+
auto it = apis.find(api_name);
55+
if (it != apis.end()) {
56+
nixlPosixIOQueueCreateFn create_fn = it->second;
57+
return create_fn();
58+
}
59+
return nullptr;
60+
}
61+
62+
static void
63+
registerIOQueue(const std::string &api_name, nixlPosixIOQueueCreateFn create_fn) {
64+
apis[api_name] = create_fn;
65+
}
66+
67+
static uint32_t
68+
normalizedMaxIOS(uint32_t max_ios) {
69+
uint32_t m = std::max(MIN_IOS, max_ios);
70+
m = std::min(m, MAX_IOS);
71+
return m;
72+
}
73+
74+
protected:
75+
static std::map<std::string, nixlPosixIOQueueCreateFn> apis;
76+
static const uint32_t MIN_IOS;
77+
static const uint32_t MAX_IOS;
78+
};
79+
80+
#define NIXL_POSIX_IO_QUEUE_REGISTER(io_queue_name, class_name) \
81+
static std::unique_ptr<nixlPosixIOQueue> class_name##Create(void) { \
82+
return std::make_unique<class_name>(); \
83+
} \
84+
static const bool registered = []() { \
85+
nixlPosixIOQueue::registerIOQueue(io_queue_name, class_name##Create); \
86+
return true; \
87+
}();
88+
89+
#endif // POSIX_IO_QUEUE_H

0 commit comments

Comments
 (0)