]>
git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rados/PoolDump.cc
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) 2015 Red Hat
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 #include "include/rados/librados.hpp"
16 #include "common/errno.h"
20 using namespace librados
;
22 #define dout_context g_ceph_context
23 #define dout_subsys ceph_subsys_rados
26 * Export RADOS objects from a live cluster
27 * to a serialized format via a file descriptor.
29 * @returns 0 on success, else error code
31 int PoolDump::dump(IoCtx
*io_ctx
)
33 ceph_assert(io_ctx
!= NULL
);
38 r
= write_simple(TYPE_POOL_BEGIN
, file_fd
);
43 io_ctx
->set_namespace(all_nspaces
);
44 librados::NObjectIterator i
= io_ctx
->nobjects_begin();
46 librados::NObjectIterator i_end
= io_ctx
->nobjects_end();
47 for (; i
!= i_end
; ++i
) {
48 const std::string oid
= i
->get_oid();
49 dout(10) << "OID '" << oid
<< "'" << dendl
;
51 // Compose OBJECT_BEGIN
52 // ====================
53 object_begin obj_begin
;
54 obj_begin
.hoid
.hobj
.oid
= i
->get_oid();
55 obj_begin
.hoid
.hobj
.nspace
= i
->get_nspace();
56 obj_begin
.hoid
.hobj
.set_key(i
->get_locator());
58 // Only output head, RadosImport only wants that
59 obj_begin
.hoid
.hobj
.snap
= CEPH_NOSNAP
;
61 // Skip setting object_begin.oi, RadosImport doesn't care
63 r
= write_section(TYPE_OBJECT_BEGIN
, obj_begin
, file_fd
);
68 // Compose TYPE_DATA chunks
69 // ========================
70 const uint32_t op_size
= 4096 * 1024;
72 io_ctx
->set_namespace(i
->get_nspace());
75 r
= io_ctx
->read(oid
, outdata
, op_size
, offset
);
81 r
= write_section(TYPE_DATA
,
82 data_section(offset
, outdata
.length(), outdata
), file_fd
);
84 // Output stream error
88 if (outdata
.length() < op_size
) {
92 offset
+= outdata
.length();
95 // Compose TYPE_ATTRS chunk
96 // ========================
97 std::map
<std::string
, bufferlist
> raw_xattrs
;
98 std::map
<std::string
, bufferlist
> xattrs
;
99 r
= io_ctx
->getxattrs(oid
, raw_xattrs
);
101 cerr
<< "error getting xattr set " << oid
<< ": " << cpp_strerror(r
)
105 // Prepend "_" to mimic how user keys are represented in a pg export
106 for (std::map
<std::string
, bufferlist
>::iterator i
= raw_xattrs
.begin();
107 i
!= raw_xattrs
.end(); ++i
) {
108 std::pair
< std::string
, bufferlist
> item(std::string("_") + std::string(i
->first
.c_str()), i
->second
);
111 r
= write_section(TYPE_ATTRS
, attr_section(xattrs
), file_fd
);
116 // Compose TYPE_OMAP_HDR section
117 // =============================
118 bufferlist omap_header
;
119 r
= io_ctx
->omap_get_header(oid
, &omap_header
);
121 cerr
<< "error getting omap header " << oid
122 << ": " << cpp_strerror(r
) << std::endl
;
125 r
= write_section(TYPE_OMAP_HDR
, omap_hdr_section(omap_header
), file_fd
);
132 string last_read
= "";
134 map
<string
, bufferlist
> values
;
135 r
= io_ctx
->omap_get_vals(oid
, last_read
, MAX_READ
, &values
);
137 cerr
<< "error getting omap keys " << oid
<< ": "
138 << cpp_strerror(r
) << std::endl
;
142 last_read
= values
.rbegin()->first
;
147 r
= write_section(TYPE_OMAP
, omap_section(values
), file_fd
);
152 } while (r
== MAX_READ
);
156 r
= write_simple(TYPE_OBJECT_END
, file_fd
);
162 r
= write_simple(TYPE_POOL_END
, file_fd
);
163 #if defined(__linux__)
164 if (file_fd
!= STDOUT_FILENO
)
165 posix_fadvise(file_fd
, 0, 0, POSIX_FADV_DONTNEED
);