phaul: use relative path for parent link

Submitted by Jacob Wen on Nov. 20, 2017, 8:03 a.m.

Details

Message ID 1511165023-1736-1-git-send-email-jian.w.wen@oracle.com
State Accepted
Series "phaul: use relative path for parent link"
Commit bad24ee436c9ef2c9738c0c64145bc017f82f06e
Headers show

Commit Message

Jacob Wen Nov. 20, 2017, 8:03 a.m.
Absolute paths for parent links may not work on restore.
e.g: restore on a different server(during migration).

See https://github.com/checkpoint-restore/criu/blob/criu-2.x-stable/criu/image.c#L432

Signed-off-by: Jacob Wen <jian.w.wen@oracle.com>
---
 phaul/src/phaul/server.go | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/phaul/src/phaul/server.go b/phaul/src/phaul/server.go
index 0994fb9..7449e63 100644
--- a/phaul/src/phaul/server.go
+++ b/phaul/src/phaul/server.go
@@ -7,6 +7,7 @@  import (
 	"github.com/golang/protobuf/proto"
 	"github.com/checkpoint-restore/criu/lib/go/src/criu"
 	"github.com/checkpoint-restore/criu/lib/go/src/rpc"
+	"path/filepath"
 )
 
 type PhaulServer struct {
@@ -54,7 +55,15 @@  func (s *PhaulServer) StartIter() error {
 
 	opts.ImagesDirFd = proto.Int32(int32(img_dir.Fd()))
 	if prev_p != "" {
-		opts.ParentImg = proto.String(prev_p)
+		p, err := filepath.Abs(img_dir.Name())
+		if err != nil {
+			return err
+		}
+		rel, err := filepath.Rel(p, prev_p)
+		if err != nil {
+			return err
+		}
+		opts.ParentImg = proto.String(rel)
 	}
 
 	pid, _, err := s.cr.StartPageServerChld(opts)

Comments

Andrey Vagin Nov. 25, 2017, 6:03 p.m.
Applied, thanks!

On Mon, Nov 20, 2017 at 04:03:43PM +0800, Jacob Wen wrote:
> Absolute paths for parent links may not work on restore.
> e.g: restore on a different server(during migration).
> 
> See https://github.com/checkpoint-restore/criu/blob/criu-2.x-stable/criu/image.c#L432
> 
> Signed-off-by: Jacob Wen <jian.w.wen@oracle.com>
> ---
>  phaul/src/phaul/server.go | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/phaul/src/phaul/server.go b/phaul/src/phaul/server.go
> index 0994fb9..7449e63 100644
> --- a/phaul/src/phaul/server.go
> +++ b/phaul/src/phaul/server.go
> @@ -7,6 +7,7 @@ import (
>  	"github.com/golang/protobuf/proto"
>  	"github.com/checkpoint-restore/criu/lib/go/src/criu"
>  	"github.com/checkpoint-restore/criu/lib/go/src/rpc"
> +	"path/filepath"
>  )
>  
>  type PhaulServer struct {
> @@ -54,7 +55,15 @@ func (s *PhaulServer) StartIter() error {
>  
>  	opts.ImagesDirFd = proto.Int32(int32(img_dir.Fd()))
>  	if prev_p != "" {
> -		opts.ParentImg = proto.String(prev_p)
> +		p, err := filepath.Abs(img_dir.Name())
> +		if err != nil {
> +			return err
> +		}
> +		rel, err := filepath.Rel(p, prev_p)
> +		if err != nil {
> +			return err
> +		}
> +		opts.ParentImg = proto.String(rel)
>  	}
>  
>  	pid, _, err := s.cr.StartPageServerChld(opts)
> -- 
> 2.7.4
>