forked from openshift/lvm-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Suleyman Akbas <[email protected]>
- Loading branch information
1 parent
99c6473
commit dc6e0a7
Showing
13 changed files
with
156 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
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,67 @@ | ||
package wipefs | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/openshift/lvm-operator/pkg/internal/exec" | ||
) | ||
|
||
var ( | ||
DefaultWipefs = "/usr/bin/wipefs" | ||
DefaultDMSetup = "/usr/sbin/dmsetup" | ||
) | ||
|
||
type Wipefs interface { | ||
Wipe(deviceName string) error | ||
RemoveMapperReference(deviceName string) error | ||
} | ||
|
||
type HostWipefs struct { | ||
exec.Executor | ||
wipefs string | ||
dmsetup string | ||
} | ||
|
||
func NewDefaultHostWipefs() *HostWipefs { | ||
return NewHostWipefs(&exec.CommandExecutor{}, DefaultWipefs, DefaultDMSetup) | ||
} | ||
|
||
func NewHostWipefs(executor exec.Executor, wipefs, dmsetup string) *HostWipefs { | ||
return &HostWipefs{ | ||
Executor: executor, | ||
wipefs: wipefs, | ||
dmsetup: dmsetup, | ||
} | ||
} | ||
|
||
// Wipe wipes the device only if force delete flag is set | ||
func (wipefs *HostWipefs) Wipe(deviceName string) error { | ||
if len(deviceName) == 0 { | ||
return fmt.Errorf("failed to wipe the device. Device name is empty") | ||
} | ||
|
||
args := []string{"--all", "--force"} | ||
args = append(args, deviceName) | ||
_, err := wipefs.ExecuteCommandWithOutputAsHost(wipefs.wipefs, args...) | ||
if err != nil { | ||
return fmt.Errorf("failed to wipe the device %q. %v", deviceName, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// RemoveMapperReference removes the device's reference from the device-mapper | ||
func (wipefs *HostWipefs) RemoveMapperReference(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) | ||
_, err := wipefs.ExecuteCommandWithOutputAsHost(wipefs.dmsetup, args...) | ||
if err != nil { | ||
return fmt.Errorf("failed to remove the reference from device-mapper %q. %v", deviceName, err) | ||
} | ||
|
||
return nil | ||
} |