aboutsummaryrefslogtreecommitdiffstats
path: root/net/ceph/osd_client.c
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:45 -0400
commit33803f3300265661b5c5d20a9811c6a2a157d545 (patch)
tree192ee4eb2d726fee466eb667f6fe938ba4a41a1e /net/ceph/osd_client.c
parenta8dd0a37bc016cfb3ac75cf8484428573bb8d862 (diff)
libceph: define source request op functions
The rbd code has a function that allocates and populates a ceph_osd_req_op structure (the in-core version of an osd request operation). When reviewed, Josh suggested two things: that the big varargs function might be better split into type-specific functions; and that this functionality really belongs in the osd client rather than rbd. This patch implements both of Josh's suggestions. It breaks up the rbd function into separate functions and defines them in the osd client module as exported interfaces. Unlike the rbd version, however, the functions don't allocate an osd_req_op structure; they are provided the address of one and that is initialized instead. The rbd function has been eliminated and calls to it have been replaced by calls to the new routines. The rbd code now now use a stack (struct) variable to hold the op rather than allocating and freeing it each time. For now only the capabilities used by rbd are implemented. Implementing all the other osd op types, and making the rest of the code use it will be done separately, in the next few patches. Note that only the extent, cls, and watch portions of the ceph_osd_req_op structure are currently used. Delete the others (xattr, pgls, and snap) from its definition so nobody thinks it's actually implemented or needed. We can add it back again later if needed, when we know it's been tested. This (and a few follow-on patches) resolves: http://tracker.ceph.com/issues/3861 Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'net/ceph/osd_client.c')
-rw-r--r--net/ceph/osd_client.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 4e5c0438ea35..02ed72820479 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -289,6 +289,90 @@ static bool osd_req_opcode_valid(u16 opcode)
289 } 289 }
290} 290}
291 291
292/*
293 * This is an osd op init function for opcodes that have no data or
294 * other information associated with them. It also serves as a
295 * common init routine for all the other init functions, below.
296 */
297void osd_req_op_init(struct ceph_osd_req_op *op, u16 opcode)
298{
299 BUG_ON(!osd_req_opcode_valid(opcode));
300
301 memset(op, 0, sizeof (*op));
302
303 op->op = opcode;
304}
305
306void osd_req_op_extent_init(struct ceph_osd_req_op *op, u16 opcode,
307 u64 offset, u64 length,
308 u64 truncate_size, u32 truncate_seq)
309{
310 size_t payload_len = 0;
311
312 BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE);
313
314 osd_req_op_init(op, opcode);
315
316 op->extent.offset = offset;
317 op->extent.length = length;
318 op->extent.truncate_size = truncate_size;
319 op->extent.truncate_seq = truncate_seq;
320 if (opcode == CEPH_OSD_OP_WRITE)
321 payload_len += length;
322
323 op->payload_len = payload_len;
324}
325EXPORT_SYMBOL(osd_req_op_extent_init);
326
327void osd_req_op_cls_init(struct ceph_osd_req_op *op, u16 opcode,
328 const char *class, const char *method,
329 const void *request_data, size_t request_data_size)
330{
331 size_t payload_len = 0;
332 size_t size;
333
334 BUG_ON(opcode != CEPH_OSD_OP_CALL);
335
336 osd_req_op_init(op, opcode);
337
338 op->cls.class_name = class;
339 size = strlen(class);
340 BUG_ON(size > (size_t) U8_MAX);
341 op->cls.class_len = size;
342 payload_len += size;
343
344 op->cls.method_name = method;
345 size = strlen(method);
346 BUG_ON(size > (size_t) U8_MAX);
347 op->cls.method_len = size;
348 payload_len += size;
349
350 op->cls.indata = request_data;
351 BUG_ON(request_data_size > (size_t) U32_MAX);
352 op->cls.indata_len = (u32) request_data_size;
353 payload_len += request_data_size;
354
355 op->cls.argc = 0; /* currently unused */
356
357 op->payload_len = payload_len;
358}
359EXPORT_SYMBOL(osd_req_op_cls_init);
360
361void osd_req_op_watch_init(struct ceph_osd_req_op *op, u16 opcode,
362 u64 cookie, u64 version, int flag)
363{
364 BUG_ON(opcode != CEPH_OSD_OP_NOTIFY_ACK && opcode != CEPH_OSD_OP_WATCH);
365
366 osd_req_op_init(op, opcode);
367
368 op->watch.cookie = cookie;
369 /* op->watch.ver = version; */ /* XXX 3847 */
370 op->watch.ver = cpu_to_le64(version);
371 if (opcode == CEPH_OSD_OP_WATCH && flag)
372 op->watch.flag = (u8) 1;
373}
374EXPORT_SYMBOL(osd_req_op_watch_init);
375
292static u64 osd_req_encode_op(struct ceph_osd_request *req, 376static u64 osd_req_encode_op(struct ceph_osd_request *req,
293 struct ceph_osd_op *dst, 377 struct ceph_osd_op *dst,
294 struct ceph_osd_req_op *src) 378 struct ceph_osd_req_op *src)