Motr  M0
cat.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 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 <stdlib.h>
23 #include <stdio.h>
24 #include <sys/time.h>
25 #include <getopt.h>
26 #include <libgen.h>
27 
28 #include "lib/string.h"
29 #include "lib/trace.h"
30 #include "lib/getopts.h"
31 #include "motr/client.h"
32 #include "motr/idx.h"
33 #include "motr/st/utils/helper.h"
34 
35 static struct m0_client *m0_instance = NULL;
36 static struct m0_container container;
37 static struct m0_config conf;
39 
40 extern struct m0_addb_ctx m0_addb_ctx;
41 
42 static void cat_usage(FILE *file, char *prog_name)
43 {
44  fprintf(file, "Usage: %s [OPTION]... DEST_FILE\n"
45 "Read from MOTR to DEST_FILE.\n"
46 "If no DEST_FILE is provided, then dump contents in console.\n"
47 "\n"
48 "Mandatory arguments to long options are mandatory for short options too.\n"
49 " -l, --local ADDR Local endpoint address.\n"
50 " -H, --ha ADDR HA endpoint address.\n"
51 " -p, --profile FID Profile FID.\n"
52 " -P, --process FID Process FID.\n"
53 " -o, --object FID ID of the motr object "
54  "Object id should larger than "
55  "M0_ID_APP.\n%*c The first 0x100000 ids"
56  " are reserved for use by client.\n"
57 " -s, --block-size INT Block size multiple of 4k in bytes or with "
58  "suffix b/k/m/g.\n%*c Ex: 1k=1024, "
59  "1m=1024*1024. Range: [4k-32m].\n"
60 " -c, --block-count INT Number of blocks (>0) to copy, can give with "
61  "suffix b/k/m/g/K/M/G.\n%*c Ex: 1k=1024, "
62  "1m=1024*1024, 1K=1000 1M=1000*1000.\n"
63 " -L, --layout-id INT Layout ID, Range: [1-14].\n"
64 " -v, --pver FID Pool version fid.\n"
65 " -e, --enable-locks Enables acquiring and releasing RW locks "
66  "before and after performing IO.\n"
67 " -b, --blocks-per-io INT Number of blocks per IO (>=0). \n%*c "
68  "Default=100 if 0 or nothing is provided.\n"
69 " -r, --read-verify Verify parity after reading the data.\n"
70 " -S, --msg_size INT Max RPC msg size 64k i.e 65536\n"
71  "%*c Note: this should match with m0d's current "
72  "rpc msg size\n"
73 " -q, --min_queue INT Minimum length of the receive queue i.e 16\n"
74 " -O, --offset INT Updates the exisiting object from given "
75  "offset.\n%*c Default=0 if not provided. "
76  "Offset should be multiple of 4k.\n"
77 " -N, --no-hole Report read error on hole in object\n"
78 " -h, --help Shows this help text and exit.\n"
79 , prog_name, WIDTH, ' ', WIDTH, ' ', WIDTH, ' ', WIDTH, ' ', WIDTH, ' ',
80 WIDTH, ' ');
81 }
82 
83 int main(int argc, char **argv)
84 {
85  struct m0_utility_param cat_param;
86  int rc;
87  char *dest_fname = NULL;
88 
89  m0_utility_args_init(argc, argv, &cat_param,
90  &dix_conf, &conf, &cat_usage);
91 
92  fprintf(stderr, "pver is : "FID_F "\n", FID_P(&cat_param.cup_pver));
93 
95  if (rc < 0) {
96  fprintf(stderr, "init failed! rc = %d\n", rc);
97  exit(EXIT_FAILURE);
98  }
99 
100  if (argv[optind] != NULL)
101  dest_fname = strdup(argv[optind]);
102 
103  rc = m0_read(&container, cat_param.cup_id, dest_fname,
104  cat_param.cup_block_size, cat_param.cup_block_count,
105  cat_param.cup_offset,
106  cat_param.cup_blks_per_io, cat_param.cup_take_locks,
107  cat_param.flags, &cat_param.cup_pver);
108  if (rc < 0) {
109  fprintf(stderr, "m0_read failed! rc = %d\n", rc);
110  }
111 
113 
114  return rc == 0 ? 0 : 1;
115 }
116 
117 /*
118  * Local variables:
119  * c-indentation-style: "K&R"
120  * c-basic-offset: 8
121  * tab-width: 8
122  * fill-column: 80
123  * scroll-step: 1
124  * End:
125  */
int optind
#define NULL
Definition: misc.h:38
struct m0_file file
Definition: di.c:36
uint64_t cup_block_size
Definition: helper.h:66
Definition: conf.py:1
M0_INTERNAL void client_init(struct sim *s, struct client_conf *conf)
Definition: client.c:148
bool cup_take_locks
Definition: helper.h:70
uint64_t cup_block_count
Definition: helper.h:67
int m0_utility_args_init(int argc, char **argv, struct m0_utility_param *params, struct m0_idx_dix_config *dix_conf, struct m0_config *conf, void(*utility_usage)(FILE *, char *))
Definition: helper.c:915
uint32_t flags
Definition: helper.h:76
struct m0_uint128 cup_id
Definition: helper.h:65
uint64_t cup_offset
Definition: helper.h:69
static void cat_usage(FILE *file, char *prog_name)
Definition: cat.c:42
#define FID_P(f)
Definition: fid.h:77
int cup_blks_per_io
Definition: helper.h:73
Definition: helper.h:53
static struct m0_container container
Definition: cat.c:36
M0_INTERNAL void client_fini(struct client_conf *conf)
Definition: client.c:177
struct m0_fid cup_pver
Definition: helper.h:75
int m0_read(struct m0_container *container, struct m0_uint128 id, char *dest, uint32_t block_size, uint32_t block_count, uint64_t offset, int blks_per_io, bool take_locks, uint32_t flags, struct m0_fid *read_pver)
Definition: helper.c:466
static struct m0_idx_dix_config dix_conf
Definition: cat.c:38
int32_t rc
Definition: trigger_fop.h:47
struct m0_addb_ctx m0_addb_ctx
#define FID_F
Definition: fid.h:75
int main(int argc, char **argv)
Definition: cat.c:83