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.
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"
22 #include "mds/JournalPointer.h"
25 #define dout_context g_ceph_context
26 #define dout_subsys ceph_subsys_journaler
28 #define dout_prefix *_dout << objecter->messenger->get_myname() << ".journalpointer "
31 std::string
JournalPointer::get_object_id() const
33 inodeno_t
const pointer_ino
= MDS_INO_LOG_POINTER_OFFSET
+ node_id
;
35 snprintf(buf
, sizeof(buf
), "%llx.%08llx", (long long unsigned)pointer_ino
, (long long unsigned)0);
37 return std::string(buf
);
42 * Blocking read of JournalPointer for this MDS
44 int JournalPointer::load(Objecter
*objecter
)
46 assert(objecter
!= NULL
);
48 // Blocking read of data
49 std::string
const object_id
= get_object_id();
50 dout(4) << "Reading journal pointer '" << object_id
<< "'" << dendl
;
53 objecter
->read_full(object_t(object_id
), object_locator_t(pool_id
),
54 CEPH_NOSNAP
, &data
, 0, &waiter
);
55 int r
= waiter
.wait();
57 // Construct JournalPointer result, null or decoded data
59 bufferlist::iterator q
= data
.begin();
62 } catch (const buffer::error
&e
) {
66 dout(1) << "Journal pointer '" << object_id
<< "' read failed: " << cpp_strerror(r
) << dendl
;
73 * Blocking write of JournalPointer for this MDS
75 * @return objecter write op status code
77 int JournalPointer::save(Objecter
*objecter
) const
79 assert(objecter
!= NULL
);
80 // It is not valid to persist a null pointer
83 // Serialize JournalPointer object
87 // Write to RADOS and wait for durability
88 std::string
const object_id
= get_object_id();
89 dout(4) << "Writing pointer object '" << object_id
<< "': 0x"
90 << std::hex
<< front
<< ":0x" << back
<< std::dec
<< dendl
;
93 objecter
->write_full(object_t(object_id
), object_locator_t(pool_id
),
95 ceph::real_clock::now(), 0,
97 int write_result
= waiter
.wait();
98 if (write_result
< 0) {
99 derr
<< "Error writing pointer object '" << object_id
<< "': " << cpp_strerror(write_result
) << dendl
;
106 * Non-blocking variant of save() that assumes objecter lock already held by
109 void JournalPointer::save(Objecter
*objecter
, Context
*completion
) const
111 assert(objecter
!= NULL
);
116 objecter
->write_full(object_t(get_object_id()), object_locator_t(pool_id
),
118 ceph::real_clock::now(), 0,