]>
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 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2009-2011 New Dream Network | |
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 | ||
15 | #include <fcntl.h> | |
16 | #include <iostream> | |
17 | #include <string.h> | |
18 | #include <string> | |
19 | ||
20 | #include "auth/Crypto.h" | |
21 | #include "client/Client.h" | |
22 | #include "librados/RadosClient.h" | |
23 | #include "common/Mutex.h" | |
24 | #include "common/ceph_argparse.h" | |
25 | #include "common/common_init.h" | |
26 | #include "common/config.h" | |
27 | #include "common/version.h" | |
28 | #include "mon/MonClient.h" | |
29 | #include "include/str_list.h" | |
30 | #include "messages/MMonMap.h" | |
31 | #include "msg/Messenger.h" | |
11fdf7f2 | 32 | #include "include/ceph_assert.h" |
b32b8144 | 33 | #include "mds/MDSMap.h" |
7c673cae FG |
34 | |
35 | #include "include/cephfs/libcephfs.h" | |
36 | ||
11fdf7f2 TL |
37 | #define DEFAULT_UMASK 002 |
38 | ||
39 | static mode_t umask_cb(void *); | |
7c673cae FG |
40 | |
41 | struct ceph_mount_info | |
42 | { | |
11fdf7f2 | 43 | mode_t umask = DEFAULT_UMASK; |
7c673cae FG |
44 | public: |
45 | explicit ceph_mount_info(CephContext *cct_) | |
46 | : default_perms(), | |
47 | mounted(false), | |
48 | inited(false), | |
11fdf7f2 TL |
49 | client(nullptr), |
50 | monclient(nullptr), | |
51 | messenger(nullptr), | |
7c673cae FG |
52 | cct(cct_) |
53 | { | |
11fdf7f2 | 54 | if (cct_) { |
7c673cae FG |
55 | cct->get(); |
56 | } | |
57 | } | |
58 | ||
59 | ~ceph_mount_info() | |
60 | { | |
61 | try { | |
62 | shutdown(); | |
63 | if (cct) { | |
64 | cct->put(); | |
11fdf7f2 | 65 | cct = nullptr; |
7c673cae FG |
66 | } |
67 | } | |
68 | catch (const std::exception& e) { | |
69 | // we shouldn't get here, but if we do, we want to know about it. | |
70 | lderr(cct) << "ceph_mount_info::~ceph_mount_info: caught exception: " | |
71 | << e.what() << dendl; | |
72 | } | |
73 | catch (...) { | |
74 | // ignore | |
75 | } | |
76 | } | |
77 | ||
78 | int init() | |
79 | { | |
7c673cae FG |
80 | int ret; |
81 | ||
11fdf7f2 TL |
82 | if (cct->_conf->log_early && |
83 | !cct->_log->is_started()) { | |
84 | cct->_log->start(); | |
85 | } | |
86 | ||
87 | { | |
88 | MonClient mc_bootstrap(cct); | |
89 | ret = mc_bootstrap.get_monmap_and_config(); | |
90 | if (ret < 0) | |
91 | return ret; | |
92 | } | |
93 | ||
94 | common_init_finish(cct); | |
95 | ||
7c673cae FG |
96 | //monmap |
97 | monclient = new MonClient(cct); | |
98 | ret = -CEPHFS_ERROR_MON_MAP_BUILD; //defined in libcephfs.h; | |
99 | if (monclient->build_initial_monmap() < 0) | |
100 | goto fail; | |
101 | ||
102 | //network connection | |
103 | messenger = Messenger::create_client_messenger(cct, "client"); | |
104 | ||
105 | //at last the client | |
106 | ret = -CEPHFS_ERROR_NEW_CLIENT; //defined in libcephfs.h; | |
107 | client = new StandaloneClient(messenger, monclient); | |
108 | if (!client) | |
109 | goto fail; | |
110 | ||
111 | ret = -CEPHFS_ERROR_MESSENGER_START; //defined in libcephfs.h; | |
112 | if (messenger->start() != 0) | |
113 | goto fail; | |
114 | ||
115 | ret = client->init(); | |
116 | if (ret) | |
117 | goto fail; | |
118 | ||
11fdf7f2 TL |
119 | { |
120 | client_callback_args args = {}; | |
121 | args.handle = this; | |
122 | args.umask_cb = umask_cb; | |
123 | client->ll_register_callbacks(&args); | |
124 | } | |
125 | ||
7c673cae FG |
126 | default_perms = Client::pick_my_perms(cct); |
127 | inited = true; | |
128 | return 0; | |
129 | ||
130 | fail: | |
131 | shutdown(); | |
132 | return ret; | |
133 | } | |
134 | ||
11fdf7f2 TL |
135 | int select_filesystem(const std::string &fs_name_) |
136 | { | |
137 | if (mounted) { | |
138 | return -EISCONN; | |
139 | } | |
140 | ||
141 | fs_name = fs_name_; | |
142 | return 0; | |
143 | } | |
144 | ||
145 | const std::string& get_filesystem(void) | |
146 | { | |
147 | return fs_name; | |
148 | } | |
149 | ||
7c673cae FG |
150 | int mount(const std::string &mount_root, const UserPerm& perms) |
151 | { | |
152 | int ret; | |
153 | ||
154 | if (mounted) | |
155 | return -EISCONN; | |
156 | ||
157 | if (!inited) { | |
158 | ret = init(); | |
159 | if (ret != 0) { | |
160 | return ret; | |
161 | } | |
162 | } | |
163 | ||
11fdf7f2 | 164 | ret = client->mount(mount_root, perms, false, fs_name); |
7c673cae FG |
165 | if (ret) { |
166 | shutdown(); | |
167 | return ret; | |
168 | } else { | |
169 | mounted = true; | |
170 | return 0; | |
171 | } | |
172 | } | |
173 | ||
174 | int unmount() | |
175 | { | |
176 | if (!mounted) | |
177 | return -ENOTCONN; | |
178 | shutdown(); | |
179 | return 0; | |
180 | } | |
11fdf7f2 TL |
181 | int abort_conn() |
182 | { | |
183 | if (mounted) { | |
184 | client->abort_conn(); | |
185 | mounted = false; | |
186 | } | |
187 | return 0; | |
188 | } | |
7c673cae FG |
189 | |
190 | void shutdown() | |
191 | { | |
192 | if (mounted) { | |
193 | client->unmount(); | |
194 | mounted = false; | |
195 | } | |
196 | if (inited) { | |
197 | client->shutdown(); | |
198 | inited = false; | |
199 | } | |
200 | if (messenger) { | |
201 | messenger->shutdown(); | |
202 | messenger->wait(); | |
203 | delete messenger; | |
11fdf7f2 | 204 | messenger = nullptr; |
7c673cae FG |
205 | } |
206 | if (monclient) { | |
207 | delete monclient; | |
11fdf7f2 | 208 | monclient = nullptr; |
7c673cae FG |
209 | } |
210 | if (client) { | |
211 | delete client; | |
11fdf7f2 | 212 | client = nullptr; |
7c673cae FG |
213 | } |
214 | } | |
215 | ||
216 | bool is_initialized() const | |
217 | { | |
218 | return inited; | |
219 | } | |
220 | ||
221 | bool is_mounted() | |
222 | { | |
223 | return mounted; | |
224 | } | |
225 | ||
11fdf7f2 TL |
226 | mode_t set_umask(mode_t umask) |
227 | { | |
228 | this->umask = umask; | |
229 | return umask; | |
230 | } | |
231 | ||
7c673cae FG |
232 | int conf_read_file(const char *path_list) |
233 | { | |
11fdf7f2 | 234 | int ret = cct->_conf.parse_config_files(path_list, nullptr, 0); |
7c673cae FG |
235 | if (ret) |
236 | return ret; | |
11fdf7f2 TL |
237 | cct->_conf.apply_changes(nullptr); |
238 | cct->_conf.complain_about_parse_errors(cct); | |
7c673cae FG |
239 | return 0; |
240 | } | |
241 | ||
242 | int conf_parse_argv(int argc, const char **argv) | |
243 | { | |
244 | int ret; | |
245 | vector<const char*> args; | |
246 | argv_to_vec(argc, argv, args); | |
11fdf7f2 | 247 | ret = cct->_conf.parse_argv(args); |
7c673cae FG |
248 | if (ret) |
249 | return ret; | |
11fdf7f2 | 250 | cct->_conf.apply_changes(nullptr); |
7c673cae FG |
251 | return 0; |
252 | } | |
253 | ||
254 | int conf_parse_env(const char *name) | |
255 | { | |
11fdf7f2 TL |
256 | auto& conf = cct->_conf; |
257 | conf.parse_env(cct->get_module_type(), name); | |
258 | conf.apply_changes(nullptr); | |
7c673cae FG |
259 | return 0; |
260 | } | |
261 | ||
262 | int conf_set(const char *option, const char *value) | |
263 | { | |
11fdf7f2 | 264 | int ret = cct->_conf.set_val(option, value); |
7c673cae FG |
265 | if (ret) |
266 | return ret; | |
11fdf7f2 | 267 | cct->_conf.apply_changes(nullptr); |
7c673cae FG |
268 | return 0; |
269 | } | |
270 | ||
271 | int conf_get(const char *option, char *buf, size_t len) | |
272 | { | |
273 | char *tmp = buf; | |
11fdf7f2 | 274 | return cct->_conf.get_val(option, &tmp, len); |
7c673cae FG |
275 | } |
276 | ||
277 | Client *get_client() | |
278 | { | |
279 | return client; | |
280 | } | |
281 | ||
282 | const char *get_cwd(const UserPerm& perms) | |
283 | { | |
284 | client->getcwd(cwd, perms); | |
285 | return cwd.c_str(); | |
286 | } | |
287 | ||
288 | int chdir(const char *to, const UserPerm& perms) | |
289 | { | |
290 | return client->chdir(to, cwd, perms); | |
291 | } | |
292 | ||
293 | CephContext *get_ceph_context() const { | |
294 | return cct; | |
295 | } | |
296 | ||
297 | UserPerm default_perms; | |
298 | private: | |
299 | bool mounted; | |
300 | bool inited; | |
301 | StandaloneClient *client; | |
302 | MonClient *monclient; | |
303 | Messenger *messenger; | |
304 | CephContext *cct; | |
305 | std::string cwd; | |
11fdf7f2 | 306 | std::string fs_name; |
7c673cae FG |
307 | }; |
308 | ||
11fdf7f2 TL |
309 | static mode_t umask_cb(void *handle) |
310 | { | |
311 | return ((struct ceph_mount_info *)handle)->umask; | |
312 | } | |
313 | ||
7c673cae FG |
314 | static void do_out_buffer(bufferlist& outbl, char **outbuf, size_t *outbuflen) |
315 | { | |
316 | if (outbuf) { | |
317 | if (outbl.length() > 0) { | |
318 | *outbuf = (char *)malloc(outbl.length()); | |
319 | memcpy(*outbuf, outbl.c_str(), outbl.length()); | |
320 | } else { | |
11fdf7f2 | 321 | *outbuf = nullptr; |
7c673cae FG |
322 | } |
323 | } | |
324 | if (outbuflen) | |
325 | *outbuflen = outbl.length(); | |
326 | } | |
327 | ||
328 | static void do_out_buffer(string& outbl, char **outbuf, size_t *outbuflen) | |
329 | { | |
330 | if (outbuf) { | |
331 | if (outbl.length() > 0) { | |
332 | *outbuf = (char *)malloc(outbl.length()); | |
333 | memcpy(*outbuf, outbl.c_str(), outbl.length()); | |
334 | } else { | |
11fdf7f2 | 335 | *outbuf = nullptr; |
7c673cae FG |
336 | } |
337 | } | |
338 | if (outbuflen) | |
339 | *outbuflen = outbl.length(); | |
340 | } | |
341 | ||
342 | extern "C" UserPerm *ceph_userperm_new(uid_t uid, gid_t gid, int ngids, | |
343 | gid_t *gidlist) | |
344 | { | |
345 | return new (std::nothrow) UserPerm(uid, gid, ngids, gidlist); | |
346 | } | |
347 | ||
348 | extern "C" void ceph_userperm_destroy(UserPerm *perm) | |
349 | { | |
350 | delete perm; | |
351 | } | |
352 | ||
353 | extern "C" const char *ceph_version(int *pmajor, int *pminor, int *ppatch) | |
354 | { | |
355 | int major, minor, patch; | |
356 | const char *v = ceph_version_to_str(); | |
357 | ||
358 | int n = sscanf(v, "%d.%d.%d", &major, &minor, &patch); | |
359 | if (pmajor) | |
360 | *pmajor = (n >= 1) ? major : 0; | |
361 | if (pminor) | |
362 | *pminor = (n >= 2) ? minor : 0; | |
363 | if (ppatch) | |
364 | *ppatch = (n >= 3) ? patch : 0; | |
365 | return VERSION; | |
366 | } | |
367 | ||
368 | extern "C" int ceph_create_with_context(struct ceph_mount_info **cmount, CephContext *cct) | |
369 | { | |
370 | *cmount = new struct ceph_mount_info(cct); | |
371 | return 0; | |
372 | } | |
373 | ||
374 | extern "C" int ceph_create_from_rados(struct ceph_mount_info **cmount, | |
375 | rados_t cluster) | |
376 | { | |
377 | auto rados = (librados::RadosClient *) cluster; | |
378 | auto cct = rados->cct; | |
379 | return ceph_create_with_context(cmount, cct); | |
380 | } | |
381 | ||
382 | extern "C" int ceph_create(struct ceph_mount_info **cmount, const char * const id) | |
383 | { | |
384 | CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT); | |
385 | if (id) { | |
386 | iparams.name.set(CEPH_ENTITY_TYPE_CLIENT, id); | |
387 | } | |
388 | ||
389 | CephContext *cct = common_preinit(iparams, CODE_ENVIRONMENT_LIBRARY, 0); | |
11fdf7f2 TL |
390 | cct->_conf.parse_env(cct->get_module_type()); // environment variables coverride |
391 | cct->_conf.apply_changes(nullptr); | |
7c673cae FG |
392 | int ret = ceph_create_with_context(cmount, cct); |
393 | cct->put(); | |
11fdf7f2 | 394 | cct = nullptr; |
7c673cae FG |
395 | return ret; |
396 | } | |
397 | ||
398 | extern "C" int ceph_unmount(struct ceph_mount_info *cmount) | |
399 | { | |
400 | return cmount->unmount(); | |
401 | } | |
402 | ||
11fdf7f2 TL |
403 | extern "C" int ceph_abort_conn(struct ceph_mount_info *cmount) |
404 | { | |
405 | return cmount->abort_conn(); | |
406 | } | |
407 | ||
7c673cae FG |
408 | extern "C" int ceph_release(struct ceph_mount_info *cmount) |
409 | { | |
410 | if (cmount->is_mounted()) | |
411 | return -EISCONN; | |
412 | delete cmount; | |
11fdf7f2 | 413 | cmount = nullptr; |
7c673cae FG |
414 | return 0; |
415 | } | |
416 | ||
417 | extern "C" void ceph_shutdown(struct ceph_mount_info *cmount) | |
418 | { | |
419 | cmount->shutdown(); | |
420 | delete cmount; | |
11fdf7f2 TL |
421 | cmount = nullptr; |
422 | } | |
423 | ||
424 | extern "C" uint64_t ceph_get_instance_id(struct ceph_mount_info *cmount) | |
425 | { | |
426 | if (cmount->is_initialized()) | |
427 | return cmount->get_client()->get_nodeid().v; | |
428 | return 0; | |
7c673cae FG |
429 | } |
430 | ||
431 | extern "C" int ceph_conf_read_file(struct ceph_mount_info *cmount, const char *path) | |
432 | { | |
433 | return cmount->conf_read_file(path); | |
434 | } | |
435 | ||
11fdf7f2 TL |
436 | extern "C" mode_t ceph_umask(struct ceph_mount_info *cmount, mode_t mode) |
437 | { | |
438 | return cmount->set_umask(mode); | |
439 | } | |
440 | ||
7c673cae FG |
441 | extern "C" int ceph_conf_parse_argv(struct ceph_mount_info *cmount, int argc, |
442 | const char **argv) | |
443 | { | |
444 | return cmount->conf_parse_argv(argc, argv); | |
445 | } | |
446 | ||
447 | extern "C" int ceph_conf_parse_env(struct ceph_mount_info *cmount, const char *name) | |
448 | { | |
449 | return cmount->conf_parse_env(name); | |
450 | } | |
451 | ||
452 | extern "C" int ceph_conf_set(struct ceph_mount_info *cmount, const char *option, | |
453 | const char *value) | |
454 | { | |
455 | return cmount->conf_set(option, value); | |
456 | } | |
457 | ||
458 | extern "C" int ceph_conf_get(struct ceph_mount_info *cmount, const char *option, | |
459 | char *buf, size_t len) | |
460 | { | |
11fdf7f2 | 461 | if (!buf) { |
7c673cae FG |
462 | return -EINVAL; |
463 | } | |
464 | return cmount->conf_get(option, buf, len); | |
465 | } | |
466 | ||
467 | extern "C" int ceph_mds_command(struct ceph_mount_info *cmount, | |
468 | const char *mds_spec, | |
469 | const char **cmd, | |
470 | size_t cmdlen, | |
471 | const char *inbuf, size_t inbuflen, | |
472 | char **outbuf, size_t *outbuflen, | |
473 | char **outsbuf, size_t *outsbuflen) | |
474 | { | |
475 | bufferlist inbl; | |
476 | bufferlist outbl; | |
477 | std::vector<string> cmdv; | |
478 | std::string outs; | |
479 | ||
480 | if (!cmount->is_initialized()) { | |
481 | return -ENOTCONN; | |
482 | } | |
483 | ||
484 | // Construct inputs | |
485 | for (size_t i = 0; i < cmdlen; ++i) { | |
486 | cmdv.push_back(cmd[i]); | |
487 | } | |
488 | inbl.append(inbuf, inbuflen); | |
489 | ||
490 | // Issue remote command | |
491 | C_SaferCond cond; | |
492 | int r = cmount->get_client()->mds_command( | |
493 | mds_spec, | |
494 | cmdv, inbl, | |
495 | &outbl, &outs, | |
496 | &cond); | |
497 | ||
498 | if (r != 0) { | |
499 | goto out; | |
500 | } | |
501 | ||
502 | // Wait for completion | |
503 | r = cond.wait(); | |
504 | ||
505 | // Construct outputs | |
506 | do_out_buffer(outbl, outbuf, outbuflen); | |
507 | do_out_buffer(outs, outsbuf, outsbuflen); | |
508 | ||
509 | out: | |
510 | return r; | |
511 | } | |
512 | ||
513 | extern "C" int ceph_init(struct ceph_mount_info *cmount) | |
514 | { | |
515 | return cmount->init(); | |
516 | } | |
517 | ||
11fdf7f2 TL |
518 | extern "C" int ceph_select_filesystem(struct ceph_mount_info *cmount, |
519 | const char *fs_name) | |
520 | { | |
521 | if (fs_name == nullptr) { | |
522 | return -EINVAL; | |
523 | } | |
524 | ||
525 | return cmount->select_filesystem(fs_name); | |
526 | } | |
527 | ||
7c673cae FG |
528 | extern "C" int ceph_mount(struct ceph_mount_info *cmount, const char *root) |
529 | { | |
530 | std::string mount_root; | |
531 | if (root) | |
532 | mount_root = root; | |
533 | return cmount->mount(mount_root, cmount->default_perms); | |
534 | } | |
535 | ||
536 | extern "C" int ceph_is_mounted(struct ceph_mount_info *cmount) | |
537 | { | |
538 | return cmount->is_mounted() ? 1 : 0; | |
539 | } | |
540 | ||
541 | extern "C" struct UserPerm *ceph_mount_perms(struct ceph_mount_info *cmount) | |
542 | { | |
543 | return &cmount->default_perms; | |
544 | } | |
545 | ||
11fdf7f2 TL |
546 | extern "C" int64_t ceph_get_fs_cid(struct ceph_mount_info *cmount) |
547 | { | |
548 | if (!cmount->is_mounted()) | |
549 | return -ENOTCONN; | |
550 | return cmount->get_client()->get_fs_cid(); | |
551 | } | |
552 | ||
553 | extern "C" int ceph_mount_perms_set(struct ceph_mount_info *cmount, | |
554 | struct UserPerm *perms) | |
555 | { | |
556 | if (cmount->is_mounted()) | |
557 | return -EISCONN; | |
558 | cmount->default_perms = *perms; | |
559 | return 0; | |
560 | } | |
561 | ||
7c673cae FG |
562 | extern "C" int ceph_statfs(struct ceph_mount_info *cmount, const char *path, |
563 | struct statvfs *stbuf) | |
564 | { | |
565 | if (!cmount->is_mounted()) | |
566 | return -ENOTCONN; | |
567 | return cmount->get_client()->statfs(path, stbuf, cmount->default_perms); | |
568 | } | |
569 | ||
570 | extern "C" int ceph_get_local_osd(struct ceph_mount_info *cmount) | |
571 | { | |
572 | if (!cmount->is_mounted()) | |
573 | return -ENOTCONN; | |
574 | return cmount->get_client()->get_local_osd(); | |
575 | } | |
576 | ||
577 | extern "C" const char* ceph_getcwd(struct ceph_mount_info *cmount) | |
578 | { | |
579 | return cmount->get_cwd(cmount->default_perms); | |
580 | } | |
581 | ||
582 | extern "C" int ceph_chdir (struct ceph_mount_info *cmount, const char *s) | |
583 | { | |
584 | if (!cmount->is_mounted()) | |
585 | return -ENOTCONN; | |
586 | return cmount->chdir(s, cmount->default_perms); | |
587 | } | |
588 | ||
589 | extern "C" int ceph_opendir(struct ceph_mount_info *cmount, | |
590 | const char *name, struct ceph_dir_result **dirpp) | |
591 | { | |
592 | if (!cmount->is_mounted()) | |
593 | return -ENOTCONN; | |
594 | return cmount->get_client()->opendir(name, (dir_result_t **)dirpp, cmount->default_perms); | |
595 | } | |
596 | ||
597 | extern "C" int ceph_closedir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp) | |
598 | { | |
599 | if (!cmount->is_mounted()) | |
600 | return -ENOTCONN; | |
601 | return cmount->get_client()->closedir(reinterpret_cast<dir_result_t*>(dirp)); | |
602 | } | |
603 | ||
604 | extern "C" struct dirent * ceph_readdir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp) | |
605 | { | |
606 | if (!cmount->is_mounted()) { | |
607 | /* Client::readdir also sets errno to signal errors. */ | |
608 | errno = ENOTCONN; | |
11fdf7f2 | 609 | return nullptr; |
7c673cae FG |
610 | } |
611 | return cmount->get_client()->readdir(reinterpret_cast<dir_result_t*>(dirp)); | |
612 | } | |
613 | ||
614 | extern "C" int ceph_readdir_r(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, struct dirent *de) | |
615 | { | |
616 | if (!cmount->is_mounted()) | |
617 | return -ENOTCONN; | |
618 | return cmount->get_client()->readdir_r(reinterpret_cast<dir_result_t*>(dirp), de); | |
619 | } | |
620 | ||
621 | extern "C" int ceph_readdirplus_r(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, | |
622 | struct dirent *de, struct ceph_statx *stx, unsigned want, | |
623 | unsigned flags, struct Inode **out) | |
624 | { | |
625 | if (!cmount->is_mounted()) | |
626 | return -ENOTCONN; | |
627 | if (flags & ~CEPH_REQ_FLAG_MASK) | |
628 | return -EINVAL; | |
629 | return cmount->get_client()->readdirplus_r(reinterpret_cast<dir_result_t*>(dirp), de, stx, want, flags, out); | |
630 | } | |
631 | ||
632 | extern "C" int ceph_getdents(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, | |
633 | char *buf, int buflen) | |
634 | { | |
635 | if (!cmount->is_mounted()) | |
636 | return -ENOTCONN; | |
637 | return cmount->get_client()->getdents(reinterpret_cast<dir_result_t*>(dirp), buf, buflen); | |
638 | } | |
639 | ||
640 | extern "C" int ceph_getdnames(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, | |
641 | char *buf, int buflen) | |
642 | { | |
643 | if (!cmount->is_mounted()) | |
644 | return -ENOTCONN; | |
645 | return cmount->get_client()->getdnames(reinterpret_cast<dir_result_t*>(dirp), buf, buflen); | |
646 | } | |
647 | ||
648 | extern "C" void ceph_rewinddir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp) | |
649 | { | |
650 | if (!cmount->is_mounted()) | |
651 | return; | |
652 | cmount->get_client()->rewinddir(reinterpret_cast<dir_result_t*>(dirp)); | |
653 | } | |
654 | ||
655 | extern "C" int64_t ceph_telldir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp) | |
656 | { | |
657 | if (!cmount->is_mounted()) | |
658 | return -ENOTCONN; | |
659 | return cmount->get_client()->telldir(reinterpret_cast<dir_result_t*>(dirp)); | |
660 | } | |
661 | ||
662 | extern "C" void ceph_seekdir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, int64_t offset) | |
663 | { | |
664 | if (!cmount->is_mounted()) | |
665 | return; | |
666 | cmount->get_client()->seekdir(reinterpret_cast<dir_result_t*>(dirp), offset); | |
667 | } | |
668 | ||
669 | extern "C" int ceph_link (struct ceph_mount_info *cmount, const char *existing, | |
670 | const char *newname) | |
671 | { | |
672 | if (!cmount->is_mounted()) | |
673 | return -ENOTCONN; | |
674 | return cmount->get_client()->link(existing, newname, cmount->default_perms); | |
675 | } | |
676 | ||
677 | extern "C" int ceph_unlink(struct ceph_mount_info *cmount, const char *path) | |
678 | { | |
679 | if (!cmount->is_mounted()) | |
680 | return -ENOTCONN; | |
681 | return cmount->get_client()->unlink(path, cmount->default_perms); | |
682 | } | |
683 | ||
684 | extern "C" int ceph_rename(struct ceph_mount_info *cmount, const char *from, | |
685 | const char *to) | |
686 | { | |
687 | if (!cmount->is_mounted()) | |
688 | return -ENOTCONN; | |
689 | return cmount->get_client()->rename(from, to, cmount->default_perms); | |
690 | } | |
691 | ||
692 | // dirs | |
693 | extern "C" int ceph_mkdir(struct ceph_mount_info *cmount, const char *path, mode_t mode) | |
694 | { | |
695 | if (!cmount->is_mounted()) | |
696 | return -ENOTCONN; | |
697 | return cmount->get_client()->mkdir(path, mode, cmount->default_perms); | |
698 | } | |
699 | ||
700 | extern "C" int ceph_mkdirs(struct ceph_mount_info *cmount, const char *path, mode_t mode) | |
701 | { | |
702 | if (!cmount->is_mounted()) | |
703 | return -ENOTCONN; | |
704 | return cmount->get_client()->mkdirs(path, mode, cmount->default_perms); | |
705 | } | |
706 | ||
707 | extern "C" int ceph_rmdir(struct ceph_mount_info *cmount, const char *path) | |
708 | { | |
709 | if (!cmount->is_mounted()) | |
710 | return -ENOTCONN; | |
711 | return cmount->get_client()->rmdir(path, cmount->default_perms); | |
712 | } | |
713 | ||
714 | // symlinks | |
715 | extern "C" int ceph_readlink(struct ceph_mount_info *cmount, const char *path, | |
716 | char *buf, int64_t size) | |
717 | { | |
718 | if (!cmount->is_mounted()) | |
719 | return -ENOTCONN; | |
720 | return cmount->get_client()->readlink(path, buf, size, cmount->default_perms); | |
721 | } | |
722 | ||
723 | extern "C" int ceph_symlink(struct ceph_mount_info *cmount, const char *existing, | |
724 | const char *newname) | |
725 | { | |
726 | if (!cmount->is_mounted()) | |
727 | return -ENOTCONN; | |
728 | return cmount->get_client()->symlink(existing, newname, cmount->default_perms); | |
729 | } | |
730 | ||
731 | extern "C" int ceph_fstatx(struct ceph_mount_info *cmount, int fd, struct ceph_statx *stx, | |
732 | unsigned int want, unsigned int flags) | |
733 | { | |
734 | if (!cmount->is_mounted()) | |
735 | return -ENOTCONN; | |
736 | if (flags & ~CEPH_REQ_FLAG_MASK) | |
737 | return -EINVAL; | |
738 | return cmount->get_client()->fstatx(fd, stx, cmount->default_perms, | |
739 | want, flags); | |
740 | } | |
741 | ||
742 | extern "C" int ceph_statx(struct ceph_mount_info *cmount, const char *path, | |
743 | struct ceph_statx *stx, unsigned int want, unsigned int flags) | |
744 | { | |
745 | if (!cmount->is_mounted()) | |
746 | return -ENOTCONN; | |
747 | if (flags & ~CEPH_REQ_FLAG_MASK) | |
748 | return -EINVAL; | |
749 | return cmount->get_client()->statx(path, stx, cmount->default_perms, | |
750 | want, flags); | |
751 | } | |
752 | ||
753 | extern "C" int ceph_fsetattrx(struct ceph_mount_info *cmount, int fd, | |
754 | struct ceph_statx *stx, int mask) | |
755 | { | |
756 | if (!cmount->is_mounted()) | |
757 | return -ENOTCONN; | |
758 | return cmount->get_client()->fsetattrx(fd, stx, mask, cmount->default_perms); | |
759 | } | |
760 | ||
761 | extern "C" int ceph_setattrx(struct ceph_mount_info *cmount, const char *relpath, | |
762 | struct ceph_statx *stx, int mask, int flags) | |
763 | { | |
764 | if (!cmount->is_mounted()) | |
765 | return -ENOTCONN; | |
766 | if (flags & ~CEPH_REQ_FLAG_MASK) | |
767 | return -EINVAL; | |
768 | return cmount->get_client()->setattrx(relpath, stx, mask, | |
769 | cmount->default_perms, flags); | |
770 | } | |
771 | ||
772 | // *xattr() calls supporting samba/vfs | |
773 | extern "C" int ceph_getxattr(struct ceph_mount_info *cmount, const char *path, const char *name, void *value, size_t size) | |
774 | { | |
775 | if (!cmount->is_mounted()) | |
776 | return -ENOTCONN; | |
777 | ||
778 | return cmount->get_client()->getxattr(path, name, value, size, cmount->default_perms); | |
779 | } | |
780 | ||
781 | extern "C" int ceph_lgetxattr(struct ceph_mount_info *cmount, const char *path, const char *name, void *value, size_t size) | |
782 | { | |
783 | if (!cmount->is_mounted()) | |
784 | return -ENOTCONN; | |
785 | return cmount->get_client()->lgetxattr(path, name, value, size, cmount->default_perms); | |
786 | } | |
787 | ||
788 | extern "C" int ceph_fgetxattr(struct ceph_mount_info *cmount, int fd, const char *name, void *value, size_t size) | |
789 | { | |
790 | if (!cmount->is_mounted()) | |
791 | return -ENOTCONN; | |
792 | return cmount->get_client()->fgetxattr(fd, name, value, size, cmount->default_perms); | |
793 | } | |
794 | ||
795 | ||
796 | extern "C" int ceph_listxattr(struct ceph_mount_info *cmount, const char *path, char *list, size_t size) | |
797 | { | |
798 | if (!cmount->is_mounted()) | |
799 | return -ENOTCONN; | |
800 | return cmount->get_client()->listxattr(path, list, size, cmount->default_perms); | |
801 | } | |
802 | ||
803 | extern "C" int ceph_llistxattr(struct ceph_mount_info *cmount, const char *path, char *list, size_t size) | |
804 | { | |
805 | if (!cmount->is_mounted()) | |
806 | return -ENOTCONN; | |
807 | return cmount->get_client()->llistxattr(path, list, size, cmount->default_perms); | |
808 | } | |
809 | ||
810 | extern "C" int ceph_flistxattr(struct ceph_mount_info *cmount, int fd, char *list, size_t size) | |
811 | { | |
812 | if (!cmount->is_mounted()) | |
813 | return -ENOTCONN; | |
814 | return cmount->get_client()->flistxattr(fd, list, size, cmount->default_perms); | |
815 | } | |
816 | ||
817 | extern "C" int ceph_removexattr(struct ceph_mount_info *cmount, const char *path, const char *name) | |
818 | { | |
819 | if (!cmount->is_mounted()) | |
820 | return -ENOTCONN; | |
821 | return cmount->get_client()->removexattr(path, name, cmount->default_perms); | |
822 | } | |
823 | ||
824 | extern "C" int ceph_lremovexattr(struct ceph_mount_info *cmount, const char *path, const char *name) | |
825 | { | |
826 | if (!cmount->is_mounted()) | |
827 | return -ENOTCONN; | |
828 | return cmount->get_client()->lremovexattr(path, name, cmount->default_perms); | |
829 | } | |
830 | ||
831 | extern "C" int ceph_fremovexattr(struct ceph_mount_info *cmount, int fd, const char *name) | |
832 | { | |
833 | if (!cmount->is_mounted()) | |
834 | return -ENOTCONN; | |
835 | return cmount->get_client()->fremovexattr(fd, name, cmount->default_perms); | |
836 | } | |
837 | ||
838 | extern "C" int ceph_setxattr(struct ceph_mount_info *cmount, const char *path, const char *name, const void *value, size_t size, int flags) | |
839 | { | |
840 | if (!cmount->is_mounted()) | |
841 | return -ENOTCONN; | |
842 | return cmount->get_client()->setxattr(path, name, value, size, flags, cmount->default_perms); | |
843 | } | |
844 | ||
845 | extern "C" int ceph_lsetxattr(struct ceph_mount_info *cmount, const char *path, const char *name, const void *value, size_t size, int flags) | |
846 | { | |
847 | if (!cmount->is_mounted()) | |
848 | return -ENOTCONN; | |
849 | return cmount->get_client()->lsetxattr(path, name, value, size, flags, cmount->default_perms); | |
850 | } | |
851 | ||
852 | extern "C" int ceph_fsetxattr(struct ceph_mount_info *cmount, int fd, const char *name, const void *value, size_t size, int flags) | |
853 | { | |
854 | if (!cmount->is_mounted()) | |
855 | return -ENOTCONN; | |
856 | return cmount->get_client()->fsetxattr(fd, name, value, size, flags, cmount->default_perms); | |
857 | } | |
858 | /* end xattr support */ | |
859 | ||
11fdf7f2 TL |
860 | extern "C" int ceph_stat(struct ceph_mount_info *cmount, const char *path, struct stat *stbuf) |
861 | { | |
862 | if (!cmount->is_mounted()) | |
863 | return -ENOTCONN; | |
864 | return cmount->get_client()->stat(path, stbuf, cmount->default_perms); | |
865 | } | |
866 | ||
867 | extern "C" int ceph_fstat(struct ceph_mount_info *cmount, int fd, struct stat *stbuf) | |
868 | { | |
869 | if (!cmount->is_mounted()) | |
870 | return -ENOTCONN; | |
871 | return cmount->get_client()->fstat(fd, stbuf, cmount->default_perms); | |
872 | } | |
873 | ||
874 | extern int ceph_lstat(struct ceph_mount_info *cmount, const char *path, struct stat *stbuf) | |
875 | { | |
876 | if (!cmount->is_mounted()) | |
877 | return -ENOTCONN; | |
878 | return cmount->get_client()->lstat(path, stbuf, cmount->default_perms); | |
879 | } | |
880 | ||
7c673cae FG |
881 | extern "C" int ceph_chmod(struct ceph_mount_info *cmount, const char *path, mode_t mode) |
882 | { | |
883 | if (!cmount->is_mounted()) | |
884 | return -ENOTCONN; | |
885 | return cmount->get_client()->chmod(path, mode, cmount->default_perms); | |
886 | } | |
887 | extern "C" int ceph_fchmod(struct ceph_mount_info *cmount, int fd, mode_t mode) | |
888 | { | |
889 | if (!cmount->is_mounted()) | |
890 | return -ENOTCONN; | |
891 | return cmount->get_client()->fchmod(fd, mode, cmount->default_perms); | |
892 | } | |
893 | extern "C" int ceph_chown(struct ceph_mount_info *cmount, const char *path, | |
894 | int uid, int gid) | |
895 | { | |
896 | if (!cmount->is_mounted()) | |
897 | return -ENOTCONN; | |
898 | return cmount->get_client()->chown(path, uid, gid, cmount->default_perms); | |
899 | } | |
900 | extern "C" int ceph_fchown(struct ceph_mount_info *cmount, int fd, | |
901 | int uid, int gid) | |
902 | { | |
903 | if (!cmount->is_mounted()) | |
904 | return -ENOTCONN; | |
905 | return cmount->get_client()->fchown(fd, uid, gid, cmount->default_perms); | |
906 | } | |
907 | extern "C" int ceph_lchown(struct ceph_mount_info *cmount, const char *path, | |
908 | int uid, int gid) | |
909 | { | |
910 | if (!cmount->is_mounted()) | |
911 | return -ENOTCONN; | |
912 | return cmount->get_client()->lchown(path, uid, gid, cmount->default_perms); | |
913 | } | |
914 | ||
915 | ||
916 | extern "C" int ceph_utime(struct ceph_mount_info *cmount, const char *path, | |
917 | struct utimbuf *buf) | |
918 | { | |
919 | if (!cmount->is_mounted()) | |
920 | return -ENOTCONN; | |
921 | return cmount->get_client()->utime(path, buf, cmount->default_perms); | |
922 | } | |
923 | ||
11fdf7f2 TL |
924 | extern "C" int ceph_futime(struct ceph_mount_info *cmount, int fd, |
925 | struct utimbuf *buf) | |
926 | { | |
927 | if (!cmount->is_mounted()) | |
928 | return -ENOTCONN; | |
929 | return cmount->get_client()->futime(fd, buf, cmount->default_perms); | |
930 | } | |
931 | ||
932 | extern "C" int ceph_utimes(struct ceph_mount_info *cmount, const char *path, | |
933 | struct timeval times[2]) | |
934 | { | |
935 | if (!cmount->is_mounted()) | |
936 | return -ENOTCONN; | |
937 | return cmount->get_client()->utimes(path, times, cmount->default_perms); | |
938 | } | |
939 | ||
940 | extern "C" int ceph_lutimes(struct ceph_mount_info *cmount, const char *path, | |
941 | struct timeval times[2]) | |
942 | { | |
943 | if (!cmount->is_mounted()) | |
944 | return -ENOTCONN; | |
945 | return cmount->get_client()->lutimes(path, times, cmount->default_perms); | |
946 | } | |
947 | ||
948 | extern "C" int ceph_futimes(struct ceph_mount_info *cmount, int fd, | |
949 | struct timeval times[2]) | |
950 | { | |
951 | if (!cmount->is_mounted()) | |
952 | return -ENOTCONN; | |
953 | return cmount->get_client()->futimes(fd, times, cmount->default_perms); | |
954 | } | |
955 | ||
956 | extern "C" int ceph_futimens(struct ceph_mount_info *cmount, int fd, | |
957 | struct timespec times[2]) | |
958 | { | |
959 | if (!cmount->is_mounted()) | |
960 | return -ENOTCONN; | |
961 | return cmount->get_client()->futimens(fd, times, cmount->default_perms); | |
962 | } | |
963 | ||
7c673cae FG |
964 | extern "C" int ceph_flock(struct ceph_mount_info *cmount, int fd, int operation, |
965 | uint64_t owner) | |
966 | { | |
967 | if (!cmount->is_mounted()) | |
968 | return -ENOTCONN; | |
969 | return cmount->get_client()->flock(fd, operation, owner); | |
970 | } | |
971 | ||
972 | extern "C" int ceph_truncate(struct ceph_mount_info *cmount, const char *path, | |
973 | int64_t size) | |
974 | { | |
975 | if (!cmount->is_mounted()) | |
976 | return -ENOTCONN; | |
977 | return cmount->get_client()->truncate(path, size, cmount->default_perms); | |
978 | } | |
979 | ||
980 | // file ops | |
981 | extern "C" int ceph_mknod(struct ceph_mount_info *cmount, const char *path, | |
982 | mode_t mode, dev_t rdev) | |
983 | { | |
984 | if (!cmount->is_mounted()) | |
985 | return -ENOTCONN; | |
986 | return cmount->get_client()->mknod(path, mode, cmount->default_perms, rdev); | |
987 | } | |
988 | ||
989 | extern "C" int ceph_open(struct ceph_mount_info *cmount, const char *path, | |
990 | int flags, mode_t mode) | |
991 | { | |
992 | if (!cmount->is_mounted()) | |
993 | return -ENOTCONN; | |
994 | return cmount->get_client()->open(path, flags, cmount->default_perms, mode); | |
995 | } | |
996 | ||
997 | extern "C" int ceph_open_layout(struct ceph_mount_info *cmount, const char *path, int flags, | |
998 | mode_t mode, int stripe_unit, int stripe_count, int object_size, const char *data_pool) | |
999 | { | |
1000 | if (!cmount->is_mounted()) | |
1001 | return -ENOTCONN; | |
1002 | return cmount->get_client()->open(path, flags, cmount->default_perms, mode, | |
1003 | stripe_unit, stripe_count, | |
1004 | object_size, data_pool); | |
1005 | } | |
1006 | ||
1007 | extern "C" int ceph_close(struct ceph_mount_info *cmount, int fd) | |
1008 | { | |
1009 | if (!cmount->is_mounted()) | |
1010 | return -ENOTCONN; | |
1011 | return cmount->get_client()->close(fd); | |
1012 | } | |
1013 | ||
1014 | extern "C" int64_t ceph_lseek(struct ceph_mount_info *cmount, int fd, | |
1015 | int64_t offset, int whence) | |
1016 | { | |
1017 | if (!cmount->is_mounted()) | |
1018 | return -ENOTCONN; | |
1019 | return cmount->get_client()->lseek(fd, offset, whence); | |
1020 | } | |
1021 | ||
1022 | extern "C" int ceph_read(struct ceph_mount_info *cmount, int fd, char *buf, | |
1023 | int64_t size, int64_t offset) | |
1024 | { | |
1025 | if (!cmount->is_mounted()) | |
1026 | return -ENOTCONN; | |
1027 | return cmount->get_client()->read(fd, buf, size, offset); | |
1028 | } | |
1029 | ||
1030 | extern "C" int ceph_preadv(struct ceph_mount_info *cmount, int fd, | |
1031 | const struct iovec *iov, int iovcnt, int64_t offset) | |
1032 | { | |
1033 | if (!cmount->is_mounted()) | |
1034 | return -ENOTCONN; | |
1035 | return cmount->get_client()->preadv(fd, iov, iovcnt, offset); | |
1036 | } | |
1037 | ||
1038 | extern "C" int ceph_write(struct ceph_mount_info *cmount, int fd, const char *buf, | |
1039 | int64_t size, int64_t offset) | |
1040 | { | |
1041 | if (!cmount->is_mounted()) | |
1042 | return -ENOTCONN; | |
1043 | return cmount->get_client()->write(fd, buf, size, offset); | |
1044 | } | |
1045 | ||
1046 | extern "C" int ceph_pwritev(struct ceph_mount_info *cmount, int fd, | |
1047 | const struct iovec *iov, int iovcnt, int64_t offset) | |
1048 | { | |
1049 | if (!cmount->is_mounted()) | |
1050 | return -ENOTCONN; | |
1051 | return cmount->get_client()->pwritev(fd, iov, iovcnt, offset); | |
1052 | } | |
1053 | ||
1054 | extern "C" int ceph_ftruncate(struct ceph_mount_info *cmount, int fd, int64_t size) | |
1055 | { | |
1056 | if (!cmount->is_mounted()) | |
1057 | return -ENOTCONN; | |
1058 | return cmount->get_client()->ftruncate(fd, size, cmount->default_perms); | |
1059 | } | |
1060 | ||
1061 | extern "C" int ceph_fsync(struct ceph_mount_info *cmount, int fd, int syncdataonly) | |
1062 | { | |
1063 | if (!cmount->is_mounted()) | |
1064 | return -ENOTCONN; | |
1065 | return cmount->get_client()->fsync(fd, syncdataonly); | |
1066 | } | |
1067 | ||
1068 | extern "C" int ceph_fallocate(struct ceph_mount_info *cmount, int fd, int mode, | |
1069 | int64_t offset, int64_t length) | |
1070 | { | |
1071 | if (!cmount->is_mounted()) | |
1072 | return -ENOTCONN; | |
1073 | return cmount->get_client()->fallocate(fd, mode, offset, length); | |
1074 | } | |
1075 | ||
11fdf7f2 TL |
1076 | extern "C" int ceph_lazyio(class ceph_mount_info *cmount, |
1077 | int fd, int enable) | |
1078 | { | |
1079 | return (cmount->get_client()->lazyio(fd, enable)); | |
1080 | } | |
1081 | ||
7c673cae FG |
1082 | extern "C" int ceph_sync_fs(struct ceph_mount_info *cmount) |
1083 | { | |
1084 | if (!cmount->is_mounted()) | |
1085 | return -ENOTCONN; | |
1086 | return cmount->get_client()->sync_fs(); | |
1087 | } | |
1088 | ||
7c673cae FG |
1089 | extern "C" int ceph_get_file_stripe_unit(struct ceph_mount_info *cmount, int fh) |
1090 | { | |
1091 | file_layout_t l; | |
1092 | int r; | |
1093 | ||
1094 | if (!cmount->is_mounted()) | |
1095 | return -ENOTCONN; | |
1096 | r = cmount->get_client()->fdescribe_layout(fh, &l); | |
1097 | if (r < 0) | |
1098 | return r; | |
1099 | return l.stripe_unit; | |
1100 | } | |
1101 | ||
1102 | extern "C" int ceph_get_path_stripe_unit(struct ceph_mount_info *cmount, const char *path) | |
1103 | { | |
1104 | file_layout_t l; | |
1105 | int r; | |
1106 | ||
1107 | if (!cmount->is_mounted()) | |
1108 | return -ENOTCONN; | |
1109 | r = cmount->get_client()->describe_layout(path, &l, cmount->default_perms); | |
1110 | if (r < 0) | |
1111 | return r; | |
1112 | return l.stripe_unit; | |
1113 | } | |
1114 | ||
1115 | extern "C" int ceph_get_file_stripe_count(struct ceph_mount_info *cmount, int fh) | |
1116 | { | |
1117 | file_layout_t l; | |
1118 | int r; | |
1119 | ||
1120 | if (!cmount->is_mounted()) | |
1121 | return -ENOTCONN; | |
1122 | r = cmount->get_client()->fdescribe_layout(fh, &l); | |
1123 | if (r < 0) | |
1124 | return r; | |
1125 | return l.stripe_count; | |
1126 | } | |
1127 | ||
1128 | extern "C" int ceph_get_path_stripe_count(struct ceph_mount_info *cmount, const char *path) | |
1129 | { | |
1130 | file_layout_t l; | |
1131 | int r; | |
1132 | ||
1133 | if (!cmount->is_mounted()) | |
1134 | return -ENOTCONN; | |
1135 | r = cmount->get_client()->describe_layout(path, &l, cmount->default_perms); | |
1136 | if (r < 0) | |
1137 | return r; | |
1138 | return l.stripe_count; | |
1139 | } | |
1140 | ||
1141 | extern "C" int ceph_get_file_object_size(struct ceph_mount_info *cmount, int fh) | |
1142 | { | |
1143 | file_layout_t l; | |
1144 | int r; | |
1145 | ||
1146 | if (!cmount->is_mounted()) | |
1147 | return -ENOTCONN; | |
1148 | r = cmount->get_client()->fdescribe_layout(fh, &l); | |
1149 | if (r < 0) | |
1150 | return r; | |
1151 | return l.object_size; | |
1152 | } | |
1153 | ||
1154 | extern "C" int ceph_get_path_object_size(struct ceph_mount_info *cmount, const char *path) | |
1155 | { | |
1156 | file_layout_t l; | |
1157 | int r; | |
1158 | ||
1159 | if (!cmount->is_mounted()) | |
1160 | return -ENOTCONN; | |
1161 | r = cmount->get_client()->describe_layout(path, &l, cmount->default_perms); | |
1162 | if (r < 0) | |
1163 | return r; | |
1164 | return l.object_size; | |
1165 | } | |
1166 | ||
1167 | extern "C" int ceph_get_file_pool(struct ceph_mount_info *cmount, int fh) | |
1168 | { | |
1169 | file_layout_t l; | |
1170 | int r; | |
1171 | ||
1172 | if (!cmount->is_mounted()) | |
1173 | return -ENOTCONN; | |
1174 | r = cmount->get_client()->fdescribe_layout(fh, &l); | |
1175 | if (r < 0) | |
1176 | return r; | |
1177 | return l.pool_id; | |
1178 | } | |
1179 | ||
1180 | extern "C" int ceph_get_path_pool(struct ceph_mount_info *cmount, const char *path) | |
1181 | { | |
1182 | file_layout_t l; | |
1183 | int r; | |
1184 | ||
1185 | if (!cmount->is_mounted()) | |
1186 | return -ENOTCONN; | |
1187 | r = cmount->get_client()->describe_layout(path, &l, cmount->default_perms); | |
1188 | if (r < 0) | |
1189 | return r; | |
1190 | return l.pool_id; | |
1191 | } | |
1192 | ||
1193 | extern "C" int ceph_get_file_pool_name(struct ceph_mount_info *cmount, int fh, char *buf, size_t len) | |
1194 | { | |
1195 | file_layout_t l; | |
1196 | int r; | |
1197 | ||
1198 | if (!cmount->is_mounted()) | |
1199 | return -ENOTCONN; | |
1200 | r = cmount->get_client()->fdescribe_layout(fh, &l); | |
1201 | if (r < 0) | |
1202 | return r; | |
1203 | string name = cmount->get_client()->get_pool_name(l.pool_id); | |
1204 | if (len == 0) | |
1205 | return name.length(); | |
1206 | if (name.length() > len) | |
1207 | return -ERANGE; | |
1208 | strncpy(buf, name.c_str(), len); | |
1209 | return name.length(); | |
1210 | } | |
1211 | ||
1212 | extern "C" int ceph_get_pool_name(struct ceph_mount_info *cmount, int pool, char *buf, size_t len) | |
1213 | { | |
1214 | if (!cmount->is_mounted()) | |
1215 | return -ENOTCONN; | |
1216 | string name = cmount->get_client()->get_pool_name(pool); | |
1217 | if (len == 0) | |
1218 | return name.length(); | |
1219 | if (name.length() > len) | |
1220 | return -ERANGE; | |
1221 | strncpy(buf, name.c_str(), len); | |
1222 | return name.length(); | |
1223 | } | |
1224 | ||
1225 | extern "C" int ceph_get_path_pool_name(struct ceph_mount_info *cmount, const char *path, char *buf, size_t len) | |
1226 | { | |
1227 | file_layout_t l; | |
1228 | int r; | |
1229 | ||
1230 | if (!cmount->is_mounted()) | |
1231 | return -ENOTCONN; | |
1232 | r = cmount->get_client()->describe_layout(path, &l, cmount->default_perms); | |
1233 | if (r < 0) | |
1234 | return r; | |
1235 | string name = cmount->get_client()->get_pool_name(l.pool_id); | |
1236 | if (len == 0) | |
1237 | return name.length(); | |
1238 | if (name.length() > len) | |
1239 | return -ERANGE; | |
1240 | strncpy(buf, name.c_str(), len); | |
1241 | return name.length(); | |
1242 | } | |
1243 | ||
d2e6a577 FG |
1244 | extern "C" int ceph_get_default_data_pool_name(struct ceph_mount_info *cmount, char *buf, size_t len) |
1245 | { | |
1246 | if (!cmount->is_mounted()) | |
1247 | return -ENOTCONN; | |
1248 | int64_t pool_id = cmount->get_client()->get_default_pool_id(); | |
1249 | ||
1250 | string name = cmount->get_client()->get_pool_name(pool_id); | |
1251 | if (len == 0) | |
1252 | return name.length(); | |
1253 | if (name.length() > len) | |
1254 | return -ERANGE; | |
1255 | strncpy(buf, name.c_str(), len); | |
1256 | return name.length(); | |
1257 | } | |
1258 | ||
7c673cae FG |
1259 | extern "C" int ceph_get_file_layout(struct ceph_mount_info *cmount, int fh, int *stripe_unit, int *stripe_count, int *object_size, int *pg_pool) |
1260 | { | |
1261 | file_layout_t l; | |
1262 | int r; | |
1263 | ||
1264 | if (!cmount->is_mounted()) | |
1265 | return -ENOTCONN; | |
1266 | r = cmount->get_client()->fdescribe_layout(fh, &l); | |
1267 | if (r < 0) | |
1268 | return r; | |
1269 | if (stripe_unit) | |
1270 | *stripe_unit = l.stripe_unit; | |
1271 | if (stripe_count) | |
1272 | *stripe_count = l.stripe_count; | |
1273 | if (object_size) | |
1274 | *object_size = l.object_size; | |
1275 | if (pg_pool) | |
1276 | *pg_pool = l.pool_id; | |
1277 | return 0; | |
1278 | } | |
1279 | ||
1280 | extern "C" int ceph_get_path_layout(struct ceph_mount_info *cmount, const char *path, int *stripe_unit, int *stripe_count, int *object_size, int *pg_pool) | |
1281 | { | |
1282 | file_layout_t l; | |
1283 | int r; | |
1284 | ||
1285 | if (!cmount->is_mounted()) | |
1286 | return -ENOTCONN; | |
1287 | r = cmount->get_client()->describe_layout(path, &l, cmount->default_perms); | |
1288 | if (r < 0) | |
1289 | return r; | |
1290 | if (stripe_unit) | |
1291 | *stripe_unit = l.stripe_unit; | |
1292 | if (stripe_count) | |
1293 | *stripe_count = l.stripe_count; | |
1294 | if (object_size) | |
1295 | *object_size = l.object_size; | |
1296 | if (pg_pool) | |
1297 | *pg_pool = l.pool_id; | |
1298 | return 0; | |
1299 | } | |
1300 | ||
1301 | extern "C" int ceph_get_file_replication(struct ceph_mount_info *cmount, int fh) | |
1302 | { | |
1303 | file_layout_t l; | |
1304 | int r; | |
1305 | ||
1306 | if (!cmount->is_mounted()) | |
1307 | return -ENOTCONN; | |
1308 | r = cmount->get_client()->fdescribe_layout(fh, &l); | |
1309 | if (r < 0) | |
1310 | return r; | |
1311 | int rep = cmount->get_client()->get_pool_replication(l.pool_id); | |
1312 | return rep; | |
1313 | } | |
1314 | ||
1315 | extern "C" int ceph_get_path_replication(struct ceph_mount_info *cmount, const char *path) | |
1316 | { | |
1317 | file_layout_t l; | |
1318 | int r; | |
1319 | ||
1320 | if (!cmount->is_mounted()) | |
1321 | return -ENOTCONN; | |
1322 | r = cmount->get_client()->describe_layout(path, &l, cmount->default_perms); | |
1323 | if (r < 0) | |
1324 | return r; | |
1325 | int rep = cmount->get_client()->get_pool_replication(l.pool_id); | |
1326 | return rep; | |
1327 | } | |
1328 | ||
1329 | extern "C" int ceph_set_default_file_stripe_unit(struct ceph_mount_info *cmount, | |
1330 | int stripe) | |
1331 | { | |
1332 | // this option no longer exists | |
1333 | return -EOPNOTSUPP; | |
1334 | } | |
1335 | ||
1336 | extern "C" int ceph_set_default_file_stripe_count(struct ceph_mount_info *cmount, | |
1337 | int count) | |
1338 | { | |
1339 | // this option no longer exists | |
1340 | return -EOPNOTSUPP; | |
1341 | } | |
1342 | ||
1343 | extern "C" int ceph_set_default_object_size(struct ceph_mount_info *cmount, int size) | |
1344 | { | |
1345 | // this option no longer exists | |
1346 | return -EOPNOTSUPP; | |
1347 | } | |
1348 | ||
1349 | extern "C" int ceph_set_default_file_replication(struct ceph_mount_info *cmount, | |
1350 | int replication) | |
1351 | { | |
1352 | // this option no longer exists | |
1353 | return -EOPNOTSUPP; | |
1354 | } | |
1355 | ||
1356 | extern "C" int ceph_set_default_preferred_pg(struct ceph_mount_info *cmount, int osd) | |
1357 | { | |
1358 | // this option no longer exists | |
1359 | return -EOPNOTSUPP; | |
1360 | } | |
1361 | ||
1362 | extern "C" int ceph_get_file_extent_osds(struct ceph_mount_info *cmount, int fh, | |
1363 | int64_t offset, int64_t *length, int *osds, int nosds) | |
1364 | { | |
1365 | if (nosds < 0) | |
1366 | return -EINVAL; | |
1367 | ||
1368 | if (!cmount->is_mounted()) | |
1369 | return -ENOTCONN; | |
1370 | ||
1371 | vector<int> vosds; | |
1372 | int ret = cmount->get_client()->get_file_extent_osds(fh, offset, length, vosds); | |
1373 | if (ret < 0) | |
1374 | return ret; | |
1375 | ||
1376 | if (!nosds) | |
1377 | return vosds.size(); | |
1378 | ||
1379 | if ((int)vosds.size() > nosds) | |
1380 | return -ERANGE; | |
1381 | ||
1382 | for (int i = 0; i < (int)vosds.size(); i++) | |
1383 | osds[i] = vosds[i]; | |
1384 | ||
1385 | return vosds.size(); | |
1386 | } | |
1387 | ||
1388 | extern "C" int ceph_get_osd_crush_location(struct ceph_mount_info *cmount, | |
1389 | int osd, char *path, size_t len) | |
1390 | { | |
1391 | if (!cmount->is_mounted()) | |
1392 | return -ENOTCONN; | |
1393 | ||
1394 | if (!path && len) | |
1395 | return -EINVAL; | |
1396 | ||
1397 | vector<pair<string, string> > loc; | |
1398 | int ret = cmount->get_client()->get_osd_crush_location(osd, loc); | |
1399 | if (ret) | |
1400 | return ret; | |
1401 | ||
1402 | size_t needed = 0; | |
1403 | size_t cur = 0; | |
1404 | vector<pair<string, string> >::iterator it; | |
1405 | for (it = loc.begin(); it != loc.end(); ++it) { | |
1406 | string& type = it->first; | |
1407 | string& name = it->second; | |
1408 | needed += type.size() + name.size() + 2; | |
1409 | if (needed <= len) { | |
1410 | if (path) | |
1411 | strcpy(path + cur, type.c_str()); | |
1412 | cur += type.size() + 1; | |
1413 | if (path) | |
1414 | strcpy(path + cur, name.c_str()); | |
1415 | cur += name.size() + 1; | |
1416 | } | |
1417 | } | |
1418 | ||
1419 | if (len == 0) | |
1420 | return needed; | |
1421 | ||
1422 | if (needed > len) | |
1423 | return -ERANGE; | |
1424 | ||
1425 | return needed; | |
1426 | } | |
1427 | ||
1428 | extern "C" int ceph_get_osd_addr(struct ceph_mount_info *cmount, int osd, | |
1429 | struct sockaddr_storage *addr) | |
1430 | { | |
1431 | if (!cmount->is_mounted()) | |
1432 | return -ENOTCONN; | |
1433 | ||
1434 | if (!addr) | |
1435 | return -EINVAL; | |
1436 | ||
1437 | entity_addr_t address; | |
1438 | int ret = cmount->get_client()->get_osd_addr(osd, address); | |
1439 | if (ret < 0) | |
1440 | return ret; | |
1441 | ||
1442 | *addr = address.get_sockaddr_storage(); | |
1443 | ||
1444 | return 0; | |
1445 | } | |
1446 | ||
1447 | extern "C" int ceph_get_file_stripe_address(struct ceph_mount_info *cmount, int fh, | |
1448 | int64_t offset, struct sockaddr_storage *addr, int naddr) | |
1449 | { | |
1450 | vector<entity_addr_t> address; | |
1451 | unsigned i; | |
1452 | int r; | |
1453 | ||
1454 | if (naddr < 0) | |
1455 | return -EINVAL; | |
1456 | ||
1457 | if (!cmount->is_mounted()) | |
1458 | return -ENOTCONN; | |
1459 | ||
1460 | r = cmount->get_client()->get_file_stripe_address(fh, offset, address); | |
1461 | if (r < 0) | |
1462 | return r; | |
1463 | ||
1464 | for (i = 0; i < (unsigned)naddr && i < address.size(); i++) | |
1465 | addr[i] = address[i].get_sockaddr_storage(); | |
1466 | ||
1467 | /* naddr == 0: drop through and return actual size */ | |
1468 | if (naddr && (address.size() > (unsigned)naddr)) | |
1469 | return -ERANGE; | |
1470 | ||
1471 | return address.size(); | |
1472 | } | |
1473 | ||
1474 | extern "C" int ceph_localize_reads(struct ceph_mount_info *cmount, int val) | |
1475 | { | |
1476 | if (!cmount->is_mounted()) | |
1477 | return -ENOTCONN; | |
1478 | if (!val) | |
1479 | cmount->get_client()->clear_filer_flags(CEPH_OSD_FLAG_LOCALIZE_READS); | |
1480 | else | |
1481 | cmount->get_client()->set_filer_flags(CEPH_OSD_FLAG_LOCALIZE_READS); | |
1482 | return 0; | |
1483 | } | |
1484 | ||
1485 | extern "C" CephContext *ceph_get_mount_context(struct ceph_mount_info *cmount) | |
1486 | { | |
1487 | return cmount->get_ceph_context(); | |
1488 | } | |
1489 | ||
1490 | extern "C" int ceph_debug_get_fd_caps(struct ceph_mount_info *cmount, int fd) | |
1491 | { | |
1492 | if (!cmount->is_mounted()) | |
1493 | return -ENOTCONN; | |
1494 | return cmount->get_client()->get_caps_issued(fd); | |
1495 | } | |
1496 | ||
1497 | extern "C" int ceph_debug_get_file_caps(struct ceph_mount_info *cmount, const char *path) | |
1498 | { | |
1499 | if (!cmount->is_mounted()) | |
1500 | return -ENOTCONN; | |
1501 | return cmount->get_client()->get_caps_issued(path, cmount->default_perms); | |
1502 | } | |
1503 | ||
1504 | extern "C" int ceph_get_stripe_unit_granularity(struct ceph_mount_info *cmount) | |
1505 | { | |
1506 | if (!cmount->is_mounted()) | |
1507 | return -ENOTCONN; | |
1508 | return CEPH_MIN_STRIPE_UNIT; | |
1509 | } | |
1510 | ||
1511 | extern "C" int ceph_get_pool_id(struct ceph_mount_info *cmount, const char *pool_name) | |
1512 | { | |
1513 | if (!cmount->is_mounted()) | |
1514 | return -ENOTCONN; | |
1515 | ||
1516 | if (!pool_name || !pool_name[0]) | |
1517 | return -EINVAL; | |
1518 | ||
1519 | /* negative range reserved for errors */ | |
1520 | int64_t pool_id = cmount->get_client()->get_pool_id(pool_name); | |
1521 | if (pool_id > 0x7fffffff) | |
1522 | return -ERANGE; | |
1523 | ||
1524 | /* get_pool_id error codes fit in int */ | |
1525 | return (int)pool_id; | |
1526 | } | |
1527 | ||
1528 | extern "C" int ceph_get_pool_replication(struct ceph_mount_info *cmount, | |
1529 | int pool_id) | |
1530 | { | |
1531 | if (!cmount->is_mounted()) | |
1532 | return -ENOTCONN; | |
1533 | return cmount->get_client()->get_pool_replication(pool_id); | |
1534 | } | |
1535 | /* Low-level exports */ | |
1536 | ||
1537 | extern "C" int ceph_ll_lookup_root(struct ceph_mount_info *cmount, | |
1538 | Inode **parent) | |
1539 | { | |
1540 | *parent = cmount->get_client()->get_root(); | |
1541 | if (*parent) | |
1542 | return 0; | |
1543 | return -EFAULT; | |
1544 | } | |
1545 | ||
1546 | extern "C" struct Inode *ceph_ll_get_inode(class ceph_mount_info *cmount, | |
1547 | vinodeno_t vino) | |
1548 | { | |
1549 | return (cmount->get_client())->ll_get_inode(vino); | |
1550 | } | |
1551 | ||
1552 | ||
1553 | /** | |
1554 | * Populates the client cache with the requested inode, and its | |
1555 | * parent dentry. | |
1556 | */ | |
1557 | extern "C" int ceph_ll_lookup_inode( | |
1558 | struct ceph_mount_info *cmount, | |
1559 | struct inodeno_t ino, | |
1560 | Inode **inode) | |
1561 | { | |
1adf2230 | 1562 | return (cmount->get_client())->ll_lookup_inode(ino, cmount->default_perms, inode); |
7c673cae FG |
1563 | } |
1564 | ||
1565 | extern "C" int ceph_ll_lookup(struct ceph_mount_info *cmount, | |
1566 | Inode *parent, const char *name, Inode **out, | |
1567 | struct ceph_statx *stx, unsigned want, | |
1568 | unsigned flags, const UserPerm *perms) | |
1569 | { | |
1570 | if (flags & ~CEPH_REQ_FLAG_MASK) | |
1571 | return -EINVAL; | |
1572 | return (cmount->get_client())->ll_lookupx(parent, name, out, stx, want, | |
1573 | flags, *perms); | |
1574 | } | |
1575 | ||
1576 | extern "C" int ceph_ll_put(class ceph_mount_info *cmount, Inode *in) | |
1577 | { | |
1578 | return (cmount->get_client()->ll_put(in)); | |
1579 | } | |
1580 | ||
1581 | extern "C" int ceph_ll_forget(class ceph_mount_info *cmount, Inode *in, | |
1582 | int count) | |
1583 | { | |
1584 | return (cmount->get_client()->ll_forget(in, count)); | |
1585 | } | |
1586 | ||
1587 | extern "C" int ceph_ll_walk(struct ceph_mount_info *cmount, const char* name, Inode **i, | |
1588 | struct ceph_statx *stx, unsigned int want, unsigned int flags, | |
1589 | const UserPerm *perms) | |
1590 | { | |
1591 | if (flags & ~CEPH_REQ_FLAG_MASK) | |
1592 | return -EINVAL; | |
1593 | return(cmount->get_client()->ll_walk(name, i, stx, want, flags, *perms)); | |
1594 | } | |
1595 | ||
1596 | extern "C" int ceph_ll_getattr(class ceph_mount_info *cmount, | |
1597 | Inode *in, struct ceph_statx *stx, | |
1598 | unsigned int want, unsigned int flags, | |
1599 | const UserPerm *perms) | |
1600 | { | |
1601 | if (flags & ~CEPH_REQ_FLAG_MASK) | |
1602 | return -EINVAL; | |
1603 | return (cmount->get_client()->ll_getattrx(in, stx, want, flags, *perms)); | |
1604 | } | |
1605 | ||
1606 | extern "C" int ceph_ll_setattr(class ceph_mount_info *cmount, | |
1607 | Inode *in, struct ceph_statx *stx, | |
1608 | int mask, const UserPerm *perms) | |
1609 | { | |
1610 | return (cmount->get_client()->ll_setattrx(in, stx, mask, *perms)); | |
1611 | } | |
1612 | ||
1613 | extern "C" int ceph_ll_open(class ceph_mount_info *cmount, Inode *in, | |
1614 | int flags, Fh **fh, const UserPerm *perms) | |
1615 | { | |
1616 | return (cmount->get_client()->ll_open(in, flags, fh, *perms)); | |
1617 | } | |
1618 | ||
1619 | extern "C" int ceph_ll_read(class ceph_mount_info *cmount, Fh* filehandle, | |
1620 | int64_t off, uint64_t len, char* buf) | |
1621 | { | |
1622 | bufferlist bl; | |
1623 | int r = 0; | |
1624 | ||
1625 | r = cmount->get_client()->ll_read(filehandle, off, len, &bl); | |
1626 | if (r >= 0) | |
1627 | { | |
1628 | bl.copy(0, bl.length(), buf); | |
1629 | r = bl.length(); | |
1630 | } | |
1631 | return r; | |
1632 | } | |
1633 | ||
1634 | extern "C" int ceph_ll_read_block(class ceph_mount_info *cmount, | |
1635 | Inode *in, uint64_t blockid, | |
1636 | char* buf, uint64_t offset, | |
1637 | uint64_t length, | |
1638 | struct ceph_file_layout* layout) | |
1639 | { | |
1640 | file_layout_t l; | |
1641 | int r = (cmount->get_client()->ll_read_block(in, blockid, buf, offset, | |
1642 | length, &l)); | |
1643 | l.to_legacy(layout); | |
1644 | return r; | |
1645 | } | |
1646 | ||
1647 | extern "C" int ceph_ll_write_block(class ceph_mount_info *cmount, | |
1648 | Inode *in, uint64_t blockid, | |
1649 | char *buf, uint64_t offset, | |
1650 | uint64_t length, | |
1651 | struct ceph_file_layout *layout, | |
1652 | uint64_t snapseq, uint32_t sync) | |
1653 | { | |
1654 | file_layout_t l; | |
1655 | int r = (cmount->get_client()->ll_write_block(in, blockid, buf, offset, | |
1656 | length, &l, snapseq, sync)); | |
1657 | l.to_legacy(layout); | |
1658 | return r; | |
1659 | } | |
1660 | ||
1661 | extern "C" int ceph_ll_commit_blocks(class ceph_mount_info *cmount, | |
1662 | Inode *in, uint64_t offset, | |
1663 | uint64_t range) | |
1664 | { | |
1665 | return (cmount->get_client()->ll_commit_blocks(in, offset, range)); | |
1666 | } | |
1667 | ||
1668 | extern "C" int ceph_ll_fsync(class ceph_mount_info *cmount, | |
1669 | Fh *fh, int syncdataonly) | |
1670 | { | |
1671 | return (cmount->get_client()->ll_fsync(fh, syncdataonly)); | |
1672 | } | |
1673 | ||
28e407b8 AA |
1674 | extern "C" int ceph_ll_sync_inode(class ceph_mount_info *cmount, |
1675 | Inode *in, int syncdataonly) | |
1676 | { | |
1677 | return (cmount->get_client()->ll_sync_inode(in, syncdataonly)); | |
1678 | } | |
1679 | ||
11fdf7f2 TL |
1680 | extern "C" int ceph_ll_fallocate(class ceph_mount_info *cmount, Fh *fh, |
1681 | int mode, int64_t offset, int64_t length) | |
1682 | { | |
1683 | return cmount->get_client()->ll_fallocate(fh, mode, offset, length); | |
1684 | } | |
1685 | ||
7c673cae FG |
1686 | extern "C" off_t ceph_ll_lseek(class ceph_mount_info *cmount, |
1687 | Fh *fh, off_t offset, int whence) | |
1688 | { | |
1689 | return (cmount->get_client()->ll_lseek(fh, offset, whence)); | |
1690 | } | |
1691 | ||
1692 | extern "C" int ceph_ll_write(class ceph_mount_info *cmount, | |
1693 | Fh *fh, int64_t off, uint64_t len, | |
1694 | const char *data) | |
1695 | { | |
1696 | return (cmount->get_client()->ll_write(fh, off, len, data)); | |
1697 | } | |
1698 | ||
1699 | extern "C" int64_t ceph_ll_readv(class ceph_mount_info *cmount, | |
1700 | struct Fh *fh, const struct iovec *iov, | |
1701 | int iovcnt, int64_t off) | |
1702 | { | |
11fdf7f2 | 1703 | return (cmount->get_client()->ll_readv(fh, iov, iovcnt, off)); |
7c673cae FG |
1704 | } |
1705 | ||
1706 | extern "C" int64_t ceph_ll_writev(class ceph_mount_info *cmount, | |
1707 | struct Fh *fh, const struct iovec *iov, | |
1708 | int iovcnt, int64_t off) | |
1709 | { | |
11fdf7f2 | 1710 | return (cmount->get_client()->ll_writev(fh, iov, iovcnt, off)); |
7c673cae FG |
1711 | } |
1712 | ||
1713 | extern "C" int ceph_ll_close(class ceph_mount_info *cmount, Fh* fh) | |
1714 | { | |
1715 | return (cmount->get_client()->ll_release(fh)); | |
1716 | } | |
1717 | ||
1718 | extern "C" int ceph_ll_create(class ceph_mount_info *cmount, | |
1719 | Inode *parent, const char *name, mode_t mode, | |
1720 | int oflags, Inode **outp, Fh **fhp, | |
1721 | struct ceph_statx *stx, unsigned want, | |
1722 | unsigned lflags, const UserPerm *perms) | |
1723 | { | |
1724 | if (lflags & ~CEPH_REQ_FLAG_MASK) | |
1725 | return -EINVAL; | |
1726 | return (cmount->get_client())->ll_createx(parent, name, mode, oflags, outp, | |
1727 | fhp, stx, want, lflags, *perms); | |
1728 | } | |
1729 | ||
1730 | extern "C" int ceph_ll_mknod(class ceph_mount_info *cmount, Inode *parent, | |
1731 | const char *name, mode_t mode, dev_t rdev, | |
1732 | Inode **out, struct ceph_statx *stx, | |
1733 | unsigned want, unsigned flags, | |
1734 | const UserPerm *perms) | |
1735 | { | |
1736 | if (flags & ~CEPH_REQ_FLAG_MASK) | |
1737 | return -EINVAL; | |
1738 | return (cmount->get_client())->ll_mknodx(parent, name, mode, rdev, | |
1739 | out, stx, want, flags, *perms); | |
1740 | } | |
1741 | ||
1742 | extern "C" int ceph_ll_mkdir(class ceph_mount_info *cmount, Inode *parent, | |
1743 | const char *name, mode_t mode, Inode **out, | |
1744 | struct ceph_statx *stx, unsigned want, | |
1745 | unsigned flags, const UserPerm *perms) | |
1746 | { | |
1747 | if (flags & ~CEPH_REQ_FLAG_MASK) | |
1748 | return -EINVAL; | |
1749 | return cmount->get_client()->ll_mkdirx(parent, name, mode, out, stx, want, | |
1750 | flags, *perms); | |
1751 | } | |
1752 | ||
1753 | extern "C" int ceph_ll_link(class ceph_mount_info *cmount, | |
1754 | Inode *in, Inode *newparent, | |
1755 | const char *name, const UserPerm *perms) | |
1756 | { | |
1757 | return cmount->get_client()->ll_link(in, newparent, name, *perms); | |
1758 | } | |
1759 | ||
1760 | extern "C" int ceph_ll_opendir(class ceph_mount_info *cmount, | |
1761 | Inode *in, | |
1762 | struct ceph_dir_result **dirpp, | |
1763 | const UserPerm *perms) | |
1764 | { | |
1765 | return (cmount->get_client()->ll_opendir(in, O_RDONLY, (dir_result_t**) dirpp, | |
1766 | *perms)); | |
1767 | } | |
1768 | ||
1769 | extern "C" int ceph_ll_releasedir(class ceph_mount_info *cmount, | |
1770 | ceph_dir_result *dir) | |
1771 | { | |
1772 | (void) cmount->get_client()->ll_releasedir(reinterpret_cast<dir_result_t*>(dir)); | |
1773 | return (0); | |
1774 | } | |
1775 | ||
1776 | extern "C" int ceph_ll_rename(class ceph_mount_info *cmount, | |
1777 | Inode *parent, const char *name, | |
1778 | Inode *newparent, const char *newname, | |
1779 | const UserPerm *perms) | |
1780 | { | |
1781 | return cmount->get_client()->ll_rename(parent, name, newparent, | |
1782 | newname, *perms); | |
1783 | } | |
1784 | ||
1785 | extern "C" int ceph_ll_unlink(class ceph_mount_info *cmount, Inode *in, | |
1786 | const char *name, const UserPerm *perms) | |
1787 | { | |
1788 | return cmount->get_client()->ll_unlink(in, name, *perms); | |
1789 | } | |
1790 | ||
1791 | extern "C" int ceph_ll_statfs(class ceph_mount_info *cmount, | |
1792 | Inode *in, struct statvfs *stbuf) | |
1793 | { | |
1794 | return (cmount->get_client()->ll_statfs(in, stbuf, cmount->default_perms)); | |
1795 | } | |
1796 | ||
1797 | extern "C" int ceph_ll_readlink(class ceph_mount_info *cmount, Inode *in, | |
1798 | char *buf, size_t bufsiz, | |
1799 | const UserPerm *perms) | |
1800 | { | |
1801 | return cmount->get_client()->ll_readlink(in, buf, bufsiz, *perms); | |
1802 | } | |
1803 | ||
1804 | extern "C" int ceph_ll_symlink(class ceph_mount_info *cmount, | |
1805 | Inode *in, const char *name, | |
1806 | const char *value, Inode **out, | |
1807 | struct ceph_statx *stx, unsigned want, | |
1808 | unsigned flags, const UserPerm *perms) | |
1809 | { | |
1810 | if (flags & ~CEPH_REQ_FLAG_MASK) | |
1811 | return -EINVAL; | |
1812 | return (cmount->get_client()->ll_symlinkx(in, name, value, out, stx, want, | |
1813 | flags, *perms)); | |
1814 | } | |
1815 | ||
1816 | extern "C" int ceph_ll_rmdir(class ceph_mount_info *cmount, | |
1817 | Inode *in, const char *name, | |
1818 | const UserPerm *perms) | |
1819 | { | |
1820 | return cmount->get_client()->ll_rmdir(in, name, *perms); | |
1821 | } | |
1822 | ||
1823 | extern "C" int ceph_ll_getxattr(class ceph_mount_info *cmount, | |
1824 | Inode *in, const char *name, void *value, | |
1825 | size_t size, const UserPerm *perms) | |
1826 | { | |
1827 | return (cmount->get_client()->ll_getxattr(in, name, value, size, *perms)); | |
1828 | } | |
1829 | ||
1830 | extern "C" int ceph_ll_listxattr(struct ceph_mount_info *cmount, | |
1831 | Inode *in, char *list, | |
1832 | size_t buf_size, size_t *list_size, | |
1833 | const UserPerm *perms) | |
1834 | { | |
1835 | int res = cmount->get_client()->ll_listxattr(in, list, buf_size, *perms); | |
1836 | if (res >= 0) { | |
1837 | *list_size = (size_t)res; | |
1838 | return 0; | |
1839 | } | |
1840 | return res; | |
1841 | } | |
1842 | ||
1843 | extern "C" int ceph_ll_setxattr(class ceph_mount_info *cmount, | |
1844 | Inode *in, const char *name, | |
1845 | const void *value, size_t size, | |
1846 | int flags, const UserPerm *perms) | |
1847 | { | |
1848 | return (cmount->get_client()->ll_setxattr(in, name, value, size, flags, *perms)); | |
1849 | } | |
1850 | ||
1851 | extern "C" int ceph_ll_removexattr(class ceph_mount_info *cmount, | |
1852 | Inode *in, const char *name, | |
1853 | const UserPerm *perms) | |
1854 | { | |
1855 | return (cmount->get_client()->ll_removexattr(in, name, *perms)); | |
1856 | } | |
1857 | ||
1858 | extern "C" int ceph_ll_getlk(struct ceph_mount_info *cmount, | |
1859 | Fh *fh, struct flock *fl, uint64_t owner) | |
1860 | { | |
1861 | return (cmount->get_client()->ll_getlk(fh, fl, owner)); | |
1862 | } | |
1863 | ||
1864 | extern "C" int ceph_ll_setlk(struct ceph_mount_info *cmount, | |
1865 | Fh *fh, struct flock *fl, uint64_t owner, | |
1866 | int sleep) | |
1867 | { | |
1868 | return (cmount->get_client()->ll_setlk(fh, fl, owner, sleep)); | |
1869 | } | |
1870 | ||
11fdf7f2 TL |
1871 | extern "C" int ceph_ll_lazyio(class ceph_mount_info *cmount, |
1872 | Fh *fh, int enable) | |
1873 | { | |
1874 | return (cmount->get_client()->ll_lazyio(fh, enable)); | |
1875 | } | |
1876 | ||
b32b8144 FG |
1877 | extern "C" int ceph_ll_delegation(struct ceph_mount_info *cmount, Fh *fh, |
1878 | unsigned cmd, ceph_deleg_cb_t cb, void *priv) | |
1879 | { | |
1880 | return (cmount->get_client()->ll_delegation(fh, cmd, cb, priv)); | |
1881 | } | |
1882 | ||
7c673cae FG |
1883 | extern "C" uint32_t ceph_ll_stripe_unit(class ceph_mount_info *cmount, |
1884 | Inode *in) | |
1885 | { | |
1886 | return (cmount->get_client()->ll_stripe_unit(in)); | |
1887 | } | |
1888 | ||
1889 | extern "C" uint32_t ceph_ll_file_layout(class ceph_mount_info *cmount, | |
1890 | Inode *in, | |
1891 | struct ceph_file_layout *layout) | |
1892 | { | |
1893 | file_layout_t l; | |
1894 | int r = (cmount->get_client()->ll_file_layout(in, &l)); | |
1895 | l.to_legacy(layout); | |
1896 | return r; | |
1897 | } | |
1898 | ||
1899 | uint64_t ceph_ll_snap_seq(class ceph_mount_info *cmount, Inode *in) | |
1900 | { | |
1901 | return (cmount->get_client()->ll_snap_seq(in)); | |
1902 | } | |
1903 | ||
1904 | extern "C" int ceph_ll_get_stripe_osd(class ceph_mount_info *cmount, | |
1905 | Inode *in, uint64_t blockno, | |
1906 | struct ceph_file_layout* layout) | |
1907 | { | |
1908 | file_layout_t l; | |
1909 | int r = (cmount->get_client()->ll_get_stripe_osd(in, blockno, &l)); | |
1910 | l.to_legacy(layout); | |
1911 | return r; | |
1912 | } | |
1913 | ||
1914 | extern "C" int ceph_ll_num_osds(class ceph_mount_info *cmount) | |
1915 | { | |
1916 | return (cmount->get_client()->ll_num_osds()); | |
1917 | } | |
1918 | ||
1919 | extern "C" int ceph_ll_osdaddr(class ceph_mount_info *cmount, | |
1920 | int osd, uint32_t *addr) | |
1921 | { | |
1922 | return (cmount->get_client()->ll_osdaddr(osd, addr)); | |
1923 | } | |
1924 | ||
1925 | extern "C" uint64_t ceph_ll_get_internal_offset(class ceph_mount_info *cmount, | |
1926 | Inode *in, | |
1927 | uint64_t blockno) | |
1928 | { | |
1929 | return (cmount->get_client()->ll_get_internal_offset(in, blockno)); | |
1930 | } | |
1931 | ||
1932 | extern "C" void ceph_buffer_free(char *buf) | |
1933 | { | |
1934 | if (buf) { | |
1935 | free(buf); | |
1936 | } | |
1937 | } | |
b32b8144 FG |
1938 | |
1939 | extern "C" uint32_t ceph_get_cap_return_timeout(class ceph_mount_info *cmount) | |
1940 | { | |
1941 | if (!cmount->is_mounted()) | |
1942 | return 0; | |
1943 | return cmount->get_client()->mdsmap->get_session_autoclose().sec(); | |
1944 | } | |
1945 | ||
1946 | extern "C" int ceph_set_deleg_timeout(class ceph_mount_info *cmount, uint32_t timeout) | |
1947 | { | |
1948 | if (!cmount->is_mounted()) | |
1949 | return -ENOTCONN; | |
1950 | return cmount->get_client()->set_deleg_timeout(timeout); | |
1951 | } | |
11fdf7f2 TL |
1952 | |
1953 | extern "C" void ceph_set_session_timeout(class ceph_mount_info *cmount, unsigned timeout) | |
1954 | { | |
1955 | cmount->get_client()->set_session_timeout(timeout); | |
1956 | } | |
1957 | ||
1958 | extern "C" void ceph_set_uuid(class ceph_mount_info *cmount, const char *uuid) | |
1959 | { | |
1960 | cmount->get_client()->set_uuid(std::string(uuid)); | |
1961 | } | |
1962 | ||
1963 | extern "C" int ceph_start_reclaim(class ceph_mount_info *cmount, | |
1964 | const char *uuid, unsigned flags) | |
1965 | { | |
1966 | if (!cmount->is_initialized()) { | |
1967 | int ret = cmount->init(); | |
1968 | if (ret != 0) | |
1969 | return ret; | |
1970 | } | |
1971 | return cmount->get_client()->start_reclaim(std::string(uuid), flags, | |
1972 | cmount->get_filesystem()); | |
1973 | } | |
1974 | ||
1975 | extern "C" void ceph_finish_reclaim(class ceph_mount_info *cmount) | |
1976 | { | |
1977 | cmount->get_client()->finish_reclaim(); | |
1978 | } |