]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | /* |
2 | * This file is open source software, licensed to you under the terms | |
3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file | |
4 | * distributed with this work for additional information regarding copyright | |
5 | * ownership. You may not use this file except in compliance with the License. | |
6 | * | |
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, | |
12 | * software distributed under the License is distributed on an | |
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
14 | * KIND, either express or implied. See the License for the | |
15 | * specific language governing permissions and limitations | |
16 | * under the License. | |
17 | */ | |
18 | ||
19 | /* | |
20 | * Copyright (C) 2015 Cloudius Systems, Ltd. | |
21 | */ | |
22 | ||
23 | #pragma once | |
24 | ||
25 | /// \mainpage | |
26 | /// | |
27 | /// Seastar is a high performance C++ application framework for high | |
28 | /// concurrency server applications. | |
29 | /// | |
30 | /// A good place to start is the [Tutorial](doc/tutorial.md). | |
31 | /// | |
32 | /// Please see: | |
33 | /// - \ref future-module Documentation on futures and promises, which are | |
34 | /// the seastar building blocks. | |
35 | /// - \ref future-util Utililty functions for working with futures | |
36 | /// - \ref memory-module Memory management | |
37 | /// - \ref networking-module TCP/IP networking | |
38 | /// - \ref fileio-module File Input/Output | |
39 | /// - \ref smp-module Multicore support | |
40 | /// - \ref fiber-module Utilities for managing loosely coupled chains of | |
41 | /// continuations, also known as fibers | |
42 | /// - \ref thread-module Support for traditional threaded execution | |
43 | ||
44 | #include <seastar/core/sstring.hh> | |
45 | #include <seastar/core/future.hh> | |
9f95a23c TL |
46 | #include <seastar/core/file-types.hh> |
47 | #include <seastar/util/bool_class.hh> | |
48 | #include "./internal/api-level.hh" | |
11fdf7f2 TL |
49 | |
50 | namespace seastar { | |
51 | ||
52 | // iostream.hh | |
53 | template <class CharType> class input_stream; | |
54 | template <class CharType> class output_stream; | |
55 | ||
56 | // reactor.hh | |
9f95a23c TL |
57 | SEASTAR_INCLUDE_API_V2 namespace api_v2 { class server_socket; } |
58 | ||
59 | #if SEASTAR_API_LEVEL <= 1 | |
60 | ||
61 | SEASTAR_INCLUDE_API_V1 namespace api_v1 { class server_socket; } | |
62 | ||
63 | #endif | |
64 | ||
11fdf7f2 TL |
65 | class connected_socket; |
66 | class socket_address; | |
9f95a23c | 67 | struct listen_options; |
11fdf7f2 TL |
68 | enum class transport; |
69 | ||
70 | // file.hh | |
71 | class file; | |
9f95a23c TL |
72 | struct file_open_options; |
73 | struct stat_data; | |
11fdf7f2 TL |
74 | |
75 | // Networking API | |
76 | ||
77 | /// \defgroup networking-module Networking | |
78 | /// | |
79 | /// Seastar provides a simple networking API, backed by two | |
80 | /// TCP/IP stacks: the POSIX stack, utilizing the kernel's | |
81 | /// BSD socket APIs, and the native stack, implement fully | |
82 | /// within seastar and able to drive network cards directly. | |
83 | /// The native stack supports zero-copy on both transmit | |
84 | /// and receive, and is implemented using seastar's high | |
85 | /// performance, lockless sharded design. The network stack | |
86 | /// can be selected with the \c \--network-stack command-line | |
87 | /// parameter. | |
88 | ||
89 | /// \addtogroup networking-module | |
90 | /// @{ | |
91 | ||
92 | /// Listen for connections on a given port | |
93 | /// | |
94 | /// Starts listening on a given address for incoming connections. | |
95 | /// | |
96 | /// \param sa socket address to listen on | |
97 | /// | |
98 | /// \return \ref server_socket object ready to accept connections. | |
99 | /// | |
100 | /// \see listen(socket_address sa, listen_options opts) | |
101 | server_socket listen(socket_address sa); | |
102 | ||
103 | /// Listen for connections on a given port | |
104 | /// | |
105 | /// Starts listening on a given address for incoming connections. | |
106 | /// | |
107 | /// \param sa socket address to listen on | |
108 | /// \param opts options controlling the listen operation | |
109 | /// | |
110 | /// \return \ref server_socket object ready to accept connections. | |
111 | /// | |
112 | /// \see listen(socket_address sa) | |
113 | server_socket listen(socket_address sa, listen_options opts); | |
114 | ||
115 | /// Establishes a connection to a given address | |
116 | /// | |
117 | /// Attempts to connect to the given address. | |
118 | /// | |
119 | /// \param sa socket address to connect to | |
120 | /// | |
121 | /// \return a \ref connected_socket object, or an exception | |
122 | future<connected_socket> connect(socket_address sa); | |
123 | ||
124 | /// Establishes a connection to a given address | |
125 | /// | |
126 | /// Attempts to connect to the given address with a defined local endpoint | |
127 | /// | |
128 | /// \param sa socket address to connect to | |
129 | /// \param local socket address for local endpoint | |
130 | /// \param proto transport protocol (TCP or SCTP) | |
131 | /// | |
132 | /// \return a \ref connected_socket object, or an exception | |
133 | future<connected_socket> connect(socket_address sa, socket_address local, transport proto); | |
134 | ||
135 | /// @} | |
136 | ||
137 | /// \defgroup fileio-module File Input/Output | |
138 | /// | |
139 | /// Seastar provides a file API to deal with persistent storage. | |
140 | /// Unlike most file APIs, seastar offers unbuffered file I/O | |
141 | /// (similar to, and based on, \c O_DIRECT). Unbuffered I/O means | |
142 | /// that the application is required to do its own caching, but | |
143 | /// delivers better performance if this caching is done correctly. | |
144 | /// | |
145 | /// For random I/O or sequential unbuffered I/O, the \ref file | |
146 | /// class provides a set of methods for reading, writing, discarding, | |
147 | /// or otherwise manipulating a file. For buffered sequential I/O, | |
148 | /// see \ref make_file_input_stream() and \ref make_file_output_stream(). | |
149 | ||
150 | /// \addtogroup fileio-module | |
151 | /// @{ | |
152 | ||
153 | /// Opens or creates a file. The "dma" in the name refers to the fact | |
154 | /// that data transfers are unbuffered and uncached. | |
155 | /// | |
156 | /// \param name the name of the file to open or create | |
157 | /// \param flags various flags controlling the open process | |
158 | /// \return a \ref file object, as a future | |
159 | /// | |
160 | /// \note | |
161 | /// The file name is not guaranteed to be stable on disk, unless the | |
162 | /// containing directory is sync'ed. | |
163 | /// | |
164 | /// \relates file | |
165 | future<file> open_file_dma(sstring name, open_flags flags); | |
166 | ||
167 | /// Opens or creates a file. The "dma" in the name refers to the fact | |
168 | /// that data transfers are unbuffered and uncached. | |
169 | /// | |
170 | /// \param name the name of the file to open or create | |
171 | /// \param flags various flags controlling the open process | |
172 | /// \param options options for opening the file | |
173 | /// \return a \ref file object, as a future | |
174 | /// | |
175 | /// \note | |
176 | /// The file name is not guaranteed to be stable on disk, unless the | |
177 | /// containing directory is sync'ed. | |
178 | /// | |
179 | /// \relates file | |
180 | future<file> open_file_dma(sstring name, open_flags flags, file_open_options options); | |
181 | ||
182 | /// Checks if a given directory supports direct io | |
183 | /// | |
184 | /// Seastar bypasses the Operating System caches and issues direct io to the | |
185 | /// underlying block devices. Projects using seastar should check if the directory | |
186 | /// lies in a filesystem that support such operations. This function can be used | |
187 | /// to do that. | |
188 | /// | |
189 | /// It will return if direct io can be used, or throw an std::system_error | |
190 | /// exception, with the EINVAL error code. | |
191 | /// | |
192 | /// A std::system_error with the respective error code is also thrown if \ref path is | |
193 | /// not a directory. | |
194 | /// | |
195 | /// \param path the directory we need to verify. | |
196 | future<> check_direct_io_support(sstring path); | |
197 | ||
198 | /// Opens a directory. | |
199 | /// | |
200 | /// \param name name of the directory to open | |
201 | /// | |
202 | /// \return a \ref file object representing a directory. The only | |
203 | /// legal operations are \ref file::list_directory(), | |
204 | /// \ref file::fsync(), and \ref file::close(). | |
205 | /// | |
206 | /// \relates file | |
207 | future<file> open_directory(sstring name); | |
208 | ||
209 | /// Creates a new directory. | |
210 | /// | |
211 | /// \param name name of the directory to create | |
9f95a23c | 212 | /// \param permissions optional file permissions of the directory to create. |
11fdf7f2 TL |
213 | /// |
214 | /// \note | |
215 | /// The directory is not guaranteed to be stable on disk, unless the | |
216 | /// containing directory is sync'ed. | |
9f95a23c | 217 | future<> make_directory(sstring name, file_permissions permissions = file_permissions::default_dir_permissions); |
11fdf7f2 TL |
218 | |
219 | /// Ensures a directory exists | |
220 | /// | |
221 | /// Checks whether a directory exists, and if not, creates it. Only | |
222 | /// the last component of the directory name is created. | |
223 | /// | |
224 | /// \param name name of the directory to potentially create | |
9f95a23c | 225 | /// \param permissions optional file permissions of the directory to create. |
11fdf7f2 TL |
226 | /// |
227 | /// \note | |
228 | /// The directory is not guaranteed to be stable on disk, unless the | |
229 | /// containing directory is sync'ed. | |
9f95a23c TL |
230 | /// If the directory exists, the provided permissions are not applied. |
231 | future<> touch_directory(sstring name, file_permissions permissions = file_permissions::default_dir_permissions); | |
11fdf7f2 TL |
232 | |
233 | /// Recursively ensures a directory exists | |
234 | /// | |
235 | /// Checks whether each component of a directory exists, and if not, creates it. | |
236 | /// | |
237 | /// \param name name of the directory to potentially create | |
9f95a23c | 238 | /// \param permissions optional file permissions of the directory to create. |
11fdf7f2 TL |
239 | /// |
240 | /// \note | |
241 | /// This function fsyncs each component created, and is therefore guaranteed to be stable on disk. | |
9f95a23c TL |
242 | /// The provided permissions are applied only on the last component in the path, if it needs to be created, |
243 | /// if intermediate directories do not exist, they are created with the default_dir_permissions. | |
244 | /// If any directory exists, the provided permissions are not applied. | |
245 | future<> recursive_touch_directory(sstring name, file_permissions permissions = file_permissions::default_dir_permissions); | |
11fdf7f2 TL |
246 | |
247 | /// Synchronizes a directory to disk | |
248 | /// | |
249 | /// Makes sure the modifications in a directory are synchronized in disk. | |
250 | /// This is useful, for instance, after creating or removing a file inside the | |
251 | /// directory. | |
252 | /// | |
253 | /// \param name name of the directory to potentially create | |
254 | future<> sync_directory(sstring name); | |
255 | ||
256 | ||
9f95a23c | 257 | /// Removes (unlinks) a file or an empty directory |
11fdf7f2 | 258 | /// |
9f95a23c | 259 | /// \param name name of the file or the directory to remove |
11fdf7f2 TL |
260 | /// |
261 | /// \note | |
262 | /// The removal is not guaranteed to be stable on disk, unless the | |
263 | /// containing directory is sync'ed. | |
264 | future<> remove_file(sstring name); | |
265 | ||
266 | /// Renames (moves) a file. | |
267 | /// | |
268 | /// \param old_name existing file name | |
269 | /// \param new_name new file name | |
270 | /// | |
271 | /// \note | |
272 | /// The rename is not guaranteed to be stable on disk, unless the | |
273 | /// both containing directories are sync'ed. | |
274 | future<> rename_file(sstring old_name, sstring new_name); | |
275 | ||
9f95a23c TL |
276 | struct follow_symlink_tag { }; |
277 | using follow_symlink = bool_class<follow_symlink_tag>; | |
278 | ||
279 | /// Return stat information about a file. | |
280 | /// | |
281 | /// \param name name of the file to return its stat information | |
282 | /// \param follow_symlink follow symbolic links. | |
283 | /// | |
284 | /// \return stat_data of the file identified by name. | |
285 | /// If name identifies a symbolic link then stat_data is returned either for the target of the link, | |
286 | /// with follow_symlink::yes, or for the link itself, with follow_symlink::no. | |
287 | future<stat_data> file_stat(sstring name, follow_symlink fs = follow_symlink::yes); | |
288 | ||
11fdf7f2 TL |
289 | /// Return the size of a file. |
290 | /// | |
291 | /// \param name name of the file to return the size | |
9f95a23c TL |
292 | /// |
293 | /// Note that file_size of a symlink is NOT the size of the symlink - | |
294 | /// which is the length of the pathname it contains - | |
295 | /// but rather the size of the file to which it points. | |
11fdf7f2 TL |
296 | future<uint64_t> file_size(sstring name); |
297 | ||
9f95a23c TL |
298 | /// Check file access. |
299 | /// | |
300 | /// \param name name of the file to check | |
301 | /// \param flags bit pattern containing type of access to check (read/write/execute or exists). | |
302 | /// | |
303 | /// If only access_flags::exists is queried, returns true if the file exists, or false otherwise. | |
304 | /// Throws a compat::filesystem::filesystem_error exception if any error other than ENOENT is encountered. | |
305 | /// | |
306 | /// If any of the access_flags (read/write/execute) is set, returns true if the file exists and is | |
307 | /// accessible with the requested flags, or false if the file exists and is not accessible | |
308 | /// as queried. | |
309 | /// Throws a compat::filesystem::filesystem_error exception if any error other than EACCES is encountered. | |
310 | /// Note that if any path component leading to the file is not searchable, the file is considered inaccessible | |
311 | /// with the requested mode and false will be returned. | |
312 | future<bool> file_accessible(sstring name, access_flags flags); | |
313 | ||
11fdf7f2 TL |
314 | /// check if a file exists. |
315 | /// | |
316 | /// \param name name of the file to check | |
317 | future<bool> file_exists(sstring name); | |
318 | ||
319 | /// Creates a hard link for a file | |
320 | /// | |
321 | /// \param oldpath existing file name | |
322 | /// \param newpath name of link | |
323 | /// | |
324 | future<> link_file(sstring oldpath, sstring newpath); | |
325 | ||
9f95a23c TL |
326 | /// Changes the permissions mode of a file or directory |
327 | /// | |
328 | /// \param name name of the file ot directory to change | |
329 | /// \param permissions permissions to set | |
330 | /// | |
331 | future<> chmod(sstring name, file_permissions permissions); | |
332 | ||
11fdf7f2 TL |
333 | /// Return information about the filesystem where a file is located. |
334 | /// | |
335 | /// \param name name of the file to inspect | |
336 | future<fs_type> file_system_at(sstring name); | |
337 | ||
338 | /// Return space available to unprivileged users in filesystem where a file is located, in bytes. | |
339 | /// | |
340 | /// \param name name of the file to inspect | |
341 | future<uint64_t> fs_avail(sstring name); | |
342 | ||
343 | /// Return free space in filesystem where a file is located, in bytes. | |
344 | /// | |
345 | /// \param name name of the file to inspect | |
346 | future<uint64_t> fs_free(sstring name); | |
347 | /// @} | |
348 | ||
349 | } |