]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * convert RGW commands to file commands | |
5 | * | |
6 | * Copyright (C) 2015 Red Hat, Inc. | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | #ifndef RADOS_RGW_FILE_H | |
15 | #define RADOS_RGW_FILE_H | |
16 | ||
17 | #include <sys/stat.h> | |
18 | #include <sys/types.h> | |
19 | #include <stdint.h> | |
20 | #include <stdbool.h> | |
21 | ||
22 | #include "librgw.h" | |
23 | ||
24 | #ifdef __cplusplus | |
25 | extern "C" { | |
26 | #endif | |
27 | ||
28 | #define LIBRGW_FILE_VER_MAJOR 1 | |
29 | #define LIBRGW_FILE_VER_MINOR 1 | |
c07f9fc5 | 30 | #define LIBRGW_FILE_VER_EXTRA 4 |
7c673cae FG |
31 | |
32 | #define LIBRGW_FILE_VERSION(maj, min, extra) ((maj << 16) + (min << 8) + extra) | |
33 | #define LIBRGW_FILE_VERSION_CODE LIBRGW_FILE_VERSION(LIBRGW_FILE_VER_MAJOR, LIBRGW_FILE_VER_MINOR, LIBRGW_FILE_VER_EXTRA) | |
34 | ||
35 | /* | |
36 | * object types | |
37 | */ | |
38 | enum rgw_fh_type { | |
39 | RGW_FS_TYPE_NIL = 0, | |
40 | RGW_FS_TYPE_FILE, | |
41 | RGW_FS_TYPE_DIRECTORY, | |
42 | }; | |
43 | ||
44 | /* | |
45 | * dynamic allocated handle to support nfs handle | |
46 | */ | |
47 | ||
48 | /* content-addressable hash */ | |
49 | struct rgw_fh_hk { | |
50 | uint64_t bucket; | |
51 | uint64_t object; | |
52 | }; | |
53 | ||
54 | struct rgw_file_handle | |
55 | { | |
56 | /* content-addressable hash */ | |
57 | struct rgw_fh_hk fh_hk; | |
58 | void *fh_private; /* librgw private data */ | |
59 | /* object type */ | |
60 | enum rgw_fh_type fh_type; | |
61 | }; | |
62 | ||
63 | struct rgw_fs | |
64 | { | |
65 | librgw_t rgw; | |
66 | void *fs_private; | |
67 | struct rgw_file_handle* root_fh; | |
68 | }; | |
69 | ||
70 | ||
71 | /* XXX mount info hypothetical--emulate Unix, support at least | |
72 | * UUID-length fsid */ | |
73 | struct rgw_statvfs { | |
74 | uint64_t f_bsize; /* file system block size */ | |
75 | uint64_t f_frsize; /* fragment size */ | |
76 | uint64_t f_blocks; /* size of fs in f_frsize units */ | |
77 | uint64_t f_bfree; /* # free blocks */ | |
78 | uint64_t f_bavail; /* # free blocks for unprivileged users */ | |
79 | uint64_t f_files; /* # inodes */ | |
80 | uint64_t f_ffree; /* # free inodes */ | |
81 | uint64_t f_favail; /* # free inodes for unprivileged users */ | |
82 | uint64_t f_fsid[2]; /* file system ID */ | |
83 | uint64_t f_flag; /* mount flags */ | |
84 | uint64_t f_namemax; /* maximum filename length */ | |
85 | }; | |
86 | ||
87 | ||
88 | void rgwfile_version(int *major, int *minor, int *extra); | |
89 | ||
90 | /* | |
91 | lookup object by name (POSIX style) | |
92 | */ | |
93 | #define RGW_LOOKUP_FLAG_NONE 0x0000 | |
94 | #define RGW_LOOKUP_FLAG_CREATE 0x0001 | |
95 | #define RGW_LOOKUP_FLAG_RCB 0x0002 /* readdir callback hint */ | |
96 | #define RGW_LOOKUP_FLAG_DIR 0x0004 | |
97 | #define RGW_LOOKUP_FLAG_FILE 0x0008 | |
98 | ||
99 | #define RGW_LOOKUP_TYPE_FLAGS \ | |
100 | (RGW_LOOKUP_FLAG_DIR|RGW_LOOKUP_FLAG_FILE) | |
101 | ||
102 | int rgw_lookup(struct rgw_fs *rgw_fs, | |
103 | struct rgw_file_handle *parent_fh, const char *path, | |
104 | struct rgw_file_handle **fh, uint32_t flags); | |
105 | ||
106 | /* | |
107 | lookup object by handle (NFS style) | |
108 | */ | |
109 | int rgw_lookup_handle(struct rgw_fs *rgw_fs, struct rgw_fh_hk *fh_hk, | |
110 | struct rgw_file_handle **fh, uint32_t flags); | |
111 | ||
112 | /* | |
113 | * release file handle | |
114 | */ | |
115 | #define RGW_FH_RELE_FLAG_NONE 0x0000 | |
116 | ||
117 | int rgw_fh_rele(struct rgw_fs *rgw_fs, struct rgw_file_handle *fh, | |
118 | uint32_t flags); | |
119 | ||
120 | /* | |
121 | attach rgw namespace | |
122 | */ | |
123 | #define RGW_MOUNT_FLAG_NONE 0x0000 | |
124 | ||
125 | int rgw_mount(librgw_t rgw, const char *uid, const char *key, | |
126 | const char *secret, struct rgw_fs **rgw_fs, | |
127 | uint32_t flags); | |
128 | ||
129 | /* | |
130 | register invalidate callbacks | |
131 | */ | |
132 | #define RGW_REG_INVALIDATE_FLAG_NONE 0x0000 | |
133 | ||
134 | typedef void (*rgw_fh_callback_t)(void *handle, struct rgw_fh_hk fh_hk); | |
135 | ||
136 | int rgw_register_invalidate(struct rgw_fs *rgw_fs, rgw_fh_callback_t cb, | |
137 | void *arg, uint32_t flags); | |
138 | ||
139 | /* | |
140 | detach rgw namespace | |
141 | */ | |
142 | #define RGW_UMOUNT_FLAG_NONE 0x0000 | |
143 | ||
144 | int rgw_umount(struct rgw_fs *rgw_fs, uint32_t flags); | |
145 | ||
146 | ||
147 | /* | |
148 | get filesystem attributes | |
149 | */ | |
150 | #define RGW_STATFS_FLAG_NONE 0x0000 | |
151 | ||
152 | int rgw_statfs(struct rgw_fs *rgw_fs, | |
153 | struct rgw_file_handle *parent_fh, | |
154 | struct rgw_statvfs *vfs_st, | |
155 | uint32_t flags); | |
156 | ||
157 | ||
158 | /* XXX (get|set)attr mask bits */ | |
159 | #define RGW_SETATTR_MODE 1 | |
160 | #define RGW_SETATTR_UID 2 | |
161 | #define RGW_SETATTR_GID 4 | |
162 | #define RGW_SETATTR_MTIME 8 | |
163 | #define RGW_SETATTR_ATIME 16 | |
164 | #define RGW_SETATTR_SIZE 32 | |
165 | #define RGW_SETATTR_CTIME 64 | |
166 | ||
167 | /* | |
168 | create file | |
169 | */ | |
170 | #define RGW_CREATE_FLAG_NONE 0x0000 | |
171 | ||
172 | int rgw_create(struct rgw_fs *rgw_fs, struct rgw_file_handle *parent_fh, | |
173 | const char *name, struct stat *st, uint32_t mask, | |
174 | struct rgw_file_handle **fh, uint32_t posix_flags, | |
175 | uint32_t flags); | |
176 | ||
177 | /* | |
178 | create a new directory | |
179 | */ | |
180 | #define RGW_MKDIR_FLAG_NONE 0x0000 | |
181 | ||
182 | int rgw_mkdir(struct rgw_fs *rgw_fs, | |
183 | struct rgw_file_handle *parent_fh, | |
184 | const char *name, struct stat *st, uint32_t mask, | |
185 | struct rgw_file_handle **fh, uint32_t flags); | |
186 | ||
187 | /* | |
188 | rename object | |
189 | */ | |
190 | #define RGW_RENAME_FLAG_NONE 0x0000 | |
191 | ||
192 | int rgw_rename(struct rgw_fs *rgw_fs, | |
193 | struct rgw_file_handle *olddir, const char* old_name, | |
194 | struct rgw_file_handle *newdir, const char* new_name, | |
195 | uint32_t flags); | |
196 | ||
197 | /* | |
198 | remove file or directory | |
199 | */ | |
200 | #define RGW_UNLINK_FLAG_NONE 0x0000 | |
201 | ||
202 | int rgw_unlink(struct rgw_fs *rgw_fs, | |
203 | struct rgw_file_handle *parent_fh, const char* path, | |
204 | uint32_t flags); | |
205 | ||
206 | /* | |
207 | read directory content | |
208 | */ | |
209 | typedef bool (*rgw_readdir_cb)(const char *name, void *arg, uint64_t offset, | |
210 | uint32_t flags); | |
211 | ||
212 | #define RGW_READDIR_FLAG_NONE 0x0000 | |
213 | #define RGW_READDIR_FLAG_DOTDOT 0x0001 /* send dot names */ | |
214 | ||
215 | int rgw_readdir(struct rgw_fs *rgw_fs, | |
216 | struct rgw_file_handle *parent_fh, uint64_t *offset, | |
217 | rgw_readdir_cb rcb, void *cb_arg, bool *eof, | |
218 | uint32_t flags); | |
219 | ||
c07f9fc5 FG |
220 | /* project offset of dirent name */ |
221 | #define RGW_DIRENT_OFFSET_FLAG_NONE 0x0000 | |
222 | ||
223 | int rgw_dirent_offset(struct rgw_fs *rgw_fs, | |
224 | struct rgw_file_handle *parent_fh, | |
225 | const char *name, int64_t *offset, | |
226 | uint32_t flags); | |
227 | ||
7c673cae FG |
228 | /* |
229 | get unix attributes for object | |
230 | */ | |
231 | #define RGW_GETATTR_FLAG_NONE 0x0000 | |
232 | ||
233 | int rgw_getattr(struct rgw_fs *rgw_fs, | |
234 | struct rgw_file_handle *fh, struct stat *st, | |
235 | uint32_t flags); | |
236 | ||
237 | /* | |
238 | set unix attributes for object | |
239 | */ | |
240 | #define RGW_SETATTR_FLAG_NONE 0x0000 | |
241 | ||
242 | int rgw_setattr(struct rgw_fs *rgw_fs, | |
243 | struct rgw_file_handle *fh, struct stat *st, | |
244 | uint32_t mask, uint32_t flags); | |
245 | ||
246 | /* | |
247 | truncate file | |
248 | */ | |
249 | #define RGW_TRUNCATE_FLAG_NONE 0x0000 | |
250 | ||
251 | int rgw_truncate(struct rgw_fs *rgw_fs, | |
252 | struct rgw_file_handle *fh, uint64_t size, | |
253 | uint32_t flags); | |
254 | ||
255 | /* | |
256 | open file | |
257 | */ | |
258 | #define RGW_OPEN_FLAG_NONE 0x0000 | |
259 | #define RGW_OPEN_FLAG_CREATE 0x0001 | |
260 | #define RGW_OPEN_FLAG_V3 0x0002 /* ops have v3 semantics */ | |
261 | #define RGW_OPEN_FLAG_STATELESS 0x0002 /* alias it */ | |
262 | ||
263 | int rgw_open(struct rgw_fs *rgw_fs, struct rgw_file_handle *parent_fh, | |
264 | uint32_t posix_flags, uint32_t flags); | |
265 | ||
266 | /* | |
267 | close file | |
268 | */ | |
269 | ||
270 | #define RGW_CLOSE_FLAG_NONE 0x0000 | |
271 | #define RGW_CLOSE_FLAG_RELE 0x0001 | |
272 | ||
273 | int rgw_close(struct rgw_fs *rgw_fs, struct rgw_file_handle *fh, | |
274 | uint32_t flags); | |
275 | ||
276 | /* | |
277 | read data from file | |
278 | */ | |
279 | #define RGW_READ_FLAG_NONE 0x0000 | |
280 | ||
281 | int rgw_read(struct rgw_fs *rgw_fs, | |
282 | struct rgw_file_handle *fh, uint64_t offset, | |
283 | size_t length, size_t *bytes_read, void *buffer, | |
284 | uint32_t flags); | |
285 | ||
286 | /* | |
287 | write data to file | |
288 | */ | |
289 | #define RGW_WRITE_FLAG_NONE 0x0000 | |
290 | ||
291 | int rgw_write(struct rgw_fs *rgw_fs, | |
292 | struct rgw_file_handle *fh, uint64_t offset, | |
293 | size_t length, size_t *bytes_written, void *buffer, | |
294 | uint32_t flags); | |
295 | ||
296 | #define RGW_UIO_NONE 0x0000 | |
297 | #define RGW_UIO_GIFT 0x0001 | |
298 | #define RGW_UIO_FREE 0x0002 | |
299 | #define RGW_UIO_BUFQ 0x0004 | |
300 | ||
301 | struct rgw_uio; | |
302 | typedef void (*rgw_uio_release)(struct rgw_uio *, uint32_t); | |
303 | ||
304 | /* buffer vector descriptors */ | |
305 | struct rgw_vio { | |
306 | void *vio_p1; | |
307 | void *vio_u1; | |
308 | void *vio_base; | |
309 | int32_t vio_len; | |
310 | }; | |
311 | ||
312 | struct rgw_uio { | |
313 | rgw_uio_release uio_rele; | |
314 | void *uio_p1; | |
315 | void *uio_u1; | |
316 | uint64_t uio_offset; | |
317 | uint64_t uio_resid; | |
318 | uint32_t uio_cnt; | |
319 | uint32_t uio_flags; | |
320 | struct rgw_vio *uio_vio; /* appended vectors */ | |
321 | }; | |
322 | ||
323 | typedef struct rgw_uio rgw_uio; | |
324 | ||
325 | int rgw_readv(struct rgw_fs *rgw_fs, | |
326 | struct rgw_file_handle *fh, rgw_uio *uio, uint32_t flags); | |
327 | ||
328 | int rgw_writev(struct rgw_fs *rgw_fs, | |
329 | struct rgw_file_handle *fh, rgw_uio *uio, uint32_t flags); | |
330 | ||
331 | /* | |
332 | sync written data | |
333 | */ | |
334 | #define RGW_FSYNC_FLAG_NONE 0x0000 | |
335 | ||
336 | int rgw_fsync(struct rgw_fs *rgw_fs, struct rgw_file_handle *fh, | |
337 | uint32_t flags); | |
338 | ||
339 | /* | |
340 | NFS commit operation | |
341 | */ | |
342 | ||
343 | #define RGW_COMMIT_FLAG_NONE 0x0000 | |
344 | ||
345 | int rgw_commit(struct rgw_fs *rgw_fs, struct rgw_file_handle *fh, | |
346 | uint64_t offset, uint64_t length, uint32_t flags); | |
347 | ||
348 | #ifdef __cplusplus | |
349 | } | |
350 | #endif | |
351 | ||
352 | #endif /* RADOS_RGW_FILE_H */ |