Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add volume id, gotten from mount request, to the mountpath #2356

Merged
merged 3 commits into from
Oct 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions api/server/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -651,6 +651,7 @@ func (d *driver) mount(w http.ResponseWriter, r *http.Request) {

// get spec and name from request
_, spec, _, _, name := d.SpecFromString(request.Name)
nameWithID := name + request.ID
attachOptions := d.attachOptionsFromSpec(spec)

// attach token in context metadata
Expand Down Expand Up @@ -686,7 +687,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 {
Expand Down Expand Up @@ -857,14 +858,16 @@ func (d *driver) unmount(w http.ResponseWriter, r *http.Request) {
}

_, _, _, _, name := d.SpecFromString(request.Name)
nameWithID := name + request.ID
vol, err := d.volFromName(name)
if err != nil {
e := d.volNotFound(method, name, err, w)
d.errorResponse(method, w, e)
return
}

mountpoint := d.mountpath(name)
mountpoint := d.mountpath(nameWithID)
mountpointWithoutID := d.mountpath(name)
id := vol.Id
if vol.Spec.Scale > 1 {
id = v.MountedAt(ctx, mountpoint)
Expand All @@ -882,6 +885,18 @@ 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(
"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(
Expand Down