1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #ifndef MESSAGE_HELPER_H
16 #define MESSAGE_HELPER_H
18 #include "msg/msg_types.h"
19 #include "messages/MDataPing.h"
21 #include "msg/xio/XioMessenger.h"
24 static inline Message* new_ping_monstyle(const char *tag, int mult)
26 Message *m = new MPing();
27 Formatter *f = new JSONFormatter(true);
29 string str = "one giant step for ";
31 f->open_object_section(tag);
32 for (int ix = 0; ix < mult; ++ix) {
33 f->dump_string(tag, str);
41 ::encode(ss.str(), bl);
48 extern struct xio_mempool *xio_msgr_mpool;
50 void xio_hook_func(struct xio_reg_mem *mp)
55 static inline Message* new_ping_with_data(const char *tag, uint32_t size)
57 static uint32_t counter;
59 MDataPing *m = new MDataPing();
60 m->counter = counter++;
66 struct xio_reg_mem *mp = m->get_mp();
67 int e = xio_mempool_alloc(xio_msgr_mpool, size, mp);
70 m->set_rdma_hook(xio_hook_func);
72 strcpy((char*) p, tag);
73 uint32_t* t = (uint32_t* ) (((char*) p) + size - 32);
76 bl.append(buffer::create_static(size, (char*) p));
79 return static_cast<Message*>(m);
83 static inline Message* new_simple_ping_with_data(const char *tag,
87 static size_t pagesize = sysconf(_SC_PAGESIZE);
88 static uint32_t counter;
90 int do_page_alignment;
92 MDataPing *m = new MDataPing();
93 m->counter = counter++;
99 segsize = (size+nfrags-1)/nfrags;
100 segsize = (segsize + 7) & ~7;
101 if (segsize < 32) segsize = 32;
103 do_page_alignment = segsize >= 1024;
104 if (do_page_alignment)
105 segsize = (segsize + pagesize - 1) & ~(pagesize - 1);
107 for (uint32_t i = 0; i < nfrags; ++i) {
108 if (do_page_alignment) {
109 if (posix_memalign(&p, pagesize, segsize))
115 throw std::bad_alloc();
116 strcpy((char*) p, tag);
117 uint32_t* t = (uint32_t* ) (((char*) p) + segsize - 32);
121 bl.append(buffer::create_static(segsize, (char*) p));
125 return static_cast<Message*>(m);
128 static inline Message* new_simple_ping_with_data(const char *tag,
131 return new_simple_ping_with_data(tag, size, 1);
135 #endif /* MESSAGE_HELPER_H */