1616from .operations .clone_index import open_clone_index , PATH_MAX
1717from .operations .resolver import resolve_group_and_subvolume_name
1818from .exception import VolumeException
19+ from .async_cloner import get_clone_state
20+ from .operations .versions .subvolume_attrs import SubvolumeStates
1921
2022from mgr_util import RTimer , format_bytes , format_dimless
2123from cephfs import ObjectNotFound
@@ -98,11 +100,6 @@ def __init__(self, volclient, vol_spec):
98100 # LibCephFS.getxattr() can be made.
99101 self .volclient = volclient
100102
101- # need to figure out how many progress bars should be printed. print 1
102- # progress bar if number of ongoing clones is less than this value,
103- # else print 2.
104- self .max_concurrent_clones = self .volclient .mgr .max_concurrent_clones
105-
106103 # Creating an RTimer instance in advance so that we can check if clone
107104 # reporting has already been initiated by calling RTimer.is_alive().
108105 self .update_task = RTimer (1 , self ._update_progress_bars )
@@ -112,6 +109,8 @@ def __init__(self, volclient, vol_spec):
112109 # progress event ID for ongoing+pending clone jobs
113110 self .onpen_pev_id : Optional [str ] = 'mgr-vol-total-clones'
114111
112+ self .ongoing_clones_count = 0
113+
115114 def initiate_reporting (self ):
116115 if self .update_task .is_alive ():
117116 log .info ('progress reporting thread is already alive, not '
@@ -143,6 +142,11 @@ def _get_clone_dst_info(self, fs_handle, ci, clone_entry,
143142 ci .dst_path = dst_subvol .path
144143 log .debug (f'destination subvolume path for clone - { ci .dst_path } ' )
145144
145+ clone_state = get_clone_state (self .volclient , self .vol_spec , ci .volname ,
146+ ci .dst_group_name , ci .dst_subvol_name )
147+ if clone_state == SubvolumeStates .STATE_INPROGRESS :
148+ self .ongoing_clones_count += 1
149+
146150 log .debug ('finished collecting info for cloning destination' )
147151
148152 def _get_clone_src_info (self , fs_handle , ci ):
@@ -174,6 +178,10 @@ def _get_info_for_all_clones(self):
174178 log .debug ('finished collecting all clone index entries, '
175179 f'found { len (clones )} clone index entries' )
176180
181+ # reset ongoing clone counter before iterating over all clone
182+ # entries
183+ self .ongoing_clones_count = 0
184+
177185 log .debug ('collecting info for clones found through clone index '
178186 'entries...' )
179187 for ce in clone_index_entries :
@@ -206,7 +214,8 @@ def _get_info_for_all_clones(self):
206214 clones .append (ci )
207215
208216 log .debug ('finished collecting info on all clones, found '
209- f'{ len (clones )} clones' )
217+ f'{ len (clones )} clones out of which '
218+ f'{ self .ongoing_clones_count } are ongoing clones' )
210219 return clones
211220
212221 def _update_progress_bar_event (self , ev_id , ev_msg , ev_progress_fraction ):
@@ -235,18 +244,24 @@ def _update_progress_bars(self):
235244 self .finish ()
236245 return
237246
247+ # there has to be 1 ongoing clone for this method to run, perhaps it
248+ # wasn't found by it because the index entry for it hasn't been created
249+ # yet.
250+ if self .ongoing_clones_count == 0 :
251+ self .ongoing_clones_count = 1
252+
238253 # onpen bar (that is progress bar for clone jobs in ongoing and pending
239254 # state) is printed when clones are in pending state. it is kept in
240255 # printing until all clone jobs finish.
241- show_onpen_bar = True if len (clones ) > self .max_concurrent_clones \
256+ show_onpen_bar = True if len (clones ) > self .ongoing_clones_count \
242257 else False
243258
244259 percent = 0.0
245260
246261 assert self .on_pev_id is not None
247262 sum_percent_ongoing = 0.0
248263 avg_percent_ongoing = 0.0
249- total_ongoing_clones = min (len (clones ), self .max_concurrent_clones )
264+ total_ongoing_clones = min (len (clones ), self .ongoing_clones_count )
250265
251266 if show_onpen_bar :
252267 assert self .onpen_pev_id is not None
0 commit comments