The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/7033

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) ===
- Adds support for VM resizing.
- Consistently uses `%dB` for RBD volume `--size` argument, rather than a mix of `%dM` when resizing and `%dB` for new volumes.
- Adds checks for actual current block device size as part of logic to decide whether the new size is a shrink or grow operation.

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
From 71047e1d8703c0990455bed00ca81542f72ee99f Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Mon, 16 Mar 2020 14:13:18 +0000
Subject: [PATCH] lxd/storage/drivers/driver/ceph/volumes: Adds VM block resize
 support

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage/drivers/driver_ceph_volumes.go | 92 +++++++++++++++-------
 1 file changed, 65 insertions(+), 27 deletions(-)

diff --git a/lxd/storage/drivers/driver_ceph_volumes.go 
b/lxd/storage/drivers/driver_ceph_volumes.go
index 212932c915..35ec28a066 100644
--- a/lxd/storage/drivers/driver_ceph_volumes.go
+++ b/lxd/storage/drivers/driver_ceph_volumes.go
@@ -4,7 +4,10 @@ import (
        "encoding/json"
        "fmt"
        "io"
+       "io/ioutil"
        "os"
+       "path/filepath"
+       "strconv"
        "strings"
 
        "github.com/pborman/uuid"
@@ -672,41 +675,74 @@ func (d *ceph) SetVolumeQuota(vol Volume, size string, op 
*operations.Operation)
                return err
        }
 
-       oldSize, err := units.ParseByteSizeString(vol.config["size"])
+       RBDSize, err := ioutil.ReadFile(fmt.Sprintf("/sys/class/block/%s/size", 
filepath.Base(RBDDevPath)))
        if err != nil {
-               return err
+               return errors.Wrapf(err, "Error getting current size")
        }
 
-       newSize, err := units.ParseByteSizeString(size)
+       RBDSizeBlocks, err := strconv.Atoi(strings.TrimSpace(string(RBDSize)))
+       if err != nil {
+               return errors.Wrapf(err, "Error getting converting current size 
to integer")
+       }
+
+       oldSizeBytes := int64(RBDSizeBlocks * 512)
+
+       newSizeBytes, err := units.ParseByteSizeString(size)
        if err != nil {
                return err
        }
 
-       // The right disjunct just means that someone unset the size property in
-       // the container's config. We obviously cannot resize to 0.
-       if oldSize == newSize || newSize == 0 {
+       // The right disjunct just means that someone unset the size property 
in the instance's config.
+       // We obviously cannot resize to 0.
+       if oldSizeBytes == newSizeBytes || newSizeBytes == 0 {
                return nil
        }
 
-       if newSize < oldSize {
-               err = shrinkFileSystem(fsType, RBDDevPath, vol, newSize)
-               if err != nil {
-                       return err
-               }
+       // Resize filesystem if needed.
+       if vol.contentType == ContentTypeFS {
+               if newSizeBytes < oldSizeBytes {
+                       err = shrinkFileSystem(fsType, RBDDevPath, vol, 
newSizeBytes)
+                       if err != nil {
+                               return err
+                       }
 
-               _, err = shared.TryRunCommand(
-                       "rbd",
-                       "resize",
-                       "--allow-shrink",
-                       "--id", d.config["ceph.user.name"],
-                       "--cluster", d.config["ceph.cluster_name"],
-                       "--pool", d.config["ceph.osd.pool_name"],
-                       "--size", fmt.Sprintf("%dM", (newSize/1024/1024)),
-                       d.getRBDVolumeName(vol, "", false, false))
-               if err != nil {
-                       return err
+                       _, err = shared.TryRunCommand(
+                               "rbd",
+                               "resize",
+                               "--allow-shrink",
+                               "--id", d.config["ceph.user.name"],
+                               "--cluster", d.config["ceph.cluster_name"],
+                               "--pool", d.config["ceph.osd.pool_name"],
+                               "--size", fmt.Sprintf("%dB", newSizeBytes),
+                               d.getRBDVolumeName(vol, "", false, false))
+                       if err != nil {
+                               return err
+                       }
+               } else {
+                       // Grow the block device.
+                       _, err = shared.TryRunCommand(
+                               "rbd",
+                               "resize",
+                               "--id", d.config["ceph.user.name"],
+                               "--cluster", d.config["ceph.cluster_name"],
+                               "--pool", d.config["ceph.osd.pool_name"],
+                               "--size", fmt.Sprintf("%dB", newSizeBytes),
+                               d.getRBDVolumeName(vol, "", false, false))
+                       if err != nil {
+                               return err
+                       }
+
+                       // Grow the filesystem.
+                       err = growFileSystem(fsType, RBDDevPath, vol)
+                       if err != nil {
+                               return err
+                       }
                }
        } else {
+               if newSizeBytes < oldSizeBytes {
+                       return fmt.Errorf("You cannot shrink block volumes")
+               }
+
                // Grow the block device.
                _, err = shared.TryRunCommand(
                        "rbd",
@@ -714,16 +750,18 @@ func (d *ceph) SetVolumeQuota(vol Volume, size string, op 
*operations.Operation)
                        "--id", d.config["ceph.user.name"],
                        "--cluster", d.config["ceph.cluster_name"],
                        "--pool", d.config["ceph.osd.pool_name"],
-                       "--size", fmt.Sprintf("%dM", (newSize/1024/1024)),
+                       "--size", fmt.Sprintf("%dB", newSizeBytes),
                        d.getRBDVolumeName(vol, "", false, false))
                if err != nil {
                        return err
                }
 
-               // Grow the filesystem.
-               err = growFileSystem(fsType, RBDDevPath, vol)
-               if err != nil {
-                       return err
+               // Move the GPT alt header to end of disk if needed.
+               if vol.IsVMBlock() {
+                       err = d.moveGPTAltHeader(RBDDevPath)
+                       if err != nil {
+                               return err
+                       }
                }
        }
 
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to