Permalink
Browse files

Do volume copy without pool open

We just need to get original lv size so we can create another of equal
size. Also, create() takes the vg lock so we now do not nest vgOpen()s
any more.

Signed-off-by: Andy Grover <agrover@redhat.com>
  • Loading branch information...
1 parent f72ccaf commit 0aecb17c255af55abdd5beeece9b0d4094ff81fd @agrover agrover committed Oct 17, 2012
Showing with 24 additions and 24 deletions.
  1. +24 −24 targetd
View
48 targetd
@@ -121,32 +121,32 @@ def copy(req, pool, vol_orig, vol_new, timeout=10):
an async completion and report actual status via async_complete().
"""
with vgopen(pool) as vg:
- orig_lv = vg.lvFromName(vol_orig)
+ copy_size = vg.lvFromName(vol_orig).getSize()
- copy_size = orig_lv.getSize()
- create(req, pool, vol_new, copy_size)
- try:
- src_path = "/dev/%s/%s" % (pool, vol_orig)
- dst_path = "/dev/%s/%s" % (pool, vol_new)
-
- start_time = time.clock()
- with open(src_path, 'rb') as fsrc:
- with open(dst_path, 'wb') as fdst:
- copied = 0
- while copied != copy_size:
- buf = fsrc.read(1024*1024)
- if not buf:
- break
- fdst.write(buf)
- copied += len(buf)
- if time.clock() > (start_time + timeout):
- req.async_completion()
- async_status(req, 0, int((float(copied)/copy_size)*100))
- complete_if_async(req, 0)
+ create(req, pool, vol_new, copy_size)
- except:
- destroy(req, vol_new)
- raise
+ try:
+ src_path = "/dev/%s/%s" % (pool, vol_orig)
+ dst_path = "/dev/%s/%s" % (pool, vol_new)
+
+ start_time = time.clock()
+ with open(src_path, 'rb') as fsrc:
+ with open(dst_path, 'wb') as fdst:
+ copied = 0
+ while copied != copy_size:
+ buf = fsrc.read(1024*1024)
+ if not buf:
+ break
+ fdst.write(buf)
+ copied += len(buf)
+ if time.clock() > (start_time + timeout):
+ req.async_completion()
+ async_status(req, 0, int((float(copied)/copy_size)*100))
+ complete_if_async(req, 0)
+
+ except:
+ destroy(req, vol_new)
+ raise
def export_list(req):
try:

0 comments on commit 0aecb17

Please sign in to comment.