aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2013-03-13 21:50:00 -0400
committerSage Weil <sage@inktank.com>2013-05-02 00:17:44 -0400
commita8dd0a37bc016cfb3ac75cf8484428573bb8d862 (patch)
tree4bd078753c105f3b1946457fdceb43f286f1b7cc /net
parentadfe695a25e92e3a4597807fbc7f9a8105218776 (diff)
libceph: define osd_req_opcode_valid()
Define a separate function to determine the validity of an opcode, and use it inside osd_req_encode_op() in order to unclutter that function. Don't update the destination op at all--and return zero--if an unsupported or unrecognized opcode is seen in osd_req_encode_op(). Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'net')
-rw-r--r--net/ceph/osd_client.c126
1 files changed, 72 insertions, 54 deletions
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 015bf9f64da7..4e5c0438ea35 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -220,70 +220,24 @@ struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
220} 220}
221EXPORT_SYMBOL(ceph_osdc_alloc_request); 221EXPORT_SYMBOL(ceph_osdc_alloc_request);
222 222
223static u64 osd_req_encode_op(struct ceph_osd_request *req, 223static bool osd_req_opcode_valid(u16 opcode)
224 struct ceph_osd_op *dst,
225 struct ceph_osd_req_op *src)
226{ 224{
227 u64 out_data_len = 0; 225 switch (opcode) {
228 struct ceph_pagelist *pagelist;
229
230 dst->op = cpu_to_le16(src->op);
231
232 switch (src->op) {
233 case CEPH_OSD_OP_STAT:
234 break;
235 case CEPH_OSD_OP_READ: 226 case CEPH_OSD_OP_READ:
236 case CEPH_OSD_OP_WRITE: 227 case CEPH_OSD_OP_STAT:
237 if (src->op == CEPH_OSD_OP_WRITE)
238 out_data_len = src->extent.length;
239 dst->extent.offset = cpu_to_le64(src->extent.offset);
240 dst->extent.length = cpu_to_le64(src->extent.length);
241 dst->extent.truncate_size =
242 cpu_to_le64(src->extent.truncate_size);
243 dst->extent.truncate_seq =
244 cpu_to_le32(src->extent.truncate_seq);
245 break;
246 case CEPH_OSD_OP_CALL:
247 pagelist = kmalloc(sizeof (*pagelist), GFP_NOFS);
248 BUG_ON(!pagelist);
249 ceph_pagelist_init(pagelist);
250
251 dst->cls.class_len = src->cls.class_len;
252 dst->cls.method_len = src->cls.method_len;
253 dst->cls.indata_len = cpu_to_le32(src->cls.indata_len);
254 ceph_pagelist_append(pagelist, src->cls.class_name,
255 src->cls.class_len);
256 ceph_pagelist_append(pagelist, src->cls.method_name,
257 src->cls.method_len);
258 ceph_pagelist_append(pagelist, src->cls.indata,
259 src->cls.indata_len);
260
261 req->r_data_out.type = CEPH_OSD_DATA_TYPE_PAGELIST;
262 req->r_data_out.pagelist = pagelist;
263 out_data_len = pagelist->length;
264 break;
265 case CEPH_OSD_OP_STARTSYNC:
266 break;
267 case CEPH_OSD_OP_NOTIFY_ACK:
268 case CEPH_OSD_OP_WATCH:
269 dst->watch.cookie = cpu_to_le64(src->watch.cookie);
270 dst->watch.ver = cpu_to_le64(src->watch.ver);
271 dst->watch.flag = src->watch.flag;
272 break;
273 default:
274 pr_err("unrecognized osd opcode %d\n", src->op);
275 WARN_ON(1);
276 break;
277 case CEPH_OSD_OP_MAPEXT: 228 case CEPH_OSD_OP_MAPEXT:
278 case CEPH_OSD_OP_MASKTRUNC: 229 case CEPH_OSD_OP_MASKTRUNC:
279 case CEPH_OSD_OP_SPARSE_READ: 230 case CEPH_OSD_OP_SPARSE_READ:
280 case CEPH_OSD_OP_NOTIFY: 231 case CEPH_OSD_OP_NOTIFY:
232 case CEPH_OSD_OP_NOTIFY_ACK:
281 case CEPH_OSD_OP_ASSERT_VER: 233 case CEPH_OSD_OP_ASSERT_VER:
234 case CEPH_OSD_OP_WRITE:
282 case CEPH_OSD_OP_WRITEFULL: 235 case CEPH_OSD_OP_WRITEFULL:
283 case CEPH_OSD_OP_TRUNCATE: 236 case CEPH_OSD_OP_TRUNCATE:
284 case CEPH_OSD_OP_ZERO: 237 case CEPH_OSD_OP_ZERO:
285 case CEPH_OSD_OP_DELETE: 238 case CEPH_OSD_OP_DELETE:
286 case CEPH_OSD_OP_APPEND: 239 case CEPH_OSD_OP_APPEND:
240 case CEPH_OSD_OP_STARTSYNC:
287 case CEPH_OSD_OP_SETTRUNC: 241 case CEPH_OSD_OP_SETTRUNC:
288 case CEPH_OSD_OP_TRIMTRUNC: 242 case CEPH_OSD_OP_TRIMTRUNC:
289 case CEPH_OSD_OP_TMAPUP: 243 case CEPH_OSD_OP_TMAPUP:
@@ -291,11 +245,11 @@ static u64 osd_req_encode_op(struct ceph_osd_request *req,
291 case CEPH_OSD_OP_TMAPGET: 245 case CEPH_OSD_OP_TMAPGET:
292 case CEPH_OSD_OP_CREATE: 246 case CEPH_OSD_OP_CREATE:
293 case CEPH_OSD_OP_ROLLBACK: 247 case CEPH_OSD_OP_ROLLBACK:
248 case CEPH_OSD_OP_WATCH:
294 case CEPH_OSD_OP_OMAPGETKEYS: 249 case CEPH_OSD_OP_OMAPGETKEYS:
295 case CEPH_OSD_OP_OMAPGETVALS: 250 case CEPH_OSD_OP_OMAPGETVALS:
296 case CEPH_OSD_OP_OMAPGETHEADER: 251 case CEPH_OSD_OP_OMAPGETHEADER:
297 case CEPH_OSD_OP_OMAPGETVALSBYKEYS: 252 case CEPH_OSD_OP_OMAPGETVALSBYKEYS:
298 case CEPH_OSD_OP_MODE_RD:
299 case CEPH_OSD_OP_OMAPSETVALS: 253 case CEPH_OSD_OP_OMAPSETVALS:
300 case CEPH_OSD_OP_OMAPSETHEADER: 254 case CEPH_OSD_OP_OMAPSETHEADER:
301 case CEPH_OSD_OP_OMAPCLEAR: 255 case CEPH_OSD_OP_OMAPCLEAR:
@@ -326,13 +280,77 @@ static u64 osd_req_encode_op(struct ceph_osd_request *req,
326 case CEPH_OSD_OP_RDUNLOCK: 280 case CEPH_OSD_OP_RDUNLOCK:
327 case CEPH_OSD_OP_UPLOCK: 281 case CEPH_OSD_OP_UPLOCK:
328 case CEPH_OSD_OP_DNLOCK: 282 case CEPH_OSD_OP_DNLOCK:
283 case CEPH_OSD_OP_CALL:
329 case CEPH_OSD_OP_PGLS: 284 case CEPH_OSD_OP_PGLS:
330 case CEPH_OSD_OP_PGLS_FILTER: 285 case CEPH_OSD_OP_PGLS_FILTER:
286 return true;
287 default:
288 return false;
289 }
290}
291
292static u64 osd_req_encode_op(struct ceph_osd_request *req,
293 struct ceph_osd_op *dst,
294 struct ceph_osd_req_op *src)
295{
296 u64 out_data_len = 0;
297 struct ceph_pagelist *pagelist;
298
299 if (WARN_ON(!osd_req_opcode_valid(src->op))) {
300 pr_err("unrecognized osd opcode %d\n", src->op);
301
302 return 0;
303 }
304
305 switch (src->op) {
306 case CEPH_OSD_OP_STAT:
307 break;
308 case CEPH_OSD_OP_READ:
309 case CEPH_OSD_OP_WRITE:
310 if (src->op == CEPH_OSD_OP_WRITE)
311 out_data_len = src->extent.length;
312 dst->extent.offset = cpu_to_le64(src->extent.offset);
313 dst->extent.length = cpu_to_le64(src->extent.length);
314 dst->extent.truncate_size =
315 cpu_to_le64(src->extent.truncate_size);
316 dst->extent.truncate_seq =
317 cpu_to_le32(src->extent.truncate_seq);
318 break;
319 case CEPH_OSD_OP_CALL:
320 pagelist = kmalloc(sizeof (*pagelist), GFP_NOFS);
321 BUG_ON(!pagelist);
322 ceph_pagelist_init(pagelist);
323
324 dst->cls.class_len = src->cls.class_len;
325 dst->cls.method_len = src->cls.method_len;
326 dst->cls.indata_len = cpu_to_le32(src->cls.indata_len);
327 ceph_pagelist_append(pagelist, src->cls.class_name,
328 src->cls.class_len);
329 ceph_pagelist_append(pagelist, src->cls.method_name,
330 src->cls.method_len);
331 ceph_pagelist_append(pagelist, src->cls.indata,
332 src->cls.indata_len);
333
334 req->r_data_out.type = CEPH_OSD_DATA_TYPE_PAGELIST;
335 req->r_data_out.pagelist = pagelist;
336 out_data_len = pagelist->length;
337 break;
338 case CEPH_OSD_OP_STARTSYNC:
339 break;
340 case CEPH_OSD_OP_NOTIFY_ACK:
341 case CEPH_OSD_OP_WATCH:
342 dst->watch.cookie = cpu_to_le64(src->watch.cookie);
343 dst->watch.ver = cpu_to_le64(src->watch.ver);
344 dst->watch.flag = src->watch.flag;
345 break;
346 default:
331 pr_err("unsupported osd opcode %s\n", 347 pr_err("unsupported osd opcode %s\n",
332 ceph_osd_op_name(src->op)); 348 ceph_osd_op_name(src->op));
333 WARN_ON(1); 349 WARN_ON(1);
334 break; 350
351 return 0;
335 } 352 }
353 dst->op = cpu_to_le16(src->op);
336 dst->payload_len = cpu_to_le32(src->payload_len); 354 dst->payload_len = cpu_to_le32(src->payload_len);
337 355
338 return out_data_len; 356 return out_data_len;