Motr  M0
cc_cp_cat.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2019-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 #include <getopt.h>
23 
24 #include "lib/memory.h" /* m0_free() */
25 #include "lib/trace.h"
26 #include "motr/client_internal.h"
27 #include "motr/st/utils/helper.h"
28 
29 static struct m0_client *instance = NULL;
30 static struct m0_container container;
31 static struct m0_config conf;
33 static struct m0_cc_io_args writer_args;
34 static struct m0_cc_io_args reader_args;
35 
36 extern struct m0_addb_ctx m0_addb_ctx;
37 
39 {
40  m0_write_cc(args->cia_container, args->cia_files,
41  args->cia_id, &args->cia_index, args->cia_block_size,
42  args->cia_block_count);
43 }
44 
46 {
47  m0_read_cc(args->cia_container, args->cia_id,
48  args->cia_files, &args->cia_index, args->cia_block_size,
49  args->cia_block_count);
50 }
51 
52 static void mt_io(struct m0_thread *writer_t,
54  struct m0_thread *reader_t,
56  int writer_numb, int reader_numb)
57 {
58  int i;
59 
60  for (i = 0; i < writer_numb; ++i) {
61  M0_THREAD_INIT(&writer_t[i], struct m0_cc_io_args *, NULL,
63  "Writer: %d", i);
64  }
65 
66  for (i = 0; i < reader_numb; ++i) {
67  M0_THREAD_INIT(&reader_t[i], struct m0_cc_io_args *, NULL,
69  "Reader: %d", i);
70  }
71 
72  for (i = 0; i < writer_numb; ++i) {
73  m0_thread_join(&writer_t[i]);
74  }
75 
76  for (i = 0; i < reader_numb; ++i) {
77  m0_thread_join(&reader_t[i]);
78  }
79 }
80 
81 static void usage(FILE *file, char *prog_name)
82 {
83  fprintf(file, "Usage: %s [OPTION]... SOURCE... DESTINATION...\n"
84 "Launch multithreaded concurrent Read/Write\n"
85 "\n"
86 "Mandatory arguments to long options are mandatory for short options too.\n"
87 " -l, --local ADDR local endpoint address\n"
88 " -H, --ha ADDR HA endpoint address\n"
89 " -p, --profile FID profile FID\n"
90 " -P, --process FID process FID\n"
91 " -o, --object FID ID of the motr object\n"
92 " -W, --writer_numb INT number of writer threads\n"
93 " -R, --reader_numb INT number of reader threads\n"
94 " -s, --block-size INT block size multiple of 4k in bytes or " \
95  "with suffix b/k/m/g Ex: 1k=1024, " \
96  "1m=1024*1024\n"
97 " -c, --block-count INT number of blocks to copy, can give with " \
98  "suffix b/k/m/g/K/M/G. Ex: 1k=1024, " \
99  "1m=1024*1024, 1K=1000 1M=1000*1000\n"
100 " -r, --read-verify verify parity after reading the data\n"
101 " -h, --help shows this help text and exit\n"
102 , prog_name);
103 }
104 
105 int main(int argc, char **argv)
106 {
107  int rc;
108  struct m0_uint128 id = M0_ID_APP;
109  struct m0_thread *writer_t;
110  struct m0_thread *reader_t;
111  char **dest_fnames = NULL;
112  char **src_fnames = NULL;
113  uint32_t block_size = 0;
114  uint32_t block_count = 0;
115  int c;
116  int i;
117  int option_index = 0;
118  int writer_numb = 0;
119  int reader_numb = 0;
120 
121  static struct option l_opts[] = {
122  {"local", required_argument, NULL, 'l'},
123  {"ha", required_argument, NULL, 'H'},
124  {"profile", required_argument, NULL, 'p'},
125  {"process", required_argument, NULL, 'P'},
126  {"object", required_argument, NULL, 'o'},
127  {"writer-numb", required_argument, NULL, 'W'},
128  {"reader-numb", required_argument, NULL, 'R'},
129  {"block-size", required_argument, NULL, 's'},
130  {"block-count", required_argument, NULL, 'c'},
131  {"read-verify", no_argument, NULL, 'r'},
132  {"help", no_argument, NULL, 'h'},
133  {0, 0, 0, 0 }};
134 
135  while ((c = getopt_long(argc, argv, ":l:H:p:P:o:W:R:s:c:rh", l_opts,
136  &option_index)) != -1) {
137  switch (c) {
138  case 'l': conf.mc_local_addr = optarg;
139  continue;
140  case 'H': conf.mc_ha_addr = optarg;
141  continue;
142  case 'p': conf.mc_profile = optarg;
143  continue;
144  case 'P': conf.mc_process_fid = optarg;
145  continue;
146  case 'o': id.u_lo = atoi(optarg);
147  continue;
148  case 'W': writer_numb = atoi(optarg);
149  continue;
150  case 'R': reader_numb = atoi(optarg);
151  continue;
152  case 's': block_size = atoi(optarg);
153  continue;
154  case 'c': block_count = atoi(optarg);
155  continue;
156  case 'r': conf.mc_is_read_verify = true;
157  continue;
158  case 'h': usage(stderr, basename(argv[0]));
159  exit(EXIT_FAILURE);
160  case '?': fprintf(stderr, "Unsupported option '%c'\n",
161  optopt);
162  usage(stderr, basename(argv[0]));
163  exit(EXIT_FAILURE);
164  case ':': fprintf(stderr, "No argument given for '%c'\n",
165  optopt);
166  usage(stderr, basename(argv[0]));
167  exit(EXIT_FAILURE);
168  default: fprintf(stderr, "Unsupported option '%c'\n", c);
169  }
170  }
171 
172  conf.mc_is_oostore = true;
173  conf.mc_tm_recv_queue_min_len = M0_NET_TM_RECV_QUEUE_DEF_LEN;
174  conf.mc_max_rpc_msg_size = M0_RPC_DEF_MAX_RPC_MSG_SIZE;
175  conf.mc_idx_service_conf = &dix_conf;
176  dix_conf.kc_create_meta = false;
177  conf.mc_idx_service_id = M0_IDX_DIX;
178 
180  &instance);
181  if (rc < 0) {
182  fprintf(stderr, "init failed! rc = %d\n", rc);
183  exit(EXIT_FAILURE);
184  }
185 
186  M0_ALLOC_ARR(src_fnames, writer_numb);
187  M0_ALLOC_ARR(dest_fnames, reader_numb);
188  M0_ALLOC_ARR(writer_t, writer_numb);
189  M0_ALLOC_ARR(reader_t, reader_numb);
190 
191  for (i = 0; i < writer_numb; ++i, ++optind) {
192  src_fnames[i] = strdup(argv[optind]);
193  }
194 
195  for (i = 0; i < reader_numb; ++i, ++optind) {
196  dest_fnames[i] = strdup(argv[optind]);
197  }
198 
201  writer_args.cia_block_count = block_count;
202  writer_args.cia_block_size = block_size;
203  writer_args.cia_files = src_fnames;
205 
208  reader_args.cia_block_count = block_count;
209  reader_args.cia_block_size = block_size;
210  reader_args.cia_files = dest_fnames;
212 
213  mt_io(writer_t, writer_args, reader_t, reader_args,
214  writer_numb, reader_numb);
216  for (i = 0; i < writer_numb; ++i) {
217  m0_free(src_fnames[i]);
218  m0_thread_fini(&writer_t[i]);
219  }
220 
221  for (i = 0; i < reader_numb; ++i) {
222  m0_free(dest_fnames[i]);
223  m0_thread_fini(&reader_t[i]);
224  }
225 
226  m0_free(writer_t);
227  m0_free(reader_t);
228  m0_free(src_fnames);
229  m0_free(dest_fnames);
230  return 0;
231 }
232 
233 /*
234  * Local variables:
235  * c-indentation-style: "K&R"
236  * c-basic-offset: 8
237  * tab-width: 8
238  * fill-column: 80
239  * scroll-step: 1
240  * End:
241  */
uint64_t id
Definition: cob.h:2380
int optind
#define M0_ALLOC_ARR(arr, nr)
Definition: memory.h:84
static void mt_io(struct m0_thread *writer_t, struct m0_cc_io_args writer_args, struct m0_thread *reader_t, struct m0_cc_io_args reader_args, int writer_numb, int reader_numb)
Definition: cc_cp_cat.c:52
static void writer_thread_launch(struct m0_cc_io_args *args)
Definition: cc_cp_cat.c:38
#define NULL
Definition: misc.h:38
static struct m0_container container
Definition: cc_cp_cat.c:30
int m0_thread_join(struct m0_thread *q)
Definition: kthread.c:169
struct m0_file file
Definition: di.c:36
static struct m0_cc_io_args writer_args
Definition: cc_cp_cat.c:33
static struct m0_client * instance
Definition: cc_cp_cat.c:29
struct m0_addb_ctx m0_addb_ctx
struct m0_container * cia_container
Definition: helper.h:56
Definition: idx.h:70
int cia_index
Definition: helper.h:61
Definition: conf.py:1
M0_INTERNAL void client_init(struct sim *s, struct client_conf *conf)
Definition: client.c:148
char * optarg
#define M0_THREAD_INIT(thread, TYPE, init, func, arg, namefmt,...)
Definition: thread.h:139
int m0_read_cc(struct m0_container *container, struct m0_uint128 id, char **dest, int *index, uint32_t block_size, uint32_t block_count)
Definition: helper.c:814
Definition: ub.c:49
const struct m0_uint128 M0_ID_APP
Definition: client.c:92
int main(int argc, char **argv)
Definition: cc_cp_cat.c:105
int i
Definition: dir.c:1033
uint32_t cia_block_size
Definition: helper.h:59
int m0_write_cc(struct m0_container *container, char **src, struct m0_uint128 id, int *index, uint32_t block_size, uint32_t block_count)
Definition: helper.c:741
static struct m0_idx_dix_config dix_conf
Definition: cc_cp_cat.c:32
static struct m0_addb2_callback c
Definition: consumer.c:41
static void reader_thread_launch(struct m0_cc_io_args *args)
Definition: cc_cp_cat.c:45
void m0_thread_fini(struct m0_thread *q)
Definition: thread.c:92
struct m0_uint128 cia_id
Definition: helper.h:57
char ** cia_files
Definition: helper.h:60
static void usage(FILE *file, char *prog_name)
Definition: cc_cp_cat.c:81
uint32_t cia_block_count
Definition: helper.h:58
bool kc_create_meta
Definition: idx.h:183
M0_INTERNAL void client_fini(struct client_conf *conf)
Definition: client.c:177
int optopt
void m0_free(void *data)
Definition: memory.c:146
static struct m0_cc_io_args reader_args
Definition: cc_cp_cat.c:34
int32_t rc
Definition: trigger_fop.h:47