All of lore.kernel.org
 help / color / mirror / Atom feed
From: Will Deacon <will.deacon@arm.com>
To: Andre Przywara <andre.przywara@arm.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH kvmtool 1/2] list: Clean up ghost socket files
Date: Fri, 24 May 2019 17:27:25 +0100	[thread overview]
Message-ID: <20190524162725.GB8993@fuggles.cambridge.arm.com> (raw)
In-Reply-To: <20190503170821.260705-2-andre.przywara@arm.com>

On Fri, May 03, 2019 at 06:08:20PM +0100, Andre Przywara wrote:
> When kvmtool (or the host kernel) crashes or gets killed, we cannot
> automatically remove the socket file we created for that VM.
> A later call of "lkvm list" iterates over all those files and complains
> about those "ghost socket files", as there is no one listening on
> the other side. Also sometimes the automatic guest name generation
> happens to generate the same name again, so an unrelated "lkvm run"
> later complains and stops, which is bad for automation.
> 
> As the only code doing a listen() on this socket is kvmtool upon VM
> *creation*, such an orphaned socket file will never come back to life,
> so we can as well unlink() those sockets in the code. This spares the
> user the messages and the burden of doing it herself.
> We keep a message in the code to notify the user of this.
> 
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> ---
>  kvm-ipc.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/kvm-ipc.c b/kvm-ipc.c
> index e07ad105..d9a07595 100644
> --- a/kvm-ipc.c
> +++ b/kvm-ipc.c
> @@ -101,9 +101,8 @@ int kvm__get_sock_by_instance(const char *name)
>  
>  	r = connect(s, (struct sockaddr *)&local, len);
>  	if (r < 0 && errno == ECONNREFUSED) {
> -		/* Tell the user clean ghost socket file */
> -		pr_err("\"%s\" could be a ghost socket file, please remove it",
> -				sock_file);
> +		/* Clean up the ghost socket file */
> +		unlink(local.sun_path);
>  		return r;
>  	} else if (r < 0) {
>  		return r;
> @@ -140,6 +139,7 @@ int kvm__enumerate_instances(int (*callback)(const char *name, int fd))
>  	struct dirent *entry;
>  	int ret = 0;
>  	const char *path;
> +	int cleaned = 0;
>  
>  	path = kvm__get_dir();
>  
> @@ -164,8 +164,11 @@ int kvm__enumerate_instances(int (*callback)(const char *name, int fd))
>  
>  			*p = 0;
>  			sock = kvm__get_sock_by_instance(entry->d_name);
> -			if (sock < 0)
> +			if (sock < 0) {
> +				if (errno == ECONNREFUSED)
> +					cleaned++;

This is fragile, because you're relying on errno being preserved from the
failing connect() call after kvm__get_sock_by_instance() returns. Yes,
that's true today, but it would be easy to change
kvm__get_sock_by_instance() in future and miss this detail.

Maybe just replace the existing print to that it says about each file being
removed?

Will

  reply	other threads:[~2019-05-24 16:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-03 17:08 [PATCH kvmtool 0/2] Automatically clean up ghost socket files Andre Przywara
2019-05-03 17:08 ` [PATCH kvmtool 1/2] list: Clean " Andre Przywara
2019-05-24 16:27   ` Will Deacon [this message]
2019-05-03 17:08 ` [PATCH kvmtool 2/2] run: Check for ghost socket file upon VM creation Andre Przywara
2019-05-24 16:27   ` Will Deacon

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=20190524162725.GB8993@fuggles.cambridge.arm.com \
    --to=will.deacon@arm.com \
    --cc=andre.przywara@arm.com \
    --cc=kvm@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.