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

Storage: Check if device has appeared in /dev/zd* when activating or creating a volume #13662

Merged
merged 1 commit into from
Jun 25, 2024
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
32 changes: 23 additions & 9 deletions lxd/storage/drivers/driver_zfs_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,13 @@ func (d *zfs) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Oper
ctx, cancel := context.WithTimeout(d.state.ShutdownCtx, 30*time.Second)
defer cancel()

if !tryExists(ctx, filepath.Join("/dev/zvol", d.dataset(vol, false))) {
return fmt.Errorf("Failed to activate created volume %q", vol.name)
}

zfsFilesystem := vol.ConfigBlockFilesystem()

devPath, err := d.GetVolumeDiskPath(vol)
devPath, err := d.tryGetVolumeDiskPathFromDataset(ctx, d.dataset(vol, false))
if err != nil {
return err
}

zfsFilesystem := vol.ConfigBlockFilesystem()

_, err = makeFSType(devPath, zfsFilesystem, nil)
if err != nil {
return err
Expand Down Expand Up @@ -1912,6 +1908,23 @@ func (d *zfs) SetVolumeQuota(vol Volume, size string, allowUnsafeResize bool, op
return nil
}

// tryGetVolumeDiskPathFromDataset attempts to find the path of the block device for the given dataset.
// It keeps retrying every half a second until the context is canceled or expires.
func (d *zfs) tryGetVolumeDiskPathFromDataset(ctx context.Context, dataset string) (string, error) {
for {
MusicDin marked this conversation as resolved.
Show resolved Hide resolved
if ctx.Err() != nil {
return "", fmt.Errorf("Failed to locate zvol for %q: %w", dataset, ctx.Err())
}

diskPath, err := d.getVolumeDiskPathFromDataset(dataset)
if err == nil {
return diskPath, nil
}

time.Sleep(500 * time.Millisecond)
}
}

func (d *zfs) getVolumeDiskPathFromDataset(dataset string) (string, error) {
// Shortcut for udev.
if shared.PathExists(filepath.Join("/dev/zvol", dataset)) {
Expand Down Expand Up @@ -2116,8 +2129,9 @@ func (d *zfs) activateVolume(vol Volume) (bool, error) {
ctx, cancel := context.WithTimeout(d.state.ShutdownCtx, 30*time.Second)
defer cancel()

if !tryExists(ctx, filepath.Join("/dev/zvol", dataset)) {
return false, fmt.Errorf("Failed to activate volume %q", vol.name)
_, err := d.tryGetVolumeDiskPathFromDataset(ctx, dataset)
if err != nil {
return false, fmt.Errorf("Failed to activate volume: %v", err)
}

d.logger.Debug("Activated ZFS volume", logger.Ctx{"volName": vol.Name(), "dev": dataset})
Expand Down
Loading