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 UPDATE_BUFFER_SIZE 8192
35 struct update_request {
36 struct dt_device *ur_dt;
37 cfs_list_t ur_list; /* attached itself to thandle */
39 int ur_rc; /* request result */
40 int ur_batchid; /* Current batch(trans) id */
41 struct update_buf *ur_buf; /* Holding the update req */
44 static inline unsigned long update_size(struct update *update)
49 size = cfs_size_round(offsetof(struct update, u_bufs[0]));
50 for (i = 0; i < UPDATE_BUF_COUNT; i++)
51 size += cfs_size_round(update->u_lens[i]);
56 static inline void *update_param_buf(struct update *update, int index,
62 if (index >= UPDATE_BUF_COUNT)
65 ptr = (char *)update + cfs_size_round(offsetof(struct update,
67 for (i = 0; i < index; i++) {
68 LASSERT(update->u_lens[i] > 0);
69 ptr += cfs_size_round(update->u_lens[i]);
73 *size = update->u_lens[index];
78 static inline unsigned long update_buf_size(struct update_buf *buf)
83 size = cfs_size_round(offsetof(struct update_buf, ub_bufs[0]));
84 for (i = 0; i < buf->ub_count; i++) {
85 struct update *update;
87 update = (struct update *)((char *)buf + size);
88 size += update_size(update);
90 LASSERT(size <= UPDATE_BUFFER_SIZE);
94 static inline void *update_buf_get(struct update_buf *buf, int index, int *size)
96 int count = buf->ub_count;
103 ptr = (char *)buf + cfs_size_round(offsetof(struct update_buf,
105 for (i = 0; i < index; i++)
106 ptr += update_size((struct update *)ptr);
109 *size = update_size((struct update *)ptr);
114 static inline void update_init_reply_buf(struct update_reply *reply, int count)
116 reply->ur_version = UPDATE_REPLY_V1;
117 reply->ur_count = count;
120 static inline void *update_get_buf_internal(struct update_reply *reply,
121 int index, int *size)
124 int count = reply->ur_count;
130 ptr = (char *)reply + cfs_size_round(offsetof(struct update_reply,
132 for (i = 0; i < index; i++) {
133 LASSERT(reply->ur_lens[i] > 0);
134 ptr += cfs_size_round(reply->ur_lens[i]);
138 *size = reply->ur_lens[index];
143 static inline void update_insert_reply(struct update_reply *reply, void *data,
144 int data_len, int index, int rc)
148 ptr = update_get_buf_internal(reply, index, NULL);
149 LASSERT(ptr != NULL);
151 *(int *)ptr = cpu_to_le32(rc);
154 LASSERT(data != NULL);
155 memcpy(ptr, data, data_len);
157 reply->ur_lens[index] = data_len + sizeof(int);
160 static inline int update_get_reply_buf(struct update_reply *reply, void **buf,
167 ptr = update_get_buf_internal(reply, index, &size);
168 LASSERT(ptr != NULL);
169 result = *(int *)ptr;
174 LASSERT(size >= sizeof(int));
175 *buf = ptr + sizeof(int);
176 return size - sizeof(int);
179 static inline int update_get_reply_result(struct update_reply *reply,
180 void **buf, int index)
185 ptr = update_get_buf_internal(reply, index, &size);
186 LASSERT(ptr != NULL && size > sizeof(int));