which returns an RAII-wrapper around a locked PG.
Signed-off-by: Ronen Friedman <rfriedma@redhat.com>
m->put();
}
+std::optional<PGLockWrapper> OSDService::get_locked_pg(spg_t pgid)
+{
+ auto pg = osd->lookup_lock_pg(pgid);
+ if (pg) {
+ return PGLockWrapper{std::move(pg)};
+ } else {
+ return std::nullopt;
+ }
+}
+
+
MPGStats* OSD::collect_pg_stats()
{
dout(15) << __func__ << dendl;
spg_t pgid,
bool allow_requested_repair_only) final;
+ /**
+ * locks the named PG, returning an RAII wrapper that unlocks upon
+ * destruction.
+ * returns nullopt if failing to lock.
+ */
+ std::optional<PGLockWrapper> get_locked_pg(spg_t pgid) final;
private:
// -- agent shared state --
uint64_t PG::get_min_alloc_size() const {
return osd->store->get_min_alloc_size();
}
+
+PGLockWrapper::~PGLockWrapper()
+{
+ if (m_pg) {
+ // otherwise - we were 'moved from'
+ m_pg->unlock();
+ }
+}
}
};
+/**
+ * Initialized with a locked PG. That PG is unlocked in the
+ * destructor.
+ * Used by OsdScrub when initiating a scrub.
+ */
+class PGLockWrapper {
+ public:
+ explicit PGLockWrapper(PGRef locked_pg) : m_pg{locked_pg} {}
+ PGRef pg() { return m_pg; }
+ ~PGLockWrapper();
+ PGLockWrapper(PGLockWrapper&& rhs) : m_pg(std::move(rhs.m_pg)) {
+ rhs.m_pg = nullptr;
+ }
+ PGLockWrapper(const PGLockWrapper& rhs) = delete;
+ private:
+ PGRef m_pg;
+};
+
#endif
#include <optional>
#include "utime.h"
-#include "scrub_job.h"
-class PG;
+#include "osd/scrubber/scrub_job.h"
+#include "osd/PG.h"
namespace Scrub {
public:
virtual int get_nodeid() const = 0; // returns the OSD number ('whoami')
+ /**
+ * locks the named PG, returning an RAII wrapper that unlocks upon
+ * destruction.
+ * returns nullopt if failing to lock.
+ */
+ virtual std::optional<PGLockWrapper> get_locked_pg(spg_t pgid) = 0;
+
/**
* A callback used by the ScrubQueue object to initiate a scrub on a specific
* PG.
m_next_response[pgid] = result;
}
+ std::optional<PGLockWrapper> get_locked_pg(spg_t pgid)
+ {
+ std::ignore = pgid;
+ return std::nullopt;
+ }
+
private:
int m_osd_num;
std::map<spg_t, schedule_result_t> m_next_response;