[v7,5/9] unix: Rename unlink_stale to unlink_sk

Submitted by Cyrill Gorcunov on May 23, 2018, 4:06 p.m.

Details

Message ID 20180523160615.31428-6-gorcunov@gmail.com
State New
Series "Add support of deleted unix sockets"
Headers show

Commit Message

Cyrill Gorcunov May 23, 2018, 4:06 p.m.
We gonna use it to detele not only stale
sockets but ghost sockets as well.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
 criu/sk-unix.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/sk-unix.c b/criu/sk-unix.c
index c0d2289d8229..4f5e00de061e 100644
--- a/criu/sk-unix.c
+++ b/criu/sk-unix.c
@@ -1758,11 +1758,11 @@  static struct file_desc_ops unix_desc_ops = {
  * Make FS clean from sockets we're about to
  * restore. See for how we bind them for details
  */
-static void unlink_stale(struct unix_sk_info *ui)
+static void unlink_sk(struct unix_sk_info *ui)
 {
 	int ret, cwd_fd = -1, root_fd = -1, ns_fd = -1;
 
-	if (ui->name[0] == '\0' || (ui->ue->uflags & USK_EXTERN))
+	if (!ui->name || ui->name[0] == '\0' || (ui->ue->uflags & USK_EXTERN))
 		return;
 
 	if (prep_unix_sk_cwd(ui, &cwd_fd, &root_fd, NULL))
@@ -1770,10 +1770,15 @@  static void unlink_stale(struct unix_sk_info *ui)
 
 	ret = unlinkat(AT_FDCWD, ui->name, 0) ? -1 : 0;
 	if (ret < 0 && errno != ENOENT) {
-		pr_warn("Can't unlink stale socket %#x peer %#x (name %s dir %s)\n",
+		pr_warn("Can't unlink socket %#x peer %#x (name %s dir %s)\n",
 			ui->ue->ino, ui->ue->peer,
 			ui->name ? (ui->name[0] ? ui->name : &ui->name[1]) : "-",
 			ui->name_dir ? ui->name_dir : "-");
+	} else if (ret == 0) {
+		pr_debug("Unlinked socket %#x peer %#x (name %s dir %s)\n",
+			 ui->ue->ino, ui->ue->peer,
+			 ui->name ? (ui->name[0] ? ui->name : &ui->name[1]) : "-",
+			 ui->name_dir ? ui->name_dir : "-");
 	}
 	revert_unix_sk_cwd(ui, &cwd_fd, &root_fd, &ns_fd);
 }
@@ -1788,8 +1793,7 @@  static int post_prepare_unix_sk(struct pprep_head *ph)
 	ui = container_of(ph, struct unix_sk_info, peer_resolve);
 	if (ui->ue->peer && fixup_unix_peer(ui))
 		return -1;
-	if (ui->name)
-		unlink_stale(ui);
+	unlink_sk(ui);
 	return 0;
 }
 

Comments

Andrey Vagin June 4, 2018, 6:51 p.m.
This patch contains changes which are inconsistent with the subject
description.

On Wed, May 23, 2018 at 07:06:11PM +0300, Cyrill Gorcunov wrote:
> We gonna use it to detele not only stale
> sockets but ghost sockets as well.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
> ---
>  criu/sk-unix.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/criu/sk-unix.c b/criu/sk-unix.c
> index c0d2289d8229..4f5e00de061e 100644
> --- a/criu/sk-unix.c
> +++ b/criu/sk-unix.c
> @@ -1758,11 +1758,11 @@ static struct file_desc_ops unix_desc_ops = {
>   * Make FS clean from sockets we're about to
>   * restore. See for how we bind them for details
>   */
> -static void unlink_stale(struct unix_sk_info *ui)
> +static void unlink_sk(struct unix_sk_info *ui)
>  {
>  	int ret, cwd_fd = -1, root_fd = -1, ns_fd = -1;
>  
> -	if (ui->name[0] == '\0' || (ui->ue->uflags & USK_EXTERN))
> +	if (!ui->name || ui->name[0] == '\0' || (ui->ue->uflags & USK_EXTERN))
>  		return;
>  
>  	if (prep_unix_sk_cwd(ui, &cwd_fd, &root_fd, NULL))
> @@ -1770,10 +1770,15 @@ static void unlink_stale(struct unix_sk_info *ui)
>  
>  	ret = unlinkat(AT_FDCWD, ui->name, 0) ? -1 : 0;
>  	if (ret < 0 && errno != ENOENT) {
> -		pr_warn("Can't unlink stale socket %#x peer %#x (name %s dir %s)\n",
> +		pr_warn("Can't unlink socket %#x peer %#x (name %s dir %s)\n",
>  			ui->ue->ino, ui->ue->peer,
>  			ui->name ? (ui->name[0] ? ui->name : &ui->name[1]) : "-",
>  			ui->name_dir ? ui->name_dir : "-");
> +	} else if (ret == 0) {
> +		pr_debug("Unlinked socket %#x peer %#x (name %s dir %s)\n",
> +			 ui->ue->ino, ui->ue->peer,
> +			 ui->name ? (ui->name[0] ? ui->name : &ui->name[1]) : "-",
> +			 ui->name_dir ? ui->name_dir : "-");
>  	}
>  	revert_unix_sk_cwd(ui, &cwd_fd, &root_fd, &ns_fd);
>  }
> @@ -1788,8 +1793,7 @@ static int post_prepare_unix_sk(struct pprep_head *ph)
>  	ui = container_of(ph, struct unix_sk_info, peer_resolve);
>  	if (ui->ue->peer && fixup_unix_peer(ui))
>  		return -1;
> -	if (ui->name)
> -		unlink_stale(ui);
> +	unlink_sk(ui);
>  	return 0;
>  }
>  
> -- 
> 2.14.3
>
Cyrill Gorcunov June 4, 2018, 7:29 p.m.
On Mon, Jun 04, 2018 at 11:51:07AM -0700, Andrey Vagin wrote:
> This patch contains changes which are inconsistent with the subject
> description.

Well, the changes make it general unlink_sk helper for this
sake I had to add some more changes to cover cases where the
helper can be called from any context.