[lxc-devel] [lxd/master] Fix resources API on some aarch64 and drive-by fix to images

stgraber on Github lxc-bot at linuxcontainers.org
Thu May 28 14:05:59 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200528/b7bd3dd4/attachment.bin>
-------------- next part --------------
From f673b791bf96b3e81366f6fb365a5026b2763906 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 27 May 2020 09:34:38 -0400
Subject: [PATCH 1/2] lxd/images: Set CreatedAt on publish
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #3425

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/images.go | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lxd/images.go b/lxd/images.go
index 08e2fe7f7e..c2bd638809 100644
--- a/lxd/images.go
+++ b/lxd/images.go
@@ -304,6 +304,7 @@ func imgPostContInfo(d *Daemon, r *http.Request, req api.ImagesPost, op *operati
 	}
 	info.Size = fi.Size()
 	info.Fingerprint = fmt.Sprintf("%x", sha256.Sum(nil))
+	info.CreatedAt = time.Now().UTC()
 
 	_, _, err = d.cluster.GetImage(project, info.Fingerprint, false, true)
 	if err != db.ErrNoSuchObject {

From 8f0d53be88303cc56155827e1159ed4cfd383062 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 28 May 2020 10:05:16 -0400
Subject: [PATCH 2/2] lxd/resources: Handle missing cache size/type
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/resources/cpu.go | 41 +++++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 18 deletions(-)

diff --git a/lxd/resources/cpu.go b/lxd/resources/cpu.go
index 52c5975c0b..148bddfba7 100644
--- a/lxd/resources/cpu.go
+++ b/lxd/resources/cpu.go
@@ -38,44 +38,49 @@ func getCPUCache(path string) ([]api.ResourcesCPUCache, error) {
 
 		// Setup the cache entry
 		cache := api.ResourcesCPUCache{}
+		cache.Type = "Unknown"
 
 		// Get the cache level
 		cacheLevel, err := readUint(filepath.Join(entryPath, "level"))
 		if err != nil {
 			return nil, errors.Wrapf(err, "Failed to read \"%s\"", filepath.Join(entryPath, "level"))
 		}
-
 		cache.Level = cacheLevel
 
 		// Get the cache size
 		content, err := ioutil.ReadFile(filepath.Join(entryPath, "size"))
 		if err != nil {
-			return nil, errors.Wrapf(err, "Failed to read \"%s\"", filepath.Join(entryPath, "size"))
-		}
-		cacheSizeStr := strings.TrimSpace(string(content))
+			if !os.IsNotExist(err) {
+				return nil, errors.Wrapf(err, "Failed to read \"%s\"", filepath.Join(entryPath, "size"))
+			}
+		} else {
+			cacheSizeStr := strings.TrimSpace(string(content))
+
+			// Handle cache sizes in KiB
+			cacheSizeMultiplier := uint64(1)
+			if strings.HasSuffix(cacheSizeStr, "K") {
+				cacheSizeMultiplier = 1024
+				cacheSizeStr = strings.TrimSuffix(cacheSizeStr, "K")
+			}
 
-		// Handle cache sizes in KiB
-		cacheSizeMultiplier := uint64(1)
-		if strings.HasSuffix(cacheSizeStr, "K") {
-			cacheSizeMultiplier = 1024
-			cacheSizeStr = strings.TrimSuffix(cacheSizeStr, "K")
-		}
+			cacheSize, err := strconv.ParseUint((cacheSizeStr), 10, 64)
+			if err != nil {
+				return nil, errors.Wrap(err, "Failed to parse cache size")
+			}
 
-		cacheSize, err := strconv.ParseUint((cacheSizeStr), 10, 64)
-		if err != nil {
-			return nil, errors.Wrap(err, "Failed to parse cache size")
+			cache.Size = cacheSize * cacheSizeMultiplier
 		}
 
-		cache.Size = cacheSize * cacheSizeMultiplier
-
 		// Get the cache type
 		cacheType, err := ioutil.ReadFile(filepath.Join(entryPath, "type"))
 		if err != nil {
-			return nil, errors.Wrapf(err, "Failed to read \"%s\"", filepath.Join(entryPath, "type"))
+			if !os.IsNotExist(err) {
+				return nil, errors.Wrapf(err, "Failed to read \"%s\"", filepath.Join(entryPath, "type"))
+			}
+		} else {
+			cache.Type = strings.TrimSpace(string(cacheType))
 		}
 
-		cache.Type = strings.TrimSpace(string(cacheType))
-
 		// Add to the list
 		caches = append(caches, cache)
 	}


More information about the lxc-devel mailing list