Skip to content

Commit

Permalink
storage: Add Misc capabilities
Browse files Browse the repository at this point in the history
a.) By default, block destructive install affecting other disks
b.) Add way to report effects on other disks
c.) Add force-install option
d.) Add Cleanup progress
e.) Fixes

Signed-off-by: Karthik Prabhu Vinod <[email protected]>
  • Loading branch information
karthikprabhuvinod committed May 7, 2020
1 parent 00c73c4 commit cc27345
Show file tree
Hide file tree
Showing 9 changed files with 497 additions and 107 deletions.
8 changes: 8 additions & 0 deletions args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type Args struct {
SkipValidationAll bool
SkipValidationAllSet bool
SwapFileSize string
ForceDestructive bool
}

func (args *Args) setKernelArgs() (err error) {
Expand Down Expand Up @@ -424,6 +425,13 @@ func (args *Args) setCommandLineArgs() (err error) {
&args.SwapFileSize, "swap-file-size", args.SwapFileSize, "Size of the swapfile; <size>[B|K|M|G]",
)

flag.BoolVar(
&args.ForceDestructive, "force-destructive",
false,
"Enable destructive installation which may cause data loss on unselected media;"+
" "+"RAID, lvm etc. Proceed with caution!",
)

spflag.ErrHelp = errors.New("Clear Linux Installer program")

saveConfigFile := args.ConfigFile
Expand Down
4 changes: 4 additions & 0 deletions clr-installer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,10 @@ func processOptionsSaveIfSet(options args.Args, md *model.SystemInstall) {
md.MediaOpts.SwapFileSize = options.SwapFileSize
md.MediaOpts.SwapFileSet = true
}

if options.ForceDestructive {
md.MediaOpts.ForceDestructive = options.ForceDestructive
}
}

func processOptionsToModel(options args.Args, md *model.SystemInstall) {
Expand Down
36 changes: 32 additions & 4 deletions gui/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,32 @@ func (window *Window) launchMenuView() {
}
}

// writeToConfirmInstallDialog is a helper function to write to dialog for confirm installation window
func writeToConfirmInstallDialog(buffer *gtk.TextBuffer, dryRunResults *storage.DryRunType) {
for _, media := range *dryRunResults.UnPlannedDestructiveResults {
log.Debug("OtherMediaChange: %s", media)
buffer.InsertMarkup(buffer.GetEndIter(),
"<b><span foreground=\"#FDB814\">"+media+"</span></b>\n")
}

for _, media := range *dryRunResults.TargetResults {
log.Debug("MediaChange: %s", media)
buffer.Insert(buffer.GetEndIter(), media+"\n")
}
}

func setConfirmButtonState(dialog *gtk.Dialog, window *Window) error {
var err error
if storage.GetImpactOnOtherDisks() && !window.model.MediaOpts.ForceDestructive {
if confirmButton, err := dialog.GetWidgetForResponse(gtk.RESPONSE_OK); err == nil {
confirmButton.SetSensitive(false)
return nil
}
return err
}
return nil
}

// confirmInstall prompts the user for confirmation before installing
func (window *Window) confirmInstall() {
var primaryText, secondaryText string
Expand Down Expand Up @@ -884,11 +910,13 @@ func (window *Window) confirmInstall() {
}
}

medias := storage.GetPlannedMediaChanges(window.model.InstallSelected, window.model.TargetMedias,
dryRunResults := storage.GetPlannedMediaChanges(window.model.InstallSelected, window.model.TargetMedias,
window.model.MediaOpts)
for _, media := range medias {
log.Debug("MediaChange: %s", media)
buffer.Insert(buffer.GetEndIter(), media+"\n")

writeToConfirmInstallDialog(buffer, dryRunResults)

if err = setConfirmButtonState(dialog, window); err != nil {
log.Error("Error setting Confirm button state", err)
}

dialog.ShowAll()
Expand Down
46 changes: 46 additions & 0 deletions locale/en_US/LC_MESSAGES/clr-installer.po
Original file line number Diff line number Diff line change
Expand Up @@ -844,3 +844,49 @@ msgstr "Creating %s"
#, c-format
msgid "Setting boot partition: %s"
msgstr "Setting boot partition: %s"
<<<<<<< HEAD
=======

#, c-format
msgid "Cleaning disk %s"
msgstr "Cleaning disk %s"

#, c-format
msgid "This will degrade RAID: %s"
msgstr "This will degrade RAID: %s"

#, c-format
msgid "Remove partition from RAID %s"
msgstr "Remove partition from RAID %s"

#, c-format
msgid "Raid [%s]: has parts from other disks: [%s]"
msgstr "Raid [%s]: has parts from other disks: [%s]"

#, c-format
msgid "Remove physical volume: %s from volume group: %s"
msgstr "Remove physical volume: %s from volume group: %s"

#, c-format
msgid "Volume group: %s has physical volumes from other disks: [%s]"
msgstr "Volume group: %s has physical volumes from other disks: [%s]"

#, c-format
msgid "Remove volume group: %s"
msgstr "Remove volume group: %s"

#, c-format
msgid "Remove physical volume: %s"
msgstr "Remove physical volume: %s"

#, c-format
msgid "Remove volumes: [%s]"
msgstr "Remove volumes: [%s]"

msgid "Effect on Other Disks:"
msgstr "Effect on Other Disks:"

msgid "Resolve above issues or use --force-destructive option"
msgstr "Resolve above issues or use --force-destructive option"

>>>>>>> c32484f... storage: All Misc fixes
4 changes: 4 additions & 0 deletions storage/block_devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ func (bd BlockDevice) GetMappedDeviceFile() string {
return filepath.Join("/dev/", bd.MappedName)
}

if bd.Type == BlockDeviceTypeLVM2Volume {
return filepath.Join("/dev/mapper", bd.Name)
}

return filepath.Join("/dev/", bd.Name)
}

Expand Down
2 changes: 1 addition & 1 deletion storage/block_devices_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func FindBlockDeviceDepthFirst(bd *BlockDevice, filterfunc BlockDevFilterFunc) (
}

// FindAllBlockDevices runs the filterfunc and returns a list of all blockdevices which
// satisfy the condition
// satisfy the condition. This tree is flattened. So dont use children of each item in list
func FindAllBlockDevices(bd *BlockDevice, filterfunc BlockDevFilterFunc) []*BlockDevice {
var result []*BlockDevice = []*BlockDevice{}

Expand Down
Loading

0 comments on commit cc27345

Please sign in to comment.