Motr  M0
stats_api.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2013-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 "errno.h"
24 #include "stdio.h"
25 
26 #include "lib/memory.h"
27 #include "fop/fop.h"
28 #include "rpc/rpclib.h"
29 #include "stats/stats_fops.h"
30 #include "stats/stats_fops_xc.h"
31 
32 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_STATS
33 #include "lib/trace.h"
34 
35 static struct m0_stats_recs *stats_recs_dup(struct m0_stats_recs *stats_recs)
36 {
37  int i;
38  struct m0_stats_recs *recs;
39 
40  M0_PRE(stats_recs != NULL);
41  M0_PRE(stats_recs->sf_nr > 0 && stats_recs->sf_stats != NULL);
42 
43  M0_ALLOC_PTR(recs);
44  if (recs == NULL)
45  goto error;
46 
47  recs->sf_nr = stats_recs->sf_nr;
48  M0_ALLOC_ARR(recs->sf_stats, recs->sf_nr);
49  if (recs->sf_stats == NULL)
50  goto free_recs;
51 
52  for (i = 0; i < recs->sf_nr; ++i) {
53  /* if stats type not defined. */
54  if (stats_recs->sf_stats[i].ss_data.se_nr <= 0)
55  continue;
56 
57  recs->sf_stats[i].ss_id = stats_recs->sf_stats[i].ss_id;
58  recs->sf_stats[i].ss_data.se_nr =
59  stats_recs->sf_stats[i].ss_data.se_nr;
61  recs->sf_stats[i].ss_data.se_nr);
62  if (recs->sf_stats[i].ss_data.se_data == NULL)
63  goto free_stats;
64 
65  memcpy(recs->sf_stats[i].ss_data.se_data,
66  stats_recs->sf_stats[i].ss_data.se_data,
67  recs->sf_stats[i].ss_data.se_nr * sizeof (uint64_t));
68  }
69 
70  return recs;
71 
72 free_stats:
73  for(; i >= 0; --i) {
74  if (recs->sf_stats[i].ss_data.se_data != NULL)
76  }
77  m0_free(recs->sf_stats);
78 free_recs:
79  m0_free(recs);
80 error:
81  return NULL;
82 }
83 
84 static struct m0_fop *query_fop_alloc(void)
85 {
86  struct m0_fop *fop;
87  struct m0_stats_query_fop *qfop;
88 
90  if (fop == NULL)
91  goto error;
92 
93  M0_ALLOC_PTR(qfop);
94  if (qfop == NULL)
95  goto free_fop;
96 
97  m0_fop_init(fop, &m0_fop_stats_query_fopt, (void *)qfop,
99 
100  return fop;
101 free_fop:
102  m0_free(fop);
103 error:
104  return NULL;
105 }
106 
108  struct m0_stats_recs **stats)
109 {
110  int rc;
111  struct m0_fop *fop;
112  struct m0_fop *rfop;
113  struct m0_rpc_item *item;
114  struct m0_stats_query_rep_fop *qrfop;
115 
116  M0_PRE(session != NULL);
117  M0_PRE(stats != NULL);
118 
119  fop = query_fop_alloc();
120  if (fop == NULL)
121  return M0_ERR(-ENOMEM);
122 
123  item = &fop->f_item;
125  if (rc != 0) {
127  return M0_RC(rc);
128  }
129 
131  qrfop = m0_stats_query_rep_fop_get(rfop);
132 
133  *stats = stats_recs_dup(&qrfop->sqrf_stats);
134 
136  return M0_RC(rc);
137 }
138 
140 {
141  struct m0_xcode_obj obj = {
142  .xo_type = m0_stats_recs_xc,
143  .xo_ptr = stats
144  };
145 
147 }
148 
149 #undef M0_TRACE_SUBSYSTEM
150 
151 /*
152  * Local variables:
153  * c-indentation-style: "K&R"
154  * c-basic-offset: 8
155  * tab-width: 8
156  * fill-column: 80
157  * scroll-step: 1
158  * End:
159  */
#define M0_PRE(cond)
#define M0_ALLOC_ARR(arr, nr)
Definition: memory.h:84
#define NULL
Definition: misc.h:38
uint32_t ss_id
Definition: stats_fops.h:58
M0_INTERNAL void m0_fop_init(struct m0_fop *fop, struct m0_fop_type *fopt, void *data, void(*fop_release)(struct m0_ref *))
Definition: fop.c:79
struct m0_uint64_seq ss_data
Definition: stats_fops.h:60
struct m0_stats_recs sqrf_stats
Definition: stats_fops.h:84
static int error
Definition: mdstore.c:64
M0_INTERNAL void m0_xcode_free_obj(struct m0_xcode_obj *obj)
Definition: xcode.c:248
static struct m0_rpc_session session
Definition: formation2.c:38
static struct m0_rpc_item * item
Definition: item.c:56
static struct foo * obj
Definition: tlist.c:302
uint64_t * se_data
Definition: stats_fops.h:51
return M0_RC(rc)
int i
Definition: dir.c:1033
return M0_ERR(-EOPNOTSUPP)
struct m0_stats_sum * sf_stats
Definition: stats_fops.h:67
static struct m0_stats_recs * stats_recs_dup(struct m0_stats_recs *stats_recs)
Definition: stats_api.c:35
M0_INTERNAL struct m0_stats_query_rep_fop * m0_stats_query_rep_fop_get(struct m0_fop *fop)
Definition: stats_fops.c:114
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
uint32_t se_nr
Definition: stats_fops.h:49
int m0_stats_query(struct m0_rpc_session *session, struct m0_stats_recs **stats)
Definition: stats_api.c:107
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
Definition: beck.c:130
uint64_t sf_nr
Definition: stats_fops.h:65
void m0_stats_free(struct m0_stats_recs *stats)
Definition: stats_api.c:139
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 struct m0_fop * query_fop_alloc(void)
Definition: stats_api.c:84
struct m0_fop_type m0_fop_stats_query_fopt
Definition: stats_fops.c:42
M0_INTERNAL void m0_stats_query_fop_release(struct m0_ref *ref)
Definition: stats_fops.c:119
void m0_free(void *data)
Definition: memory.c:146
struct m0_rpc_item f_item
Definition: fop.h:83
int32_t rc
Definition: trigger_fop.h:47
Definition: fop.h:79