Motr  M0
util.h
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 
22 #pragma once
23 
24 #ifndef __MOTR_ISCSERVICE_DEMO_UTIL_H__
25 #define __MOTR_ISCSERVICE_DEMO_UTIL_H__
26 
27 #include "iscservice/isc.h" /* m0_fop_isc */
28 #include "rpc/rpc_machine.h" /* M0_RPC_DEF_MAX_RPC_MSG_SIZE */
29 
30 /* Import */
31 struct m0_fid;
32 struct isc_req;
33 struct m0_buf;
34 struct m0_rpc_link;
35 struct m0_layout_io_plop;
36 struct m0_obj;
37 struct m0_config;
38 struct m0_client;
40 
45 };
46 
48 struct isc_req {
52  int cir_rc;
58  struct m0_fop cir_fop;
63 };
64 
65 extern struct m0_realm uber_realm;
66 extern struct m0_semaphore isc_sem;
67 extern struct m0_list isc_reqs;
68 
72 int isc_init(struct m0_config*, struct m0_client**);
73 void isc_fini(struct m0_client*);
74 
78 uint64_t isc_m0gs(struct m0_obj*, struct m0_client*);
79 
89 int isc_req_prepare(struct isc_req *, struct m0_buf *args,
90  const struct m0_fid *comp,
91  struct m0_layout_io_plop *iopl, uint32_t reply_len);
92 
104 int isc_req_send(struct isc_req *req);
105 
109 void isc_req_fini(struct isc_req *req);
110 
111 int alloc_segs(struct m0_bufvec *data, struct m0_indexvec *ext,
112  struct m0_bufvec *attr, uint64_t bsz, uint32_t cnt);
113 void free_segs(struct m0_bufvec *data, struct m0_indexvec *ext,
114  struct m0_bufvec *attr);
115 uint64_t set_exts(struct m0_indexvec *ext, uint64_t off, uint64_t bsz);
116 
117 extern bool m0trace_on;
118 extern int trace_level;
119 extern char *prog;
120 
121 enum {
125 };
126 
127 #define LOG(_fmt, ...) \
128  fprintf(stderr, "%s: %s():%d: "_fmt, prog, __func__, __LINE__, ##__VA_ARGS__)
129 #define ERR(_fmt, ...) if (trace_level >= LOG_ERROR) LOG(_fmt, ##__VA_ARGS__)
130 #define ERRS(_fmt, ...) if (trace_level >= LOG_ERROR) \
131  LOG(_fmt ": %s\n", ##__VA_ARGS__, strerror(errno))
132 #define DBG(_fmt, ...) if (trace_level >= LOG_DEBUG) LOG(_fmt, ##__VA_ARGS__)
133 #define DBG2(_fmt, ...) if (trace_level >= LOG_DEBUG2) LOG(_fmt, ##__VA_ARGS__)
134 
135 #define CHECK_BSZ_ARGS(bsz, m0bs) \
136  if ((bsz) < 1 || (bsz) % PAGE_SIZE) { \
137  ERR("bsz(%lu) must be multiple of %luK\n", (m0bs), PAGE_SIZE/1024); \
138  return -EINVAL; \
139  } \
140  if ((m0bs) < 1 || (m0bs) % (bsz)) { \
141  ERR("bsz(%lu) must divide m0bs(%lu)\n", (bsz), (m0bs)); \
142  return -EINVAL; \
143  }
144 
145 #endif /* __MOTR_ISCSERVICE_DEMO_UTIL_H__ */
146 
147 /*
148  * Local variables:
149  * c-indentation-style: "K&R"
150  * c-basic-offset: 8
151  * tab-width: 8
152  * fill-column: 80
153  * scroll-step: 1
154  * End:
155  */
int isc_req_prepare(struct isc_req *, struct m0_buf *args, const struct m0_fid *comp, struct m0_layout_io_plop *iopl, uint32_t reply_len)
Definition: util.c:108
int trace_level
Definition: util.c:41
uint64_t set_exts(struct m0_indexvec *ext, uint64_t off, uint64_t bsz)
Definition: util.c:95
Definition: client.h:788
int isc_init(struct m0_config *, struct m0_client **)
Definition: util.c:247
int cir_rc
Definition: util.h:52
m0_conf_service_type
Definition: schema.h:194
static struct io_request req
Definition: file.c:100
void isc_fini(struct m0_client *)
Definition: util.c:281
struct m0_bufvec data
Definition: di.c:40
struct m0_rpc_session * cir_rpc_sess
Definition: util.h:54
Definition: ub.c:49
char * prog
Definition: iscdemo.c:316
struct m0_buf cir_result
Definition: util.h:50
Definition: buf.h:37
void free_segs(struct m0_bufvec *data, struct m0_indexvec *ext, struct m0_bufvec *attr)
Definition: util.c:67
Definition: cnt.h:36
static void attr(struct m0_addb2__context *ctx, const uint64_t *v, char *buf)
Definition: dump.c:949
struct m0_semaphore isc_sem
Definition: util.c:43
bool m0trace_on
Definition: util.c:42
Definition: list.h:72
struct m0_list isc_reqs
Definition: util.c:44
struct m0_layout_plop * cir_plop
Definition: util.h:60
Definition: fid.h:38
struct m0_fop cir_fop
Definition: util.h:58
int isc_req_send(struct isc_req *req)
Definition: util.c:198
Definition: util.h:48
struct m0_fop_isc cir_isc_fop
Definition: util.h:56
struct m0_list_link cir_link
Definition: util.h:62
void isc_req_fini(struct isc_req *req)
Definition: util.c:229
int alloc_segs(struct m0_bufvec *data, struct m0_indexvec *ext, struct m0_bufvec *attr, uint64_t bsz, uint32_t cnt)
Definition: util.c:75
isc_buffer_len
Definition: util.h:41
uint64_t isc_m0gs(struct m0_obj *, struct m0_client *)
Definition: util.c:49
struct m0_realm uber_realm
Definition: util.c:40
Definition: fop.h:79
Definition: vec.h:145