Whamcloud - gitweb
LU-5319 ptlrpc: Add OBD_CONNECT_MULTIMODRPCS flag
[fs/lustre-release.git] / lustre / include / lustre_update.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2013, 2014, Intel Corporation.
24  */
25 /*
26  * lustre/include/lustre_update.h
27  *
28  * Author: Di Wang <di.wang@intel.com>
29  */
30
31 #ifndef _LUSTRE_UPDATE_H
32 #define _LUSTRE_UPDATE_H
33 #include <lustre_net.h>
34
35 #define OUT_UPDATE_INIT_BUFFER_SIZE     4096
36 #define OUT_UPDATE_REPLY_SIZE           8192
37
38 struct dt_object;
39 struct dt_object_hint;
40 struct dt_object_format;
41 struct dt_allocation_hint;
42 struct dt_key;
43 struct dt_rec;
44 struct thandle;
45
46 struct update_buffer {
47         struct object_update_request    *ub_req;
48         size_t                          ub_req_size;
49 };
50
51 /**
52  * Tracking the updates being executed on this dt_device.
53  */
54 struct dt_update_request {
55         struct dt_device                *dur_dt;
56         /* attached itself to thandle */
57         struct list_head                dur_list;
58         int                             dur_flags;
59         /* update request result */
60         int                             dur_rc;
61         /* Current batch(transaction) id */
62         __u64                           dur_batchid;
63         /* Holding object updates */
64         struct update_buffer            dur_buf;
65         struct list_head                dur_cb_items;
66 };
67
68 static inline void
69 *object_update_param_get(const struct object_update *update, size_t index,
70                          size_t *size)
71 {
72         const struct    object_update_param *param;
73         size_t          i;
74
75         if (index >= update->ou_params_count)
76                 return NULL;
77
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));
82
83         if (size != NULL)
84                 *size = param->oup_len;
85
86         if (param->oup_len == 0)
87                 return NULL;
88
89         return (void *)&param->oup_buf[0];
90 }
91
92 static inline unsigned long
93 object_update_request_size(const struct object_update_request *our)
94 {
95         unsigned long   size;
96         size_t          i = 0;
97
98         size = offsetof(struct object_update_request, ourq_updates[0]);
99         for (i = 0; i < our->ourq_count; i++) {
100                 struct object_update *update;
101
102                 update = (struct object_update *)((char *)our + size);
103                 size += object_update_size(update);
104         }
105         return size;
106 }
107
108 static inline void
109 object_update_reply_init(struct object_update_reply *reply, size_t count)
110 {
111         reply->ourp_magic = UPDATE_REPLY_MAGIC;
112         reply->ourp_count = count;
113 }
114
115 static inline void
116 object_update_result_insert(struct object_update_reply *reply,
117                             void *data, size_t data_len, size_t index,
118                             int rc)
119 {
120         struct object_update_result *update_result;
121         char *ptr;
122
123         update_result = object_update_result_get(reply, index, NULL);
124         LASSERT(update_result != NULL);
125
126         update_result->our_rc = ptlrpc_status_hton(rc);
127         if (data_len > 0) {
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);
133         }
134
135         reply->ourp_lens[index] = cfs_size_round(data_len +
136                                         sizeof(struct object_update_result));
137 }
138
139 static inline int
140 object_update_result_data_get(const struct object_update_reply *reply,
141                               struct lu_buf *lbuf, size_t index)
142 {
143         struct object_update_result *update_result;
144         size_t size = 0;
145         int    result;
146
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)
152                 RETURN(-EFAULT);
153
154         result = ptlrpc_status_ntoh(update_result->our_rc);
155         if (result < 0)
156                 return result;
157
158         lbuf->lb_buf = update_result->our_data;
159         lbuf->lb_len = update_result->our_datalen;
160
161         return 0;
162 }
163
164 static inline void update_inc_batchid(struct dt_update_request *update)
165 {
166         update->dur_batchid++;
167 }
168
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_update_pack(const struct lu_env *env, struct update_buffer *ubuf,
178                     enum update_type op, const struct lu_fid *fid,
179                     int params_count, __u16 *param_sizes, const void **bufs,
180                     __u64 batchid);
181 int out_create_pack(const struct lu_env *env, struct update_buffer *ubuf,
182                     const struct lu_fid *fid, struct lu_attr *attr,
183                     struct dt_allocation_hint *hint,
184                     struct dt_object_format *dof, __u64 batchid);
185 int out_object_destroy_pack(const struct lu_env *env,
186                             struct update_buffer *ubuf,
187                             const struct lu_fid *fid, __u64 batchid);
188 int out_index_delete_pack(const struct lu_env *env, struct update_buffer *ubuf,
189                           const struct lu_fid *fid, const struct dt_key *key,
190                           __u64 batchid);
191 int out_index_insert_pack(const struct lu_env *env, struct update_buffer *ubuf,
192                           const struct lu_fid *fid, const struct dt_rec *rec,
193                           const struct dt_key *key, __u64 batchid);
194 int out_xattr_set_pack(const struct lu_env *env, struct update_buffer *ubuf,
195                        const struct lu_fid *fid, const struct lu_buf *buf,
196                        const char *name, int flag, __u64 batchid);
197 int out_xattr_del_pack(const struct lu_env *env, struct update_buffer *ubuf,
198                        const struct lu_fid *fid, const char *name,
199                        __u64 batchid);
200 int out_attr_set_pack(const struct lu_env *env, struct update_buffer *ubuf,
201                       const struct lu_fid *fid, const struct lu_attr *attr,
202                       __u64 batchid);
203 int out_ref_add_pack(const struct lu_env *env, struct update_buffer *ubuf,
204                      const struct lu_fid *fid, __u64 batchid);
205 int out_ref_del_pack(const struct lu_env *env, struct update_buffer *ubuf,
206                      const struct lu_fid *fid, __u64 batchid);
207 int out_write_pack(const struct lu_env *env, struct update_buffer *ubuf,
208                    const struct lu_fid *fid, const struct lu_buf *buf,
209                    loff_t pos, __u64 batchid);
210 int out_attr_get_pack(const struct lu_env *env, struct update_buffer *ubuf,
211                       const struct lu_fid *fid);
212 int out_index_lookup_pack(const struct lu_env *env, struct update_buffer *ubuf,
213                           const struct lu_fid *fid, struct dt_rec *rec,
214                           const struct dt_key *key);
215 int out_xattr_get_pack(const struct lu_env *env, struct update_buffer *ubuf,
216                        const struct lu_fid *fid, const char *name);
217 #endif