Skip to content

Commit 9408a79

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 9408a79

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: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
#ifdef HAVE_LIBAIO
21+
std::unique_ptr<nixlPosixIOQueue> nixlPosixAioIOQueueCreate(uint32_t max_ios);
22+
#endif
23+
#ifdef HAVE_LIBURING
24+
std::unique_ptr<nixlPosixIOQueue> nixlPosixIoUringIOQueueCreate(uint32_t max_ios);
25+
#endif
26+
#ifdef HAVE_LINUXAIO
27+
std::unique_ptr<nixlPosixIOQueue> nixlPosixLinuxAioIOQueueCreate(uint32_t max_ios);
28+
#endif
29+
30+
static const struct {
31+
const char *name;
32+
nixlPosixIOQueue::nixlPosixIOQueueCreateFn createFn;
33+
} factories[] = {
34+
#ifdef HAVE_LIBAIO
35+
{"POSIXAIO", nixlPosixAioIOQueueCreate},
36+
#endif
37+
#ifdef HAVE_LIBURING
38+
{"URING", nixlPosixIoUringIOQueueCreate},
39+
#endif
40+
#ifdef HAVE_LINUXAIO
41+
{"AIO", nixlPosixLinuxAioIOQueueCreate},
42+
#endif
43+
};
44+
45+
const uint32_t nixlPosixIOQueue::MIN_IOS = 64;
46+
const uint32_t nixlPosixIOQueue::MAX_IOS = 1024 * 64;
47+
48+
std::unique_ptr<nixlPosixIOQueue>
49+
nixlPosixIOQueue::instantiate(std::string_view io_queue_type, uint32_t max_ios) {
50+
for (const auto &factory : factories) {
51+
if (io_queue_type == factory.name) {
52+
return factory.createFn(max_ios);
53+
}
54+
}
55+
return nullptr;
56+
}

src/plugins/posix/io_queue.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 <functional>
26+
#include "backend_aux.h"
27+
28+
typedef void (*nixlPosixIOQueueDoneCb)(void *ctx, uint32_t data_size, int error);
29+
30+
class nixlPosixIOQueue {
31+
public:
32+
using nixlPosixIOQueueCreateFn =
33+
std::function<std::unique_ptr<nixlPosixIOQueue>(uint32_t max_ios)>;
34+
35+
nixlPosixIOQueue(uint32_t max_ios) : max_ios_(normalizedMaxIOS(max_ios)) {}
36+
37+
virtual ~nixlPosixIOQueue() {}
38+
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+
instantiate(std::string_view io_queue_type, uint32_t max_ios);
54+
55+
protected:
56+
static uint32_t
57+
normalizedMaxIOS(uint32_t max_ios) {
58+
uint32_t m = std::max(MIN_IOS, max_ios);
59+
m = std::min(m, MAX_IOS);
60+
return m;
61+
}
62+
63+
uint32_t max_ios_;
64+
static const uint32_t MIN_IOS;
65+
static const uint32_t MAX_IOS;
66+
};
67+
68+
#endif // POSIX_IO_QUEUE_H

0 commit comments

Comments
 (0)