@@ -113,95 +113,101 @@ def handle_open_image(self,
113113 self .finish (image_spec )
114114 return
115115
116- self .get_mirror_mode (image_spec , image )
116+ self .get_mirror_info (image_spec , image )
117117
118- def get_mirror_mode (self , image_spec : ImageSpec , image : rbd .Image ) -> None :
118+ def get_mirror_info (self , image_spec : ImageSpec , image : rbd .Image ) -> None :
119119 pool_id , namespace , image_id = image_spec
120120
121- self .log .debug ("CreateSnapshotRequests.get_mirror_mode : {}/{}/{}" .format (
121+ self .log .debug ("CreateSnapshotRequests.get_mirror_info : {}/{}/{}" .format (
122122 pool_id , namespace , image_id ))
123123
124- def cb (comp : rados .Completion , mode : Optional [int ]) -> None :
125- self .handle_get_mirror_mode (image_spec , image , comp , mode )
124+ def cb (comp : rados .Completion , info : Optional [Dict [ str , Union [ str , int ]] ]) -> None :
125+ self .handle_get_mirror_info (image_spec , image , comp , info )
126126
127127 try :
128- image .aio_mirror_image_get_mode (cb )
128+ image .aio_mirror_image_get_info (cb )
129129 except Exception as e :
130130 self .log .error (
131- "exception when getting mirror mode for {}/{}/{}: {}" .format (
131+ "exception when getting mirror info for {}/{}/{}: {}" .format (
132132 pool_id , namespace , image_id , e ))
133133 self .close_image (image_spec , image )
134134
135- def handle_get_mirror_mode (self ,
135+ def handle_get_mirror_info (self ,
136136 image_spec : ImageSpec ,
137137 image : rbd .Image ,
138138 comp : rados .Completion ,
139- mode : Optional [int ]) -> None :
139+ info : Optional [Dict [ str , Union [ str , int ]] ]) -> None :
140140 pool_id , namespace , image_id = image_spec
141141
142142 self .log .debug (
143- "CreateSnapshotRequests.handle_get_mirror_mode {}/{}/{}: r={} mode ={}" .format (
144- pool_id , namespace , image_id , comp .get_return_value (), mode ))
143+ "CreateSnapshotRequests.handle_get_mirror_info {}/{}/{}: r={} info ={}" .format (
144+ pool_id , namespace , image_id , comp .get_return_value (), info ))
145145
146- if mode is None :
147- if comp .get_return_value () != - errno .ENOENT :
148- self .log .error (
149- "error when getting mirror mode for {}/{}/{}: {}" .format (
150- pool_id , namespace , image_id , comp .get_return_value ()))
146+ if info is None :
147+ self .log .error (
148+ "error when getting mirror info for {}/{}/{}: {}" .format (
149+ pool_id , namespace , image_id , comp .get_return_value ()))
151150 self .close_image (image_spec , image )
152151 return
153152
154- if mode != rbd .RBD_MIRROR_IMAGE_MODE_SNAPSHOT :
153+ if info [ 'state' ] != rbd .RBD_MIRROR_IMAGE_ENABLED :
155154 self .log .debug (
156- "CreateSnapshotRequests.handle_get_mirror_mode : {}/{}/{}: {}" .format (
155+ "CreateSnapshotRequests.handle_get_mirror_info : {}/{}/{}: {}" .format (
157156 pool_id , namespace , image_id ,
158- "snapshot mirroring is not enabled" ))
157+ "mirroring is not enabled" ))
159158 self .close_image (image_spec , image )
160159 return
161160
162- self .get_mirror_info (image_spec , image )
161+ if not info ['primary' ]:
162+ self .log .debug (
163+ "CreateSnapshotRequests.handle_get_mirror_info: {}/{}/{}: {}" .format (
164+ pool_id , namespace , image_id ,
165+ "is not primary" ))
166+ self .close_image (image_spec , image )
167+ return
163168
164- def get_mirror_info (self , image_spec : ImageSpec , image : rbd .Image ) -> None :
169+ self .get_mirror_mode (image_spec , image )
170+
171+ def get_mirror_mode (self , image_spec : ImageSpec , image : rbd .Image ) -> None :
165172 pool_id , namespace , image_id = image_spec
166173
167- self .log .debug ("CreateSnapshotRequests.get_mirror_info : {}/{}/{}" .format (
174+ self .log .debug ("CreateSnapshotRequests.get_mirror_mode : {}/{}/{}" .format (
168175 pool_id , namespace , image_id ))
169176
170- def cb (comp : rados .Completion , info : Optional [Dict [ str , Union [ str , int ]] ]) -> None :
171- self .handle_get_mirror_info (image_spec , image , comp , info )
177+ def cb (comp : rados .Completion , mode : Optional [int ]) -> None :
178+ self .handle_get_mirror_mode (image_spec , image , comp , mode )
172179
173180 try :
174- image .aio_mirror_image_get_info (cb )
181+ image .aio_mirror_image_get_mode (cb )
175182 except Exception as e :
176183 self .log .error (
177- "exception when getting mirror info for {}/{}/{}: {}" .format (
184+ "exception when getting mirror mode for {}/{}/{}: {}" .format (
178185 pool_id , namespace , image_id , e ))
179186 self .close_image (image_spec , image )
180187
181- def handle_get_mirror_info (self ,
188+ def handle_get_mirror_mode (self ,
182189 image_spec : ImageSpec ,
183190 image : rbd .Image ,
184191 comp : rados .Completion ,
185- info : Optional [Dict [ str , Union [ str , int ]] ]) -> None :
192+ mode : Optional [int ]) -> None :
186193 pool_id , namespace , image_id = image_spec
187194
188195 self .log .debug (
189- "CreateSnapshotRequests.handle_get_mirror_info {}/{}/{}: r={} info ={}" .format (
190- pool_id , namespace , image_id , comp .get_return_value (), info ))
196+ "CreateSnapshotRequests.handle_get_mirror_mode {}/{}/{}: r={} mode ={}" .format (
197+ pool_id , namespace , image_id , comp .get_return_value (), mode ))
191198
192- if info is None :
193- if comp .get_return_value () != - errno .ENOENT :
194- self .log .error (
195- "error when getting mirror info for {}/{}/{}: {}" .format (
196- pool_id , namespace , image_id , comp .get_return_value ()))
199+ if mode is None :
200+ self .log .error (
201+ "error when getting mirror mode for {}/{}/{}: {}" .format (
202+ pool_id , namespace , image_id , comp .get_return_value ()))
197203 self .close_image (image_spec , image )
198204 return
199205
200- if not info [ 'primary' ] :
206+ if mode != rbd . RBD_MIRROR_IMAGE_MODE_SNAPSHOT :
201207 self .log .debug (
202- "CreateSnapshotRequests.handle_get_mirror_info : {}/{}/{}: {}" .format (
208+ "CreateSnapshotRequests.handle_get_mirror_mode : {}/{}/{}: {}" .format (
203209 pool_id , namespace , image_id ,
204- "is not primary " ))
210+ "not enabled for snapshot mirroring " ))
205211 self .close_image (image_spec , image )
206212 return
207213
0 commit comments