-
Notifications
You must be signed in to change notification settings - Fork 40
/
libcephfs.cc
1626 lines (1445 loc) · 40.9 KB
/
libcephfs.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2009-2011 New Dream Network
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#include <fcntl.h>
#include <iostream>
#include <string.h>
#include <string>
#include "auth/Crypto.h"
#include "client/Client.h"
#include "include/cephfs/libcephfs.h"
#include "common/Mutex.h"
#include "common/ceph_argparse.h"
#include "common/common_init.h"
#include "common/config.h"
#include "common/version.h"
#include "mon/MonClient.h"
#include "include/str_list.h"
#include "messages/MMonMap.h"
#include "msg/Messenger.h"
#include "include/assert.h"
struct ceph_mount_info
{
public:
ceph_mount_info(uint64_t msgr_nonce_, CephContext *cct_)
: msgr_nonce(msgr_nonce_),
mounted(false),
inited(false),
client(NULL),
monclient(NULL),
messenger(NULL),
cct(cct_)
{
}
~ceph_mount_info()
{
try {
shutdown();
if (cct) {
cct->put();
cct = NULL;
}
}
catch (const std::exception& e) {
// we shouldn't get here, but if we do, we want to know about it.
lderr(cct) << "ceph_mount_info::~ceph_mount_info: caught exception: "
<< e.what() << dendl;
}
catch (...) {
// ignore
}
}
int init()
{
common_init_finish(cct);
int ret;
//monmap
monclient = new MonClient(cct);
ret = -CEPHFS_ERROR_MON_MAP_BUILD; //defined in libcephfs.h;
if (monclient->build_initial_monmap() < 0)
goto fail;
//network connection
messenger = Messenger::create(cct, cct->_conf->ms_type, entity_name_t::CLIENT(), "client", msgr_nonce);
//at last the client
ret = -CEPHFS_ERROR_NEW_CLIENT; //defined in libcephfs.h;
client = new Client(messenger, monclient);
if (!client)
goto fail;
ret = -CEPHFS_ERROR_MESSENGER_START; //defined in libcephfs.h;
if (messenger->start() != 0)
goto fail;
ret = client->init();
if (ret)
goto fail;
inited = true;
return 0;
fail:
shutdown();
return ret;
}
int mount(const std::string &mount_root)
{
int ret;
if (mounted)
return -EISCONN;
ret = init();
if (ret != 0) {
return ret;
}
ret = client->mount(mount_root);
if (ret) {
shutdown();
return ret;
} else {
mounted = true;
return 0;
}
}
int unmount()
{
if (!mounted)
return -ENOTCONN;
shutdown();
return 0;
}
void shutdown()
{
if (mounted) {
client->unmount();
mounted = false;
}
if (inited) {
client->shutdown();
inited = false;
}
if (messenger) {
messenger->shutdown();
messenger->wait();
delete messenger;
messenger = NULL;
}
if (monclient) {
delete monclient;
monclient = NULL;
}
if (client) {
delete client;
client = NULL;
}
}
bool is_initialized() const
{
return inited;
}
bool is_mounted()
{
return mounted;
}
int conf_read_file(const char *path_list)
{
std::deque<std::string> parse_errors;
int ret = cct->_conf->parse_config_files(path_list, &parse_errors, NULL, 0);
if (ret)
return ret;
cct->_conf->apply_changes(NULL);
complain_about_parse_errors(cct, &parse_errors);
return 0;
}
int conf_parse_argv(int argc, const char **argv)
{
int ret;
vector<const char*> args;
argv_to_vec(argc, argv, args);
ret = cct->_conf->parse_argv(args);
if (ret)
return ret;
cct->_conf->apply_changes(NULL);
return 0;
}
int conf_parse_env(const char *name)
{
md_config_t *conf = cct->_conf;
vector<const char*> args;
env_to_vec(args, name);
int ret = conf->parse_argv(args);
if (ret)
return ret;
conf->apply_changes(NULL);
return 0;
}
int conf_set(const char *option, const char *value)
{
int ret = cct->_conf->set_val(option, value);
if (ret)
return ret;
cct->_conf->apply_changes(NULL);
return 0;
}
int conf_get(const char *option, char *buf, size_t len)
{
char *tmp = buf;
return cct->_conf->get_val(option, &tmp, len);
}
Client *get_client()
{
return client;
}
const char *get_cwd()
{
client->getcwd(cwd);
return cwd.c_str();
}
CephContext *get_ceph_context() const {
return cct;
}
private:
uint64_t msgr_nonce;
bool mounted;
bool inited;
Client *client;
MonClient *monclient;
Messenger *messenger;
CephContext *cct;
std::string cwd;
};
static void do_out_buffer(bufferlist& outbl, char **outbuf, size_t *outbuflen)
{
if (outbuf) {
if (outbl.length() > 0) {
*outbuf = (char *)malloc(outbl.length());
memcpy(*outbuf, outbl.c_str(), outbl.length());
} else {
*outbuf = NULL;
}
}
if (outbuflen)
*outbuflen = outbl.length();
}
static void do_out_buffer(string& outbl, char **outbuf, size_t *outbuflen)
{
if (outbuf) {
if (outbl.length() > 0) {
*outbuf = (char *)malloc(outbl.length());
memcpy(*outbuf, outbl.c_str(), outbl.length());
} else {
*outbuf = NULL;
}
}
if (outbuflen)
*outbuflen = outbl.length();
}
extern "C" const char *ceph_version(int *pmajor, int *pminor, int *ppatch)
{
int major, minor, patch;
const char *v = ceph_version_to_str();
int n = sscanf(v, "%d.%d.%d", &major, &minor, &patch);
if (pmajor)
*pmajor = (n >= 1) ? major : 0;
if (pminor)
*pminor = (n >= 2) ? minor : 0;
if (ppatch)
*ppatch = (n >= 3) ? patch : 0;
return VERSION;
}
extern "C" int ceph_create_with_context(struct ceph_mount_info **cmount, CephContext *cct)
{
uint64_t nonce = 0;
// 6 bytes of random and 2 bytes of pid
get_random_bytes((char*)&nonce, sizeof(nonce));
nonce &= ~0xffff;
nonce |= (uint64_t)getpid();
*cmount = new struct ceph_mount_info(nonce, cct);
return 0;
}
extern "C" int ceph_create(struct ceph_mount_info **cmount, const char * const id)
{
CephInitParameters iparams(CEPH_ENTITY_TYPE_CLIENT);
if (id) {
iparams.name.set(CEPH_ENTITY_TYPE_CLIENT, id);
}
CephContext *cct = common_preinit(iparams, CODE_ENVIRONMENT_LIBRARY, 0);
cct->_conf->parse_env(); // environment variables coverride
cct->_conf->apply_changes(NULL);
return ceph_create_with_context(cmount, cct);
}
extern "C" int ceph_unmount(struct ceph_mount_info *cmount)
{
return cmount->unmount();
}
extern "C" int ceph_release(struct ceph_mount_info *cmount)
{
if (cmount->is_mounted())
return -EISCONN;
delete cmount;
return 0;
}
extern "C" void ceph_shutdown(struct ceph_mount_info *cmount)
{
cmount->shutdown();
delete cmount;
}
extern "C" int ceph_conf_read_file(struct ceph_mount_info *cmount, const char *path)
{
return cmount->conf_read_file(path);
}
extern "C" int ceph_conf_parse_argv(struct ceph_mount_info *cmount, int argc,
const char **argv)
{
return cmount->conf_parse_argv(argc, argv);
}
extern "C" int ceph_conf_parse_env(struct ceph_mount_info *cmount, const char *name)
{
return cmount->conf_parse_env(name);
}
extern "C" int ceph_conf_set(struct ceph_mount_info *cmount, const char *option,
const char *value)
{
return cmount->conf_set(option, value);
}
extern "C" int ceph_conf_get(struct ceph_mount_info *cmount, const char *option,
char *buf, size_t len)
{
if (buf == NULL) {
return -EINVAL;
}
return cmount->conf_get(option, buf, len);
}
extern "C" int ceph_mds_command(struct ceph_mount_info *cmount,
const char *mds_spec,
const char **cmd,
size_t cmdlen,
const char *inbuf, size_t inbuflen,
char **outbuf, size_t *outbuflen,
char **outsbuf, size_t *outsbuflen)
{
bufferlist inbl;
bufferlist outbl;
std::vector<string> cmdv;
std::string outs;
if (!cmount->is_initialized()) {
return -ENOTCONN;
}
// Construct inputs
for (size_t i = 0; i < cmdlen; ++i) {
cmdv.push_back(cmd[i]);
}
inbl.append(inbuf, inbuflen);
// Issue remote command
C_SaferCond cond;
int r = cmount->get_client()->mds_command(
mds_spec,
cmdv, inbl,
&outbl, &outs,
&cond);
if (r != 0) {
goto out;
}
// Wait for completion
r = cond.wait();
// Construct outputs
do_out_buffer(outbl, outbuf, outbuflen);
do_out_buffer(outs, outsbuf, outsbuflen);
out:
return r;
}
extern "C" int ceph_init(struct ceph_mount_info *cmount)
{
return cmount->init();
}
extern "C" int ceph_mount(struct ceph_mount_info *cmount, const char *root)
{
std::string mount_root;
if (root)
mount_root = root;
return cmount->mount(mount_root);
}
extern "C" int ceph_is_mounted(struct ceph_mount_info *cmount)
{
return cmount->is_mounted() ? 1 : 0;
}
extern "C" int ceph_statfs(struct ceph_mount_info *cmount, const char *path,
struct statvfs *stbuf)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->statfs(path, stbuf);
}
extern "C" int ceph_get_local_osd(struct ceph_mount_info *cmount)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->get_local_osd();
}
extern "C" const char* ceph_getcwd(struct ceph_mount_info *cmount)
{
return cmount->get_cwd();
}
extern "C" int ceph_chdir (struct ceph_mount_info *cmount, const char *s)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->chdir(s);
}
extern "C" int ceph_opendir(struct ceph_mount_info *cmount,
const char *name, struct ceph_dir_result **dirpp)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->opendir(name, (dir_result_t **)dirpp);
}
extern "C" int ceph_closedir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->closedir(reinterpret_cast<dir_result_t*>(dirp));
}
extern "C" struct dirent * ceph_readdir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp)
{
if (!cmount->is_mounted()) {
/* Client::readdir also sets errno to signal errors. */
errno = -ENOTCONN;
return NULL;
}
return cmount->get_client()->readdir(reinterpret_cast<dir_result_t*>(dirp));
}
extern "C" int ceph_readdir_r(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, struct dirent *de)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->readdir_r(reinterpret_cast<dir_result_t*>(dirp), de);
}
extern "C" int ceph_readdirplus_r(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp,
struct dirent *de, struct stat *st, int *stmask)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->readdirplus_r(reinterpret_cast<dir_result_t*>(dirp), de, st, stmask);
}
extern "C" int ceph_getdents(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp,
char *buf, int buflen)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->getdents(reinterpret_cast<dir_result_t*>(dirp), buf, buflen);
}
extern "C" int ceph_getdnames(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp,
char *buf, int buflen)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->getdnames(reinterpret_cast<dir_result_t*>(dirp), buf, buflen);
}
extern "C" void ceph_rewinddir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp)
{
if (!cmount->is_mounted())
return;
cmount->get_client()->rewinddir(reinterpret_cast<dir_result_t*>(dirp));
}
extern "C" int64_t ceph_telldir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->telldir(reinterpret_cast<dir_result_t*>(dirp));
}
extern "C" void ceph_seekdir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, int64_t offset)
{
if (!cmount->is_mounted())
return;
cmount->get_client()->seekdir(reinterpret_cast<dir_result_t*>(dirp), offset);
}
extern "C" int ceph_link (struct ceph_mount_info *cmount, const char *existing,
const char *newname)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->link(existing, newname);
}
extern "C" int ceph_unlink(struct ceph_mount_info *cmount, const char *path)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->unlink(path);
}
extern "C" int ceph_rename(struct ceph_mount_info *cmount, const char *from,
const char *to)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->rename(from, to);
}
// dirs
extern "C" int ceph_mkdir(struct ceph_mount_info *cmount, const char *path, mode_t mode)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->mkdir(path, mode);
}
extern "C" int ceph_mkdirs(struct ceph_mount_info *cmount, const char *path, mode_t mode)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->mkdirs(path, mode);
}
extern "C" int ceph_rmdir(struct ceph_mount_info *cmount, const char *path)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->rmdir(path);
}
// symlinks
extern "C" int ceph_readlink(struct ceph_mount_info *cmount, const char *path,
char *buf, int64_t size)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->readlink(path, buf, size);
}
extern "C" int ceph_symlink(struct ceph_mount_info *cmount, const char *existing,
const char *newname)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->symlink(existing, newname);
}
// inode stuff
extern "C" int ceph_stat(struct ceph_mount_info *cmount, const char *path,
struct stat *stbuf)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->stat(path, stbuf);
}
extern "C" int ceph_lstat(struct ceph_mount_info *cmount, const char *path,
struct stat *stbuf)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->lstat(path, stbuf);
}
extern "C" int ceph_setattr(struct ceph_mount_info *cmount, const char *relpath,
struct stat *attr, int mask)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->setattr(relpath, attr, mask);
}
// *xattr() calls supporting samba/vfs
extern "C" int ceph_getxattr(struct ceph_mount_info *cmount, const char *path, const char *name, void *value, size_t size)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->getxattr(path, name, value, size);
}
extern "C" int ceph_lgetxattr(struct ceph_mount_info *cmount, const char *path, const char *name, void *value, size_t size)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->lgetxattr(path, name, value, size);
}
extern "C" int ceph_listxattr(struct ceph_mount_info *cmount, const char *path, char *list, size_t size)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->listxattr(path, list, size);
}
extern "C" int ceph_llistxattr(struct ceph_mount_info *cmount, const char *path, char *list, size_t size)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->llistxattr(path, list, size);
}
extern "C" int ceph_removexattr(struct ceph_mount_info *cmount, const char *path, const char *name)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->removexattr(path, name);
}
extern "C" int ceph_lremovexattr(struct ceph_mount_info *cmount, const char *path, const char *name)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->lremovexattr(path, name);
}
extern "C" int ceph_setxattr(struct ceph_mount_info *cmount, const char *path, const char *name, const void *value, size_t size, int flags)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->setxattr(path, name, value, size, flags);
}
extern "C" int ceph_lsetxattr(struct ceph_mount_info *cmount, const char *path, const char *name, const void *value, size_t size, int flags)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->lsetxattr(path, name, value, size, flags);
}
/* end xattr support */
extern "C" int ceph_chmod(struct ceph_mount_info *cmount, const char *path, mode_t mode)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->chmod(path, mode);
}
extern "C" int ceph_fchmod(struct ceph_mount_info *cmount, int fd, mode_t mode)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->fchmod(fd, mode);
}
extern "C" int ceph_chown(struct ceph_mount_info *cmount, const char *path,
int uid, int gid)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->chown(path, uid, gid);
}
extern "C" int ceph_fchown(struct ceph_mount_info *cmount, int fd,
int uid, int gid)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->fchown(fd, uid, gid);
}
extern "C" int ceph_lchown(struct ceph_mount_info *cmount, const char *path,
int uid, int gid)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->lchown(path, uid, gid);
}
extern "C" int ceph_utime(struct ceph_mount_info *cmount, const char *path,
struct utimbuf *buf)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->utime(path, buf);
}
extern "C" int ceph_truncate(struct ceph_mount_info *cmount, const char *path,
int64_t size)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->truncate(path, size);
}
// file ops
extern "C" int ceph_mknod(struct ceph_mount_info *cmount, const char *path,
mode_t mode, dev_t rdev)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->mknod(path, mode, rdev);
}
extern "C" int ceph_open(struct ceph_mount_info *cmount, const char *path,
int flags, mode_t mode)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->open(path, flags, mode);
}
extern "C" int ceph_open_layout(struct ceph_mount_info *cmount, const char *path, int flags,
mode_t mode, int stripe_unit, int stripe_count, int object_size, const char *data_pool)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->open(path, flags, mode, stripe_unit,
stripe_count, object_size, data_pool);
}
extern "C" int ceph_close(struct ceph_mount_info *cmount, int fd)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->close(fd);
}
extern "C" int64_t ceph_lseek(struct ceph_mount_info *cmount, int fd,
int64_t offset, int whence)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->lseek(fd, offset, whence);
}
extern "C" int ceph_read(struct ceph_mount_info *cmount, int fd, char *buf,
int64_t size, int64_t offset)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->read(fd, buf, size, offset);
}
extern "C" int ceph_write(struct ceph_mount_info *cmount, int fd, const char *buf,
int64_t size, int64_t offset)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->write(fd, buf, size, offset);
}
extern "C" int ceph_ftruncate(struct ceph_mount_info *cmount, int fd, int64_t size)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->ftruncate(fd, size);
}
extern "C" int ceph_fsync(struct ceph_mount_info *cmount, int fd, int syncdataonly)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->fsync(fd, syncdataonly);
}
extern "C" int ceph_fallocate(struct ceph_mount_info *cmount, int fd, int mode,
int64_t offset, int64_t length)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->fallocate(fd, mode, offset, length);
}
extern "C" int ceph_fstat(struct ceph_mount_info *cmount, int fd, struct stat *stbuf)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->fstat(fd, stbuf);
}
extern "C" int ceph_sync_fs(struct ceph_mount_info *cmount)
{
if (!cmount->is_mounted())
return -ENOTCONN;
return cmount->get_client()->sync_fs();
}
extern "C" int ceph_get_file_stripe_unit(struct ceph_mount_info *cmount, int fh)
{
struct ceph_file_layout l;
int r;
if (!cmount->is_mounted())
return -ENOTCONN;
r = cmount->get_client()->fdescribe_layout(fh, &l);
if (r < 0)
return r;
return l.fl_stripe_unit;
}
extern "C" int ceph_get_path_stripe_unit(struct ceph_mount_info *cmount, const char *path)
{
struct ceph_file_layout l;
int r;
if (!cmount->is_mounted())
return -ENOTCONN;
r = cmount->get_client()->describe_layout(path, &l);
if (r < 0)
return r;
return l.fl_stripe_unit;
}
extern "C" int ceph_get_file_stripe_count(struct ceph_mount_info *cmount, int fh)
{
struct ceph_file_layout l;
int r;
if (!cmount->is_mounted())
return -ENOTCONN;
r = cmount->get_client()->fdescribe_layout(fh, &l);
if (r < 0)
return r;
return l.fl_stripe_count;
}
extern "C" int ceph_get_path_stripe_count(struct ceph_mount_info *cmount, const char *path)
{
struct ceph_file_layout l;
int r;
if (!cmount->is_mounted())
return -ENOTCONN;
r = cmount->get_client()->describe_layout(path, &l);
if (r < 0)
return r;
return l.fl_stripe_count;
}
extern "C" int ceph_get_file_object_size(struct ceph_mount_info *cmount, int fh)
{
struct ceph_file_layout l;
int r;
if (!cmount->is_mounted())
return -ENOTCONN;
r = cmount->get_client()->fdescribe_layout(fh, &l);
if (r < 0)
return r;
return l.fl_object_size;
}
extern "C" int ceph_get_path_object_size(struct ceph_mount_info *cmount, const char *path)
{
struct ceph_file_layout l;
int r;
if (!cmount->is_mounted())
return -ENOTCONN;
r = cmount->get_client()->describe_layout(path, &l);
if (r < 0)
return r;
return l.fl_object_size;
}
extern "C" int ceph_get_file_pool(struct ceph_mount_info *cmount, int fh)
{
struct ceph_file_layout l;
int r;
if (!cmount->is_mounted())
return -ENOTCONN;
r = cmount->get_client()->fdescribe_layout(fh, &l);
if (r < 0)
return r;
return l.fl_pg_pool;
}
extern "C" int ceph_get_path_pool(struct ceph_mount_info *cmount, const char *path)
{
struct ceph_file_layout l;
int r;
if (!cmount->is_mounted())
return -ENOTCONN;
r = cmount->get_client()->describe_layout(path, &l);
if (r < 0)
return r;
return l.fl_pg_pool;
}
extern "C" int ceph_get_file_pool_name(struct ceph_mount_info *cmount, int fh, char *buf, size_t len)
{
struct ceph_file_layout l;
int r;
if (!cmount->is_mounted())
return -ENOTCONN;
r = cmount->get_client()->fdescribe_layout(fh, &l);
if (r < 0)
return r;
string name = cmount->get_client()->get_pool_name(l.fl_pg_pool);
if (len == 0)
return name.length();
if (name.length() > len)
return -ERANGE;
strncpy(buf, name.c_str(), len);
return name.length();
}
extern "C" int ceph_get_pool_name(struct ceph_mount_info *cmount, int pool, char *buf, size_t len)
{
if (!cmount->is_mounted())
return -ENOTCONN;
string name = cmount->get_client()->get_pool_name(pool);
if (len == 0)
return name.length();
if (name.length() > len)
return -ERANGE;
strncpy(buf, name.c_str(), len);
return name.length();
}
extern "C" int ceph_get_path_pool_name(struct ceph_mount_info *cmount, const char *path, char *buf, size_t len)
{
struct ceph_file_layout l;
int r;
if (!cmount->is_mounted())
return -ENOTCONN;
r = cmount->get_client()->describe_layout(path, &l);
if (r < 0)
return r;
string name = cmount->get_client()->get_pool_name(l.fl_pg_pool);
if (len == 0)
return name.length();
if (name.length() > len)
return -ERANGE;
strncpy(buf, name.c_str(), len);
return name.length();
}
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)
{
struct ceph_file_layout l;
int r;
if (!cmount->is_mounted())
return -ENOTCONN;
r = cmount->get_client()->fdescribe_layout(fh, &l);
if (r < 0)
return r;
if (stripe_unit)
*stripe_unit = l.fl_stripe_unit;
if (stripe_count)
*stripe_count = l.fl_stripe_count;
if (object_size)
*object_size = l.fl_object_size;
if (pg_pool)
*pg_pool = l.fl_pg_pool;
return 0;
}
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)
{