From: Stefan Hajnoczi <stefanha@gmail.com>
To: Ishani Chugh <chugh.ishani@research.iiit.ac.in>
Cc: qemu-devel@nongnu.org, jsnow@redhat.com, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH 1/3] backup: QEMU Backup Tool
Date: Fri, 25 Aug 2017 15:12:10 +0100 [thread overview]
Message-ID: <20170825141210.GA11641@stefanha-x1.localdomain> (raw)
In-Reply-To: <1503493480-21691-2-git-send-email-chugh.ishani@research.iiit.ac.in>
On Wed, Aug 23, 2017 at 06:34:38PM +0530, Ishani Chugh wrote:
> + def write_config(self):
> + """
> + Writes configuration to ini file.
> + """
> + config_file = open(self.config_file+".tmp", 'w')
Please use whitespace around arithmetic operators:
self.config_file + ".tmp"
> + self.config.write(config_file)
> + config_file.flush()
> + os.fsync(config_file.fileno())
> + config_file.close()
> + os.rename(self.config_file+".tmp", self.config_file)
self.config_file + ".tmp"
> +
> + def get_socket_address(self, socket_address):
> + """
> + Return Socket address in form of string or tuple
> + """
> + if socket_address.startswith('tcp'):
> + return (socket_address.split(':')[1],
> + int(socket_address.split(':')[2]))
> + return socket_address.split(':', 2)[1]
> +
> + def _full_backup(self, guest_name):
> + """
> + Performs full backup of guest
> + """
> + if guest_name not in self.config.sections():
> + print("Cannot find specified guest", file=sys.stderr)
> + sys.exit(1)
> +
> + self.verify_guest_running(guest_name)
> + connection = QEMUMonitorProtocol(
> + self.get_socket_address(
> + self.config[guest_name]['qmp']))
> + connection.connect()
> + cmd = {"execute": "transaction", "arguments": {"actions": []}}
> + drive_list = []
> + for key in self.config[guest_name]:
> + if key.startswith("drive_"):
> + drive = key[len('drive_'):]
> + drive_list.append(drive)
> + target = self.config[guest_name][key]
> + sub_cmd = {"type": "drive-backup", "data": {"device": drive,
> + "target": target,
> + "sync": "full"}}
> + cmd['arguments']['actions'].append(sub_cmd)
> + qmp_return = connection.cmd_obj(cmd)
> + if 'error' in qmp_return:
> + print(qmp_return['error']['desc'], file=sys.stderr)
> + sys.exit(1)
> + print("Backup Started")
> + while len(drive_list) != 0:
PEP8 says:
For sequences, (strings, lists, tuples), use the fact that empty sequences are false.
Yes: if not seq:
if seq:
No: if len(seq):
if not len(seq):
This statement should be:
while drive_list:
> + event = connection.pull_event(wait=True)
> + print(event)
Please remove debugging or add a --verbose command-line option that
makes the print statement conditional:
if verbose:
print(event)
> + if event['event'] == 'SHUTDOWN':
> + print("The guest was SHUT DOWN", file=sys.stderr)
> + sys.exit(1)
> +
> + if event['event'] == 'RESET':
> + print("The guest was Rebooted", file=sys.stderr)
> + sys.exit(1)
I think you found this is a soft reset and the blockjob is still
running. There is no need to exit. You can ignore this event.
> +
> + if event['event'] == 'BLOCK_JOB_COMPLETED':
> + if event['data']['device'] in drive_list and \
> + event['data']['type'] == 'backup':
> + print("*"+event['data']['device'])
Please use whitespace around arithmetic operators:
print("*" + event['data']['device'])
> + drive_list.remove(event['data']['device'])
> +
> + if event['event'] == 'BLOCK_JOB_ERROR':
> + if event['data']['device'] in drive_list and \
> + event['data']['type'] == 'backup':
> + print(event['data']['device']+" Backup Failed", file=sys.stderr)
The drive was not removed from drive_list so the loop never terminates.
sys.exit(1)?
next prev parent reply other threads:[~2017-08-25 14:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-23 13:04 [Qemu-devel] [PATCH 0/3] QEMU Backup Tool Ishani Chugh
2017-08-23 13:04 ` [Qemu-devel] [PATCH 1/3] backup: " Ishani Chugh
2017-08-25 14:12 ` Stefan Hajnoczi [this message]
2017-08-23 13:04 ` [Qemu-devel] [PATCH 2/3] Test for full Backup Ishani Chugh
2017-08-25 14:24 ` Stefan Hajnoczi
2017-08-25 14:36 ` Peter Maydell
2017-08-25 15:15 ` John Snow
2017-08-23 13:04 ` [Qemu-devel] [PATCH 3/3] Add manpage for QEMU Backup Tool Ishani Chugh
-- strict thread matches above, loose matches on Subject: below --
2017-08-29 15:50 [Qemu-devel] [PATCH 0/3] " Ishani Chugh
2017-08-29 15:50 ` [Qemu-devel] [PATCH 1/3] backup: " Ishani Chugh
2017-08-29 13:47 [Qemu-devel] [PATCH 0/3] " Ishani Chugh
2017-08-29 13:47 ` [Qemu-devel] [PATCH 1/3] backup: " Ishani Chugh
2017-08-21 11:10 [Qemu-devel] [PATCH 0/3] " Ishani Chugh
2017-08-21 11:10 ` [Qemu-devel] [PATCH 1/3] backup: " Ishani Chugh
2017-08-22 14:13 ` Stefan Hajnoczi
2017-08-22 16:59 ` Ishani
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170825141210.GA11641@stefanha-x1.localdomain \
--to=stefanha@gmail.com \
--cc=chugh.ishani@research.iiit.ac.in \
--cc=jsnow@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).