Revision 229fb4ea lib/backend.py
b/lib/backend.py | ||
---|---|---|
37 | 37 |
# C0302: This module has become too big and should be split up |
38 | 38 |
|
39 | 39 |
|
40 |
import base64 |
|
41 |
import errno |
|
42 |
import logging |
|
40 | 43 |
import os |
41 | 44 |
import os.path |
45 |
import random |
|
46 |
import re |
|
42 | 47 |
import shutil |
43 |
import time
|
|
48 |
import signal
|
|
44 | 49 |
import stat |
45 |
import errno |
|
46 |
import re |
|
47 |
import random |
|
48 |
import logging |
|
49 | 50 |
import tempfile |
51 |
import time |
|
50 | 52 |
import zlib |
51 |
import base64 |
|
52 |
import signal |
|
53 | 53 |
|
54 | 54 |
from ganeti import errors |
55 | 55 |
from ganeti import utils |
... | ... | |
2233 | 2233 |
return device.unique_id |
2234 | 2234 |
|
2235 | 2235 |
|
2236 |
def _WipeDevice(path, offset, size):
|
|
2237 |
"""This function actually wipes the device.
|
|
2236 |
def _DumpDevice(source_path, target_path, offset, size):
|
|
2237 |
"""This function images/wipes the device using a local file.
|
|
2238 | 2238 |
|
2239 |
@param path: The path to the device to wipe |
|
2240 |
@param offset: The offset in MiB in the file |
|
2241 |
@param size: The size in MiB to write |
|
2239 |
@type source_path: string |
|
2240 |
@param source_path: path of the image or data source (e.g., "/dev/zero") |
|
2241 |
|
|
2242 |
@type target_path: string |
|
2243 |
@param target_path: path of the device to image/wipe |
|
2244 |
|
|
2245 |
@type offset: int |
|
2246 |
@param offset: offset in MiB in the output file |
|
2247 |
|
|
2248 |
@type size: int |
|
2249 |
@param size: maximum size in MiB to write (data source might be smaller) |
|
2250 |
|
|
2251 |
@return: None |
|
2252 |
@raise RPCFail: in case of failure |
|
2242 | 2253 |
|
2243 | 2254 |
""" |
2244 | 2255 |
# Internal sizes are always in Mebibytes; if the following "dd" command |
... | ... | |
2246 | 2257 |
# function must be adjusted accordingly before being passed to "dd". |
2247 | 2258 |
block_size = 1024 * 1024 |
2248 | 2259 |
|
2249 |
cmd = [constants.DD_CMD, "if=/dev/zero", "seek=%d" % offset,
|
|
2250 |
"bs=%s" % block_size, "oflag=direct", "of=%s" % path, |
|
2260 |
cmd = [constants.DD_CMD, "if=%s" % source_path, "seek=%d" % offset,
|
|
2261 |
"bs=%s" % block_size, "oflag=direct", "of=%s" % target_path,
|
|
2251 | 2262 |
"count=%d" % size] |
2252 | 2263 |
result = utils.RunCmd(cmd) |
2253 | 2264 |
|
2254 | 2265 |
if result.failed: |
2255 |
_Fail("Wipe command '%s' exited with error: %s; output: %s", result.cmd,
|
|
2266 |
_Fail("Dump command '%s' exited with error: %s; output: %s", result.cmd,
|
|
2256 | 2267 |
result.fail_reason, result.output) |
2257 | 2268 |
|
2258 | 2269 |
|
... | ... | |
2273 | 2284 |
rdev = None |
2274 | 2285 |
|
2275 | 2286 |
if not rdev: |
2276 |
_Fail("Cannot execute wipe for device %s: device not found", disk.iv_name) |
|
2277 |
|
|
2278 |
# Do cross verify some of the parameters |
|
2287 |
_Fail("Cannot wipe device %s: device not found", disk.iv_name) |
|
2279 | 2288 |
if offset < 0: |
2280 | 2289 |
_Fail("Negative offset") |
2281 | 2290 |
if size < 0: |
2282 | 2291 |
_Fail("Negative size") |
2283 | 2292 |
if offset > rdev.size: |
2284 |
_Fail("Offset is bigger than device size")
|
|
2293 |
_Fail("Wipe offset is bigger than device size")
|
|
2285 | 2294 |
if (offset + size) > rdev.size: |
2286 |
_Fail("The provided offset and size to wipe is bigger than device size") |
|
2295 |
_Fail("Wipe offset and size are bigger than device size") |
|
2296 |
|
|
2297 |
_DumpDevice("/dev/zero", rdev.dev_path, offset, size) |
|
2287 | 2298 |
|
2288 |
_WipeDevice(rdev.dev_path, offset, size) |
|
2289 | 2299 |
|
2290 | 2300 |
|
2291 | 2301 |
def BlockdevPauseResumeSync(disks, pause): |
Also available in: Unified diff