fix(storage): close create flow capability gate, raw disk stats/CoW guards, and UI recovery path
This commit is contained in:
1 parent
04f0d8d096
commit
a4fb1c6db6
8 files changed
+43
-15
No files matched your search
@@ -690,7 +690,7 @@ export const SettingsModal: React.FC<Props> = ({ locale, detail, driverID, stats
|
||||
locale={locale}
|
||||
value={(form.disk_cache as DiskCache) || 'default'}
|
||||
dirty={dirty('disk_cache')}
|
||||
disabled={!diskCacheSupported}
|
||||
supported={diskCacheSupported}
|
||||
reason={tr('diskCacheRequiresRuntime')}
|
||||
onReset={reset('disk_cache')}
|
||||
resetLabel={tr('resetField')}
|
||||
|
||||
@@ -20,7 +20,7 @@ interface DiskOptions {
|
||||
|
||||
function isWindowsRawDevicePath(disk?: string): boolean {
|
||||
const s = (disk ?? '').trim().replace(/\//g, '\\')
|
||||
return /^\\\\[.?]\\(physicaldrive|harddiskvolume|harddisk|volume\{)/i.test(s)
|
||||
return /^\\\\\.\\(physicaldrive|harddiskvolume|harddisk|volume\{)|^\\\\\?\\volume\{/i.test(s)
|
||||
}
|
||||
|
||||
/** Resizing, compacting and optimizing the VM's disk, one at a time. */
|
||||
|
||||
@@ -7,7 +7,7 @@ interface Props {
|
||||
locale: Locale
|
||||
value: DiskCache
|
||||
dirty: boolean
|
||||
disabled?: boolean
|
||||
supported?: boolean
|
||||
reason?: string
|
||||
onReset: () => void
|
||||
resetLabel: string
|
||||
@@ -15,21 +15,26 @@ interface Props {
|
||||
onChange: (cache: DiskCache) => void
|
||||
}
|
||||
|
||||
export const DiskCacheRow: React.FC<Props> = ({ locale, value, dirty, disabled = false, reason, onReset, resetLabel, error, onChange }) => {
|
||||
export const DiskCacheRow: React.FC<Props> = ({ locale, value, dirty, supported = true, reason, onReset, resetLabel, error, onChange }) => {
|
||||
const tr = (k: I18nKey, v?: Record<string, string | number>) => t(locale, k, v)
|
||||
const desc = value === 'writeback'
|
||||
const baseDesc = value === 'writeback'
|
||||
? tr('diskCacheDescWriteback')
|
||||
: value === 'none'
|
||||
? tr('diskCacheDescNone')
|
||||
: value === 'unsafe'
|
||||
? tr('diskCacheDescUnsafe')
|
||||
: tr('diskCacheDescDefault')
|
||||
const rowDisabled = !supported && value === 'default'
|
||||
const disableNonDefault = !supported
|
||||
const desc = !supported && value !== 'default' && reason
|
||||
? `${baseDesc} · ${reason}`
|
||||
: baseDesc
|
||||
|
||||
return (
|
||||
<SetRow
|
||||
field="disk_cache"
|
||||
dirty={dirty}
|
||||
disabled={disabled}
|
||||
disabled={rowDisabled}
|
||||
reason={reason}
|
||||
onReset={onReset}
|
||||
resetLabel={resetLabel}
|
||||
@@ -43,9 +48,9 @@ export const DiskCacheRow: React.FC<Props> = ({ locale, value, dirty, disabled =
|
||||
onChange={onChange}
|
||||
options={[
|
||||
{ value: 'default', label: tr('diskCacheOptionDefault') },
|
||||
{ value: 'writeback', label: tr('diskCacheOptionWriteback') },
|
||||
{ value: 'none', label: tr('diskCacheOptionNone') },
|
||||
{ value: 'unsafe', label: tr('diskCacheOptionUnsafe') },
|
||||
{ value: 'writeback', label: tr('diskCacheOptionWriteback'), disabled: disableNonDefault },
|
||||
{ value: 'none', label: tr('diskCacheOptionNone'), disabled: disableNonDefault },
|
||||
{ value: 'unsafe', label: tr('diskCacheOptionUnsafe'), disabled: disableNonDefault },
|
||||
]}
|
||||
/>
|
||||
}
|
||||
|
||||
@@ -44,6 +44,15 @@ func (a *App) createVMFlow(opts reims.CreateOpts) (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !active.Manifest.HasCapability("win32-native-aio") {
|
||||
loc := i18n.EffectiveLocale(cfgCopy.Locale)
|
||||
if dcache := strings.TrimSpace(opts.DiskCache); dcache != "" && !strings.EqualFold(dcache, "default") {
|
||||
return errors.New(i18n.T(loc, "validate.disk_cache_requires_runtime"))
|
||||
}
|
||||
if reims.IsWindowsRawDevicePath(opts.Disk) {
|
||||
return errors.New(i18n.T(loc, "validate.raw_disk_requires_runtime"))
|
||||
}
|
||||
}
|
||||
c := reims.NewClient(&cfgCopy, *active)
|
||||
|
||||
// Always defer starting to StartVM so commit-memory checks, Win10 cold-reboot
|
||||
|
||||
+2
-5
@@ -529,8 +529,8 @@ func vmCreate(ctx context.Context, cfg *config.Config, loc i18n.Locale, args []s
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.TrimSpace(*disk) != "" || strings.TrimSpace(*diskMode) != "" {
|
||||
return fmt.Errorf("--disk and --disk-mode are only supported by the %s driver", driver.BuiltinReimsMacOSDriverID)
|
||||
if strings.TrimSpace(*disk) != "" || strings.TrimSpace(*diskMode) != "" || strings.TrimSpace(*diskCache) != "" {
|
||||
return fmt.Errorf("--disk, --disk-mode, and --disk-cache are only supported by the %s driver", driver.BuiltinReimsMacOSDriverID)
|
||||
}
|
||||
req := driver.CreateRequest{
|
||||
DriverID: drv.ID(),
|
||||
@@ -542,9 +542,6 @@ func vmCreate(ctx context.Context, cfg *config.Config, loc i18n.Locale, args []s
|
||||
"disk_size": *diskSize,
|
||||
},
|
||||
}
|
||||
if *diskCache != "" {
|
||||
req.Options["disk_cache"] = *diskCache
|
||||
}
|
||||
if issues := drv.ValidateCreate(ctx, req); len(issues) > 0 {
|
||||
return fmt.Errorf("%s", issues[0].Message)
|
||||
}
|
||||
|
||||
@@ -98,3 +98,13 @@ func TestApplyPartitionExtentMatches(t *testing.T) {
|
||||
t.Fatalf("expected only clean APFS candidate, got %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInspectDiskUsageSkipsRawDevice(t *testing.T) {
|
||||
du, err := InspectDiskUsage(`\\.\Harddisk1Partition2`)
|
||||
if err != nil {
|
||||
t.Fatalf("InspectDiskUsage on raw device returned error: %v", err)
|
||||
}
|
||||
if du.Format != "raw" || du.Path != `\\.\Harddisk1Partition2` {
|
||||
t.Fatalf("unexpected DiskUsage for raw device: %+v", du)
|
||||
}
|
||||
}
|
||||
@@ -76,6 +76,9 @@ func ComputeCPUPercent(prev, cur ProcessSample, logicalCPUs int) float64 {
|
||||
// InspectDiskUsage returns actual host bytes consumed and virtual logical capacity
|
||||
// for a .qcow2 or raw disk image without spawning qemu-img.
|
||||
func InspectDiskUsage(path string) (DiskUsage, error) {
|
||||
if IsWindowsRawDevicePath(path) {
|
||||
return DiskUsage{Path: path, Format: "raw"}, nil
|
||||
}
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return DiskUsage{}, err
|
||||
|
||||
@@ -247,7 +247,11 @@ func (c *Client) createWithDisk(ctx context.Context, o CreateOpts, args []string
|
||||
}
|
||||
defer release()
|
||||
|
||||
switch o.DiskMode {
|
||||
mode := strings.ToLower(strings.TrimSpace(o.DiskMode))
|
||||
if mode == "" && IsWindowsRawDevicePath(disk) {
|
||||
mode = "in-place"
|
||||
}
|
||||
switch mode {
|
||||
case "in-place", "inplace", "link":
|
||||
default:
|
||||
// reims-ctl may copy a large image. Its source and backing files are
|
||||
|
||||
Reference in new issue
Block a user