Motr  M0
console_mesg.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2011-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 
23 #include <stdio.h> /* fprintf */
24 
25 #include "lib/errno.h" /* ENOTSUP */
26 #include "lib/misc.h" /* M0_BITS */
27 
28 #include "console/console_mesg.h"
29 #include "console/console_it.h" /* m0_cons_fop_fields_show */
30 
31 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_CONSOLE
32 #include "lib/trace.h"
33 
34 M0_INTERNAL void m0_cons_fop_name_print(const struct m0_fop_type *ftype)
35 {
36  printf("%.2d %s\n", ftype->ft_rpc_item_type.rit_opcode, ftype->ft_name);
37 }
38 
39 M0_INTERNAL int m0_cons_fop_send(struct m0_fop *fop,
40  struct m0_rpc_session *session,
41  m0_time_t resend_interval,
42  uint64_t nr_sent_max)
43 {
44  struct m0_rpc_item *item;
45  int rc;
46 
47  M0_PRE(fop != NULL && session != NULL);
48 
49  item = &fop->f_item;
50  item->ri_deadline = 0;
53  item->ri_nr_sent_max = nr_sent_max;
54  item->ri_resend_interval = resend_interval;
55 
56  rc = m0_rpc_post(item);
57  if (rc == 0) {
59  if (rc != 0)
60  fprintf(stderr, "Error while waiting for reply: %d\n",
61  rc);
62  } else {
63  fprintf(stderr, "m0_rpc_post failed!\n");
64  }
65  return M0_RC(rc);
66 }
67 
68 M0_INTERNAL int m0_cons_fop_show(struct m0_fop_type *fopt)
69 {
70  struct m0_fop *fop;
71  int rc;
72  struct m0_rpc_machine mach;
73 
74  m0_sm_group_init(&mach.rm_sm_grp);
75  fop = m0_fop_alloc(fopt, NULL, &mach);
76  if (fop == NULL) {
77  fprintf(stderr, "FOP allocation failed\n");
78  return M0_ERR(-ENOMEM);
79  }
80 
82 
84  m0_sm_group_fini(&mach.rm_sm_grp);
85  return M0_RC(rc);
86 }
87 
88 M0_INTERNAL void m0_cons_fop_list_show(void)
89 {
90  struct m0_fop_type *ftype;
91 
92  fprintf(stdout, "List of FOP's: \n");
93  ftype = NULL;
94  while ((ftype = m0_fop_type_next(ftype)) != NULL)
96 }
97 
98 #undef M0_TRACE_SUBSYSTEM
99 
100 /*
101  * Local variables:
102  * c-indentation-style: "K&R"
103  * c-basic-offset: 8
104  * tab-width: 8
105  * fill-column: 80
106  * scroll-step: 1
107  * End:
108  */
M0_INTERNAL int m0_rpc_post(struct m0_rpc_item *item)
Definition: rpc.c:63
uint32_t rit_opcode
Definition: item.h:474
m0_time_t ri_resend_interval
Definition: item.h:144
#define M0_PRE(cond)
enum m0_rpc_item_priority ri_prio
Definition: item.h:133
#define NULL
Definition: misc.h:38
const m0_time_t M0_TIME_NEVER
Definition: time.c:108
uint64_t m0_time_t
Definition: time.h:37
static struct m0_addb2_mach * mach
Definition: storage.c:42
static struct m0_rpc_session session
Definition: formation2.c:38
static struct m0_rpc_item * item
Definition: item.c:56
int m0_rpc_item_wait_for_reply(struct m0_rpc_item *item, m0_time_t timeout)
Definition: item.c:824
M0_INTERNAL void m0_sm_group_fini(struct m0_sm_group *grp)
Definition: sm.c:65
M0_INTERNAL struct m0_fop_type * m0_fop_type_next(struct m0_fop_type *ftype)
Definition: fop.c:296
return M0_RC(rc)
M0_INTERNAL int m0_cons_fop_send(struct m0_fop *fop, struct m0_rpc_session *session, m0_time_t resend_interval, uint64_t nr_sent_max)
Builds and send FOP using rpc_post and waits for reply.
Definition: console_mesg.c:39
return M0_ERR(-EOPNOTSUPP)
const char * ft_name
Definition: fop.h:225
M0_INTERNAL int m0_cons_fop_fields_show(struct m0_fop *fop)
Iterate over FOP fields and prints the names.
Definition: console_it.c:277
M0_INTERNAL void m0_sm_group_init(struct m0_sm_group *grp)
Definition: sm.c:53
uint64_t ri_nr_sent_max
Definition: item.h:146
M0_INTERNAL int m0_cons_fop_show(struct m0_fop_type *fopt)
Iterate over FOP fields and print names.
Definition: console_mesg.c:68
struct m0_rpc_session * ri_session
Definition: item.h:147
void m0_fop_put_lock(struct m0_fop *fop)
Definition: fop.c:199
static struct m0_fop * fop
Definition: item.c:57
struct m0_rpc_item_type ft_rpc_item_type
Definition: fop.h:235
M0_INTERNAL void m0_cons_fop_list_show(void)
Helper function to print list of FOPs.
Definition: console_mesg.c:88
M0_INTERNAL void m0_cons_fop_name_print(const struct m0_fop_type *ftype)
Definition: console_mesg.c:34
struct m0_rpc_item f_item
Definition: fop.h:83
int32_t rc
Definition: trigger_fop.h:47
Definition: fop.h:79
m0_time_t ri_deadline
Definition: item.h:141
struct m0_fop * m0_fop_alloc(struct m0_fop_type *fopt, void *data, struct m0_rpc_machine *mach)
Definition: fop.c:96