-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: wipe devices before using if enabled
Signed-off-by: Suleyman Akbas <[email protected]>
- Loading branch information
1 parent
bd11b2a
commit 7d3abc8
Showing
17 changed files
with
554 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package dmsetup | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/openshift/lvm-operator/pkg/internal/exec" | ||
) | ||
|
||
var ( | ||
DefaultDMSetup = "/usr/sbin/dmsetup" | ||
ErrReferenceNotFound = fmt.Errorf("device-mapper reference not found") | ||
) | ||
|
||
type Dmsetup interface { | ||
Remove(deviceName string) error | ||
} | ||
|
||
type HostDmsetup struct { | ||
exec.Executor | ||
dmsetup string | ||
} | ||
|
||
func NewDefaultHostDmsetup() *HostDmsetup { | ||
return NewHostDmsetup(&exec.CommandExecutor{}, DefaultDMSetup) | ||
} | ||
|
||
func NewHostDmsetup(executor exec.Executor, dmsetup string) *HostDmsetup { | ||
return &HostDmsetup{ | ||
Executor: executor, | ||
dmsetup: dmsetup, | ||
} | ||
} | ||
|
||
// Remove removes the device's reference from the device-mapper | ||
func (dmsetup *HostDmsetup) Remove(deviceName string) error { | ||
if len(deviceName) == 0 { | ||
return fmt.Errorf("failed to remove device-mapper reference. Device name is empty") | ||
} | ||
|
||
args := []string{"remove"} | ||
args = append(args, deviceName) | ||
output, err := dmsetup.ExecuteCommandWithOutputAsHost(dmsetup.dmsetup, args...) | ||
if err != nil { | ||
if strings.Contains(output, "not found") { | ||
return ErrReferenceNotFound | ||
} | ||
return fmt.Errorf("failed to remove the reference from device-mapper %q: %v", deviceName, err) | ||
} | ||
|
||
return nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.