Revision 1d3dfa29 lib/impexpd/__init__.py
b/lib/impexpd/__init__.py | ||
---|---|---|
115 | 115 |
self._dd_stderr_fd = dd_stderr_fd |
116 | 116 |
self._dd_pid_fd = dd_pid_fd |
117 | 117 |
|
118 |
assert (self._opts.magic is None or |
|
119 |
constants.IE_MAGIC_RE.match(self._opts.magic)) |
|
120 |
|
|
118 | 121 |
@staticmethod |
119 | 122 |
def GetBashCommand(cmd): |
120 | 123 |
"""Prepares a command to be run in Bash. |
... | ... | |
197 | 200 |
",".join(addr1), ",".join(addr2) |
198 | 201 |
] |
199 | 202 |
|
203 |
def _GetMagicCommand(self): |
|
204 |
"""Returns the command to read/write the magic value. |
|
205 |
|
|
206 |
""" |
|
207 |
if not self._opts.magic: |
|
208 |
return None |
|
209 |
|
|
210 |
# Prefix to ensure magic isn't interpreted as option to "echo" |
|
211 |
magic = "M=%s" % self._opts.magic |
|
212 |
|
|
213 |
cmd = StringIO() |
|
214 |
|
|
215 |
if self._mode == constants.IEM_IMPORT: |
|
216 |
cmd.write("{ ") |
|
217 |
cmd.write(utils.ShellQuoteArgs(["read", "-n", str(len(magic)), "magic"])) |
|
218 |
cmd.write(" && ") |
|
219 |
cmd.write("if test \"$magic\" != %s; then" % utils.ShellQuote(magic)) |
|
220 |
cmd.write(" echo %s >&2;" % utils.ShellQuote("Magic value mismatch")) |
|
221 |
cmd.write(" exit 1;") |
|
222 |
cmd.write("fi;") |
|
223 |
cmd.write(" }") |
|
224 |
|
|
225 |
elif self._mode == constants.IEM_EXPORT: |
|
226 |
cmd.write(utils.ShellQuoteArgs(["echo", "-E", "-n", magic])) |
|
227 |
|
|
228 |
else: |
|
229 |
raise errors.GenericError("Invalid mode '%s'" % self._mode) |
|
230 |
|
|
231 |
return cmd.getvalue() |
|
232 |
|
|
200 | 233 |
def _GetDdCommand(self): |
201 | 234 |
"""Returns the command for measuring throughput. |
202 | 235 |
|
203 | 236 |
""" |
204 | 237 |
dd_cmd = StringIO() |
238 |
|
|
239 |
magic_cmd = self._GetMagicCommand() |
|
240 |
if magic_cmd: |
|
241 |
dd_cmd.write("{ ") |
|
242 |
dd_cmd.write(magic_cmd) |
|
243 |
dd_cmd.write(" && ") |
|
244 |
|
|
245 |
dd_cmd.write("{ ") |
|
205 | 246 |
# Setting LC_ALL since we want to parse the output and explicitely |
206 | 247 |
# redirecting stdin, as the background process (dd) would have /dev/null as |
207 | 248 |
# stdin otherwise |
208 |
dd_cmd.write("{ LC_ALL=C dd bs=%s <&0 2>&%d & pid=${!};" %
|
|
249 |
dd_cmd.write("LC_ALL=C dd bs=%s <&0 2>&%d & pid=${!};" % |
|
209 | 250 |
(BUFSIZE, self._dd_stderr_fd)) |
210 | 251 |
# Send PID to daemon |
211 | 252 |
dd_cmd.write(" echo $pid >&%d;" % self._dd_pid_fd) |
212 | 253 |
# And wait for dd |
213 | 254 |
dd_cmd.write(" wait $pid;") |
214 | 255 |
dd_cmd.write(" }") |
256 |
|
|
257 |
if magic_cmd: |
|
258 |
dd_cmd.write(" }") |
|
259 |
|
|
215 | 260 |
return dd_cmd.getvalue() |
216 | 261 |
|
217 | 262 |
def _GetTransportCommand(self): |
Also available in: Unified diff