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) 2016 SUSE LINUX GmbH
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 CEPH_RBD_MIRROR_IMAGEDELETER_H
16 #define CEPH_RBD_MIRROR_IMAGEDELETER_H
18 #include "common/Mutex.h"
19 #include "common/Cond.h"
20 #include "common/Thread.h"
21 #include "common/Timer.h"
33 class ImageDeleterAdminSocketHook
;
36 * Manage deletion of non-primary images.
40 static const int EISPRM
= 1000;
42 ImageDeleter(ContextWQ
*work_queue
, SafeTimer
*timer
, Mutex
*timer_lock
);
44 ImageDeleter(const ImageDeleter
&) = delete;
45 ImageDeleter
& operator=(const ImageDeleter
&) = delete;
47 void schedule_image_delete(RadosRef local_rados
,
48 int64_t local_pool_id
,
49 const std::string
& global_image_id
);
50 void wait_for_scheduled_deletion(int64_t local_pool_id
,
51 const std::string
&global_image_id
,
53 bool notify_on_failed_retry
=true);
54 void cancel_waiter(int64_t local_pool_id
,
55 const std::string
&global_image_id
);
57 void print_status(Formatter
*f
, std::stringstream
*ss
);
59 // for testing purposes
60 std::vector
<std::string
> get_delete_queue_items();
61 std::vector
<std::pair
<std::string
, int> > get_failed_queue_items();
62 void set_failed_timer_interval(double interval
);
66 class ImageDeleterThread
: public Thread
{
67 ImageDeleter
*m_image_deleter
;
69 ImageDeleterThread(ImageDeleter
*image_deleter
) :
70 m_image_deleter(image_deleter
) {}
71 void *entry() override
{
72 m_image_deleter
->run();
79 int64_t local_pool_id
;
80 std::string global_image_id
;
83 bool notify_on_failed_retry
= true;
84 Context
*on_delete
= nullptr;
86 DeleteInfo(RadosRef local_rados
, int64_t local_pool_id
,
87 const std::string
& global_image_id
) :
88 local_rados(local_rados
), local_pool_id(local_pool_id
),
89 global_image_id(global_image_id
) {
92 bool match(int64_t local_pool_id
, const std::string
&global_image_id
) {
93 return (this->local_pool_id
== local_pool_id
&&
94 this->global_image_id
== global_image_id
);
97 void to_string(std::stringstream
& ss
);
98 void print_status(Formatter
*f
, std::stringstream
*ss
,
99 bool print_failure_info
=false);
102 std::atomic
<unsigned> m_running
{ 0 };
104 ContextWQ
*m_work_queue
;
106 std::deque
<std::unique_ptr
<DeleteInfo
> > m_delete_queue
;
108 Cond m_delete_queue_cond
;
110 unique_ptr
<DeleteInfo
> m_active_delete
;
112 ImageDeleterThread m_image_deleter_thread
;
114 std::deque
<std::unique_ptr
<DeleteInfo
>> m_failed_queue
;
115 double m_failed_interval
;
116 SafeTimer
*m_failed_timer
;
117 Mutex
*m_failed_timer_lock
;
119 ImageDeleterAdminSocketHook
*m_asok_hook
;
122 bool process_image_delete();
123 int image_has_snapshots_and_children(librados::IoCtx
*ioctx
,
124 std::string
& image_id
,
125 bool *has_snapshots
);
127 void complete_active_delete(int r
);
128 void enqueue_failed_delete(int error_code
);
129 void retry_failed_deletions();
131 unique_ptr
<DeleteInfo
> const*
132 find_delete_info(int64_t local_pool_id
, const std::string
&global_image_id
);
136 } // namespace mirror
139 #endif // CEPH_RBD_MIRROR_IMAGEDELETER_H