Motr  M0
reglib.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2021 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 #include <stdio.h>
22 #include <unistd.h> /* getopt */
23 #include "motr/client_internal.h" /* m0_client */
24 #include "util.h"
25 
26 char *prog;
27 
28 const char *help_str = "\
29 \n\
30 Usage: %s OPTIONS libpath\n\
31 \n\
32  -e <addr> endpoint address\n\
33  -x <addr> ha-agent (hax) endpoint address\n\
34  -f <fid> process fid\n\
35  -p <fid> profile fid\n\
36 \n";
37 
38 static void usage()
39 {
40  fprintf(stderr, help_str, prog);
41  exit(1);
42 }
43 
44 int main(int argc, char **argv)
45 {
46  int rc;
47  int opt;
48  struct m0_client *cinst = NULL;
49  struct m0_config conf = {};
50 
51  prog = basename(strdup(argv[0]));
52 
53  while ((opt = getopt(argc, argv, ":he:x:f:p:")) != -1) {
54  switch (opt) {
55  case 'e':
56  conf.mc_local_addr = optarg;
57  break;
58  case 'x':
59  conf.mc_ha_addr = optarg;
60  break;
61  case 'f':
62  conf.mc_process_fid = optarg;
63  break;
64  case 'p':
65  conf.mc_profile = optarg;
66  break;
67  case 'h':
68  usage();
69  break;
70  default:
71  ERR("unknown option: %c\n", optopt);
72  usage();
73  break;
74  }
75  }
76 
77  if (conf.mc_local_addr == NULL || conf.mc_ha_addr == NULL ||
78  conf.mc_process_fid == NULL || conf.mc_profile == NULL) {
79  ERR("mandatory parameter is missing\n");
80  usage();
81  }
82  if (argc - optind < 1)
83  usage();
84 
85  rc = isc_init(&conf, &cinst);
86  if (rc != 0) {
87  ERR("isc_init() failed: %d\n", rc);
88  return 2;
89  }
90 
92  &cinst->m0c_reqh);
93  if (rc != 0)
94  ERR("loading of library failed: rc=%d\n", rc);
95 
96  isc_fini(cinst);
97 
98  if (rc == 0)
99  printf("%s success\n", prog);
100 
101  return rc != 0 ? 1 : 0;
102 }
103 
104 /*
105  * Local variables:
106  * c-indentation-style: "K&R"
107  * c-basic-offset: 8
108  * tab-width: 8
109  * fill-column: 80
110  * scroll-step: 1
111  * End:
112  */
static void usage()
Definition: reglib.c:38
int optind
struct m0_fid m0c_profile_fid
#define NULL
Definition: misc.h:38
#define ERR(_fmt,...)
Definition: util.h:129
Definition: conf.py:1
char * optarg
char * prog
Definition: reglib.c:26
struct m0_reqh m0c_reqh
int main(int argc, char **argv)
Definition: reglib.c:44
M0_INTERNAL int m0_isc_lib_register(const char *libpath, struct m0_fid *profile, struct m0_reqh *reqh)
Definition: isc.c:730
static struct m0_client cinst
Definition: sync.c:84
int isc_init(struct m0_config *conf, struct m0_client **cinst)
Definition: util.c:247
void isc_fini(struct m0_client *cinst)
Definition: util.c:281
int optopt
int32_t rc
Definition: trigger_fop.h:47
const char * help_str
Definition: reglib.c:28