Motr  M0
fi_command.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2017-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 #undef M0_TRACE_SUBSYSTEM
24 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_OTHER
25 
26 #include "lib/trace.h"
27 #include "fis/fi_command.h"
28 #include "fis/fi_command_fops.h" /* m0_fi_command_req_fopt */
29 #include "fop/fop.h" /* m0_fop */
30 #include "rpc/rpc.h" /* m0_rpc_session */
31 #include "rpc/rpclib.h" /* m0_rpc_post_sync */
32 
45 
51 static bool fi_str_not_empty(const char *s)
52 {
53  return s != NULL && *s != '\0';
54 }
55 
56 M0_INTERNAL int m0_fi_command_post_sync(struct m0_rpc_session *sess,
57  const char *func,
58  const char *tag,
59  enum m0_fi_disp disp,
60  uint32_t num1,
61  uint32_t num2)
62 {
63  struct m0_fop *fop;
64  struct m0_fi_command_rep *rep;
65  struct m0_fi_command_req req = {
66  .fcr_func = M0_BUF_INITS((char *)func),
67  .fcr_tag = M0_BUF_INITS((char *)tag),
68  .fcr_disp = disp,
69  .fcr_num1 = num1,
70  .fcr_num2 = num2,
71  };
72  int rc;
73 
74  M0_ENTRY("func=%s, tag=%s, disp=%d", func, tag, disp);
75  M0_PRE(m0_rpc_session_validate(sess) == 0);
76  M0_PRE(_0C(fi_str_not_empty(func)) &&
78 
80  session_machine(sess));
81  if (fop == NULL)
82  return M0_ERR(-ENOMEM);
83  rc = m0_rpc_post_sync(fop, sess, NULL, 0);
84  if (rc == 0) {
86  rc = rep->fcp_rc;
87  }
88  fop->f_data.fd_data = NULL; /* protect local data from freeing */
90  return M0_RC(rc);
91 }
92 
94 #undef M0_TRACE_SUBSYSTEM
95 
96 /*
97  * Local variables:
98  * c-indentation-style: "K&R"
99  * c-basic-offset: 8
100  * tab-width: 8
101  * fill-column: 80
102  * scroll-step: 1
103  * End:
104  */
void * fd_data
Definition: fop.h:75
#define M0_PRE(cond)
#define NULL
Definition: misc.h:38
static struct io_request req
Definition: file.c:100
static uint64_t tag(uint8_t code, uint64_t id)
Definition: addb2.c:1047
struct m0_fop_type m0_fi_command_req_fopt
void * m0_fop_data(const struct m0_fop *fop)
Definition: fop.c:220
struct m0_fop_getxattr_rep * rep
Definition: dir.c:455
return M0_RC(rc)
#define M0_ENTRY(...)
Definition: trace.h:170
return M0_ERR(-EOPNOTSUPP)
struct m0_rpc_item * ri_reply
Definition: item.h:163
int m0_rpc_post_sync(struct m0_fop *fop, struct m0_rpc_session *session, const struct m0_rpc_item_ops *ri_ops, m0_time_t deadline)
Definition: rpclib.c:284
M0_INTERNAL struct m0_rpc_machine * session_machine(const struct m0_rpc_session *s)
Definition: session.c:147
#define M0_BUF_INITS(str)
Definition: buf.h:70
M0_INTERNAL int m0_fi_command_post_sync(struct m0_rpc_session *sess, const char *func, const char *tag, enum m0_fi_disp disp, uint32_t num1, uint32_t num2)
Definition: fi_command.c:56
M0_INTERNAL int m0_rpc_session_validate(struct m0_rpc_session *session)
Definition: session.c:573
struct m0_fop_data f_data
Definition: fop.h:82
#define _0C(exp)
Definition: assert.h:311
void m0_fop_put_lock(struct m0_fop *fop)
Definition: fop.c:199
static struct m0_fop * fop
Definition: item.c:57
struct m0_fop * m0_rpc_item_to_fop(const struct m0_rpc_item *item)
Definition: fop.c:346
static bool fi_str_not_empty(const char *s)
Definition: fi_command.c:51
static struct m0_addb2_source * s
Definition: consumer.c:39
struct m0_rpc_item f_item
Definition: fop.h:83
m0_fi_disp
Definition: fi_command.h:59
int32_t rc
Definition: trigger_fop.h:47
Definition: fop.h:79
struct m0_fop * m0_fop_alloc(struct m0_fop_type *fopt, void *data, struct m0_rpc_machine *mach)
Definition: fop.c:96