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 */
40 struct update_buf *ur_buf; /* Holding the update req */
43 static inline unsigned long update_size(struct update *update)
48 size = cfs_size_round(offsetof(struct update, u_bufs[0]));
49 for (i = 0; i < UPDATE_BUF_COUNT; i++)
50 size += cfs_size_round(update->u_lens[i]);
55 static inline void *update_param_buf(struct update *update, int index,
61 if (index >= UPDATE_BUF_COUNT)
64 ptr = (char *)update + cfs_size_round(offsetof(struct update,
66 for (i = 0; i < index; i++) {
67 LASSERT(update->u_lens[i] > 0);
68 ptr += cfs_size_round(update->u_lens[i]);
72 *size = update->u_lens[index];
77 static inline unsigned long update_buf_size(struct update_buf *buf)
82 size = cfs_size_round(offsetof(struct update_buf, ub_bufs[0]));
83 for (i = 0; i < buf->ub_count; i++) {
84 struct update *update;
86 update = (struct update *)((char *)buf + size);
87 size += update_size(update);
89 LASSERT(size <= UPDATE_BUFFER_SIZE);
93 static inline void *update_buf_get(struct update_buf *buf, int index, int *size)
95 int count = buf->ub_count;
102 ptr = (char *)buf + cfs_size_round(offsetof(struct update_buf,
104 for (i = 0; i < index; i++)
105 ptr += update_size((struct update *)ptr);
108 *size = update_size((struct update *)ptr);
113 static inline void update_init_reply_buf(struct update_reply *reply, int count)
115 reply->ur_version = UPDATE_REPLY_V1;
116 reply->ur_count = count;
119 static inline void *update_get_buf_internal(struct update_reply *reply,
120 int index, int *size)
123 int count = reply->ur_count;
129 ptr = (char *)reply + cfs_size_round(offsetof(struct update_reply,
131 for (i = 0; i < index; i++) {
132 LASSERT(reply->ur_lens[i] > 0);
133 ptr += cfs_size_round(reply->ur_lens[i]);
137 *size = reply->ur_lens[index];
142 static inline void update_insert_reply(struct update_reply *reply, void *data,
143 int data_len, int index, int rc)
147 ptr = update_get_buf_internal(reply, index, NULL);
148 LASSERT(ptr != NULL);
150 *(int *)ptr = cpu_to_le32(rc);
153 LASSERT(data != NULL);
154 memcpy(ptr, data, data_len);
156 reply->ur_lens[index] = data_len + sizeof(int);
159 static inline int update_get_reply_buf(struct update_reply *reply, void **buf,
166 ptr = update_get_buf_internal(reply, index, &size);
167 result = *(int *)ptr;
172 LASSERT((ptr != NULL && size >= sizeof(int)));
173 *buf = ptr + sizeof(int);
174 return size - sizeof(int);
177 static inline int update_get_reply_result(struct update_reply *reply,
178 void **buf, int index)
183 ptr = update_get_buf_internal(reply, index, &size);
184 LASSERT(ptr != NULL && size > sizeof(int));