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_IMAGE_SYNC_THROTTLER_H
16 #define CEPH_RBD_MIRROR_IMAGE_SYNC_THROTTLER_H
21 #include "common/Mutex.h"
22 #include "librbd/ImageCtx.h"
23 #include "include/Context.h"
24 #include "librbd/journal/TypeTraits.h"
30 namespace journal
{ class Journaler
; }
31 namespace librbd
{ namespace journal
{ struct MirrorPeerClientMeta
; } }
36 template <typename
> class ImageSync
;
38 class ProgressContext
;
41 * Manage concurrent image-syncs
43 template <typename ImageCtxT
= librbd::ImageCtx
>
44 class ImageSyncThrottler
: public md_config_obs_t
{
47 typedef librbd::journal::TypeTraits
<ImageCtxT
> TypeTraits
;
48 typedef typename
TypeTraits::Journaler Journaler
;
49 typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta
;
52 ~ImageSyncThrottler() override
;
53 ImageSyncThrottler(const ImageSyncThrottler
&) = delete;
54 ImageSyncThrottler
& operator=(const ImageSyncThrottler
&) = delete;
56 void start_sync(ImageCtxT
*local_image_ctx
,
57 ImageCtxT
*remote_image_ctx
, SafeTimer
*timer
,
58 Mutex
*timer_lock
, const std::string
&mirror_uuid
,
59 Journaler
*journaler
, MirrorPeerClientMeta
*client_meta
,
60 ContextWQ
*work_queue
, Context
*on_finish
,
61 ProgressContext
*progress_ctx
= nullptr);
63 void cancel_sync(librados::IoCtx
&local_io_ctx
,
64 const std::string local_image_id
);
66 void set_max_concurrent_syncs(uint32_t max
);
68 void print_status(Formatter
*f
, std::stringstream
*ss
);
71 typedef std::pair
<int64_t, std::string
> PoolImageId
;
75 void handle_sync_finished(C_SyncHolder
*sync_holder
);
77 const char **get_tracked_conf_keys() const override
;
78 void handle_conf_change(const struct md_config_t
*conf
,
79 const std::set
<std::string
> &changed
) override
;
81 uint32_t m_max_concurrent_syncs
;
83 std::list
<C_SyncHolder
*> m_sync_queue
;
84 std::map
<PoolImageId
, C_SyncHolder
*> m_inflight_syncs
;
91 #endif // CEPH_RBD_MIRROR_IMAGE_SYNC_THROTTLER_H