]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net> | |
7 | * | |
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. | |
12 | * | |
13 | */ | |
14 | ||
15 | ||
16 | #include "common/debug.h" | |
17 | #include "common/errno.h" | |
18 | #include "common/Cond.h" | |
19 | #include "osdc/Objecter.h" | |
20 | #include "mds/mdstypes.h" | |
11fdf7f2 | 21 | #include "msg/Messenger.h" |
7c673cae FG |
22 | |
23 | #include "mds/JournalPointer.h" | |
24 | ||
25 | ||
26 | #define dout_context g_ceph_context | |
27 | #define dout_subsys ceph_subsys_journaler | |
28 | #undef dout_prefix | |
29 | #define dout_prefix *_dout << objecter->messenger->get_myname() << ".journalpointer " | |
30 | ||
31 | ||
32 | std::string JournalPointer::get_object_id() const | |
33 | { | |
34 | inodeno_t const pointer_ino = MDS_INO_LOG_POINTER_OFFSET + node_id; | |
35 | char buf[32]; | |
36 | snprintf(buf, sizeof(buf), "%llx.%08llx", (long long unsigned)pointer_ino, (long long unsigned)0); | |
37 | ||
38 | return std::string(buf); | |
39 | } | |
40 | ||
41 | ||
42 | /** | |
43 | * Blocking read of JournalPointer for this MDS | |
44 | */ | |
45 | int JournalPointer::load(Objecter *objecter) | |
46 | { | |
11fdf7f2 | 47 | ceph_assert(objecter != NULL); |
7c673cae FG |
48 | |
49 | // Blocking read of data | |
50 | std::string const object_id = get_object_id(); | |
51 | dout(4) << "Reading journal pointer '" << object_id << "'" << dendl; | |
52 | bufferlist data; | |
53 | C_SaferCond waiter; | |
54 | objecter->read_full(object_t(object_id), object_locator_t(pool_id), | |
55 | CEPH_NOSNAP, &data, 0, &waiter); | |
56 | int r = waiter.wait(); | |
57 | ||
58 | // Construct JournalPointer result, null or decoded data | |
59 | if (r == 0) { | |
11fdf7f2 | 60 | auto q = data.cbegin(); |
7c673cae FG |
61 | try { |
62 | decode(q); | |
63 | } catch (const buffer::error &e) { | |
64 | return -EINVAL; | |
65 | } | |
66 | } else { | |
67 | dout(1) << "Journal pointer '" << object_id << "' read failed: " << cpp_strerror(r) << dendl; | |
68 | } | |
69 | return r; | |
70 | } | |
71 | ||
72 | ||
73 | /** | |
74 | * Blocking write of JournalPointer for this MDS | |
75 | * | |
76 | * @return objecter write op status code | |
77 | */ | |
78 | int JournalPointer::save(Objecter *objecter) const | |
79 | { | |
11fdf7f2 | 80 | ceph_assert(objecter != NULL); |
7c673cae | 81 | // It is not valid to persist a null pointer |
11fdf7f2 | 82 | ceph_assert(!is_null()); |
7c673cae FG |
83 | |
84 | // Serialize JournalPointer object | |
85 | bufferlist data; | |
86 | encode(data); | |
87 | ||
88 | // Write to RADOS and wait for durability | |
89 | std::string const object_id = get_object_id(); | |
90 | dout(4) << "Writing pointer object '" << object_id << "': 0x" | |
91 | << std::hex << front << ":0x" << back << std::dec << dendl; | |
92 | ||
93 | C_SaferCond waiter; | |
94 | objecter->write_full(object_t(object_id), object_locator_t(pool_id), | |
95 | SnapContext(), data, | |
96 | ceph::real_clock::now(), 0, | |
97 | &waiter); | |
98 | int write_result = waiter.wait(); | |
99 | if (write_result < 0) { | |
100 | derr << "Error writing pointer object '" << object_id << "': " << cpp_strerror(write_result) << dendl; | |
101 | } | |
102 | return write_result; | |
103 | } | |
104 | ||
105 | ||
106 | /** | |
107 | * Non-blocking variant of save() that assumes objecter lock already held by | |
108 | * caller | |
109 | */ | |
110 | void JournalPointer::save(Objecter *objecter, Context *completion) const | |
111 | { | |
11fdf7f2 | 112 | ceph_assert(objecter != NULL); |
7c673cae FG |
113 | |
114 | bufferlist data; | |
115 | encode(data); | |
116 | ||
117 | objecter->write_full(object_t(get_object_id()), object_locator_t(pool_id), | |
118 | SnapContext(), data, | |
119 | ceph::real_clock::now(), 0, | |
120 | completion); | |
121 | } | |
122 |