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 4096
36 #define OUT_UPDATE_REPLY_SIZE 8192
39 struct dt_object_hint;
40 struct dt_object_format;
41 struct dt_allocation_hint;
46 struct update_buffer {
47 struct object_update_request *ub_req;
52 * Tracking the updates being executed on this dt_device.
54 struct dt_update_request {
55 struct dt_device *dur_dt;
56 /* attached itself to thandle */
57 struct list_head dur_list;
59 /* update request result */
61 /* Current batch(transaction) id */
63 /* Holding object updates */
64 struct update_buffer dur_buf;
65 struct list_head dur_cb_items;
69 *object_update_param_get(const struct object_update *update, size_t index,
72 const struct object_update_param *param;
75 if (index >= update->ou_params_count)
78 param = &update->ou_params[0];
79 for (i = 0; i < index; i++)
80 param = (struct object_update_param *)((char *)param +
81 object_update_param_size(param));
84 *size = param->oup_len;
86 if (param->oup_len == 0)
89 return (void *)¶m->oup_buf[0];
92 static inline unsigned long
93 object_update_request_size(const struct object_update_request *our)
98 size = offsetof(struct object_update_request, ourq_updates[0]);
99 for (i = 0; i < our->ourq_count; i++) {
100 struct object_update *update;
102 update = (struct object_update *)((char *)our + size);
103 size += object_update_size(update);
109 object_update_reply_init(struct object_update_reply *reply, size_t count)
111 reply->ourp_magic = UPDATE_REPLY_MAGIC;
112 reply->ourp_count = count;
116 object_update_result_insert(struct object_update_reply *reply,
117 void *data, size_t data_len, size_t index,
120 struct object_update_result *update_result;
123 update_result = object_update_result_get(reply, index, NULL);
124 LASSERT(update_result != NULL);
126 update_result->our_rc = ptlrpc_status_hton(rc);
128 LASSERT(data != NULL);
129 ptr = (char *)update_result +
130 cfs_size_round(sizeof(struct object_update_reply));
131 update_result->our_datalen = data_len;
132 memcpy(ptr, data, data_len);
135 reply->ourp_lens[index] = cfs_size_round(data_len +
136 sizeof(struct object_update_result));
140 object_update_result_data_get(const struct object_update_reply *reply,
141 struct lu_buf *lbuf, size_t index)
143 struct object_update_result *update_result;
147 LASSERT(lbuf != NULL);
148 update_result = object_update_result_get(reply, index, &size);
149 if (update_result == NULL ||
150 size < cfs_size_round(sizeof(struct object_update_reply)) ||
151 update_result->our_datalen > size)
154 result = ptlrpc_status_ntoh(update_result->our_rc);
158 lbuf->lb_buf = update_result->our_data;
159 lbuf->lb_len = update_result->our_datalen;
164 static inline void update_inc_batchid(struct dt_update_request *update)
166 update->dur_batchid++;
169 /* target/out_lib.c */
170 struct thandle_update;
171 struct dt_update_request *out_find_update(struct thandle_update *tu,
172 struct dt_device *dt_dev);
173 void dt_update_request_destroy(struct dt_update_request *update);
174 struct dt_update_request *dt_update_request_create(struct dt_device *dt);
175 struct dt_update_request *dt_update_request_find_or_create(struct thandle *th,
176 struct dt_object *dt);
177 int out_prep_update_req(const struct lu_env *env, struct obd_import *imp,
178 const struct object_update_request *ureq,
179 struct ptlrpc_request **reqp);
180 int out_remote_sync(const struct lu_env *env, struct obd_import *imp,
181 struct dt_update_request *update,
182 struct ptlrpc_request **reqp);
183 int out_update_pack(const struct lu_env *env, struct update_buffer *ubuf,
184 enum update_type op, const struct lu_fid *fid,
185 int params_count, __u16 *param_sizes, const void **bufs,
187 int out_create_pack(const struct lu_env *env, struct update_buffer *ubuf,
188 const struct lu_fid *fid, struct lu_attr *attr,
189 struct dt_allocation_hint *hint,
190 struct dt_object_format *dof, __u64 batchid);
191 int out_object_destroy_pack(const struct lu_env *env,
192 struct update_buffer *ubuf,
193 const struct lu_fid *fid, __u64 batchid);
194 int out_index_delete_pack(const struct lu_env *env, struct update_buffer *ubuf,
195 const struct lu_fid *fid, const struct dt_key *key,
197 int out_index_insert_pack(const struct lu_env *env, struct update_buffer *ubuf,
198 const struct lu_fid *fid, const struct dt_rec *rec,
199 const struct dt_key *key, __u64 batchid);
200 int out_xattr_set_pack(const struct lu_env *env, struct update_buffer *ubuf,
201 const struct lu_fid *fid, const struct lu_buf *buf,
202 const char *name, int flag, __u64 batchid);
203 int out_xattr_del_pack(const struct lu_env *env, struct update_buffer *ubuf,
204 const struct lu_fid *fid, const char *name,
206 int out_attr_set_pack(const struct lu_env *env, struct update_buffer *ubuf,
207 const struct lu_fid *fid, const struct lu_attr *attr,
209 int out_ref_add_pack(const struct lu_env *env, struct update_buffer *ubuf,
210 const struct lu_fid *fid, __u64 batchid);
211 int out_ref_del_pack(const struct lu_env *env, struct update_buffer *ubuf,
212 const struct lu_fid *fid, __u64 batchid);
213 int out_write_pack(const struct lu_env *env, struct update_buffer *ubuf,
214 const struct lu_fid *fid, const struct lu_buf *buf,
215 loff_t pos, __u64 batchid);
216 int out_attr_get_pack(const struct lu_env *env, struct update_buffer *ubuf,
217 const struct lu_fid *fid);
218 int out_index_lookup_pack(const struct lu_env *env, struct update_buffer *ubuf,
219 const struct lu_fid *fid, struct dt_rec *rec,
220 const struct dt_key *key);
221 int out_xattr_get_pack(const struct lu_env *env, struct update_buffer *ubuf,
222 const struct lu_fid *fid, const char *name);