This repository has been archived by the owner on Feb 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
c0appz.c
1455 lines (1252 loc) · 35.3 KB
/
c0appz.c
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
/* -*- C -*- */
/*
* Copyright (c) 2017-2020 Seagate Technology LLC and/or its Affiliates
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For any questions about this software or licensing,
* please email [email protected] or [email protected].
*
* Original author: Ganesan Umanesan <[email protected]>
* Original creation date: 10-Jan-2017
*
* Subsequent Modifications: Abhishek Saha <[email protected]>
* Date of Modification: 02-Nov-2018
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <lib/semaphore.h>
#include <lib/trace.h>
#include <lib/memory.h>
#include <lib/mutex.h>
#include <sys/user.h> /* PAGE_SIZE */
#include "motr/client.h"
#include "motr/client_internal.h"
#include "conf/confc.h" /* m0_confc_open_sync */
#include "conf/dir.h" /* m0_conf_dir_len */
#include "conf/helpers.h" /* m0_confc_root_open */
#include "conf/diter.h" /* m0_conf_diter_next_sync */
#include "conf/obj_ops.h" /* M0_CONF_DIREND */
#include "spiel/spiel.h" /* m0_spiel_process_lib_load */
#include "reqh/reqh.h" /* m0_reqh */
#include "lib/types.h" /* uint32_t */
#include "c0appz.h"
#include "c0appz_internal.h"
#include "iscservice/isc.h"
#include "lib/buf.h"
#include "rpc/rpclib.h"
#include "c0appz_isc.h"
#ifndef DEBUG
#define DEBUG 0
#endif
const char *c0appz_help_txt = "\
The utility requires startup configuration file with a few cluster-\n\
specific parameters which usually don't change until the cluster is\n\
reconfigured by the system administrator. For example:\n\
\n\
$ cat $HOME/.c0appz/c0cprc/client-22\n\
HA_ENDPOINT_ADDR = 172.18.1.22@o2ib:12345:34:101\n\
PROFILE_FID = 0x7000000000000001:0xcfd\n\
M0_POOL_TIER1 = 0x6f00000000000001:0xc74 # tier1-nvme\n\
M0_POOL_TIER2 = 0x6f00000000000001:0xc8a # tier2-ssd\n\
M0_POOL_TIER3 = 0x6f00000000000001:0xca5 # tier3-hdd\n\
LOCAL_ENDPOINT_ADDR0 = 172.18.1.22@o2ib:12345:41:351\n\
LOCAL_PROC_FID0 = 0x7200000000000001:0x645\n\
\n\
c0cprc is the utility name (c0cp in this case) + rc suffix.\n\
client-22 is the client node name where the utility is run.\n\
HA_ENDPOINT_ADDR is the address of HA agent running on the node.\n\
LOCAL_ENDPOINT_ADDRx and LOCAL_PROC_FIDx addresses and fids are\n\
allocated by system administrator for each user's application\n\
working with the object store cluster.\n\
The easiest way to generate this file is like this:\n\
\n\
$ cd ~/m0client-sample-apps\n\
$ make c=22 sagercf\n\
\n\
Where 22 is the last byte in the client's node IP address.\n";
enum {
MAX_M0_BUFSZ = 128*1024*1024, /* max bs for object store I/O */
MAX_POOLS = 16,
MAX_RCFILE_NAME_LEN = 512,
MAX_CONF_STR_LEN = 128,
MAX_CONF_PARAMS = 32,
};
/* static variables */
static struct m0_client *m0_instance = NULL;
static struct m0_container container;
static struct m0_config m0_conf;
static struct m0_idx_dix_config dix_conf;
static struct m0_spiel spiel_inst;
static char c0rcfile[MAX_RCFILE_NAME_LEN] = "./.c0appzrc";
/*
******************************************************************************
* STATIC FUNCTION PROTOTYPES
******************************************************************************
*/
static size_t read_data_from_file(FILE *fp, struct m0_bufvec *data,
size_t bsz, uint32_t cnt);
static size_t write_data_to_file(FILE *fp, struct m0_bufvec *data,
size_t bsz, uint32_t cnt);
/*
******************************************************************************
* GLOBAL VARIABLES
******************************************************************************
*/
struct m0_realm uber_realm;
unsigned unit_size = 0;
int perf=0; /* performance option */
extern int64_t qos_total_weight; /* total bytes read or written */
extern pthread_mutex_t qos_lock; /* lock qos_total_weight */
int trace_level=0;
bool m0trace_on = false;
struct param {
char name[MAX_CONF_STR_LEN];
char value[MAX_CONF_STR_LEN];
};
static struct m0_fid pools[MAX_POOLS] = {};
/*
******************************************************************************
* STATIC FUNCTIONS
******************************************************************************
*/
/**
* Read parameters into array p[] from file.
*/
static int read_params(FILE *in, struct param *p, int max_params)
{
int ln, n=0;
char s[MAX_CONF_STR_LEN];
for (ln=1; max_params > 0 && fgets(s, MAX_CONF_STR_LEN, in); ln++) {
if (sscanf(s, " %[#\n\r]", p->name))
continue; /* skip emty line or comment */
if (sscanf(s, " %[a-z_A-Z0-9] = %[^#\n\r]",
p->name, p->value) < 2) {
ERR("error at line %d: %s\n", ln, s);
return -1;
}
DBG("%d: name='%s' value='%s'\n", ln, p->name, p->value);
p++, max_params--, n++;
}
return n;
}
static const char* param_get(const char *name, const struct param p[], int n)
{
while (n-- > 0)
if (strcmp(p[n].name, name) == 0)
return p[n].value;
return NULL;
}
/**
* Set pools fids at pools[] from parameters array p[].
*/
static int pools_fids_set(struct param p[], int n)
{
int i;
char pname[32];
const char *pval;
for (i = 0; i < MAX_POOLS; i++) {
sprintf(pname, "M0_POOL_TIER%d", i + 1);
if ((pval = param_get(pname, p, n)) == NULL)
break;
if (m0_fid_sscanf(pval, pools + i) != 0) {
ERR("failed to parse FID of %s\n", pname);
return -1;
}
}
return i;
}
/**
* Return pool fid from pools[] at tier_idx.
*/
static struct m0_fid *tier2pool(uint8_t tier_idx)
{
if (tier_idx < 1 || tier_idx > MAX_POOLS)
return NULL;
return pools + tier_idx - 1;
}
/* Warning: non-reentrant. */
static char* fid2str(const struct m0_fid *fid)
{
static char buf[256];
if (fid)
sprintf(buf, FID_F, FID_P(fid));
else
sprintf(buf, "%p", fid);
return buf;
}
static uint64_t roundup_power2(uint64_t x)
{
uint64_t power = 1;
while (power < x)
power *= 2;
return power;
}
/*
******************************************************************************
* EXTERN FUNCTIONS
******************************************************************************
*/
/**
* Calculate the optimal block size for the object store I/O
*/
uint64_t c0appz_m0bs(uint64_t idhi, uint64_t idlo, uint64_t obj_sz, int tier)
{
int rc;
int k;
unsigned long usz; /* unit size */
unsigned long gsz; /* data units in parity group */
uint64_t max_bs;
unsigned lid;
struct m0_reqh *reqh = &m0_instance->m0c_reqh;
struct m0_pool_version *pver;
struct m0_pdclust_attr *pa;
struct m0_fid *pool = tier2pool(tier);
struct m0_obj obj;
if (obj_sz > MAX_M0_BUFSZ)
obj_sz = MAX_M0_BUFSZ;
rc = m0_pool_version_get(reqh->rh_pools, pool, &pver);
if (rc != 0) {
ERR("m0_pool_version_get(pool=%s) failed: rc=%d\n",
fid2str(pool), rc);
return 0;
}
if (c0appz_ex(idhi, idlo, &obj))
lid = obj.ob_attr.oa_layout_id;
else if (unit_size) /* set explicitly via -u option ? */
lid = m0_client_layout_id(m0_instance);
else
lid = m0_layout_find_by_buffsize(&reqh->rh_ldom, &pver->pv_id,
obj_sz);
usz = m0_obj_layout_id_to_unit_size(lid);
pa = &pver->pv_attr;
gsz = usz * pa->pa_N;
/*
* The buffer should be max 4-times pool-width deep counting by
* 1MB units, otherwise we may get -E2BIG from Motr BE subsystem
* when there are too many units in one fop and the transaction
* grow too big.
*
* Also, the bigger is unit size - the bigger transaction it may
* require. LNet maximum frame size is 1MB, so, for example, 2MB
* unit will be sent by two LNet frames and will make bigger BE
* transaction.
*/
k = 8 / (usz / 0x80000 ?: 1);
max_bs = usz * k * pa->pa_P * pa->pa_N / (pa->pa_N + 2 * pa->pa_K);
max_bs = max_bs / gsz * gsz; /* make it multiple of group size */
DBG("usz=%lu (N,K,P)=(%u,%u,%u) max_bs=%lu\n",
usz, pa->pa_N, pa->pa_K, pa->pa_P, max_bs);
if (obj_sz >= max_bs)
return max_bs;
else if (obj_sz <= gsz)
return gsz;
else
return roundup_power2(obj_sz);
}
void free_segs(struct m0_bufvec *data, struct m0_indexvec *ext,
struct m0_bufvec *attr)
{
m0_indexvec_free(ext);
m0_bufvec_free(data);
m0_bufvec_free(attr);
}
int alloc_segs(struct m0_bufvec *data, struct m0_indexvec *ext,
struct m0_bufvec *attr, uint64_t bsz, uint32_t cnt)
{
int i, rc;
rc = m0_bufvec_alloc(data, cnt, bsz) ?:
m0_bufvec_alloc(attr, cnt, 1) ?:
m0_indexvec_alloc(ext, cnt);
if (rc != 0)
goto err;
for (i = 0; i < cnt; i++)
attr->ov_vec.v_count[i] = 0; /* no attrs */
return 0;
err:
free_segs(data, ext, attr);
return rc;
}
uint64_t set_exts(struct m0_indexvec *ext, uint64_t off, uint64_t bsz)
{
uint32_t i;
for (i = 0; i < ext->iv_vec.v_nr; i++) {
ext->iv_index[i] = off;
ext->iv_vec.v_count[i] = bsz;
off += bsz;
}
return i * bsz;
}
/*
* c0appz_cp()
* copy to an object.
*/
int c0appz_cp(uint64_t idhi, uint64_t idlo, char *filename,
uint64_t bsz, uint64_t cnt, uint64_t m0bs)
{
int rc=0;
uint32_t cnt_per_op;
uint64_t off = 0;
struct m0_uint128 id = {idhi, idlo};
struct m0_indexvec ext;
struct m0_bufvec data;
struct m0_bufvec attr;
FILE *fp;
m0_time_t st;
m0_time_t read_time = 0;
m0_time_t write_time = 0;
double time;
double fs_bw;
double client_bw;
struct m0_obj obj = {};
CHECK_BSZ_ARGS(bsz, m0bs);
cnt_per_op = m0bs / bsz;
/* Open src file */
fp = fopen(filename, "rb");
if (fp == NULL) {
fprintf(stderr,"%s(): error on opening input file %s: %s\n",
__func__, filename, strerror(errno));
return -errno;
}
/* Allocate data buffers, bufvec and indexvec for write */
rc = alloc_segs(&data, &ext, &attr, bsz, cnt_per_op);
if (rc != 0)
goto out;
/* Open the object entity we want to write to */
m0_obj_init(&obj, &uber_realm, &id, M0_DEFAULT_LAYOUT_ID);
rc = open_entity(&obj.ob_entity);
if (rc != 0) {
fprintf(stderr, "%s(): open_entity() failed: rc=%d\n",
__func__, rc);
goto free_vecs;
}
for (; cnt > 0; cnt -= cnt_per_op) {
if (cnt < cnt_per_op)
cnt_per_op = cnt;
/* Read data from source file. */
st = m0_time_now();
rc = read_data_from_file(fp, &data, bsz, cnt_per_op);
if (rc != cnt_per_op) {
fprintf(stderr, "%s(): reading from %s at %lu failed: "
"expected %u, got %d records\n",
__func__, filename, off, cnt_per_op, rc);
rc = -EIO;
break;
}
read_time = m0_time_add(read_time,
m0_time_sub(m0_time_now(), st));
DBG("IO block: off=0x%lx len=0x%lx\n", off, bsz);
off += set_exts(&ext, off, bsz);
/* Copy data to the object */
st = m0_time_now();
rc = write_data_to_object(&obj, &ext, &data, &attr);
if (rc != 0) {
ERR("writing to object failed: rc=%d\n", rc);
break;
}
write_time = m0_time_add(write_time,
m0_time_sub(m0_time_now(), st));
/* QOS */
pthread_mutex_lock(&qos_lock);
qos_objio_signal_start();
qos_total_weight += cnt_per_op * bsz;
pthread_mutex_unlock(&qos_lock);
/* END */
}
m0_entity_fini(&obj.ob_entity);
free_vecs:
free_segs(&data, &ext, &attr);
out:
fclose(fp);
if (perf && rc == 0) {
time = (double) read_time / M0_TIME_ONE_SECOND;
fs_bw = off / 1000000.0 / time;
ppf("Motr I/O[ \033[0;31mOSFS: %10.4lf s %10.4lf MB/s\033[0m ]",time, fs_bw);
time = (double) write_time / M0_TIME_ONE_SECOND;
client_bw = off / 1000000.0 / time;
ppf("[ \033[0;31mMOTR: %10.4lf s %10.4lf MB/s\033[0m ]\n",time, client_bw);
}
return rc;
}
/*
* c0appz_cp_async()
* copy to an object from a file in an asynchronous manner
*/
int c0appz_cp_async(uint64_t idhi, uint64_t idlo, char *src, uint64_t bsz,
uint64_t cnt, uint32_t op_cnt, uint64_t m0bs)
{
int rc = 0;
uint32_t i;
uint32_t nr_ops_sent;
uint32_t cnt_per_op;
uint64_t off = 0;
struct m0_uint128 id = {idhi, idlo};
struct m0_aio_op *aio;
struct m0_aio_opgrp aio_grp;
FILE *fp;
CHECK_BSZ_ARGS(bsz, m0bs);
cnt_per_op = m0bs / bsz;
/* open file */
fp = fopen(src, "rb");
if (fp == NULL) {
fprintf(stderr,"%s(): failed to open output file %s: %s\n",
__func__, src, strerror(errno));
return -errno;
}
/* Initialise operation group. */
rc = m0_aio_opgrp_init(&aio_grp, bsz, cnt_per_op, op_cnt);
if (rc != 0)
goto out;
/* Open the object. */
m0_obj_init(&aio_grp.cag_obj, &uber_realm,
&id, M0_DEFAULT_LAYOUT_ID);
rc = open_entity(&aio_grp.cag_obj.ob_entity);
if (rc != 0) {
fprintf(stderr, "%s(): open_entity() failed: rc=%d\n",
__func__, rc);
goto fini;
}
while (cnt > 0 && rc == 0) {
/* Set each op. */
for (i = 0, nr_ops_sent = 0; i < op_cnt && cnt > 0;
i++, cnt -= cnt_per_op, nr_ops_sent++) {
aio = &aio_grp.cag_aio_ops[i];
if (cnt < cnt_per_op)
cnt_per_op = cnt;
/* Read data from source file. */
rc = read_data_from_file(fp, &aio->cao_data,
bsz, cnt_per_op);
if (rc != cnt_per_op) {
fprintf(stderr,
"%s(): reading from %s at %lu failed: "
"expected %u, read %u records\n",
__func__, src, off, cnt_per_op, rc);
rc = -EIO;
break;
}
off += set_exts(&aio->cao_ext, off, bsz);
/* Launch IO op. */
rc = write_data_to_object_async(aio);
if (rc != 0) {
fprintf(stderr, "%s(): writing to object failed\n",
__func__);
break;
}
/* QOS */
pthread_mutex_lock(&qos_lock);
qos_objio_signal_start();
qos_total_weight += cnt_per_op * bsz;
pthread_mutex_unlock(&qos_lock);
/* END */
}
/* Wait for all ops to complete. */
for (i = 0; i < nr_ops_sent; i++)
m0_semaphore_down(&aio_grp.cag_sem);
/* Finalise ops. */
for (i = 0; i < nr_ops_sent; i++)
m0_aio_op_fini_free(aio_grp.cag_aio_ops + i);
rc = rc ?: aio_grp.cag_rc;
}
fini:
m0_entity_fini(&aio_grp.cag_obj.ob_entity);
m0_aio_opgrp_fini(&aio_grp);
out:
fclose(fp);
return rc;
}
/*
* c0appz_cat()
* cat object.
*/
int c0appz_cat(uint64_t idhi, uint64_t idlo, char *filename,
uint64_t bsz, uint64_t cnt, uint64_t m0bs)
{
int rc=0;
uint32_t cnt_per_op;
uint64_t off = 0;
struct m0_uint128 id = {idhi, idlo};
struct m0_indexvec ext;
struct m0_bufvec data;
struct m0_bufvec attr;
FILE *fp;
m0_time_t st;
m0_time_t read_time = 0;
m0_time_t write_time = 0;
double time;
double fs_bw;
double client_bw;
struct m0_obj obj = {};
CHECK_BSZ_ARGS(bsz, m0bs);
cnt_per_op = m0bs / bsz;
/* open output file */
fp = fopen(filename, "w");
if (fp == NULL) {
fprintf(stderr,"error! could not open output file %s\n", filename);
return 1;
}
/* Allocate data buffers, bufvec and indexvec for write. */
rc = alloc_segs(&data, &ext, &attr, bsz, cnt_per_op);
if (rc != 0)
goto out;
/* Open object. */
m0_obj_init(&obj, &uber_realm, &id, M0_DEFAULT_LAYOUT_ID);
rc = open_entity(&obj.ob_entity);
if (rc != 0) {
fprintf(stderr, "%s(): open_entity() failed: rc=%d\n",
__func__, rc);
goto free_vecs;
}
for (; cnt > 0; cnt -= cnt_per_op) {
if (cnt < cnt_per_op)
cnt_per_op = cnt;
off += set_exts(&ext, off, bsz);
/* Copy data from the object*/
st = m0_time_now();
rc = read_data_from_object(&obj, &ext, &data, &attr);
read_time = m0_time_add(read_time,
m0_time_sub(m0_time_now(), st));
if (rc != 0) {
fprintf(stderr, "%s(): reading from object failed: rc=%d\n",
__func__, rc);
break;
}
/* Output data to file. */
st = m0_time_now();
if (write_data_to_file(fp, &data, bsz, cnt_per_op)
!= cnt_per_op) {
rc = -EIO;
break;
}
write_time = m0_time_add(write_time,
m0_time_sub(m0_time_now(), st));
/* QOS */
pthread_mutex_lock(&qos_lock);
qos_objio_signal_start();
qos_total_weight += cnt_per_op * bsz;
pthread_mutex_unlock(&qos_lock);
/* END */
}
m0_entity_fini(&obj.ob_entity);
free_vecs:
free_segs(&data, &ext, &attr);
out:
/* block */
qos_pthread_cond_wait();
fprintf(stderr,"writing to file...\n");
/* Fs will flush data back to device when closing a file. */
st = m0_time_now();
fclose(fp);
write_time = m0_time_add(write_time,
m0_time_sub(m0_time_now(), st));
if (perf && rc == 0) {
time = (double) read_time / M0_TIME_ONE_SECOND;
client_bw = off / 1000000.0 / time;
ppf("Motr I/O[ \033[0;31mMOTR: %10.4lf s %10.4lf MB/s\033[0m ]",time, client_bw);
time = (double) write_time / M0_TIME_ONE_SECOND;
fs_bw = off / 1000000.0 / time;
ppf("[ \033[0;31mOSFS: %10.4lf s %10.4lf MB/s\033[0m ]\n",time, fs_bw);
}
return rc;
}
/*
* c0appz_rm()
* delete object.
*/
int c0appz_rm(uint64_t idhi,uint64_t idlo)
{
int rc;
struct m0_obj obj = {};
struct m0_op *op = NULL;
struct m0_uint128 id;
id.u_hi = idhi;
id.u_lo = idlo;
m0_obj_init(&obj, &uber_realm, &id, M0_DEFAULT_LAYOUT_ID);
rc = open_entity(&obj.ob_entity);
if (rc < 0) {
fprintf(stderr,"error! [%d]\n", rc);
fprintf(stderr,"object not found\n");
return rc;
}
m0_entity_delete(&obj.ob_entity, &op);
m0_op_launch(&op, 1);
rc = m0_op_wait(op, M0_BITS(M0_OS_FAILED,
M0_OS_STABLE),
M0_TIME_NEVER);
m0_op_fini(op);
m0_op_free(op);
m0_entity_fini(&obj.ob_entity);
return rc;
}
int c0appz_rmach_bulk_cutoff(struct m0_rpc_link *link, uint32_t *bulk_cutoff)
{
if (link == NULL || bulk_cutoff == NULL)
return -EINVAL;
*bulk_cutoff = link->rlk_conn.c_rpc_machine->rm_bulk_cutoff;
return 0;
}
static int c0appz_spiel_prepare(struct m0_spiel *spiel)
{
struct m0_reqh *reqh = &m0_instance->m0c_reqh;
int rc;
rc = m0_spiel_init(spiel, reqh);
if (rc != 0) {
fprintf(stderr, "error! spiel initialisation failed.\n");
return rc;
}
rc = m0_spiel_cmd_profile_set(spiel, m0_conf.mc_profile);
if (rc != 0) {
fprintf(stderr, "error! spiel initialisation failed.\n");
return rc;
}
rc = m0_spiel_rconfc_start(spiel, NULL);
if (rc != 0) {
fprintf(stderr, "error! starting of rconfc failed in spiel failed.\n");
return rc;
}
return 0;
}
static void c0appz_spiel_destroy(struct m0_spiel *spiel)
{
m0_spiel_rconfc_stop(spiel);
m0_spiel_fini(spiel);
}
static bool conf_obj_is_svc(const struct m0_conf_obj *obj)
{
return m0_conf_obj_type(obj) == &M0_CONF_SERVICE_TYPE;
}
struct m0_rpc_link * c0appz_isc_rpc_link_get(struct m0_fid *svc_fid)
{
struct m0_reqh *reqh = &m0_instance->m0c_reqh;
struct m0_reqh_service_ctx *ctx;
struct m0_pools_common *pc = reqh->rh_pools;
m0_tl_for(pools_common_svc_ctx, &pc->pc_svc_ctxs, ctx) {
if (ctx->sc_type == M0_CST_ISCS &&
m0_fid_eq(&ctx->sc_fid, svc_fid))
return &ctx->sc_rlink;
} m0_tl_endfor;
return NULL;
}
/*
* Loads a library into m0d instances.
*/
int c0appz_isc_api_register(const char *libpath)
{
int rc;
struct m0_reqh *reqh = &m0_instance->m0c_reqh;
struct m0_confc *confc;
struct m0_conf_root *root;
struct m0_conf_process *proc;
struct m0_conf_service *svc;
struct m0_conf_diter it;
rc = c0appz_spiel_prepare(&spiel_inst);
if (rc != 0) {
fprintf(stderr, "error! spiel initialization failed");
return rc;
}
confc = m0_reqh2confc(reqh);
rc = m0_confc_root_open(confc, &root);
if (rc != 0) {
c0appz_spiel_destroy(&spiel_inst);
return rc;
}
rc = m0_conf_diter_init(&it, confc,
&root->rt_obj,
M0_CONF_ROOT_NODES_FID,
M0_CONF_NODE_PROCESSES_FID,
M0_CONF_PROCESS_SERVICES_FID);
if (rc != 0) {
m0_confc_close(&root->rt_obj);
c0appz_spiel_destroy(&spiel_inst);
return rc;
}
while (M0_CONF_DIRNEXT ==
(rc = m0_conf_diter_next_sync(&it, conf_obj_is_svc))) {
svc = M0_CONF_CAST(m0_conf_diter_result(&it), m0_conf_service);
if (svc->cs_type != M0_CST_ISCS)
continue;
proc = M0_CONF_CAST(m0_conf_obj_grandparent(&svc->cs_obj),
m0_conf_process);
rc = m0_spiel_process_lib_load(&spiel_inst, &proc->pc_obj.co_id,
libpath);
if (rc != 0) {
fprintf(stderr, "error! loading the library %s failed "
"for process "FID_F": rc=%d\n", libpath,
FID_P(&proc->pc_obj.co_id), rc);
m0_conf_diter_fini(&it);
m0_confc_close(&root->rt_obj);
c0appz_spiel_destroy(&spiel_inst);
return rc;
}
}
m0_conf_diter_fini(&it);
m0_confc_close(&root->rt_obj);
c0appz_spiel_destroy(&spiel_inst);
return 0;
}
int c0appz_isc_nxt_svc_get(struct m0_fid *svc_fid, struct m0_fid *nxt_fid,
enum m0_conf_service_type s_type)
{
struct m0_reqh *reqh = &m0_instance->m0c_reqh;
struct m0_reqh_service_ctx *ctx;
struct m0_pools_common *pc = reqh->rh_pools;
struct m0_fid null_fid = M0_FID0;
struct m0_fid current_fid = *svc_fid;
m0_tl_for(pools_common_svc_ctx, &pc->pc_svc_ctxs, ctx) {
if (ctx->sc_type == s_type && m0_fid_eq(¤t_fid,
&null_fid)) {
*nxt_fid = ctx->sc_fid;
return 0;
} else if (ctx->sc_type == s_type &&
m0_fid_eq(svc_fid, &ctx->sc_fid))
current_fid = null_fid;
} m0_tl_endfor;
*nxt_fid = M0_FID0;
return -ENOENT;
}
int c0appz_isc_req_prepare(struct c0appz_isc_req *req, struct m0_buf *args,
const struct m0_fid *comp_fid,
struct m0_buf *reply_buf, struct m0_fid *svc_fid,
uint32_t reply_len)
{
struct m0_fop_isc *fop_isc = &req->cir_isc_fop;
struct m0_fop *arg_fop = &req->cir_fop;
struct m0_rpc_link *link;
int rc;
req->cir_args = args;
req->cir_result = reply_buf;
fop_isc->fi_comp_id = *comp_fid;
req->cir_rpc_link = c0appz_isc_rpc_link_get(svc_fid);
if (req->cir_rpc_link == NULL) {
fprintf(stderr, "error! cannot find rpc_link for isc service "
FID_F, FID_P(svc_fid));
return -EINVAL;
}
link = req->cir_rpc_link;
m0_rpc_at_init(&fop_isc->fi_args);
rc = m0_rpc_at_add(&fop_isc->fi_args, args, &link->rlk_conn);
if (rc != 0) {
m0_rpc_at_fini(&fop_isc->fi_args);
fprintf(stderr, "error! m0_rpc_at_add() failed with %d\n", rc);
return rc;
}
/* Initialise the reply RPC AT buffer to be received.*/
m0_rpc_at_init(&fop_isc->fi_ret);
rc = m0_rpc_at_recv(&fop_isc->fi_ret, &link->rlk_conn,
reply_len, false);
if (rc != 0) {
m0_rpc_at_fini(&fop_isc->fi_args);
m0_rpc_at_fini(&fop_isc->fi_ret);
fprintf(stderr, "error! m0_rpc_at_recv() failed with %d\n", rc);
return rc;
}
m0_fop_init(arg_fop, &m0_fop_isc_fopt, fop_isc, m0_fop_release);
return rc;
}
int c0appz_isc_req_send_sync(struct c0appz_isc_req *req)
{
struct m0_fop *reply_fop;
struct m0_fop_isc_rep isc_reply;
int rc;
rc = m0_rpc_post_sync(&req->cir_fop, &req->cir_rpc_link->rlk_sess, NULL,
M0_TIME_IMMEDIATELY);
if (rc != 0) {
fprintf(stderr, "Failed to send request to "FID_F": rc=%d\n",
FID_P(&req->cir_proc), rc);
return rc;
}
reply_fop = m0_rpc_item_to_fop(req->cir_fop.f_item.ri_reply);
isc_reply = *(struct m0_fop_isc_rep *)m0_fop_data(reply_fop);
req->cir_rc = isc_reply.fir_rc;
if (req->cir_rc != 0)
fprintf(stderr, "Got error from "FID_F": rc=%d\n",
FID_P(&req->cir_proc), rc);
rc = m0_rpc_at_rep_get(&req->cir_isc_fop.fi_ret, &isc_reply.fir_ret,
req->cir_result);
if (rc != 0)
fprintf(stderr, "rpc_at_rep_get() from "FID_F" failed: rc=%d\n",
FID_P(&req->cir_proc), rc);
return req->cir_rc == 0 ? rc : req->cir_rc;
}
static void fop_fini_lock(struct m0_fop *fop)
{
struct m0_rpc_machine *mach = m0_fop_rpc_machine(fop);
m0_rpc_machine_lock(mach);
m0_fop_fini(fop);
m0_rpc_machine_unlock(mach);
}
void c0appz_isc_req_fini(struct c0appz_isc_req *req)
{
struct m0_fop *reply_fop;
reply_fop = m0_rpc_item_to_fop(req->cir_fop.f_item.ri_reply);
if (reply_fop != NULL)
m0_fop_put_lock(reply_fop);
req->cir_fop.f_item.ri_reply = NULL;
m0_rpc_at_fini(&req->cir_isc_fop.fi_args);
m0_rpc_at_fini(&req->cir_isc_fop.fi_ret);
req->cir_fop.f_data.fd_data = NULL;
fop_fini_lock(&req->cir_fop);
}
/*
* c0appz_ex()
* object exists test.
*/
int c0appz_ex(uint64_t idhi, uint64_t idlo, struct m0_obj *obj_out)
{
int rc;
struct m0_obj obj = {};
struct m0_uint128 id;
id.u_hi = idhi;
id.u_lo = idlo;
m0_obj_init(&obj, &uber_realm, &id, M0_DEFAULT_LAYOUT_ID);
rc = open_entity(&obj.ob_entity);
if (rc != 0)
return 0;
if (obj_out != NULL)
*obj_out = obj;
/* success */
return 1;
}
static int read_conf_params(int idx, const struct param params[], int n)
{
int i;
struct conf_params_to_read {
const char *name;
const char **conf_ptr;
} p[] = { { "HA_ENDPOINT_ADDR", &m0_conf.mc_ha_addr },
{ "PROFILE_FID", &m0_conf.mc_profile },
{ "LOCAL_ENDPOINT_ADDR%d", &m0_conf.mc_local_addr },
{ "LOCAL_PROC_FID%d", &m0_conf.mc_process_fid }, };
char pname[256];
for (i = 0; i < ARRAY_SIZE(p); i++) {
sprintf(pname, p[i].name, idx);
*(p[i].conf_ptr) = param_get(pname, params, n);
if (*(p[i].conf_ptr) == NULL) {
ERR("%s is not set at %s\n", pname, c0rcfile);
return -EINVAL;
}
}
return 0;
}
/*
* c0appz_addb_init()
* Application specific addb settings
*/
int c0appz_addb_init(int val)
{
m0_conf.mc_is_addb_init = val;
return 0;
}
/*
* c0appz_init()
* init client resources.
*/
int c0appz_init(int idx)
{
int rc;
int lid;
int rc_params_nr;
FILE *fp;
struct param rc_params[MAX_CONF_PARAMS] = {};
fp = fopen(c0rcfile, "r");
if (fp == NULL) {
ERR("failed to open resource file %s: %s\n", c0rcfile,