Motr  M0
truncate.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 "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 trunc_usage(FILE *file, char *prog_name)
43 {
44  fprintf(file, "Usage: %s [OPTION]...\n"
45 "Truncate MOTR object to a given size.\n"
46 "\n"
47 "Mandatory arguments to long options are mandatory for short options too.\n"
48 " -l, --local ADDR Local endpoint address.\n"
49 " -H, --ha ADDR HA endpoint address.\n"
50 " -p, --profile FID Profile FID.\n"
51 " -P, --process FID Process FID.\n"
52 " -o, --object FID ID of the motr object. "
53  "Object id should larger than "
54  "M0_ID_APP.\n%*c The first 0x100000 ids"
55  " are reserved for use by client.\n"
56 " -s, --block-size INT Block size multiple of 4k in bytes or with "
57  "suffix b/k/m/g.\n%*c Ex: 1k=1024, "
58  "1m=1024*1024. Range: [4k-32m].\n"
59 " -c, --block-count INT Number of blocks (>0) to copy, can give with "
60  "suffix b/k/m/g/K/M/G.\n%*c Ex: 1k=1024, "
61  "1m=1024*1024, 1K=1000 1M=1000*1000.\n"
62 " -t, --trunc-len INT Number of blocks (>0) to punch out,"
63  "can give with suffix b/k/m/g/K/M/G.\n"
64 " -L, --layout-id INT Layout ID. Range: [1-14].\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). Default=100 "
68  "if 0 or nothing is provided.\n"
69 " -S, --msg_size INT Max RPC msg size 64k i.e 65536\n"
70  "%*c Note: this should match with m0d's current "
71  "rpc msg size\n"
72 " -q, --min_queue INT Minimum length of the receive queue i.e 16\n"
73 
74 " -h, --help Shows this help text and exit.\n"
75 , prog_name, WIDTH, ' ', WIDTH, ' ', WIDTH, ' ', WIDTH, ' ');
76 }
77 
78 int main(int argc, char **argv)
79 {
80  int rc;
81  struct m0_utility_param trunc_params;
82 
83  m0_utility_args_init(argc, argv, &trunc_params, &dix_conf,
84  &conf, &trunc_usage);
85 
86  /* Read Verify is only for m0cat */
87  conf.mc_is_read_verify = false;
88 
90  if (rc < 0) {
91  fprintf(stderr, "init failed! rc = %d\n", rc);
92  exit(EXIT_FAILURE);
93  }
94 
95  rc = m0_truncate(&container, trunc_params.cup_id,
96  trunc_params.cup_block_size,
97  trunc_params.cup_block_count,
98  trunc_params.cup_trunc_len,
99  trunc_params.cup_blks_per_io,
100  trunc_params.cup_take_locks);
101  if (rc < 0) {
102  fprintf(stderr, "m0_truncate failed! rc = %d\n", rc);
103  }
104 
106 
107  return rc;
108 }
109 
110 /*
111  * Local variables:
112  * c-indentation-style: "K&R"
113  * c-basic-offset: 8
114  * tab-width: 8
115  * fill-column: 80
116  * scroll-step: 1
117  * End:
118  */
uint64_t cup_trunc_len
Definition: helper.h:71
#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
static void trunc_usage(FILE *file, char *prog_name)
Definition: truncate.c:42
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 main(int argc, char **argv)
Definition: truncate.c:78
static struct m0_container container
Definition: truncate.c:36
struct m0_uint128 cup_id
Definition: helper.h:65
int cup_blks_per_io
Definition: helper.h:73
static struct m0_idx_dix_config dix_conf
Definition: truncate.c:38
Definition: helper.h:53
M0_INTERNAL void client_fini(struct client_conf *conf)
Definition: client.c:177
int32_t rc
Definition: trigger_fop.h:47
int m0_truncate(struct m0_container *container, struct m0_uint128 id, uint32_t block_size, uint32_t trunc_count, uint32_t trunc_len, int blks_per_io, bool take_locks)
Definition: helper.c:607
struct m0_addb_ctx m0_addb_ctx