Motr  M0
unlink.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 <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 /* Client parameters */
34 
35 static struct m0_client *m0_instance = NULL;
36 static struct m0_container container;
37 static struct m0_config conf;
39 
40 static void unlink_usage(FILE *file, char *prog_name)
41 {
42  fprintf(file, "Usage: %s [OPTION]...\n"
43 "Delete from MOTR.\n"
44 "\n"
45 "Mandatory arguments to long options are mandatory for short options too.\n"
46 " -l, --local ADDR local endpoint address\n"
47 " -H, --ha ADDR HA endpoint address\n"
48 " -p, --profile FID profile FID\n"
49 " -P, --process FID process FID\n"
50 " -o, --object FID ID of the motr object. "
51  "Object id should larger than "
52  "M0_ID_APP.\n%*c The first 0x100000 "
53  "ids are reserved for use by client.\n"
54 " -L, --layout-id INT layout ID, range: [1-14]\n"
55 " -n, --n_obj INT No of objects to unlink\n"
56 " -e, --enable-locks enables acquiring and releasing RW locks "
57  "before and after performing IO.\n"
58 " -S, --msg_size INT Max RPC msg size 64k i.e 65536\n"
59  "%*c Note: this should match with m0d's "
60  "current rpc msg size\n"
61 " -q, --min_queue INT Minimum length of the receive queue i.e 16\n"
62 " -h, --help shows this help text and exit\n"
63 , prog_name, WIDTH, ' ', WIDTH, ' ');
64 }
65 
66 
67 int main(int argc, char **argv)
68 {
69  struct m0_utility_param ulink_params;
70  struct m0_uint128 b_id = M0_ID_APP;
71  int i = 0;
72  int rc;
73 
74  m0_utility_args_init(argc, argv, &ulink_params,
76 
78  if (rc < 0) {
79  fprintf(stderr, "init failed! rc = %d\n", rc);
80  exit(EXIT_FAILURE);
81  }
82 
83  /* Setting up base object id to object id received */
84  b_id.u_lo = ulink_params.cup_id.u_lo;
85  for (i = 0; i < ulink_params.cup_n_obj; ++i) {
86  ulink_params.cup_id.u_lo = b_id.u_lo + i;
87  rc = m0_unlink(&container, ulink_params.cup_id,
88  ulink_params.cup_take_locks);
89  if (rc != 0)
90  fprintf(stderr, "Failed to unlink obj id: %" PRIu64 ", "
91  "rc: %d\n", ulink_params.cup_id.u_lo, rc);
92  }
93 
95 
96  return rc;
97 }
98 
99 /*
100  * Local variables:
101  * c-indentation-style: "K&R"
102  * c-basic-offset: 8
103  * tab-width: 8
104  * fill-column: 80
105  * scroll-step: 1
106  * End:
107  */
#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
#define PRIu64
Definition: types.h:58
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
struct m0_uint128 cup_id
Definition: helper.h:65
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 m0_unlink(struct m0_container *container, struct m0_uint128 id, bool take_locks)
Definition: helper.c:683
int32_t rc
Definition: trigger_fop.h:47