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 struct list_head 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 */
42 struct list_head ur_cb_items;
45 static inline unsigned long update_size(struct update *update)
50 size = cfs_size_round(offsetof(struct update, u_bufs[0]));
51 for (i = 0; i < UPDATE_BUF_COUNT; i++)
52 size += cfs_size_round(update->u_lens[i]);
57 static inline void *update_param_buf(struct update *update, int index,
63 if (index >= UPDATE_BUF_COUNT)
66 ptr = (char *)update + cfs_size_round(offsetof(struct update,
68 for (i = 0; i < index; i++) {
69 LASSERT(update->u_lens[i] > 0);
70 ptr += cfs_size_round(update->u_lens[i]);
74 *size = update->u_lens[index];
79 static inline unsigned long update_buf_size(struct update_buf *buf)
84 size = cfs_size_round(offsetof(struct update_buf, ub_bufs[0]));
85 for (i = 0; i < buf->ub_count; i++) {
86 struct update *update;
88 update = (struct update *)((char *)buf + size);
89 size += update_size(update);
91 LASSERT(size <= UPDATE_BUFFER_SIZE);
95 static inline void *update_buf_get(struct update_buf *buf, int index, int *size)
97 int count = buf->ub_count;
104 ptr = (char *)buf + cfs_size_round(offsetof(struct update_buf,
106 for (i = 0; i < index; i++)
107 ptr += update_size((struct update *)ptr);
110 *size = update_size((struct update *)ptr);
115 static inline void update_init_reply_buf(struct update_reply *reply, int count)
117 reply->ur_version = UPDATE_REPLY_V1;
118 reply->ur_count = count;
121 static inline void *update_get_buf_internal(struct update_reply *reply,
122 int index, int *size)
125 int count = reply->ur_count;
131 ptr = (char *)reply + cfs_size_round(offsetof(struct update_reply,
133 for (i = 0; i < index; i++) {
134 LASSERT(reply->ur_lens[i] > 0);
135 ptr += cfs_size_round(reply->ur_lens[i]);
139 *size = reply->ur_lens[index];
144 static inline void update_insert_reply(struct update_reply *reply, void *data,
145 int data_len, int index, int rc)
149 ptr = update_get_buf_internal(reply, index, NULL);
150 LASSERT(ptr != NULL);
152 *(int *)ptr = cpu_to_le32(rc);
155 LASSERT(data != NULL);
156 memcpy(ptr, data, data_len);
158 reply->ur_lens[index] = data_len + sizeof(int);
161 static inline int update_get_reply_buf(struct update_reply *reply,
162 struct lu_buf *lbuf, int index)
168 LASSERT(lbuf != NULL);
170 ptr = update_get_buf_internal(reply, index, &size);
171 LASSERT(ptr != NULL);
172 result = *(int *)ptr;
177 LASSERT(size >= sizeof(int));
179 lbuf->lb_buf = ptr + sizeof(int);
180 lbuf->lb_len = size - sizeof(int);
185 static inline int update_get_reply_result(struct update_reply *reply,
186 void **buf, int index)
191 ptr = update_get_buf_internal(reply, index, &size);
192 LASSERT(ptr != NULL && size > sizeof(int));
196 static inline void update_inc_batchid(struct update_request *update)
198 update->ur_batchid++;