From 8253002c2ba49cd9770301454080c483792fbb21 Mon Sep 17 00:00:00 2001 From: Vignesh Laxman Date: Sat, 7 Oct 2023 04:09:21 +0000 Subject: [PATCH 1/3] Add volume id got from mount request to path Signed-off-by: Vignesh Laxman --- api/server/docker.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/api/server/docker.go b/api/server/docker.go index 2f07d3122..11bbaabc2 100644 --- a/api/server/docker.go +++ b/api/server/docker.go @@ -318,8 +318,8 @@ func (d *driver) status(w http.ResponseWriter, r *http.Request) { io.WriteString(w, fmt.Sprintln("osd plugin", d.version)) } -func (d *driver) mountpath(name string) string { - return path.Join(volume.MountBase, name) +func (d *driver) mountpath(nameWithID string) string { + return path.Join(volume.MountBase, nameWithID) } func (d *driver) getConn() (*grpc.ClientConn, error) { @@ -651,6 +651,8 @@ func (d *driver) mount(w http.ResponseWriter, r *http.Request) { // get spec and name from request _, spec, _, _, name := d.SpecFromString(request.Name) + _, _, _, _, volID := d.SpecFromString(request.ID) + nameWithID := name + volID attachOptions := d.attachOptionsFromSpec(spec) // attach token in context metadata @@ -686,7 +688,7 @@ func (d *driver) mount(w http.ResponseWriter, r *http.Request) { // If a scaled volume is already mounted, check if it can be unmounted and // detached. If not return an error. - mountpoint := d.mountpath(name) + mountpoint := d.mountpath(nameWithID) if vol.Spec.Scale > 1 { id := v.MountedAt(ctx, mountpoint) if len(id) != 0 { @@ -857,6 +859,8 @@ func (d *driver) unmount(w http.ResponseWriter, r *http.Request) { } _, _, _, _, name := d.SpecFromString(request.Name) + _, _, _, _, volID := d.SpecFromString(request.ID) + nameWithID := name + volID vol, err := d.volFromName(name) if err != nil { e := d.volNotFound(method, name, err, w) @@ -864,7 +868,7 @@ func (d *driver) unmount(w http.ResponseWriter, r *http.Request) { return } - mountpoint := d.mountpath(name) + mountpoint := d.mountpath(nameWithID) id := vol.Id if vol.Spec.Scale > 1 { id = v.MountedAt(ctx, mountpoint) From 1a745366ef535f8122a862a06ee052b39890da85 Mon Sep 17 00:00:00 2001 From: Vignesh Laxman Date: Mon, 16 Oct 2023 06:25:19 +0000 Subject: [PATCH 2/3] Add Unmount() function for mountpath without ID Signed-off-by: Vignesh Laxman --- api/server/docker.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/api/server/docker.go b/api/server/docker.go index 11bbaabc2..12b34d115 100644 --- a/api/server/docker.go +++ b/api/server/docker.go @@ -869,6 +869,7 @@ func (d *driver) unmount(w http.ResponseWriter, r *http.Request) { } mountpoint := d.mountpath(nameWithID) + mountpointWithoutID := d.mountpath(name) id := vol.Id if vol.Spec.Scale > 1 { id = v.MountedAt(ctx, mountpoint) @@ -886,6 +887,15 @@ func (d *driver) unmount(w http.ResponseWriter, r *http.Request) { opts := make(map[string]string) opts[options.OptionsDeleteAfterUnmount] = "true" + errWithoutID := v.Unmount(correlation.TODO(), id, mountpointWithoutID, opts) + if errWithoutID != nil { + d.logRequest(method, request.Name).Warnf( + "Cannot unmount volume %v, %v", + mountpointWithoutID, err) + d.errorResponse(method, w, err) + return + } + err = v.Unmount(correlation.TODO(), id, mountpoint, opts) if err != nil { d.logRequest(method, request.Name).Warnf( From e65e7ef2c26cdfdd251b29d6394809a7c624aff4 Mon Sep 17 00:00:00 2001 From: Vignesh Laxman Date: Tue, 17 Oct 2023 03:35:07 +0000 Subject: [PATCH 3/3] Code modification and comment addition for two Unmount() Signed-off-by: Vignesh Laxman --- api/server/docker.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/api/server/docker.go b/api/server/docker.go index 12b34d115..5597d7e3c 100644 --- a/api/server/docker.go +++ b/api/server/docker.go @@ -651,8 +651,7 @@ func (d *driver) mount(w http.ResponseWriter, r *http.Request) { // get spec and name from request _, spec, _, _, name := d.SpecFromString(request.Name) - _, _, _, _, volID := d.SpecFromString(request.ID) - nameWithID := name + volID + nameWithID := name + request.ID attachOptions := d.attachOptionsFromSpec(spec) // attach token in context metadata @@ -859,8 +858,7 @@ func (d *driver) unmount(w http.ResponseWriter, r *http.Request) { } _, _, _, _, name := d.SpecFromString(request.Name) - _, _, _, _, volID := d.SpecFromString(request.ID) - nameWithID := name + volID + nameWithID := name + request.ID vol, err := d.volFromName(name) if err != nil { e := d.volNotFound(method, name, err, w) @@ -887,6 +885,9 @@ func (d *driver) unmount(w http.ResponseWriter, r *http.Request) { opts := make(map[string]string) opts[options.OptionsDeleteAfterUnmount] = "true" + // Unmount volume mounted at old paths without the ID attached to the path + // The Unmount() function is called twice so that the volume that has been mounted before this version upgrade can be unmounted + // If volume is already unmounted, this is a no-op errWithoutID := v.Unmount(correlation.TODO(), id, mountpointWithoutID, opts) if errWithoutID != nil { d.logRequest(method, request.Name).Warnf(