talos

Форк
0
59 строк · 1.6 Кб
1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4

5
package vm
6

7
import (
8
	"errors"
9
	"fmt"
10
	"os"
11
	"syscall"
12

13
	"github.com/siderolabs/talos/pkg/provision"
14
)
15

16
// UserDiskName returns disk device path.
17
func (p *Provisioner) UserDiskName(index int) string {
18
	// the disk IDs are assigned in the following way:
19
	// * ata-QEMU_HARDDISK_QM00001
20
	// * ata-QEMU_HARDDISK_QM00003
21
	// * ata-QEMU_HARDDISK_QM00005
22
	return fmt.Sprintf("/dev/disk/by-id/ata-QEMU_HARDDISK_QM%05d", (index-1)*2+1)
23
}
24

25
// CreateDisks creates empty disk files for each disk.
26
func (p *Provisioner) CreateDisks(state *State, nodeReq provision.NodeRequest) (diskPaths []string, err error) {
27
	diskPaths = make([]string, len(nodeReq.Disks))
28

29
	for i, disk := range nodeReq.Disks {
30
		diskPath := state.GetRelativePath(fmt.Sprintf("%s-%d.disk", nodeReq.Name, i))
31

32
		var diskF *os.File
33

34
		diskF, err = os.Create(diskPath)
35
		if err != nil {
36
			return nil, err
37
		}
38

39
		defer diskF.Close() //nolint:errcheck
40

41
		if err = diskF.Truncate(int64(disk.Size)); err != nil {
42
			return nil, err
43
		}
44

45
		if !disk.SkipPreallocate {
46
			if err = syscall.Fallocate(int(diskF.Fd()), 0, 0, int64(disk.Size)); err != nil {
47
				fmt.Fprintf(os.Stderr, "WARNING: failed to preallocate disk space for %q (size %d): %s", diskPath, disk.Size, err)
48
			}
49
		}
50

51
		diskPaths[i] = diskPath
52
	}
53

54
	if len(diskPaths) == 0 {
55
		return nil, errors.New("node request must have at least one disk defined to be used as primary disk")
56
	}
57

58
	return diskPaths, nil
59
}
60

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.