Motr  M0
rwlock_helper.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Seagate Technology LLC and/or its Affiliates
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * For any questions about this software or licensing,
17  * please email opensource@seagate.com or cortx-questions@seagate.com.
18  *
19  */
20 
21 #include <unistd.h>
22 
23 #include "lib/trace.h"
24 #include "lib/user_space/getopts.h"
25 #include "motr/init.h"
26 #include "module/instance.h"
27 #include "rm/rm.h"
28 #include "rm/rm_rwlock.h"
29 #include "rm/rm_service.h"
30 #include "rpc/rpclib.h" /* m0_rpc_client_connect */
31 #include "rm/st/wlock_helper.h"
32 
33 int main(int argc, char **argv)
34 {
35  static struct m0 instance;
36  struct m0_net_domain domain;
37  struct m0_net_buffer_pool buffer_pool;
38  struct m0_reqh reqh;
39  struct m0_reqh_service *rm_service;
40  struct m0_fid process_fid = M0_FID_TINIT('r', 1, 5);
41  struct m0_fid rms_fid = M0_FID_TINIT('s', 3, 10);
42  struct m0_rpc_machine rpc_mach;
43  const char *rm_ep;
44  const char *c_ep;
45  int delay;
46  int rc;
47 
48  rc = m0_init(&instance);
49  M0_SET0(&domain);
50  if (rc != 0)
51  return M0_ERR(rc);
52  M0_SET0(&domain);
53  rc = M0_GETOPTS("m0rwlock", argc, argv,
54  M0_STRINGARG('s',
55  "server endpoint (RM)",
56  LAMBDA(void, (const char *string) {
57  rm_ep = string; })),
58  M0_STRINGARG('c',
59  "client endpoint",
60  LAMBDA(void, (const char *string) {
61  c_ep = string; })),
62  M0_FORMATARG('d',
63  "delay between write lock get and put",
64  "%i", &delay));
65  if (rc != 0)
66  return M0_ERR(rc);
67  printf("s %s, c %s, d %d\n", rm_ep, c_ep, delay);
69  if (rc != 0)
70  goto m0_fini;
71  rc = m0_rpc_net_buffer_pool_setup(&domain, &buffer_pool, 2, 1);
72  if (rc != 0)
73  goto domain_fini;
74  rc = M0_REQH_INIT(&reqh,
75  .rhia_dtm = (void *)1,
76  .rhia_mdstore = (void *)1,
77  .rhia_fid = &process_fid);
78  if (rc != 0)
79  goto buffer_cleanup;
82  &rms_fid);
83  if (rc != 0)
84  goto reqh_fini;
85  rc = m0_rpc_machine_init(&rpc_mach, &domain, c_ep, &reqh, &buffer_pool,
86  ~(uint32_t)0, 1 << 17, 2);
87  if (rc != 0)
88  goto services_terminate;
89  rc = rm_write_lock_get(&rpc_mach, rm_ep);
90  if (rc != 0)
91  goto mach_fini;
92  else
93  m0_console_printf("Got write lock\n");
94  sleep(delay);
96  m0_console_printf("Released write lock\n");
97 mach_fini:
98  m0_rpc_machine_fini(&rpc_mach);
99 services_terminate:
101 reqh_fini:
102  m0_reqh_fini(&reqh);
103 buffer_cleanup:
104  m0_rpc_net_buffer_pool_cleanup(&buffer_pool);
105 domain_fini:
107 m0_fini:
108  m0_fini();
109  return M0_RC(rc);
110 }
M0_INTERNAL int rm_write_lock_get(struct m0_rpc_machine *rpc_mach, const char *rm_ep)
Definition: wlock_helper.c:195
#define M0_GETOPTS(progname, argc, argv,...)
Definition: getopts.h:169
void mach_fini(struct m0_addb2_mach *m)
Definition: common.c:78
void m0_rpc_machine_fini(struct m0_rpc_machine *machine)
Definition: rpc_machine.c:233
M0_INTERNAL void m0_reqh_services_terminate(struct m0_reqh *reqh)
Definition: reqh.c:675
void m0_net_domain_fini(struct m0_net_domain *dom)
Definition: domain.c:71
#define NULL
Definition: misc.h:38
void m0_fini(void)
Definition: init.c:318
#define M0_REQH_INIT(reqh,...)
Definition: reqh.h:262
void m0_console_printf(const char *fmt,...)
Definition: trace.c:801
static int delay
Definition: dump.c:174
int main(int argc, char **argv)
Definition: rwlock_helper.c:33
int m0_init(struct m0 *instance)
Definition: init.c:310
#define M0_SET0(obj)
Definition: misc.h:64
M0_INTERNAL void m0_reqh_fini(struct m0_reqh *reqh)
Definition: reqh.c:320
return M0_RC(rc)
#define M0_STRINGARG(ch, desc, func)
Definition: getopts.h:207
return M0_ERR(-EOPNOTSUPP)
#define LAMBDA(T,...)
Definition: thread.h:153
struct m0_reqh_service * rm_service
Definition: rpc_machine.h:131
#define M0_FID_TINIT(type, container, key)
Definition: fid.h:90
#define M0_FORMATARG(ch, desc, fmt, ptr)
Definition: getopts.h:218
M0_INTERNAL int m0_rpc_net_buffer_pool_setup(struct m0_net_domain *ndom, struct m0_net_buffer_pool *app_pool, uint32_t bufs_nr, uint32_t tm_nr)
Definition: rpc.c:229
Definition: instance.h:80
M0_INTERNAL int m0_rpc_machine_init(struct m0_rpc_machine *machine, struct m0_net_domain *net_dom, const char *ep_addr, struct m0_reqh *reqh, struct m0_net_buffer_pool *receive_pool, uint32_t colour, m0_bcount_t msg_size, uint32_t queue_len)
Definition: rpc_machine.c:123
struct m0_net_xprt * m0_net_xprt_default_get(void)
Definition: net.c:151
Definition: reqh.h:94
M0_INTERNAL int m0_reqh_service_setup(struct m0_reqh_service **out, struct m0_reqh_service_type *stype, struct m0_reqh *reqh, struct m0_reqh_context *rctx, const struct m0_fid *fid)
Definition: reqh_service.c:565
struct m0_reqh_service_type m0_rms_type
Definition: rm_service.c:69
M0_INTERNAL void m0_reqh_start(struct m0_reqh *reqh)
Definition: reqh.c:711
struct m0_reqh reqh
Definition: rm_foms.c:48
int m0_net_domain_init(struct m0_net_domain *dom, const struct m0_net_xprt *xprt)
Definition: domain.c:36
Definition: fid.h:38
M0_INTERNAL void rm_write_lock_put()
Definition: wlock_helper.c:186
static struct m0 instance
Definition: main.c:78
static void reqh_fini(void)
Definition: ms_fom_ut.c:351
void m0_rpc_net_buffer_pool_cleanup(struct m0_net_buffer_pool *app_pool)
Definition: rpc.c:264
static struct m0_layout_domain domain
Definition: layout.c:49
int32_t rc
Definition: trigger_fop.h:47
static const char * process_fid
Definition: idx_dix.c:73