The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/3940
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Closes #3938. Signed-off-by: Christian Brauner <[email protected]>
From 2b6e15a2f5e159898edc6bc8ad543ffe454b8ed9 Mon Sep 17 00:00:00 2001 From: Christian Brauner <[email protected]> Date: Thu, 12 Oct 2017 20:19:18 +0200 Subject: [PATCH] dir: make sure pool is mounted Closes #3938. Signed-off-by: Christian Brauner <[email protected]> --- lxd/storage_dir.go | 137 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 123 insertions(+), 14 deletions(-) diff --git a/lxd/storage_dir.go b/lxd/storage_dir.go index 487cc8991..dc2a5a5b7 100644 --- a/lxd/storage_dir.go +++ b/lxd/storage_dir.go @@ -289,6 +289,14 @@ func (s *storageDir) GetContainerPoolInfo() (int64, string, string) { func (s *storageDir) StoragePoolUpdate(writable *api.StoragePoolPut, changedConfig []string) error { logger.Infof(`Updating DIR storage pool "%s"`, s.pool.Name) + ourMount, err := s.StoragePoolMount() + if err != nil { + return err + } + if ourMount { + defer s.StoragePoolUmount() + } + changeable := changeableStoragePoolProperties["dir"] unchangeable := []string{} for _, change := range changedConfig { @@ -311,13 +319,21 @@ func (s *storageDir) StoragePoolUpdate(writable *api.StoragePoolPut, changedConf func (s *storageDir) StoragePoolVolumeCreate() error { logger.Infof("Creating DIR storage volume \"%s\" on storage pool \"%s\".", s.volume.Name, s.pool.Name) + ourMount, err := s.StoragePoolMount() + if err != nil { + return err + } + if ourMount { + defer s.StoragePoolUmount() + } + source := s.pool.Config["source"] if source == "" { return fmt.Errorf("no \"source\" property found for the storage pool") } storageVolumePath := getStoragePoolVolumeMountPoint(s.pool.Name, s.volume.Name) - err := os.MkdirAll(storageVolumePath, 0711) + err = os.MkdirAll(storageVolumePath, 0711) if err != nil { return err } @@ -334,12 +350,17 @@ func (s *storageDir) StoragePoolVolumeDelete() error { return fmt.Errorf("no \"source\" property found for the storage pool") } + _, err := s.StoragePoolUmount() + if err != nil { + return err + } + storageVolumePath := getStoragePoolVolumeMountPoint(s.pool.Name, s.volume.Name) if !shared.PathExists(storageVolumePath) { return nil } - err := os.RemoveAll(storageVolumePath) + err = os.RemoveAll(storageVolumePath) if err != nil { return err } @@ -370,6 +391,14 @@ func (s *storageDir) StoragePoolVolumeUmount() (bool, error) { func (s *storageDir) StoragePoolVolumeUpdate(writable *api.StorageVolumePut, changedConfig []string) error { logger.Infof(`Updating DIR storage volume "%s"`, s.pool.Name) + ourMount, err := s.StoragePoolMount() + if err != nil { + return err + } + if ourMount { + defer s.StoragePoolUmount() + } + changeable := changeableStoragePoolVolumeProperties["dir"] unchangeable := []string{} for _, change := range changedConfig { @@ -395,13 +424,21 @@ func (s *storageDir) ContainerStorageReady(name string) bool { func (s *storageDir) ContainerCreate(container container) error { logger.Debugf("Creating empty DIR storage volume for container \"%s\" on storage pool \"%s\".", s.volume.Name, s.pool.Name) + ourMount, err := s.StoragePoolMount() + if err != nil { + return err + } + if ourMount { + defer s.StoragePoolUmount() + } + source := s.pool.Config["source"] if source == "" { return fmt.Errorf("no \"source\" property found for the storage pool") } containerMntPoint := getContainerMountPoint(s.pool.Name, container.Name()) - err := createContainerMountpoint(containerMntPoint, container.Path(), container.IsPrivileged()) + err = createContainerMountpoint(containerMntPoint, container.Path(), container.IsPrivileged()) if err != nil { return err } @@ -427,6 +464,14 @@ func (s *storageDir) ContainerCreate(container container) error { func (s *storageDir) ContainerCreateFromImage(container container, imageFingerprint string) error { logger.Debugf("Creating DIR storage volume for container \"%s\" on storage pool \"%s\".", s.volume.Name, s.pool.Name) + ourMount, err := s.StoragePoolMount() + if err != nil { + return err + } + if ourMount { + defer s.StoragePoolUmount() + } + source := s.pool.Config["source"] if source == "" { return fmt.Errorf("no \"source\" property found for the storage pool") @@ -435,7 +480,7 @@ func (s *storageDir) ContainerCreateFromImage(container container, imageFingerpr privileged := container.IsPrivileged() containerName := container.Name() containerMntPoint := getContainerMountPoint(s.pool.Name, containerName) - err := createContainerMountpoint(containerMntPoint, container.Path(), privileged) + err = createContainerMountpoint(containerMntPoint, container.Path(), privileged) if err != nil { return err } @@ -483,6 +528,14 @@ func (s *storageDir) ContainerDelete(container container) error { return fmt.Errorf("no \"source\" property found for the storage pool") } + ourMount, err := s.StoragePoolMount() + if err != nil { + return err + } + if ourMount { + defer s.StoragePoolUmount() + } + // Delete the container on its storage pool: // ${POOL}/containers/<container_name> containerName := container.Name() @@ -498,7 +551,7 @@ func (s *storageDir) ContainerDelete(container container) error { } } - err := deleteContainerMountpoint(containerMntPoint, container.Path(), s.GetStorageTypeName()) + err = deleteContainerMountpoint(containerMntPoint, container.Path(), s.GetStorageTypeName()) if err != nil { return err } @@ -584,6 +637,14 @@ func (s *storageDir) copySnapshot(target container, source container) error { func (s *storageDir) ContainerCopy(target container, source container, containerOnly bool) error { logger.Debugf("Copying DIR container storage %s -> %s.", source.Name(), target.Name()) + ourMount, err := s.StoragePoolMount() + if err != nil { + return err + } + if ourMount { + defer s.StoragePoolUmount() + } + ourStart, err := source.StorageStart() if err != nil { return err @@ -642,16 +703,24 @@ func (s *storageDir) ContainerCopy(target container, source container, container } func (s *storageDir) ContainerMount(c container) (bool, error) { - return true, nil + return s.StoragePoolMount() } func (s *storageDir) ContainerUmount(name string, path string) (bool, error) { - return true, nil + return s.StoragePoolUmount() } func (s *storageDir) ContainerRename(container container, newName string) error { logger.Debugf("Renaming DIR storage volume for container \"%s\" from %s -> %s.", s.volume.Name, s.volume.Name, newName) + ourMount, err := s.StoragePoolMount() + if err != nil { + return err + } + if ourMount { + defer s.StoragePoolUmount() + } + source := s.pool.Config["source"] if source == "" { return fmt.Errorf("no \"source\" property found for the storage pool") @@ -661,7 +730,7 @@ func (s *storageDir) ContainerRename(container container, newName string) error oldContainerSymlink := shared.VarPath("containers", container.Name()) newContainerMntPoint := getContainerMountPoint(s.pool.Name, newName) newContainerSymlink := shared.VarPath("containers", newName) - err := renameContainerMountpoint(oldContainerMntPoint, oldContainerSymlink, newContainerMntPoint, newContainerSymlink) + err = renameContainerMountpoint(oldContainerMntPoint, oldContainerSymlink, newContainerMntPoint, newContainerSymlink) if err != nil { return err } @@ -702,6 +771,14 @@ func (s *storageDir) ContainerRename(container container, newName string) error func (s *storageDir) ContainerRestore(container container, sourceContainer container) error { logger.Debugf("Restoring DIR storage volume for container \"%s\" from %s -> %s.", s.volume.Name, sourceContainer.Name(), container.Name()) + ourMount, err := s.StoragePoolMount() + if err != nil { + return err + } + if ourMount { + defer s.StoragePoolUmount() + } + targetPath := container.Path() sourcePath := sourceContainer.Path() @@ -728,10 +805,18 @@ func (s *storageDir) ContainerGetUsage(container container) (int64, error) { func (s *storageDir) ContainerSnapshotCreate(snapshotContainer container, sourceContainer container) error { logger.Debugf("Creating DIR storage volume for snapshot \"%s\" on storage pool \"%s\".", s.volume.Name, s.pool.Name) + ourMount, err := s.StoragePoolMount() + if err != nil { + return err + } + if ourMount { + defer s.StoragePoolUmount() + } + // Create the path for the snapshot. targetContainerName := snapshotContainer.Name() targetContainerMntPoint := getSnapshotMountPoint(s.pool.Name, targetContainerName) - err := os.MkdirAll(targetContainerMntPoint, 0711) + err = os.MkdirAll(targetContainerMntPoint, 0711) if err != nil { return err } @@ -800,10 +885,18 @@ onSuccess: func (s *storageDir) ContainerSnapshotCreateEmpty(snapshotContainer container) error { logger.Debugf("Creating empty DIR storage volume for snapshot \"%s\" on storage pool \"%s\".", s.volume.Name, s.pool.Name) + ourMount, err := s.StoragePoolMount() + if err != nil { + return err + } + if ourMount { + defer s.StoragePoolUmount() + } + // Create the path for the snapshot. targetContainerName := snapshotContainer.Name() targetContainerMntPoint := getSnapshotMountPoint(s.pool.Name, targetContainerName) - err := os.MkdirAll(targetContainerMntPoint, 0711) + err = os.MkdirAll(targetContainerMntPoint, 0711) if err != nil { return err } @@ -869,13 +962,21 @@ func dirSnapshotDeleteInternal(poolName string, snapshotName string) error { func (s *storageDir) ContainerSnapshotDelete(snapshotContainer container) error { logger.Debugf("Deleting DIR storage volume for snapshot \"%s\" on storage pool \"%s\".", s.volume.Name, s.pool.Name) + ourMount, err := s.StoragePoolMount() + if err != nil { + return err + } + if ourMount { + defer s.StoragePoolUmount() + } + source := s.pool.Config["source"] if source == "" { return fmt.Errorf("no \"source\" property found for the storage pool") } snapshotContainerName := snapshotContainer.Name() - err := dirSnapshotDeleteInternal(s.pool.Name, snapshotContainerName) + err = dirSnapshotDeleteInternal(s.pool.Name, snapshotContainerName) if err != nil { return err } @@ -887,11 +988,19 @@ func (s *storageDir) ContainerSnapshotDelete(snapshotContainer container) error func (s *storageDir) ContainerSnapshotRename(snapshotContainer container, newName string) error { logger.Debugf("Renaming DIR storage volume for snapshot \"%s\" from %s -> %s.", s.volume.Name, s.volume.Name, newName) + ourMount, err := s.StoragePoolMount() + if err != nil { + return err + } + if ourMount { + defer s.StoragePoolUmount() + } + // Rename the mountpoint for the snapshot: // ${POOL}/snapshots/<old_snapshot_name> to ${POOL}/snapshots/<new_snapshot_name> oldSnapshotMntPoint := getSnapshotMountPoint(s.pool.Name, snapshotContainer.Name()) newSnapshotMntPoint := getSnapshotMountPoint(s.pool.Name, newName) - err := os.Rename(oldSnapshotMntPoint, newSnapshotMntPoint) + err = os.Rename(oldSnapshotMntPoint, newSnapshotMntPoint) if err != nil { return err } @@ -901,11 +1010,11 @@ func (s *storageDir) ContainerSnapshotRename(snapshotContainer container, newNam } func (s *storageDir) ContainerSnapshotStart(container container) (bool, error) { - return true, nil + return s.StoragePoolMount() } func (s *storageDir) ContainerSnapshotStop(container container) (bool, error) { - return true, nil + return s.StoragePoolUmount() } func (s *storageDir) ImageCreate(fingerprint string) error {
_______________________________________________ lxc-devel mailing list [email protected] http://lists.linuxcontainers.org/listinfo/lxc-devel
