Motr  M0
touch.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 "motr/client.h"
30 #include "motr/idx.h"
31 #include "motr/st/utils/helper.h"
32 
33 static struct m0_client *m0_instance = NULL;
34 static struct m0_container container;
35 static struct m0_config conf;
37 
38 static void touch_usage(FILE *file, char *prog_name)
39 {
40  fprintf(file, "Usage: %s [OPTION]...\n"
41 "Create empty MOTR object.\n"
42 "\n"
43 "Mandatory arguments to long options are mandatory for short options too.\n"
44 " -l, --local ADDR Local endpoint address.\n"
45 " -H, --ha ADDR HA endpoint address.\n"
46 " -p, --profile FID Profile FID.\n"
47 " -P, --process FID Process FID.\n"
48 " -o, --object FID ID of the motr object. "
49  "Object id should larger than "
50  "M0_ID_APP.\n%*c The first 0x100000 "
51  "ids are reserved for use by client.\n"
52 " -L, --layout-id INT Layout ID, Range:[1-14].\n"
53 " -n, --n_obj INT Number of objects to touch.\n"
54 " -S, --msg_size INT Max RPC msg size 64k i.e 65536\n"
55  "%*c Note: this should match with m0d's "
56  "current rpc msg size\n"
57 " -q, --min_queue INT Minimum length of the receive queue i.e 16\n"
58 
59 " -e, --enable-locks Enables acquiring and releasing RW locks "
60  "before and after performing IO.\n"
61 " -h, --help Shows this help text and exit.\n"
62 , prog_name, WIDTH, ' ', WIDTH, ' ');
63 }
64 
65 
66 int main(int argc, char **argv)
67 {
68  struct m0_utility_param touch_params;
69  struct m0_uint128 b_id = M0_ID_APP;
70  int i = 0;
71  int rc;
72 
73  m0_utility_args_init(argc, argv, &touch_params,
75 
76  /* Read Verify is only for m0cat */
77  conf.mc_is_read_verify = false;
78 
80  if (rc < 0) {
81  fprintf(stderr, "init failed! rc = %d\n", rc);
82  exit(EXIT_FAILURE);
83  }
84 
85  /* Setting up base object id to object id received */
86  b_id.u_lo = touch_params.cup_id.u_lo;
87  for (i = 0; i < touch_params.cup_n_obj; ++i) {
88  touch_params.cup_id.u_lo = b_id.u_lo + i;
89  rc = touch(&container, touch_params.cup_id,
90  touch_params.cup_take_locks);
91  if (rc != 0) {
92  if (rc == -EEXIST) {
93  fprintf(stderr, "Object id: " U128X_F "exists. "
94  "rc = %d\n",
95  U128_P(&touch_params.cup_id),
96  rc);
97  } else {
98  fprintf(stderr, "Failed to touch Object id: "
99  U128X_F "rc = %d\n",
100  U128_P(&touch_params.cup_id),
101  rc);
102  }
103 
104  }
105  }
106 
108 
109  return rc;
110 }
111 
112 /*
113  * Local variables:
114  * c-indentation-style: "K&R"
115  * c-basic-offset: 8
116  * tab-width: 8
117  * fill-column: 80
118  * scroll-step: 1
119  * End:
120  */
static void touch_usage(FILE *file, char *prog_name)
Definition: touch.c:38
#define NULL
Definition: misc.h:38
struct m0_file file
Definition: di.c:36
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
const struct m0_uint128 M0_ID_APP
Definition: client.c:92
int i
Definition: dir.c:1033
static struct m0_idx_dix_config dix_conf
Definition: touch.c:36
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
int touch(struct m0_container *container, struct m0_uint128 id, bool take_locks)
Definition: helper.c:310
#define U128_P(x)
Definition: types.h:45
struct m0_uint128 cup_id
Definition: helper.h:65
#define U128X_F
Definition: types.h:42
static struct m0_container container
Definition: touch.c:34
Definition: helper.h:53
M0_INTERNAL void client_fini(struct client_conf *conf)
Definition: client.c:177
uint64_t u_lo
Definition: types.h:37
int main(int argc, char **argv)
Definition: touch.c:66
int32_t rc
Definition: trigger_fop.h:47