Skip to content

Commit a81c168

Browse files
plugins/posix: file_api abstraction
This patch set replaces the queue-abstraction based API implementation with the file_api abstraction. Unlike queue abstraction, the file_api abstraction is very low-level. It 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 file_api 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 011d7de commit a81c168

15 files changed

+858
-845
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/file_api.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 "file_api.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, nixlPosixFileApi::nixlPosixFileApiCreateFn> nixlPosixFileApi::apis = {};
21+
const uint32_t nixlPosixFileApi::MIN_AIO_REQS = 64;
22+
const uint32_t nixlPosixFileApi::MAX_AIO_REQS = 1024 * 64;

src/plugins/posix/file_api.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 FILE_API_H
19+
#define FILE_API_H
20+
21+
#include <stdint.h>
22+
#include <map>
23+
#include <string>
24+
#include <memory>
25+
#include "backend_aux.h"
26+
27+
typedef void (*nixlPosixFileApiDoneCb)(void *ctx, uint32_t data_size, int error);
28+
29+
class nixlPosixFileApi {
30+
public:
31+
typedef std::unique_ptr<nixlPosixFileApi> (*nixlPosixFileApiCreateFn)(void);
32+
33+
nixlPosixFileApi() {}
34+
35+
virtual ~nixlPosixFileApi() {}
36+
37+
virtual nixl_status_t
38+
init(uint32_t max_chunks) = 0;
39+
virtual nixl_status_t
40+
add(int fd,
41+
void *buf,
42+
size_t len,
43+
off_t offset,
44+
bool read,
45+
nixlPosixFileApiDoneCb clb,
46+
void *ctx) = 0;
47+
virtual nixl_status_t
48+
post(void) = 0;
49+
virtual nixl_status_t
50+
pump(void) = 0;
51+
52+
static std::unique_ptr<nixlPosixFileApi>
53+
getApi(const std::string &api_name) {
54+
auto it = apis.find(api_name);
55+
if (it != apis.end()) {
56+
nixlPosixFileApiCreateFn create_fn = it->second;
57+
return create_fn();
58+
}
59+
return nullptr;
60+
}
61+
62+
static void
63+
registerApi(const std::string &api_name, nixlPosixFileApiCreateFn create_fn) {
64+
apis[api_name] = create_fn;
65+
}
66+
67+
static uint32_t
68+
normalizedMaxChunks(uint32_t max_chunks) {
69+
uint32_t m = std::max(MIN_AIO_REQS, max_chunks);
70+
m = std::min(m, MAX_AIO_REQS);
71+
return m;
72+
}
73+
74+
protected:
75+
static std::map<std::string, nixlPosixFileApiCreateFn> apis;
76+
static const uint32_t MIN_AIO_REQS;
77+
static const uint32_t MAX_AIO_REQS;
78+
};
79+
80+
#define NIXL_FILE_API_REGISTER(api_name, class_name) \
81+
static std::unique_ptr<nixlPosixFileApi> class_name##Create(void) { \
82+
return std::make_unique<class_name>(); \
83+
} \
84+
static const bool registered = []() { \
85+
nixlPosixFileApi::registerApi(api_name, class_name##Create); \
86+
return true; \
87+
}();
88+
89+
#endif // FILE_API_H

0 commit comments

Comments
 (0)