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
34 #define OUT_UPDATE_INIT_BUFFER_SIZE 8192
35 #define OUT_UPDATE_REPLY_SIZE 8192
36 struct dt_update_request {
37 struct dt_device *dur_dt;
38 /* attached itself to thandle */
39 struct list_head dur_list;
41 /* update request result */
43 /* Current batch(transaction) id */
45 /* Holding the update req */
46 struct object_update_request *dur_req;
48 struct list_head dur_cb_items;
51 static inline unsigned long
52 object_update_param_size(const struct object_update_param *param)
54 return cfs_size_round(sizeof(*param) + param->oup_len);
57 static inline unsigned long
58 object_update_size(const struct object_update *update)
60 const struct object_update_param *param;
64 size = offsetof(struct object_update, ou_params[0]);
65 for (i = 0; i < update->ou_params_count; i++) {
66 param = (struct object_update_param *)((char *)update + size);
67 size += object_update_param_size(param);
74 *object_update_param_get(const struct object_update *update, int index,
77 const struct object_update_param *param;
80 if (index >= update->ou_params_count)
83 param = &update->ou_params[0];
84 for (i = 0; i < index; i++)
85 param = (struct object_update_param *)((char *)param +
86 object_update_param_size(param));
89 *size = param->oup_len;
91 if (param->oup_len == 0)
94 return (void *)¶m->oup_buf[0];
97 static inline unsigned long
98 object_update_request_size(const struct object_update_request *our)
103 size = offsetof(struct object_update_request, ourq_updates[0]);
104 for (i = 0; i < our->ourq_count; i++) {
105 struct object_update *update;
107 update = (struct object_update *)((char *)our + size);
108 size += object_update_size(update);
113 static inline struct object_update
114 *object_update_request_get(const struct object_update_request *our,
115 int index, int *size)
120 if (index >= our->ourq_count)
123 ptr = (char *)our + offsetof(struct object_update_request,
125 for (i = 0; i < index; i++)
126 ptr += object_update_size((struct object_update *)ptr);
129 *size = object_update_size((struct object_update *)ptr);
135 object_update_reply_init(struct object_update_reply *reply, int count)
137 reply->ourp_magic = UPDATE_REPLY_MAGIC;
138 reply->ourp_count = count;
141 static inline struct object_update_result
142 *object_update_result_get(const struct object_update_reply *reply,
143 int index, int *size)
146 int count = reply->ourp_count;
152 ptr = (char *)reply +
153 cfs_size_round(offsetof(struct object_update_reply,
155 for (i = 0; i < index; i++) {
156 LASSERT(reply->ourp_lens[i] > 0);
157 ptr += cfs_size_round(reply->ourp_lens[i]);
161 *size = reply->ourp_lens[index];
163 return (struct object_update_result *)ptr;
167 object_update_result_insert(struct object_update_reply *reply,
168 void *data, int data_len, int index,
171 struct object_update_result *update_result;
174 update_result = object_update_result_get(reply, index, NULL);
175 LASSERT(update_result != NULL);
177 update_result->our_rc = ptlrpc_status_hton(rc);
179 LASSERT(data != NULL);
180 ptr = (char *)update_result +
181 cfs_size_round(sizeof(struct object_update_reply));
182 update_result->our_datalen = data_len;
183 memcpy(ptr, data, data_len);
186 reply->ourp_lens[index] = cfs_size_round(data_len +
187 sizeof(struct object_update_result));
191 object_update_result_data_get(const struct object_update_reply *reply,
192 struct lu_buf *lbuf, int index)
194 struct object_update_result *update_result;
198 LASSERT(lbuf != NULL);
199 update_result = object_update_result_get(reply, index, &size);
200 if (update_result == NULL ||
201 size < cfs_size_round(sizeof(struct object_update_reply)) ||
202 update_result->our_datalen > size)
205 result = ptlrpc_status_ntoh(update_result->our_rc);
209 lbuf->lb_buf = update_result->our_data;
210 lbuf->lb_len = update_result->our_datalen;
215 static inline void update_inc_batchid(struct dt_update_request *update)
217 update->dur_batchid++;