@@ -225,10 +225,6 @@ func (d *SSLVMDisk) CreateSnapshot(snapshotId string, encryptKey string, encForm
225225 return nil
226226}
227227
228- func (d * SSLVMDisk ) PostCreateFromRemoteHostImage (string ) {
229- log .Infof ("slvm post create from fuse do nothing" )
230- }
231-
232228func (d * SSLVMDisk ) ResetFromSnapshot (ctx context.Context , params interface {}) (jsonutils.JSONObject , error ) {
233229 err := lvmutils .LVActive (d .GetPath (), false , d .Storage .Lvmlockd ())
234230 if err != nil {
@@ -304,6 +300,43 @@ func (d *SSLVMDisk) CreateFromSnapshotLocation(ctx context.Context, snapshotLoca
304300 return ret , nil
305301}
306302
303+ func (d * SSLVMDisk ) PostCreateFromRemoteHostImage (diskUrl string , snapshotId string ) {
304+ if len (snapshotId ) == 0 {
305+ return
306+ }
307+ snapshotPath := d .GetSnapshotPath (snapshotId )
308+
309+ curPath := snapshotPath
310+ for {
311+ if ! fileutils2 .Exists (curPath ) {
312+ break
313+ }
314+ if inUse , err := lvmutils .IsDeviceInUse (curPath ); inUse {
315+ log .Errorf ("slvm PostCreateFromRemoteHostImage %s inuse" , curPath )
316+ break
317+ } else if err != nil {
318+ log .Errorf ("slvm PostCreateFromRemoteHostImage failed check device %s is inuse: %s" , curPath , err )
319+ break
320+ }
321+
322+ img , err := qemuimg .NewQemuImage (curPath )
323+ if err != nil {
324+ log .Errorf ("failed open qemu image %s: %s" , curPath , err )
325+ break
326+ }
327+ backPath := img .BackFilePath
328+ if err := lvmutils .LVDeactivate (curPath ); err != nil {
329+ log .Errorf ("failed deactivate lv %s: %s" , curPath , err )
330+ break
331+ }
332+ if len (backPath ) == 0 || strings .HasPrefix (path .Base (backPath ), IMAGECACHE_PREFIX ) {
333+ break
334+ } else {
335+ curPath = backPath
336+ }
337+ }
338+ }
339+
307340func (d * SSLVMDisk ) DeleteSnapshot (snapshotId , convertSnapshot string , blockStream bool , encryptInfo apis.SEncryptInfo ) error {
308341 err := lvmutils .LVActive (d .GetPath (), false , d .Storage .Lvmlockd ())
309342 if err != nil {
0 commit comments