4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.htm
23 * Copyright (c) 2013, Intel Corporation.
26 * lustre/include/lustre_update.h
28 * Author: Di Wang <di.wang@intel.com>
31 #ifndef _LUSTRE_UPDATE_H
32 #define _LUSTRE_UPDATE_H
33 #include <lustre_net.h>
35 #define OUT_UPDATE_INIT_BUFFER_SIZE 8192
36 #define OUT_UPDATE_REPLY_SIZE 8192
37 struct dt_update_request {
38 struct dt_device *dur_dt;
39 /* attached itself to thandle */
40 struct list_head dur_list;
42 /* update request result */
44 /* Current batch(transaction) id */
46 /* Holding the update req */
47 struct object_update_request *dur_req;
49 struct list_head dur_cb_items;
52 static inline unsigned long
53 object_update_param_size(const struct object_update_param *param)
55 return cfs_size_round(sizeof(*param) + param->oup_len);
58 static inline unsigned long
59 object_update_size(const struct object_update *update)
61 const struct object_update_param *param;
65 size = offsetof(struct object_update, ou_params[0]);
66 for (i = 0; i < update->ou_params_count; i++) {
67 param = (struct object_update_param *)((char *)update + size);
68 size += object_update_param_size(param);
75 *object_update_param_get(const struct object_update *update, size_t index,
78 const struct object_update_param *param;
81 if (index >= update->ou_params_count)
84 param = &update->ou_params[0];
85 for (i = 0; i < index; i++)
86 param = (struct object_update_param *)((char *)param +
87 object_update_param_size(param));
90 *size = param->oup_len;
92 if (param->oup_len == 0)
95 return (void *)¶m->oup_buf[0];
98 static inline unsigned long
99 object_update_request_size(const struct object_update_request *our)
104 size = offsetof(struct object_update_request, ourq_updates[0]);
105 for (i = 0; i < our->ourq_count; i++) {
106 struct object_update *update;
108 update = (struct object_update *)((char *)our + size);
109 size += object_update_size(update);
114 static inline struct object_update
115 *object_update_request_get(const struct object_update_request *our,
116 size_t index, size_t *size)
121 if (index >= our->ourq_count)
124 ptr = (char *)our + offsetof(struct object_update_request,
126 for (i = 0; i < index; i++)
127 ptr += object_update_size((struct object_update *)ptr);
130 *size = object_update_size((struct object_update *)ptr);
136 object_update_reply_init(struct object_update_reply *reply, size_t count)
138 reply->ourp_magic = UPDATE_REPLY_MAGIC;
139 reply->ourp_count = count;
142 static inline struct object_update_result
143 *object_update_result_get(const struct object_update_reply *reply,
144 size_t index, size_t *size)
147 size_t count = reply->ourp_count;
153 ptr = (char *)reply +
154 cfs_size_round(offsetof(struct object_update_reply,
156 for (i = 0; i < index; i++) {
157 LASSERT(reply->ourp_lens[i] > 0);
158 ptr += cfs_size_round(reply->ourp_lens[i]);
162 *size = reply->ourp_lens[index];
164 return (struct object_update_result *)ptr;
168 object_update_result_insert(struct object_update_reply *reply,
169 void *data, size_t data_len, size_t index,
172 struct object_update_result *update_result;
175 update_result = object_update_result_get(reply, index, NULL);
176 LASSERT(update_result != NULL);
178 update_result->our_rc = ptlrpc_status_hton(rc);
180 LASSERT(data != NULL);
181 ptr = (char *)update_result +
182 cfs_size_round(sizeof(struct object_update_reply));
183 update_result->our_datalen = data_len;
184 memcpy(ptr, data, data_len);
187 reply->ourp_lens[index] = cfs_size_round(data_len +
188 sizeof(struct object_update_result));
192 object_update_result_data_get(const struct object_update_reply *reply,
193 struct lu_buf *lbuf, size_t index)
195 struct object_update_result *update_result;
199 LASSERT(lbuf != NULL);
200 update_result = object_update_result_get(reply, index, &size);
201 if (update_result == NULL ||
202 size < cfs_size_round(sizeof(struct object_update_reply)) ||
203 update_result->our_datalen > size)
206 result = ptlrpc_status_ntoh(update_result->our_rc);
210 lbuf->lb_buf = update_result->our_data;
211 lbuf->lb_len = update_result->our_datalen;
216 static inline void update_inc_batchid(struct dt_update_request *update)
218 update->dur_batchid++;